package com.dsk.web.controller.search.macroMarket;

import com.alibaba.fastjson2.JSONObject;
import com.dsk.common.core.domain.AjaxResult;
import com.dsk.common.dtos.ComposeQueryDto;
import com.dsk.system.service.RegionalEnterprisesService;
import com.dsk.web.controller.search.controller.PageQueryLimit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName RegionalEnterprisesController
 * @Description 区域企业
 * @Author Dgm
 * @Date 2023/5/24 16:20
 * @Version
 */
@RestController
@RequestMapping(value="/enterprises")
public class RegionalEnterprisesController {

    @Autowired
    private RegionalEnterprisesService regionalEnterprisesService;

    @PostMapping("regional/page")
    public AjaxResult page(@RequestBody JSONObject object) throws Exception{
        ComposeQueryDto compose = JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
        compose.getPage().setPage(compose.getPageNum());
        compose.getPage().setLimit(compose.getPageSize());
        compose.getPage().setField(compose.getField());
        compose.getPage().setOrder(compose.getOrder());
        if (PageQueryLimit.pageLimit(compose.getPage())){
            return AjaxResult.error("翻页已达到上限");
        }
        return regionalEnterprisesService.enterprisePage(compose);
    }
}
