浏览代码

出入库

koushanshan 2 年之前
父节点
当前提交
c0ff5f14c0

+ 27 - 5
src/main/java/com/dk/mdm/service/ivt/inbound/InboundCheckService.java

@@ -1,5 +1,8 @@
 package com.dk.mdm.service.ivt.inbound;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.dk.common.infrastructure.constant.Constant;
 import com.dk.common.infrastructure.enums.ErrorCodeEnum;
 import com.dk.common.mapper.BaseMapper;
@@ -22,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 
@@ -66,7 +70,24 @@ public class InboundCheckService extends BaseService<Inbound> {
 	 * @author : 寇珊珊
 	 */
 	@Transactional(rollbackFor = {Exception.class})
-	public ResponseResultVO<?> checkInboundInsert(InboundVO inboundVO) {
+	public ResponseResultVO<?> checkInboundInsert(Map<String, Object> map) {
+		//region map转json
+		JSONObject total = new JSONObject();
+		JSONArray detail = new JSONArray();
+		//总单
+		if (map.get("total") != null) {
+			total = (JSONObject) JSON.toJSON(map.get("total"));
+		}
+		//明细
+		if (map.get("total") != null) {
+			detail = (JSONArray) JSON.toJSON(map.get("detail"));
+		}
+		InboundVO inboundVO = new InboundVO();
+		inboundVO = total.toJavaObject(InboundVO.class);
+		List<InboundItemVO> inboundItemVOList = detail.toJavaList(InboundItemVO.class);
+		inboundVO.setItemList(inboundItemVOList);
+		//endregion
+
 		//region  总单
 		//获取 id/单号
 		Map<String , Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.INVENTORYPROFITINBOUND.getName(),false);
@@ -100,6 +121,7 @@ public class InboundCheckService extends BaseService<Inbound> {
 			inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.INVENTORY_PROFIT.getValue());
 			//endregion
 
+
 			//总单id
 			inboundItemVO.setIntoId(inboundVO.getIntoId());
 			//入库类型
@@ -124,9 +146,9 @@ public class InboundCheckService extends BaseService<Inbound> {
 		//endregion
 
 		//region 修改库存
-		Map<String, Object> map = new HashMap<>();
-		map.put("intoDetail", inboundVO.getItemList());
-		inventoryService.updateInventoryInformation(map);
+//		Map<String, Object> invMap = new HashMap<>();
+//		invMap.put("intoDetail", inboundVO.getItemList());
+//		inventoryService.updateInventoryInformation(invMap);
 		//endregion
 
 		return ResponseResultUtil.success(inboundVO);
@@ -142,7 +164,7 @@ public class InboundCheckService extends BaseService<Inbound> {
 		//入库状态
 		String intoStatus = null;
 		//已入库数量>0 入库中数量>0
-		if (intoQty.compareTo(BigDecimal.ZERO) > 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0 ) {
+		if (intoQty.compareTo(BigDecimal.ZERO) >= 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0 ) {
 			//入库中
 			intoStatus = Constant.IntoStatus.RUKUZHONG.getName();
 		}

+ 18 - 23
src/main/java/com/dk/mdm/service/ivt/inbound/InboundOtherService.java

@@ -222,11 +222,6 @@ public class InboundOtherService extends BaseService<Inbound> {
 	 */
 	@Transactional(rollbackFor = {Exception.class})
 	public ResponseResultVO<?> otherInboundUpdate(InboundVO inboundVO) {
-		// 办理参数为false 并且 自动办理为false
-		if(!inboundVO.getFlgHandleSetting() && !inboundVO.getFlgAutoHandle()){
-			return ResponseResultUtil.error(ErrorCodeEnum.WITHDRAWING_FROM_WAREHOUSE.getCode(),
-					ErrorCodeEnum.WITHDRAWING_FROM_WAREHOUSE.getMessage());
-		}
 		//region 明细数量金额  求和
 		BigDecimal sumQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
 		BigDecimal sumAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
@@ -279,13 +274,10 @@ public class InboundOtherService extends BaseService<Inbound> {
 			);
 			//endregion
 
-
 			//region  todo调用库存
-//            if(Constant.IntoStatus.YIRUKU.getName().equals(inboundResponse.getIntoStatus())){
-//                Map<String, Object> map = new HashMap<>();
-//                map.put("intoDetail",inboundVO.getItemList());
-//                inventoryService.updateInventoryInformation(map);
-//            }
+			Map<String, Object> map = new HashMap<>();
+			map.put("intoDetail", inboundVO.getItemList());
+			inventoryService.updateInventoryInformation(map);
 			//endregion
 		}
 		//endregion
@@ -378,10 +370,10 @@ public class InboundOtherService extends BaseService<Inbound> {
 			);
 			//endregion
 
-			//region  todo 调用库存
-//                Map<String, Object> map = new HashMap<>();
-//                map.put("intoDetail",inboundItemResponseList);
-//                inventoryService.updateInventoryInformation(map);
+			//region
+			Map<String, Object> map = new HashMap<>();
+			map.put("intoDetail", inboundItemResponseList);
+			inventoryService.updateInventoryInformation(map);
 			//endregion
 		}
 		//endregion
@@ -421,7 +413,6 @@ public class InboundOtherService extends BaseService<Inbound> {
 	}
 
 
-
 	/**
 	 * @desc   : 其他入库办理
 	 * @date   : 2024/3/7 15:47
@@ -440,9 +431,17 @@ public class InboundOtherService extends BaseService<Inbound> {
 			inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
 			inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.getValue());
 			//endregion
+			//region  修改明细
 			if (inboundItemVO.getIntoId() != null) {
 				InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
-				//编辑明细
+				//region 校验数量是否超出
+				if (inboundItemVO.getIntoingQty().compareTo(inboundItemResponse.getIntoQty()) > 0) {
+					return ResponseResultUtil.error(ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITY_IN_THE_OUTBOUND_SHIPMENT.getCode(),
+							ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITY_IN_THE_OUTBOUND_SHIPMENT.getMessage());
+				}
+				//endregion
+
+				//region 编辑明细
 				inboundItemVO
 						.setIntoQty(inboundItemResponse.getIntoQty().add(inboundItemVO.getIntoingQty()))
 						.setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt()))
@@ -461,6 +460,7 @@ public class InboundOtherService extends BaseService<Inbound> {
 						new UpdateWrapper<InboundItem>().lambda()
 								.eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
 				);
+				//endregion
 			}
 			//endregion
 
@@ -484,6 +484,7 @@ public class InboundOtherService extends BaseService<Inbound> {
 				//新建
 				inboundItemMapper.insert(inboundItem);
 			}
+			//endregion
 		}
 		//endregion
 
@@ -522,7 +523,6 @@ public class InboundOtherService extends BaseService<Inbound> {
 		);
 		//endregion
 
-		//todo 如果是已入库 调用库存  后续写库存这里补上
 		//region 修改库存
 		Map<String, Object> map = new HashMap<>();
 		map.put("intoDetail", inboundVO.getItemList());
@@ -539,11 +539,6 @@ public class InboundOtherService extends BaseService<Inbound> {
 	 */
 	@Transactional(rollbackFor = {Exception.class})
 	public ResponseResultVO<?> otherInboundCancel(InboundVO inboundVO) {
-		// 办理参数为true
-		if(inboundVO.getFlgHandleSetting()){
-			return ResponseResultUtil.error(ErrorCodeEnum.UNABLE_TO_RECALL.getCode(),
-					ErrorCodeEnum.UNABLE_TO_RECALL.getMessage());
-		}
 		//region 总单数据信息
 		InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
 		Inbound inbound = new Inbound();

+ 67 - 52
src/main/java/com/dk/mdm/service/ivt/inbound/InboundPurchaseReturnService.java

@@ -35,6 +35,7 @@ import com.dk.mdm.model.vo.ivt.InboundVO;
 import com.dk.mdm.model.vo.ivt.OutboundItemVO;
 import com.dk.mdm.service.common.CommonService;
 import com.dk.mdm.service.ivt.inventory.InventoryService;
+import com.dk.mdm.service.mac.AccountService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -80,6 +81,9 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
     @Autowired
     private InventoryService inventoryService;
 
+    @Autowired
+    private AccountService accountService;
+
 
     /**
      * @desc : 条件查询
@@ -124,7 +128,7 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
         //自动办理标识
         String flgHandleSetting = commonMapper.getSettingValue(map);
         //自动办理标识为1 自动办理入库
-        if(Constant.FlgAutoHandleStringType.ONE.getValue().equals(flgHandleSetting)){
+        if (Constant.FlgAutoHandleStringType.ONE.getValue().equals(flgHandleSetting)) {
             inboundVO.setFlgHandleSetting(Constant.FlgHandleSetting.TRUE.getValue());
             inboundVO.setFlgAutoHandle(Constant.FlgAutoHandle.TRUE.getValue());
         }
@@ -210,12 +214,11 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
         }
         //endregion
 
-        //region 已入库调用账款 todo
-//        if(Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus()){
-//
-//        }
-        //endregio
-
+        //region 已入库调用账款
+        if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
+            accountService.accPayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
+        }
+        //endregion
 
         //region 库存
 //        if(Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())){
@@ -244,9 +247,9 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
         //region  自动办理参数为true  已入库编辑
         //自动办理参数为true
         if (Constant.FlgHandleSetting.TRUE.getValue().equals(inboundVO.getFlgHandleSetting())) {
-            //region   todo  退账 当单据红的账款id不为空说明有账, 要先退账才能进行操作
+            //region 退账
             if (inboundVO.getReceivableId() != null) {
-
+                accountService.reversePayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
             }
             //endregion
 
@@ -294,13 +297,13 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
             );
             //endregion
 
-            //region   todo  入账 当单据红的账款id不为空说明有账, 最后要入账
+            //region  账款
             if (inboundVO.getReceivableId() != null) {
-
+                accountService.accPayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
             }
             //endregion
 
-            //region  todo调用库存
+            //region  todo 调用库存
 //                Map<String, Object> map = new HashMap<>();
 //                map.put("intoDetail",inboundVO.getItemList());
 //                inventoryService.updateInventoryInformation(map);
@@ -343,8 +346,8 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
     }
 
     /**
-     * @desc   : 采购退货入库作废
-     * @date   : 2024/3/26 9:24
+     * @desc : 采购退货入库作废
+     * @date : 2024/3/26 9:24
      * @author : 寇珊珊
      */
     @Transactional(rollbackFor = {Exception.class})
@@ -359,9 +362,9 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
         //region  自动办理参数为true  已入库编辑
         //自动办理参数为true
         if (Constant.FlgHandleSetting.TRUE.getValue().equals(inboundResponse.getFlgHandleSetting())) {
-            //region   todo  退账 当单据红的账款id不为空说明有账, 要先退账才能进行操作
+            //region 退账
             if (inboundResponse.getReceivableId() != null) {
-
+                accountService.reversePayable(inboundResponse.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
             }
             //endregion
 
@@ -396,13 +399,13 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
             );
             //endregion
 
-
-            //region   todo  入账 当单据红的账款id不为空说明有账, 最后要入账
+            //region  账款
             if (inboundResponse.getReceivableId() != null) {
-
+                accountService.accPayable(inboundResponse.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
             }
             //endregion
 
+
             //region  todo 调用库存
 //                Map<String, Object> map = new HashMap<>();
 //                map.put("intoDetail",inboundItemResponseList);
@@ -447,7 +450,6 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
     }
 
 
-
     /**
      * @desc : 采购退货入库办理
      * @date : 2024/3/7 15:47
@@ -464,32 +466,35 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
         for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
             //查询原单
             InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
-            if (inboundItemVO.getIntoId() != null) {
-                //region 将库存需要的参数赋值
-                inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName());
-                inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_RETURN.getValue());
-                //endregion
-
-                //编辑明细
-                inboundItemVO
-                        .setIntoQty(inboundItemResponse.getIntoingQty().add(inboundItemVO.getIntoingQty()))
-                        .setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt()))
-                        .setIntoingQty(BigDecimal.ZERO)
-                        .setIntoAmt(BigDecimal.ZERO)
-                        .setCostPrice(inboundItemVO.getPriceInto())
-                        .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP));
-                //入库状态
-                String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
-                inboundItemVO.setIntoStatus(intoStatus);
-                //实体转换
-                InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
-                //修改
-                inboundItemMapper.update(inboundItem,
-                        new UpdateWrapper<InboundItem>().lambda()
-                                .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
-                );
+            //region 校验数量是否超出
+            if (inboundItemVO.getIntoingQty().compareTo(inboundItemResponse.getIntoQty()) > 0) {
+                return ResponseResultUtil.error(ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITY_IN_THE_OUTBOUND_SHIPMENT.getCode(),
+                        ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITY_IN_THE_OUTBOUND_SHIPMENT.getMessage());
             }
             //endregion
+            //region 将库存需要的参数赋值
+            inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName());
+            inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_RETURN.getValue());
+            //endregion
+            //region 编辑明细
+            inboundItemVO
+                    .setIntoQty(inboundItemResponse.getIntoingQty().add(inboundItemVO.getIntoingQty()))
+                    .setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt()))
+                    .setIntoingQty(BigDecimal.ZERO)
+                    .setIntoAmt(BigDecimal.ZERO)
+                    .setCostPrice(inboundItemVO.getPriceInto())
+                    .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP));
+            //入库状态
+            String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
+            inboundItemVO.setIntoStatus(intoStatus);
+            //实体转换
+            InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
+            //修改
+            inboundItemMapper.update(inboundItem,
+                    new UpdateWrapper<InboundItem>().lambda()
+                            .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
+            );
+            //endregion
         }
         //endregion
 
@@ -529,12 +534,11 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
         );
         //endregion
 
-
-        //region todo  调用账款
-
+        //region  账款
+        accountService.accPayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
         //endregion
 
-        //region  todo 调用库存 这里后续把删除的明细也加上
+        //region  todo 调用库存
 //                Map<String, Object> map = new HashMap<>();
 //                map.put("intoDetail",inboundVO.getItemList());
 //                inventoryService.updateInventoryInformation(map);
@@ -555,6 +559,12 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
         InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
         //endregion
 
+        //region 退账
+        if (inboundVO.getReceivableId() != null) {
+            accountService.reversePayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
+        }
+        //endregion
+
         //region 修改总单数据信息
         Inbound inbound = new Inbound();
         inbound.setIntoId(inboundVO.getIntoId());
@@ -605,6 +615,12 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
         //endregion
 
 
+        //region  账款
+        if (inboundVO.getReceivableId() != null) {
+            accountService.accPayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
+        }
+        //endregion
+
         //region  todo 调用库存
 //                Map<String, Object> map = new HashMap<>();
 //                map.put("intoDetail",inboundItemResponseList);
@@ -643,8 +659,8 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
 
 
     /**
-     * @desc   : 获取单据信息(编辑用)
-     * @date   : 2024/3/16 16:28
+     * @desc : 获取单据信息(编辑用)
+     * @date : 2024/3/16 16:28
      * @author : 寇珊珊
      */
     public ResponseResultVO<?> selectByUpdate(String id) {
@@ -652,7 +668,7 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
         //总单
         InboundResponse inboundResponse = inboundMapper.selectMessageByOtherQuery(new InboundQuery().setIntoId(id).setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName()));
         //单据不存在
-        if(inboundResponse==null){
+        if (inboundResponse == null) {
             return ResponseResultUtil.error(ErrorCodeEnum.THERE_ORDER_IS_NOT_CAN_INBOUND_QUANTITY.getCode(),
                     ErrorCodeEnum.THERE_ORDER_IS_NOT_CAN_INBOUND_QUANTITY.getMessage());
         }
@@ -664,5 +680,4 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
     }
 
 
-
 }

+ 75 - 69
src/main/java/com/dk/mdm/service/ivt/inbound/InboundPurchaseService.java

@@ -7,6 +7,7 @@ import com.dk.common.infrastructure.constant.Constant;
 import com.dk.common.infrastructure.enums.ErrorCodeEnum;
 import com.dk.common.mapper.BaseMapper;
 import com.dk.common.model.pojo.PageList;
+import com.dk.common.model.vo.AnnexVO;
 import com.dk.common.response.ResponseCodeEnum;
 import com.dk.common.response.ResponseResultUtil;
 import com.dk.common.response.ResponseResultVO;
@@ -32,6 +33,7 @@ import com.dk.mdm.model.vo.ivt.InboundItemVO;
 import com.dk.mdm.model.vo.ivt.InboundVO;
 import com.dk.mdm.service.common.CommonService;
 import com.dk.mdm.service.ivt.inventory.InventoryService;
+import com.dk.mdm.service.mac.AccountService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -83,7 +85,8 @@ public class InboundPurchaseService extends BaseService<Inbound> {
     @Autowired
     private InventoryService inventoryService;
 
-
+    @Autowired
+    private AccountService accountService;
 
 
     /**
@@ -130,7 +133,7 @@ public class InboundPurchaseService extends BaseService<Inbound> {
         //自动办理标识
         String flgHandleSetting = commonMapper.getSettingValue(map);
         //自动办理标识为1 自动办理入库
-        if(Constant.FlgAutoHandleStringType.ONE.getValue().equals(flgHandleSetting)){
+        if (Constant.FlgAutoHandleStringType.ONE.getValue().equals(flgHandleSetting)) {
             inboundVO.setFlgHandleSetting(Constant.FlgHandleSetting.TRUE.getValue());
             inboundVO.setFlgAutoHandle(Constant.FlgAutoHandle.TRUE.getValue());
         }
@@ -274,10 +277,10 @@ public class InboundPurchaseService extends BaseService<Inbound> {
         }
         //endregion
 
-        //region 已入库调用账款 todo
-//        if(Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus()){
-//
-//        }
+        //region 已入库调用账款
+        if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
+            accountService.accPayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
+        }
         //endregion
 
         //region 库存
@@ -308,9 +311,9 @@ public class InboundPurchaseService extends BaseService<Inbound> {
         //region  自动办理参数为true  已入库编辑
         //自动办理参数为true
         if (Constant.FlgHandleSetting.TRUE.getValue().equals(inboundVO.getFlgHandleSetting())) {
-            //region   todo  退账 当单据红的账款id不为空说明有账, 要先退账才能进行操作
+            //region 退账
             if (inboundVO.getReceivableId() != null) {
-
+                accountService.reversePayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
             }
             //endregion
 
@@ -385,18 +388,16 @@ public class InboundPurchaseService extends BaseService<Inbound> {
             }
             //endregion
 
-            //region   todo  入账 当单据红的账款id不为空说明有账, 最后要入账
+            //region  账款
             if (inboundVO.getReceivableId() != null) {
-
+                accountService.accPayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
             }
             //endregion
 
             //region  todo调用库存
-//            if(Constant.IntoStatus.YIRUKU.getName().equals(inboundResponse.getIntoStatus())){
 //                Map<String, Object> map = new HashMap<>();
 //                map.put("intoDetail",inboundVO.getItemList());
 //                inventoryService.updateInventoryInformation(map);
-//            }
             //endregion
         }
         //endregion
@@ -436,6 +437,7 @@ public class InboundPurchaseService extends BaseService<Inbound> {
                 //endregion
             }
             //endregion
+
             //region  修改入库总单
             Inbound inbound = new Inbound();
             inbound.setIntoId(inboundVO.getIntoId());
@@ -446,6 +448,7 @@ public class InboundPurchaseService extends BaseService<Inbound> {
                     new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
             );
             //endregion
+
             //region 修改采购总单
             Purchase purchase = new Purchase();
             purchase.setPurId(inboundVO.getFromId());
@@ -465,8 +468,8 @@ public class InboundPurchaseService extends BaseService<Inbound> {
     }
 
     /**
-     * @desc   : 采购入库作废
-     * @date   : 2024/3/26 9:24
+     * @desc : 采购入库作废
+     * @date : 2024/3/26 9:24
      * @author : 寇珊珊
      */
     @Transactional(rollbackFor = {Exception.class})
@@ -481,9 +484,9 @@ public class InboundPurchaseService extends BaseService<Inbound> {
         //region  自动办理参数为true  已入库编辑
         //自动办理参数为true
         if (Constant.FlgHandleSetting.TRUE.getValue().equals(inboundResponse.getFlgHandleSetting())) {
-            //region   todo  退账 当单据红的账款id不为空说明有账, 要先退账才能进行操作
+            //region 退账
             if (inboundResponse.getReceivableId() != null) {
-
+                accountService.reversePayable(inboundResponse.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
             }
             //endregion
 
@@ -546,9 +549,9 @@ public class InboundPurchaseService extends BaseService<Inbound> {
             }
             //endregion
 
-            //region   todo  入账 当单据红的账款id不为空说明有账, 最后要入账
+            //region  账款
             if (inboundResponse.getReceivableId() != null) {
-
+                accountService.accPayable(inboundResponse.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
             }
             //endregion
 
@@ -639,53 +642,56 @@ public class InboundPurchaseService extends BaseService<Inbound> {
         for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
             //入库明细根据id查询
             InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
-            if (inboundItemVO.getIntoId() != null) {
-                //region 将库存需要的参数赋值
-                inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName());
-                inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
-                //endregion
-
-                //region 采购明细
-                //根据id查询
-                PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
-                //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
-                PurchaseItem purchaseItem = new PurchaseItem();
-                purchaseItem.setItemId(inboundItemVO.getFromItemId());
-                purchaseItem.setIntoingQty(inboundItemResponse.getIntoingQty().negate());
-                purchaseItem.setIntoingAmt(inboundItemResponse.getIntoingAmt().negate());
-                purchaseItem.setIntoQty(inboundItemVO.getIntoQty());
-                purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt());
-                //入库状态
-                String purItemIntoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
-                        purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()));
-                purchaseItem.setIntoStatus(purItemIntoStatus);
-                int countRow = purchaseItemMapper.updateById(purchaseItem);
-                //数量超出
-                if (countRow == 0) {
-                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
-                }
-                //endregion
-                //region 编辑入库明细
-                inboundItemVO
-                        .setIntoQty(inboundItemResponse.getIntoQty().add(inboundItemVO.getIntoingQty()))
-                        .setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt()))
-                        .setIntoingQty(BigDecimal.ZERO)
-                        .setIntoingAmt(BigDecimal.ZERO)
-                        .setCostPrice(inboundItemVO.getPriceInto())
-                        .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
-                ;
-                //入库状态
-                String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
-                inboundItemVO.setIntoStatus(intoStatus);
-                //实体转换
-                InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
-                //修改
-                inboundItemMapper.update(inboundItem,
-                        new UpdateWrapper<InboundItem>().lambda()
-                                .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
-                );
-                //endregion
+            //region 校验数量是否超出
+            if (inboundItemVO.getIntoingQty().compareTo(inboundItemResponse.getIntoQty()) > 0) {
+                return ResponseResultUtil.error(ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITY_IN_THE_OUTBOUND_SHIPMENT.getCode(),
+                        ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITY_IN_THE_OUTBOUND_SHIPMENT.getMessage());
             }
+            //endregion
+            //region 将库存需要的参数赋值
+            inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName());
+            inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
+            //endregion
+            //region 采购明细
+            //根据id查询
+            PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
+            //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
+            PurchaseItem purchaseItem = new PurchaseItem();
+            purchaseItem.setItemId(inboundItemVO.getFromItemId());
+            purchaseItem.setIntoingQty(inboundItemResponse.getIntoingQty().negate());
+            purchaseItem.setIntoingAmt(inboundItemResponse.getIntoingAmt().negate());
+            purchaseItem.setIntoQty(inboundItemVO.getIntoQty());
+            purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt());
+            //入库状态
+            String purItemIntoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
+                    purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()));
+            purchaseItem.setIntoStatus(purItemIntoStatus);
+            int countRow = purchaseItemMapper.updateById(purchaseItem);
+            //数量超出
+            if (countRow == 0) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+            }
+            //endregion
+            //region 编辑入库明细
+            inboundItemVO
+                    .setIntoQty(inboundItemResponse.getIntoQty().add(inboundItemVO.getIntoingQty()))
+                    .setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt()))
+                    .setIntoingQty(BigDecimal.ZERO)
+                    .setIntoingAmt(BigDecimal.ZERO)
+                    .setCostPrice(inboundItemVO.getPriceInto())
+                    .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
+            ;
+            //入库状态
+            String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
+            inboundItemVO.setIntoStatus(intoStatus);
+            //实体转换
+            InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
+            //修改
+            inboundItemMapper.update(inboundItem,
+                    new UpdateWrapper<InboundItem>().lambda()
+                            .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
+            );
+            //endregion
         }
         //endregion
 
@@ -774,8 +780,8 @@ public class InboundPurchaseService extends BaseService<Inbound> {
         }
         //endregion
 
-        //region todo  调用账款
-
+        //region  账款
+        accountService.accPayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
         //endregion
 
         //region  todo 调用库存 这里后续把删除的明细也加上
@@ -800,9 +806,9 @@ public class InboundPurchaseService extends BaseService<Inbound> {
         InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
         //endregion
 
-        //region   todo  退账 当单据红的账款id不为空说明有账, 要先退账才能进行操作
-        if (inboundResponse.getReceivableId() != null) {
-
+        //region 退账
+        if (inboundVO.getReceivableId() != null) {
+            accountService.reversePayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
         }
         //endregion
 

+ 25 - 2
src/main/java/com/dk/mdm/service/ivt/outbound/OutboundCheckService.java

@@ -1,5 +1,8 @@
 package com.dk.mdm.service.ivt.outbound;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.dk.common.infrastructure.constant.Constant;
 import com.dk.common.infrastructure.enums.ErrorCodeEnum;
 import com.dk.common.mapper.BaseMapper;
@@ -12,6 +15,7 @@ import com.dk.mdm.mapper.ivt.OutboundItemMapper;
 import com.dk.mdm.mapper.ivt.OutboundMapper;
 import com.dk.mdm.model.pojo.ivt.Outbound;
 import com.dk.mdm.model.pojo.ivt.OutboundItem;
+import com.dk.mdm.model.vo.ivt.InOutRecordVO;
 import com.dk.mdm.model.vo.ivt.OutboundItemVO;
 import com.dk.mdm.model.vo.ivt.OutboundVO;
 import com.dk.mdm.service.common.CommonService;
@@ -21,6 +25,8 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 
@@ -62,7 +68,24 @@ public class OutboundCheckService extends BaseService<Outbound> {
      * @author : 寇珊珊
      */
     @Transactional(rollbackFor = {Exception.class})
-    public ResponseResultVO<?> otherOutboundInsert(OutboundVO outboundVO) {
+    public ResponseResultVO<?> otherOutboundInsert(Map<String, Object> map) {
+        //region map转json
+        JSONObject total = new JSONObject();
+        JSONArray detail = new JSONArray();
+        //总单
+        if (map.get("total") != null) {
+            total = (JSONObject) JSON.toJSON(map.get("total"));
+        }
+        //明细
+        if (map.get("total") != null) {
+            detail = (JSONArray) JSON.toJSON(map.get("detail"));
+        }
+        OutboundVO outboundVO = new OutboundVO();
+        outboundVO = total.toJavaObject(OutboundVO.class);
+        List<OutboundItemVO> outboundItemVOList = detail.toJavaList(OutboundItemVO.class);
+        outboundVO.setItemList(outboundItemVOList);
+        //endregion
+
         //region  总单
         //获取 id/单号
         Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.INVENTORYLOSEOUTBOUND.getName(), false);
@@ -140,7 +163,7 @@ public class OutboundCheckService extends BaseService<Outbound> {
         //出库状态
         String outStatus = null;
         //已出库数量<0 出库中数量<0
-        if (outQty.compareTo(BigDecimal.ZERO) < 0 && outingQty.compareTo(BigDecimal.ZERO) < 0) {
+        if (outQty.compareTo(BigDecimal.ZERO) <= 0 && outingQty.compareTo(BigDecimal.ZERO) < 0) {
             //出库中
             outStatus = Constant.OutStatus.CHUKUZHONG.getName();
         }

+ 23 - 41
src/main/java/com/dk/mdm/service/ivt/outbound/OutboundOtherService.java

@@ -14,19 +14,13 @@ import com.dk.mdm.infrastructure.convert.ivt.OutboundItemConvert;
 import com.dk.mdm.mapper.common.CommonMapper;
 import com.dk.mdm.mapper.ivt.OutboundItemMapper;
 import com.dk.mdm.mapper.ivt.OutboundMapper;
-import com.dk.mdm.model.pojo.ivt.Inbound;
-import com.dk.mdm.model.pojo.ivt.InboundItem;
 import com.dk.mdm.model.pojo.ivt.Outbound;
 import com.dk.mdm.model.pojo.ivt.OutboundItem;
-import com.dk.mdm.model.query.ivt.InboundItemQuery;
 import com.dk.mdm.model.query.ivt.OutboundItemQuery;
 import com.dk.mdm.model.query.ivt.OutboundQuery;
-import com.dk.mdm.model.response.ivt.InboundItemResponse;
 import com.dk.mdm.model.response.ivt.InboundResponse;
 import com.dk.mdm.model.response.ivt.OutboundItemResponse;
 import com.dk.mdm.model.response.ivt.OutboundResponse;
-import com.dk.mdm.model.vo.ivt.InboundItemVO;
-import com.dk.mdm.model.vo.ivt.InboundVO;
 import com.dk.mdm.model.vo.ivt.OutboundItemVO;
 import com.dk.mdm.model.vo.ivt.OutboundVO;
 import com.dk.mdm.service.common.CommonService;
@@ -70,7 +64,6 @@ public class OutboundOtherService extends BaseService<Outbound> {
     @Autowired
     private OutboundItemConvert outboundItemConvert;
 
-
     @Autowired
     private CommonMapper commonMapper;
 
@@ -78,7 +71,6 @@ public class OutboundOtherService extends BaseService<Outbound> {
     private InventoryService inventoryService;
 
 
-
     /**
      * @desc : 条件查询
      * @date : 2024/3/18 11:20
@@ -206,17 +198,11 @@ public class OutboundOtherService extends BaseService<Outbound> {
         }
         //endregion
 
-        //region  已出库  账款
-        if(Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())){
-
-        }
-        //endregion
-
         //region 修改库存
         if(Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())){
-//            Map<String, Object> invMap = new HashMap<>();
-//            invMap.put("outDetail",outboundVO.getItemList());
-//            inventoryService.updateInventoryInformation(invMap);
+            Map<String, Object> invMap = new HashMap<>();
+            invMap.put("outDetail",outboundVO.getItemList());
+            inventoryService.updateInventoryInformation(invMap);
         }
         //endregion
 
@@ -231,11 +217,6 @@ public class OutboundOtherService extends BaseService<Outbound> {
      */
     @Transactional(rollbackFor = {Exception.class})
     public ResponseResultVO<?> otherOutboundUpdate(OutboundVO outboundVO) {
-        // 办理参数为false 并且 自动办理为false
-        if(!outboundVO.getFlgHandleSetting() && !outboundVO.getFlgAutoHandle()){
-            return ResponseResultUtil.error(ErrorCodeEnum.WITHDRAWING_FROM_WAREHOUSE.getCode(),
-                    ErrorCodeEnum.WITHDRAWING_FROM_WAREHOUSE.getMessage());
-        }
         //region 明细数量金额  求和
         BigDecimal sumQty = outboundVO.getItemList().stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
         BigDecimal sumAmt = outboundVO.getItemList().stream().map(OutboundItemVO::getOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
@@ -287,12 +268,11 @@ public class OutboundOtherService extends BaseService<Outbound> {
             );
             //endregion
 
-
             //region 修改库存
             if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
-//                Map<String, Object> invMap = new HashMap<>();
-//                invMap.put("outDetail", outboundVO.getItemList());
-//                inventoryService.updateInventoryInformation(invMap);
+                Map<String, Object> invMap = new HashMap<>();
+                invMap.put("outDetail", outboundVO.getItemList());
+                inventoryService.updateInventoryInformation(invMap);
             }
             //endregion
         }
@@ -346,14 +326,10 @@ public class OutboundOtherService extends BaseService<Outbound> {
         List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(outboundResponse.getOutId()));
         //endregion
 
+
         //region  自动办理参数为true  已出库编辑
         //自动办理参数为true
         if (Constant.FlgHandleSetting.TRUE.getValue().equals(outboundResponse.getFlgHandleSetting())) {
-            //region   todo  退账 当单据红的账款id不为空说明有账, 要先退账才能进行操作
-            if (outboundResponse.getReceivableId() != null) {
-
-            }
-            //endregion
 
             //region 修改明细
             for (OutboundItemResponse outboundItemResponse : outboundItemResponseList) {
@@ -387,9 +363,9 @@ public class OutboundOtherService extends BaseService<Outbound> {
             //endregion
 
             //region  修改库存
-//                Map<String, Object> map = new HashMap<>();
-//                map.put("outDetail",outboundItemResponseList);
-//                inventoryService.updateInventoryInformation(map);
+            Map<String, Object> map = new HashMap<>();
+            map.put("outDetail", outboundItemResponseList);
+            inventoryService.updateInventoryInformation(map);
             //endregion
         }
         //endregion
@@ -443,14 +419,21 @@ public class OutboundOtherService extends BaseService<Outbound> {
                     ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getMessage());
         }
         for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
+            //查询原单
+            OutboundItemResponse outboundItemResponse = outboundItemMapper.selectById(outboundItemVO.getItemId());
+            //region 校验数量是否超出
+            if(outboundItemVO.getOutingQty().compareTo(outboundItemResponse.getOutQty()) > 0){
+                return ResponseResultUtil.error(ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITYIN_THE_WAREHOUSE.getCode(),
+                        ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITYIN_THE_WAREHOUSE.getMessage());
+            }
+            //endregion
+
             if (outboundItemVO.getItemId() != null) {
                 //region 将库存需要的参数赋值
                 outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
                 outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.OTHER_OUTBOUND.getValue());
                 //endregion
 
-                //查询原单
-                OutboundItemResponse outboundItemResponse = outboundItemMapper.selectById(outboundItemVO.getItemId());
                 //编辑明细
                 outboundItemVO
                         .setOutQty(outboundItemResponse.getOutQty().add(outboundItemVO.getOutingQty()))
@@ -494,7 +477,7 @@ public class OutboundOtherService extends BaseService<Outbound> {
         }
         //endregion
 
-        //region 删除明细 todo 2024年3月20日13:16:22 这里可能用不到
+        //region 删除明细
         if (outboundVO.getDeleteItemList() != null) {
          for (OutboundItemVO outboundItemVO : outboundVO.getDeleteItemList()) {
                 if (outboundItemVO.getItemId() != null) {
@@ -532,9 +515,9 @@ public class OutboundOtherService extends BaseService<Outbound> {
 
 
         //region 修改库存
-//        Map<String, Object> map = new HashMap<>();
-//        map.put("outDetail", outboundVO.getItemList());
-//        inventoryService.updateInventoryInformation(map);
+        Map<String, Object> map = new HashMap<>();
+        map.put("outDetail", outboundVO.getItemList());
+        inventoryService.updateInventoryInformation(map);
         //endregion
 
         return ResponseResultUtil.success(outboundVO);
@@ -599,7 +582,6 @@ public class OutboundOtherService extends BaseService<Outbound> {
         }
         //endregion
 
-
         //region 修改库存
         Map<String, Object> map = new HashMap<>();
         map.put("outDetail", outboundItemResponseList);

+ 75 - 76
src/main/java/com/dk/mdm/service/ivt/outbound/OutboundSaleOrderService.java

@@ -45,6 +45,7 @@ import com.dk.mdm.model.vo.ivt.OutboundItemVO;
 import com.dk.mdm.model.vo.ivt.OutboundVO;
 import com.dk.mdm.service.common.CommonService;
 import com.dk.mdm.service.ivt.inventory.InventoryService;
+import com.dk.mdm.service.mac.AccountService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -101,6 +102,9 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
     
     @Autowired
     private MultiOwnerMapper multiOwnerMapper;
+
+    @Autowired
+    private AccountService  accountService;
     
 
     /**
@@ -274,10 +278,10 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
         }
         //endregion
 
-        //region 已入库调用账款 todo
-//        if(Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus()){
-//
-//        }
+        //region  已出库  账款
+        if(Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())){
+            accountService.accPayable(outboundVO.getOutId(),Constant.InventoryDocCode.OUTBOUND.getTableName());
+        }
         //endregion
 
         //region 库存
@@ -367,11 +371,6 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
      */
     @Transactional(rollbackFor = {Exception.class})
     public ResponseResultVO<?> saleOutboundUpdate(OutboundVO outboundVO) {
-        // 办理参数为false 并且 自动办理为false
-        if (!outboundVO.getFlgHandleSetting() && !outboundVO.getFlgAutoHandle()) {
-            return ResponseResultUtil.error(ErrorCodeEnum.WITHDRAWING_FROM_WAREHOUSE.getCode(),
-                    ErrorCodeEnum.WITHDRAWING_FROM_WAREHOUSE.getMessage());
-        }
         //region 根据id查询   并且明细数量金额  求和
         OutboundResponse outboundResponse = outboundMapper.selectById(outboundVO.getOutId());
         BigDecimal sumQty = outboundVO.getItemList().stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
@@ -381,9 +380,9 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
         //region  自动办理参数为true  已入库编辑
         //自动办理参数为true
         if (Constant.FlgHandleSetting.TRUE.getValue().equals(outboundVO.getFlgHandleSetting())) {
-            //region   todo  退账 当单据红的账款id不为空说明有账, 要先退账才能进行操作
+            //region 退账
             if (outboundVO.getReceivableId() != null) {
-
+                accountService.reversePayable(outboundVO.getOutId(),Constant.InventoryDocCode.OUTBOUND.getTableName());
             }
             //endregion
 
@@ -458,19 +457,16 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
             }
             //endregion
 
-            //region   todo  入账 当单据红的账款id不为空说明有账, 最后要入账
+            //region  账款
             if (outboundVO.getReceivableId() != null) {
-
+                accountService.reversePayable(outboundVO.getOutId(),Constant.InventoryDocCode.OUTBOUND.getTableName());
             }
             //endregion
 
-
             //region 修改库存
-            if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
 //                Map<String, Object> invMap = new HashMap<>();
 //                invMap.put("outDetail", outboundVO.getItemList());
 //                inventoryService.updateInventoryInformation(invMap);
-            }
             //endregion
         }
         //endregion
@@ -555,9 +551,9 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
         //region  自动办理参数为true  已入库编辑
         //自动办理参数为true
         if (Constant.FlgHandleSetting.TRUE.getValue().equals(outboundResponse.getFlgHandleSetting())) {
-            //region   todo  退账 当单据红的账款id不为空说明有账, 要先退账才能进行操作
+            //region 退账
             if (outboundResponse.getReceivableId() != null) {
-
+                accountService.reversePayable(outboundResponse.getOutId(),Constant.InventoryDocCode.OUTBOUND.getTableName());
             }
             //endregion
 
@@ -620,13 +616,12 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
             }
             //endregion
 
-            //region   todo  入账 当单据红的账款id不为空说明有账, 最后要入账
+            //region  入账
             if (outboundResponse.getReceivableId() != null) {
-
+                accountService.reversePayable(outboundResponse.getOutId(),Constant.InventoryDocCode.OUTBOUND.getTableName());
             }
             //endregion
 
-            //region  todo 调用库存
             //region  修改库存
 //                Map<String, Object> map = new HashMap<>();
 //                map.put("outDetail",outboundItemResponseList);
@@ -719,60 +714,64 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
                     ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getMessage());
         }
         for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
-            if (outboundItemVO.getOutId() != null) {
-                //明细根据id查询
-                OutboundItemResponse outboundItemResponse = outboundItemMapper.selectById(outboundItemVO.getItemId());
+            //明细根据id查询
+            OutboundItemResponse outboundItemResponse = outboundItemMapper.selectById(outboundItemVO.getItemId());
+            //region 校验数量是否超出
+            if (outboundItemVO.getOutingQty().compareTo(outboundItemResponse.getOutQty()) > 0) {
+                return ResponseResultUtil.error(ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITYIN_THE_WAREHOUSE.getCode(),
+                        ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITYIN_THE_WAREHOUSE.getMessage());
+            }
+            //endregion
 
-                //region 将库存需要的参数赋值
-                outboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName());
-                outboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
-                //endregion
+            //region 将库存需要的参数赋值
+            outboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName());
+            outboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
+            //endregion
 
-                //region  出库明细
-                //编辑明细
-                outboundItemVO
-                        .setOutQty(outboundItemResponse.getOutQty().add(outboundItemVO.getOutingQty()))
-                        .setOutAmt(outboundItemResponse.getOutAmt().add(outboundItemVO.getOutingAmt()))
-                        .setOutingQty(BigDecimal.ZERO)
-                        .setOutAmt(BigDecimal.ZERO)
-                        .setCostPrice(outboundItemVO.getPriceOut())
-                        .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
-                ;
+            //region  出库明细
+            //编辑明细
+            outboundItemVO
+                    .setOutQty(outboundItemResponse.getOutQty().add(outboundItemVO.getOutingQty()))
+                    .setOutAmt(outboundItemResponse.getOutAmt().add(outboundItemVO.getOutingAmt()))
+                    .setOutingQty(BigDecimal.ZERO)
+                    .setOutAmt(BigDecimal.ZERO)
+                    .setCostPrice(outboundItemVO.getPriceOut())
+                    .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
+            ;
+            //出库状态
+            String outStatus = this.setOutStatus(outboundItemVO.getOutingQty(), outboundItemVO.getOutQty());
+            outboundItemVO.setOutStatus(outStatus);
+            //实体转换
+            OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
+            //修改
+            outboundItemMapper.update(outboundItem,
+                    new UpdateWrapper<OutboundItem>().lambda()
+                            .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
+            );
+            //endregion
+
+            //region  销售订单明细
+            if (outboundItemVO.getFromItemId() != null) {
+                //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
+                OrderItem orderItem = new OrderItem();
+                orderItem.setItemId(outboundItemVO.getFromItemId());
+                orderItem.setOutingQty(outboundItemVO.getOutingQty());
+                orderItem.setOutingAmt(outboundItemVO.getOutingAmt());
+                orderItem.setOutQty(outboundItemVO.getOutQty());
+                orderItem.setOutAmt(outboundItemVO.getOutAmt());
+                //根据id查询
+                OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemVO.getFromItemId());
                 //出库状态
-                String outStatus = this.setOutStatus(outboundItemVO.getOutingQty(), outboundItemVO.getOutQty());
-                outboundItemVO.setOutStatus(outStatus);
-                //实体转换
-                OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
+                String orderOutStatus = this.setOutStatus(orderItemResponse.getOutingQty().add(orderItem.getOutingQty()), orderItemResponse.getOutQty().add(orderItem.getOutQty()));
+                orderItem.setOutStatus(orderOutStatus);
                 //修改
-                outboundItemMapper.update(outboundItem,
-                        new UpdateWrapper<OutboundItem>().lambda()
-                                .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
-                );
-                //endregion
-
-                //region  销售订单明细
-                if (outboundItemVO.getFromItemId() != null) {
-                    //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
-                    OrderItem orderItem = new OrderItem();
-                    orderItem.setItemId(outboundItemVO.getFromItemId());
-                    orderItem.setOutingQty(outboundItemVO.getOutingQty());
-                    orderItem.setOutingAmt(outboundItemVO.getOutingAmt());
-                    orderItem.setOutQty(outboundItemVO.getOutQty());
-                    orderItem.setOutAmt(outboundItemVO.getOutAmt());
-                    //根据id查询
-                    OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemVO.getFromItemId());
-                    //出库状态
-                    String orderOutStatus = this.setOutStatus(orderItemResponse.getOutingQty().add(orderItem.getOutingQty()), orderItemResponse.getOutQty().add(orderItem.getOutQty()));
-                    orderItem.setOutStatus(orderOutStatus);
-                    //修改
-                    int countRow = orderItemMapper.updateById(orderItem);
-                    //数量超出
-                    if (countRow == 0) {
-                        throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
-                    }
+                int countRow = orderItemMapper.updateById(orderItem);
+                //数量超出
+                if (countRow == 0) {
+                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
                 }
-                //endregion
             }
+            //endregion
 
         }
         //endregion
@@ -861,11 +860,11 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
         }
         //endregion
 
-        //region todo  调用账款
-
+        //region  入账
+        accountService.reversePayable(outboundResponse.getOutId(),Constant.InventoryDocCode.OUTBOUND.getTableName());
         //endregion
 
-        //region  todo 调用库存 这里后续把删除的明细也加上
+        //region   调用库存
 //                Map<String, Object> map = new HashMap<>();
 //                map.put("outDetail",outboundVO.getItemList());
 //                inventoryService.updateInventoryInformation(map);
@@ -885,10 +884,11 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
         OutboundResponse outboundResponse = outboundMapper.selectById(outboundVO.getOutId());
         //endregion
 
-        //region   todo  退账 当单据红的账款id不为空说明有账, 要先退账才能进行操作
+        //region    退账
         if (outboundResponse.getReceivableId() != null) {
-
+            accountService.reversePayable(outboundResponse.getOutId(),Constant.InventoryDocCode.OUTBOUND.getTableName());
         }
+        //endregion
 
         //region 修改订单数据信息
         if (outboundResponse.getFromId() != null) {
@@ -986,8 +986,7 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
         }
         //endregion
 
-
-        //region  todo 调用库存
+        //region   调用库存
 //                Map<String, Object> map = new HashMap<>();
 //                map.put("outDetail",outboundItemResponseList);
 //                inventoryService.updateInventoryInformation(map);

+ 58 - 52
src/main/java/com/dk/mdm/service/ivt/outbound/OutboundSaleReturnService.java

@@ -24,6 +24,7 @@ import com.dk.mdm.model.vo.ivt.OutboundItemVO;
 import com.dk.mdm.model.vo.ivt.OutboundVO;
 import com.dk.mdm.service.common.CommonService;
 import com.dk.mdm.service.ivt.inventory.InventoryService;
+import com.dk.mdm.service.mac.AccountService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -69,6 +70,9 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
     @Autowired
     private InventoryService inventoryService;
 
+    @Autowired
+    private AccountService accountService;
+
 
     /**
      * @desc : 销售退货出库新建
@@ -167,7 +171,7 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
 
         //region  已出库  账款
         if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
-
+            accountService.accPayable(outboundVO.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
         }
         //endregion
 
@@ -190,11 +194,6 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
      */
     @Transactional(rollbackFor = {Exception.class})
     public ResponseResultVO<?> saleReturnOutboundUpdate(OutboundVO outboundVO) {
-        // 办理参数为false 并且 自动办理为false
-        if (!outboundVO.getFlgHandleSetting() && !outboundVO.getFlgAutoHandle()) {
-            return ResponseResultUtil.error(ErrorCodeEnum.WITHDRAWING_FROM_WAREHOUSE.getCode(),
-                    ErrorCodeEnum.WITHDRAWING_FROM_WAREHOUSE.getMessage());
-        }
         //region 明细数量金额  求和
         BigDecimal sumQty = outboundVO.getItemList().stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
         BigDecimal sumAmt = outboundVO.getItemList().stream().map(OutboundItemVO::getOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
@@ -203,9 +202,9 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
         //region  自动办理参数为true  已出库编辑
         //自动办理参数为true
         if (Constant.FlgHandleSetting.TRUE.getValue().equals(outboundVO.getFlgHandleSetting())) {
-            //region   todo  退账 当单据红的账款id不为空说明有账, 要先退账才能进行操作
+            //region 退账
             if (outboundVO.getReceivableId() != null) {
-
+                accountService.reversePayable(outboundVO.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
             }
             //endregion
 
@@ -251,18 +250,16 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
             );
             //endregion
 
-            //region   todo  入账 当单据红的账款id不为空说明有账, 最后要入账
+            //region  账款
             if (outboundVO.getReceivableId() != null) {
-
+                accountService.reversePayable(outboundVO.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
             }
             //endregion
 
             //region 修改库存
-            if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
 //                Map<String, Object> invMap = new HashMap<>();
 //                invMap.put("outDetail", outboundVO.getItemList());
 //                inventoryService.updateInventoryInformation(invMap);
-            }
             //endregion
         }
         //endregion
@@ -318,9 +315,9 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
         //region  自动办理参数为true  已出库编辑
         //自动办理参数为true
         if (Constant.FlgHandleSetting.TRUE.getValue().equals(outboundResponse.getFlgHandleSetting())) {
-            //region   todo  退账 当单据红的账款id不为空说明有账, 要先退账才能进行操作
+            //region 退账
             if (outboundResponse.getReceivableId() != null) {
-
+                accountService.reversePayable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
             }
             //endregion
 
@@ -355,10 +352,9 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
             );
             //endregion
 
-
-            //region   todo  入账 当单据红的账款id不为空说明有账, 最后要入账
+            //region  入账
             if (outboundResponse.getReceivableId() != null) {
-
+                accountService.reversePayable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
             }
             //endregion
 
@@ -412,6 +408,10 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
      */
     @Transactional(rollbackFor = {Exception.class})
     public ResponseResultVO<?> saleReturnHandleOutbound(OutboundVO outboundVO) {
+        //region 查询出库总单数据信息
+        OutboundResponse outboundResponse = outboundMapper.selectById(outboundVO.getOutId());
+        //endregion
+
         //region 编辑明细
         //校验明细
         if (outboundVO.getItemList().size() == 0) {
@@ -419,35 +419,40 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
                     ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getMessage());
         }
         for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
-            if (outboundItemVO.getItemId() != null) {
-                //查询原单
-                OutboundItemResponse outboundItemResponse = outboundItemMapper.selectById(outboundItemVO.getItemId());
-                //region 将库存需要的参数赋值
-                outboundItemResponse.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
-                outboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.SALE_RETURN.getValue());
-                //endregion
-
-                //编辑明细
-                outboundItemVO
-                        .setOutQty(outboundItemResponse.getOutQty().add(outboundItemVO.getOutingQty()))
-                        .setOutAmt(outboundItemResponse.getOutAmt().add(outboundItemVO.getOutingAmt()))
-                        .setOutingQty(outboundItemResponse.getOutingQty().subtract(outboundItemVO.getOutingQty()))
-                        .setOutAmt(outboundItemResponse.getOutingAmt().subtract(outboundItemVO.getOutingAmt()))
-                        .setCostPrice(outboundItemVO.getPriceOut())
-                        .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
-                ;
-                //出库状态
-                String outStatus = this.setOutStatus(outboundItemVO.getOutingQty(), outboundItemVO.getOutQty());
-                outboundItemVO.setOutStatus(outStatus);
-                //实体转换
-                OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
-                //修改
-                outboundItemMapper.update(outboundItem,
-                        new UpdateWrapper<OutboundItem>().lambda()
-                                .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
-                );
+            //查询原单
+            OutboundItemResponse outboundItemResponse = outboundItemMapper.selectById(outboundItemVO.getItemId());
+            //region 校验数量是否超出
+            if (outboundItemVO.getOutingQty().compareTo(outboundItemResponse.getOutQty()) > 0) {
+                return ResponseResultUtil.error(ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITYIN_THE_WAREHOUSE.getCode(),
+                        ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITYIN_THE_WAREHOUSE.getMessage());
             }
             //endregion
+
+            //region 将库存需要的参数赋值
+            outboundItemResponse.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
+            outboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.SALE_RETURN.getValue());
+            //endregion
+
+            //region 编辑明细
+            outboundItemVO
+                    .setOutQty(outboundItemResponse.getOutQty().add(outboundItemVO.getOutingQty()))
+                    .setOutAmt(outboundItemResponse.getOutAmt().add(outboundItemVO.getOutingAmt()))
+                    .setOutingQty(outboundItemResponse.getOutingQty().subtract(outboundItemVO.getOutingQty()))
+                    .setOutAmt(outboundItemResponse.getOutingAmt().subtract(outboundItemVO.getOutingAmt()))
+                    .setCostPrice(outboundItemVO.getPriceOut())
+                    .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
+            ;
+            //出库状态
+            String outStatus = this.setOutStatus(outboundItemVO.getOutingQty(), outboundItemVO.getOutQty());
+            outboundItemVO.setOutStatus(outStatus);
+            //实体转换
+            OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
+            //修改
+            outboundItemMapper.update(outboundItem,
+                    new UpdateWrapper<OutboundItem>().lambda()
+                            .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
+            );
+            //endregion
         }
         //endregion
 
@@ -487,11 +492,11 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
         //endregion
 
 
-        //region todo  调用账款
-
+        //region 入账
+        accountService.reversePayable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
         //endregion
 
-        //region  todo 调用库存 这里后续把删除的明细也加上
+        //region   调用库存
 //                Map<String, Object> map = new HashMap<>();
 //                map.put("outDetail",outboundVO.getItemList());
 //                inventoryService.updateInventoryInformation(map);
@@ -511,6 +516,11 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
         OutboundResponse outboundResponse = outboundMapper.selectById(outboundVO.getOutId());
         //endregion
 
+        //region    退账
+        if (outboundResponse.getReceivableId() != null) {
+            accountService.reversePayable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
+        }
+
         //region 修改总单数据信息
         Outbound outbound = new Outbound();
         outbound.setOutId(outboundVO.getOutId());
@@ -559,11 +569,7 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
         }
         //endregion
 
-        //region 账款
-
-        //endregion
-
-        //region  todo 调用库存
+        //region   调用库存
 //                Map<String, Object> map = new HashMap<>();
 //                map.put("outDetail",outboundItemResponseList);
 //                inventoryService.updateInventoryInformation(map);