package cn.estsh.i3plus.ext.mes.pcn.apiservice.schedulejob;


import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesWorkCellScanMonitorLogService;
import cn.estsh.impp.framework.boot.init.ApplicationProperties;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @Description : 生产开模统计job
 * @Reference :
 * @Author : Castle
 * @CreateDate 2024/6/26 18:22
 * @Modify:
 **/
@Slf4j
@DisallowConcurrentExecution
@Component
@ApiOperation("工位操作日志字段补录job")
public class MesWorkCellOperationLogJob extends BaseMesScheduleJob {

    @Autowired
    private IMesWorkCellScanMonitorLogService logService;

    public MesWorkCellOperationLogJob() {
        super(MesWorkCellOperationLogJob.class, "工位操作日志字段补录job");
    }

    @Override
    public void executeMesJob(JobExecutionContext context, ApplicationProperties applicationProperties) {
        if (true) return;
        /**
         * 入参
         * {
         *     "organizeCode":"CK01",
         *     "pageSize":50,
         *     "times":50 超过50次job,还未完成的直接写成完成
         * }
         */
        String jobParam = this.getJobParam();
        JSONObject params = JSONUtil.parseObj(jobParam);

        String organizeCode = params.get("organizeCode").toString();
        Integer pageSize = Integer.parseInt(params.get("pageSize").toString());
        Object timesO = params.get("times");
        int times = 50;
        if (!Objects.isNull(timesO)) {
             times = Integer.parseInt(timesO.toString());
        }
        logService.doRecordCellOperationLog(organizeCode,pageSize, times);
    }

}
