package cn.ey.biz.module.system.controller.admin.codeblock;

import cn.ey.biz.common.pojo.PageResult;
import cn.ey.biz.common.pojo.R;
import cn.ey.biz.module.system.api.codeblock.dto.CodeBlockWideTableDTO;
import cn.ey.biz.module.system.api.codeblock.dto.CodeBlockWideTableReqDTO;
import cn.ey.biz.module.system.controller.admin.codeblock.vo.CodeBlockPageReqVO;
import cn.ey.biz.module.system.controller.admin.codeblock.vo.CodeBlockPageRespVO;
import cn.ey.biz.module.system.controller.admin.codeblock.vo.CodeBlockTreeValueVO;
import cn.ey.biz.module.system.controller.admin.codeblock.vo.CodeBlockWideTableVO;
import cn.ey.biz.module.system.controller.engagement.code.vo.EngagementCodeRuleReqVOList;
import cn.ey.biz.module.system.convert.codeblock.CodeBlockConvert;
import cn.ey.biz.module.system.dal.dataobject.codeblock.CodeBlockDO;
import cn.ey.biz.module.system.service.codeblock.CodeBlockWideService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import static cn.ey.biz.common.pojo.R.success;

@Api(tags = "管理后台 - 编码表查询")
@RestController
@RequestMapping("/system/code/block/")
@Validated
public class CodeBlockWideTableController {

    @Resource
    private CodeBlockWideService codeBlockingWideService;

    @PostMapping("list")
    @ApiOperation("编码表查询")
    public R<CodeBlockWideTableVO> queryCountryRegionForBack(@RequestBody EngagementCodeRuleReqVOList reqVOList) {
        CodeBlockWideTableVO codeBlockWideTableVO = codeBlockingWideService.queryCountryRegionForBack(reqVOList);
        return R.success(codeBlockWideTableVO);
    }

    @PostMapping("page")
    @ApiOperation("编码表分页查询")
    public R<PageResult<CodeBlockPageRespVO>> listPage(@RequestBody CodeBlockPageReqVO codeBlockPageReqVO) {
        IPage<CodeBlockDO> pageList = codeBlockingWideService.getDictDataPage(codeBlockPageReqVO);
        PageResult<CodeBlockDO> pageResult = new PageResult<>(pageList.getRecords(), pageList.getTotal());
        return success(CodeBlockConvert.INSTANCE.convertPage(pageResult));
    }

    @PostMapping("businessList")
    @ApiOperation("商机编码表查询")
    public R<CodeBlockWideTableDTO> queryCountryRegion(@RequestBody CodeBlockWideTableReqDTO reqVOList) {
        CodeBlockWideTableVO codeBlockWideTableVO = codeBlockingWideService.queryCountryRegion(reqVOList);
        return R.success(CodeBlockConvert.INSTANCE.voConvertDto(codeBlockWideTableVO));
    }

    @GetMapping("treeCodeList")
    @ApiOperation("业务线树查询")
    public R<List<CodeBlockTreeValueVO>> getTreeList() {
        List<CodeBlockTreeValueVO> treeList = codeBlockingWideService.treeCodeList();
        return R.success(treeList);
    }

    @GetMapping("treeCityCodeList")
    @ApiOperation("地区树查询")
    public R<List<CodeBlockTreeValueVO>> treeCityCodeList() {
        List<CodeBlockTreeValueVO> treeList = codeBlockingWideService.treeCityCodes();
        return R.success(treeList);
    }

    @GetMapping("/business/treeCodeList")
    @ApiOperation("商机业务线树查询")
    public R<List<CodeBlockTreeValueVO>> getBusinessTreeList() {
        List<CodeBlockTreeValueVO> treeList = codeBlockingWideService.getBusinessTreeList();
        return R.success(treeList);
    }

    @GetMapping("/business/treeCityCodeList")
    @ApiOperation("地区树查询")
    public R<List<CodeBlockTreeValueVO>> getBusinessTreeCityCodeList() {
        List<CodeBlockTreeValueVO> treeList = codeBlockingWideService.getBusinessTreeCityCodeList();
        return R.success(treeList);
    }
}
