futian.liu
2023-11-27 df34fa79f9616167babe07b0f63da6e9ddcc9620
consum-base/src/main/java/com/consum/base/service/LWarehouseFlowService.java
@@ -8,10 +8,9 @@
import com.walker.db.page.GenericPager;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.jdbc.service.BaseServiceImpl;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
import org.springframework.stereotype.Service;
/**
 * @ClassName LWarehouseFlowService
@@ -254,4 +253,106 @@
        return selectSplit(sql.toString(), paramts, param.getPageNum(), param.getPageSize(), new MapperUtil());
    }
    public GenericPager<Map<String, Object>> queryAllBusinessFlow(LWhFormOutputQry param) {
        StringBuilder sql = new StringBuilder("SELECT\n"
            + "CASE WHEN flow.BUSINESS_TYPE=1 THEN tCaiGou.id \n"
            + "WHEN (flow.BUSINESS_TYPE=2 OR flow.BUSINESS_TYPE=4 OR flow.BUSINESS_TYPE=6) THEN tTrans.id \n"
            + "WHEN flow.BUSINESS_TYPE=3 THEN tFormOut.id \n"
            + "WHEN flow.BUSINESS_TYPE=5 THEN tScrapped.id \n"
            + "WHEN flow.BUSINESS_TYPE=7 THEN tInventory.id END id,\n"
            + "\n"
            + "CASE WHEN flow.BUSINESS_TYPE=1 THEN tCaiGou.BUSINESS_FORM_CODE \n"
            + "WHEN (flow.BUSINESS_TYPE=2 OR flow.BUSINESS_TYPE=4 OR flow.BUSINESS_TYPE=6) THEN tTrans.BUSINESS_FORM_CODE \n"
            + "WHEN flow.BUSINESS_TYPE=3 THEN tFormOut.BUSINESS_FORM_CODE \n"
            + "WHEN flow.BUSINESS_TYPE=5 THEN tScrapped.BUSINESS_FORM_CODE \n"
            + "WHEN flow.BUSINESS_TYPE=7 THEN tInventory.BUSINESS_FORM_CODE END BUSINESS_FORM_CODE,\n"
            + "\n"
            + "CASE WHEN flow.BUSINESS_TYPE=1 THEN tCaiGou.AGENCY_NAME \n"
            + "WHEN (flow.BUSINESS_TYPE=2 OR flow.BUSINESS_TYPE=4 OR flow.BUSINESS_TYPE=6) THEN tTrans.OPERATOR_NAME \n"
            + "WHEN flow.BUSINESS_TYPE=3 THEN tFormOut.AGENCY_NAME \n"
            + "WHEN flow.BUSINESS_TYPE=5 THEN tScrapped.AGENCY_NAME \n"
            + "WHEN flow.BUSINESS_TYPE=7 THEN tInventory.AGENCY_NAME END AGENCY_NAME,\n"
            + "\n"
            + "record.GOODS_TEMPLATE_NAME,\n"
            + "record.BASE_GOODS_MODELS_NAME,\n"
            + "record.THIS_TYPE,\n"
            + "flow.BUSINESS_TYPE,\n"
            + "record.THIS_COUNT,\n"
            + "flow.DEAL_TIME,\n"
            + "flow.OPERATOR_NAME,\n"
            + "record.TOTAL_PRICE\n"
            + "FROM  L_WAREHOUSE_FLOW flow\n"
            + "LEFT JOIN L_WH_GOODS_RECORD record ON flow.id=record.WAREHOUSE_FLOW_ID\n"
            + "LEFT JOIN L_WH_FORM_PROCURE tCaiGou ON flow.BUSINESS_TYPE=1 AND tCaiGou.id=flow.BUSINESS_FORM_ID\n"
            + "LEFT JOIN L_WH_FORM_TRANSFER tTrans ON (flow.BUSINESS_TYPE=2 or flow.BUSINESS_TYPE=4 or flow.BUSINESS_TYPE=6) AND tTrans.id=flow.BUSINESS_FORM_ID\n"
            + "LEFT JOIN L_WH_FORM_OUTPUT tFormOut ON flow.BUSINESS_TYPE=3 AND tFormOut.id=flow.BUSINESS_FORM_ID\n"
            + "LEFT JOIN L_WH_FORM_INVENTORY tInventory ON flow.BUSINESS_TYPE=7 AND tInventory.id=flow.BUSINESS_FORM_ID\n"
            + "LEFT JOIN L_WH_FORM_SCRAPPED tScrapped ON flow.BUSINESS_TYPE=5 AND tScrapped.id=flow.BUSINESS_FORM_ID\n"
            + "LEFT JOIN base_warehouse bw ON flow.WAREHOUSE_ID = bw.id\n"
            + "LEFT JOIN fin_sys_tenant fst ON fst.id = bw.AGENCY_ID\n"
            + "WHERE record.id IS NOT NULL ");
        HashMap<String, Object> paramts = new HashMap<>();
        //机构
        if (param.getAgencyId() != null) {
            sql.append("AND fst.id like :agencyId ");
            paramts.put("agencyId", param.getAgencyId() + StringUtils.CHAR_PERCENT);
        }
        //物品名称
        if (StringUtils.isNotEmpty(param.getGoodsName())) {
            sql.append(" AND record.GOODS_TEMPLATE_NAME like :goodsTemplateName");
            paramts.put("goodsTemplateName", StringUtils.CHAR_PERCENT + param.getGoodsName() + StringUtils.CHAR_PERCENT);
        }
        if (param.getBaseGoodsId() != null) {
            sql.append(" AND record.BASE_GOODS_TEMPLATE_ID=:goodsTemplateId");
            paramts.put("goodsTemplateId", param.getBaseGoodsId());
        }
        //规格型号
        if (param.getBaseGoodsModelsId() != null) {
            sql.append(" AND record.BASE_GOODS_MODELS_ID=:baseGoodsModelsId");
            paramts.put("baseGoodsModelsId", param.getBaseGoodsModelsId());
        }
        // 同码表,1采购入库 2退还入库 3调拨入库 4盘盈入库 5申领出库 6调拨出库 7盘亏出库 8报废出库 9其他出库
        Integer flowType = param.getStates();
        if (flowType != null) {
            Map<String, Short> typeByFlowType = WhBusinessEnum.getTypeByFlowType(flowType.shortValue());
            //本次调整类型(1=调增;2=调减)
            Short flowThisType = typeByFlowType.get("flowThisType");
            //单据类型 1 采购2 调拨 3出库4部门分发5报废6部门物品回退仓库7物品盘点
            Short flowBusinessType = typeByFlowType.get("flowBusinessType");
            if (flowThisType != null) {
                sql.append(" AND flow.THIS_TYPE=:flowThisType");
                paramts.put("flowThisType", flowThisType);
            }
            if (flowBusinessType != null) {
                sql.append(" AND flow.BUSINESS_TYPE=:flowBusinessType");
                paramts.put("flowBusinessType", flowBusinessType);
            }
        }
        // 单号
        String businessFormCode = param.getBusinessFormCode();
        if (StringUtils.isNotEmpty(businessFormCode)) {
            sql.append(" and case when flow.BUSINESS_TYPE = 1 THEN tCaiGou.BUSINESS_FORM_CODE =:whereBusinessFormCode" +
                " WHEN ( flow.BUSINESS_TYPE = 2 OR flow.BUSINESS_TYPE = 4 OR flow.BUSINESS_TYPE = 6 ) THEN tTrans.BUSINESS_FORM_CODE =:whereBusinessFormCode" +
                " WHEN flow.BUSINESS_TYPE = 3 THEN tFormOut.BUSINESS_FORM_CODE=:whereBusinessFormCode" +
                " WHEN flow.BUSINESS_TYPE = 5 THEN tScrapped.BUSINESS_FORM_CODE =:whereBusinessFormCode" +
                " WHEN flow.BUSINESS_TYPE = 7 THEN tInventory.BUSINESS_FORM_CODE =:whereBusinessFormCode end");
            paramts.put("whereBusinessFormCode", businessFormCode);
        }
        // 操作时间
        if (param.getStartTime() != null) {
            sql.append(" and flow.DEAL_TIME >=:dealTimeStart ");
            paramts.put("dealTimeStart", param.getStartTime() * 1000000);
        }
        if (param.getEndTime() != null) {
            sql.append(" and flow.DEAL_TIME <:dealTimeEnd ");
            paramts.put("dealTimeEnd", param.getEndTime() * 1000000 + 240000);
        }
        sql.append(" ORDER BY record.DEAL_TIME desc,record.id DESC ");
        return selectSplit(sql.toString(), paramts, param.getPageNum(), param.getPageSize(), new MapperUtil());
    }
}