ProductAttributeHistoryAction.java

package com.mycim.webapp.actions.spec;

import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.jdbc.Page;
import com.mycim.framework.utils.lang.collections.MapUtils;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.prp.*;
import com.mycim.webapp.actions.PrpSetupAction;
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.lang.Override;
import java.util.*;

/**
 * @author Luopeng.Wang
 * @version 6.0.0
 * @date 2021/3/30
 **/
public class ProductAttributeHistoryAction extends PrpSetupAction {

    @Override
    public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        return mapping.getInputForward();
    }

    public Page queryHistories(Map map) {
        ProductAttributeHistoryQueryDto historyQuery = new ProductAttributeHistoryQueryDto();

        historyQuery.setPageNo(MapUtils.getInteger(map, "page"));
        historyQuery.setPageSize(MapUtils.getInteger(map, "limit"));

        historyQuery.setFacilityRrn(LocalContext.getFacilityRrn());
        historyQuery.setProcessId(MapUtils.getString(map, "processId"));
        historyQuery.setProcessVersion(MapUtils.getInteger(map, "processVersion"));
        historyQuery.setProductId(MapUtils.getString(map, "productId"));
        historyQuery.setProductVersion(MapUtils.getInteger(map, "productVersion"));

        Page historyPage = productAttributeService.queryProductAttributeHistories(historyQuery);

        return historyPage;
    }

    public List<Map> queryProductVersions(Map map) {
        String productId = MapUtils.getString(map, "productId");
        Long productRrn = prpService.getProductRrnById(productId);

        List<Map> rebuildProdutVersions = new ArrayList<>();

        List<ProductVersion> productVersions = productService.getProductVersions(productRrn);
        for (ProductVersion prodverion : productVersions) {
            Map<String, String> newProcessVersion = new HashMap<>();
            newProcessVersion.put("key", String.valueOf(prodverion.getInstanceVersion()));
            newProcessVersion.put("value", String.valueOf(prodverion.getInstanceVersion()) + " (" +
                    prodverion.getVersionStatus() + ")");
            if (!rebuildProdutVersions.contains(newProcessVersion)) {
                rebuildProdutVersions.add(newProcessVersion);
            }

        }

        return rebuildProdutVersions;
    }

    public List<Map> queryProcessVersions(Map map) {
        String processId = MapUtils.getString(map, "processId");
        long processRrn = this.getInstanceRrn(processId, LocalContext.getFacilityRrn(), ObjectList.WFL_KEY);

        List<Map> rebuildProcessVersions = new ArrayList<>();
        if (processRrn <= 0L) {
            return rebuildProcessVersions;
        }
        ProcessPlanning processPlanning = new ProcessPlanning();
        if (processRrn <= 0L) {
            return rebuildProcessVersions;
        }
        processPlanning.setInstanceRrn(processRrn);
        Collection processVersions = prpService.getProcessVersions(processPlanning);

        for (Iterator iterator = processVersions.iterator(); iterator.hasNext(); ) {
            Map newMap = new HashMap<>();

            ProcessVersion processVersion = (ProcessVersion) iterator.next();
            int version = processVersion.getInstanceVersion();
            String versionDesc = version + " (" + processVersion.getVersionStatus() + ")";

            newMap.put("key", version);
            newMap.put("value", versionDesc);

            rebuildProcessVersions.add(newMap);
        }
        return rebuildProcessVersions;
    }

    public List<Map> queryProductIds(Map map) {
        String processId = MapUtils.getString(map, "processId");
        long processRrn = this.getInstanceRrn(processId, LocalContext.getFacilityRrn(), ObjectList.WFL_KEY);

        List<Map> rebuildProducts = new ArrayList<>();
        for (Item item : prpService.getUsedByProducts(processRrn)) {
            Map<String, String> newMap = new HashMap<>();
            String productId = item.getInstanceId();
            newMap.put("key", productId);
            newMap.put("value", productId);
            rebuildProducts.add(newMap);
        }
        return rebuildProducts;
    }

}