AutoSkipStepByLotSamplingAction.java
package com.mycim.webapp.actions.lot.lotsampling;
import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.utils.beans.BeanUtils;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.framework.utils.lang.collections.CollectionUtils;
import com.mycim.framework.utils.lang.math.NumberUtils;
import com.mycim.valueobject.consts.SessionNames;
import com.mycim.valueobject.security.User;
import com.mycim.valueobject.wip.Lot;
import com.mycim.webapp.actions.WipSetupAction;
import com.mycim.webapp.forms.AutoSkipStepByForm;
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.*;
/**
* @author can.yang
* @date 2021/6/22
*/
public class AutoSkipStepByLotSamplingAction extends WipSetupAction {
public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
String user = LocalContext.getUserId();
Long userRrn = LocalContext.getUserRrn();
Long facilityRrn = LocalContext.getFacilityRrn();
User currentUser = new User();
if ((user == null) || (facilityRrn == null)) {
return mapping.findForward("login");
} else {
currentUser.setInstanceRrn(userRrn.longValue());
currentUser.setInstanceId(user);
}
if (form == null) {
form = new AutoSkipStepByForm();
request.setAttribute(mapping.getAttribute(), form);
}
HashMap parameters = (HashMap) request.getAttribute(SessionNames.PARAMETERSINFO_KEY);
Assert.isFalse((parameters == null),
Errors.create().content("Parameters are not enough!").build());
Collection mapLots = (Collection) request.getAttribute(SessionNames.PROCESS_NEXT_STEP_INFO_KEY);
Assert.isFalse(CollectionUtils.isEmpty(mapLots), Errors.create()
.content("Parameters are not enough!").build());
List<String> lotRrns=new ArrayList<>();
List<Lot> lots = new ArrayList<>();
for (Object mapLot : mapLots) {
Lot lot = new Lot();
BeanUtils.copyMapToBean(lot, (Map) mapLot);
lotRrns.add(StringUtils.toString(lot.getLotRrn()));
lots.add(lot);
}
if (CollectionUtils.isNotEmpty(lotRrns)) {
lotSamplingService.autoSkipStepByLotSampling(lots, currentUser, lotRrns);
}
parameters.put(SessionNames.RUNSTEP_FLAG, StringUtils.toString(NumberUtils.INTEGER_ZERO));
request.getRequestDispatcher(mapping.findForward("workflow").getPath()).forward(request,response);
return null;
}
}