JobManagementGetEquipmentAction.java

package com.mycim.webapp.actions.operation.query;

import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.utils.lang.collections.CollectionUtils;
import com.mycim.framework.utils.lang.collections.MapUtils;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.ems.ChecklistJob;
import com.mycim.valueobject.ems.Equipment;
import com.mycim.valueobject.wip.Lot;
import com.mycim.valueobject.wip.LotRunCardStore;
import com.mycim.webapp.actions.WipSetupAction;
import com.mycim.webapp.forms.JobOfEquipmentInfoForm;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Johnson.Wang
 * @version 6.0.0
 * @date 2019/9/24
 **/
public class JobManagementGetEquipmentAction extends WipSetupAction {

    public Map select(JobOfEquipmentInfoForm form) {
        // Populate the form bean instance
        List jsonArray = new ArrayList<>();

        List<Equipment> equipList = wipQueryService.getEquipment4Ext(form.getEquipmentRrn(), form.getStationRrn());

        if (CollectionUtils.isNotEmpty(equipList)) {
            for (Equipment equipment : equipList) {
                Map jsonObject = new HashMap<>();
                jsonObject.put("equipmentRrn", equipment.getInstanceRrn());// 设备Rrn
                jsonObject.put("equipmentId", equipment.getInstanceId());// 设备号
                jsonObject.put("description", equipment.getInstanceDesc());// 描述
                jsonObject.put("currentStatus", equipment.getCurrentStatus());// 设备状态
                jsonObject.put("processingBatchType", equipment.getProcessingBatchType());// 作业类型
                jsonObject.put("processingBatchSizeMin", equipment.getProcessingBatchSizeMin());// 作业最小大小
                jsonObject.put("processingBatchSizeMax", equipment.getProcessingBatchSizeMax());// 作业最大大小
                jsonObject.put("jobBuffer", equipment.getJobBuffer());// 作业缓冲区
                jsonObject.put("numberOfRunningJobs", equipment.getNumberOfRunningJobs());// 运行作业数
                jsonObject.put("pmHold", equipment.getPmHoldFlag());
                jsonObject.put("operationMode", equipment.getOperationMode());

                List<ChecklistJob> checklistJobs = emsService.getActiveChecklistJobs(equipment.getInstanceRrn());
                if (!checklistJobs.isEmpty()) {
                    jsonObject.put("checklistSize", checklistJobs.size() + "");
                }

                jsonArray.add(jsonObject);
            }
        }

        Map result = new HashMap<>();
        result.put("results", jsonArray.size());
        result.put("rows", jsonArray);

        return result;
    }

    public Map validateEqptStatusAvailable(Map params) {
        long lotRrn = MapUtils.getLong(params, "lotRrn");
        long equipRrn = MapUtils.getLong(params, "equipRrn");

        Equipment equipment = emsService.getEquipment(equipRrn);
        Lot lot = lotInqService.getLot(lotRrn);
        //错误 #44859 runcard lot在operator panel中runcard lot异常
        if(lotRunCardQueryService.checkLotInRunCard(lot.getLotRrn())){
            //这里需要回填 runcard 的 carrier
            LotRunCardStore lotRunCardStore = lotRunCardQueryService.getSplitRunCardLotStore(lot.getLotRrn());
            lot.setCarrierRrn(lotRunCardStore.getCarrierRrn());
            lot.setCarrierId(lotRunCardStore.getCarrierId());
        }
        boolean available = wipCheckService.checkEqptStatusAvailable(lot, equipment);

        Map data = new HashMap(2);
        Assert.isTrue(available, Errors.create().key(MessageIdList.JOBMANAGER_CHECK_EQP)
                                       .content("Can not check the state of the EQP, please try again later!").build());
        data.put("operationMode", equipment.getOperationMode());
        data.put("jobRrn", lot.getJobRrn());
        carrierService.checkPcdIsValid(lot.getCarrierRrn(), LocalContext.getFacilityRrn());
        return data;
    }

}