From b545e94f0c1f5e1436f7b2e038aa539206dee468 Mon Sep 17 00:00:00 2001 From: songguoqiang <765017469@qq.com> Date: Fri, 10 May 2024 17:21:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/eam/enums/ErrorCodeConstants.java | 4 + .../itemaccounts/ItemAccountsController.java | 2 +- .../ItemInLocationController.java | 2 +- .../vo/ItemInLocationExcelVO.java | 4 +- .../itemaccounts/ItemAccountsMapper.java | 40 ++++++---- .../itemaccounts/ItemAccountsServiceImpl.java | 78 ++++++++++++------- .../transaction/TransactionServiceImpl.java | 11 +-- 7 files changed, 88 insertions(+), 53 deletions(-) diff --git a/win-module-eam/win-module-eam-api/src/main/java/com/win/module/eam/enums/ErrorCodeConstants.java b/win-module-eam/win-module-eam-api/src/main/java/com/win/module/eam/enums/ErrorCodeConstants.java index 9fffd09..770ac9c 100644 --- a/win-module-eam/win-module-eam-api/src/main/java/com/win/module/eam/enums/ErrorCodeConstants.java +++ b/win-module-eam/win-module-eam-api/src/main/java/com/win/module/eam/enums/ErrorCodeConstants.java @@ -130,6 +130,8 @@ public interface ErrorCodeConstants { ErrorCode ITEM_IS_HAVE= new ErrorCode(1_000_020_045, "该备件已存在!"); ErrorCode ProducePlan_NOT_EXISTS= new ErrorCode(1_000_020_046, "生产计划不存在!"); ErrorCode ITEM_CAN_NOT_DELETE= new ErrorCode(1_000_020_045, "该备件已存在于备件台账,不允许删除!"); + + ErrorCode LOCATION_COUNTS_EXISTS= new ErrorCode(1_000_020_045, "该库存数不为0,不能更换库位!"); ErrorCode MOLD_ACCOUNT_EXISTS = new ErrorCode(1_000_020_050, "该编号模具已存在!"); ErrorCode FALSE_LOCATION_ACCOUNT_EXISTS = new ErrorCode(1_000_020_051, "该备件有账外库且库存大于0,应该优先出账外库"); ErrorCode OUT_BIG_APPLY = new ErrorCode(1_000_020_052, "出库数量大于申领数量"); @@ -163,5 +165,7 @@ public interface ErrorCodeConstants { //备件入库记录 ErrorCode LOCATION_EXISTS = new ErrorCode(1_000_020_021, "该库位已与备件绑定不可重复绑定"); + ErrorCode ITEM_EXISTS = new ErrorCode(1_000_020_021, "该备件已绑定不可重复绑定"); + } diff --git a/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/itemaccounts/ItemAccountsController.java b/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/itemaccounts/ItemAccountsController.java index af59e60..9dbc381 100644 --- a/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/itemaccounts/ItemAccountsController.java +++ b/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/itemaccounts/ItemAccountsController.java @@ -271,7 +271,7 @@ public class ItemAccountsController { @GetMapping("/getByItemNumber") @Operation(summary = "根据备件编码查询库位信息") // @PreAuthorize("@ss.hasPermission('basic:item:query')") - public CommonResult scanCodeByNumber(@RequestParam("itemNumber") String itemNumber) { + public CommonResult getByItemNumber(@RequestParam("itemNumber") String itemNumber) { ItemAccountsRespVO convert = ItemAccountsConvert.INSTANCE.convert(itemAccountsService.getByItemNumber(itemNumber)); if(convert!=null){ ItemDO itemDO = itemService.getByNumber(itemNumber); diff --git a/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/iteminlocation/ItemInLocationController.java b/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/iteminlocation/ItemInLocationController.java index 1556de8..a518429 100644 --- a/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/iteminlocation/ItemInLocationController.java +++ b/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/iteminlocation/ItemInLocationController.java @@ -121,7 +121,7 @@ public class ItemInLocationController { LocationDO locationDO = locationService.getByNumber(vo.getLocationNumber()); vo.setLocationName(locationDO.getName()); } - ExcelUtils.write(response, "备件入库记录.xls", "数据", ItemInLocationExcelVO.class, datas); + ExcelUtils.write(response, "备件归还记录.xls", "数据", ItemInLocationExcelVO.class, datas); } @GetMapping("/get-import-template") diff --git a/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/iteminlocation/vo/ItemInLocationExcelVO.java b/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/iteminlocation/vo/ItemInLocationExcelVO.java index a8ce7e3..fd38e57 100644 --- a/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/iteminlocation/vo/ItemInLocationExcelVO.java +++ b/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/iteminlocation/vo/ItemInLocationExcelVO.java @@ -42,8 +42,8 @@ public class ItemInLocationExcelVO { @ExcelProperty("数量") private BigDecimal qty; - @ExcelProperty("领用人") - private String receiver; + @ExcelProperty("归还人") + private String returner; @ExcelProperty("创建时间") private LocalDateTime createTime; diff --git a/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/dal/mysql/itemaccounts/ItemAccountsMapper.java b/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/dal/mysql/itemaccounts/ItemAccountsMapper.java index a04ea55..6ff581d 100644 --- a/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/dal/mysql/itemaccounts/ItemAccountsMapper.java +++ b/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/dal/mysql/itemaccounts/ItemAccountsMapper.java @@ -69,11 +69,11 @@ public interface ItemAccountsMapper extends BaseMapperX { ItemAccountsDO newLocation = getByLocationAndType(param.getLocationNumber(), ItemAccountStatusEnum.NEW.getCode());//账内库库存 newQty = newLocation == null ? BigDecimal.ZERO : newLocation.getQty(); if (outQty.compareTo(BigDecimal.ZERO) > 0) {//说明账外库存在且数据不为0 需要先把账外库清空 - outLocation.setQty(outQty); + outLocation.setQty(BigDecimal.ZERO); result = this.updateById(outLocation); //添加库存事务 TransactionDO transactionDO = new TransactionDO(); - transactionDO.setQty(outLocation.getQty()); + transactionDO.setQty(outQty); transactionDO.setType(outLocation.getType()); list.add(transactionDO); BigDecimal subtractOutQty = qtyNew.subtract(outQty);//差几个零件 @@ -83,21 +83,26 @@ public interface ItemAccountsMapper extends BaseMapperX { result = this.updateById(inLocation); //添加库存事务 TransactionDO transactionDO1 = new TransactionDO(); - transactionDO1.setQty(inLocation.getQty()); + transactionDO1.setQty(subtractOutQty); transactionDO1.setType(inLocation.getType()); list.add(transactionDO1); } - if (inQty.compareTo(BigDecimal.ZERO) > 0 && inQty.compareTo(subtractOutQty) < 0) {//账内库存在且不足差额 - inLocation.setQty(inQty); + if (inQty.compareTo(BigDecimal.ZERO) > 0 && inQty.compareTo(subtractOutQty) < 0) {//账内库存在且不足差额需要清空账内 + inLocation.setQty(BigDecimal.ZERO); result = this.updateById(inLocation); + //添加库存事务 + TransactionDO transactionDO0 = new TransactionDO(); + transactionDO0.setQty(inQty); + transactionDO0.setType(inLocation.getType()); + list.add(transactionDO0); BigDecimal subtractInQty = subtractOutQty.subtract(inQty);//减去之后的数量 if (inQty.compareTo(BigDecimal.ZERO) > 0 && inQty.compareTo(subtractInQty) >= 0) {//新到货存在且足够差额 BigDecimal subtractNewQty = newQty.subtract(subtractInQty);//减去之后的数量 newLocation.setQty(subtractNewQty); - //添加库存事务 result = this.updateById(newLocation); + //添加库存事务 TransactionDO transactionDO2 = new TransactionDO(); - transactionDO2.setQty(newLocation.getQty()); + transactionDO2.setQty(subtractInQty); transactionDO2.setType(newLocation.getType()); list.add(transactionDO2); } else { @@ -111,7 +116,7 @@ public interface ItemAccountsMapper extends BaseMapperX { result = this.updateById(newLocation); //添加库存事务 TransactionDO transactionDO3 = new TransactionDO(); - transactionDO3.setQty(newLocation.getQty()); + transactionDO3.setQty(subtractOutQty); transactionDO3.setType(newLocation.getType()); list.add(transactionDO3); } else { @@ -126,16 +131,16 @@ public interface ItemAccountsMapper extends BaseMapperX { result = this.updateById(inLocation); //添加库存事务 TransactionDO transactionDO4 = new TransactionDO(); - transactionDO4.setQty(inLocation.getQty()); + transactionDO4.setQty(qtyNew); transactionDO4.setType(inLocation.getType()); list.add(transactionDO4); } - if (inQty.compareTo(BigDecimal.ZERO) > 0 && inQty.compareTo(qtyNew) < 0) {//账内库存在且不足差额 - inLocation.setQty(inQty); + if (inQty.compareTo(BigDecimal.ZERO) > 0 && inQty.compareTo(qtyNew) < 0) {//账内库存在且不足差额清空 + inLocation.setQty(BigDecimal.ZERO); result = this.updateById(inLocation); //添加库存事务 TransactionDO transactionDO5 = new TransactionDO(); - transactionDO5.setQty(inLocation.getQty()); + transactionDO5.setQty(inQty); transactionDO5.setType(inLocation.getType()); list.add(transactionDO5); BigDecimal subtractInQty = qtyNew.subtract(inQty);//减去之后的数量 @@ -145,7 +150,7 @@ public interface ItemAccountsMapper extends BaseMapperX { result = this.updateById(newLocation); //添加库存事务 TransactionDO transactionDO6 = new TransactionDO(); - transactionDO6.setQty(newLocation.getQty()); + transactionDO6.setQty(subtractInQty); transactionDO6.setType(newLocation.getType()); list.add(transactionDO6); } else { @@ -159,7 +164,7 @@ public interface ItemAccountsMapper extends BaseMapperX { result = this.updateById(newLocation); //添加库存事务 TransactionDO transactionDO7 = new TransactionDO(); - transactionDO7.setQty(newLocation.getQty()); + transactionDO7.setQty(qtyNew); transactionDO7.setType(newLocation.getType()); list.add(transactionDO7); } else { @@ -173,7 +178,7 @@ public interface ItemAccountsMapper extends BaseMapperX { result = this.updateById(outLocation); //添加库存事务 TransactionDO transactionDO8 = new TransactionDO(); - transactionDO8.setQty(outLocation.getQty()); + transactionDO8.setQty(qtyNew); transactionDO8.setType(outLocation.getType()); list.add(transactionDO8); } @@ -189,8 +194,9 @@ public interface ItemAccountsMapper extends BaseMapperX { BigDecimal subtractNewQty = itemAccountsDO.getQty().subtract(qtyNew);//减去之后的数量 itemAccountsDO.setQty(subtractNewQty); result = this.updateById(itemAccountsDO); + //事务记录 TransactionDO transactionDO = new TransactionDO(); - transactionDO.setQty(subtractNewQty); + transactionDO.setQty(qtyNew); transactionDO.setType(itemAccountsDO.getType()); list.add(transactionDO); } @@ -204,6 +210,7 @@ public interface ItemAccountsMapper extends BaseMapperX { if (itemAccountsDO == null) {//不存在新增 itemAccountsDO = ItemAccountsConvert.INSTANCE.convert(param); result = this.insert(itemAccountsDO); + //库存事务 TransactionDO transactionDO = new TransactionDO(); transactionDO.setQty(itemAccountsDO.getQty()); transactionDO.setType(itemAccountsDO.getType()); @@ -212,6 +219,7 @@ public interface ItemAccountsMapper extends BaseMapperX { BigDecimal qty = itemAccountsDO.getQty(); BigDecimal add = qty.add(param.getQty()); itemAccountsDO.setQty(add); + //库存事务 result = updateById(itemAccountsDO); TransactionDO transactionDO = new TransactionDO(); transactionDO.setQty(itemAccountsDO.getQty()); diff --git a/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/service/itemaccounts/ItemAccountsServiceImpl.java b/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/service/itemaccounts/ItemAccountsServiceImpl.java index fdca236..e8ccb4a 100644 --- a/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/service/itemaccounts/ItemAccountsServiceImpl.java +++ b/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/service/itemaccounts/ItemAccountsServiceImpl.java @@ -77,6 +77,8 @@ public class ItemAccountsServiceImpl implements ItemAccountsService { validate(createReqVO.getItemNumber(),createReqVO.getLocationNumber());//校验库位是否被使用 long id = 0; List list = new ArrayList<>(); + validate(createReqVO.getItemNumber(), createReqVO.getLocationNumber());//校验非当前备件,库位相同是否存在存在即提醒 + validate1(createReqVO.getItemNumber(), createReqVO.getLocationNumber());//校验当前备件,非库位是否存在存在即提醒 //账内校验 ItemAccountsDO itemAccountsDO = validateItemAndTypeAndLocation(createReqVO.getItemNumber(), createReqVO.getType(), createReqVO.getLocationNumber()); @@ -172,7 +174,7 @@ public class ItemAccountsServiceImpl implements ItemAccountsService { //int i = itemAccountsMapper.updateById(itemAccountsDO1); //记录新到货转账内 //id = itemAccountsDO1.getId(); - itemNewTurnInDO.setType("3"); + itemNewTurnInDO.setType("2"); itemNewTurnInDO.setItemNumber(createReqVO.getItemNumber()); itemNewTurnInDO.setAreaNumber(createReqVO.getAreaNumber()); itemNewTurnInDO.setLocationNumber(createReqVO.getLocationNumber()); @@ -206,6 +208,20 @@ public class ItemAccountsServiceImpl implements ItemAccountsService { itemNewTurnInDO.setLocationNumber(itemAccounts.getLocationNumber()); itemNewTurnInDO.setNewQty(newqty); itemNewTurnInDO.setQty(newqty); + //添加库存事务 + TransactionCreateReqVO transactionCreateReqVO = new TransactionCreateReqVO(); + transactionCreateReqVO.setItemNumber(createReqVO.getItemNumber()); + transactionCreateReqVO.setLocationNumber(createReqVO.getLocationNumber()); + transactionCreateReqVO.setAreaNumber(createReqVO.getAreaNumber()); + transactionCreateReqVO.setTransactionType("IN"); + transactionCreateReqVO.setQty(createReqVO.getQty()); + transactionCreateReqVO.setDescribes("新到货转账内往账内添加数据");//描述 + transactionCreateReqVO.setOperator(null); + transactionCreateReqVO.setCreator(getLoginUserId().toString()); + transactionCreateReqVO.setAssociatedNumber(null); + transactionCreateReqVO.setInventoryAction(TransactionEnum.NEW_TURN_IN.getCode()); + transactionCreateReqVO.setType(ItemAccountStatusEnum.IN.getCode()); + list.add(transactionCreateReqVO); } //记录表 itemNewTurnInMapper.insert(itemNewTurnInDO); @@ -480,18 +496,26 @@ public class ItemAccountsServiceImpl implements ItemAccountsService { @Transactional public Integer replaceLocation(ItemAccountsDO accountsDO) { ItemAccountsDO itemAccountsDO = itemAccountsMapper.selectById(accountsDO.getId()); - if(accountsDO.getItemNumber().equals(itemAccountsDO.getItemNumber())){ + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("available", BooleanTypeEnum.Y.getCode()); + queryWrapper.eq("item_number", accountsDO.getItemNumber()); + List lists = itemAccountsMapper.selectList(queryWrapper); + if(!lists.isEmpty()){ + throw ServiceExceptionUtil.exception(ITEM_IS_HAVE); + } + if(accountsDO.getItemNumber().equals(itemAccountsDO.getItemNumber())){//判断是否更换的为同一个备件 throw ServiceExceptionUtil.exception(LOCATION_CAN_NOT_REPLACE2); } - //查询新备件在备件台账中是否存在 + BigDecimal allByLocation = getAllByLocation(accountsDO.getLocationNumber()); + if(allByLocation.compareTo(BigDecimal.ZERO)!=0){//该库位下有库存不能更换 + throw ServiceExceptionUtil.exception(LOCATION_COUNTS_EXISTS); + } + //查询该库位下所有数据 QueryWrapper itemAccountsDOQueryWrapper = new QueryWrapper<>(); itemAccountsDOQueryWrapper.eq("available", BooleanTypeEnum.Y.getCode()); - if (itemAccountsDO.getIsInAccount() != null) { - itemAccountsDOQueryWrapper.eq("is_in_account", itemAccountsDO.getIsInAccount()); - } - itemAccountsDOQueryWrapper.eq("item_number", accountsDO.getItemNumber()); + itemAccountsDOQueryWrapper.eq("location_number", itemAccountsDO.getLocationNumber()); List itemAccountsDOList = itemAccountsMapper.selectList(itemAccountsDOQueryWrapper); - if (itemAccountsDOList.size() == 0) { + for (ItemAccountsDO en:itemAccountsDOList) { //新增备件库位变更记录 ItemLocationReplaceDO itemLocationReplaceDO = new ItemLocationReplaceDO(); itemLocationReplaceDO.setItemNumber(accountsDO.getItemNumber()); @@ -499,26 +523,10 @@ public class ItemAccountsServiceImpl implements ItemAccountsService { itemLocationReplaceDO.setLocationNumber(accountsDO.getLocationNumber()); itemLocationReplaceDO.setCreateTime(LocalDateTime.now()); itemLocationReplaceMapper.insert(itemLocationReplaceDO); - //删除备件台账的数据 - itemAccountsMapper.deleteById(itemAccountsDO); - //新增一条备件台账(该库位下的) - ItemAccountsDO newItemAccountsDO = new ItemAccountsDO(); - newItemAccountsDO.setIsInAccount(itemAccountsDO.getIsInAccount()); - newItemAccountsDO.setItemNumber(accountsDO.getItemNumber()); - newItemAccountsDO.setLocationNumber(accountsDO.getLocationNumber()); - //根据库位查询库区 - QueryWrapper locationDOQueryWrapper = new QueryWrapper<>(); - locationDOQueryWrapper.eq("available", BooleanTypeEnum.Y.getCode()); - locationDOQueryWrapper.eq("number", accountsDO.getLocationNumber()); - LocationDO locationDO = locationMapper.selectOne(locationDOQueryWrapper); - newItemAccountsDO.setAreaNumber(locationDO.getAreaNumber()); + en.setItemNumber(accountsDO.getItemNumber()); //库位中新的备件数量是0 - newItemAccountsDO.setQty(BigDecimal.ZERO); - newItemAccountsDO.setCreateTime(LocalDateTime.now()); - newItemAccountsDO.setAvailable(BooleanTypeEnum.Y.getCode()); - itemAccountsMapper.insert(newItemAccountsDO); - } else { - throw ServiceExceptionUtil.exception(LOCATION_CAN_NOT_REPLACE); + en.setQty(BigDecimal.ZERO); + itemAccountsMapper.updateById(en); } return 1; } @@ -564,7 +572,7 @@ public class ItemAccountsServiceImpl implements ItemAccountsService { } /** - * 备件号和库位号是否存在 + * 非当前备件号和库位号是否存在 */ private void validate(String itemNumber,String locationNumber) { QueryWrapper queryWrapper = new QueryWrapper<>(); @@ -577,5 +585,19 @@ public class ItemAccountsServiceImpl implements ItemAccountsService { } } + /** + * 备件号和非库位号是否存在 + */ + private void validate1(String itemNumber,String locationNumber) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("item_number",itemNumber); + queryWrapper.ne("location_number",locationNumber); + queryWrapper.eq("available","TRUE"); + List itemAccountsDOS = itemAccountsMapper.selectList(queryWrapper); + if(!itemAccountsDOS.isEmpty()){ + throw exception(ITEM_EXISTS); + } + } + } diff --git a/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/service/transaction/TransactionServiceImpl.java b/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/service/transaction/TransactionServiceImpl.java index 8c744d5..dc2949a 100644 --- a/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/service/transaction/TransactionServiceImpl.java +++ b/win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/service/transaction/TransactionServiceImpl.java @@ -62,17 +62,18 @@ public class TransactionServiceImpl implements TransactionService { public Integer create(List createReqVOList) { int result = 0; for (TransactionCreateReqVO createReqVO : createReqVOList) { - TransactionDO transactionDO = TransactionConvert.INSTANCE.convert(createReqVO); + //生成单据号 QueryWrapper itemDOQueryWrapper = new QueryWrapper<>(); - itemDOQueryWrapper.eq("number", transactionDO.getItemNumber()); + itemDOQueryWrapper.eq("number", createReqVO.getItemNumber()); ItemDO itemDO = itemMapper.selectOne(itemDOQueryWrapper); - transactionDO.setUom(itemDO.getUom()); + createReqVO.setUom(itemDO.getUom()); //result += Mapper.insert(transactionDO); ItemAccountsCreateReqVO itemAccountsCreateReqVO = new ItemAccountsCreateReqVO(); - BeanUtils.copyProperties(transactionDO, itemAccountsCreateReqVO); - List transactionDOS = itemAccountsMapper.updateItemAccountsQty(itemAccountsCreateReqVO, transactionDO.getTransactionType(), transactionDO.getInventoryAction()); + BeanUtils.copyProperties(createReqVO, itemAccountsCreateReqVO); + List transactionDOS = itemAccountsMapper.updateItemAccountsQty(itemAccountsCreateReqVO, createReqVO.getTransactionType(), createReqVO.getInventoryAction()); for(TransactionDO en:transactionDOS){//循环出库存记录 + TransactionDO transactionDO = TransactionConvert.INSTANCE.convert(createReqVO); transactionDO.setType(en.getType()); transactionDO.setQty(en.getQty()); result += Mapper.insert(transactionDO);