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

import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesBasDowntimeReasonTypeService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.constant.MesCommonConstant;
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.i3plus.pojo.mes.bean.MesDowntimeReasonType;
import cn.estsh.impp.framework.boot.auth.AuthUtil;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.util.ResultBean;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
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;

/**
 * @Description :设备停机类型
 * @Reference :
 * @Author : gsz
 * @CreateDate : 2024-05-17 14:16
 * @Modify:
 **/
@RestController
@RequestMapping(MesCommonConstant.MES_YANFEN + "/mesDowntimeReasonType")
public class MesDowntimeReasonTypeController {

    @Autowired
    private IMesBasDowntimeReasonTypeService downtimeReasonTypeService;

    @GetMapping(value = "/find-downtime-type-reason")
    @ApiOperation(value = "查询设备停机类型和原因")
    public ResultBean findMesDowntimeTypeReason(MesDowntimeReasonType mesDowntimeReasontype, Pager pager) {
        try {
            mesDowntimeReasontype.setOrganizeCode(!StringUtils.isEmpty(mesDowntimeReasontype.getOrganizeCode())?mesDowntimeReasontype.getOrganizeCode():AuthUtil.getOrganizeCode());
            //查询汇总工单数量
            List<MesDowntimeReasonType> mesDowntimeReasonTypes = downtimeReasonTypeService.findMesDowntimeTypeReason(mesDowntimeReasontype, pager);

            return ResultBean.success("查询成功")
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setListPager(new ListPager<>(mesDowntimeReasonTypes, pager));
        } catch (ImppBusiException e) {
            return ResultBean.fail(e).build();
        } catch (Exception e) {
            return ResultBean.fail(e);
        }
    }
}
