| | |
| | | package com.consum.base.core.service; |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import com.consum.base.service.BaseGoodsModelsServiceImpl; |
| | | import com.consum.base.service.BaseWarehouseServiceImpl; |
| | | import com.consum.base.service.LWhWarningServiceImpl; |
| | | import com.consum.model.po.BaseWarehouse; |
| | | import com.consum.model.po.FinSysTenantUser; |
| | | import com.consum.model.po.WhWarning; |
| | | import com.walker.infrastructure.utils.NumberGenerator; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.consum.base.core.utils.IdUtil; |
| | | import com.consum.base.service.BaseGoodsModelsService; |
| | | import com.consum.base.service.BaseWarehouseService; |
| | | import com.consum.base.service.LWhWarningServiceImpl; |
| | | import com.consum.model.po.BaseWarehouse; |
| | | import com.consum.model.po.FinSysTenantUser; |
| | | import com.consum.model.po.WhWarning; |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | |
| | | /** |
| | | * @ClassName LWhWarningCoreServiceImpl |
| | |
| | | * @Version 1.0 |
| | | **/ |
| | | @Service |
| | | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) |
| | | public class LWhWarningCoreServiceImpl { |
| | | |
| | | @Resource |
| | | private LWhWarningServiceImpl lWhWarningService; |
| | | @Resource |
| | | private BaseWarehouseServiceImpl baseWarehouseService; |
| | | private BaseWarehouseService baseWarehouseService; |
| | | @Resource |
| | | private BaseGoodsModelsServiceImpl baseGoodsModelsService; |
| | | private BaseGoodsModelsService baseGoodsModelsService; |
| | | |
| | | /** |
| | | * 当库存变动时调用该方法 |
| | |
| | | * @param warehouseId |
| | | * @param baseModelIdList |
| | | */ |
| | | public void updateKuCun(Short warehouseType, Long warehouseId, List<Long> baseModelIdList, FinSysTenantUser sysInfo, Long dealTime) { |
| | | public void updateKuCun(Short warehouseType, Long warehouseId, List<Long> baseModelIdList, FinSysTenantUser sysInfo, |
| | | Long dealTime) { |
| | | if (baseModelIdList == null) { |
| | | baseModelIdList = new ArrayList<>(); |
| | | } |
| | | sysInfo = sysInfo == null ? new FinSysTenantUser() : sysInfo; |
| | | // 获取到达到阈值的物品 |
| | | List<Map<String, Object>> kuCunNotifyList = lWhWarningService.checkKuCun(warehouseType, warehouseId, baseModelIdList); |
| | | // |
| | | // log.info("没有达到阈值的物品"); |
| | | List<Map<String, Object>> kuCunNotifyList = |
| | | lWhWarningService.checkKuCun(warehouseType, warehouseId, baseModelIdList); |
| | | // log.info("没有达到阈值的物品"); |
| | | if (CollectionUtils.isEmpty(kuCunNotifyList)) { |
| | | kuCunNormalModel(warehouseType, warehouseId, baseModelIdList); |
| | | return; |
| | | } |
| | | List<Long> allChangModelList = baseModelIdList.stream() |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | List<Long> allChangModelList = baseModelIdList.stream().distinct().collect(Collectors.toList()); |
| | | baseModelIdList = allChangModelList; |
| | | |
| | | // 将数据插入库存预警【WH_WARNING】 |
| | |
| | | List<Map<String, Object>> modelInfoList = baseGoodsModelsService.queryGoodsModelInfo(baseGoodsModelsId); |
| | | Map<String, Object> modelInfo = modelInfoList.get(0); |
| | | |
| | | whWarning.setId(NumberGenerator.getLongSequenceNumber()); |
| | | whWarning.setId(IdUtil.generateId()); |
| | | whWarning.setWarehouseType(0); |
| | | whWarning.setBaseWarehouseId(warehouseId); |
| | | whWarning.setBaseWarehouseName(baseWarehouses.getWarehouseName()); |
| | | whWarning.setBaseGoodsTemplateId(Convert.toLong(modelInfo.get("goodsId"))); |
| | | whWarning.setBaseGoodsTemplateName(Convert.toStr(modelInfo.get("goodsName"))); |
| | | whWarning.setBaseGoodsModelsId(baseGoodsModelsId); |
| | | whWarning.setBaseGoodsModelsName((String) modelInfo.get("modelName")); |
| | | whWarning.setBaseGoodsModelsName((String)modelInfo.get("modelName")); |
| | | whWarning.setGoodsType(2); |
| | | whWarning.setWarningType(warningType); |
| | | whWarning.setUpperLimit(upperLimit); |
| | |
| | | warningList.add(whWarning); |
| | | } |
| | | |
| | | //修改以前的预警状态 |
| | | // 修改以前的预警状态 |
| | | baseModelIdList.removeAll(kuCunNotifyModelIdList); |
| | | kuCunNormalModel(warehouseType, warehouseId, baseModelIdList); |
| | | |
| | | //批量插入预警 |
| | | // 批量插入预警 |
| | | lWhWarningService.insertBatch(warningList); |
| | | |
| | | } |
| | | |
| | | private String KU_CUN_NORMAL_MODEL = "update WH_WARNING set STATES=2 where WAREHOUSE_TYPE=? and BASE_WAREHOUSE_ID=?"; |
| | | private String KU_CUN_NORMAL_MODEL = |
| | | "update WH_WARNING set STATES=2 where WAREHOUSE_TYPE=? and BASE_WAREHOUSE_ID=?"; |
| | | |
| | | /** |
| | | * |
| | | * @param warehouseType |
| | | * @param warehouseId |
| | | * @param normalBaseModelIdList 库存正常的 |
| | |
| | | |
| | | StringBuilder sql = new StringBuilder(KU_CUN_NORMAL_MODEL); |
| | | if (!org.springframework.util.CollectionUtils.isEmpty(normalBaseModelIdList)) { |
| | | sql.append(" and BASE_GOODS_MODELS_ID in(?)"); |
| | | params.add(org.apache.commons.lang3.StringUtils.join(normalBaseModelIdList, ",")); |
| | | sql.append(" and BASE_GOODS_MODELS_ID in(") |
| | | .append(org.apache.commons.lang3.StringUtils.join(normalBaseModelIdList, ",")).append(")"); |
| | | } |
| | | return lWhWarningService.update(sql.toString(), params.toArray()); |
| | | } |