package cn.estsh.i3plus.ext.mes.apiservice.controller.busi.bu;

import cn.estsh.i3plus.ext.mes.api.busi.bu.IMesPersonnelSkillsKanbanService;
import cn.estsh.i3plus.ext.mes.pojo.model.bu.PersonnelSkillsKanbanDataModel;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.impp.framework.base.controller.MesBaseController;
import cn.estsh.impp.framework.boot.auth.AuthUtil;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.util.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(CommonConstWords.BASE_URL_MES+"/personnel-skills-kanban")
@Api(tags = "人员技能看板controller")
public class MesPersonnelSkillsKanbanController extends MesBaseController {

    @Autowired
    private IMesPersonnelSkillsKanbanService personnelSkillsKanbanService;

    @GetMapping(value = "/query-skill-level-number")
    @ApiOperation(value = "技能水平人数查询")
    public ResultBean getSkillLevelNumber(String workCenterCode) {
        String organizeCode = AuthUtil.getOrganize().getOrganizeCode();
        try {
            return ResultBean.success("技能水平人数查询")
                    .setResultList(personnelSkillsKanbanService.getSkillLevelNumber(workCenterCode, organizeCode))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException imppException) {

            return ResultBean.fail(imppException);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

//    @GetMapping(value = "/query-process")
//    @ApiOperation(value = "工序查询")
//    public ResultBean getProcess(String workCenterCode) {
//        String organizeCode = AuthUtil.getOrganize().getOrganizeCode();
//        try {
//            return ResultBean.success("工序查询")
//                    .setResultList(personnelSkillsKanbanService.getProcess(workCenterCode, organizeCode))
//                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
//        } catch (ImppBusiException imppException) {
//
//            return ResultBean.fail(imppException);
//        } catch (Exception e) {
//            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
//        }
//    }

    @GetMapping(value = "/query-people")
    @ApiOperation(value = "人员查询")
    public ResultBean getPeople(String workCenterCode) {
        String organizeCode = AuthUtil.getOrganize().getOrganizeCode();
        try {
            return ResultBean.success("人员查询")
                    .setResultList(personnelSkillsKanbanService.getPeople(workCenterCode, organizeCode))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException imppException) {

            return ResultBean.fail(imppException);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }

    }

    @GetMapping(value = "/query-table-data")
    @ApiOperation(value = "表格数据查询")
    public ResultBean getTableData(String workCenterCode, Pager pager) {
        String organizeCode = AuthUtil.getOrganize().getOrganizeCode();
        try {
            PersonnelSkillsKanbanDataModel tableData = personnelSkillsKanbanService.getTableData(workCenterCode, organizeCode, pager);
            return ResultBean.success("表格数据查询")
                    .setResultObject(tableData)
                    .setListPager(tableData.getPagerList())
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException imppException) {

            return ResultBean.fail(imppException);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }

    }

    @GetMapping(value = "/query-base-data")
    @ApiOperation(value = "看板基础数据查询")
    public ResultBean getBaseData(String workCenterCode) {
        String organizeCode = AuthUtil.getOrganize().getOrganizeCode();
        try {
            return ResultBean.success("表格数据查询")
                    .setResultObject(personnelSkillsKanbanService.getBaseData(workCenterCode, organizeCode))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException imppException) {

            return ResultBean.fail(imppException);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }

    }

}
