EquipPmCounterStatusAction.java

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

import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.framework.utils.lang.collections.MapUtils;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.ems.Entity;
import com.mycim.valueobject.ems.Equipment;
import com.mycim.valueobject.prp.RecipeVersion;
import com.mycim.valueobject.wip.Lot;
import com.mycim.valueobject.wip.LotStatus;
import com.mycim.webapp.actions.WipSetupAction;

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

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

    /**
     * 检查设备计数型PM状态
     */
    public String validateEqptPMCounterStatus(Map<String, Object> request) {
        String eqptId = MapUtils.getString(request, "eqptId");
        String lotId = MapUtils.getString(request, "lotId");
        Assert.isFalse(StringUtils.isEmpty(eqptId) || StringUtils.isEmpty(lotId),
                       Errors.create().key(MessageIdList.PARAMETER_MISSING).content(
                               "If the " + "parameter " + "is" + " " + "lost, " + "please " + "login" + " " + "again!")
                             .build());

        Entity entity = emsService.getEntity(
                new Equipment(eqptId, getNamedSpace(ObjectList.ENTITY_KEY, LocalContext.getFacilityRrn()),
                              ObjectList.ENTITY_KEY));
        Assert.isFalse(entity == null || entity.getInstanceRrn() <= 0,
                       Errors.create().key(MessageIdList.EQUIPMENT_MISSING_ID).content("设备号为空或不存在").build());

        Lot lot = lotQueryService.getLot(lotId, LocalContext.getFacilityRrn());
        Assert.isFalse(lot == null || lot.getLotRrn() <= 0,
                       Errors.create().key(MessageIdList.LOT_MISSING_ID).content("No such lotId!").build());

        // 获取recipeRrn传入lot的recipeLogicalRrn变量中

        RecipeVersion recipe = recipeService.getLotRecipe(lot);
        long recipeRrn = 0L;
        if (recipe != null) {
            recipeRrn = recipe.getInstanceRrn();
        }
        lot.setRecipeLogicalRrn(recipeRrn);
        /**
         * 张教练 diff设备状态卡控 和组batch 手动进站异常  同时报出
         */
        //检查设备是否diff
        //检查lot是否组batch 手动操作阻止
        String checkInfo =  wipCheckService.checkBatchAndDiff(lot.getLotRrn(),entity.getInstanceRrn());
        //msg 在 impl 已经进行国际化处理了
        Assert.isFalse(StringUtils.isNotEmpty(checkInfo),  Errors.create().content(checkInfo).build());

        String checkResult = wipCheckService
                .checkEqptAndRecipeAndReticleAtJobIn(lot, entity.getInstanceRrn(), lot.getRecipeId(),
                                                     LocalContext.getUserRrn());

        Assert.isFalse(StringUtils.isNotBlank(checkResult), Errors.create().content(checkResult).build());

        String pmCounterMsg = "";
        if (LotStatus.WAITING.equals(lot.getLotStatus())) {
            List<Lot> lotsTempForCheckEqpt = new ArrayList<>();
            lotsTempForCheckEqpt.add(lot);
            pmCounterMsg = wipCheckService
                    .validateEqptPMCounterStatus(entity, lot.getRecipeLogicalRrn(), lotsTempForCheckEqpt);
        }

        return pmCounterMsg;
    }

}