From eb58395b79a966e8476840c9f6323a324f251191 Mon Sep 17 00:00:00 2001 From: judy <278197488@qq.com> Date: Wed, 28 Aug 2024 15:36:35 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E6=88=90=E7=9B=98=E7=82=B9=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/shkj/wms/bo/BusinStockInvAddBo.java | 28 +++----- .../business/BusinStockInvController.java | 6 +- .../wms/service/IBusinStockInvService.java | 2 +- .../impl/BusinStockInvServiceImpl.java | 65 +++++++++---------- .../java/com/shkj/wms/utils/IntIdUtil.java | 55 ++++++++++++++++ .../com/shkj/wms/vo/StockLocationInvVo.java | 5 ++ .../mapper/wms/BusinStockInvMapper.xml | 4 +- 7 files changed, 106 insertions(+), 59 deletions(-) create mode 100644 shkj-wms/src/main/java/com/shkj/wms/utils/IntIdUtil.java diff --git a/shkj-wms/src/main/java/com/shkj/wms/bo/BusinStockInvAddBo.java b/shkj-wms/src/main/java/com/shkj/wms/bo/BusinStockInvAddBo.java index 5da7c21..e4e1737 100644 --- a/shkj-wms/src/main/java/com/shkj/wms/bo/BusinStockInvAddBo.java +++ b/shkj-wms/src/main/java/com/shkj/wms/bo/BusinStockInvAddBo.java @@ -24,32 +24,24 @@ public class BusinStockInvAddBo implements Serializable { private static final long serialVersionUID = 1L; + /** - * 盘点类型 + * 巷道 */ - @NotBlank(message = "盘点类型不得为空") - @Dict(type = "inv_type_dict", message = "盘点类型与数据字典值不匹配") - private String invType; + private String tunnel; /** - * 盘点方式 明盘 open 盲盘 close + * 排 */ - @NotBlank(message = "盘点方式不得为空") - private String invWay; + private String locationRow; /** - * 库存id集合 + * 列 */ - @NotEmpty(message = "库存id集合不得为空") - private List stockIds; - - // /** -// * 货位分组 -// */ -// @NotEmpty(message = "货位分组不得为空") -// private List locationGroups; + private String locationColumn; + /** - * 货位分组 + * 层 */ - private List locationGroups; + private String layer; } diff --git a/shkj-wms/src/main/java/com/shkj/wms/controller/business/BusinStockInvController.java b/shkj-wms/src/main/java/com/shkj/wms/controller/business/BusinStockInvController.java index 6a89561..67da76f 100644 --- a/shkj-wms/src/main/java/com/shkj/wms/controller/business/BusinStockInvController.java +++ b/shkj-wms/src/main/java/com/shkj/wms/controller/business/BusinStockInvController.java @@ -36,11 +36,11 @@ public class BusinStockInvController extends BaseController { private final IBusinStockInvService iBusinStockInvService; /** - * 新增盘点计划 + * 生成盘点计划 */ - @Log(title = "新增盘点计划", businessType = BusinessType.INSERT) + @Log(title = "生成盘点计划", businessType = BusinessType.INSERT) @PostMapping("/add") - public Result add(@Valid @RequestBody BusinStockInvAddBo bo) { + public Result add(@Valid @RequestBody BusinStockInvLocQueryBo bo) { return iBusinStockInvService.generateInventoryPlan(bo); } diff --git a/shkj-wms/src/main/java/com/shkj/wms/service/IBusinStockInvService.java b/shkj-wms/src/main/java/com/shkj/wms/service/IBusinStockInvService.java index 40a5534..90a204d 100644 --- a/shkj-wms/src/main/java/com/shkj/wms/service/IBusinStockInvService.java +++ b/shkj-wms/src/main/java/com/shkj/wms/service/IBusinStockInvService.java @@ -42,7 +42,7 @@ List queryList(BusinStockInvQueryBo bo); * @param bo 盘点计划新增业务对象 * @return */ - Result generateInventoryPlan(BusinStockInvAddBo bo); + Result generateInventoryPlan(BusinStockInvLocQueryBo bo); /** diff --git a/shkj-wms/src/main/java/com/shkj/wms/service/impl/BusinStockInvServiceImpl.java b/shkj-wms/src/main/java/com/shkj/wms/service/impl/BusinStockInvServiceImpl.java index 142bb1a..3d54933 100644 --- a/shkj-wms/src/main/java/com/shkj/wms/service/impl/BusinStockInvServiceImpl.java +++ b/shkj-wms/src/main/java/com/shkj/wms/service/impl/BusinStockInvServiceImpl.java @@ -18,6 +18,7 @@ import com.shkj.wms.enums.InvStatusEnum; import com.shkj.wms.enums.TaskStatusEnum; import com.shkj.wms.mapper.BusinStockInvMapper; import com.shkj.wms.service.*; +import com.shkj.wms.utils.IntIdUtil; import com.shkj.wms.vo.BusinStockInvExeVo; import com.shkj.wms.vo.BusinStockInvVo; import com.shkj.wms.vo.StockLocationInvVo; @@ -87,48 +88,42 @@ public class BusinStockInvServiceImpl extends ServiceImpl generateInventoryPlan(BusinStockInvAddBo bo) { - - Long branchId = SecurityUtils.getCurrentBranchId(); - String username = SecurityUtils.getUsername(); - Map> locationGroupStockDic = new HashMap<>(); - Map orderNosDic = new HashMap<>(); - for (Long stockId : bo.getStockIds()) { - - LambdaQueryWrapper wrapper = new LambdaQueryWrapper().ne(BusinStockInv::getInvStatus, InvStatusEnum.end).ne(BusinStockInv::getInvStatus, InvStatusEnum.cancel); - BusinStockInv businStockInvOne = iBusinStockInvService.getOne(wrapper); - if (businStockInvOne != null) { - LambdaQueryWrapper locationWrapper = new LambdaQueryWrapper().eq(BaseLocation::getId, businStockInvOne.getLocationId()); - BaseLocation locationOne = iBaseLocationService.getOne(locationWrapper); - return Result.err().msg("货位" + locationOne.getLocationName() + "存在没有结束的盘点单" + businStockInvOne.getInvOrderNo() + ",不允许再次生成!"); + public Result generateInventoryPlan(BusinStockInvLocQueryBo bo) { + + /** + * 1.查询需要盘点的货位 + */ + List stockLocationInvVos = this.queryLocatonStocklist(bo); + List locIdList = new ArrayList<>(); + for (StockLocationInvVo stockLocationInvVo : stockLocationInvVos) { + locIdList.add(stockLocationInvVo.getLocationId()); + } + if (locIdList.size()>0){ + LambdaQueryWrapper wrapper = new LambdaQueryWrapper().in(BusinStockInv::getLocationId,locIdList).ne(BusinStockInv::getInvStatus, InvStatusEnum.end).ne(BusinStockInv::getInvStatus, InvStatusEnum.cancel); + List list = iBusinStockInvService.list(wrapper); + for (BusinStockInv businStockInv : list) { + businStockInv.setInvStatus(InvStatusEnum.end.getValue()); + businStockInv.setRemark("下一轮盘点把上次未完成的进行完成"); } - + iBusinStockInvService.updateBatchById(list); + } + List businStockInvs = new ArrayList<>(); + Long lineId =0L; + for (StockLocationInvVo stockLocationInvVo : stockLocationInvVos) { + lineId++; BusinStockInv inv = new BusinStockInv(); - /* inv.setInvOrderNo(orderNosDic.get(locationGroup)); - inv.setConsignorId(stockLot.getConsignorId()); - inv.setLocationId(stockLot.getLocationId()); - inv.setGoodId(stockLot.getGoodId()); - inv.setBatchId(stockLot.getBatchId()); - inv.setQuantity(stockLot.getQuantity()); + inv.setInvOrderNo(IntIdUtil.generateIntId()+""); + inv.setLocationId(stockLocationInvVo.getLocationId()); inv.setInvQty(BigDecimal.ZERO); inv.setInvCase(BigDecimal.ZERO); inv.setInvPiece(BigDecimal.ZERO); - inv.setOrderUser(username); + inv.setOrderUser(SecurityUtils.getUsername()); inv.setInvStatus(InvStatusEnum.init.getValue()); - inv.setInvType(bo.getInvType()); - inv.setInvWay(bo.getInvWay()); - inv.setStatus(stockLot.getStatus()); - inv.setBranchId(stockLot.getBranchId()); - inv.setContainerId(stockLot.getContainerId()); - inv.setOrderType(OrderTypeEnum.PD.getValue()); - if (locationGroupStockDic.containsKey(locationGroup)) { - inv.setLineId(Long.valueOf(locationGroupStockDic.get(locationGroup).size())); - } else { - inv.setLineId(0L); - }*/ - this.save(inv); + inv.setBranchId(SecurityUtils.getCurrentBranchId()); + inv.setLineId(lineId); + businStockInvs.add(inv); } - return Result.ok(); + return iBusinStockInvService.saveBatch(businStockInvs)?Result.ok().msg("生成盘点单成功"):Result.err().msg("生成盘点单失败"); } /** diff --git a/shkj-wms/src/main/java/com/shkj/wms/utils/IntIdUtil.java b/shkj-wms/src/main/java/com/shkj/wms/utils/IntIdUtil.java new file mode 100644 index 0000000..5d8c1d4 --- /dev/null +++ b/shkj-wms/src/main/java/com/shkj/wms/utils/IntIdUtil.java @@ -0,0 +1,55 @@ +package com.shkj.wms.utils; + +import com.shkj.common.core.redis.RedisCache; +import com.shkj.common.core.text.Convert; +import com.shkj.common.utils.spring.SpringUtils; + +import java.time.LocalDate; +import java.util.Date; + +/** + * @author lch + */ +public class IntIdUtil { + + + + private static Date date = new Date(); + private static StringBuilder buf = new StringBuilder(); +// private static int seq = 0; + private static final int ROTATION = 99999; + + public static synchronized String next() { + + Integer seq = Convert.toInt(SpringUtils.getBean(RedisCache.class).getCacheObject("seq"), 0); + + if (seq > ROTATION) { + seq = 0; + } +// buf.delete(0, buf.length()); +// date.setTime(System.currentTimeMillis()); + String str = String.format("%1$05d", seq++); + SpringUtils.getBean(RedisCache.class).setCacheObject("seq", seq); + System.out.println("redis的值为"+seq); + return str; + } + + public static Long generateIntId() { + //生成规则 年份后两位-10【2位】 + 1年内第几天【3位】 + 随机数【5位】 + LocalDate now = LocalDate.now(); + // 因为int的最大数是2147483647 所以前2位=当前年-10 + String yearStr = now.getYear() - 10 + ""; + yearStr = yearStr.substring(2); + StringBuilder id = new StringBuilder(yearStr + String.format("%1$03d", now.getDayOfYear() )+ next()); + return Long.parseLong(id.toString()); + } + + public static void main(String[] args) { + for (int i = 0; i < 10000; i++) { + Long aLong = IntIdUtil.generateIntId(); + System.out.println(aLong + "==>" + Long.parseLong(aLong.intValue() + "")); + } + } + + +} diff --git a/shkj-wms/src/main/java/com/shkj/wms/vo/StockLocationInvVo.java b/shkj-wms/src/main/java/com/shkj/wms/vo/StockLocationInvVo.java index b35c1e9..41f4ef8 100644 --- a/shkj-wms/src/main/java/com/shkj/wms/vo/StockLocationInvVo.java +++ b/shkj-wms/src/main/java/com/shkj/wms/vo/StockLocationInvVo.java @@ -15,6 +15,11 @@ import java.io.Serializable; public class StockLocationInvVo implements Serializable { private static final long serialVersionUID = 1L; + /** + * 货位ID + */ + private Long locationId; + /** * 货位编号 */ diff --git a/shkj-wms/src/main/resources/mapper/wms/BusinStockInvMapper.xml b/shkj-wms/src/main/resources/mapper/wms/BusinStockInvMapper.xml index 1e83d0e..60d2bdc 100644 --- a/shkj-wms/src/main/resources/mapper/wms/BusinStockInvMapper.xml +++ b/shkj-wms/src/main/resources/mapper/wms/BusinStockInvMapper.xml @@ -257,7 +257,7 @@