WetBatchSetupAction.java
package com.mycim.webapp.actions.wetBatch;
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.CollectionUtils;
import com.mycim.framework.utils.lang.collections.MapUtils;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.SystemConstant;
import com.mycim.valueobject.prp.ProcessPlanning;
import com.mycim.valueobject.prp.ProcessVersion;
import com.mycim.valueobject.prp.ProductSpecInfo;
import com.mycim.valueobject.wetbatch.WetBatchBean;
import com.mycim.valueobject.wetbatch.dto.WetBatchQueryDto;
import com.mycim.webapp.Constants;
import com.mycim.webapp.WebUtils;
import com.mycim.webapp.actions.wetBatch.form.WetBatchForm;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Author: yibing.liu
* @Date: 2021/12/31 17:14
*/
public class WetBatchSetupAction extends WetBatchAction {
@Override
public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
WetBatchForm theForm = getForm(form);
if (request.getParameter("appendSetup") != null){
clearFormSearch(theForm);
theForm.setAppendSetup(SystemConstant.Str.ONE);
}
if (StringUtils.isNotBlank(theForm.getSearchPreEquipmentGroupId()) && StringUtils.isNotBlank(theForm.getSearchPreRecipeId())
&& StringUtils.isNotBlank(theForm.getSearchPostEquipmentGroupId()) && StringUtils.isNotBlank(theForm.getSearchPostRecipeId()) ){
return query(mapping, form, request);
}
return mapping.getInputForward();
}
public ActionForward query(ActionMapping mapping, ActionForm form, HttpServletRequest request) {
WetBatchForm theForm = getForm(form);
WetBatchQueryDto wetBatchQueryDto = new WetBatchQueryDto();
List<WetBatchBean> wetBatchBeanList = new ArrayList<>();
if (StringUtils.isNotBlank(theForm.getSearchPreEquipmentGroupId()) && StringUtils.isNotBlank(theForm.getSearchPreRecipeId())
&& StringUtils.isNotBlank(theForm.getSearchPostEquipmentGroupId()) && StringUtils.isNotBlank(theForm.getSearchPostRecipeId()) ){
Assert.isFalse(wetBatchQueryDto.setPreEquipmentGroupId(theForm.getSearchPreEquipmentGroupId()),
Errors.create().key(MessageIdList.CAN_NOT_EMPTY).content("{} cannot be empty!").args("Pre EqpGroup ID").build());
Assert.isFalse(wetBatchQueryDto.setPreRecipeId(theForm.getSearchPreRecipeId()),
Errors.create().key(MessageIdList.CAN_NOT_EMPTY).content("{} cannot be empty!").args("Pre Recipe ID").build());
Assert.isFalse(wetBatchQueryDto.setPostEquipmentGroupId(theForm.getSearchPostEquipmentGroupId()),
Errors.create().key(MessageIdList.CAN_NOT_EMPTY).content("{} cannot be empty!").args("Post EQPGroup ID").build());
Assert.isFalse(wetBatchQueryDto.setPostRecipeId(theForm.getSearchPostRecipeId()),
Errors.create().key(MessageIdList.CAN_NOT_EMPTY).content("{} cannot be empty!").args("Post Recipe ID").build());
wetBatchBeanList = wetBatchQueryService.queryItemProdList(wetBatchQueryDto);
}
request.setAttribute("wetBatchList", wetBatchBeanList);
return mapping.findForward(Constants.VIEW_KEY);
}
public ActionForward addItem(ActionMapping mapping, ActionForm form, HttpServletRequest request) {
WetBatchForm theForm = getForm(form);
WetBatchQueryDto wetBatchQueryDto = new WetBatchQueryDto();
Assert.isFalse(wetBatchQueryDto.setProductId(theForm.getProductId()),
Errors.create().key(MessageIdList.CAN_NOT_EMPTY).content("{} cannot be empty!").args("Product ID").build());
buildParams(wetBatchQueryDto, theForm);
if (StringUtils.isNotBlank(theForm.getSearchPostEquipmentGroupId())
&& StringUtils.isNotBlank(theForm.getSearchPostRecipeId())
&& StringUtils.isNotBlank(theForm.getSearchPreEquipmentGroupId())
&& StringUtils.isNotBlank(theForm.getSearchPreRecipeId())){
Assert.isFalse(!StringUtils.equalsIgnoreCase(theForm.getSearchPostEquipmentGroupId(), wetBatchQueryDto.getPostEquipmentGroupId())
|| !StringUtils.equalsIgnoreCase(theForm.getSearchPostRecipeId(), wetBatchQueryDto.getPostRecipeId())
|| !StringUtils.equalsIgnoreCase(theForm.getSearchPreEquipmentGroupId(), wetBatchQueryDto.getPreEquipmentGroupId())
|| !StringUtils.equalsIgnoreCase(theForm.getSearchPreRecipeId(), wetBatchQueryDto.getPreRecipeId()),
Errors.create().key(MessageIdList.NOT_BELONG_GROUP).content("Does not belong to a group of current query conditions!").build());
}
List<WetBatchBean> wetBatchBeanList = wetBatchQueryService.queryItemProdList(wetBatchQueryDto);
Assert.isFalse(CollectionUtils.isNotEmpty(wetBatchBeanList),
Errors.create().key(MessageIdList.HAS_EXIST).content("Has Exist!").build());
wetBatchQueryDto.setPreFlowSeq(theForm.getPreFlowSeq());
wetBatchQueryDto.setPreStageId(theForm.getPreStageId());
wetBatchQueryDto.setPreStepDesc(theForm.getPreOperationDesc());
wetBatchQueryDto.setPostFlowSeq(theForm.getPostFlowSeq());
wetBatchQueryDto.setPostStageId(theForm.getPostStageId());
wetBatchQueryDto.setPostStepDesc(theForm.getPostOperationDesc());
wetBatchService.addItemProd(wetBatchQueryDto);
clearFormParam(theForm);
WebUtils.setSuccessMsg(request);
return query(mapping, form, request);
}
public ActionForward deleteItem(ActionMapping mapping, ActionForm form, HttpServletRequest request) {
WetBatchForm theForm = getForm(form);
WetBatchQueryDto wetBatchQueryDto = new WetBatchQueryDto();
Assert.isFalse(wetBatchQueryDto.setWetBatchItemRrn(theForm.getWetBatchItemRrn()),
Errors.create().key(MessageIdList.CAN_NOT_EMPTY).content("{} cannot be empty!").args("Wet Batch Item Rrn").build());
wetBatchService.deleteItemProd(wetBatchQueryDto);
return query(mapping, form, request);
}
public Map<String, Object> getProcessByProduct(Map map) {
long facilityRrn = LocalContext.getFacilityRrn();
String productId = StringUtils.trimToUpperCase(MapUtils.getString(map, "productId"));
Assert.isFalse(StringUtils.isBlank(productId),
Errors.create().key(MessageIdList.PRODUCT_ID_CANNOT_EMPTY).content("Product ID cannot be empty!").build());
long productRrn = getInstanceRrn(productId, getNamedSpace(ObjectList.PRODUCT_KEY, facilityRrn), ObjectList.PRODUCT_KEY);
Assert.isFalse(productRrn <= 0,
Errors.create().key(MessageIdList.PRODUCT_PRODUCT_MISSING).content("产品不存在!").build());
Map<String, Object> result = new HashMap<>();
List<String> processIds = prpService.getProcessIdsByProductRrn(productRrn);
for (String processId : processIds) {
result.put("processId", processId);
ProcessPlanning processPlanning = new ProcessPlanning(processId, getNamedSpace(ObjectList.WFL_KEY,facilityRrn), ObjectList.WFL_KEY);
processPlanning = prpService.getProcessPlanning(processPlanning);
ProductSpecInfo productSpecInfo = specService
.getLatestActivatedProductSpecItemInfo(productRrn, processPlanning.getInstanceRrn());
result.put("processVer", productSpecInfo.getProcessVersion());
}
return result;
}
private void buildParams(WetBatchQueryDto wetBatchQueryDto, WetBatchForm theForm) {
Assert.isFalse(wetBatchQueryDto.setPreEquipmentGroupId(theForm.getPreEqptGroupId()),
Errors.create().key(MessageIdList.CAN_NOT_EMPTY).content("{} cannot be empty!").args("Pre EqpGroup ID").build());
Assert.isFalse(wetBatchQueryDto.setPreRecipeId(theForm.getPreRecipeId()),
Errors.create().key(MessageIdList.CAN_NOT_EMPTY).content("{} cannot be empty!").args("Pre Recipe ID").build());
Assert.isFalse(wetBatchQueryDto.setPostEquipmentGroupId(theForm.getPostEqptGroupId()),
Errors.create().key(MessageIdList.CAN_NOT_EMPTY).content("{} cannot be empty!").args("Post EQPGroup ID").build());
Assert.isFalse(wetBatchQueryDto.setPostRecipeId(theForm.getPostRecipeId()),
Errors.create().key(MessageIdList.CAN_NOT_EMPTY).content("{} cannot be empty!").args("Post Recipe ID").build());
}
}