futian.liu
2023-12-09 186f6eb07df6934d2e28330ba39dcfce30c0063a
consum-base/src/main/java/com/consum/base/service/LWhWarningServiceImpl.java
@@ -3,11 +3,13 @@
import com.consum.base.core.utils.MapperUtil;
import com.consum.base.pojo.query.WhWarningQry;
import com.walker.db.page.GenericPager;
import com.walker.infrastructure.utils.CollectionUtils;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.jdbc.service.BaseServiceImpl;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@@ -19,6 +21,31 @@
 **/
@Service
public class LWhWarningServiceImpl extends BaseServiceImpl {
    private static String GET_WARNING_TYPE_NUM = "SELECT COUNT(1) AS total_num,count(CASE WHEN wareWarn.WARNING_TYPE=1 THEN 1 ELSE NULL END) AS up_num,count(CASE WHEN wareWarn.WARNING_TYPE=2 THEN 1 ELSE NULL END) AS low_num FROM WH_WARNING wareWarn LEFT JOIN BASE_WAREHOUSE ware ON ware.id=wareWarn.BASE_WAREHOUSE_ID WHERE 1=1 ";
    public Map<String, Object> getWarningTypeNum(WhWarningQry param) {
        StringBuilder sql = new StringBuilder(GET_WARNING_TYPE_NUM);
        HashMap<String, Object> paramts = new HashMap<>();
        if (param.getStates() != null) {
            sql.append(" AND wareWarn.states = :states");
            paramts.put("states", param.getStates());
        }
        //机构
        if (param.getAgencyId() != null) {
            sql.append(" and ware.AGENCY_ID=:agencyId");
            paramts.put("agencyId", param.getAgencyId());
        }
        List<Map<String, Object>> mapList = select(sql.toString(), paramts, new MapperUtil());
        if (CollectionUtils.isEmpty(mapList)) {
            Map<String, Object> rtnMap = new HashMap<>();
            rtnMap.put("totalNum", 0);
            rtnMap.put("upNum", 0);
            rtnMap.put("lowNum", 0);
            return rtnMap;
        }
        return mapList.get(0);
    }
    private static String GET_LIST_WITH_PAGE = "SELECT wareWarn.*,ware.WAREHOUSE_NAME,goodsTemp.CATEGORY_NAME,CONCAT(cate.CLASSIFICATION,'类') cost_Type,goodsTemp.GOODS_NAME,baseModel.MODEL_NAME,basemodel.UNIT FROM WH_WARNING wareWarn LEFT JOIN BASE_GOODS_MODELS baseModel ON baseModel.ID=wareWarn.BASE_GOODS_MODELS_ID LEFT JOIN BASE_GOODS_TEMPLATE goodsTemp ON wareWarn.BASE_GOODS_TEMPLATE_ID=goodsTemp.id LEFT JOIN BASE_CATEGORY cate ON cate.id=goodsTemp.CATEGORY_ID LEFT JOIN BASE_WAREHOUSE ware ON ware.id=wareWarn.BASE_WAREHOUSE_ID WHERE 1=1 ";
@@ -31,8 +58,8 @@
        }
        //机构
        if (param.getAgencyId() != null) {
            sql.append(" and left(ware.AGENCY_ID, length(:lengthAgencyId)) = :agencyId");
            paramts.put("lengthAgencyId", param.getAgencyId());
            sql.append(" and ware.AGENCY_ID=:agencyId");
//            paramts.put("lengthAgencyId", param.getAgencyId());
            paramts.put("agencyId", param.getAgencyId());
        }
        //仓库类型
@@ -51,7 +78,8 @@
        }
        if (param.getGoodsTemplateId() != null) {
            sql.append(" AND goodsTemp.id=:goodsTemplateId");
            paramts.put("goodsTemplateId", param.getGoodsTemplateId());        }
            paramts.put("goodsTemplateId", param.getGoodsTemplateId());
        }
        //分类
        if (param.getCategoryId() != null) {
            sql.append(" AND cate.id=:categoryId");
@@ -64,9 +92,77 @@
            sql.append(" AND cate.CLASSIFICATION=':costType'");
            paramts.put("costType", costType);
        }
        sql.append(" ORDER BY wareWarn.id DESC ");
        if (param.getWarningType() != null) {
            sql.append(" AND wareWarn.WARNING_TYPE=:warningType");
            paramts.put("warningType", param.getWarningType());
        }
        //规格型号
        if (param.getBaseGoodsModelsId() != null) {
            sql.append(" AND wareWarn.BASE_GOODS_MODELS_ID=:baseGoodsModelsId");
            paramts.put("baseGoodsModelsId", param.getBaseGoodsModelsId());
        }
        sql.append(" ORDER BY wareWarn.DEAL_TIME DESC ");
        return selectSplit(sql.toString(), paramts, param.getPageNum(), param.getPageSize(), new MapperUtil());
    }
    /**
     * 查询指定仓库的库存是否超预警
     *
     * @param warehouseType
     * @param warehouseId
     * @param baseModelId
     */
    private String CHECK_KUCUN_PREFIX = "SELECT warnConf.*,goods.goods_Num,CASE WHEN warnConf.LOWER_LIMIT>=goods.goods_Num THEN 2 WHEN warnConf.UPPER_LIMIT<=goods.goods_Num THEN 1 END AS WARNING_TYPE FROM (";
    private String CHECK_KUCUN_CONFIG_PREFIX = "SELECT WAREHOUSE_TYPE,BASE_WAREHOUSE_ID,BASE_GOODS_MODELS_ID,LOWER_LIMIT,UPPER_LIMIT FROM WH_WARNING_CONFIG";
    private String CHECK_KUCUN_CONFIG_WHERE = " WHERE 1=1";
    private String CHECK_KUCUN_CONFIG_JOINTKUCUN = ") warnConf LEFT JOIN (";
    private String CHECK_KUCUN_KUCUN_PREFIX = "SELECT WAREHOUSE_TYPE,WAREHOUSE_ID,BASE_GOODS_MODELS_ID,count(1) goods_Num FROM L_WH_GOODS";
    private String CHECK_KUCUN_KUCUN_WHERE = " WHERE 1=1 and STATES=1";
    private String CHECK_KUCUN_KUCUN_END = " GROUP BY BASE_GOODS_MODELS_ID)";
    private String CHECK_KUCUN_END = "goods ON goods.BASE_GOODS_MODELS_ID=warnConf.BASE_GOODS_MODELS_ID AND goods.WAREHOUSE_TYPE=warnConf.WAREHOUSE_TYPE AND goods.BASE_GOODS_MODELS_ID=warnConf.BASE_GOODS_MODELS_ID WHERE (warnConf.LOWER_LIMIT>=goods.goods_Num OR warnConf.UPPER_LIMIT<=goods.goods_Num)";
    public List<Map<String, Object>> checkKuCun(Short warehouseType, Long warehouseId, List<Long> baseModelIdList) {
        StringBuilder checkKucunPrefix = new StringBuilder(CHECK_KUCUN_PREFIX);
        StringBuilder checkKucunConfigPrefix = new StringBuilder(CHECK_KUCUN_CONFIG_PREFIX);
        StringBuilder checkKucunConfigWhere = new StringBuilder(CHECK_KUCUN_CONFIG_WHERE);
        StringBuilder checkKucunConfigJointkucun = new StringBuilder(CHECK_KUCUN_CONFIG_JOINTKUCUN);
        StringBuilder checkKucunKucunPrefix = new StringBuilder(CHECK_KUCUN_KUCUN_PREFIX);
        StringBuilder checkKucunKucunWhere = new StringBuilder(CHECK_KUCUN_KUCUN_WHERE);
        StringBuilder checkKucunKucunEnd = new StringBuilder(CHECK_KUCUN_KUCUN_END);
        StringBuilder checkKucunEnd = new StringBuilder(CHECK_KUCUN_END);
        Map<String, Object> paramMap = new HashMap<>();
        if (warehouseType != null) {
            checkKucunConfigWhere.append(" and WAREHOUSE_TYPE =:ConfigWarehouseType");
            paramMap.put("ConfigWarehouseType", warehouseType);
            checkKucunKucunWhere.append(" and WAREHOUSE_TYPE =:KuCunWarehouseType");
            paramMap.put("KuCunWarehouseType", warehouseType);
        }
        if (warehouseId != null) {
            checkKucunConfigWhere.append(" and BASE_WAREHOUSE_ID =:ConfigWarehouseId");
            paramMap.put("ConfigWarehouseId", warehouseId);
            checkKucunKucunWhere.append(" and WAREHOUSE_ID =:KuCunWarehouseId");
            paramMap.put("KuCunWarehouseId", warehouseId);
        }
        if (!CollectionUtils.isEmpty(baseModelIdList)) {
            checkKucunConfigWhere.append(" and BASE_GOODS_MODELS_ID in(:ConfigBaseModelIds)");
            paramMap.put("ConfigBaseModelIds", baseModelIdList);
            checkKucunKucunWhere.append(" and BASE_GOODS_MODELS_ID in(:KuCunBaseModelIds)");
            paramMap.put("KuCunBaseModelIds", baseModelIdList);
        }
        checkKucunPrefix.append(checkKucunConfigPrefix)
                .append(checkKucunConfigWhere)
                .append(checkKucunConfigJointkucun)
                .append(checkKucunKucunPrefix)
                .append(checkKucunKucunWhere)
                .append(checkKucunKucunEnd)
                .append(checkKucunEnd);
        return select(checkKucunPrefix.toString(), paramMap, new MapperUtil());
    }
}