package cn.estsh.i3plus.ext.mes.pcn.apiservice.controller.base;

import cn.estsh.i3plus.ext.mes.pcn.api.base.IAntiStaticCheckDetailService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesAntiStaticCheckDetail;
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.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.*;

/**
 * @author yumingxing
 * @version 1.0
 * @date 2021/2/4 18:05
 **/
@RestController
@Api(tags = "防静电点检")
@RequestMapping(CommonConstWords.BASE_URL_MES_PCN+ "/anti-static-check")
public class AntiStaticCheckDetailController {
    @Autowired
    private IAntiStaticCheckDetailService antiStaticCheckDetailService;

    @GetMapping("query")
    @ApiOperation(value = "条件分页")
    public ResultBean queryPager(MesAntiStaticCheckDetail detail, Pager pager) {
        try {
            return ResultBean.success("查询成功").setListPager(this.antiStaticCheckDetailService.queryByPager(detail, pager))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping("query-cell")
    @ApiOperation(value = "查询工序代码下拉框")
    public ResultBean queryCell(String orderNo, String organizeCode) {
        try {
            return ResultBean.success("查询成功").setResultList(this.antiStaticCheckDetailService.queryCell(orderNo, organizeCode))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    //@GetMapping("query-process-code-list")
    //@ApiOperation(value = "查询工序代码下拉框")
    //public ResultBean queryProcessCode(String orderNo, String organizeCode) {
    //    try {
    //        return ResultBean.success("查询成功").setResultList(this.antiStaticCheckDetailService.queryProcessCodeList(orderNo, organizeCode))
    //                .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
    //    } catch (ImppBusiException busExcep) {
    //        return ResultBean.fail(busExcep);
    //    } catch (Exception e) {
    //        return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
    //    }
    //}

    @PutMapping("update")
    @ApiOperation(value = "修改")
    public ResultBean update(@RequestBody MesAntiStaticCheckDetail detail) {
        try {
            this.antiStaticCheckDetailService.update(detail);
            return ResultBean.success("修改成功")
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

}
