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

import cn.estsh.i3plus.ext.mes.api.base.IReportExtService;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesBadCell;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesBadCellDetail;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesProdUnbindRecord;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
import cn.estsh.i3plus.pojo.base.bean.ListPager;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;

import java.util.List;

/**
 * @Author: xiangming.liao
 * @CreateDate: 2021/01/18 13:33 下午
 * @Description:
 **/
@RestController
@Api(tags = "报表数据")
@RequestMapping(CommonConstWords.BASE_URL_MES + "/report-ext")
public class ReportExtController {
    public static final Logger LOGGER = LoggerFactory.getLogger(ReportExtController.class);

    @Autowired
    private IReportExtService reportExtService;

    @GetMapping(value = "mes-bad-cell/query")
    @ApiOperation("工位不良主表数据")
    public ResultBean queryMesBadCell(MesBadCell mesBadCell, Pager pager) {
        try {
            mesBadCell.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            ListPager listPager = reportExtService.queryMesBadCell(mesBadCell, pager);
            return ResultBean.success("查询成功").setListPager(listPager).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException var4) {
            return ResultBean.fail(var4);
        } catch (Exception var5) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(var5);
        }
    }

    @GetMapping(value = "mes-bad-cell-detail/find")
    @ApiOperation("工位不良明细表数据")
    public ResultBean findMesBadCellDetail(MesBadCellDetail mesBadCellDetail) {
        try {
            mesBadCellDetail.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            List<MesBadCellDetail> mesBadCellDetails = reportExtService.findMesBadCellDetail(mesBadCellDetail);
            return ResultBean.success("查询成功").setResultList(mesBadCellDetails).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException var4) {
            return ResultBean.fail(var4);
        } catch (Exception var5) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(var5);
        }
    }

    @GetMapping(value = "/mes-prod-unbind-record/query")
    @ApiOperation("查询条码解绑记录")
    public ResultBean queryProdUnbindRecord(MesProdUnbindRecord prodUnbindRecord, Pager pager){
        try {
            prodUnbindRecord.setOrganizeCode(AuthUtil.getOrganizeCode());
            return ResultBean.success().setListPager(reportExtService.queryProdUnbindRecord(prodUnbindRecord, pager))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
}
