koushanshan 2 лет назад
Родитель
Сommit
e45fe456cd

+ 4 - 1
src/main/java/com/dk/mdm/controller/ivt/InboundOtherController.java

@@ -13,6 +13,7 @@ import com.dk.mdm.model.response.ivt.InboundResponse;
 import com.dk.mdm.model.response.sale.OutReturnItemResponse;
 import com.dk.mdm.model.vo.ivt.InboundVO;
 import com.dk.mdm.service.ivt.InboundOtherService;
+import com.dk.mdm.service.ivt.InboundService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -36,6 +37,8 @@ public class InboundOtherController {
     @Autowired
     private InboundOtherService inboundOtherService;
 
+    @Autowired
+    private InboundService inboundService;
 
 
 
@@ -115,7 +118,7 @@ public class InboundOtherController {
     @ApiOperation(value = "获取单据信息(编辑用)", notes = "获取单据信息(编辑用)")
     @PostMapping({"select_by_update/{id}"})
     public ResponseResultVO<?> selectByUpdate(@PathVariable String id) {
-        return inboundOtherService.selectByUpdate(id);
+        return inboundService.selectByUpdate(id);
     }
 
 }

+ 16 - 0
src/main/java/com/dk/mdm/controller/ivt/InboundPurchaseController.java

@@ -14,6 +14,7 @@ import com.dk.mdm.model.response.ivt.InboundResponse;
 import com.dk.mdm.model.vo.ivt.InboundVO;
 import com.dk.mdm.service.ivt.InboundOtherService;
 import com.dk.mdm.service.ivt.InboundPurchaseService;
+import com.dk.mdm.service.ivt.InboundService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -38,6 +39,10 @@ public class InboundPurchaseController {
     private InboundPurchaseService inheritedPurchaseService;
 
 
+    @Autowired
+    private InboundService inboundService;
+
+
 
 
     /**
@@ -111,4 +116,15 @@ public class InboundPurchaseController {
         return inheritedPurchaseService.purchaseInboundCancel(inboundVO);
     }
 
+    /**
+     * @desc   : 获取单据信息(编辑用)
+     * @date   : 2024/3/14 16:37
+     * @author : 寇珊珊
+     */
+    @ApiOperation(value = "获取单据信息(编辑用)", notes = "获取单据信息(编辑用)")
+    @PostMapping({"select_by_update/{id}"})
+    public ResponseResultVO<?> selectByUpdate(@PathVariable String id) {
+        return inboundService.selectByUpdate(id);
+    }
+
 }

+ 17 - 4
src/main/java/com/dk/mdm/controller/ivt/InboundSaleReturnController.java

@@ -10,13 +10,11 @@ import com.dk.mdm.model.response.ivt.InboundResponse;
 import com.dk.mdm.model.vo.ivt.InboundVO;
 import com.dk.mdm.service.ivt.InboundPurchaseService;
 import com.dk.mdm.service.ivt.InboundSaleReturnService;
+import com.dk.mdm.service.ivt.InboundService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
 
@@ -34,6 +32,10 @@ public class InboundSaleReturnController {
     private InboundSaleReturnService inboundSaleReturnService;
 
 
+    @Autowired
+    private InboundService inboundService;
+
+
 
     /**
      * @desc   : 条件查询
@@ -93,4 +95,15 @@ public class InboundSaleReturnController {
         return inboundSaleReturnService.saleReturnInboundCancel(inboundVO);
     }
 
+
+    /**
+     * @desc   : 获取单据信息(编辑用)
+     * @date   : 2024/3/14 16:37
+     * @author : 寇珊珊
+     */
+    @ApiOperation(value = "获取单据信息(编辑用)", notes = "获取单据信息(编辑用)")
+    @PostMapping({"select_by_update/{id}"})
+    public ResponseResultVO<?> selectByUpdate(@PathVariable String id) {
+        return inboundService.selectByUpdate(id);
+    }
 }

+ 5 - 1
src/main/java/com/dk/mdm/mapper/ivt/InboundItemMapper.xml

@@ -146,7 +146,7 @@
         left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpii.sku_id
         left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
         left join dkic_b.t_psi_inventory tpi on tpi.inv_id = tpii.inv_id
-        left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpi.wh_id
+        left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpii.wh_id
         <include refid="Condition"/>
         <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
             limit #{end} offset #{start}
@@ -158,6 +158,10 @@
         SELECT
         count(1)
         FROM dkic_b.t_psi_inbound_item tpii
+        left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpii.sku_id
+        left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
+        left join dkic_b.t_psi_inventory tpi on tpi.inv_id = tpii.inv_id
+        left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpii.wh_id
         <include refid="Condition"/>
     </select>
 

+ 9 - 4
src/main/java/com/dk/mdm/mapper/ivt/InboundMapper.xml

@@ -59,7 +59,7 @@
         <result column="op_app_code" property="opAppCode"/>
         <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
         <result column="op_db_user" property="opDbUser"/>
-        <result column="entry_reason" property="entryReason" typeHandler="UuidTypeHandler"/>
+        <result column="into_reason" property="intoReason" typeHandler="UuidTypeHandler"/>
         <result column="wh_id" property="whId"/>
     </resultMap>
 
@@ -91,7 +91,8 @@
         <result column="payable_id" property="payableId" typeHandler="UuidTypeHandler"/>
         <result column="flg_valid" property="flgValid"/>
         <result column="cp_id" property="cpId"/>
-        <result column="entry_reason" property="entryReason" typeHandler="UuidTypeHandler"/>
+        <result column="into_reason" property="intoReason" typeHandler="UuidTypeHandler"/>
+        <result column="into_reason_name" property="intoReasonName" />
     </resultMap>
 
 
@@ -278,7 +279,8 @@
         tmc.cus_from                                      as "cusFrom",
         makestaff.staff_name                              as "makeStaffName",
         sys.f_get_name_i18n(tdktype.kind_name_i18n, 'zh_CN') AS  "intoTypeName",
-        sys.f_get_name_i18n(tdk.kind_name_i18n, 'zh_CN') AS  "intoStatusName"
+        sys.f_get_name_i18n(tdk.kind_name_i18n, 'zh_CN') AS  "intoStatusName",
+        tmd.data_value                                   as into_reason_name
         FROM dkic_b.t_psi_inbound tpi
         <include refid="Join_Table"/>
         <include refid="Condition"/>
@@ -305,6 +307,7 @@
         LEFT JOIN sys.t_data_kind tdktype   ON tdktype.kind_code = tpi.into_type
         Left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpi.wh_id
         left join dkic_b.t_mst_customer tmc on tpi.cus_id = tmc.cus_id
+        left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpi.into_reason
     </sql>
 
 
@@ -317,12 +320,14 @@
         ,tms1.staff_name as "makeStaffName"
         ,tmp.sup_name as "supplierName"
         ,tmw.wh_name as "whName"
+        ,tmd.data_value  as into_reason_name
         FROM dkic_b.t_psi_inbound tpi
         Left join dkic_b.t_mst_org tmo on tmo.org_id = tpi.org_id
         Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpi.sup_id
         Left join dkic_b.t_mst_staff tms on tms.staff_id = tpi.staff_id
         Left join dkic_b.t_mst_staff tms1 on tms1.staff_id = tpi.make_staff
         Left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpi.wh_id
+        left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpi.into_reason
         WHERE tpi.into_id = #{intoId}::uuid
     </select>
 
@@ -405,7 +410,7 @@
                 #{item.cpId},
                 #{item.opAppCode},
                 #{item.whId},
-                #{item.entryReason}::uuid,
+                #{item.intoReason}::uuid,
             </trim>
             )
         </foreach>

+ 4 - 5
src/main/java/com/dk/mdm/model/pojo/ivt/Inbound.java

@@ -29,12 +29,11 @@ import java.time.LocalDateTime;
 @Data
 @AllArgsConstructor
 @NoArgsConstructor
-@EqualsAndHashCode(callSuper = true)
 @Accessors(chain = true)
 @ExportTitle("入库单")
-@TableName(value = "t_psi_inbound", autoResultMap = true)
+@TableName(value = "t_psi_inbound", autoResultMap = true, schema = "dkic_b")
 @ApiModel(value="实体类:入库单", description="表名:t_psi_inbound")
-public class Inbound extends PageInfo<Inbound> implements Serializable {
+public class Inbound implements Serializable {
 
     /*
      * 数据库字段
@@ -179,7 +178,7 @@ public class Inbound extends PageInfo<Inbound> implements Serializable {
     @Excel(name = "入库日期")
     @ApiModelProperty(value = "入库日期")
     @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
-    @TableField(typeHandler = TimestampTypeHandler.class)
+    @TableField(typeHandler = TimestampTypeHandler.class, updateStrategy = FieldStrategy.IGNORED)
     private LocalDate intoDate;
 
 
@@ -327,7 +326,7 @@ public class Inbound extends PageInfo<Inbound> implements Serializable {
     @Excel(name = "入库原因")
     @ApiModelProperty(value = "入库原因")
     @TableField(typeHandler = UuidTypeHandler.class)
-    private String entryReason;
+    private String intoReason;
 
 
 

+ 2 - 3
src/main/java/com/dk/mdm/model/pojo/ivt/InboundItem.java

@@ -27,12 +27,11 @@ import java.time.LocalDateTime;
 @Data
 @AllArgsConstructor
 @NoArgsConstructor
-@EqualsAndHashCode(callSuper = true)
 @Accessors(chain = true)
 @ExportTitle("入库明细")
-@TableName(value = "t_psi_inbound_item", autoResultMap = true)
+@TableName(value = "t_psi_inbound_item", autoResultMap = true, schema = "dkic_b")
 @ApiModel(value="实体类:入库明细", description="表名:t_psi_inbound_item")
-public class InboundItem extends PageInfo<InboundItem> implements Serializable {
+public class InboundItem implements Serializable {
 
     /*
      * 数据库字段

+ 6 - 1
src/main/java/com/dk/mdm/model/response/ivt/InboundResponse.java

@@ -288,7 +288,7 @@ public class InboundResponse extends PageInfo<InboundResponse> implements Serial
     @Excel(name = "企业ID")
     @ApiModelProperty(value = "入库原因")
     @TableField(typeHandler = UuidTypeHandler.class)
-    private String entryReason;
+    private String intoReason;
 
 
     /**
@@ -349,6 +349,11 @@ public class InboundResponse extends PageInfo<InboundResponse> implements Serial
      */
     private List<InboundItemResponse> inboundItemList;
 
+
+    @Excel(name = "入库原因")
+    @ApiModelProperty(value = "入库原因")
+    private String intoReasonName;
+
     private static final long serialVersionUID = 1L;
 
 }

+ 2 - 4
src/main/java/com/dk/mdm/model/vo/ivt/InboundVO.java

@@ -332,10 +332,10 @@ public class InboundVO extends PageInfo<InboundVO> implements Serializable {
     private String whId;
 
 
-    @Excel(name = "企业ID")
+    @Excel(name = "入库原因")
     @ApiModelProperty(value = "入库原因")
     @TableField(typeHandler = UuidTypeHandler.class)
-    private String entryReason;
+    private String intoReason;
 
 
 
@@ -359,8 +359,6 @@ public class InboundVO extends PageInfo<InboundVO> implements Serializable {
     @ApiModelProperty(value = "明细")
     private List<InboundItemVO> itemList;
 
-    @ApiModelProperty(value = "大编辑标识")
-    private Boolean allEdit;
 
     @ApiModelProperty(value = "删除明细")
     private List<InboundItemVO> deleteItemList;

+ 0 - 3
src/main/java/com/dk/mdm/service/ivt/InboundItemService.java

@@ -63,9 +63,6 @@ public class InboundItemService extends BaseService<InboundItem> {
 		//实体转换
 		InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
 
-		//设置id
-		Map<String, Object> uniqueNoteCode = commonService.getUniqueNoteCode(Constant.docNameConstant.INBIUNDDETAIL.getName(), false);
-		inboundItem.setItemId(uniqueNoteCode.get("outId").toString());
 
 		//新建
 		inboundItemMapper.insert(inboundItem);

+ 106 - 112
src/main/java/com/dk/mdm/service/ivt/InboundOtherService.java

@@ -1,5 +1,6 @@
 package com.dk.mdm.service.ivt;
 
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.dk.common.infrastructure.annotaiton.Pagination;
 import com.dk.common.infrastructure.constant.Constant;
 import com.dk.common.infrastructure.enums.ErrorCodeEnum;
@@ -16,10 +17,8 @@ import com.dk.mdm.model.pojo.ivt.Inbound;
 import com.dk.mdm.model.pojo.ivt.InboundItem;
 import com.dk.mdm.model.query.ivt.InboundItemQuery;
 import com.dk.mdm.model.query.ivt.InboundQuery;
-import com.dk.mdm.model.query.sale.OutReturnItemQuery;
 import com.dk.mdm.model.response.ivt.InboundItemResponse;
 import com.dk.mdm.model.response.ivt.InboundResponse;
-import com.dk.mdm.model.response.sale.OutReturnItemResponse;
 import com.dk.mdm.model.vo.ivt.InboundItemVO;
 import com.dk.mdm.model.vo.ivt.InboundVO;
 import com.dk.mdm.service.common.CommonService;
@@ -31,6 +30,7 @@ import java.math.BigDecimal;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 
 
 /**
@@ -39,7 +39,6 @@ import java.util.Map;
  * @author : 寇珊珊
  */
 @Service
-@Transactional
 public class InboundOtherService extends BaseService<Inbound> {
 
 	@Override
@@ -138,9 +137,6 @@ public class InboundOtherService extends BaseService<Inbound> {
 					ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
 		}
 		for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
-			Map<String , Object> map = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHERINBOUNDITEM.getName(),true);
-			//明细id
-			inboundItemVO.setItemId(map.get("outId").toString());
 			//总单id
 			inboundItemVO.setIntoId(inboundVO.getIntoId());
 			//入库类型
@@ -192,96 +188,102 @@ public class InboundOtherService extends BaseService<Inbound> {
 	 */
 	@Transactional(rollbackFor = {Exception.class})
 	public ResponseResultVO<?> otherHandleInbound(InboundVO inboundVO) {
-		//大编辑标识
-		if (inboundVO.getAllEdit() != null && inboundVO.getAllEdit()) {
-			//region 编辑明细
-			//校验明细
-			if (inboundVO.getItemList().size() == 0) {
-				return ResponseResultUtil.error(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
-						ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
-			}
-			for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
-				if (inboundItemVO.getIntoId() != null) {
-					InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getIntoId());
-					//编辑明细
-					inboundItemVO
-							.setIntoQty(inboundItemResponse.getIntoQty().add(inboundItemVO.getIntoingQty()))
-							.setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt()))
-							.setIntoingQty(inboundItemResponse.getIntoingQty().subtract(inboundItemVO.getIntoingQty()))
-							.setIntoingAmt(inboundItemResponse.getIntoingAmt().subtract(inboundItemVO.getIntoingAmt()))
-					;
-					//入库状态
-					String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
-					inboundItemVO.setIntoStatus(intoStatus);
-					//实体转换
-					InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
-					//修改
-					inboundItemMapper.updateById(inboundItem);
-				}
-				//endregion
-
-				//region 新建明细
-				else {
-					Map<String , Object> map = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHERINBOUNDITEM.getName(),true);
-					inboundItemVO
-							.setItemId(map.get("outId").toString())
-							.setIntoQty(inboundItemVO.getIntoingQty())
-							.setIntoAmt(inboundItemVO.getIntoingAmt())
-							.setIntoId(inboundVO.getIntoId())
-							.setCostPrice(inboundItemVO.getPriceInto())
-							.setCostAmt((inboundItemVO.getIntoingQty().add(inboundItemVO.getIntoQty())).multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
-							.setIntoType(Constant.IntoType.OTHER.getName());
-					//入库状态
-					String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
-					inboundItemVO.setIntoStatus(intoStatus);
-					//实体转换
-					InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
-					//新建
-					inboundItemMapper.insert(inboundItem);
-				}
+		//region 编辑明细
+		//校验明细
+		if (inboundVO.getItemList().size() == 0) {
+			return ResponseResultUtil.error(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
+					ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
+		}
+		for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
+			if (inboundItemVO.getIntoId() != null) {
+				InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
+				//编辑明细
+				inboundItemVO
+						.setIntoQty(inboundItemResponse.getIntoQty().add(inboundItemVO.getIntoingQty()))
+						.setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt()))
+						.setIntoingQty(inboundItemResponse.getIntoingQty().subtract(inboundItemVO.getIntoingQty()))
+						.setIntoingAmt(inboundItemResponse.getIntoingAmt().subtract(inboundItemVO.getIntoingAmt()))
+				;
+				//入库状态
+				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 (inboundVO.getDeleteItemList() != null) {
-				for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
-					if (inboundItemVO.getItemId() != null) {
-						InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
-						inboundItem.setFlgValid(false);
-						inboundItemMapper.updateById(inboundItem);
-					}
-				}
+			//region 新建明细
+			else {
+				inboundItemVO
+						.setIntoQty(inboundItemVO.getIntoingQty())
+						.setIntoAmt(inboundItemVO.getIntoingAmt())
+						.setIntoId(inboundVO.getIntoId())
+						.setCostPrice(inboundItemVO.getPriceInto())
+						.setCostAmt((inboundItemVO.getIntoingQty().add(inboundItemVO.getIntoQty())).multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
+						.setIntoType(Constant.IntoType.OTHER.getName());
+				//入库状态
+				String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
+				inboundItemVO.setIntoStatus(intoStatus);
+				//实体转换
+				InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
+				//新建
+				inboundItemMapper.insert(inboundItem);
 			}
-			//endregion
+		}
+		//endregion
 
-			//region 编辑总单
-			BigDecimal sumIntoQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
-			BigDecimal sumIntoAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
-			BigDecimal sumIntoingQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
-			BigDecimal sumIntoingAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
-			inboundVO.setIntoQty(sumIntoQty);
-			inboundVO.setIntoAmt(sumIntoAmt);
-			inboundVO.setIntoingQty(sumIntoingQty);
-			inboundVO.setIntoingAmt(sumIntoingAmt);
-			//已入库数量==入库中数量   入库完成
-			if(inboundVO.getIntoQty().compareTo(inboundVO.getIntoingQty())==0){
-				//已入库
-				inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
-			} else {
-				//入库中
-				inboundVO.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
+		//region 删除明细
+		if (inboundVO.getDeleteItemList() != null) {
+			for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
+				if (inboundItemVO.getItemId() != null) {
+					InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
+					inboundItem.setFlgValid(false);
+					//修改
+					inboundItemMapper.update(inboundItem,
+							new UpdateWrapper<InboundItem>().lambda()
+									.eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
+					);
+				}
 			}
-			//实体转换
-			Inbound inbound = inboundConvert.convertToPo(inboundVO);
-			//修改
-			inboundMapper.updateById(inbound);
-			//endregion
-
-			//todo 如果是已入库 调用库存  后续写库存这里补上
-			//region 修改库存
+		}
+		//endregion
 
-			//endregion
+		//region 编辑总单
+		InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
+		BigDecimal sumIntoQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+		BigDecimal sumIntoAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+		BigDecimal sumIntoingQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+		BigDecimal sumIntoingAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+		inboundVO.setIntoQty(sumIntoQty);
+		inboundVO.setIntoAmt(sumIntoAmt);
+		inboundVO.setIntoingQty(inboundResponse.getIntoingQty().subtract(sumIntoingQty));
+		inboundVO.setIntoingAmt(inboundResponse.getIntoingAmt().subtract(sumIntoingAmt));
+		//已入库数量==入库中数量   入库完成
+		if (inboundVO.getIntoQty().compareTo(inboundVO.getIntoingQty()) == 0) {
+			//已入库
+			inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
+		} else {
+			//入库中
+			inboundVO.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
 		}
+		//实体转换
+		Inbound inbound = inboundConvert.convertToPo(inboundVO);
+		//修改
+		inboundMapper.update(inbound,
+				new UpdateWrapper<Inbound>().lambda()
+						.eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
+		);
+		//endregion
+
+		//todo 如果是已入库 调用库存  后续写库存这里补上
+		//region 修改库存
+
+		//endregion
 		return ResponseResultUtil.success(inboundVO);
 	}
 
@@ -303,7 +305,11 @@ public class InboundOtherService extends BaseService<Inbound> {
 				.setIntoingAmt(inboundResponse.getIntoingAmt().add(inboundResponse.getIntoAmt()))
 				.setIntoQty(BigDecimal.ZERO)
 				.setIntoAmt(BigDecimal.ZERO);
-		inboundMapper.updateById(inbound);
+		//修改
+		inboundMapper.update(inbound,
+				new UpdateWrapper<Inbound>().lambda()
+						.eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
+		);
 		//endregion
 
 		//region 明细数据
@@ -319,7 +325,11 @@ public class InboundOtherService extends BaseService<Inbound> {
 					.setIntoQty(BigDecimal.ZERO)
 					.setIntoAmt(BigDecimal.ZERO)
 					.setItemId(inboundItemResponse.getItemId());
-			inboundItemMapper.updateById(inboundItem);
+			//修改
+			inboundItemMapper.update(inboundItem,
+					new UpdateWrapper<InboundItem>().lambda()
+							.eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
+			);
 		}
 		//endregion
 
@@ -339,8 +349,8 @@ public class InboundOtherService extends BaseService<Inbound> {
 	public String setIntoStatus(BigDecimal intoingQty, BigDecimal intoQty) {
 		//入库状态
 		String intoStatus = null;
-		//已入库数量=0 入库中数量>0
-		if (intoQty.compareTo(BigDecimal.ZERO) == 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0) {
+		//已入库数量>0 入库中数量>0
+		if (intoQty.compareTo(BigDecimal.ZERO) > 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0 ) {
 			//入库中
 			intoStatus = Constant.IntoStatus.RUKUZHONG.getName();
 		}
@@ -349,30 +359,14 @@ public class InboundOtherService extends BaseService<Inbound> {
 			//待入库
 			intoStatus = Constant.IntoStatus.DAIRUKU.getName();
 		}
-		//已入库数量>0 入库中数量>0
-		else if (intoQty.compareTo(BigDecimal.ZERO) > 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0) {
-			//入库
-			intoStatus = Constant.IntoStatus.RUKUZHONG.getName();
+		//已入库数量>0 入库中数量=0
+		else if (intoQty.compareTo(BigDecimal.ZERO) >0 && intoingQty.compareTo(BigDecimal.ZERO)==0) {
+			//入库
+			intoStatus = Constant.IntoStatus.YIRUKU.getName();
 		}
 		return intoStatus;
 	}
 
 
-	/**
-	 * @desc   : 获取单据信息(编辑用)
-	 * @date   : 2024/3/14 16:38
-	 * @author : 寇珊珊
-	 */
-	public ResponseResultVO<?> selectByUpdate(String id) {
-		Map<String, Object> dataInfo = new HashMap<>();
-		//总单
-		InboundResponse inboundResponse = inboundMapper.selectById(id);
-		dataInfo.put("data", inboundResponse);
-
-		// 明细
-		List<InboundItemResponse> inboundItemResponses = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(id));
-		dataInfo.put("dataItem", inboundItemResponses);
-		return ResponseResultUtil.success(dataInfo);
-	}
 	
 }

+ 177 - 161
src/main/java/com/dk/mdm/service/ivt/InboundPurchaseService.java

@@ -1,5 +1,6 @@
 package com.dk.mdm.service.ivt;
 
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.dk.common.exception.BaseBusinessException;
 import com.dk.common.infrastructure.annotaiton.Pagination;
 import com.dk.common.infrastructure.constant.Constant;
@@ -22,7 +23,6 @@ import com.dk.mdm.model.pojo.pur.Purchase;
 import com.dk.mdm.model.pojo.pur.PurchaseItem;
 import com.dk.mdm.model.query.ivt.InboundItemQuery;
 import com.dk.mdm.model.query.ivt.InboundQuery;
-import com.dk.mdm.model.query.pur.PurchaseItemQuery;
 import com.dk.mdm.model.response.ivt.InboundItemResponse;
 import com.dk.mdm.model.response.ivt.InboundResponse;
 import com.dk.mdm.model.response.pur.PurchaseItemResponse;
@@ -38,6 +38,7 @@ import java.math.BigDecimal;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 
 
 /**
@@ -76,7 +77,6 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 
 
 
-
 	/**
 	 * @desc   : 条件查询
 	 * @date   : 2024/3/7 14:12
@@ -89,8 +89,6 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 	}
 
 
-
-
 	/**
 	 * @desc   : 查询明细
 	 * @date   : 2024/3/9 15:43
@@ -118,7 +116,7 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 	public ResponseResultVO<?> purchaseInboundInsert(InboundVO inboundVO) {
 		//region  总单
 		//获取 id/单号
-		Map<String , Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHERINBOUND.getName(),false);
+		Map<String , Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.PURCASEINBOUND.getName(),false);
 		inboundVO.setIntoId(codeMap.get("outId").toString()).
 				setIntoNo(codeMap.get("outNote").toString());
 		//入库类型
@@ -138,6 +136,10 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 					.setIntoingQty(BigDecimal.ZERO)
 					.setIntoingAmt(BigDecimal.ZERO)
 			;
+		}else{
+			inboundVO.setIntoQty(BigDecimal.ZERO)
+					.setIntoAmt(BigDecimal.ZERO)
+			;
 		}
 		//实体转换
 		Inbound inbound = inboundConvert.convertToPo(inboundVO);
@@ -172,10 +174,6 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 					ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
 		}
 		for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
-			//region  入库明细
-			Map<String , Object> map = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHERINBOUNDITEM.getName(),true);
-			//明细id
-			inboundItemVO.setItemId(map.get("outId").toString());
 			//总单id
 			inboundItemVO.setIntoId(inboundVO.getIntoId());
 			//入库类型
@@ -187,6 +185,10 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 						.setIntoingQty(BigDecimal.ZERO)
 						.setIntoingAmt(BigDecimal.ZERO)
 				;
+			}else{
+				inboundItemVO
+						.setIntoQty(BigDecimal.ZERO)
+						.setIntoAmt(BigDecimal.ZERO);
 			}
 			//成本单价
 			inboundItemVO.setCostPrice(inboundItemVO.getCostPrice());
@@ -247,178 +249,184 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 	 */
 	@Transactional(rollbackFor = {Exception.class})
 	public ResponseResultVO<?> purchaseHandleInbound(InboundVO inboundVO) {
-		//大编辑标识
-		if (inboundVO.getAllEdit() != null && inboundVO.getAllEdit()) {
-			//region 编辑明细
-			//校验明细
-			if (inboundVO.getItemList().size() == 0) {
-				return ResponseResultUtil.error(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
-						ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
+		//region 编辑明细
+		//校验明细
+		if (inboundVO.getItemList().size() == 0) {
+			return ResponseResultUtil.error(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
+					ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
+		}
+		for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
+			if (inboundItemVO.getIntoId() != null) {
+				InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
+				//编辑明细
+				inboundItemVO
+						.setIntoQty(inboundItemResponse.getIntoQty().add(inboundItemVO.getIntoingQty()))
+						.setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt()))
+						.setIntoingQty(inboundItemResponse.getIntoingQty().subtract(inboundItemVO.getIntoingQty()))
+						.setIntoingAmt(inboundItemResponse.getIntoingAmt().subtract(inboundItemVO.getIntoingAmt()))
+				;
+				//入库状态
+				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()))
+				);
 			}
-			for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
-				if (inboundItemVO.getIntoId() != null) {
-					InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
-					//编辑明细
-					inboundItemVO
-							.setIntoQty(inboundItemResponse.getIntoQty().add(inboundItemVO.getIntoingQty()))
-							.setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt()))
-							.setIntoingQty(inboundItemResponse.getIntoingQty().subtract(inboundItemVO.getIntoingQty()))
-							.setIntoingAmt(inboundItemResponse.getIntoingAmt().subtract(inboundItemVO.getIntoingAmt()))
-					;
-					//入库状态
-					String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
-					inboundItemVO.setIntoStatus(intoStatus);
-					//实体转换
-					InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
-					//修改
-					inboundItemMapper.updateById(inboundItem);
-				}
-				//endregion
-				//region 新建明细
-				else {
-					Map<String , Object> map = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHERINBOUNDITEM.getName(),true);
-					inboundItemVO
-							.setItemId(map.get("outId").toString())
-							.setIntoQty(inboundItemVO.getIntoingQty())
-							.setIntoAmt(inboundItemVO.getIntoingAmt())
-							.setIntoId(inboundVO.getIntoId())
-							.setCostPrice(inboundItemVO.getPriceInto())
-							.setCostAmt((inboundItemVO.getIntoingQty().add(inboundItemVO.getIntoQty())).multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
-							.setIntoType(Constant.IntoType.SALE.getName());
-					//入库状态
-					String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
-					inboundItemVO.setIntoStatus(intoStatus);
-					//实体转换
-					InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
-					//新建
-					inboundItemMapper.insert(inboundItem);
-				}
-				//region  采购
-				//采购明细
-				if(inboundItemVO.getFromItemId()!=null){
+			//endregion
+			//region 新建明细
+			else {
+				inboundItemVO
+						.setIntoQty(inboundItemVO.getIntoingQty())
+						.setIntoAmt(inboundItemVO.getIntoingAmt())
+						.setIntoId(inboundVO.getIntoId())
+						.setCostPrice(inboundItemVO.getPriceInto())
+						.setCostAmt((inboundItemVO.getIntoingQty().add(inboundItemVO.getIntoQty())).multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
+						.setIntoType(Constant.IntoType.SALE.getName());
+				//入库状态
+				String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
+				inboundItemVO.setIntoStatus(intoStatus);
+				//实体转换
+				InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
+				//新建
+				inboundItemMapper.insert(inboundItem);
+			}
+			//region  采购
+			//采购明细
+			if (inboundItemVO.getFromItemId() != null) {
 //					PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
-					PurchaseItem  purchaseItem = new PurchaseItem();
-					purchaseItem.setItemId(inboundItemVO.getFromItemId());
+				PurchaseItem purchaseItem = new PurchaseItem();
+				purchaseItem.setItemId(inboundItemVO.getFromItemId());
 //					purchaseItem.setIntoingQty(purchaseItemResponse.getIntoingQty().add(inboundItemVO.getIntoingQty()));
 //					purchaseItem.setIntoingAmt(purchaseItemResponse.getIntoingAmt().add(inboundItemVO.getIntoingAmt()));
 //					purchaseItem.setIntoQty(purchaseItemResponse.getIntoQty().add(inboundItemVO.getIntoQty()));
 //					purchaseItem.setIntoAmt(purchaseItemResponse.getIntoAmt().add(inboundItemVO.getIntoAmt()));
-					purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty());
-					purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt());
-					purchaseItem.setIntoQty(inboundItemVO.getIntoQty());
-					purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt());
-					//入库状态
-					String intoStatus = this.setIntoStatus(purchaseItem.getIntoingQty(), purchaseItem.getIntoQty());
-					purchaseItem.setIntoStatus(intoStatus);
-					int countRow = purchaseItemMapper.updateById(purchaseItem);
-					//数量超出
-					if (countRow == 0) {
-						throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
-					}
+				purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty());
+				purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt());
+				purchaseItem.setIntoQty(inboundItemVO.getIntoQty());
+				purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt());
+				//入库状态
+				String intoStatus = this.setIntoStatus(purchaseItem.getIntoingQty(), purchaseItem.getIntoQty());
+				purchaseItem.setIntoStatus(intoStatus);
+				int countRow = purchaseItemMapper.updateById(purchaseItem);
+				//数量超出
+				if (countRow == 0) {
+					throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
 				}
-				//endregion
 			}
 			//endregion
+		}
+		//endregion
 
-			//region 删除明细
-			BigDecimal sumDelIntoQty = BigDecimal.ZERO;
-			BigDecimal sumDelIntoAmt = BigDecimal.ZERO;
-			BigDecimal sumDelIntoingQty = BigDecimal.ZERO;
-			BigDecimal sumDelIntoingAmt = BigDecimal.ZERO;
-			if (inboundVO.getDeleteItemList() != null) {
-				 sumDelIntoQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
-				 sumDelIntoAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
-				 sumDelIntoingQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
-				 sumDelIntoingAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
-				for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
-					if (inboundItemVO.getItemId() != null) {
-						InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
-						inboundItem.setFlgValid(false);
-						inboundItemMapper.updateById(inboundItem);
-					}
-					//region  采购
-					if(inboundItemVO.getFromItemId()!=null){
-						//region 采购订单明细
+		//region 删除明细
+		BigDecimal sumDelIntoQty = BigDecimal.ZERO;
+		BigDecimal sumDelIntoAmt = BigDecimal.ZERO;
+		BigDecimal sumDelIntoingQty = BigDecimal.ZERO;
+		BigDecimal sumDelIntoingAmt = BigDecimal.ZERO;
+		if (inboundVO.getDeleteItemList() != null) {
+			sumDelIntoQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+			sumDelIntoAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+			sumDelIntoingQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+			sumDelIntoingAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+			for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
+				if (inboundItemVO.getItemId() != null) {
+					InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
+					inboundItem.setFlgValid(false);
+					//修改
+					inboundItemMapper.update(inboundItem,
+							new UpdateWrapper<InboundItem>().lambda()
+									.eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
+					);
+				}
+				//region  采购
+				if (inboundItemVO.getFromItemId() != null) {
+					//region 采购订单明细
 //						PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
-						PurchaseItem  purchaseItem = new PurchaseItem();
-							purchaseItem.setItemId(inboundItemVO.getFromItemId());
+					PurchaseItem purchaseItem = new PurchaseItem();
+					purchaseItem.setItemId(inboundItemVO.getFromItemId());
 //							purchaseItem.setIntoingQty(purchaseItemResponse.getIntoingQty().subtract(inboundItemVO.getIntoingQty()));
 //							purchaseItem.setIntoingAmt(purchaseItemResponse.getIntoingAmt().subtract(inboundItemVO.getIntoingAmt()));
 //							purchaseItem.setIntoQty(purchaseItemResponse.getIntoQty().subtract(inboundItemVO.getIntoQty()));
 //							purchaseItem.setIntoAmt(purchaseItemResponse.getIntoAmt().subtract(inboundItemVO.getIntoAmt()));
-							purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty().negate());
-							purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt().negate());
-							purchaseItem.setIntoQty(inboundItemVO.getIntoQty().negate());
-							purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt().negate());
-							//入库状态
-							String intoStatus = this.setIntoStatus(purchaseItem.getIntoingQty(), purchaseItem.getIntoQty());
-							purchaseItem.setIntoStatus(intoStatus);
-							int countRow = purchaseItemMapper.updateById(purchaseItem);
-							//数量超出
-							if (countRow == 0) {
-								throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
-							}
-						//endregion
+					purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty().negate());
+					purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt().negate());
+					purchaseItem.setIntoQty(inboundItemVO.getIntoQty().negate());
+					purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt().negate());
+					//入库状态
+					String intoStatus = this.setIntoStatus(purchaseItem.getIntoingQty(), purchaseItem.getIntoQty());
+					purchaseItem.setIntoStatus(intoStatus);
+					int countRow = purchaseItemMapper.updateById(purchaseItem);
+					//数量超出
+					if (countRow == 0) {
+						throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
 					}
 					//endregion
-
 				}
-			}
-			//endregion
+				//endregion
 
-			//region 编辑总单
-			BigDecimal sumIntoQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
-			BigDecimal sumIntoAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
-			BigDecimal sumIntoingQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
-			BigDecimal sumIntoingAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
-			inboundVO.setIntoQty(sumIntoQty);
-			inboundVO.setIntoAmt(sumIntoAmt);
-			inboundVO.setIntoingQty(sumIntoingQty);
-			inboundVO.setIntoingAmt(sumIntoingAmt);
-			//已入库数量==入库中数量   入库完成
-			if(inboundVO.getIntoQty().compareTo(inboundVO.getIntoingQty())==0){
-				//已入库
-				inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
-			} else {
-				//入库中
-				inboundVO.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
 			}
-			//实体转换
-			Inbound inbound = inboundConvert.convertToPo(inboundVO);
-			//修改
-			inboundMapper.updateById(inbound);
-			//endregion
+		}
+		//endregion
+
+		//region 编辑总单
+		InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
+		BigDecimal sumIntoQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+		BigDecimal sumIntoAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+		BigDecimal sumIntoingQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+		BigDecimal sumIntoingAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+		inboundVO.setIntoQty(sumIntoQty);
+		inboundVO.setIntoAmt(sumIntoAmt);
+		inboundVO.setIntoingQty(inboundResponse.getIntoingQty().subtract(sumIntoingQty));
+		inboundVO.setIntoingAmt(inboundResponse.getIntoingAmt().subtract(sumIntoingAmt));
+		//已入库数量==入库中数量   入库完成
+		if (inboundVO.getIntoQty().compareTo(inboundVO.getIntoingQty()) == 0) {
+			//已入库
+			inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
+		} else {
+			//入库中
+			inboundVO.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
+		}
+		//实体转换
+		Inbound inbound = inboundConvert.convertToPo(inboundVO);
+		//修改
+		inboundMapper.update(inbound,
+				new UpdateWrapper<Inbound>().lambda()
+						.eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
+		);
+		//endregion
 
-			//region  修改采购订单
-			if(inboundVO.getFromId()!=null){
-				PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
-				Purchase  purchase = new Purchase();
-				purchase.setPurId(purchaseResponse.getPurId());
+		//region  修改采购订单
+		if (inboundVO.getFromId() != null) {
+			PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
+			Purchase purchase = new Purchase();
+			purchase.setPurId(purchaseResponse.getPurId());
 //				purchase.setIntoQty(purchaseResponse.getIntoQty().add(sumIntoQty).subtract(sumDelIntoQty));
 //				purchase.setIntoAmt(purchaseResponse.getIntoAmt().add(sumIntoAmt).subtract(sumDelIntoAmt));
 //				purchase.setIntoingQty(purchaseResponse.getIntoingQty().subtract(sumIntoingQty).subtract(sumDelIntoingQty));
 //				purchase.setIntoingAmt(purchaseResponse.getIntoingAmt().subtract(sumIntoingAmt).subtract(sumDelIntoingAmt));
-				purchase.setIntoQty(sumIntoQty.subtract(sumDelIntoQty));
-				purchase.setIntoAmt(sumIntoAmt.subtract(sumDelIntoAmt));
-				purchase.setIntoingQty((sumIntoingQty.add(sumDelIntoingQty)).negate());
-				purchase.setIntoingAmt((sumIntoingAmt.add(sumDelIntoingAmt)).negate());
-				//入库状态
-				String intoStatus = this.setIntoStatus(purchase.getIntoingQty(), purchase.getIntoQty());
-				purchase.setIntoStatus(intoStatus);
-				//修改
-				int countRow = purchaseMapper.updateById(purchase);
-				//数量超出
-				if (countRow == 0) {
-					throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
-				}
+			purchase.setIntoQty(sumIntoQty.subtract(sumDelIntoQty));
+			purchase.setIntoAmt(sumIntoAmt.subtract(sumDelIntoAmt));
+			purchase.setIntoingQty((sumIntoingQty.add(sumDelIntoingQty)).negate());
+			purchase.setIntoingAmt((sumIntoingAmt.add(sumDelIntoingAmt)).negate());
+			//入库状态
+			String intoStatus = this.setIntoStatus(purchase.getIntoingQty(), purchase.getIntoQty());
+			purchase.setIntoStatus(intoStatus);
+			//修改
+			int countRow = purchaseMapper.updateById(purchase);
+			//数量超出
+			if (countRow == 0) {
+				throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
 			}
-			//endregion
+		}
+		//endregion
 
-			//todo 如果是已入库 调用库存  后续写库存这里补上
-			//region 修改库存
+		//todo 如果是已入库 调用库存  后续写库存这里补上
+		//region 修改库存
 
-			//endregion
-		}
+		//endregion
 		return ResponseResultUtil.success(inboundVO);
 	}
 
@@ -467,7 +475,11 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 		inbound.setIntoingAmt(inboundResponse.getIntoingAmt().add(inboundResponse.getIntoAmt()));
 		inbound.setIntoQty(BigDecimal.ZERO);
 		inbound.setIntoAmt(BigDecimal.ZERO);
-		inboundMapper.updateById(inbound);
+		//修改
+		inboundMapper.update(inbound,
+				new UpdateWrapper<Inbound>().lambda()
+						.eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
+		);
 		//endregion
 
 		//region 明细数据
@@ -509,7 +521,11 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 					.setIntoQty(BigDecimal.ZERO)
 					.setIntoAmt(BigDecimal.ZERO)
 					.setItemId(inboundItemResponse.getItemId());
-			inboundItemMapper.updateById(inboundItem);
+			//修改
+			inboundItemMapper.update(inboundItem,
+					new UpdateWrapper<InboundItem>().lambda()
+							.eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
+			);
 			//endregion
 		}
 		//endregion
@@ -532,8 +548,8 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 	public String setIntoStatus(BigDecimal intoingQty, BigDecimal intoQty) {
 		//入库状态
 		String intoStatus = null;
-		//已入库数量=0 入库中数量>0
-		if (intoQty.compareTo(BigDecimal.ZERO) == 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0) {
+		//已入库数量>0 入库中数量>0
+		if (intoQty.compareTo(BigDecimal.ZERO) > 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0 ) {
 			//入库中
 			intoStatus = Constant.IntoStatus.RUKUZHONG.getName();
 		}
@@ -542,10 +558,10 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 			//待入库
 			intoStatus = Constant.IntoStatus.DAIRUKU.getName();
 		}
-		//已入库数量>0 入库中数量>0
-		else if (intoQty.compareTo(BigDecimal.ZERO) > 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0) {
-			//入库
-			intoStatus = Constant.IntoStatus.RUKUZHONG.getName();
+		//已入库数量>0 入库中数量=0
+		else if (intoQty.compareTo(BigDecimal.ZERO) >0 && intoingQty.compareTo(BigDecimal.ZERO)==0) {
+			//入库
+			intoStatus = Constant.IntoStatus.YIRUKU.getName();
 		}
 		return intoStatus;
 	}

+ 211 - 168
src/main/java/com/dk/mdm/service/ivt/InboundSaleReturnService.java

@@ -1,5 +1,6 @@
 package com.dk.mdm.service.ivt;
 
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.dk.common.exception.BaseBusinessException;
 import com.dk.common.infrastructure.annotaiton.Pagination;
 import com.dk.common.infrastructure.constant.Constant;
@@ -44,8 +45,10 @@ 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;
+import java.util.UUID;
 
 
 /**
@@ -54,7 +57,6 @@ import java.util.Map;
  * @date : 2024/3/7 14:11
  */
 @Service
-@Transactional
 public class InboundSaleReturnService extends BaseService<Inbound> {
 
     @Override
@@ -95,6 +97,24 @@ public class InboundSaleReturnService extends BaseService<Inbound> {
                 inboundMapper.selectInboundAndItemCountByCond(inboundQuery));
     }
 
+    /**
+     * @desc   : 查询明细
+     * @date   : 2024/3/15 16:43
+     * @author : 寇珊珊
+     */
+    @Pagination
+    public ResponseResultVO<Map<String, Object>> selectOtherInboundItemInfoById(String id) {
+        Map<String, Object> result = new HashMap<>();
+        // 商品明细
+        List<InboundItemResponse> inboundItemResponses = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(id));
+        result.put("itemList", inboundItemResponses);
+        // 收款
+
+        // 附件
+        return ResponseResultUtil.success(result);
+    }
+
+
 
     /**
      * @desc : 销售退货入库新建
@@ -105,7 +125,7 @@ public class InboundSaleReturnService extends BaseService<Inbound> {
     public ResponseResultVO<?> saleReturnInboundInsert(InboundVO inboundVO) {
         //region  总单
         //获取 id/单号
-        Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHERINBOUND.getName(), false);
+        Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.SALERETURN.getName(), false);
         inboundVO.setIntoId(codeMap.get("outId").toString()).
                 setIntoNo(codeMap.get("outNote").toString());
         //入库类型
@@ -129,6 +149,10 @@ public class InboundSaleReturnService extends BaseService<Inbound> {
                     .setIntoingQty(BigDecimal.ZERO)
                     .setIntoingAmt(BigDecimal.ZERO)
             ;
+        }else{
+            inboundVO.setIntoQty(BigDecimal.ZERO)
+                    .setIntoAmt(BigDecimal.ZERO)
+            ;
         }
 
         //实体转换
@@ -169,10 +193,6 @@ public class InboundSaleReturnService extends BaseService<Inbound> {
                     ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
         }
         for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
-            //region  明细
-            Map<String, Object> map = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHERINBOUNDITEM.getName(), true);
-            //明细id
-            inboundItemVO.setItemId(map.get("outId").toString());
             //总单id
             inboundItemVO.setIntoId(inboundVO.getIntoId());
             //入库类型
@@ -180,7 +200,14 @@ public class InboundSaleReturnService extends BaseService<Inbound> {
             //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
             if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
                 inboundItemVO.setIntoQty(inboundItemVO.getIntoingQty())
-                        .setIntoAmt(inboundItemVO.getIntoingAmt());
+                        .setIntoAmt(inboundItemVO.getIntoingAmt())
+                        .setIntoingQty(BigDecimal.ZERO)
+                        .setIntoingAmt(BigDecimal.ZERO)
+                       ;
+            }else{
+                inboundItemVO
+                        .setIntoQty(BigDecimal.ZERO)
+                        .setIntoAmt(BigDecimal.ZERO);
             }
             //成本单价
             inboundItemVO.setCostPrice(inboundItemVO.getCostPrice());
@@ -245,64 +272,111 @@ public class InboundSaleReturnService extends BaseService<Inbound> {
      */
     @Transactional(rollbackFor = {Exception.class})
     public ResponseResultVO<?> saleReturnHandleInbound(InboundVO inboundVO) {
-        //大编辑标识
-        if (inboundVO.getAllEdit() != null && inboundVO.getAllEdit()) {
-            //region 编辑明细
-            //校验明细
-            if (inboundVO.getItemList().size() == 0) {
-                return ResponseResultUtil.error(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
-                        ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
+        //region 编辑明细
+        //校验明细
+        if (inboundVO.getItemList().size() == 0) {
+            return ResponseResultUtil.error(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
+                    ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
+        }
+        for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
+            if (inboundItemVO.getIntoId() != null) {
+                //编辑明细
+                inboundItemVO.setCostPrice(inboundItemVO.getPriceInto())
+                        .setCostAmt(inboundItemVO.getIntoingQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
+                        .setIntoQty(inboundItemVO.getIntoingQty())
+                        .setIntoAmt(inboundItemVO.getIntoingAmt());
+                //入库状态
+                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()))
+                );
             }
-            for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
-                if (inboundItemVO.getIntoId() != null) {
-                    //编辑明细
-                    inboundItemVO.setCostPrice(inboundItemVO.getPriceInto())
-                            .setCostAmt(inboundItemVO.getIntoingQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
-                            .setIntoQty(inboundItemVO.getIntoingQty())
-                            .setIntoAmt(inboundItemVO.getIntoingAmt());
-                    //入库状态
-                    String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
-                    inboundItemVO.setIntoStatus(intoStatus);
-                    //实体转换
-                    InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
-                    //修改
-                    inboundItemMapper.updateById(inboundItem);
+            //endregion
+            //region 新建明细
+            else {
+                inboundItemVO
+                        .setIntoQty(inboundItemVO.getIntoingQty())
+                        .setIntoAmt(inboundItemVO.getIntoingAmt())
+                        .setIntoId(inboundVO.getIntoId())
+                        .setCostPrice(inboundItemVO.getPriceInto())
+                        .setCostAmt(inboundItemVO.getIntoingQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
+                        .setIntoType(Constant.IntoType.PURRETURN.getName());
+                //入库状态
+                String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
+                inboundItemVO.setIntoStatus(intoStatus);
+                //实体转换
+                InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
+                //新建
+                inboundItemMapper.insert(inboundItem);
+            }
+            //endregion
+
+            //region  销售退货明细
+            if (inboundItemVO.getFromItemId() != null) {
+//                    IntoReturnItemResponse intoReturnItemResponse = intoReturnItemMapper.selectById(inboundItemVO.getFromItemId());
+                IntoReturnItem intoReturnItem = new IntoReturnItem();
+                intoReturnItem.setItemId(inboundItemVO.getFromItemId());
+//                    intoReturnItem.setOutQty(intoReturnItemResponse.getOutQty().add(inboundItemVO.getIntoQty()));
+//                    intoReturnItem.setOutAmt(intoReturnItemResponse.getOutAmt().add(inboundItemVO.getIntoAmt()));
+//                    intoReturnItem.setOutingQty(intoReturnItemResponse.getOutingQty().add(inboundItemVO.getIntoingQty()));
+//                    intoReturnItem.setOutingAmt(intoReturnItemResponse.getOutingAmt().add(inboundItemVO.getIntoingAmt()));
+                intoReturnItem.setOutQty(inboundItemVO.getIntoQty());
+                intoReturnItem.setOutAmt(inboundItemVO.getIntoAmt());
+                intoReturnItem.setOutingQty(inboundItemVO.getIntoingQty());
+                intoReturnItem.setOutingAmt(inboundItemVO.getIntoingAmt());
+                //出库状态
+                String outStatus = this.setOutStatus(intoReturnItem.getOutingQty(), intoReturnItem.getOutQty());
+                intoReturnItem.setOutStatus(outStatus);
+                //修改
+                int countRow = intoReturnItemMapper.updateById(intoReturnItem);
+                //数量超出
+                if (countRow == 0) {
+                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
                 }
-                //endregion
-                //region 新建明细
-                else {
-                    Map<String, Object> map = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHERINBOUNDITEM.getName(), true);
-                    inboundItemVO
-                            .setItemId(map.get("outId").toString())
-                            .setIntoQty(inboundItemVO.getIntoingQty())
-                            .setIntoAmt(inboundItemVO.getIntoingAmt())
-                            .setIntoId(inboundVO.getIntoId())
-                            .setCostPrice(inboundItemVO.getPriceInto())
-                            .setCostAmt(inboundItemVO.getIntoingQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
-                            .setIntoType(Constant.IntoType.PURRETURN.getName());
-                    //入库状态
-                    String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
-                    inboundItemVO.setIntoStatus(intoStatus);
-                    //实体转换
+            }
+            //endregion
+        }
+        //endregion
+
+        //region 删除明细
+        BigDecimal sumDelOutQty = BigDecimal.ZERO;
+        BigDecimal sumDelOutAmt = BigDecimal.ZERO;
+        BigDecimal sumDelOutingQty = BigDecimal.ZERO;
+        BigDecimal sumDelOutingAmt = BigDecimal.ZERO;
+        if (inboundVO.getDeleteItemList() != null) {
+            sumDelOutQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+            sumDelOutAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+            sumDelOutingQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+            sumDelOutingAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+            for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
+                if (inboundItemVO.getItemId() != null) {
                     InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
-                    //新建
-                    inboundItemMapper.insert(inboundItem);
+                    inboundItem.setFlgValid(false);
+                    //修改
+                    inboundItemMapper.update(inboundItem,
+                            new UpdateWrapper<InboundItem>().lambda()
+                                    .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
+                    );
                 }
-                //endregion
-
                 //region  销售退货明细
                 if (inboundItemVO.getFromItemId() != null) {
-//                    IntoReturnItemResponse intoReturnItemResponse = intoReturnItemMapper.selectById(inboundItemVO.getFromItemId());
+                    //region 销售退货订单明细
+//                        IntoReturnItemResponse intoReturnItemResponse = intoReturnItemMapper.selectById(inboundItemVO.getFromItemId());
                     IntoReturnItem intoReturnItem = new IntoReturnItem();
                     intoReturnItem.setItemId(inboundItemVO.getFromItemId());
-//                    intoReturnItem.setOutQty(intoReturnItemResponse.getOutQty().add(inboundItemVO.getIntoQty()));
-//                    intoReturnItem.setOutAmt(intoReturnItemResponse.getOutAmt().add(inboundItemVO.getIntoAmt()));
-//                    intoReturnItem.setOutingQty(intoReturnItemResponse.getOutingQty().add(inboundItemVO.getIntoingQty()));
-//                    intoReturnItem.setOutingAmt(intoReturnItemResponse.getOutingAmt().add(inboundItemVO.getIntoingAmt()));
-                    intoReturnItem.setOutQty(inboundItemVO.getIntoQty());
-                    intoReturnItem.setOutAmt(inboundItemVO.getIntoAmt());
-                    intoReturnItem.setOutingQty(inboundItemVO.getIntoingQty());
-                    intoReturnItem.setOutingAmt(inboundItemVO.getIntoingAmt());
+//                        intoReturnItem.setOutQty(intoReturnItemResponse.getOutQty().subtract(inboundItemVO.getIntoQty()));
+//                        intoReturnItem.setOutAmt(intoReturnItemResponse.getOutAmt().subtract(inboundItemVO.getIntoAmt()));
+//                        intoReturnItem.setOutingQty(intoReturnItemResponse.getOutingQty().subtract(inboundItemVO.getIntoingQty()));
+//                        intoReturnItem.setOutingAmt(intoReturnItemResponse.getOutingAmt().subtract(inboundItemVO.getIntoingAmt()));
+                    intoReturnItem.setOutQty(inboundItemVO.getIntoQty().negate());
+                    intoReturnItem.setOutAmt(inboundItemVO.getIntoAmt().negate());
+                    intoReturnItem.setOutingQty(inboundItemVO.getIntoingQty().negate());
+                    intoReturnItem.setOutingAmt(inboundItemVO.getIntoingAmt().negate());
                     //出库状态
                     String outStatus = this.setOutStatus(intoReturnItem.getOutingQty(), intoReturnItem.getOutQty());
                     intoReturnItem.setOutStatus(outStatus);
@@ -312,113 +386,72 @@ public class InboundSaleReturnService extends BaseService<Inbound> {
                     if (countRow == 0) {
                         throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
                     }
+                    //endregion
                 }
                 //endregion
-            }
-            //endregion
-
-            //region 删除明细
-            BigDecimal sumDelOutQty = BigDecimal.ZERO;
-            BigDecimal sumDelOutAmt = BigDecimal.ZERO;
-            BigDecimal sumDelOutingQty = BigDecimal.ZERO;
-            BigDecimal sumDelOutingAmt = BigDecimal.ZERO;
-            if (inboundVO.getDeleteItemList() != null) {
-                sumDelOutQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
-                sumDelOutAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
-                sumDelOutingQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
-                sumDelOutingAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
-                for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
-                    if (inboundItemVO.getItemId() != null) {
-                        InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
-                        inboundItem.setFlgValid(false);
-                        inboundItemMapper.updateById(inboundItem);
-                    }
-                    //region  销售退货明细
-                    if (inboundItemVO.getFromItemId() != null) {
-                        //region 销售退货订单明细
-//                        IntoReturnItemResponse intoReturnItemResponse = intoReturnItemMapper.selectById(inboundItemVO.getFromItemId());
-                        IntoReturnItem intoReturnItem = new IntoReturnItem();
-                        intoReturnItem.setItemId(inboundItemVO.getFromItemId());
-//                        intoReturnItem.setOutQty(intoReturnItemResponse.getOutQty().subtract(inboundItemVO.getIntoQty()));
-//                        intoReturnItem.setOutAmt(intoReturnItemResponse.getOutAmt().subtract(inboundItemVO.getIntoAmt()));
-//                        intoReturnItem.setOutingQty(intoReturnItemResponse.getOutingQty().subtract(inboundItemVO.getIntoingQty()));
-//                        intoReturnItem.setOutingAmt(intoReturnItemResponse.getOutingAmt().subtract(inboundItemVO.getIntoingAmt()));
-                        intoReturnItem.setOutQty(inboundItemVO.getIntoQty().negate());
-                        intoReturnItem.setOutAmt(inboundItemVO.getIntoAmt().negate());
-                        intoReturnItem.setOutingQty(inboundItemVO.getIntoingQty().negate());
-                        intoReturnItem.setOutingAmt(inboundItemVO.getIntoingAmt().negate());
-                        //出库状态
-                        String outStatus = this.setOutStatus(intoReturnItem.getOutingQty(), intoReturnItem.getOutQty());
-                        intoReturnItem.setOutStatus(outStatus);
-                        //修改
-                        int countRow = intoReturnItemMapper.updateById(intoReturnItem);
-                        //数量超出
-                        if (countRow == 0) {
-                            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
-                        }
-                        //endregion
-                    }
-                    //endregion
 
-                }
             }
-            //endregion
+        }
+        //endregion
 
-            //region 编辑总单
-            BigDecimal sumOutQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
-            BigDecimal sumOutAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
-            BigDecimal sumOutingQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
-            BigDecimal sumOutingAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
-            inboundVO.setIntoQty(sumOutQty);
-            inboundVO.setIntoAmt(sumOutAmt);
-            inboundVO.setIntoingQty(sumOutingQty);
-            inboundVO.setIntoAmt(sumOutingAmt);
-            //已入库数量==入库中数量   入库完成
-            if (inboundVO.getIntoQty().compareTo(inboundVO.getIntoingQty()) == 0) {
-                //已入库
-                inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
-            } else {
-                //入库中
-                inboundVO.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
-            }
-            //实体转换
-            Inbound inbound = inboundConvert.convertToPo(inboundVO);
-            //修改
-            inboundMapper.updateById(inbound);
-            //endregion
+        //region 编辑总单
+        InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
+        BigDecimal sumOutQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+        BigDecimal sumOutAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+        BigDecimal sumOutingQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+        BigDecimal sumOutingAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+        inboundVO.setIntoQty(sumOutQty);
+        inboundVO.setIntoAmt(sumOutAmt);
+        inboundVO.setIntoingQty(inboundResponse.getIntoingQty().subtract(sumOutingQty));
+        inboundVO.setIntoingAmt(inboundResponse.getIntoingAmt().subtract(sumOutingAmt));
+        //已入库数量==入库中数量   入库完成
+        if (inboundVO.getIntoQty().compareTo(inboundVO.getIntoingQty()) == 0) {
+            //已入库
+            inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
+        } else {
+            //入库中
+            inboundVO.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
+        }
+        //实体转换
+        Inbound inbound = inboundConvert.convertToPo(inboundVO);
+        //修改
+        inboundMapper.update(inbound,
+                new UpdateWrapper<Inbound>().lambda()
+                        .eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
+        );
+        //endregion
 
-            //region  修改销售退货订单
-            if (inboundVO.getFromId() != null) {
-                //查询
+        //region  修改销售退货订单
+        if (inboundVO.getFromId() != null) {
+            //查询
 //                IntoReturnResponse intoReturnResponse = intoReturnMapper.selectById(inboundVO.getFromId());
-                IntoReturn intoReturn = new IntoReturn();
-                intoReturn.setReturnId(inboundVO.getFromId());
+            IntoReturn intoReturn = new IntoReturn();
+            intoReturn.setReturnId(inboundVO.getFromId());
 //                intoReturn.setOutQty(intoReturnResponse.getOutQty().add(sumOutQty).subtract(sumDelOutQty));
 //                intoReturn.setOutAmt(intoReturnResponse.getOutAmt().add(sumOutAmt).subtract(sumDelOutAmt));
 //                intoReturn.setOutingQty(intoReturnResponse.getOutingQty().subtract(sumOutQty).subtract(sumDelOutingQty));
 //                intoReturn.setOutingAmt(intoReturnResponse.getOutingAmt().subtract(sumOutAmt).subtract(sumDelOutingAmt));
-                intoReturn.setOutQty(sumOutQty.subtract(sumDelOutQty));
-                intoReturn.setOutAmt(sumOutAmt.subtract(sumDelOutAmt));
-                intoReturn.setOutingQty((sumOutQty.add(sumDelOutingQty)).negate());
-                intoReturn.setOutingAmt((sumOutAmt.add(sumDelOutingAmt)).negate());
-                //入库状态
-                String outStatus = this.setOutStatus(intoReturn.getOutingQty(), intoReturn.getOutQty());
-                intoReturn.setOutStatus(outStatus);
-                //修改
-                int countRow = intoReturnMapper.updateById(intoReturn);
-                //数量超出
-                if (countRow == 0) {
-                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
-                }
-
+            intoReturn.setOutQty(sumOutQty.subtract(sumDelOutQty));
+            intoReturn.setOutAmt(sumOutAmt.subtract(sumDelOutAmt));
+            intoReturn.setOutingQty((sumOutQty.add(sumDelOutingQty)).negate());
+            intoReturn.setOutingAmt((sumOutAmt.add(sumDelOutingAmt)).negate());
+            //入库状态
+            String outStatus = this.setOutStatus(intoReturn.getOutingQty(), intoReturn.getOutQty());
+            intoReturn.setOutStatus(outStatus);
+            //修改
+            int countRow = intoReturnMapper.updateById(intoReturn);
+            //数量超出
+            if (countRow == 0) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
             }
-            //endregion
-
-            //todo 如果是已入库 调用库存  后续写库存这里补上
-            //region 修改库存
 
-            //endregion
         }
+        //endregion
+
+        //todo 如果是已入库 调用库存  后续写库存这里补上
+        //region 修改库存
+
+        //endregion
         return ResponseResultUtil.success(inboundVO);
     }
 
@@ -468,7 +501,11 @@ public class InboundSaleReturnService extends BaseService<Inbound> {
         inbound.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
         inbound.setIntoQty(BigDecimal.ZERO);
         inbound.setIntoAmt(BigDecimal.ZERO);
-        inboundMapper.updateById(inbound);
+        //修改
+        inboundMapper.update(inbound,
+                new UpdateWrapper<Inbound>().lambda()
+                        .eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
+        );
         //endregion
 
         //region 明细数据
@@ -510,7 +547,11 @@ public class InboundSaleReturnService extends BaseService<Inbound> {
                     .setIntoQty(BigDecimal.ZERO)
                     .setIntoAmt(BigDecimal.ZERO)
                     .setItemId(inboundItemResponse.getItemId());
-            inboundItemMapper.updateById(inboundItem);
+            //修改
+            inboundItemMapper.update(inboundItem,
+                    new UpdateWrapper<InboundItem>().lambda()
+                            .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
+            );
             //endregion
         }
         //endregion
@@ -533,8 +574,8 @@ public class InboundSaleReturnService extends BaseService<Inbound> {
     public String setIntoStatus(BigDecimal intoingQty, BigDecimal intoQty) {
         //入库状态
         String intoStatus = null;
-        //已入库数量=0 入库中数量>0
-        if (intoQty.compareTo(BigDecimal.ZERO) == 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0) {
+        //已入库数量>0 入库中数量>0
+        if (intoQty.compareTo(BigDecimal.ZERO) > 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0 ) {
             //入库中
             intoStatus = Constant.IntoStatus.RUKUZHONG.getName();
         }
@@ -543,10 +584,10 @@ public class InboundSaleReturnService extends BaseService<Inbound> {
             //待入库
             intoStatus = Constant.IntoStatus.DAIRUKU.getName();
         }
-        //已入库数量>0 入库中数量>0
-        else if (intoQty.compareTo(BigDecimal.ZERO) > 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0) {
-            //入库
-            intoStatus = Constant.IntoStatus.RUKUZHONG.getName();
+        //已入库数量>0 入库中数量=0
+        else if (intoQty.compareTo(BigDecimal.ZERO) >0 && intoingQty.compareTo(BigDecimal.ZERO)==0) {
+            //入库
+            intoStatus = Constant.IntoStatus.YIRUKU.getName();
         }
         return intoStatus;
     }
@@ -558,24 +599,26 @@ public class InboundSaleReturnService extends BaseService<Inbound> {
      * @author : 寇珊珊
      */
     public String setOutStatus(BigDecimal outingQty, BigDecimal outQty) {
-        //库状态
+        //库状态
         String outStatus = null;
-        //已入库数量=0 入库中数量>0
-        if (outQty.compareTo(BigDecimal.ZERO) == 0 && outingQty.compareTo(BigDecimal.ZERO) > 0) {
-            //库中
-            outStatus = Constant.OutStatus.CHUKUZHONG.getName();
+        //已出库数量>0 出库中数量>0
+        if (outQty.compareTo(BigDecimal.ZERO) > 0 && outingQty.compareTo(BigDecimal.ZERO) > 0 ) {
+            //库中
+            outStatus =Constant.OutStatus.CHUKUZHONG.getName();
         }
-        //已入库数量=0 入库中数量=0
+        //出入库数量=0 出库中数量=0
         else if (outQty.compareTo(BigDecimal.ZERO) == 0 && outingQty.compareTo(BigDecimal.ZERO) == 0) {
-            //待
+            //待
             outStatus = Constant.OutStatus.DAICHUKU.getName();
         }
-        //已入库数量>0 入库中数量>0
-        else if (outQty.compareTo(BigDecimal.ZERO) > 0 && outingQty.compareTo(BigDecimal.ZERO) > 0) {
-            //入库中
+        //已出库数量>0 出库中数量=0
+        else if (outQty.compareTo(BigDecimal.ZERO) >0 && outingQty.compareTo(BigDecimal.ZERO)==0) {
+            //已出库
             outStatus = Constant.OutStatus.YICHUKU.getName();
         }
         return outStatus;
     }
 
+
+
 }

+ 19 - 0
src/main/java/com/dk/mdm/service/ivt/InboundService.java

@@ -121,5 +121,24 @@ public class InboundService extends BaseService<Inbound> {
 
 
 
+	/**
+	 * @desc   : 获取单据信息(编辑用)
+	 * @date   : 2024/3/14 16:38
+	 * @author : 寇珊珊
+	 */
+	public ResponseResultVO<?> selectByUpdate(String id) {
+		Map<String, Object> dataInfo = new HashMap<>();
+		//总单
+		InboundResponse inboundResponse = inboundMapper.selectById(id);
+		dataInfo.put("data", inboundResponse);
+
+		// 明细
+		List<InboundItemResponse> inboundItemResponses = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(id));
+		dataInfo.put("dataItem", inboundItemResponses);
+		return ResponseResultUtil.success(dataInfo);
+	}
+
+
+
 
 }