# OperationPanelQueryManagerImpl.java

    package com.mycim.server.wip.manager.impl;

    import com.mycim.framework.utils.lang.StringUtils;
    import com.mycim.framework.utils.lang.collections.MapUtils;
    import com.mycim.server.wip.dao.OperationPanelQueryDAO;
    import com.mycim.server.wip.manager.OperationPanelQueryManager;
    import com.mycim.valueobject.runcard.util.RunCardUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    import java.util.List;
    import java.util.Map;

    /**
     * @author Johnson.Wang
     * @version 6.0.0
     * @date 2019/9/19
     **/
    @Service
    @Transactional
    public class OperationPanelQueryManagerImpl implements OperationPanelQueryManager {

        @Autowired
        private OperationPanelQueryDAO operationPanelQueryDAO;

        @Override
        public int countLotForOperatorPanel(Map condition) {
            rebuildOperatorParam(condition);
            return operationPanelQueryDAO.countLotForOperatorPanel(condition);
        }

        @Override
        public List<Map<String, Object>> listLotForOperatorPanel(Map condition) {
            rebuildOperatorParam(condition);
            return operationPanelQueryDAO.listLotForOperatorPanel(condition);
        }

        @Override
        public List<Map<String, Object>> listLotForOperatorPanelByRuncard(Map<String, Object> condition) {
            rebuildOperatorParam(condition);
            List<Map<String, Object>> lotList = operationPanelQueryDAO.listLotForOperatorPanelByRuncard(condition);
            for (Map<String, Object> lot : lotList) {
                lot.put("rcFlag", Boolean.TRUE);
                lot.put("rcLotId", RunCardUtils.buildRunCardLotId(MapUtils.getString(lot, "lotId")));
            }
            return lotList;
        }

        private void rebuildOperatorParam(Map condition) {
            // 处理条件中的 lot category数组
            String[] lotCategoryArray = (String[]) MapUtils.getObject(condition, "lotCategory");
            String lotCategoryStr = StringUtils.EMPTY;
            if (lotCategoryArray != null && lotCategoryArray.length > 0) {
                for (int i = 0; i < lotCategoryArray.length; i++) {
                    if (StringUtils.isNotBlank(lotCategoryArray[i])) {
                        lotCategoryStr += "'" + lotCategoryArray[i] + "'";
                        if (i != (lotCategoryArray.length - 1)) {
                            lotCategoryStr += ", ";
                        }
                    }
                }
            }
            condition.put("lotCategory", lotCategoryStr);

            // 条件lotID，productID处理
            if (StringUtils.isNotBlank(MapUtils.getString(condition, "lotId"))) {
                String lotId = MapUtils.getString(condition, "lotId");
                if (StringUtils.indexOf(lotId, "*") > -1) {
                    lotId = StringUtils.replace(lotId, "*", "%").toString();
                    condition.put("lotId", StringUtils.trimToUpperCase(lotId));
                }
            }
            if (StringUtils.isNotBlank(MapUtils.getString(condition, "proId"))) {
                String productId = MapUtils.getString(condition, "proId");
                if (StringUtils.indexOf(productId, "*") > -1) {
                    productId = StringUtils.replace(productId, "*", "%").toString();
                    condition.put("proId", StringUtils.trimToUpperCase(productId));
                }
            }
        }

    }