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

import cn.estsh.i3plus.ext.mes.api.busi.jx.ISxWorkCellTaktCollectRecordService;
import cn.estsh.i3plus.ext.mes.pojo.bean.SxWorkCellTaktCollectRecord;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
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.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.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @PROJECT_NAME: i3plus-mes-panasonic-jx
 * @DESCRIPTION:
 * @USER: xinwang.yi
 * @DATE: 2023-11-13 17:18
 */
@RestController
@RequestMapping(MesExtConstWords.BASE_URL_MES_JX + "/report")
@Api(tags = "松下工位节拍采集报表")
public class SxWorkCelITaktCollectRecordReportController extends MesBaseController {

    @Autowired
    private ISxWorkCellTaktCollectRecordService workCellTaktCollectRecordService;

    @GetMapping(value = "/work-cell-takt-collect-record/query")
    @ApiOperation(value = "按条件分页查询MES工位节拍采集记录数据")
    public ResultBean queryMesProdBindRecord(SxWorkCellTaktCollectRecord workCelITaktCollectRecord, Pager pager) {
        try {
            workCelITaktCollectRecord.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            ListPager listPager = workCellTaktCollectRecordService.queryWorkCellTaktCollectRecrodLByPager(workCelITaktCollectRecord, pager);
            return ResultBean.success("查询成功").setListPager(listPager)
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PutMapping(value = "/work-cell-takt-collect-record/update-valid-batch")
    @ApiOperation(value = "批量禁用/启用状态", notes = "批量禁用/启用状态")
    public ResultBean updateSxWorkCellTaktCollectPlcCfgStatus(String[] ids, int status) {
        try {
            ConvertBean.modelSafeArrayNumber(ids, true);
            workCellTaktCollectRecordService.updateWorkCellTaktCollectRecordValid(ids, status, AuthUtil.getSessionUser().getUserName());
            return ResultBean.success("修改成功")
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

}
