CompletedssLotHistoryAction.java
package com.mycim.webapp.actions.lot.completedsslothistory;
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.lang.StringUtils;
import com.mycim.framework.utils.lang.collections.MapUtils;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.consts.CompletedssConstants;
import com.mycim.valueobject.consts.SessionNames;
import com.mycim.valueobject.wip.Lot;
import com.mycim.webapp.actions.WipSetupAction;
import com.mycim.webapp.forms.lot.CompletedssLotHistoryForm;
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.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author sandy
* @date 2019.09.23
* @description 完成品批次 操作查询
*/
public class CompletedssLotHistoryAction extends WipSetupAction {
@Override
public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
return mapping.findForward("previousPage");
}
public ActionForward search(CompletedssLotHistoryForm theForm, ActionMapping mapping, HttpServletRequest request,
HttpServletResponse response) throws Exception {
Integer thisPage = 1;
theForm.setThisPage(thisPage);
theForm.setPageSize(20);// 设置每页显示条数
Integer pageSize = theForm.getPageSize();
String lotId = theForm.getLotId();
String productId = theForm.getProductId();
String processId = theForm.getProcessId();
Long productRrn = null;
Long lotRrn = null;
Long processRrn = null;
if (StringUtils.isNotBlank(productId)) {
productRrn = getInstanceRrn(productId.trim().toUpperCase(), LocalContext.getFacilityRrn(),
ObjectList.PRODUCT_KEY);
Assert.isFalse(productRrn == null || 0 == productRrn,
Errors.create().key(MessageIdList.PRODUCT_PRODUCT_MISSING).content("产品不存在!").build());
theForm.setProductRrn(productRrn);
}
if (StringUtils.isNotBlank(processId)) {
processRrn = getInstanceRrn(processId.trim().toUpperCase(), LocalContext.getFacilityRrn(),
ObjectList.WFL_KEY);
Assert.isFalse(processRrn == null || 0 == processRrn,
Errors.create().key(MessageIdList.PROCESS_PROCESS_MISSING).content("流程不存在!").build());
theForm.setProcessRrn(processRrn);
}
if (StringUtils.isNotBlank(lotId)) {
Lot lot = lotQueryService.getLot(StringUtils.trimToUpperCase(lotId), LocalContext.getFacilityRrn());
Assert.isFalse(lot.equals(new Lot()),
Errors.create().key(MessageIdList.LOT_MISSING_ID).content("No such lotId!").build());
lotRrn = lot.getLotRrn();
theForm.setLotRrn(lotRrn);
}
Integer start = 1;
Integer end = pageSize;
Map<String, Object> condtion = new HashMap<String, Object>();
condtion.put("productRrn", productRrn);
condtion.put("lotRrn", lotRrn);
condtion.put("operationType", theForm.getOperationType());
condtion.put("processRrn", processRrn);
condtion.put("start", start);
condtion.put("end", end);
condtion.put(SessionNames.LANGUAGE_KEY, I18nUtils.getCurrentLanguage());
List<Map<String, Object>> completedssLotHistory = lotService.queryCompletedssLotHistory(condtion);
for (Map<String, Object> map : completedssLotHistory) {// 处理详情
buildNewCompletedssLotHistory(condtion, map);
}
Integer count = lotService.countCompletedssLotHistory(condtion);
Integer lastPageSize = count % pageSize;
Integer maxPage = 0;
if (lastPageSize == 0) {
maxPage = count / pageSize;
} else {
maxPage = count / pageSize + 1;
}
theForm.setLastPageSize(lastPageSize);
theForm.setMaxPage(maxPage);
request.setAttribute("completedssLotHistory", completedssLotHistory);
return mapping.findForward("result");
}
public ActionForward changePage(CompletedssLotHistoryForm theform, ActionMapping mapping,
HttpServletRequest request, HttpServletResponse response) throws Exception {
Integer pageSize = 20;
Integer thisPage = theform.getThisPage();
Long lotRrn = theform.getLotRrn();
Long productRrn = theform.getProductRrn();
Long processRrn = theform.getProcessRrn();
String operationType = theform.getOperationType();
Integer start = (thisPage - 1) * pageSize + 1;
Integer end = thisPage * pageSize;
Map<String, Object> condtion = new HashMap<String, Object>();
condtion.put("operationType", operationType);
condtion.put("productRrn", productRrn);
condtion.put("processRrn", processRrn);
condtion.put("lotRrn", lotRrn);
condtion.put("start", start);
condtion.put("end", end);
List<Map<String, Object>> completedssLotHistory = lotService.queryCompletedssLotHistory(condtion);
for (Map<String, Object> map : completedssLotHistory) {// 处理详情
buildNewCompletedssLotHistory(condtion, map);
}
request.setAttribute("completedssLotHistory", completedssLotHistory);
return mapping.findForward("result");
}
private void buildNewCompletedssLotHistory(Map<String, Object> condtion, Map<String, Object> map) {
String operationDetails = MapUtils.getString(map, "operationDetails");
String[] detailArry = {};
if (StringUtils.isNotBlank(operationDetails)) {
detailArry = operationDetails.split("\\|");
map.put("detailArry", detailArry);
} else {
map.put("detailArry", detailArry);
}
String transId = MapUtils.getString(map, "operationType");
if (CompletedssConstants.COMPLETEDSS_CANCLE_FREEZE.equalsIgnoreCase(transId)) {
if (StringUtils.equalsIgnoreCase("CN", MapUtils.getString(condtion, "language"))) {
map.put("operationType", "解冻");
} else {
map.put("operationType", "Cancle Freeze");
}
} else if (CompletedssConstants.COMPLETEDSS_CANCLE_SCRAP.equalsIgnoreCase(transId)) {
if (StringUtils.equalsIgnoreCase("CN", MapUtils.getString(condtion, "language"))) {
map.put("operationType", "取消报废");
} else {
map.put("operationType", "Cancle Scrap");
}
} else if (CompletedssConstants.COMPLETEDSS_CANCLE_SHIP.equalsIgnoreCase(transId)) {
if (StringUtils.equalsIgnoreCase("CN", MapUtils.getString(condtion, "language"))) {
map.put("operationType", "退货");
} else {
map.put("operationType", "Cancle Ship");
}
} else if (CompletedssConstants.COMPLETEDSS_FREEZE.equalsIgnoreCase(transId)) {
if (StringUtils.equalsIgnoreCase("CN", MapUtils.getString(condtion, "language"))) {
map.put("operationType", "冻结");
} else {
map.put("operationType", "Freeze");
}
} else if (CompletedssConstants.COMPLETEDSS_SCRAP.equalsIgnoreCase(transId)) {
if (StringUtils.equalsIgnoreCase("CN", MapUtils.getString(condtion, "language"))) {
map.put("operationType", "报废");
} else {
map.put("operationType", "Scrap");
}
} else if (CompletedssConstants.COMPLETEDSS_SPILT_PACKAGE.equalsIgnoreCase(transId)) {
if (StringUtils.equalsIgnoreCase("CN", MapUtils.getString(condtion, "language"))) {
map.put("operationType", "拆包");
} else {
map.put("operationType", "Spilt Package");
}
} else if (CompletedssConstants.COMPLETEDSS_PACKAGE.equalsIgnoreCase(transId)) {
if (StringUtils.equalsIgnoreCase("CN", MapUtils.getString(condtion, "language"))) {
map.put("operationType", "包装");
} else {
map.put("operationType", "Package");
}
} else if (CompletedssConstants.COMPLETEDSS_SHIP.equalsIgnoreCase(transId)) {
if (StringUtils.equalsIgnoreCase("CN", MapUtils.getString(condtion, "language"))) {
map.put("operationType", "出货");
} else {
map.put("operationType", "Shipment");
}
} else if (CompletedssConstants.COMPLETEDSS_DIVIDE_BOX.equalsIgnoreCase(transId)) {
if (StringUtils.equalsIgnoreCase("CN", MapUtils.getString(condtion, "language"))) {
map.put("operationType", "分盒");
} else {
map.put("operationType", "Divide Box");
}
} else if (CompletedssConstants.COMPLETEDSS_IN.equalsIgnoreCase(transId)) {
if (StringUtils.equalsIgnoreCase("CN", MapUtils.getString(condtion, "language"))) {
map.put("operationType", "入库");
} else {
map.put("operationType", "In Storage");
}
} else if (CompletedssConstants.COMPLETEDSS_RETURN.equalsIgnoreCase(transId)) {
if (StringUtils.equalsIgnoreCase("CN", MapUtils.getString(condtion, "language"))) {
map.put("operationType", "返线");
} else {
map.put("operationType", "Return Line");
}
}
map.put("productId", getInstanceId(MapUtils.getLong(map, "productRrn")));
map.put("processId", getInstanceId(MapUtils.getLong(map, "processRrn")));
}
}