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

+ 118 - 0
src/main/java/com/dk/mdm/controller/ivt/OutboundOtherController.java

@@ -0,0 +1,118 @@
+package com.dk.mdm.controller.ivt;
+
+
+import com.dk.common.model.pojo.PageList;
+import com.dk.common.response.ResponseResultVO;
+import com.dk.common.service.BaseService;
+import com.dk.mdm.model.pojo.ivt.Outbound;
+import com.dk.mdm.model.query.ivt.OutboundQuery;
+import com.dk.mdm.model.response.ivt.InboundResponse;
+import com.dk.mdm.model.vo.ivt.OutboundVO;
+import com.dk.mdm.service.ivt.InboundService;
+import com.dk.mdm.service.ivt.OutboundOtherService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+import java.util.Map;
+
+
+@Api(tags = "其他出库单API接口")
+@RestController
+@RequestMapping("/ivt/outbound_other")
+public class OutboundOtherController {
+
+    public BaseService<Outbound> getService() {
+        return outboundOtherService;
+    }
+
+    @Autowired
+    private OutboundOtherService outboundOtherService;
+
+    @Autowired
+    private InboundService inboundService;
+
+
+
+    /**
+     * @desc   : 条件查询
+     * @date   : 2024/3/7 14:09
+     * @author : 寇珊珊
+     */
+    @ApiOperation(value = "条件查询", notes = "条件查询")
+    @PostMapping({"list_by"})
+    public ResponseResultVO<PageList<InboundResponse>> selectByCond(@Valid @RequestBody OutboundQuery outboundQuery) {
+        return outboundOtherService.selectByCond(outboundQuery);
+    }
+
+    /**
+     * @desc   : 查询明细信息
+     * @date   : 2024/3/9 15:45
+     * @author : 寇珊珊
+     */
+    @ApiOperation(value = "明细信息条件查询", notes = "明细信息条件查询")
+    @PostMapping({"select_outbound_other_item_info_by_id/{id}"})
+    public ResponseResultVO<Map<String, Object>> selectOutboundOtherItemInfoById(@PathVariable String id) {
+        return outboundOtherService.selectOutboundOtherItemInfoById(id);
+    }
+
+
+    /**
+     * @desc   : 其他出库新建
+     * @date   : 2024/3/7 14:00
+     * @author : 寇珊珊
+     */
+    @ApiOperation(
+            value = "其他出库新建",
+            notes = "其他出库新建"
+    )
+    @PostMapping({"other_inbound_insert"})
+    public ResponseResultVO<?> otherOutboundInsert(@Valid @RequestBody OutboundVO outboundVO) {
+        return outboundOtherService.otherOutboundInsert(outboundVO);
+    }
+
+
+    /**
+     * @desc   : 其他出库办理
+     * @date   : 2024/3/7 15:34
+     * @author : 寇珊珊
+     */
+    @ApiOperation(
+            value = "其他出库办理",
+            notes = "其他出库办理"
+    )
+    @PostMapping({"other_handle_inbound"})
+    public ResponseResultVO<?> otherHandleOutbound(@Valid @RequestBody OutboundVO outboundVO) {
+        return outboundOtherService.otherHandleOutbound(outboundVO);
+    }
+
+
+
+    /**
+     * @desc   : 其它入库撤销
+     * @date   : 2024/3/7 17:06
+     * @author : 寇珊珊
+     */
+    @ApiOperation(
+            value = "其它入库撤销",
+            notes = "其它入库撤销"
+    )
+    @PostMapping({"other_inbound_cancel"})
+    public ResponseResultVO<?> otherOutboundCancel(@Valid @RequestBody OutboundVO outboundVO){
+        return outboundOtherService.otherOutboundCancel(outboundVO);
+    }
+
+    /**
+     * @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);
+    }
+
+}

+ 9 - 0
src/main/java/com/dk/mdm/mapper/sale/OrderItemMapper.java

@@ -3,6 +3,7 @@ package com.dk.mdm.mapper.sale;
 import com.dk.mdm.model.pojo.sale.OrderItem;
 import com.dk.common.mapper.BaseMapper;
 import com.dk.mdm.model.query.sale.OrderItemQuery;
+import com.dk.mdm.model.response.ivt.IntoReturnResponse;
 import com.dk.mdm.model.response.sale.OrderItemResponse;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
@@ -55,5 +56,13 @@ public interface OrderItemMapper extends BaseMapper<OrderItem> {
      * @date : 2024-03-09 15:44
      */
     List<OrderItem> selectByZIdForUpdate(String id);
+
+
+    /**
+     * @desc   : 根据id查询
+     * @date   : 2024/3/19 15:01
+     * @author : 寇珊珊
+     */
+    OrderItemResponse selectById(@Param("itemId") String itemId);
 }
 

+ 76 - 4
src/main/java/com/dk/mdm/mapper/sale/OrderItemMapper.xml

@@ -9,6 +9,11 @@
         , order_id, item_index, sku_id, item_qty, price_std, amt_std, price_sale, item_amt, price_discount, non_std_code, out_status, outing_qty, outing_amt, out_qty, out_amt, return_qty, return_amt, remarks, flg_valid, cp_id, op_create_time, op_create_user_id, op_update_time, op_update_user_id, op_app_code, op_timestamp, op_db_user
     </sql>
 
+    <sql id="Base_Column_List_Response">
+        t.item_id, t.order_id, t.item_index, t.sku_id, t.item_qty, t.price_std, t.amt_std, t.price_sale, t.item_amt, t.price_discount, t.non_std_code,
+        t.out_status, t.outing_qty, t.outing_amt, t.out_qty, t.out_amt, t.return_qty, t.return_amt, t.remarks, t.flg_valid, t.cp_id
+    </sql>
+
     <!-- 通用查询映射结果 -->
     <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.sale.OrderItem">
         <id column="item_id" property="itemId"/>
@@ -189,11 +194,11 @@
     </select>
 
     <!-- 根据主键查询表t_psi_order_item的一行数据 -->
-    <select id="selectById" resultMap="BaseResultMap">
+    <select id="selectById" resultMap="BaseResultMapResponse">
         SELECT
-        <include refid="Base_Column_List"/>
-        FROM dkic_b.t_psi_order_item
-        WHERE item_id = #{itemId}::uuid
+        <include refid="Base_Column_List_Response"/>
+        FROM dkic_b.t_psi_order_item t
+        WHERE t.item_id = #{itemId}::uuid
     </select>
 
     <!-- 根据主键锁定表t_psi_order_item的一行数据 -->
@@ -355,4 +360,71 @@
           and t.order_id = #{orderId}::uuid
         order by t.item_index
     </select>
+
+    <!-- 根据id修改-->
+    <update id="updateById" parameterType="com.dk.mdm.model.pojo.sale.OrderItem">
+        update dkic_b.t_psi_order_item
+        <set>
+            <if test=" et!=null and et.itemIndex != null">
+                item_index = #{et.itemIndex,jdbcType=INTEGER},
+            </if>
+            <if test=" et!=null and et.skuId != null">
+                sku_id = #{et.skuId,typeHandler=UuidTypeHandler},
+            </if>
+            <if test=" et!=null and et.itemQty != null">
+                item_qty = #{et.itemQty,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.priceStd != null">
+                price_std = #{et.priceStd,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.amtStd != null">
+                amt_std = #{et.amtStd,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.priceSale != null">
+                price_sale = #{et.priceSale,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.itemAmt != null">
+                item_amt = #{et.itemAmt,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.priceDiscount != null">
+                price_discount = #{et.priceDiscount,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.nonStdCode != null">
+                non_std_code = #{et.nonStdCode,jdbcType=VARCHAR},
+            </if>
+            <if test=" et!=null and et.outStatus != null">
+                out_status = #{et.outStatus,jdbcType=VARCHAR},
+            </if>
+            <if test=" et!=null and et.outingQty != null">
+                outing_qty = outing_qty + #{et.outingQty,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.outingAmt != null">
+                outing_amt = outing_amt + #{et.outingAmt,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.outQty != null">
+                out_qty = out_qty + #{et.outQty,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.outAmt != null">
+                out_amt = out_amt + #{et.outAmt,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.returnQty != null">
+                return_qty = #{et.returnQty,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.returnAmt != null">
+                return_amt = #{et.returnAmt,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.remarks != null">
+                remarks = #{et.remarks,jdbcType=VARCHAR},
+            </if>
+            <if test=" et!=null and et.flgValid != null">
+                flg_valid = #{et.flgValid,jdbcType=BOOLEAN},
+            </if>
+            <if test=" et!=null and et.cpId != null">
+                cp_id = #{et.cpId,jdbcType=INTEGER},
+            </if>
+        </set>
+        where item_id = #{et.itemId,typeHandler=UuidTypeHandler}
+        and item_qty >=(out_qty + outing_qty)
+    </update>
+
 </mapper>

+ 114 - 0
src/main/java/com/dk/mdm/mapper/sale/OrderMapper.xml

@@ -628,4 +628,118 @@
             )
         </foreach>
     </insert>
+
+    <!-- 根据id修改-->
+    <update id="updateById" parameterType="com.dk.mdm.model.pojo.sale.Order">
+        update dkic_b.t_psi_order
+        <set>
+            <if test=" et!=null and et.orderType != null">
+                order_type =#{et.orderType,jdbcType=VARCHAR},
+            </if>
+            <if test=" et!=null and et.orgId != null">
+                org_id =#{et.orgId,typeHandler=UuidTypeHandler},
+            </if>
+            <if test=" et!=null and et.staffId != null">
+                staff_id =#{et.staffId,typeHandler=UuidTypeHandler},
+            </if>
+            <if test=" et!=null and et.cusId != null">
+                cus_id =#{et.cusId,typeHandler=UuidTypeHandler},
+            </if>
+            <if test=" et!=null and et.addressArea != null">
+                address_area =#{et.addressArea,typeHandler=JsonTypeHandler},
+            </if>
+            <if test=" et!=null and et.addressName != null">
+                address_name =#{et.addressName,jdbcType=VARCHAR},
+            </if>
+            <if test=" et!=null and et.addressNo != null">
+                address_no =#{et.addressNo,jdbcType=VARCHAR},
+            </if>
+            <if test=" et!=null and et.addressGcj02 != null">
+                address_gcj02 =#{et.addressGcj02,typeHandler=JsonTypeHandler},
+            </if>
+            <if test=" et!=null and et.addressFull != null">
+                address_full =#{et.addressFull,jdbcType=VARCHAR},
+            </if>
+            <if test=" et!=null and et.contactName != null">
+                contact_name =#{et.contactName,jdbcType=VARCHAR},
+            </if>
+            <if test=" et!=null and et.contactPhone != null">
+                contact_phone =#{et.contactPhone,jdbcType=VARCHAR},
+            </if>
+            <if test=" et!=null and et.salesChannel != null">
+                sales_channel =#{et.salesChannel,jdbcType=OTHER},
+            </if>
+            <if test=" et!=null and et.deliveryDate != null">
+                delivery_date =#{et.deliveryDate,jdbcType=DATE},
+            </if>
+            <if test=" et!=null and et.sumQuantity != null">
+                sum_quantity =#{et.sumQuantity,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.sumStandard != null">
+                sum_standard =#{et.sumStandard,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.sumAmount != null">
+                sum_amount =#{et.sumAmount,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.saleDiscount != null">
+                sale_discount =#{et.saleDiscount,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.orderStatus != null">
+                order_status =#{et.orderStatus,jdbcType=VARCHAR},
+            </if>
+            <if test=" et!=null and et.outStatus != null">
+                out_status =#{et.outStatus,jdbcType=VARCHAR},
+            </if>
+            <if test=" et!=null and et.outingQty != null">
+                outing_qty = outing_qty + #{et.outingQty,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.outingAmt != null">
+                outing_amt = outing_amt + #{et.outingAmt,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.outQty != null">
+                out_qty =out_qty + #{et.outQty,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.outAmt != null">
+                out_amt = out_amt + #{et.outAmt,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.returnQty != null">
+                return_qty =#{et.returnQty,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.returnAmt != null">
+                return_amt =#{et.returnAmt,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.amtReceivable != null">
+                amt_receivable =#{et.amtReceivable,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.amtHandle != null">
+                amt_handle =#{et.amtHandle,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.amtResidue != null">
+                amt_residue =#{et.amtResidue,jdbcType=NUMERIC},
+            </if>
+            <if test=" et!=null and et.remarks != null">
+                remarks =#{et.remarks,jdbcType=VARCHAR},
+            </if>
+            <if test=" et!=null and et.annexPaths != null">
+                annex_paths =#{et..annexPaths,typeHandler=JsonTypeHandler},
+            </if>
+            <if test=" et!=null and et.makeStaff != null">
+                make_staff =#{et.makeStaff,jdbcType=OTHER},
+            </if>
+            <if test=" et!=null and et.makeTime != null">
+                make_time =#{et.makeTime,jdbcType=TIMESTAMP},
+            </if>
+            <if test=" et!=null and et.flgValid != null">
+                flg_valid =#{et.flgValid,jdbcType=BOOLEAN},
+            </if>
+            <if test=" et!=null and et.cpId != null">
+                cp_id =#{et.cpId,jdbcType=INTEGER},
+            </if>
+        </set>
+        where order_id =#{et.orderId,typeHandler=UuidTypeHandler}
+        and sum_quantity >= (out_qty + outing_qty)
+    </update>
+
+
+
 </mapper>

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

@@ -188,18 +188,18 @@ public class InboundItem  extends PageInfo<InboundItem> implements Serializable
 
 
     /**
-     * 成本单价
+     * 入库核对单价
      */
-    @Excel(name = "成本单价")
-    @ApiModelProperty(value = "成本单价")
+    @Excel(name = "入库核对单价")
+    @ApiModelProperty(value = "入库核对单价")
     private BigDecimal costPrice;
 
 
     /**
-     * 成本金额
+     * 入库核对金额
      */
-    @Excel(name = "成本金额")
-    @ApiModelProperty(value = "成本金额")
+    @Excel(name = "入库核对金额")
+    @ApiModelProperty(value = "入库核对金额")
     private BigDecimal costAmt;
 
 

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

@@ -176,18 +176,18 @@ public class InboundItemResponse  {
 
 
     /**
-     * 成本单价
+     * 入库核对单价
      */
-    @Excel(name = "成本单价")
-    @ApiModelProperty(value = "成本单价")
+    @Excel(name = "入库核对单价")
+    @ApiModelProperty(value = "入库核对单价")
     private BigDecimal costPrice;
 
 
     /**
-     * 成本金额
+     * 入库核对金额
      */
-    @Excel(name = "成本金额")
-    @ApiModelProperty(value = "成本金额")
+    @Excel(name = "入库核对金额")
+    @ApiModelProperty(value = "入库核对金额")
     private BigDecimal costAmt;
 
 

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

@@ -152,16 +152,16 @@ public class InboundItemVO  {
 
 
     /**
-     * 成本单价
+     * 入库核对单价
      */
-    @ApiModelProperty(value = "成本单价")
+    @ApiModelProperty(value = "入库核对单价")
     private BigDecimal costPrice;
 
 
     /**
-     * 成本金额
+     * 入库核对金额
      */
-    @ApiModelProperty(value = "成本金额")
+    @ApiModelProperty(value = "入库核对金额")
     private BigDecimal costAmt;
 
 

+ 7 - 9
src/main/java/com/dk/mdm/service/ivt/InboundOtherService.java

@@ -145,7 +145,8 @@ public class InboundOtherService extends BaseService<Inbound> {
 			inboundItemVO.setOutQty(BigDecimal.ZERO);
 			//入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
 			if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
-				inboundItemVO.setIntoQty(inboundItemVO.getIntoingQty())
+				inboundItemVO
+						.setIntoQty(inboundItemVO.getIntoingQty())
 						.setIntoAmt(inboundItemVO.getIntoingAmt())
 						.setIntoingQty(BigDecimal.ZERO)
 						.setIntoingAmt(BigDecimal.ZERO)
@@ -155,12 +156,6 @@ public class InboundOtherService extends BaseService<Inbound> {
 						.setIntoQty(BigDecimal.ZERO)
 						.setIntoAmt(BigDecimal.ZERO);
 			}
-			//成本单价
-			inboundItemVO.setCostPrice(inboundItemVO.getPriceInto());
-			//成本金额
-			inboundItemVO.setCostAmt((inboundItemVO.getIntoingQty().add(inboundItemVO.getIntoQty())).multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP));
-			//库存数量  已入库-出库
-			inboundItemVO.setInvQty(inboundItemVO.getIntoQty().subtract(inboundItemVO.getOutQty()));
 			//入库状态
 			inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
 			//实体转换
@@ -224,7 +219,7 @@ public class InboundOtherService extends BaseService<Inbound> {
 						.setIntoAmt(inboundItemVO.getIntoingAmt())
 						.setIntoId(inboundVO.getIntoId())
 						.setCostPrice(inboundItemVO.getPriceInto())
-						.setCostAmt((inboundItemVO.getIntoingQty().add(inboundItemVO.getIntoQty())).multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
+						.setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
 						.setIntoType(Constant.IntoType.OTHER.getName());
 				//入库状态
 				String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
@@ -311,12 +306,15 @@ public class InboundOtherService extends BaseService<Inbound> {
 		List<InboundItemResponse> orderEntryItemResponsesList = inboundItemMapper.selectByCond(inboundItemQuery);
 		for (InboundItemResponse inboundItemResponse : orderEntryItemResponsesList) {
 			InboundItem inboundItem = new InboundItem();
-			inboundItem.setIntoId(inbound.getIntoId())
+			inboundItem
+					.setIntoId(inbound.getIntoId())
 					.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName())
 					.setIntoingQty(inboundItemResponse.getIntoingQty().add(inboundItemResponse.getIntoQty()))
 					.setIntoingAmt(inboundItemResponse.getIntoingAmt().add(inboundItemResponse.getIntoAmt()))
 					.setIntoQty(BigDecimal.ZERO)
 					.setIntoAmt(BigDecimal.ZERO)
+					.setCostPrice(BigDecimal.ZERO)
+					.setCostAmt(BigDecimal.ZERO)
 					.setItemId(inboundItemResponse.getItemId());
 			//修改
 			inboundItemMapper.update(inboundItem,

+ 50 - 24
src/main/java/com/dk/mdm/service/ivt/InboundPurchaseReturnService.java

@@ -25,6 +25,8 @@ import com.dk.mdm.model.query.ivt.InboundItemQuery;
 import com.dk.mdm.model.query.ivt.InboundQuery;
 import com.dk.mdm.model.response.ivt.InboundItemResponse;
 import com.dk.mdm.model.response.ivt.InboundResponse;
+import com.dk.mdm.model.response.ivt.IntoReturnItemResponse;
+import com.dk.mdm.model.response.ivt.IntoReturnResponse;
 import com.dk.mdm.model.vo.ivt.InboundItemVO;
 import com.dk.mdm.model.vo.ivt.InboundVO;
 import com.dk.mdm.service.common.CommonService;
@@ -131,7 +133,8 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
         inboundVO.setReturnAmt(inboundVO.getIntoingAmt());
         //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
         if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
-            inboundVO.setIntoQty(inboundVO.getIntoingQty())
+            inboundVO
+                    .setIntoQty(inboundVO.getIntoingQty())
                     .setIntoAmt(inboundVO.getIntoingAmt())
                     .setIntoingQty(BigDecimal.ZERO)
                     .setIntoingAmt(BigDecimal.ZERO)
@@ -156,8 +159,11 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
             intoReturn.setOutingAmt(inboundVO.getIntoingAmt().negate());
             intoReturn.setOutQty(inboundVO.getIntoQty());
             intoReturn.setOutAmt(inboundVO.getIntoQty());
+            //根据id查询
+            IntoReturnResponse intoReturnResponse = intoReturnMapper.selectById(inboundVO.getFromId());
             //入库状态
-            String outStatus = this.setOutStatus(intoReturn.getOutingQty(), intoReturn.getOutQty());
+            String outStatus = this.setOutStatus(intoReturnResponse.getOutingQty().add(intoReturn.getOutingQty()),
+                    intoReturnResponse.getOutQty().add(intoReturn.getOutQty()));
             intoReturn.setOutStatus(outStatus);
             //修改
             int countRow = intoReturnMapper.updateById(intoReturn);
@@ -182,22 +188,19 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
             inboundItemVO.setIntoType(inboundVO.getIntoType());
             //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
             if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
-                inboundItemVO.setIntoQty(inboundItemVO.getIntoingQty())
+                inboundItemVO
+                        .setIntoQty(inboundItemVO.getIntoingQty())
                         .setIntoAmt(inboundItemVO.getIntoingAmt())
                         .setIntoingQty(BigDecimal.ZERO)
                         .setIntoingAmt(BigDecimal.ZERO)
+                        .setCostPrice(inboundItemVO.getPriceInto())
+                        .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
                 ;
             } else {
                 inboundItemVO
                         .setIntoQty(BigDecimal.ZERO)
                         .setIntoAmt(BigDecimal.ZERO);
             }
-            //成本单价
-            inboundItemVO.setCostPrice(inboundItemVO.getPriceInto());
-            //成本金额
-            inboundItemVO.setCostAmt((inboundItemVO.getIntoingQty().add(inboundItemVO.getIntoQty())).multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP));
-            //库存数量  已入库-出库
-            inboundItemVO.setInvQty(inboundItemVO.getIntoQty().abs().subtract(inboundItemVO.getOutQty()));
             //入库状态
             inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
             //实体转换
@@ -214,8 +217,11 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
                 intoReturnItem.setOutAmt(inboundItemVO.getIntoAmt().abs());
                 intoReturnItem.setOutingQty(inboundItemVO.getIntoingQty().abs());
                 intoReturnItem.setOutingAmt(inboundItemVO.getIntoingAmt().abs());
+                //根据id查询
+                IntoReturnItemResponse intoReturnItemResponse = intoReturnItemMapper.selectById(inboundItemVO.getFromItemId());
                 //出库状态
-                String outStatus = this.setOutStatus(intoReturnItem.getOutingQty(), intoReturnItem.getOutQty());
+                String outStatus = this.setOutStatus(intoReturnItemResponse.getOutingQty().add(intoReturnItem.getOutingQty()),
+                        intoReturnItemResponse.getOutQty().add(intoReturnItem.getOutQty()));
                 intoReturnItem.setOutStatus(outStatus);
                 //修改
                 int countRow = intoReturnItemMapper.updateById(intoReturnItem);
@@ -258,12 +264,13 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
                 //查询原单
                 InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
                 //编辑明细
-                inboundItemVO.setCostPrice(inboundItemVO.getPriceInto())
-                        .setCostAmt((inboundItemVO.getIntoingQty().add(inboundItemVO.getIntoQty())).multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
+                inboundItemVO
                         .setIntoingQty(inboundItemResponse.getIntoingQty().subtract(inboundItemVO.getIntoingQty()))
                         .setIntoingAmt(inboundItemResponse.getIntoingAmt().subtract(inboundItemVO.getIntoingAmt()))
                         .setIntoQty(inboundItemResponse.getIntoingQty().add(inboundItemVO.getIntoingQty()))
-                        .setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt()));
+                        .setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt()))
+                        .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);
@@ -283,7 +290,7 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
                         .setIntoAmt(inboundItemVO.getIntoingAmt())
                         .setIntoId(inboundVO.getIntoId())
                         .setCostPrice(inboundItemVO.getPriceInto())
-                        .setCostAmt(inboundItemVO.getIntoingQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
+                        .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
                         .setIntoType(Constant.IntoType.PURRETURN.getName());
                 //入库状态
                 String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
@@ -304,8 +311,11 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
                 intoReturnItem.setOutAmt(inboundItemVO.getIntoAmt().abs());
                 intoReturnItem.setOutingQty(inboundItemVO.getIntoingQty());
                 intoReturnItem.setOutingAmt(inboundItemVO.getIntoingAmt());
+                //根据id查询
+                IntoReturnItemResponse intoReturnItemResponse = intoReturnItemMapper.selectById(inboundItemVO.getFromItemId());
                 //出库状态
-                String outStatus = this.setOutStatus(intoReturnItem.getOutingQty(), intoReturnItem.getOutQty());
+                String outStatus = this.setOutStatus(intoReturnItemResponse.getOutingQty().add(intoReturnItem.getOutingQty()),
+                        intoReturnItemResponse.getOutQty().add(intoReturnItem.getOutQty()));
                 intoReturnItem.setOutStatus(outStatus);
                 //修改
                 int countRow = intoReturnItemMapper.updateById(intoReturnItem);
@@ -348,8 +358,11 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
                     intoReturnItem.setOutAmt(inboundItemVO.getIntoAmt());
                     intoReturnItem.setOutingQty(inboundItemVO.getIntoingQty());
                     intoReturnItem.setOutingAmt(inboundItemVO.getIntoingAmt());
+                    //根据id查询
+                    IntoReturnItemResponse intoReturnItemResponse = intoReturnItemMapper.selectById(inboundItemVO.getFromItemId());
                     //出库状态
-                    String outStatus = this.setOutStatus(intoReturnItem.getOutingQty(), intoReturnItem.getOutQty());
+                    String outStatus = this.setOutStatus(intoReturnItemResponse.getOutingQty().add(intoReturnItem.getOutingQty()),
+                            intoReturnItemResponse.getOutQty().add(intoReturnItem.getOutQty()));
                     intoReturnItem.setOutStatus(outStatus);
                     //修改
                     int countRow = intoReturnItemMapper.updateById(intoReturnItem);
@@ -396,8 +409,11 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
             intoReturn.setOutAmt((sumIntoAmt.subtract(sumDelIntoAmt)).abs());
             intoReturn.setOutingQty(sumIntoQty.add(sumDelIntoingQty));
             intoReturn.setOutingAmt(sumIntoAmt.add(sumDelIntoingAmt));
-            //入库状态
-            String outStatus = this.setOutStatus(intoReturn.getOutingQty(), intoReturn.getOutQty());
+            //根据id查询
+            IntoReturnResponse intoReturnResponse = intoReturnMapper.selectById(inboundVO.getFromId());
+            //出库状态
+            String outStatus = this.setOutStatus(intoReturnResponse.getOutingQty().add(intoReturn.getOutingQty()),
+                    intoReturnResponse.getOutQty().add(intoReturn.getOutQty()));
             intoReturn.setOutStatus(outStatus);
             //修改
             int countRow = intoReturnMapper.updateById(intoReturn);
@@ -436,8 +452,11 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
             intoReturn.setOutAmt(inboundResponse.getIntoAmt());
             intoReturn.setOutingQty(inboundResponse.getIntoQty().abs());
             intoReturn.setOutingAmt(inboundResponse.getIntoAmt().abs());
-            //入库状态
-            String outStatus = this.setOutStatus(intoReturn.getOutingQty(), intoReturn.getOutQty());
+            //根据id查询
+            IntoReturnResponse intoReturnResponse = intoReturnMapper.selectById(inboundVO.getFromId());
+            //出库状态
+            String outStatus = this.setOutStatus(intoReturnResponse.getOutingQty().add(intoReturn.getOutingQty()),
+                    intoReturnResponse.getOutQty().add(intoReturn.getOutQty()));
             intoReturn.setOutStatus(outStatus);
             //修改
             int countRow = intoReturnMapper.updateById(intoReturn);
@@ -475,8 +494,11 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
                 intoReturnItem.setOutAmt(inboundItemResponse.getIntoAmt());
                 intoReturnItem.setOutingQty(inboundItemResponse.getIntoQty().abs());
                 intoReturnItem.setOutingAmt(inboundItemResponse.getIntoAmt().abs());
-                //入库状态
-                String outStatus = this.setOutStatus(intoReturnItem.getOutingQty(), intoReturnItem.getOutQty());
+                //根据id查询
+                IntoReturnItemResponse intoReturnItemResponse = intoReturnItemMapper.selectById(inboundItemResponse.getFromItemId());
+                //出库状态
+                String outStatus = this.setOutStatus(intoReturnItemResponse.getOutingQty().add(intoReturnItem.getOutingQty()),
+                        intoReturnItemResponse.getOutQty().add(intoReturnItem.getOutQty()));
                 intoReturnItem.setOutStatus(outStatus);
                 //修改
                 int countRow = intoReturnItemMapper.updateById(intoReturnItem);
@@ -489,13 +511,17 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
 
             //region修改入库明细信息
             InboundItem inboundItem = new InboundItem();
-            inboundItem.setIntoId(inbound.getIntoId())
+            inboundItem
+                    .setIntoId(inbound.getIntoId())
                     .setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName())
                     .setIntoingQty(inboundItemResponse.getIntoingQty().add(inboundItemResponse.getIntoQty()))
                     .setIntoingAmt(inboundItemResponse.getIntoingAmt().add(inboundItemResponse.getIntoAmt()))
                     .setIntoQty(BigDecimal.ZERO)
                     .setIntoAmt(BigDecimal.ZERO)
-                    .setItemId(inboundItemResponse.getItemId());
+                    .setItemId(inboundItemResponse.getItemId())
+                    .setCostPrice(BigDecimal.ZERO)
+                    .setCostAmt(BigDecimal.ZERO)
+            ;
             //修改
             inboundItemMapper.update(inboundItem,
                     new UpdateWrapper<InboundItem>().lambda()

+ 39 - 15
src/main/java/com/dk/mdm/service/ivt/InboundPurchaseService.java

@@ -25,6 +25,8 @@ import com.dk.mdm.model.query.ivt.InboundItemQuery;
 import com.dk.mdm.model.query.ivt.InboundQuery;
 import com.dk.mdm.model.response.ivt.InboundItemResponse;
 import com.dk.mdm.model.response.ivt.InboundResponse;
+import com.dk.mdm.model.response.pur.PurchaseItemResponse;
+import com.dk.mdm.model.response.pur.PurchaseResponse;
 import com.dk.mdm.model.vo.ivt.InboundItemVO;
 import com.dk.mdm.model.vo.ivt.InboundVO;
 import com.dk.mdm.service.common.CommonService;
@@ -152,8 +154,11 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 			purchaseUpdate.setIntoingAmt(inboundVO.getIntoingAmt().negate());
 			purchaseUpdate.setIntoAmt(inboundVO.getIntoAmt());
 			purchaseUpdate.setIntoQty(inboundVO.getIntoQty());
+			//根据id查询
+			PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
 			//入库状态
-			String intoStatus = this.setIntoStatus(purchaseUpdate.getIntoingQty(), purchaseUpdate.getIntoQty());
+			String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchaseUpdate.getIntoingQty()),
+					purchaseResponse.getIntoQty().add(purchaseUpdate.getIntoQty()));
 			purchaseUpdate.setIntoStatus(intoStatus);
 			//修改
 			int countRow = purchaseMapper.updateById(purchaseUpdate);
@@ -183,18 +188,14 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 						.setIntoAmt(inboundItemVO.getIntoingAmt())
 						.setIntoingQty(BigDecimal.ZERO)
 						.setIntoingAmt(BigDecimal.ZERO)
+						.setCostPrice(inboundItemVO.getPriceInto())
+						.setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
 				;
 			}else{
 				inboundItemVO
 						.setIntoQty(BigDecimal.ZERO)
 						.setIntoAmt(BigDecimal.ZERO);
 			}
-			//成本单价
-			inboundItemVO.setCostPrice(inboundItemVO.getPriceInto());
-			//成本金额
-			inboundItemVO.setCostAmt((inboundItemVO.getIntoingQty().add(inboundItemVO.getIntoQty())).multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP));
-			//库存数量  已入库-出库
-			inboundItemVO.setInvQty(inboundItemVO.getIntoQty().subtract(inboundItemVO.getOutQty()));
 			//入库状态
 			inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
 			//实体转换
@@ -211,8 +212,11 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 				purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt());
 				purchaseItem.setIntoQty(inboundItemVO.getIntoQty());
 				purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt());
+				//根据id查询
+				PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
 				//入库状态
-				String intoStatus = this.setIntoStatus(purchaseItem.getIntoingQty(), purchaseItem.getIntoQty());
+				String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
+						purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()));
 				purchaseItem.setIntoStatus(intoStatus);
 				int countRow = purchaseItemMapper.updateById(purchaseItem);
 				//数量超出
@@ -259,6 +263,8 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 						.setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoAmt()))
 						.setIntoingQty(inboundItemResponse.getIntoingQty().subtract(inboundItemVO.getIntoingQty()))
 						.setIntoingAmt(inboundItemResponse.getIntoingAmt().subtract(inboundItemVO.getIntoingAmt()))
+						.setCostPrice(inboundItemVO.getPriceInto())
+						.setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
 				;
 				//入库状态
 				String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
@@ -279,7 +285,7 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 						.setIntoAmt(inboundItemVO.getIntoingAmt())
 						.setIntoId(inboundVO.getIntoId())
 						.setCostPrice(inboundItemVO.getPriceInto())
-						.setCostAmt((inboundItemVO.getIntoingQty().add(inboundItemVO.getIntoQty())).multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
+						.setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
 						.setIntoType(Constant.IntoType.SALE.getName());
 				//入库状态
 				String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
@@ -299,8 +305,11 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 				purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt());
 				purchaseItem.setIntoQty(inboundItemVO.getIntoQty());
 				purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt());
+				//根据id查询
+				PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
 				//入库状态
-				String intoStatus = this.setIntoStatus(purchaseItem.getIntoingQty(), purchaseItem.getIntoQty());
+				String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
+						purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()));
 				purchaseItem.setIntoStatus(intoStatus);
 				int countRow = purchaseItemMapper.updateById(purchaseItem);
 				//数量超出
@@ -342,8 +351,11 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 					purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt().negate());
 					purchaseItem.setIntoQty(inboundItemVO.getIntoQty().negate());
 					purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt().negate());
+					//根据id查询
+					PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
 					//入库状态
-					String intoStatus = this.setIntoStatus(purchaseItem.getIntoingQty(), purchaseItem.getIntoQty());
+					String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
+							purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()));
 					purchaseItem.setIntoStatus(intoStatus);
 					int countRow = purchaseItemMapper.updateById(purchaseItem);
 					//数量超出
@@ -389,8 +401,11 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 			purchase.setIntoAmt(sumIntoAmt.subtract(sumDelIntoAmt));
 			purchase.setIntoingQty((sumIntoingQty.add(sumDelIntoingQty)).negate());
 			purchase.setIntoingAmt((sumIntoingAmt.add(sumDelIntoingAmt)).negate());
+			//根据id查询
+			PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
 			//入库状态
-			String purIntoStatus = this.setIntoStatus(purchase.getIntoingQty(), purchase.getIntoQty());
+			String purIntoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()),
+					purchaseResponse.getIntoQty().add(purchase.getIntoQty()));
 			purchase.setIntoStatus(purIntoStatus);
 			//修改
 			int countRow = purchaseMapper.updateById(purchase);
@@ -429,8 +444,11 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 			purchase.setIntoAmt(inboundResponse.getIntoAmt().negate());
 			purchase.setIntoingQty(inboundResponse.getIntoQty());
 			purchase.setIntoingAmt(inboundResponse.getIntoAmt());
+			//根据id查询
+			PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
 			//入库状态
-			String intoStatus = this.setIntoStatus(purchase.getIntoingQty(), purchase.getIntoQty());
+			String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()),
+					purchaseResponse.getIntoQty().add(purchase.getIntoQty()));
 			purchase.setIntoStatus(intoStatus);
 			int countRow =  purchaseMapper.updateById(purchase);
 			//数量超出
@@ -469,8 +487,11 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 				purchaseItem.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
 				purchaseItem.setIntoingQty(inboundItemResponse.getIntoQty());
 				purchaseItem.setIntoingAmt(inboundItemResponse.getIntoAmt());
+				//根据id查询
+				PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemResponse.getFromItemId());
 				//入库状态
-				String intoStatus= this.setIntoStatus(purchaseItem.getIntoingQty(), purchaseItem.getIntoQty());
+				String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
+						purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()));
 				purchaseItem.setIntoStatus(intoStatus);
 				//修改
 				int countRow = purchaseItemMapper.updateById(purchaseItem);
@@ -483,12 +504,15 @@ public class InboundPurchaseService extends BaseService<Inbound> {
 
 			//region修改入库明细信息
 			InboundItem inboundItem = new InboundItem();
-			inboundItem.setIntoId(inbound.getIntoId())
+			inboundItem
+					.setIntoId(inbound.getIntoId())
 					.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName())
 					.setIntoingQty(inboundItemResponse.getIntoingQty().add(inboundItemResponse.getIntoQty()))
 					.setIntoingAmt(inboundItemResponse.getIntoingAmt().add(inboundItemResponse.getIntoAmt()))
 					.setIntoQty(BigDecimal.ZERO)
 					.setIntoAmt(BigDecimal.ZERO)
+					.setCostPrice(BigDecimal.ZERO)
+					.setCostAmt(BigDecimal.ZERO)
 					.setItemId(inboundItemResponse.getItemId());
 			//修改
 			inboundItemMapper.update(inboundItem,

+ 433 - 0
src/main/java/com/dk/mdm/service/ivt/OutboundOtherService.java

@@ -0,0 +1,433 @@
+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;
+import com.dk.common.mapper.BaseMapper;
+import com.dk.common.model.pojo.PageList;
+import com.dk.common.response.ResponseResultUtil;
+import com.dk.common.response.ResponseResultVO;
+import com.dk.common.service.BaseService;
+import com.dk.mdm.infrastructure.convert.ivt.OutboundConvert;
+import com.dk.mdm.infrastructure.convert.ivt.OutboundItemConvert;
+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.query.ivt.OutboundItemQuery;
+import com.dk.mdm.model.query.ivt.OutboundQuery;
+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.OutboundItemVO;
+import com.dk.mdm.model.vo.ivt.OutboundVO;
+import com.dk.mdm.service.common.CommonService;
+import org.springframework.beans.factory.annotation.Autowired;
+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;
+
+
+/**
+ * @desc   : 其他出库业务层
+ * @date   : 2024/3/18 15:33
+ * @author : 寇珊珊
+ */
+@Service
+public class OutboundOtherService extends BaseService<Outbound> {
+
+    @Override
+    public BaseMapper<Outbound> getRepository() {
+        return outboundMapper;
+    }
+
+    @Autowired
+    private CommonService commonService;
+
+    @Autowired
+    private OutboundMapper outboundMapper;
+
+    @Autowired
+    private OutboundConvert outboundConvert;
+
+    @Autowired
+    private OutboundItemMapper outboundItemMapper;
+
+    @Autowired
+    private OutboundItemConvert outboundItemConvert;
+
+
+
+    /**
+     * @desc : 条件查询
+     * @date : 2024/3/18 11:20
+     * @author : 寇珊珊
+     */
+    @Pagination
+    public ResponseResultVO<PageList<InboundResponse>> selectByCond(OutboundQuery outboundQuery) {
+        return super.mergeListWithCount(outboundQuery, outboundMapper.selectByCond(outboundQuery),
+                outboundMapper.countByCond(outboundQuery));
+    }
+
+    /**
+     * @desc : 查询明细
+     * @date : 2024/3/15 16:43
+     * @author : 寇珊珊
+     */
+    @Pagination
+    public ResponseResultVO<Map<String, Object>> selectOutboundOtherItemInfoById(String id) {
+        Map<String, Object> result = new HashMap<>();
+        // 商品明细
+        List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(id));
+        result.put("itemList", outboundItemResponseList);
+        // 收款
+
+        // 附件
+        return ResponseResultUtil.success(result);
+    }
+
+
+    /**
+     * @desc : 其他出库新建
+     * @date : 2024/3/7 14:13
+     * @author : 寇珊珊
+     */
+    @Transactional(rollbackFor = {Exception.class})
+    public ResponseResultVO<?> otherOutboundInsert(OutboundVO outboundVO) {
+        //region  总单
+        //获取 id/单号
+        Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHEROUTBOUND.getName(), false);
+        outboundVO.setOutId(codeMap.get("outId").toString()).
+                setOutNo(codeMap.get("outNote").toString());
+        //出库类型
+        outboundVO.setOutType(Constant.OutType.OTHER.getName());
+        //自动入库标识
+        if (outboundVO.getAutomaticFlg()) {
+            //已出库
+            outboundVO.setOutStatus(Constant.OutStatus.YICHUKU.getName());
+        } else {
+            //出库中
+            outboundVO.setOutStatus(Constant.OutStatus.CHUKUZHONG.getName());
+        }
+        //出库状态等于已出库 更新合计出库数量/金额 = 出库中数量/出库中金额
+        if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
+            outboundVO
+                    .setOutQty(outboundVO.getOutingQty())
+                    .setOutAmt(outboundVO.getOutingAmt())
+                    .setOutingQty(BigDecimal.ZERO)
+                    .setOutingAmt(BigDecimal.ZERO)
+            ;
+        } else {
+            outboundVO
+                    .setOutQty(BigDecimal.ZERO)
+                    .setOutAmt(BigDecimal.ZERO)
+            ;
+        }
+
+        //实体转换
+        Outbound outbound = outboundConvert.convertToPo(outboundVO);
+        outboundMapper.insert(outbound);
+        //endregion
+
+
+        //region 明细
+        //校验明细
+        if (outboundVO.getItemList().size() == 0) {
+            return ResponseResultUtil.error(ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getCode(),
+                    ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getMessage());
+        }
+        for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
+            //总单id
+            outboundItemVO.setOutId(outboundVO.getOutId());
+            //出库类型
+            outboundItemVO.setOutType(outboundVO.getOutType());
+            //出库状态等于已出库  更新合计出库数量/金额 = 出库中数量/出库中金额
+            if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
+                outboundItemVO
+                        .setOutQty(outboundItemVO.getOutingQty())
+                        .setOutAmt(outboundItemVO.getOutingAmt())
+                        .setOutingQty(BigDecimal.ZERO)
+                        .setOutingAmt(BigDecimal.ZERO)
+                        .setCostPrice(outboundItemVO.getPriceOut())
+                        .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
+                ;
+            } else {
+                outboundItemVO
+                        .setOutQty(BigDecimal.ZERO)
+                        .setOutAmt(BigDecimal.ZERO);
+            }
+            //入库状态
+            outboundItemVO.setOutStatus(outboundItemVO.getOutStatus());
+            //实体转换
+            OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
+            outboundItemMapper.insert(outboundItem);
+            //endregion
+
+
+        }
+        //endregion
+
+        //todo 如果是已出库 调用库存  后续写库存这里补上
+        //region 库存
+
+
+        //endregion
+
+
+        return ResponseResultUtil.success(outboundVO);
+    }
+
+
+    /**
+     * @desc : 其他出库办理
+     * @date : 2024/3/7 15:47
+     * @author : 寇珊珊
+     */
+    @Transactional(rollbackFor = {Exception.class})
+    public ResponseResultVO<?> otherHandleOutbound(OutboundVO outboundVO) {
+        //region 编辑明细
+        //校验明细
+        if (outboundVO.getItemList().size() == 0) {
+            return ResponseResultUtil.error(ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getCode(),
+                    ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getMessage());
+        }
+        for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
+            if (outboundItemVO.getItemId() != null) {
+                //查询原单
+                OutboundItemResponse outboundItemResponse = outboundItemMapper.selectById(outboundItemVO.getItemId());
+                //编辑明细
+                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
+            //region 新建明细
+            else {
+                outboundItemVO
+                        .setOutId(outboundItemVO.getOutId())
+                        .setOutQty(outboundItemVO.getOutingQty())
+                        .setOutAmt(outboundItemVO.getOutingAmt())
+                        .setCostPrice(outboundItemVO.getPriceOut())
+                        .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
+                        .setOutType(Constant.OutType.OTHER.getName());
+                //入库状态
+                String outStatus = this.setOutStatus(outboundItemVO.getOutingQty(), outboundItemVO.getOutQty());
+                outboundItemVO.setOutStatus(outStatus);
+                //实体转换
+                OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
+                //新建
+                outboundItemMapper.insert(outboundItem);
+            }
+            //endregion
+
+        }
+        //endregion
+
+        //region 删除明细
+        if (outboundVO.getDeleteItemList() != null) {
+         for (OutboundItemVO outboundItemVO : outboundVO.getDeleteItemList()) {
+                if (outboundItemVO.getItemId() != null) {
+                    OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
+                    outboundItem.setFlgValid(false);
+                    //修改
+                    outboundItemMapper.update(outboundItem,
+                            new UpdateWrapper<OutboundItem>().lambda()
+                                    .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
+                    );
+                }
+            }
+        }
+        //endregion
+
+        //region 编辑总单
+        OutboundResponse outboundResponse = outboundMapper.selectById(outboundVO.getOutId());
+        BigDecimal sumOutQty = outboundVO.getItemList().stream().map(OutboundItemVO::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+        BigDecimal sumOutAmt = outboundVO.getItemList().stream().map(OutboundItemVO::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+        BigDecimal sumOutingQty = outboundVO.getItemList().stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+        BigDecimal sumOutingAmt = outboundVO.getItemList().stream().map(OutboundItemVO::getOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+        outboundVO.setOutQty(sumOutQty);
+        outboundVO.setOutAmt(sumOutAmt);
+        outboundVO.setOutingQty(outboundResponse.getOutingQty().subtract(sumOutingQty));
+        outboundVO.setOutingAmt(outboundResponse.getOutingAmt().subtract(sumOutingAmt));
+        //出库状态
+        String outStatus = this.setOutStatus(outboundVO.getOutingQty(), outboundVO.getOutQty());
+        outboundVO.setOutStatus(outStatus);
+        //实体转换
+        Outbound outbound = outboundConvert.convertToPo(outboundVO);
+        //修改
+        outboundMapper.update(outbound,
+                new UpdateWrapper<Outbound>().lambda()
+                        .eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
+        );
+        //endregion
+
+
+        //todo 如果是已出库 调用库存  后续写库存这里补上
+        //region 修改库存
+
+        //endregion
+        return ResponseResultUtil.success(outboundVO);
+    }
+
+
+    /**
+     * @desc : 其他出库撤销
+     * @date : 2024/3/7 17:06
+     * @author : 寇珊珊
+     */
+    @Transactional(rollbackFor = {Exception.class})
+    public ResponseResultVO<?> otherOutboundCancel(OutboundVO outboundVO) {
+        //region 查询出库总单数据信息
+        OutboundResponse outboundResponse = outboundMapper.selectById(outboundVO.getOutId());
+        //endregion
+
+        //region 修改总单数据信息
+        Outbound outbound = new Outbound();
+        outbound.setOutId(outboundVO.getOutId());
+        outbound.setOutDate(null);
+        outbound.setOutStatus(Constant.OutStatus.CHUKUZHONG.getName());
+        outbound.setOutingQty(outboundResponse.getOutingQty().add(outboundResponse.getOutQty()));
+        outbound.setOutingAmt(outboundResponse.getOutingAmt().add(outboundResponse.getOutAmt()));
+        outbound.setOutQty(BigDecimal.ZERO);
+        outbound.setOutAmt(BigDecimal.ZERO);
+        //修改
+        outboundMapper.update(outbound,
+                new UpdateWrapper<Outbound>().lambda()
+                        .eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
+        );
+        //endregion
+
+        //region 明细数据
+        //根据总单id查明细
+        List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(outboundVO.getOutId()));
+        for (OutboundItemResponse outboundItemResponse : outboundItemResponseList) {
+            //region修改出库明细信息
+            OutboundItem outboundItem = new OutboundItem();
+            outboundItem
+                    .setOutId(outboundResponse.getOutId())
+                    .setOutStatus(Constant.OutStatus.CHUKUZHONG.getName())
+                    .setOutingQty(outboundItemResponse.getOutingQty().add(outboundItemResponse.getOutQty()))
+                    .setOutAmt(outboundItemResponse.getOutingAmt().add(outboundItemResponse.getOutAmt()))
+                    .setOutQty(BigDecimal.ZERO)
+                    .setOutAmt(BigDecimal.ZERO)
+                    .setItemId(outboundItemResponse.getItemId())
+                    .setCostPrice(BigDecimal.ZERO)
+                    .setCostAmt(BigDecimal.ZERO)
+            ;
+            //修改
+            outboundItemMapper.update(outboundItem,
+                    new UpdateWrapper<OutboundItem>().lambda()
+                            .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
+            );
+            //endregion
+        }
+        //endregion
+
+
+        //todo 调用库存  后续写库存这里补上
+        //region 修改库存
+
+        //endregion
+
+        return ResponseResultUtil.success();
+    }
+
+
+    /**
+     * @desc : 入库状态通用(目前本页面)
+     * @date : 2024/3/9 8:59
+     * @author : 寇珊珊
+     */
+    public String setIntoStatus(BigDecimal intoingQty, BigDecimal intoQty) {
+        //入库状态
+        String intoStatus = null;
+        //已出库数量>0 出库中数量>0
+        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.DAIRUKU.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/9 8:59
+     * @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
+        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) {
+            //已出库
+            outStatus = Constant.OutStatus.YICHUKU.getName();
+        }
+        return outStatus;
+    }
+
+
+    /**
+     * @desc : 获取单据信息(编辑用)
+     * @date : 2024/3/16 16:28
+     * @author : 寇珊珊
+     */
+    public ResponseResultVO<?> selectByUpdate(String id) {
+        Map<String, Object> dataInfo = new HashMap<>();
+        //总单
+        OutboundResponse outboundResponse = outboundMapper.selectMessageByOtherQuery(new OutboundQuery().setOutId(id).setOutStatus(Constant.OutStatus.CHUKUZHONG.getName()));
+        //单据不存在
+        if (outboundResponse == null) {
+            return ResponseResultUtil.error(ErrorCodeEnum.THERE_ORDER_IS_NOT_CAN_OUTBOUND_QUANTITY.getCode(),
+                    ErrorCodeEnum.THERE_ORDER_IS_NOT_CAN_OUTBOUND_QUANTITY.getMessage());
+        }
+        dataInfo.put("data", outboundResponse);
+        // 明细
+        List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(outboundResponse.getOutId()));
+        dataInfo.put("dataItem", outboundItemResponseList);
+        return ResponseResultUtil.success(dataInfo);
+    }
+
+
+}

+ 612 - 0
src/main/java/com/dk/mdm/service/ivt/OutboundSaleOrderService.java

@@ -0,0 +1,612 @@
+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;
+import com.dk.common.infrastructure.enums.ErrorCodeEnum;
+import com.dk.common.mapper.BaseMapper;
+import com.dk.common.model.pojo.PageList;
+import com.dk.common.response.ResponseCodeEnum;
+import com.dk.common.response.ResponseResultUtil;
+import com.dk.common.response.ResponseResultVO;
+import com.dk.common.service.BaseService;
+import com.dk.mdm.infrastructure.convert.ivt.OutboundConvert;
+import com.dk.mdm.infrastructure.convert.ivt.OutboundItemConvert;
+import com.dk.mdm.mapper.ivt.OutboundItemMapper;
+import com.dk.mdm.mapper.ivt.OutboundMapper;
+import com.dk.mdm.mapper.sale.OrderItemMapper;
+import com.dk.mdm.mapper.sale.OrderMapper;
+import com.dk.mdm.model.pojo.ivt.Outbound;
+import com.dk.mdm.model.pojo.ivt.OutboundItem;
+import com.dk.mdm.model.pojo.sale.Order;
+import com.dk.mdm.model.pojo.sale.OrderItem;
+import com.dk.mdm.model.query.ivt.OutboundItemQuery;
+import com.dk.mdm.model.query.ivt.OutboundQuery;
+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.response.sale.OrderItemResponse;
+import com.dk.mdm.model.response.sale.OrderResponse;
+import com.dk.mdm.model.vo.ivt.OutboundItemVO;
+import com.dk.mdm.model.vo.ivt.OutboundVO;
+import com.dk.mdm.service.common.CommonService;
+import org.springframework.beans.factory.annotation.Autowired;
+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;
+
+
+/**
+ * @desc   : 销售出库业务层
+ * @date   : 2024/3/18 15:33
+ * @author : 寇珊珊
+ */
+@Service
+public class OutboundSaleOrderService extends BaseService<Outbound> {
+
+    @Override
+    public BaseMapper<Outbound> getRepository() {
+        return outboundMapper;
+    }
+
+    @Autowired
+    private CommonService commonService;
+
+    @Autowired
+    private OutboundMapper outboundMapper;
+
+    @Autowired
+    private OutboundConvert outboundConvert;
+
+    @Autowired
+    private OutboundItemMapper outboundItemMapper;
+
+    @Autowired
+    private OutboundItemConvert outboundItemConvert;
+
+    @Autowired
+    private OrderMapper orderMapper;
+
+    @Autowired
+    private OrderItemMapper  orderItemMapper;
+
+
+    /**
+     * @desc : 条件查询
+     * @date : 2024/3/18 11:20
+     * @author : 寇珊珊
+     */
+    @Pagination
+    public ResponseResultVO<PageList<InboundResponse>> selectByCond(OutboundQuery outboundQuery) {
+        return super.mergeListWithCount(outboundQuery, outboundMapper.selectByCond(outboundQuery),
+                outboundMapper.countByCond(outboundQuery));
+    }
+
+    /**
+     * @desc : 查询明细
+     * @date : 2024/3/15 16:43
+     * @author : 寇珊珊
+     */
+    @Pagination
+    public ResponseResultVO<Map<String, Object>> selectOutBoundSaleOrderItemInfoById(String id) {
+        Map<String, Object> result = new HashMap<>();
+        // 商品明细
+        List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(id));
+        result.put("itemList", outboundItemResponseList);
+        // 收款
+
+        // 附件
+        return ResponseResultUtil.success(result);
+    }
+
+
+    /**
+     * @desc : 销售出库新建
+     * @date : 2024/3/7 14:13
+     * @author : 寇珊珊
+     */
+    @Transactional(rollbackFor = {Exception.class})
+    public ResponseResultVO<?> saleOrderOutboundInsert(OutboundVO outboundVO) {
+        //region  总单
+        //获取 id/单号
+        Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.SALEORDER.getName(), false);
+        outboundVO.setOutId(codeMap.get("outId").toString()).
+                setOutNo(codeMap.get("outNote").toString());
+        //出库类型
+        outboundVO.setOutType(Constant.OutType.SALE.getName());
+        //自动入库标识
+        if (outboundVO.getAutomaticFlg()) {
+            //已出库
+            outboundVO.setOutStatus(Constant.OutStatus.YICHUKU.getName());
+        } else {
+            //出库中
+            outboundVO.setOutStatus(Constant.OutStatus.CHUKUZHONG.getName());
+        }
+        //出库状态等于已出库 更新合计出库数量/金额 = 出库中数量/出库中金额
+        if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
+            outboundVO
+                    .setOutQty(outboundVO.getOutingQty())
+                    .setOutAmt(outboundVO.getOutingAmt())
+                    .setOutingQty(BigDecimal.ZERO)
+                    .setOutingAmt(BigDecimal.ZERO)
+            ;
+        } else {
+            outboundVO
+                    .setOutQty(BigDecimal.ZERO)
+                    .setOutAmt(BigDecimal.ZERO)
+            ;
+        }
+
+        //实体转换
+        Outbound outbound = outboundConvert.convertToPo(outboundVO);
+        outboundMapper.insert(outbound);
+        //endregion
+
+        //region 销售退货
+        if (outboundVO.getFromId() != null) {
+            //赋值  (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
+            Order order = new Order();
+            order.setOrderId(outboundVO.getFromId());
+            order.setOutingQty(outboundVO.getOutingQty());
+            order.setOutingAmt(outboundVO.getOutingAmt());
+            order.setOutQty(outboundVO.getOutQty());
+            order.setOutAmt(outboundVO.getOutAmt());
+            //根据id查询
+            OrderResponse orderResponse = orderMapper.selectById(outboundVO.getFromId());
+            //入库状态
+            String outStatus = this.setOutStatus(orderResponse.getOutingQty().add(order.getOutingQty()), orderResponse.getOutQty().add(order.getOutQty()));
+            order.setOutStatus(outStatus);
+            //修改
+            int countRow = orderMapper.updateById(order);
+            //数量超出
+            if (countRow == 0) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
+            }
+        }
+        //endregion
+
+
+        //region 明细
+        //校验明细
+        if (outboundVO.getItemList().size() == 0) {
+            return ResponseResultUtil.error(ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getCode(),
+                    ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getMessage());
+        }
+        for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
+            //总单id
+            outboundItemVO.setOutId(outboundVO.getOutId());
+            //出库类型
+            outboundItemVO.setOutType(outboundVO.getOutType());
+            //出库状态等于已出库  更新合计出库数量/金额 = 出库中数量/出库中金额
+            if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
+                outboundItemVO
+                        .setOutQty(outboundItemVO.getOutingQty())
+                        .setOutAmt(outboundItemVO.getOutingAmt())
+                        .setOutingQty(BigDecimal.ZERO)
+                        .setOutingAmt(BigDecimal.ZERO)
+                        .setCostPrice(outboundItemVO.getPriceOut())
+                        .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
+                ;
+            } else {
+                outboundItemVO
+                        .setOutQty(BigDecimal.ZERO)
+                        .setOutAmt(BigDecimal.ZERO);
+            }
+            //入库状态
+            outboundItemVO.setOutStatus(outboundItemVO.getOutStatus());
+            //实体转换
+            OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
+            outboundItemMapper.insert(outboundItem);
+            //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(orderItemResponse.getOutingQty().add(orderItem.getOutingQty()), orderItemResponse.getOutQty().add(orderItem.getOutQty()));
+                orderItem.setOutStatus(outStatus);
+                //修改
+                int countRow = orderItemMapper.updateById(orderItem);
+                //数量超出
+                if (countRow == 0) {
+                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
+                }
+            }
+            //endregion
+
+        }
+        //endregion
+
+        //todo 如果是已出库 调用库存  后续写库存这里补上
+        //region 库存
+
+
+        //endregion
+
+
+        return ResponseResultUtil.success(outboundVO);
+    }
+
+
+    /**
+     * @desc : 销售出库办理
+     * @date : 2024/3/7 15:47
+     * @author : 寇珊珊
+     */
+    @Transactional(rollbackFor = {Exception.class})
+    public ResponseResultVO<?> saleOrderHandleOutbound(OutboundVO outboundVO) {
+        //region 编辑明细
+        //校验明细
+        if (outboundVO.getItemList().size() == 0) {
+            return ResponseResultUtil.error(ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getCode(),
+                    ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getMessage());
+        }
+        for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
+            if (outboundItemVO.getItemId() != null) {
+                //查询原单
+                OutboundItemResponse outboundItemResponse = outboundItemMapper.selectById(outboundItemVO.getItemId());
+                //编辑明细
+                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
+            //region 新建明细
+            else {
+                outboundItemVO
+                        .setOutId(outboundItemVO.getOutId())
+                        .setOutQty(outboundItemVO.getOutQty())
+                        .setOutAmt(outboundItemVO.getOutAmt())
+                        .setCostPrice(outboundItemVO.getPriceOut())
+                        .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
+                        .setOutType(Constant.OutType.SALE.getName());
+                //入库状态
+                String outStatus = this.setOutStatus(outboundItemVO.getOutingQty(), outboundItemVO.getOutQty());
+                outboundItemVO.setOutStatus(outStatus);
+                //实体转换
+                OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
+                //新建
+                outboundItemMapper.insert(outboundItem);
+            }
+            //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(orderItemResponse.getOutingQty().add(orderItem.getOutingQty()), orderItemResponse.getOutQty().add(orderItem.getOutQty()));
+                orderItem.setOutStatus(outStatus);
+                //修改
+                int countRow = orderItemMapper.updateById(orderItem);
+                //数量超出
+                if (countRow == 0) {
+                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
+                }
+            }
+            //endregion
+        }
+        //endregion
+
+        //region 删除明细
+        BigDecimal sumDelOutQty = BigDecimal.ZERO;
+        BigDecimal sumDelOutAmt = BigDecimal.ZERO;
+        BigDecimal sumDelOutingQty = BigDecimal.ZERO;
+        BigDecimal sumDelOutingAmt = BigDecimal.ZERO;
+        if (outboundVO.getDeleteItemList() != null) {
+            sumDelOutQty = outboundVO.getDeleteItemList().stream().map(OutboundItemVO::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+            sumDelOutAmt = outboundVO.getDeleteItemList().stream().map(OutboundItemVO::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+            sumDelOutingQty = outboundVO.getDeleteItemList().stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+            sumDelOutingAmt = outboundVO.getDeleteItemList().stream().map(OutboundItemVO::getOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+            for (OutboundItemVO outboundItemVO : outboundVO.getDeleteItemList()) {
+                if (outboundItemVO.getItemId() != null) {
+                    OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
+                    outboundItem.setFlgValid(false);
+                    //修改
+                    outboundItemMapper.update(outboundItem,
+                            new UpdateWrapper<OutboundItem>().lambda()
+                                    .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
+                    );
+                }
+                //region  销售退货明细
+                if (outboundItemVO.getFromItemId() != null) {
+                    //region 销售退货订单明细
+                    //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
+                    OrderItem orderItem = new OrderItem();
+                    orderItem.setItemId(outboundItemVO.getFromItemId());
+                    orderItem.setOutingQty(outboundItemVO.getOutingQty().negate());
+                    orderItem.setOutingAmt(outboundItemVO.getOutingAmt().negate());
+                    orderItem.setOutQty(outboundItemVO.getOutQty().negate());
+                    orderItem.setOutAmt(outboundItemVO.getOutAmt().negate());
+                    //根据id查询
+                    OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemVO.getFromItemId());
+                    //出库状态
+                    String outStatus = this.setOutStatus(orderItemResponse.getOutingQty().add(orderItem.getOutingQty()), orderItemResponse.getOutQty().add(orderItem.getOutQty()));
+                    orderItem.setOutStatus(outStatus);
+                    //修改
+                    int countRow = orderItemMapper.updateById(orderItem);
+                    //数量超出
+                    if (countRow == 0) {
+                        throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
+                    }
+                    //endregion
+                }
+                //endregion
+
+            }
+        }
+        //endregion
+
+        //region 编辑总单
+        OutboundResponse outboundResponse = outboundMapper.selectById(outboundVO.getOutId());
+        BigDecimal sumOutQty = outboundVO.getItemList().stream().map(OutboundItemVO::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+        BigDecimal sumOutAmt = outboundVO.getItemList().stream().map(OutboundItemVO::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+        BigDecimal sumOutingQty = outboundVO.getItemList().stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+        BigDecimal sumOutingAmt = outboundVO.getItemList().stream().map(OutboundItemVO::getOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+        outboundVO.setOutQty(sumOutQty);
+        outboundVO.setOutAmt(sumOutAmt);
+        outboundVO.setOutingQty(outboundResponse.getOutingQty().subtract(sumOutingQty));
+        outboundVO.setOutingAmt(outboundResponse.getOutingAmt().subtract(sumOutingAmt));
+        //出库状态
+        String outStatus = this.setOutStatus(outboundVO.getOutingQty(), outboundVO.getOutQty());
+        outboundVO.setOutStatus(outStatus);
+        //实体转换
+        Outbound outbound = outboundConvert.convertToPo(outboundVO);
+        //修改
+        outboundMapper.update(outbound,
+                new UpdateWrapper<Outbound>().lambda()
+                        .eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
+        );
+        //endregion
+
+        //region  修改销售退货订单
+        if (outboundVO.getFromId() != null) {
+            //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
+            Order order = new Order();
+            order.setOrderId(outboundVO.getFromId());
+            order.setOutingQty(sumOutQty.subtract(sumDelOutQty));
+            order.setOutingAmt(sumOutAmt.subtract(sumDelOutAmt));
+            order.setOutQty((sumOutingQty.add(sumDelOutingQty)).negate());
+            order.setOutAmt((sumOutingAmt.add(sumDelOutingAmt)).negate());
+            //根据id查询
+            OrderResponse orderResponse = orderMapper.selectById(outboundVO.getFromId());
+            //出库状态
+            String orderOutStatus = this.setOutStatus(orderResponse.getOutingQty().add(order.getOutingQty()), orderResponse.getOutQty().add(order.getOutQty()));
+            order.setOutStatus(orderOutStatus);
+            //修改
+            int countRow = orderMapper.updateById(order);
+            //数量超出
+            if (countRow == 0) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
+            }
+        }
+        //endregion
+
+        //todo 如果是已出库 调用库存  后续写库存这里补上
+        //region 修改库存
+
+        //endregion
+        return ResponseResultUtil.success(outboundVO);
+    }
+
+
+    /**
+     * @desc : 销售出库撤销
+     * @date : 2024/3/7 17:06
+     * @author : 寇珊珊
+     */
+    @Transactional(rollbackFor = {Exception.class})
+    public ResponseResultVO<?> saleOrderOutboundCancel(OutboundVO outboundVO) {
+        //region 查询出库总单数据信息
+        OutboundResponse outboundResponse = outboundMapper.selectById(outboundVO.getOutId());
+        //endregion
+
+        //region 修改订单数据信息
+        if (outboundResponse.getFromId() != null) {
+            //赋值  (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
+            Order order = new Order();
+            order.setOrderId(outboundVO.getFromId());
+            order.setOutingQty(outboundVO.getOutingQty());
+            order.setOutingAmt(outboundVO.getOutingAmt());
+            order.setOutQty(outboundVO.getOutQty().negate());
+            order.setOutAmt(outboundVO.getOutAmt().negate());
+            //根据id查询
+            OrderResponse orderResponse = orderMapper.selectById(outboundVO.getFromId());
+            //出库状态
+            String outStatus = this.setOutStatus(orderResponse.getOutingQty().add(order.getOutingQty()), orderResponse.getOutQty().add(order.getOutQty()));
+            order.setOutStatus(outStatus);
+            //修改
+            int countRow = orderMapper.updateById(order);
+            //数量超出
+            if (countRow == 0) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
+            }
+
+        }
+        //endregion
+
+        //region 修改总单数据信息
+        Outbound outbound = new Outbound();
+        outbound.setOutId(outboundVO.getOutId());
+        outbound.setOutDate(null);
+        outbound.setOutStatus(Constant.OutStatus.CHUKUZHONG.getName());
+        outbound.setOutQty(BigDecimal.ZERO);
+        outbound.setOutAmt(BigDecimal.ZERO);
+        //修改
+        outboundMapper.update(outbound,
+                new UpdateWrapper<Outbound>().lambda()
+                        .eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
+        );
+        //endregion
+
+        //region 明细数据
+        //根据总单id查明细
+        List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(outboundVO.getOutId()));
+        for (OutboundItemResponse outboundItemResponse : outboundItemResponseList) {
+            //region 修改销售退货明细数据信息
+            if (outboundItemResponse.getFromItemId() != null) {
+                //赋值  (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
+                OrderItem orderItem = new OrderItem();
+                orderItem.setItemId(outboundItemResponse.getFromItemId());
+                orderItem.setOutQty(outboundItemResponse.getOutQty().negate());
+                orderItem.setOutAmt(outboundItemResponse.getOutAmt().negate());
+                orderItem.setOutingQty(outboundItemResponse.getOutingQty());
+                orderItem.setOutingAmt(outboundItemResponse.getOutingAmt());
+                //根据id查询
+                OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemResponse.getFromItemId());
+                //出库状态
+                String outStatus = this.setOutStatus(orderItemResponse.getOutingQty().add(orderItem.getOutingQty()), orderItemResponse.getOutQty().add(orderItem.getOutQty()));
+                orderItem.setOutStatus(outStatus);
+                //修改
+                int countRow = orderItemMapper.updateById(orderItem);
+                //数量超出
+                if (countRow == 0) {
+                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
+                }
+            }
+            //endregion
+
+            //region修改出库明细信息
+            OutboundItem outboundItem = new OutboundItem();
+            outboundItem
+                    .setOutId(outboundResponse.getOutId())
+                    .setOutStatus(Constant.OutStatus.CHUKUZHONG.getName())
+                    .setOutingQty(outboundItemResponse.getOutingQty().add(outboundItemResponse.getOutQty()))
+                    .setOutAmt(outboundItemResponse.getOutingAmt().add(outboundItemResponse.getOutAmt()))
+                    .setOutQty(BigDecimal.ZERO)
+                    .setOutAmt(BigDecimal.ZERO)
+                    .setCostPrice(BigDecimal.ZERO)
+                    .setCostAmt(BigDecimal.ZERO)
+                    .setItemId(outboundItemResponse.getItemId());
+            //修改
+            outboundItemMapper.update(outboundItem,
+                    new UpdateWrapper<OutboundItem>().lambda()
+                            .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
+            );
+            //endregion
+        }
+        //endregion
+
+
+        //todo 调用库存  后续写库存这里补上
+        //region 修改库存
+
+        //endregion
+
+        return ResponseResultUtil.success();
+    }
+
+
+    /**
+     * @desc : 入库状态通用(目前本页面)
+     * @date : 2024/3/9 8:59
+     * @author : 寇珊珊
+     */
+    public String setIntoStatus(BigDecimal intoingQty, BigDecimal intoQty) {
+        //入库状态
+        String intoStatus = null;
+        //已出库数量>0 出库中数量>0
+        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.DAIRUKU.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/9 8:59
+     * @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
+        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) {
+            //已出库
+            outStatus = Constant.OutStatus.YICHUKU.getName();
+        }
+        return outStatus;
+    }
+
+
+    /**
+     * @desc : 获取单据信息(编辑用)
+     * @date : 2024/3/16 16:28
+     * @author : 寇珊珊
+     */
+    public ResponseResultVO<?> selectByUpdate(String id) {
+        Map<String, Object> dataInfo = new HashMap<>();
+        //总单
+        OutboundResponse outboundResponse = outboundMapper.selectMessageByOtherQuery(new OutboundQuery().setOutId(id).setOutStatus(Constant.OutStatus.CHUKUZHONG.getName()));
+        //单据不存在
+        if (outboundResponse == null) {
+            return ResponseResultUtil.error(ErrorCodeEnum.THERE_ORDER_IS_NOT_CAN_OUTBOUND_QUANTITY.getCode(),
+                    ErrorCodeEnum.THERE_ORDER_IS_NOT_CAN_OUTBOUND_QUANTITY.getMessage());
+        }
+        dataInfo.put("data", outboundResponse);
+        // 明细
+        List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(outboundResponse.getOutId()));
+        dataInfo.put("dataItem", outboundItemResponseList);
+        return ResponseResultUtil.success(dataInfo);
+    }
+
+
+}

+ 45 - 23
src/main/java/com/dk/mdm/service/ivt/OutboundSaleReturnService.java

@@ -26,6 +26,8 @@ import com.dk.mdm.model.query.ivt.OutboundQuery;
 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.response.sale.OutReturnItemResponse;
+import com.dk.mdm.model.response.sale.OutReturnResponse;
 import com.dk.mdm.model.vo.ivt.OutboundItemVO;
 import com.dk.mdm.model.vo.ivt.OutboundVO;
 import com.dk.mdm.service.common.CommonService;
@@ -155,14 +157,17 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
             outReturn.setIntoingAmt(outboundVO.getOutingAmt().abs());
             outReturn.setIntoQty(outboundVO.getOutQty().abs());
             outReturn.setIntoAmt(outboundVO.getOutAmt().abs());
+            //根据id查询
+            OutReturnResponse outReturnResponse = outReturnMapper.selectById(outboundVO.getFromId());
             //入库状态
-            String intoStatus = this.setIntoStatus(outReturn.getIntoingQty(), outReturn.getIntoQty());
+            String intoStatus = this.setIntoStatus(outReturnResponse.getIntoQty().add(outReturn.getIntoingQty()),
+                    outReturnResponse.getIntoQty().add(outReturn.getIntoQty()));
             outReturn.setIntoStatus(intoStatus);
             //修改
             int countRow = outReturnMapper.updateById(outReturn);
             //数量超出
             if (countRow == 0) {
-                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
             }
         }
         //endregion
@@ -186,16 +191,14 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
                         .setOutAmt(outboundItemVO.getOutingAmt())
                         .setOutingQty(BigDecimal.ZERO)
                         .setOutingAmt(BigDecimal.ZERO)
+                        .setCostPrice(outboundItemVO.getPriceOut())
+                        .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
                 ;
             } else {
                 outboundItemVO
                         .setOutQty(BigDecimal.ZERO)
                         .setOutAmt(BigDecimal.ZERO);
             }
-            //成本单价
-            outboundItemVO.setCostPrice(outboundItemVO.getPriceOut());
-            //成本金额
-            outboundItemVO.setCostAmt((outboundItemVO.getOutingQty().add(outboundItemVO.getOutQty())).multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP));
             //入库状态
             outboundItemVO.setOutStatus(outboundItemVO.getOutStatus());
             //实体转换
@@ -212,14 +215,17 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
                 outReturnItem.setIntoAmt(outboundItemVO.getOutAmt().abs());
                 outReturnItem.setIntoingQty(outboundItemVO.getOutingQty().abs());
                 outReturnItem.setIntoingAmt(outboundItemVO.getOutingAmt().abs());
+                //根据id查询
+                OutReturnItemResponse outReturnItemResponse = outReturnItemMapper.selectById(outboundItemVO.getFromItemId());
                 //入库状态
-                String intoStatus = this.setIntoStatus(outReturnItem.getIntoingQty(), outReturnItem.getIntoQty());
+                String intoStatus = this.setIntoStatus(outReturnItemResponse.getIntoingQty().add(outReturnItem.getIntoingQty()),
+                        outReturnItemResponse.getIntoQty().add(outReturnItem.getIntoQty()));
                 outReturnItem.setIntoStatus(intoStatus);
                 //修改
                 int countRow = outReturnItemMapper.updateById(outReturnItem);
                 //数量超出
                 if (countRow == 0) {
-                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
                 }
             }
             //endregion
@@ -257,12 +263,12 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
                 OutboundItemResponse outboundItemResponse = outboundItemMapper.selectById(outboundItemVO.getItemId());
                 //编辑明细
                 outboundItemVO
-                        .setCostPrice(outboundItemVO.getPriceOut())
-                        .setCostAmt((outboundItemVO.getOutingQty().add(outboundItemVO.getOutQty())).multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
                         .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());
@@ -283,7 +289,7 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
                         .setOutQty(outboundItemVO.getOutQty().abs())
                         .setOutAmt(outboundItemVO.getOutAmt().abs())
                         .setCostPrice(outboundItemVO.getPriceOut())
-                        .setCostAmt((outboundItemVO.getOutingQty().add(outboundItemVO.getOutQty())).multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
+                        .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
                         .setOutType(Constant.OutType.SALE_RETURN.getName());
                 //入库状态
                 String outStatus = this.setOutStatus(outboundItemVO.getOutingQty(), outboundItemVO.getOutQty());
@@ -304,14 +310,17 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
                 outReturnItem.setIntoAmt(outboundItemVO.getOutAmt().abs());
                 outReturnItem.setIntoingQty(outboundItemVO.getOutingQty());
                 outReturnItem.setIntoingAmt(outboundItemVO.getOutingAmt());
+                //根据id查询
+                OutReturnItemResponse outReturnItemResponse = outReturnItemMapper.selectById(outboundItemVO.getFromItemId());
                 //入库状态
-                String intoStatus = this.setIntoStatus(outReturnItem.getIntoingQty(), outReturnItem.getIntoQty());
+                String intoStatus = this.setIntoStatus(outReturnItemResponse.getIntoingQty().add(outReturnItem.getIntoingQty()),
+                        outReturnItemResponse.getIntoQty().add(outReturnItem.getIntoQty()));
                 outReturnItem.setIntoStatus(intoStatus);
                 //修改
                 int countRow = outReturnItemMapper.updateById(outReturnItem);
                 //数量超出
                 if (countRow == 0) {
-                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
                 }
             }
             //endregion
@@ -348,14 +357,16 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
                     outReturnItem.setIntoAmt(outboundItemVO.getOutAmt());
                     outReturnItem.setIntoingQty(outboundItemVO.getOutingQty());
                     outReturnItem.setIntoingAmt(outboundItemVO.getOutingAmt());
-                    //入库状态
-                    String intoStatus = this.setIntoStatus(outReturnItem.getIntoingQty(), outReturnItem.getIntoQty());
+                    //根据id查询
+                    OutReturnItemResponse outReturnItemResponse = outReturnItemMapper.selectById(outboundItemVO.getFromItemId());
+                    String intoStatus = this.setIntoStatus(outReturnItemResponse.getIntoingQty().add(outReturnItem.getIntoingQty()),
+                            outReturnItemResponse.getIntoQty().add(outReturnItem.getIntoQty()));
                     outReturnItem.setIntoStatus(intoStatus);
                     //修改
                     int countRow = outReturnItemMapper.updateById(outReturnItem);
                     //数量超出
                     if (countRow == 0) {
-                        throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+                        throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
                     }
                     //endregion
                 }
@@ -396,14 +407,17 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
             outReturn.setIntoAmt((sumOutAmt.subtract(sumDelOutAmt)).abs());
             outReturn.setIntoingQty(sumOutQty.add(sumDelOutingQty));
             outReturn.setIntoingAmt(sumOutAmt.add(sumDelOutingAmt));
+            //根据id查询
+            OutReturnResponse outReturnResponse = outReturnMapper.selectById(outboundVO.getFromId());
             //入库状态
-            String outReturnIntoStatus = this.setIntoStatus(outReturn.getIntoingQty(), outReturn.getIntoQty());
-            outReturn.setIntoStatus(outReturnIntoStatus);
+            String intoStatus = this.setIntoStatus(outReturnResponse.getIntoQty().add(outReturn.getIntoingQty()),
+                    outReturnResponse.getIntoQty().add(outReturn.getIntoQty()));
+            outReturn.setIntoStatus(intoStatus);
             //修改
             int countRow = outReturnMapper.updateById(outReturn);
             //数量超出
             if (countRow == 0) {
-                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
             }
 
 
@@ -438,14 +452,17 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
             outReturn.setIntoAmt(outboundResponse.getOutAmt());
             outReturn.setIntoingQty(outboundResponse.getOutQty().abs());
             outReturn.setIntoingAmt(outboundResponse.getOutAmt().abs());
+            //根据id查询
+            OutReturnResponse outReturnResponse = outReturnMapper.selectById(outboundVO.getFromId());
             //入库状态
-            String intoStatus = this.setIntoStatus(outReturn.getIntoingQty(), outReturn.getIntoQty());
+            String intoStatus = this.setIntoStatus(outReturnResponse.getIntoQty().add(outReturn.getIntoingQty()),
+                    outReturnResponse.getIntoQty().add(outReturn.getIntoQty()));
             outReturn.setIntoStatus(intoStatus);
             //修改
             int countRow = outReturnMapper.updateById(outReturn);
             //数量超出
             if (countRow == 0) {
-                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
             }
 
         }
@@ -478,14 +495,17 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
                 outReturnItem.setIntoAmt(outboundItemResponse.getOutAmt());
                 outReturnItem.setIntoingQty(outboundItemResponse.getOutQty().abs());
                 outReturnItem.setIntoingAmt(outboundItemResponse.getOutAmt().abs());
+                //根据id查询
+                OutReturnItemResponse outReturnItemResponse = outReturnItemMapper.selectById(outboundItemResponse.getFromItemId());
                 //入库状态
-                String intoStatus = this.setIntoStatus(outReturnItem.getIntoingQty(), outReturnItem.getIntoQty());
+                String intoStatus = this.setIntoStatus(outReturnItemResponse.getIntoingQty().add(outReturnItem.getIntoingQty()),
+                        outReturnItemResponse.getIntoQty().add(outReturnItem.getIntoQty()));
                 outReturnItem.setIntoStatus(intoStatus);
                 //修改
                 int countRow = outReturnItemMapper.updateById(outReturnItem);
                 //数量超出
                 if (countRow == 0) {
-                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
                 }
             }
             //endregion
@@ -499,6 +519,8 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
                     .setOutAmt(outboundItemResponse.getOutingAmt().add(outboundItemResponse.getOutAmt()))
                     .setOutQty(BigDecimal.ZERO)
                     .setOutAmt(BigDecimal.ZERO)
+                    .setCostPrice(BigDecimal.ZERO)
+                    .setCostAmt(BigDecimal.ZERO)
                     .setItemId(outboundItemResponse.getItemId());
             //修改
             outboundItemMapper.update(outboundItem,