ViewEdcValueOfLotHistoryAction.java

package com.mycim.webapp.actions.dmmedcvalue;

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.MapUtils;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.wip.Lot;
import com.mycim.valueobject.wip.Unit;
import com.mycim.webapp.actions.NpwSetupAction;
import com.mycim.webapp.forms.LotInfoFormNpw;
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;

public class ViewEdcValueOfLotHistoryAction extends NpwSetupAction {

    @Override
    public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        LotInfoFormNpw theform = (LotInfoFormNpw) form;
        return mapping.findForward("npwlothistorypage");
    }

    public Map query4npw(LotInfoFormNpw theform, HttpServletRequest request, HttpServletResponse response) {
        Long facility = LocalContext.getFacilityRrn();
        String unitId = theform.getUnitId();
        String carrierId = theform.getCarrierId();
        String lotId = theform.getLotId();
        String eqptId = theform.getEqptId();
        String startTime = theform.getStartTime();
        String endTime = theform.getEndTime();
        Long lotRrn = null;
        Long unitRrn = null;

        Map condition = new HashMap();

        // 如果晶圆号不为空,则先根据晶圆号查询
        if (StringUtils.isNotEmpty(unitId)) {
            Unit unit = wipQueryService.getUnit(facility, unitId);
            Assert.notNull(unit, Errors.create().key(MessageIdList.UNIT_MISSING_ID).content("No such unitId!").build());
            condition.put("unitRrn", unit.getUnitRrn());
            condition.put("unitId", unitId);
        }
        if (StringUtils.isNotEmpty(carrierId)) {
            Long carrierRrn = getInstanceRrn(carrierId, facility, ObjectList.ENTITY_KEY);
            Assert.isFalse(carrierRrn <= 0, Errors.create().key(MessageIdList.CARRIER_CASSETTE_ID_MISSING)
                                                  .content("No such Cassette ID!").build());
            condition.put("carrierId", carrierId);
            condition.put("carrierRrn", carrierRrn);
        }
        if (StringUtils.isNotBlank(lotId)) {
            Lot lot = lotQueryService.getLot(lotId);
            lotId = lot.getLotId();
            lotRrn = lot.getLotRrn();
            Assert.isFalse(lotRrn <= 0,
                           Errors.create().key(MessageIdList.LOT_MISSING_ID).content("No such lotId").build());
            condition.put("lotId", lotId);
            condition.put("lotRrn", lotRrn);
        }
        if (StringUtils.isNotBlank(eqptId)) {
            long eqptRrn = getInstanceRrn(eqptId, getNamedSpace(ObjectList.ENTITY_KEY, facility), ObjectList.ENTITY_KEY,
                                          ObjectList.EQUIPMENT_KEY);
            Assert.isFalse(eqptRrn <= 0, Errors.create().key(MessageIdList.EQUIPMENT_ID_NOT_EXIST)
                                               .content("Equipment ID does not exist!").build());
            condition.put("eqptId", eqptId);
            condition.put("eqptRrn", eqptRrn);

        }
        if (StringUtils.isNotBlank(startTime)) {
            condition.put("startTime", startTime);
        }
        if (StringUtils.isNotBlank(endTime)) {
            condition.put("endTime", endTime);
        }

        List edcHistory = new ArrayList();
            /*if (StringUtils.isNotBlank(lotId) || StringUtils.isNotBlank(request.getParameter("eqptId"))) {
                List furanceEdc = dmmService.getDmmEdcSpcForMainEqpt(condition);
                edcHistory.addAll(furanceEdc);
            }*/

        List edcReHistory = dmmService.getDmmEdcHistory(condition);
        edcHistory.addAll(edcReHistory);

        List resultArray = new ArrayList();
        for (Object obj : edcHistory) {
            Map map = (Map) obj;
            List _list = (List) MapUtils.getObject(map, "list");
            if (_list != null) {
                map.put("size", _list.size());
                map.put("list", _list);
            }
            resultArray.add(map);
        }
        Map rteturnResult = new HashMap();

        rteturnResult.put("results", resultArray);
        rteturnResult.put("success", "true");

        return rteturnResult;
    }

}