OperationSaveAction.java
package com.mycim.webapp.actions.operation;
import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.fa.sesa.i18n.I18nUtils;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.utils.beans.PropertyUtils;
import com.mycim.framework.utils.lang.BooleanUtils;
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.framework.utils.lang.math.NumberUtils;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.bas.ObjectVersion;
import com.mycim.valueobject.consts.SessionNames;
import com.mycim.valueobject.ems.EntityGroup;
import com.mycim.valueobject.prp.Context;
import com.mycim.valueobject.prp.ContextValue;
import com.mycim.valueobject.prp.Operation;
import com.mycim.valueobject.prp.Route;
import com.mycim.valueobject.sys.Field;
import com.mycim.webapp.Constants;
import com.mycim.webapp.WebUtils;
import com.mycim.webapp.actions.PrpSetupAction;
import com.mycim.webapp.forms.OperationInfoForm;
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;
/**
* 步骤SETUP
*
* @author Johnson.Wang
* @version 6.0.0
* @date 2019/8/21
**/
public class OperationSaveAction extends PrpSetupAction {
@Override
public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
OperationInfoForm operationInfoForm = (OperationInfoForm) form;
// debug: 清除operationparaonly标记
String operationReadOnly = WebUtils.getParameter("operationparaonly", request);
if (StringUtils.isNotBlank(operationReadOnly)) {
if (BooleanUtils.toBoolean(operationReadOnly.trim())) {
request.setAttribute("operationparaonly", "Y");
}
}
Operation operation = new Operation(StringUtils.trim(operationInfoForm.getInstanceId()),
getNamedSpace(ObjectList.OPERATION_KEY, LocalContext.getFacilityRrn()),
ObjectList.OPERATION_KEY);
Context context = new Context(Constants.EDCCONTEXT4LOT_KEY,
getNamedSpace(ObjectList.CONTEXT_KEY, LocalContext.getFacilityRrn()),
ObjectList.CONTEXT_KEY);
operation = (Operation) getInstance(operation);
context = (Context) getInstance(context);
Assert.isFalse(StringUtils.isNotEmpty(operation.getSystemUsed()),
Errors.create().key(MessageIdList.STEP_IS_DUMMY).content("step: {} is DUMMY!")
.args(operation != null ? operation.getInstanceId() : "").build());
PropertyUtils.copyProperties(operationInfoForm, operation);
request.setAttribute(SessionNames.OPERATION_KEY, operation);
operationInfoForm.setTransId(Constants.MODIFY_KEY);
if (operation.getInstanceRrn() == 0) {
operationInfoForm.setObjectDeleteEnable("false");
operationInfoForm.setTransId(Constants.CREATE_KEY);
operationInfoForm.setTrackUnitFlag("on");
operationInfoForm.setKeepUnitHistoryFlag("on");
request.setAttribute(SessionNames.CONTEXT_KEY, context);
operationInfoForm.setTransId(Constants.CREATE_KEY);
return (mapping.findForward(Constants.CREATE_KEY));
}
if (!WebUtils.getParameterBoolean("homePage", request)) {
operationInfoForm.setNpwType(operation.getAttribute3());
}
//判断NPW step 和 普通 step 是否对应菜单
if ((StringUtils.isBlank(operation.getAttribute3()) &&
StringUtils.equalsIgnoreCase(operationInfoForm.getNpwType(), Constants.NPW_TYPE)) ||
(StringUtils.isBlank(operationInfoForm.getNpwType()) &&
StringUtils.equalsIgnoreCase(operation.getAttribute3(), Constants.NPW_TYPE))) {
operationInfoForm.setInstanceId("");
request.setAttribute("errorMsgAlert", I18nUtils
.getMessage("step.cant_edit_this_menu", "Step:{} not allowed to edit in this" + " menu" + "! ",
operation.getInstanceId()));
return init(mapping, form, request, response);
}
ContextValue contextValue = new ContextValue();
contextValue.setContextKey9("MOVEOUT");
contextValue.setContextKey1(operationInfoForm.getInstanceId());
contextValue.setContextRrn(context.getInstanceRrn());
List<ObjectVersion> versions = baseService.getObjectVersions(operation);
operation.setVersions(versions);
Map operationExtMap = prpService.getOperationExtInfo(operation.getInstanceRrn());
context.setValues(ctxService.simulateFilterContextValues(contextValue, LocalContext.getFacilityRrn()));
operationInfoForm.setVersionEditEnable(String.valueOf(checkVersionEditEnable(versions)));
operationInfoForm.setObjectDeleteEnable(checkObjectDeleteEnable(versions));
operationInfoForm.setOperationSubType(operation.getObjectSubtype());
operationInfoForm.setReworkFlag(MapUtils.getString(operationExtMap, "REWORK_FLAG"));
operationInfoForm.setDisableFlag(MapUtils.getString(operationExtMap, "Disable_FLAG"));
operationInfoForm.setEdcFlg(MapUtils.getString(operationExtMap, "IS_EDC_FLG"));
operationInfoForm.setEdcCategory(MapUtils.getString(operationExtMap, "edc_category"));
operationInfoForm.setTransId(Constants.MODIFY_KEY);
if (context.getValues().size() > 0) {
String edcId = ((ContextValue) context.getValues().iterator().next()).getResultValue1();
operationInfoForm.setEdcId(edcId);
operation.setEdcId(edcId);
}
EntityGroup entityGroup = exisEntityGroup(operation.getInstanceId());
if (entityGroup.getInstanceRrn() > 0 &&
StringUtils.equals(operationInfoForm.getEntityGroupRrn() + "", entityGroup.getInstanceRrn() + "")) {
operationInfoForm.setReason("1");
} else {
operationInfoForm.setReason("0");
operationInfoForm.setBuildEntityGroupRrn(operationInfoForm.getEntityGroupRrn() + "");
}
request.setAttribute(SessionNames.OPERATION_KEY, operation);
return (mapping.findForward(Constants.MODIFY_KEY));
}
public ActionForward useInfo(ActionMapping mapping, OperationInfoForm form, HttpServletRequest request) {
long operationRrn = this
.getInstanceRrn(form.getInstanceId(), LocalContext.getFacilityRrn(), ObjectList.OPERATION_KEY);
List<Route> routes = prpService.getUsedByRoutes(operationRrn);
if (CollectionUtils.isNotEmpty(routes)) {
List<Map> wflLists = new ArrayList<>();
for (Route route : routes) {
Map<String, Object> wfl = new HashMap<>(10);
wfl.put("routeId", route.getInstanceId());
wfl.put("routeDesc", route.getInstanceDesc());
wfl.put("routeRrn", route.getInstanceRrn());
wfl.put("routeVersion", route.getCurrentVersion());
wflLists.add(wfl);
}
request.setAttribute("wflLists", wflLists);
}
return mapping.findForward("wheretouse");
}
public ActionForward update(ActionMapping mapping, OperationInfoForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
String operationId = form.getInstanceId();
Assert.isFalse(NumberUtils.isCreatable(operationId),
Errors.create().key(MessageIdList.OPERATION_PURE_NUMBER).content("步骤不能为纯数字").build());
String workArea = form.getWorkArea();
Assert.isFalse(StringUtils.isBlank(workArea),
Errors.create().key(MessageIdList.WORKAREA_EMPTY_MESSAGE).content("Workarea empty").build());
String buildEntityGroupId = form.getBuildEntityGroupRrn();
Assert.isFalse(StringUtils.isBlank(buildEntityGroupId),
Errors.create().key(MessageIdList.EQUIPMENTGROUP_EMPTY_ID).content("设备组号不能为空!").build());
String lowYiled = form.getLowYield() + "";
if (StringUtils.isNotBlank(lowYiled)) {
Assert.isTrue((NumberUtils.toDouble(lowYiled, 0.0) >= 0.0 && NumberUtils.toDouble(lowYiled, 0.0) <= 100.0),
Errors.create().key(MessageIdList.LOW_YIELD_MESSAGE)
.content("The Low Yield must be between {} to {}!").args("0", "100").build());
}
Operation operation = new Operation(operationId,
getNamedSpace(ObjectList.OPERATION_KEY, LocalContext.getFacilityRrn()),
ObjectList.OPERATION_KEY);
operation = (Operation) getInstance(operation);
Long buildEntityGroupRrn = this
.getInstanceRrn(buildEntityGroupId.trim(), LocalContext.getFacilityRrn(), ObjectList.ENTITYGROUP_KEY);
Assert.isFalse(buildEntityGroupRrn <= 0,
Errors.create().key(MessageIdList.ENTITYGROUP_INVALID_ID).content("Invalid EQP Grp. ID!")
.build());
form.setEntityGroupRrn(buildEntityGroupRrn);
form.setBuildEntityGroupRrn(String.valueOf(buildEntityGroupRrn));
String instanceStatus = operation.getInstanceStatus();
PropertyUtils.copyProperties(operation, form);
operation.setInstanceStatus(instanceStatus);
operation.setTransId(Constants.MODIFY_KEY);
operation.setTransPerformedby(LocalContext.getUserId());
operation.setEdcCategory(
StringUtils.isNotEmpty(operation.getEdcCategory()) ? operation.getEdcCategory() : StringUtils.EMPTY);
if (StringUtils.isNotEmpty(form.getMvinWflId())) {
operation.setMvinWflRrn(getInstanceRrn(form.getMvinWflId().trim(),
getNamedSpace(ObjectList.WFL_KEY, LocalContext.getFacilityRrn()),
ObjectList.WFL_KEY));
}
if (StringUtils.isNotEmpty(form.getMvouWflId())) {
operation.setMvouWflRrn(getInstanceRrn(form.getMvouWflId().trim(),
getNamedSpace(ObjectList.WFL_KEY, LocalContext.getFacilityRrn()),
ObjectList.WFL_KEY));
}
if (StringUtils.isNotEmpty(form.getWsMvinWflId())) {
operation.setWsMvinWflRrn(getInstanceRrn(form.getWsMvinWflId().trim(),
getNamedSpace(ObjectList.WFL_KEY, LocalContext.getFacilityRrn()),
ObjectList.WFL_KEY));
}
if (StringUtils.isNotEmpty(form.getWsMvouWflId())) {
operation.setWsMvouWflRrn(getInstanceRrn(form.getWsMvouWflId().trim(),
getNamedSpace(ObjectList.WFL_KEY, LocalContext.getFacilityRrn()),
ObjectList.WFL_KEY));
}
if (StringUtils.isNotEmpty(form.getAbortWflId())) {
operation.setAbortWflRrn(getInstanceRrn(form.getAbortWflId().trim(),
getNamedSpace(ObjectList.WFL_KEY, LocalContext.getFacilityRrn()),
ObjectList.WFL_KEY));
}
if (StringUtils.isNotEmpty(form.getExternalReworkWflId())) {
operation.setExternalReworkWflRrn(getInstanceRrn(form.getExternalReworkWflId().trim(),
getNamedSpace(ObjectList.WFL_KEY,
LocalContext.getFacilityRrn()),
ObjectList.WFL_KEY));
}
if (StringUtils.isNotEmpty(form.getMonitorFlag()) &&
StringUtils.equalsIgnoreCase("on", form.getMonitorFlag())) {
operation.setMonitorFlag("1");
}
prpService.updateOperation(operation);
WebUtils.setSuccessMsg(request);
return init(mapping, form, request, response);
}
public ActionForward create(ActionMapping mapping, OperationInfoForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
String operationId = form.getInstanceId();
form.setKeepUnitHistoryFlag(FALSE);//不再往unit_history表插入数据
Assert.isFalse(StringUtils.isBlank(operationId),
Errors.create().key(MessageIdList.OPERATION_EMPTY_NUMBER).content("步骤号不能为空!").build());
Assert.isFalse(NumberUtils.isCreatable(operationId),
Errors.create().key(MessageIdList.OPERATION_PURE_NUMBER).content("步骤号不能为纯数字!").build());
String workArea = form.getWorkArea();
Assert.isFalse(StringUtils.isBlank(workArea),
Errors.create().key(MessageIdList.WORKAREA_EMPTY_MESSAGE).content("工作区域不能为空!").build());
String buildEntityGroupId = form.getBuildEntityGroupRrn();
Assert.isFalse(StringUtils.isBlank(buildEntityGroupId),
Errors.create().key(MessageIdList.EQUIPMENTGROUP_EMPTY_ID).content("设备组号不能为空!").build());
String lowYiled = form.getLowYield() + "";
if (StringUtils.isNotBlank(lowYiled)) {
Assert.isTrue((NumberUtils.toDouble(lowYiled, 0.0) >= 0.0 && NumberUtils.toDouble(lowYiled, 0.0) <= 100.0),
Errors.create().key(MessageIdList.LOW_YIELD_MESSAGE)
.content("The Low Yield must be between {} to {}!").args("0", "100").build());
}
Operation operation = new Operation(form.getInstanceId(),
getNamedSpace(ObjectList.OPERATION_KEY, LocalContext.getFacilityRrn()),
ObjectList.OPERATION_KEY);
Long buildEntityGroupRrn = this
.getInstanceRrn(buildEntityGroupId.trim(), LocalContext.getFacilityRrn(), ObjectList.ENTITYGROUP_KEY);
Assert.isFalse(buildEntityGroupRrn <= 0,
Errors.create().key(MessageIdList.ENTITYGROUP_INVALID_ID).content("Invalid EQP Grp. ID!")
.build());
form.setEntityGroupRrn(buildEntityGroupRrn);
form.setBuildEntityGroupRrn(String.valueOf(buildEntityGroupRrn));
PropertyUtils.copyProperties(operation, form);
operation.setAttribute3(form.getNpwType());
operation.setTransId(Constants.CREATE_KEY);
operation.setTransPerformedby(LocalContext.getUserId());
operation.setRecipeId(form.getRecipeId());
operation.setEdcCategory(
StringUtils.isNotEmpty(operation.getEdcCategory()) ? operation.getEdcCategory() : StringUtils.EMPTY);
if (StringUtils.isNotEmpty(form.getMvinWflId())) {
operation.setMvinWflRrn(getInstanceRrn(form.getMvinWflId().trim(),
getNamedSpace(ObjectList.WFL_KEY, LocalContext.getFacilityRrn()),
ObjectList.WFL_KEY));
}
if (StringUtils.isNotEmpty(form.getMvouWflId())) {
operation.setMvouWflRrn(getInstanceRrn(form.getMvouWflId().trim(),
getNamedSpace(ObjectList.WFL_KEY, LocalContext.getFacilityRrn()),
ObjectList.WFL_KEY));
}
if (StringUtils.isNotEmpty(form.getWsMvinWflId())) {
operation.setWsMvinWflRrn(getInstanceRrn(form.getWsMvinWflId().trim(),
getNamedSpace(ObjectList.WFL_KEY, LocalContext.getFacilityRrn()),
ObjectList.WFL_KEY));
}
if (StringUtils.isNotEmpty(form.getWsMvouWflId())) {
operation.setWsMvouWflRrn(getInstanceRrn(form.getWsMvouWflId().trim(),
getNamedSpace(ObjectList.WFL_KEY, LocalContext.getFacilityRrn()),
ObjectList.WFL_KEY));
}
if (StringUtils.isNotEmpty(form.getAbortWflId())) {
operation.setAbortWflRrn(getInstanceRrn(form.getAbortWflId().trim(),
getNamedSpace(ObjectList.WFL_KEY, LocalContext.getFacilityRrn()),
ObjectList.WFL_KEY));
}
if (StringUtils.isNotEmpty(form.getExternalReworkWflId())) {
operation.setExternalReworkWflRrn(getInstanceRrn(form.getExternalReworkWflId().trim(),
getNamedSpace(ObjectList.WFL_KEY,
LocalContext.getFacilityRrn()),
ObjectList.WFL_KEY));
}
if (StringUtils.isNotEmpty(form.getMonitorFlag()) &&
StringUtils.equalsIgnoreCase("on", form.getMonitorFlag())) {
operation.setMonitorFlag("1");
}
long operationRrn = prpService.insertOperation(operation);
setDefaultAttributes(operationRrn);
WebUtils.setSuccessMsg(request);
return init(mapping, form, request, response);
}
public ActionForward copy(ActionMapping mapping, OperationInfoForm form,
HttpServletRequest request) throws Exception {
// the new Id is stored in the url COPY key
String id = request.getParameter(Constants.COPY_KEY);
Operation copyOperation = new Operation(id,
getNamedSpace(ObjectList.OPERATION_KEY, LocalContext.getFacilityRrn()),
ObjectList.OPERATION_KEY);
doCopy(form, copyOperation);
form.setBuildEntityGroupRrn(String.valueOf(form.getEntityGroupRrn()));
// for logic equal tag, copy is the same action as create
form.setTransId(Constants.CREATE_KEY);
return (mapping.findForward(Constants.MODIFY_KEY));
}
public ActionForward delete(ActionMapping mapping, OperationInfoForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
String operationId = form.getInstanceId();
// add by Bright for chint 添加步骤删除的判断,如果步骤正被使用,不允许删除
long operationRrn = 0;
if (StringUtils.isNotEmpty(operationId)) {
operationId = operationId.trim().toUpperCase();
operationRrn = this.getInstanceRrn(operationId, LocalContext.getFacilityRrn(), "OPERATION");
}
Assert.isFalse(operationRrn < 1,
Errors.create().key(MessageIdList.OPERATION_INVALID_ID).content("Invalid step id!").build());
Assert.isFalse(prpService.isOperationUsing(operationRrn),
Errors.create().key(MessageIdList.OPERATION_BEING_USED)
.content("This step is being used by the" + " " + "process and cannot be " + "deleted!")
.build());
//check step是否被Route ID引用,如果引用则不能删除
List<Route> usedByRoutes = prpService.getUsedByRoutes(operationRrn);
Assert.isFalse(CollectionUtils.isNotEmpty(usedByRoutes),
Errors.create().key(MessageIdList.OPERATION_USED_BY_SUBPLAN)
.content("This step is being used by the " + "Sub Plan and cannot be " + "deleted!")
.build());
Operation operation = new Operation(operationId,
getNamedSpace(ObjectList.OPERATION_KEY, LocalContext.getFacilityRrn()),
ObjectList.OPERATION_KEY);
operation.setInstanceRrn(operationRrn);
operation = (Operation) getInstance(operation);
// #26315 有储存标记的库房步骤不能删除
Assert.isFalse(StringUtils.isNotBlank(operation.getStoreFlag()) && "on".equals(operation.getStoreFlag()),
Errors.create().key(MessageIdList.OPERATION_INVALID_STOREFLAG)
.content("Store flag step cannot be deleted!").build());
operation.setTransId(Constants.DELETE_KEY);
operation.setTransPerformedby(LocalContext.getUserId());
process(operation);
form.setInstanceId("");
OperationInfoForm deleteForm = new OperationInfoForm();
deleteForm.setNpwType(form.getNpwType());
deleteForm.setTransId(Constants.CREATE_KEY);
request.setAttribute("operationInfoForm", deleteForm);
WebUtils.setSuccessMsg(request);
return init(mapping, form, request, response);
}
/**
* 创建operation 的同时,添加属性字段的默认值
*/
public void setDefaultAttributes(long operationRrn) {
List<Map> attributes = sysService
.getAllAttributes(operationRrn, getNamedSpace(ObjectList.OPERATION_KEY, LocalContext.getFacilityRrn()),
ObjectList.OPERATION_KEY, I18nUtils.getCurrentLanguage());
Field field = new Field("FLD_CHECK_USER", getNamedSpace(ObjectList.FIELD_KEY, LocalContext.getFacilityRrn()),
ObjectList.FIELD_KEY);
field = sysService.getField(field);
List<Map> objectAttributeValues = new ArrayList<>();
for (Map attribute : attributes) {
long fieldRrn = MapUtils.getLongValue(attribute, "FIELD_RRN", 0L);
Map<String, Object> attributeValues = new HashMap<>(4);
attributeValues.put("instanceRrn", operationRrn + "");
attributeValues.put("instanceVersion", "1");
attributeValues.put("fieldRrn", fieldRrn + "");
if (fieldRrn == field.getInstanceRrn()) {
attributeValues.put("attributeValue", field.getDefaultValue() + "");
} else {
attributeValues.put("attributeValue", "");
}
objectAttributeValues.add(attributeValues);
}
sysService.maintainAttribute(objectAttributeValues);
}
}