LotPortalAction.java

package com.mycim.webapp.actions.lot.lotportal;

import com.fa.sesa.exception.Errors;
import com.fa.sesa.exception.SystemIllegalArgumentException;
import com.fa.sesa.i18n.I18nUtils;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.logging.Logger;
import com.mycim.framework.logging.LoggerFactory;
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.framework.utils.lang.time.DateUtils;
import com.mycim.framework.utils.msg.JsonUtils;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.SystemConstant;
import com.mycim.valueobject.consts.EventName;
import com.mycim.valueobject.consts.ReferenceDetailNames;
import com.mycim.valueobject.ems.Entity;
import com.mycim.valueobject.ems.Equipment;
import com.mycim.valueobject.prp.Item;
import com.mycim.valueobject.prp.SubTechnology;
import com.mycim.valueobject.prp.Technology;
import com.mycim.valueobject.sys.ReferenceFileDetail;
import com.mycim.valueobject.wip.Lot;
import com.mycim.valueobject.wip.LotStatus;
import com.mycim.valueobject.wip.dto.LotQueryParameterDto;
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 org.springframework.util.StopWatch;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.stream.Collectors;

/**
 * 批次查询
 *
 * @author pinyan.song
 * @version 6.0.0
 * @date 2019-9-23
 **/
public class LotPortalAction extends WipSetupAction {
    private static final Logger logger = LoggerFactory.getLogger(LotPortalAction.class);

    public volatile Set<CountDownProp> countDownPropList = Collections.synchronizedSortedSet(new TreeSet<>());

    public static <T> List<T> deepCopy(List<T> src) throws Exception {
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(src);
        ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
        ObjectInputStream in = new ObjectInputStream(byteIn);
        @SuppressWarnings("unchecked") List<T> dest = (List<T>) in.readObject();
        return dest;
    }

    @Override
    public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        long facilityRrn = LocalContext.getFacilityRrn();
        String language = I18nUtils.getCurrentLanguage().toString();
        String userId = LocalContext.getUserId();
        int tabMaxCount = Integer.MAX_VALUE;
        String tabMaxCountStr = sysService.getRefFileValue("$PORTAL_TAB_MAX_COUNT", "LOTPORTAL", "DATA_1_VALUE");
        if (StringUtils.isNotBlank(tabMaxCountStr) && NumberUtils.isNumber(tabMaxCountStr)) {
            tabMaxCount = NumberUtils.toInt(tabMaxCountStr, Integer.MAX_VALUE);
        }
        request.setAttribute("totalTabCount", tabMaxCount);
        // String[] typesReferenceFile = new String[]{"lotType", "project", "lotCategory", "productType", "workArea",
        //         "stage"};
        // String wayReferenceFile = "referenceFile";
        // getComboboxData(typesReferenceFile, wayReferenceFile, language, userId, facilityRrn, request);
        //
        // String[] typesObject = new String[]{"PRODUCT", "PROCESS", "PROCEDURE", "STATION", "ENTITYGROUP"};
        // String wayObject = "object";
        // getComboboxData(typesObject, wayObject, language, userId, facilityRrn, request);
        //
        // String[] typesNoWay = new String[]{"lotStatus", "userDep"};
        // getComboboxData(typesNoWay, "", language, userId, facilityRrn, request);
        //
        // String typePriority = "priority";
        // getConditonCombo(typePriority, "", request);


        return mapping.findForward("lotPortal");
    }

    public List<Map> cascadeWSE(Map<String, Object> params) {
        String type = MapUtils.getString(params, "type");
        String operationRrns = MapUtils.getString(params, "operationRrns");
        String cascadeSource = MapUtils.getString(params, "cascadeSource");
        return lotQueryService.getWorkAreaAndEqptGroupAndStationComboData(type, operationRrns, cascadeSource);
    }

    public List<Map> cascadeWfl(Map<String, Object> params) {
        String type = MapUtils.getString(params, "type");
        String cascadeSource = MapUtils.getString(params, "cascadeSource");
        return wipWorkflowQueryService.qryWflCombo(type, cascadeSource);
    }

    public List<Map> conditionCombo(Map<String, Object> params) {
        String type = MapUtils.getString(params, "type");
        String cascadeSource = MapUtils.getString(params, "cascadeSource");
        return lotQueryService.qryConditionCombo(type, cascadeSource);
    }

    public List<Map> cascadeLotType(Map<String, Object> params) {
        List<String> categoryArray = (List) params.get("parent");

        StringBuilder categoryStr = new StringBuilder(StringUtils.EMPTY);
        for (String value : categoryArray) {
            categoryStr.append(StringUtils.trimToUpperCase(value)).append(",");
        }

        List<Map<String, String>> allTypesList = this.lotService
                .getLotTypeOptions(LocalContext.getFacilityRrn(), I18nUtils.getCurrentLanguage().toString(), null);
        List<Map> list = new ArrayList<Map>();

        if (allTypesList != null && allTypesList.size() > 0) {
            for (Map<String, String> typeMap : allTypesList) {
                String createCategory = typeMap.get("createCategory");
                int a = StringUtils.indexOf(categoryStr.toString(), createCategory + ",");
                if (StringUtils.indexOf(categoryStr.toString(), createCategory + ",") > -1) {
                    String s = typeMap.get("value");
                    Map<String, Object> data = new HashMap<>(2);
                    data.put("key", s);
                    data.put("value", s);
                    list.add(data);
                }
            }
        }
        Map<String, Object> combo = new HashMap<>(2);
        if (StringUtils.equalsIgnoreCase("CN", I18nUtils.getCurrentLanguage().toString())) {
            combo.put("key", "--选择--");
        } else {
            combo.put("key", "--Choice--");
        }
        combo.put("value", " ");
        list.add(0, combo);
        return list;
    }

    public List<Map> getComboboxData(Map<String, Object> params) {
        String type = MapUtils.getString(params, "type");

        List<Map> data;
        if (StringUtils.equalsIgnoreCase("lotStatus", type)) {
            data = lotQueryService.initLotStatusComboDoOrder();
        } else if (StringUtils.equalsIgnoreCase("process", type) && this.isSpecialRole()){
            data = lotQueryService.initLotPortalComboDataWithPermission(type);
        } else {
            data = lotQueryService.initLotPortalComboData(type);
        }

        if (StringUtils.equalsIgnoreCase("lotCategory", type)) {
            Map<String, Object> combo = new HashMap<>(2);
            combo.put("key", "ALL");
            combo.put("value", "ALL");
            data.add(combo);
            data.remove(0);
        }
        if (StringUtils.equalsIgnoreCase("lotType", type)) {
            Map<String, Object> combo = new HashMap<>(2);
            combo.put("key", "ALL");
            combo.put("value", "ALL");
            data.add(combo);
        }
        return data;
    }

    public ActionForward exportLotQuery(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String fileName = "lotListInfo_" + DateUtils.getNowTime(DateUtils.DATE_FORMAT4DAYD) + ".xlsx";
        Map<String, Object> titles = WebUtils.getExportTitles(request);
        List<Map<String, Object>> data = (List<Map<String, Object>>) WebUtils.getExportDatas(request);
        titles.put("title", "lotListInfo");
        int i = 0;
        for (Map<String, Object> m : data) {
            i++;
            m.put("seq", i);
        }

        WebUtils.exportExcel(fileName, titles, data, TemplateLocation.LOT_INFO_LIST, response);
        return WebUtils.NULLActionForward;
    }

    public String listenExportAll(Map<String, Object> params) throws InterruptedException {
        Iterator<CountDownProp> iterator = countDownPropList.iterator();
        while (iterator.hasNext()) {
            CountDownProp next = iterator.next();
            if (next.getCountDownLatch().getCount() == 0) {
                iterator.remove();
                continue;
            }
            if (next.getCountDownKey() + 15 * 60 * 1000 < (new Date()).getTime()) {
                next.getCountDownLatch().countDown();
                iterator.remove();
                continue;
            }
        }
        long countDownKey = MapUtils.getLongValue(params, "timestamp");
        CountDownLatch countDownLatch = new CountDownLatch(1);
        CountDownProp prop = new CountDownProp(countDownKey, countDownLatch);
        countDownPropList.add(prop);
        countDownLatch.await();
        return "success";
    }

    public ActionForward exportAll(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String strVal = request.getParameter("strVal");
        HashMap params = JsonUtils.getValue2Bean(strVal, HashMap.class);
        long countDownKey = MapUtils.getLongValue(params, "timestamp");

        long tempTime = (new Date()).getTime();
        CountDownProp prop = null;
        while (true) {
            boolean finded = false;
            for (CountDownProp prop1 : countDownPropList) {
                if (prop1.getCountDownKey() == countDownKey) {
                    prop = prop1;
                    finded = true;
                    break;
                }
            }
            if (finded) {
                break;
            }
            if (tempTime + 2 * 1000 < (new Date()).getTime()) {
                break;
            }
        }
        try {
            StopWatch sw = new StopWatch("lot exportAll action");
            String fileName = "lotListInfo_" + DateUtils.getNowTime(DateUtils.DATE_FORMAT4DAYD) + ".xlsx";
            Map<String, Object> titles = WebUtils.getExportTitles(request);
            sw.start("query");
            List<Map<String, Object>> results = lotQueryService
                    .ryAllLotInfoForLotPortal(buildQueryParameterDtoNoPage(params));
            sw.stop();

            titles.put("title", "lotListInfo");
            WebUtils.exportExcel(fileName, titles, results, TemplateLocation.LOT_INFO_LIST, response);

            if (prop != null) {
                prop.getCountDownLatch().countDown();
            }
        } catch (Exception e) {
            LOGGER.error(e);
            if (prop != null && prop.getCountDownLatch().getCount() != 0) {
                prop.getCountDownLatch().countDown();
            }

            throw new SystemIllegalArgumentException(Errors.create().content(e.getMessage()).build());
        }
        return WebUtils.NULLActionForward;
    }

    public Map query(Map<String, Object> params) throws Exception {
        StopWatch sw = new StopWatch("lot query action");
        Map map = new HashMap();

        String rowStart = MapUtils.getString(params, "start");
        String pageSize = MapUtils.getString(params, "limit");
        int totalCount = 0;
        int qtyTotal = 0;
        sw.start("query");
        List<Map<String, Object>> coll;
        if (this.isSpecialRole()){
            coll = lotQueryService.queryLotListCacheWithDataPermission(buildQueryParameterDto(params, rowStart, pageSize));
        } else {
            coll = lotQueryService.queryLotListCache(buildQueryParameterDto(params, rowStart, pageSize));
        }
        sw.stop();
        if (CollectionUtils.isNotEmpty(coll)) {
            HashMap firstLot = (HashMap) coll.iterator().next();
            totalCount = Integer.parseInt(firstLot.get("lotCount").toString());
            qtyTotal = MapUtils.getIntValue(firstLot, "qtyCount");
        }

        map.put("data", coll);
        map.put("totalCount", totalCount);
        map.put("qtyTotal", qtyTotal);
        String project = params.get("project") + "";
        if (StringUtils.isNotBlank(project)) {
            StringBuilder builder = new StringBuilder();
            //获取projectId
            builder.append(
                    getReferenceFileDetail(ReferenceDetailNames.PROJECT_TYPE, project, LocalContext.getFacilityRrn())
                            .getData2Value());
            List<Map<String, String>> dataList = (List) map.get("data");
            //将projectId和projectCode进行拼接并判断每个lotId是否满足
            List<Map<String, String>> list = dataList.stream().filter(s -> s.get("lotID")
                                                                            .startsWith(builder.toString() + project))
                                                     .collect(Collectors.toList());
            map.put("data", list);
        }
        if (logger.isDebugEnabled()) {
            logger.debug(sw.prettyPrint());
        }
        return map;
    }


    public List<Map> getData(Map<String, Object> params) {
        String op = MapUtils.getString(params, "op");
        op = StringUtils.isEmpty(op) ? "init" : op;
        switch (op) {
            case "init":
                return getComboboxData(params);
            case "cascadeLotType":
                return cascadeLotType(params);
            case "conditionCombo":
                return conditionCombo(params);
            case "cascadeWfl":
                return cascadeWfl(params);
            case "cascadeWSE":
                return cascadeWSE(params);
            case "cascadeTech":
                return cascadeTech(params);
            default:
                return null;
        }
    }

    private List<Map> cascadeTech(Map<String, Object> params) {
        List<Map> comboList = new ArrayList<>();
        Map<String, Object> conditionMap = new HashMap<>(2);
        String cascadeSource = MapUtils.getString(params, "cascadeArray");

        Map<String, String> temp = new HashMap(3);
        if (StringUtils.equalsIgnoreCase("CN", I18nUtils.getCurrentLanguage().toString())) {
            temp.put("key", "--选择--");
        } else {
            temp.put("key", "--Choice--");
        }
        temp.put("value", " ");
        comboList.add(temp);

        if (StringUtils.isNotBlank(cascadeSource)) {
            String[] cascadeConditionArray = cascadeSource.split(";;");
            conditionMap.put("productId", StringUtils.trimToUpperCase(cascadeConditionArray[0]));
            conditionMap.put("technologyId", StringUtils.trimToUpperCase(cascadeConditionArray[1]));
            conditionMap.put("subTechnologyId", StringUtils.trimToUpperCase(cascadeConditionArray[2]));
        }

        if (StringUtils.equalsIgnoreCase("productId", MapUtils.getString(params, "type"))) {
            String technologyId = MapUtils.getString(conditionMap, "technologyId");
            String subTechnologyId = MapUtils.getString(conditionMap, "subTechnologyId");
            String cascadeArray4Product = MapUtils.getString(params, "cascadeArray4Product");

            Map wfl = new HashMap();
            wfl.put("type", "product");
            wfl.put("cascadeSource", cascadeArray4Product);
            List<Map> list = cascadeWfl(wfl);

            List<Map> temp4Product = new ArrayList<>();
            if (StringUtils.isNotBlank(subTechnologyId)) {
                SubTechnology subTechnology = new SubTechnology(subTechnologyId,
                                                                getNamedSpace(ObjectList.SUB_TECHNOLOGY,
                                                                              LocalContext.getFacilityRrn()),
                                                                ObjectList.SUB_TECHNOLOGY);
                List<Item> products = prpService.getSubTechnology(subTechnology).getProducts();
                if (null == products) {
                    return comboList;
                }
                for (Item product : products) {
                    Map map = new HashMap(3);
                    map.put("key", product.getInstanceId());
                    map.put("value", product.getInstanceId());
                    temp4Product.add(map);
                }
            } else if (StringUtils.isNotBlank(technologyId)) {
                Technology technology = new Technology(technologyId, getNamedSpace(ObjectList.TECHNOLOGY,
                                                                                   LocalContext.getFacilityRrn()),
                                                       ObjectList.TECHNOLOGY);
                List<SubTechnology> subTechnologys = prpService.getTechnology(technology).getSubTechnologys();
                if (null == subTechnologys) {
                    return comboList;
                }
                for (SubTechnology subTechnology : subTechnologys) {
                    List<Item> products = prpService.getSubTechnology(subTechnology).getProducts();
                    for (Item product : products) {
                        Map map = new HashMap(3);
                        map.put("key", product.getInstanceId());
                        map.put("value", product.getInstanceId());
                        temp4Product.add(map);
                    }
                }
            }

            for (Map techMap : temp4Product) {
                for (Map wflMap : list) {
                    if (StringUtils.equals(MapUtils.getString(techMap, "key"), MapUtils.getString(wflMap, "key"))) {
                        comboList.add(techMap);
                    }
                }
            }
        } else if (StringUtils.equalsIgnoreCase("subTechnologyId", MapUtils.getString(params, "type"))) {
            String technologyId = MapUtils.getString(conditionMap, "technologyId");
            String productId = MapUtils.getString(conditionMap, "productId");
            if (StringUtils.isNotBlank(productId)) {
                SubTechnology subTechnology = prpService.getSubTechnology(productId);
                Map map = new HashMap(3);
                map.put("key", subTechnology.getInstanceId());
                map.put("value", subTechnology.getInstanceId());
                comboList.add(map);
            } else if (StringUtils.isNotBlank(technologyId)) {
                Technology technology = new Technology(technologyId, getNamedSpace(ObjectList.TECHNOLOGY,
                                                                                   LocalContext.getFacilityRrn()),
                                                       ObjectList.TECHNOLOGY);
                List<SubTechnology> subTechnologys = prpService.getTechnology(technology).getSubTechnologys();
                if (null == subTechnologys) {
                    return comboList;
                }
                for (SubTechnology subTechnology : subTechnologys) {
                    Map map = new HashMap(3);
                    map.put("key", subTechnology.getInstanceId());
                    map.put("value", subTechnology.getInstanceId());
                    comboList.add(map);
                }
            }
        } else if (StringUtils.equalsIgnoreCase("technologyId", MapUtils.getString(params, "type"))) {
            String subTechnologyId = MapUtils.getString(conditionMap, "subTechnologyId");
            String productId = MapUtils.getString(conditionMap, "productId");
            if (StringUtils.isNotBlank(productId)) {
                Technology technology = prpService.getTechnology(productId);
                Map map = new HashMap(3);
                map.put("key", technology.getInstanceId());
                map.put("value", technology.getInstanceId());
                comboList.add(map);
            } else if (StringUtils.isNotBlank(subTechnologyId)) {
                SubTechnology subTechnology = new SubTechnology(subTechnologyId,
                                                                getNamedSpace(ObjectList.SUB_TECHNOLOGY,
                                                                              LocalContext.getFacilityRrn()),
                                                                ObjectList.SUB_TECHNOLOGY);
                SubTechnology subTechnology1 = prpService.getSubTechnology(subTechnology);
                Map map = new HashMap(3);
                map.put("key", subTechnology1.getTechnologyId());
                map.put("value", subTechnology1.getTechnologyId());
                comboList.add(map);
            }
        }

        return comboList;
    }

    private int getQTBufferTime() {
        String refFileId = "$$QTIME_BUFFER_TIME";
        List<ReferenceFileDetail> datas = sysService.getRefFileValues(refFileId, LocalContext.getFacilityRrn());
        int bufferTime = 0;
        for (ReferenceFileDetail data : datas) {
            bufferTime = Integer.parseInt(data.getData1Value());
        }
        bufferTime = bufferTime / 60;
        return bufferTime;
    }

    private LotQueryParameterDto buildQueryParameterDto(Map<String, Object> params, String rowStart,
                                                        String pageSize) throws Exception {
        LotQueryParameterDto dto = buildQueryParameterDtoNoPage(params);
        dto.setStartRow(rowStart);
        dto.setPageSize(pageSize);
        return dto;
    }

    private LotQueryParameterDto buildQueryParameterDtoNoPage(Map<String, Object> params) throws Exception {
        LotQueryParameterDto parameterDto = new LotQueryParameterDto();

        parameterDto.setFacilityRrn(LocalContext.getFacilityRrn());
        parameterDto.setUserRrn(LocalContext.getUserRrn());

        List<String> lotStatus1List = (ArrayList<String>) MapUtils.getObject(params, "lotStatus1");
        List<String> lotCategoryArray = new ArrayList<>();
        String lotCategory1 = MapUtils.getString(params, "lotCategory1");
        if (StringUtils.isBlank(lotCategory1) || lotCategory1.indexOf("ALL") >= 0) {
            lotCategoryArray.add("");
        } else {
            lotCategoryArray = (List<String>) params.get("lotCategory1");
        }
        List<String> lotStatus = (List<String>) MapUtils.getObject(params, "lotStatus1");
        List<String> tempLotStatus = deepCopy(lotStatus);
        for (String status : tempLotStatus) {
            if (StringUtils.equalsIgnoreCase("ACTIVE_HOLD", status)) {
                lotStatus.remove(status);
                lotStatus.add("ACTIVE");
                lotStatus.add("HOLD");
            }
        }
        List<String> lotTypeArray = new ArrayList<>();
        String lotType1 = MapUtils.getString(params, "lotType1");
        if (StringUtils.isBlank(lotCategory1) || lotType1.indexOf("ALL") >= 0) {
            lotTypeArray.add("");
        } else {
            lotTypeArray = (List<String>) params.get("lotType1");
        }
        parameterDto.setLotStatus(lotStatus.toArray(new String[lotStatus.size()]));
        parameterDto.setPriority(MapUtils.getString(params, "priority", "").trim());
        parameterDto.setLotId(MapUtils.getString(params, "lotId", "").trim());
        parameterDto.setLotType(lotTypeArray.toArray(new String[lotTypeArray.size()]));
        parameterDto.setLotStatus(lotStatus1List.toArray(new String[lotStatus1List.size()]));
        parameterDto.setLotCategory(lotCategoryArray.toArray(new String[lotCategoryArray.size()]));
        parameterDto.setProductId(MapUtils.getString(params, "productId", "").trim());
        parameterDto.setProcessId(MapUtils.getString(params, "processId1", "").trim());
        parameterDto.setProductType(MapUtils.getString(params, "productType", "").trim());
        parameterDto.setRouteId(MapUtils.getString(params, "routeId", "").trim());
        parameterDto.setCarrierId(MapUtils.getString(params, "cassete", "").trim());
        parameterDto.setStationId(MapUtils.getString(params, "stationId", "").trim());
        parameterDto.setEqpGroupId(MapUtils.getString(params, "eqptGroupId1", "").trim());
        parameterDto.setStageId(MapUtils.getString(params, "stageId", "").trim());
        parameterDto.setCustomId(MapUtils.getString(params, "customId", "").trim());
        parameterDto.setWorkArea(MapUtils.getString(params, "workArea1", "").trim());
        parameterDto.setMfgEqptGroupId(MapUtils.getString(params, "MFGEqptGroupId1", "").trim());
        parameterDto.setPlocation(MapUtils.getString(params, "pLocation1", "").trim());
        parameterDto.setMaterialLotId(MapUtils.getString(params, "materialLotId", "").trim());
        parameterDto.setProcessLocation(MapUtils.getString(params, "processLocation", "").trim());
        parameterDto.setMySpecialLot(MapUtils.getString(params, "mySpecialLot", "").trim());
        parameterDto.setProject(MapUtils.getString(params, "project", "").trim());
        parameterDto.setWorkOrderId(MapUtils.getString(params, "workOrderId1" , StringUtils.EMPTY).trim());
        return parameterDto;
    }

    private Map buildEquipInfoForLot(Lot lot) {
        long facilityRrn = LocalContext.getFacilityRrn();
        Map<String, Object> equipmentInfo = new HashMap<>();
        if (lot.getEqptRrn() != null) {
            String lotStatus = lot.getLotStatus();
            long equipmenRrn = lot.getEqptRrn();
            Entity equipment = new Equipment();
            equipment.setInstanceRrn(equipmenRrn);
            equipment = emsService.getEntity(equipment);
            String equipmentId = equipment.getInstanceId();
            equipmentInfo.put("equipmentId", equipmentId);
            // check equipment status
            String equipmenStatus = emsService.getEntityCurrentStatus(equipmenRrn);
            equipmentInfo.put("equipmentStatus", equipmenStatus);
            if (equipmenStatus != null &&
                    (equipmenStatus.equals(EventName.DOWN) || equipmenStatus.equals(EventName.OFF) ||
                            equipmenStatus.equals(EventName.FACD)) &&
                    !((StringUtils.equals(lotStatus, LotStatus.RUNNING) ||
                            StringUtils.equals(lotStatus, LotStatus.DISPATCH) ||
                            StringUtils.equals(lotStatus, LotStatus.PROCESSED)) &&
                            StringUtils.equalsIgnoreCase(equipmenStatus, EventName.DOWN))) {
                equipmentInfo.put("equipmentAvailable", "NOT_AVAILABLE");
            } else {
                equipmentInfo.put("equipmentAvailable", "AVAILABLE");
            }
        }
        return equipmentInfo;
    }

    private void getComboboxData(String[] types, String way, String language, String user, long facility,
                                 HttpServletRequest request) {

        Map map = new HashMap();
        for (String type : types) {
            Map param = new HashMap();
            param.put("type", type);
            if ("lotCategory".equals(type)) {
                //lotCategory 显示问题被其他功能反复修改多次,针对 LotPortal(批次查询页面),拧出来单独处理
                map.put(type, getComboboxData4LotCategory());
            } else {
                map.put(type, getComboboxData(param));
            }
        }
        if (StringUtils.equals(way, "referenceFile")) {
            put("COMBOXDATAS", JsonUtils.toString(map), request);
        } else if (StringUtils.equals(way, "object")) {
            put("COMBOXDATASOBJECT", JsonUtils.toString(map), request);
        } else {
            put("COMBOXDATASLOTSTATUSANDUSERDEP", JsonUtils.toString(map), request);
        }
    }

    /**
     * 针对 LotPortal(批次查询页面),查询$LOT_CREATE_CATEGORY
     **/
    private List<Map> getComboboxData4LotCategory() {
        List<Map> list = new ArrayList<>();
        List<ReferenceFileDetail> details = getReferenceFileDetails("$LOT_CREATE_CATEGORY");
        for (ReferenceFileDetail rfd : details) {
            Map<String, Object> combo = new HashMap<>(2);
            combo.put("key", rfd.getKey1Value());
            combo.put("value", rfd.getData1Value());
            list.add(combo);
        }
        Map<String, Object> combo = new HashMap<>(2);
        combo.put("key", "ALL");
        combo.put("value", "ALL");
        list.add(combo);
        return list;
    }

    private void getConditonCombo(String type, String cascadeSource, HttpServletRequest request) {
        Map map = new HashMap();
        List<Map> comboList = lotQueryService.qryConditionCombo(type, cascadeSource);
        map.put(type, comboList);
        put("COMBOXDATASPRIORITY", JsonUtils.toString(map), request);
    }

    class CountDownProp implements Comparable {
        private long countDownKey;

        private CountDownLatch countDownLatch;

        CountDownProp(long countDownKey, CountDownLatch countDownLatch) {
            this.countDownKey = countDownKey;
            this.countDownLatch = countDownLatch;
        }

        public long getCountDownKey() {
            return countDownKey;
        }

        public void setCountDownKey(long countDownKey) {
            this.countDownKey = countDownKey;
        }

        public CountDownLatch getCountDownLatch() {
            return countDownLatch;
        }

        public void setCountDownLatch(CountDownLatch countDownLatch) {
            this.countDownLatch = countDownLatch;
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (!(obj instanceof CountDownProp)) {
                return false;
            }
            CountDownProp t = (CountDownProp) obj;
            return this.countDownKey == t.countDownKey;
        }

        @Override
        public int compareTo(Object obj) {
            CountDownProp team = (CountDownProp) obj;
            int num = (int) (this.countDownKey - team.countDownKey);
            return num;
        }

    }

}