LotUnitInfoAction.java
package com.mycim.webapp.actions.unit;
import com.fa.sesa.i18n.I18nUtils;
import com.mycim.framework.utils.beans.BeanUtils;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.framework.utils.lang.time.DateUtils;
import com.mycim.valueobject.ems.Carrier;
import com.mycim.valueobject.wip.Lot;
import com.mycim.valueobject.wip.Unit;
import com.mycim.webapp.TemplateLocation;
import com.mycim.webapp.WebUtils;
import com.mycim.webapp.actions.WipSetupAction;
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 sandy
* @version 6.0.0
* @date 2019/9/21
**/
public class LotUnitInfoAction extends WipSetupAction {
@Override
public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
Long lotRrn = WebUtils.getParameterLong("lotRrn", request);
Lot lot = lotQueryService.getLot(lotRrn);
List<Unit> unitList = buildLotUnit(lot);
request.setAttribute("unitList", unitList);
request.setAttribute("lot", lot);
return mapping.getInputForward();
}
public ActionForward export(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
String language = I18nUtils.getCurrentLanguage().toString();
Long lotRrn = WebUtils.getParameterLong("lotRrn", request);
Lot lot = lotQueryService.getLot(lotRrn);
List unitList = buildLotUnit(lot);
List<Map> unitListMap = new ArrayList<Map>();
for (int i = 0; i < unitList.size(); i++) {
Unit unit = (Unit) unitList.get(i);
Map map = BeanUtils.copyBeanToMap(unit);
map.put("seq", i + 1);
unitListMap.add(map);
}
Map<String, Object> titles = WebUtils.getExportTitles(request);
if (StringUtils.equalsIgnoreCase("CN", language)) {
titles.put("seq", "序号");
titles.put("lotUnitInfo", "批次晶圆片信息");
} else {
titles.put("seq", "seq");
titles.put("lotUnitInfo", "Lot Unit Info");
}
// 导出
String exportDateTime = DateUtils.getNowTime(DateUtils.DATE_FORMAT4NOSPLICING);
String fileName = "LotUnitInfo_" + exportDateTime + ".xlsx";
WebUtils.exportExcel(fileName, titles, unitListMap, TemplateLocation.LOT_UNIT_INFO, response);
return WebUtils.NULLActionForward;
}
public ActionForward lotUnit4Choose(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
Long lotRrn = WebUtils.getParameterLong("lotRrn", request);
Integer seq = WebUtils.getParameterInt("seq", request);
Lot lot = lotQueryService.getLot(lotRrn);
List<Unit> unitList = buildLotUnit(lot);
request.setAttribute("unitList", unitList);
request.setAttribute("lot", lot);
request.setAttribute("seq", seq);
return mapping.findForward("lotUnit4Choose");
}
private List<Unit> buildLotUnit(Lot lot) throws Exception {
//todo
// LotRunCardStore runcardStore = lotQueryService.getSplitRunCardLotStore(lot.getLotRrn());
// if (runcardStore != null) {
// if (StringUtils.equalsIgnoreCase(SplitRunCardConstants.STATUS_BANK_OUT,
// runcardStore.getSubStatus())) {
// unitList = wipQueryService.getRCStoreUnits(lot.getLotRrn());
// } else {
// unitList = wipQueryService.getUnitList(lot.getLotRrn());
// for (Unit unit : unitList) {
// if (StringUtils.startsWith(unit.getUnitId(), "RC-")) {
// unit.setUnitId(StringUtils.substring(unit.getUnitId(), 3));
// }
// }
// }
// } else {
// unitList = wipQueryService.getUnitList(lot.getLotRrn());
// }
List<Unit> unitList = wipQueryService.getUnitList(lot.getLotRrn());
Collections.sort(unitList, new Comparator<Unit>() {
@Override
public int compare(Unit o1, Unit o2) {
return o1.getPositionInCarrier() - o2.getPositionInCarrier();
}
});
Carrier carrier = carrierService.getCarrier(lot.getCarrierRrn());
int tmp = 0;
List<Unit> tmpList = new ArrayList<Unit>();
for (Iterator it = unitList.iterator(); it.hasNext(); ) {
tmp++;
Unit unit = (Unit) it.next();
Integer position = unit.getPositionInCarrier();
int diff = position - tmp;
diff = diff < 0 ? tmp - position : diff;
for (int m = 0; m < diff; m++) {
tmp++;
tmpList.add(new Unit());
}
tmpList.add(unit);
}
int maxPosition = 25;
if (carrier != null && carrier.getSlotCount() != null && carrier.getSlotCount() > 0) {
maxPosition = carrier.getSlotCount().intValue();
}
int diff = maxPosition - tmpList.size();
for (int m = 0; m < diff; m++) {
tmpList.add(new Unit());
}
return tmpList;
}
}