Просмотр исходного кода

Merge branch 'master' of http://git.dongkesoft.com:9001/iBOSS-2.0-Mini/iboss-server-mdm

songyang 2 лет назад
Родитель
Сommit
943c1e83d1

+ 3 - 1
src/main/java/com/dk/mdm/controller/ivt/inbound/InboundItemController.java

@@ -1,6 +1,7 @@
 package com.dk.mdm.controller.ivt.inbound;
 
 import com.dk.common.model.pojo.PageList;
+import com.dk.common.response.ResponseResultUtil;
 import com.dk.common.response.ResponseResultVO;
 import com.dk.mdm.model.pojo.ivt.InboundItem;
 import com.dk.common.service.BaseService;
@@ -17,6 +18,7 @@ import io.swagger.annotations.Api;
 import com.dk.mdm.service.ivt.inbound.InboundItemService;
 
 import javax.validation.Valid;
+import java.util.List;
 
 @Api(tags = "入库明细API接口")
 @RestController
@@ -82,7 +84,7 @@ public class InboundItemController{
             notes = "入库成本核对"
     )
     @PostMapping({"cost_check_ok"})
-    public ResponseResultVO<?> CostCheckOk(@Valid @RequestBody InboundItemQuery inboundItemQuery) {
+    public ResponseResultVO<?> CostCheckOk(@Valid @RequestBody List<InboundItemQuery> inboundItemQuery) {
         return inboundItemService.CostCheckOk(inboundItemQuery);
     }
 }

+ 6 - 0
src/main/java/com/dk/mdm/mapper/ivt/InboundItemMapper.java

@@ -77,5 +77,11 @@ public interface InboundItemMapper extends BaseMapper<InboundItem>{
      */
     List<InboundItemResponse> selectByInboundReturnCond(InboundItemQuery inboundItemQuery);
 
+    /**
+     * @desc   : 入库成本核对
+     * @author : 常皓宁
+     * @date   : 2024/4/18 9:07
+     */
+    int  updateCost(InboundItem inboundItem);
 }
 

+ 14 - 0
src/main/java/com/dk/mdm/mapper/ivt/InboundItemMapper.xml

@@ -559,4 +559,18 @@
             limit #{end} offset #{start}
         </if>
     </select>
+
+    <!--入库成本核对-->
+    <update id="updateCost" parameterType="com.dk.mdm.model.pojo.ivt.InboundItem">
+        update dkic_b.t_psi_inbound_item
+        <set>
+            <if test="costPrice!= null">
+                cost_price= #{costPrice},
+            </if>
+            <if test="costAmt!= null">
+                cost_amt = #{costAmt},
+            </if>
+        </set>
+        where item_id = #{itemId}::uuid
+    </update>
 </mapper>

+ 14 - 0
src/main/java/com/dk/mdm/mapper/ivt/InventoryBatchMapper.java

@@ -77,6 +77,20 @@ public interface InventoryBatchMapper extends BaseMapper<InventoryBatch>{
      */
     InventoryBatchResponse  selectByFromCondition(InventoryBatchQuery inventoryBatchQuery);
 
+    /**
+     * @desc   : 入库成本核对查询存货批次明细
+     * @author : 常皓宁
+     * @date   : 2024/4/18 9:42
+     */
+    InventoryBatchResponse  selectCostCondition(InventoryBatchQuery inventoryBatchQuery);
+
+    /**
+     * @desc   : 修改存货批次明细(入库成本核对)
+     * @author : 常皓宁
+     * @date   : 2024/4/18 10:29
+     */
+    int updateInventoryBatchCost(InventoryBatchQuery inventoryBatchQuery);
+
 
 
 }

+ 18 - 0
src/main/java/com/dk/mdm/mapper/ivt/InventoryBatchMapper.xml

@@ -275,4 +275,22 @@
     </update>
 
 
+    <!--入库成本核对查询存货批次明细-->
+    <select id="selectCostCondition" resultMap="BaseResultMapResponse">
+        SELECT
+        <include refid="Base_Column_List_Response"/>
+        FROM dkic_b.t_psi_inventory_batch tpib
+        WHERE tpib.from_item_id = #{fromItemId}::uuid
+        AND tpib.flg_valid
+    </select>
+
+    <!-- 修改存货批次明细(入库成本核对)-->
+    <update id="updateInventoryBatchCost" parameterType="com.dk.mdm.model.pojo.ivt.InventoryBatch">
+        update dkic_b.t_psi_inventory_batch
+        set cost_amt = #{costAmt,jdbcType=NUMERIC},
+            cost_price = #{costPrice,jdbcType=NUMERIC},
+            where batch_id = #{batchId,typeHandler=UuidTypeHandler}
+    </update>
+
+
 </mapper>

+ 7 - 0
src/main/java/com/dk/mdm/mapper/ivt/InventoryMapper.java

@@ -72,5 +72,12 @@ public interface InventoryMapper extends BaseMapper<Inventory>{
      */
     int deleteData(Inventory inventory);
 
+    /**
+     * @desc   : 修改存货单价/存货资产
+     * @author : 常皓宁
+     * @date   : 2024/4/18 14:57
+     */
+    int updateCost(Inventory inventory);
+
 }
 

+ 14 - 0
src/main/java/com/dk/mdm/mapper/ivt/InventoryMapper.xml

@@ -286,5 +286,19 @@
         where inv_id = #{invId,typeHandler=UuidTypeHandler}
     </delete>
 
+    <!--修改存货单价/存货资产-->
+    <update id="updateCost" parameterType="com.dk.mdm.model.pojo.ivt.Inventory">
+        update dkic_b.t_psi_inventory
+        <set>
+            <if test="costPrice != null">
+                cost_price = #{costPrice,jdbcType=NUMERIC},
+            </if>
+            <if test="costAmt != null">
+                cost_amt = #{costAmt,jdbcType=NUMERIC},
+            </if>
+        </set>
+        where inv_id =#{invId,typeHandler=UuidTypeHandler}
+    </update>
+
 
 </mapper>

+ 21 - 0
src/main/java/com/dk/mdm/mapper/ivt/OutboundItemCostMapper.java

@@ -50,5 +50,26 @@ public interface OutboundItemCostMapper extends BaseMapper<OutboundItemCost>{
     int deleteData(InOutRecord inOutRecord);
 
 
+    /**
+     * @desc   : 入库成本核对查询出库成本
+     * @author : 常皓宁
+     * @date   : 2024/4/18 9:46
+     */
+    List<OutboundItemCostResponse> selectCostOutbound(OutboundItemCostQuery outboundItemCostQuery);
+
+    /**
+     * @desc   : 修改出库成本(入库成本核对)
+     * @author : 常皓宁
+     * @date   : 2024/4/18 10:55
+     */
+    int updateOutboundCost(OutboundItemCostQuery outboundItemCostQuery);
+
+    /**
+     * @desc   : 修改最后一条出库成本(入库成本核对)
+     * @author : 常皓宁
+     * @date   : 2024/4/18 10:55
+     */
+    int updateLastCost(OutboundItemCostQuery updateLastCost);
+
 }
 

+ 25 - 0
src/main/java/com/dk/mdm/mapper/ivt/OutboundItemCostMapper.xml

@@ -161,4 +161,29 @@
     </delete>
 
 
+    <!-- 入库成本核对查询出库成本 -->
+    <select id="selectCostOutbound" resultMap="BaseResultMapResponse">
+        SELECT
+        <include refid="Base_Column_List_Response"/>
+        FROM dkic_b.t_psi_outbound_item_cost tpoic
+        where tpoic.batch_id = #{batchId}::uuid
+        AND tpoic.flg_valid
+    </select>
+
+    <!-- 修改出库成本(入库成本核对)-->
+    <update id="updateOutboundCost" parameterType="com.dk.mdm.model.pojo.ivt.OutboundItemCost">
+        update dkic_b.t_psi_outbound_item_cost
+        set cost_amt = #{costAmt,jdbcType=NUMERIC},
+            cost_price = #{costPrice,jdbcType=NUMERIC},
+            where batch_id = #{batchId,typeHandler=UuidTypeHandler}
+    </update>
+
+    <!-- 修改最后一条出库成本(入库成本核对)-->
+    <update id="updateLastCost" parameterType="com.dk.mdm.model.pojo.ivt.OutboundItemCost">
+        update dkic_b.t_psi_outbound_item_cost
+        set cost_amt += #{costAmt,jdbcType=NUMERIC}
+        where batch_id = #{batchId,typeHandler=UuidTypeHandler}
+    </update>
+
+
 </mapper>

+ 15 - 0
src/main/java/com/dk/mdm/mapper/ivt/OutboundItemMapper.java

@@ -3,6 +3,7 @@ package com.dk.mdm.mapper.ivt;
 import com.dk.mdm.model.pojo.ivt.OutboundItem;
 import com.dk.common.mapper.BaseMapper;
 import com.dk.mdm.model.query.ivt.InboundItemQuery;
+import com.dk.mdm.model.query.ivt.OutboundItemCostQuery;
 import com.dk.mdm.model.query.ivt.OutboundItemQuery;
 import com.dk.mdm.model.response.ivt.InboundItemResponse;
 import com.dk.mdm.model.response.ivt.OutboundItemResponse;
@@ -88,6 +89,20 @@ public interface OutboundItemMapper extends BaseMapper<OutboundItem>{
     List<OutboundItemResponse> selectOutboundItem(OutboundItemQuery outboundItemQuery);
 
 
+    /**
+     * @desc   : 修改出库明细成本单价 金额
+     * @author : 常皓宁
+     * @date   : 2024/4/18 13:47
+     */
+    int  updateOutCost(OutboundItemQuery outboundItemQuery);
+
+    /**
+     * @desc   : 修改最后一条出库成本(入库成本核对)
+     * @author : 常皓宁
+     * @date   : 2024/4/18 10:55
+     */
+    int updateLastCost(OutboundItemQuery outboundItemQuery);
+
 
 }
 

+ 22 - 0
src/main/java/com/dk/mdm/mapper/ivt/OutboundItemMapper.xml

@@ -560,4 +560,26 @@
         left join dkic_b.t_psi_inventory tpi on tpi.inv_id = tpii.inv_id
     </sql>
 
+    <!--修改出库明细成本单价 金额 -->
+    <update id="updateOutCost" parameterType="com.dk.mdm.model.pojo.ivt.OutboundItem">
+        update dkic_b.t_psi_outbound_item
+        <set>
+            <if test=" costPrice != null">
+                cost_price = #{costPrice,jdbcType=NUMERIC},
+            </if>
+            <if test=" costAmt != null">
+                cost_amt = #{costAmt,jdbcType=NUMERIC},
+            </if>
+        </set>
+        where item_id = #{itemId,typeHandler=UuidTypeHandler}
+    </update>
+
+    <!-- 修改最后一条出库成本(入库成本核对)-->
+    <update id="updateLastCost" parameterType="com.dk.mdm.model.pojo.ivt.OutboundItem">
+        update dkic_b.t_psi_outbound_item
+        set cost_amt += #{costAmt,jdbcType=NUMERIC}
+        where item_id = #{itemId,typeHandler=UuidTypeHandler}
+    </update>
+
+
 </mapper>

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

@@ -292,10 +292,10 @@
                tmgs.sku_model                             as "skuModel",
                tmgs.sku_name                              as "skuName",
                t.item_qty                                 as "orderQty",
-               t.item_qty - t.outing_qty                  as "canOutingQty",
-               t.item_qty - t.outing_qty                  as outing_qty,
+               t.item_qty - t.outing_qty - t.out_qty      as "canOutingQty",
+               t.item_qty - t.outing_qty - t.out_qty      as outing_qty,
                t.price_sale                               as "priceOut",
-               t.price_sale * (t.item_qty - t.outing_qty) as outing_amt,
+               t.price_sale * (t.item_qty - t.outing_qty - t.out_qty) as outing_amt,
                t.non_std_code,
                t.remarks,
                t.wh_id,

+ 134 - 5
src/main/java/com/dk/mdm/service/ivt/inbound/InboundItemService.java

@@ -6,13 +6,18 @@ import com.dk.common.model.pojo.PageList;
 import com.dk.common.response.ResponseResultUtil;
 import com.dk.common.response.ResponseResultVO;
 import com.dk.mdm.infrastructure.convert.ivt.InboundItemConvert;
-import com.dk.mdm.model.pojo.ivt.Inbound;
-import com.dk.mdm.model.pojo.ivt.InboundItem;
-import com.dk.mdm.mapper.ivt.InboundItemMapper;
+import com.dk.mdm.mapper.ivt.*;
+import com.dk.mdm.model.pojo.ivt.*;
 import com.dk.common.service.BaseService;
 import com.dk.common.mapper.BaseMapper;
 import com.dk.mdm.model.query.ivt.InboundItemQuery;
+import com.dk.mdm.model.query.ivt.InventoryBatchQuery;
+import com.dk.mdm.model.query.ivt.OutboundItemCostQuery;
+import com.dk.mdm.model.query.ivt.OutboundItemQuery;
 import com.dk.mdm.model.response.ivt.InboundItemResponse;
+import com.dk.mdm.model.response.ivt.InventoryBatchResponse;
+import com.dk.mdm.model.response.ivt.InventoryResponse;
+import com.dk.mdm.model.response.ivt.OutboundItemCostResponse;
 import com.dk.mdm.model.vo.ivt.InboundItemVO;
 import com.dk.mdm.model.vo.ivt.InboundVO;
 import com.dk.mdm.service.common.CommonService;
@@ -20,6 +25,8 @@ import org.springframework.stereotype.Service;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
+import java.util.List;
 import java.util.Map;
 
 @Service
@@ -40,6 +47,18 @@ public class InboundItemService extends BaseService<InboundItem> {
 	@Autowired
 	private CommonService commonService;
 
+	@Autowired
+	private InventoryBatchMapper inventoryBatchMapper;
+
+	@Autowired
+	private OutboundItemCostMapper outboundItemCostMapper;
+
+	@Autowired
+	private OutboundItemMapper outboundItemMapper;
+
+	@Autowired
+	private InventoryMapper inventoryMapper;
+
 	/**
 	 * @desc   : 条件查询 (采购入库用)
 	 * @author : 常皓宁
@@ -87,9 +106,119 @@ public class InboundItemService extends BaseService<InboundItem> {
 	 * @date   : 2024/4/17 15:26
 	 */
 	@Transactional(rollbackFor = {Exception.class})
-	public ResponseResultVO<?> CostCheckOk(InboundItemQuery inboundItemQuery) {
+	public ResponseResultVO<?> CostCheckOk(List<InboundItemQuery> inboundItemQuery) {
+		for(InboundItemQuery inboundItem : inboundItemQuery){
+			//修改入库明细表
+			InboundItem inboundItem1 = new InboundItem()
+					.setItemId(inboundItem.getItemId())
+					.setCostPrice(inboundItem.getCostPrice())
+					.setCostAmt(inboundItem.getCostAmt());
+			inboundItemMapper.updateCost(inboundItem1);
+			//查询存货批次明细
+			InventoryBatchResponse inventoryBatchResponse =
+					inventoryBatchMapper.selectByFromCondition(new InventoryBatchQuery().setFromItemId(inboundItem.getItemId()));
+			//查询出库成本
+			List<OutboundItemCostResponse> outboundItemCostResponses =
+					outboundItemCostMapper.selectCostOutbound(new OutboundItemCostQuery().setBatchId(inventoryBatchResponse.getBatchId()));
+			//当出库成本有数据且数量不为0(理论上是没有数据 数量就是0)
+			BigDecimal outCostAmtTotal = BigDecimal.ZERO;//总出库成本总和
+			if(outboundItemCostResponses.size() > 0){
+				for(OutboundItemCostResponse outboundItemCostResponse : outboundItemCostResponses){
+					//出库数量不是0
+					if(outboundItemCostResponse.getOutQty().compareTo(BigDecimal.ZERO) != 0){
+						//出库成本 单独计算后面需要合计
+						BigDecimal outCostAmt = inboundItem.getCostPrice().multiply(outboundItemCostResponse.getOutQty());
+						//先用出库单价*出库数量计算金额 如果后面有差额 就更最后一条数据
+						OutboundItemCostQuery outboundItemCostQuery = new OutboundItemCostQuery()
+								.setBatchId(outboundItemCostResponse.getBatchId())
+								.setCostPrice(inboundItem.getCostPrice())
+								.setCostAmt(outCostAmt);
+						//修改出库成本
+						outboundItemCostMapper.updateOutboundCost(outboundItemCostQuery);
+						//修改出库明细表
+						OutboundItemQuery outboundItemQuery = new OutboundItemQuery()
+								.setItemId(outboundItemCostResponse.getOutItemId())
+								.setCostPrice(inboundItem.getCostPrice())
+								.setCostAmt(outCostAmt);
+						outboundItemMapper.updateOutCost(outboundItemQuery);
+
+						outCostAmtTotal.add(outCostAmt);
+						//修改存货批次明细
+						InventoryBatchQuery inventoryBatchQuery = new InventoryBatchQuery()
+								.setBatchId(inventoryBatchResponse.getBatchId())
+								.setCostPrice(inboundItem.getCostPrice())
+								.setCostAmt(inboundItem.getCostPrice().multiply(inventoryBatchResponse.getInvQty()));
+						inventoryBatchMapper.updateInventoryBatchCost(inventoryBatchQuery);
+						//修改总单
+						this.updateInventory(new InventoryBatchQuery().setInvId(inventoryBatchResponse.getInvId()));
+					}
+					//出库数量是0
+					else if(outboundItemCostResponse.getOutQty().compareTo(BigDecimal.ZERO) == 0){
+						InventoryBatchQuery inventoryBatchQuery = new InventoryBatchQuery()
+								.setBatchId(inventoryBatchResponse.getBatchId())
+								.setCostPrice(inboundItem.getCostPrice())
+								.setCostAmt(inboundItem.getCostAmt());
+						inventoryBatchMapper.updateInventoryBatchCost(inventoryBatchQuery);
+						//修改总单
+						this.updateInventory(new InventoryBatchQuery().setInvId(inventoryBatchResponse.getInvId()));
+					}
+				}
+				//出库成本 金额之和 加上 存货批次明细成本金额(存货资产) = 核对金额
+				//如果出库成本核对有差额 就更最后一条数据
+				BigDecimal batchCostAmt = inboundItem.getCostPrice().multiply(inventoryBatchResponse.getInvQty());//存货资产
+				//修改的成本金额总和(存货资产 + 出库成本 金额)
+				BigDecimal costAmtTotal = batchCostAmt.add(outCostAmtTotal);
+				if(costAmtTotal.compareTo(inboundItem.getCostAmt())!= 0){
+					//修改出库成本
+					OutboundItemCostQuery updateLastCost = new OutboundItemCostQuery()
+							.setBatchId(outboundItemCostResponses.get(outboundItemCostResponses.size() - 1).getBatchId())
+							.setCostAmt(inboundItem.getCostAmt().subtract(costAmtTotal));
+					outboundItemCostMapper.updateLastCost(updateLastCost);
+					//修改出库明细
+					OutboundItemQuery outboundItemQuery = new OutboundItemQuery()
+							.setItemId(outboundItemCostResponses.get(outboundItemCostResponses.size() - 1).getOutItemId())
+							.setCostPrice(inboundItem.getCostPrice())
+							.setCostAmt(inboundItem.getCostAmt().subtract(costAmtTotal));
+					outboundItemMapper.updateLastCost(outboundItemQuery);
+				}
+			}
+			//当出库成本没有数据 只修改存货批次明细
+			else{
+				InventoryBatchQuery inventoryBatchQuery = new InventoryBatchQuery()
+						.setBatchId(inventoryBatchResponse.getBatchId())
+						.setCostPrice(inboundItem.getCostPrice())
+						.setCostAmt(inboundItem.getCostAmt());
+				inventoryBatchMapper.updateInventoryBatchCost(inventoryBatchQuery);
+				//修改总单
+				this.updateInventory(new InventoryBatchQuery().setInvId(inventoryBatchResponse.getInvId()));
+			}
+		}
+		return ResponseResultUtil.success();
+	}
 
-		return null;
+	/**
+	 * @desc   : 修改存货总单信息(入库成本核对)
+	 * @author : 常皓宁
+	 * @date   : 2024/4/18 15:07
+	 */
+	@Transactional(rollbackFor = {Exception.class})
+	public ResponseResultVO<?> updateInventory(InventoryBatchQuery inventoryBatchQuery) {
+		//总单
+		InventoryResponse inventoryResponse = inventoryMapper.selectById(inventoryBatchQuery.getInvId());
+		//明细
+		List<InventoryBatchResponse> inventoryBatchList
+				= inventoryBatchMapper.selectByCond(new InventoryBatchQuery().setInvId(inventoryBatchQuery.getInvId()));
+
+		BigDecimal inventoryCostTotal = BigDecimal.ZERO;
+		for(InventoryBatchResponse inventoryBatchResponse1 : inventoryBatchList){
+			inventoryCostTotal.add(inventoryBatchResponse1.getCostAmt());
+		}
+		Inventory inventory = new Inventory()
+				.setInvId(inventoryBatchQuery.getInvId())
+				.setCostPrice(inventoryCostTotal.divide(inventoryResponse.getInvQty()).setScale(2, BigDecimal.ROUND_HALF_UP))
+				.setCostAmt(inventoryCostTotal);
+		inventoryMapper.updateCost(inventory);
+		return ResponseResultUtil.success(inventoryBatchQuery);
 	}
 
 }

+ 72 - 67
src/main/java/com/dk/mdm/service/mac/AccountService.java

@@ -239,7 +239,7 @@ public class AccountService extends BaseService<Account> {
      * @date : 2024-03-22 11:08
      */
     public void updateMac(String macId) {
-        if(macId == null){
+        if (macId == null) {
             return;
         }
         // 查询当前账户流水合计
@@ -249,7 +249,7 @@ public class AccountService extends BaseService<Account> {
         // 更新资金账户
         MoneyAccount moneyAccountForUpdate = moneyAccountMapper.selectByIdForUpdate(macId);
         // 如果账户不允许为负数
-        if(!moneyAccountForUpdate.getFlgNegative()) {
+        if (!moneyAccountForUpdate.getFlgNegative()) {
             // 如果余额小于0 ,则提示余额不足
             if (sumAmtInflow.compareTo(BigDecimal.ZERO) == -1) {
                 throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.RESIDUE_NO_LESS.getMessage());
@@ -268,7 +268,7 @@ public class AccountService extends BaseService<Account> {
      * @date : 2024-03-22 11:08
      */
     public void updateContractAssets(String objectId) {
-        if(objectId == null){
+        if (objectId == null) {
             return;
         }
         // 更新账款总表上的总应收账款和总剩余应收
@@ -290,7 +290,7 @@ public class AccountService extends BaseService<Account> {
      * @date : 2024-03-22 11:08
      */
     public void updatePurEstimate(String objectId) {
-        if(objectId == null){
+        if (objectId == null) {
             return;
         }
         // 更新账款总表上的总应收账款和总剩余应收
@@ -353,12 +353,12 @@ public class AccountService extends BaseService<Account> {
 
             // 如果当前出库单对应的订单全部出库了,并且订单有收款(锁定金额),则自动做应收核销
             // 如果是销售出库
-            if(outbound.getOutType().equals(Constant.OutType.SALE.getName())){
+            if (outbound.getOutType().equals(Constant.OutType.SALE.getName())) {
                 Order orderForUpdate = orderMapper.selectByIdForUpdate(outbound.getFromId());
                 // 如果当前订单已经全部出库
-                if(orderForUpdate.getOutQty().compareTo(orderForUpdate.getSumQuantity()) == 0){
+                if (orderForUpdate != null && orderForUpdate.getOutQty().compareTo(orderForUpdate.getSumQuantity()) == 0) {
                     RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(orderForUpdate.getOrderId());
-                    if(recPayForUpdate != null && recPayForUpdate.getFlgLock()){
+                    if (recPayForUpdate != null && recPayForUpdate.getFlgLock()) {
                         // 先把收款单解锁
                         RecPay recPayUpdate = new RecPay();
                         recPayUpdate.setFlgLock(false).setRpId(recPayForUpdate.getRpId());
@@ -380,10 +380,11 @@ public class AccountService extends BaseService<Account> {
                                 .setObjectId(objectId);
                         super.updateByUuid(accountUpdate);
 
+                        // 查出当前订单需要核销的应收单据
                         List<AccountItemResponse> accountItemResponseList = accountItemMapper.getReceivableAccountItemForUpdate(
                                 new AccountItemQuery().setObjectId(objectId).setOrderId(orderForUpdate.getOrderId()));
 
-                        if(accountItemResponseList.size() > 0){
+                        if (accountItemResponseList.size() > 0) {
                             // 记录核销了哪些应收账
                             List<RecPayHandleItem> receivableList = new ArrayList<>();
 
@@ -395,10 +396,10 @@ public class AccountService extends BaseService<Account> {
                                 recPayHandleItem.setRpId(recPayForUpdate.getRpId()).setCpId(recPayForUpdate.getCpId()).setAccDate(recPayForUpdate.getAccDate())
                                         .setAccItemId(accountItemResponse.getAccItemId());
                                 // 如果定金比应收金额大
-                                if(lockAmt.compareTo(accountItemResponse.getAmtResidue()) == 1){
+                                if (lockAmt.compareTo(accountItemResponse.getAmtResidue()) == 1) {
                                     recPayHandleItem.setAmtReceivableHandle(accountItemResponse.getAmtResidue());
                                     lockAmt = lockAmt.subtract(accountItemResponse.getAmtResidue());
-                                }else{
+                                } else {
                                     recPayHandleItem.setAmtReceivableHandle(lockAmt);
                                     lockAmt = BigDecimal.ZERO;
                                 }
@@ -419,7 +420,7 @@ public class AccountService extends BaseService<Account> {
                                 accountItemService.updateByUuid(accountItemUpdate);
 
                                 // 如果定金都用完了,跳出循环
-                                if(lockAmt.compareTo(BigDecimal.ZERO)==0){
+                                if (lockAmt.compareTo(BigDecimal.ZERO) == 0) {
                                     break;
                                 }
                             }
@@ -503,9 +504,9 @@ public class AccountService extends BaseService<Account> {
      */
     public void reverseReceivable(String invoiceId, String biznisType) {
         // 更新账款明细应收收款
-        AccountItem accountItemForUpdate = null;
+        AccountItem accountItemForUpdate;
         // 账务对象Id
-        String objectId = null;
+        String objectId;
 
         if ("t_psi_outbound".equals(biznisType)) {
             Outbound outbound = outboundMapper.selectByIdForUpdate(invoiceId);
@@ -520,60 +521,64 @@ public class AccountService extends BaseService<Account> {
             Account accountUpdate;
             // 如果当前出库单对应的订单做了应收收款,则自动作废应收核销,并且锁定金额订单收款(锁定金额)
             // 如果是销售出库
-            if(outbound.getOutType().equals(Constant.OutType.SALE.getName())){
+            if (outbound.getOutType().equals(Constant.OutType.SALE.getName())) {
                 RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(outbound.getFromId());
-                // 查出并锁定所有应收核销明细
-                List<RecPayHandleItem> recPayHandleItemForUpdateList = recPayHandleItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
-                for (RecPayHandleItem recPayHandleItemForUpdate : recPayHandleItemForUpdateList) {
-                    // 更新账款明细应收收款
-                    accountItemForUpdate = accountItemMapper.selectByIdForUpdate(recPayHandleItemForUpdate.getAccItemId());
-                    AccountItem accountItemUpdate = new AccountItem();
-                    accountItemUpdate.setAmtHandle(accountItemForUpdate.getAmtHandle().subtract(recPayHandleItemForUpdate.getAmtReceivableHandle()))
-                            .setItemId(recPayHandleItemForUpdate.getAccItemId());
-                    accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()));
-                    accountItemService.updateByUuid(accountItemUpdate);
-
-                    // 删掉核销明细
-                    recPayHandleItemMapper.deleteById(recPayHandleItemForUpdate.getItemId());
-                }
+                if (recPayForUpdate != null) {
+                    // 查出并锁定所有应收核销明细
+                    List<RecPayHandleItem> recPayHandleItemForUpdateList = recPayHandleItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
+                    if (recPayHandleItemForUpdateList.size() > 0) {
+                        for (RecPayHandleItem recPayHandleItemForUpdate : recPayHandleItemForUpdateList) {
+                            // 更新账款明细应收收款
+                            accountItemForUpdate = accountItemMapper.selectByIdForUpdate(recPayHandleItemForUpdate.getAccItemId());
+                            AccountItem accountItemUpdate = new AccountItem();
+                            accountItemUpdate.setAmtHandle(accountItemForUpdate.getAmtHandle().subtract(recPayHandleItemForUpdate.getAmtReceivableHandle()))
+                                    .setItemId(recPayHandleItemForUpdate.getAccItemId());
+                            accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()));
+                            accountItemService.updateByUuid(accountItemUpdate);
 
-                // 把总帐上的钱加回来
-                accountForUpdate = accountMapper.selectByIdForUpdate(recPayForUpdate.getObjectId());
-                accountUpdate = new Account();
-                accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().subtract(recPayForUpdate.getSumAmtReceivableHandle()))// 总应收收款金额
-                        .setObjectId(accountForUpdate.getObjectId());
-                // 剩余应收 = 总应收账款-总应收收款金额
-                accountUpdate.setReceivableResidue(accountForUpdate.getReceivable().subtract(accountUpdate.getReceivableHandle()));
-                // 可退金额 = 总收款金额-总应收收款金额+总应收优惠金额
-                accountUpdate.setReceiptResidue(accountForUpdate.getReceipt().subtract(accountUpdate.getReceivableHandle()));
-
-                // 更新前的最后校验
-                // 可用金额为负数,则不能保存
-                if (accountUpdate.getReceiptResidue().compareTo(BigDecimal.ZERO) == -1) {
-                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_NO_LESS.getMessage());
-                }
-                super.updateByUuid(accountUpdate);
-
-                // 先把收款单锁定
-                RecPay recPayUpdate = new RecPay();
-                recPayUpdate.setFlgLock(true).setRpId(recPayForUpdate.getRpId());
-                receiptService.updateByUuid(recPayUpdate);
-
-                // 账款明细解锁
-                List<RecPayItem> recPayItemList = recPayItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
-                for (RecPayItem recPayItem : recPayItemList) {
-                    AccountItem accountItemUpdate = new AccountItem();
-                    accountItemUpdate.setFlgLock(true).setItemId(recPayItem.getAccItemId());
-                    accountItemService.updateByUuid(accountItemUpdate);
-                }
+                            // 删掉核销明细
+                            recPayHandleItemMapper.deleteById(recPayHandleItemForUpdate.getItemId());
+                        }
+
+                        // 把总帐上的钱加回来
+                        accountForUpdate = accountMapper.selectByIdForUpdate(recPayForUpdate.getObjectId());
+                        accountUpdate = new Account();
+                        accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().subtract(recPayForUpdate.getSumAmtReceivableHandle()))// 总应收收款金额
+                                .setObjectId(accountForUpdate.getObjectId());
+                        // 剩余应收 = 总应收账款-总应收收款金额
+                        accountUpdate.setReceivableResidue(accountForUpdate.getReceivable().subtract(accountUpdate.getReceivableHandle()));
+                        // 可退金额 = 总收款金额-总应收收款金额+总应收优惠金额
+                        accountUpdate.setReceiptResidue(accountForUpdate.getReceipt().subtract(accountUpdate.getReceivableHandle()));
+
+                        // 更新前的最后校验
+                        // 可用金额为负数,则不能保存
+                        if (accountUpdate.getReceiptResidue().compareTo(BigDecimal.ZERO) == -1) {
+                            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_NO_LESS.getMessage());
+                        }
+                        super.updateByUuid(accountUpdate);
+
+                        // 先把收款单锁定
+                        RecPay recPayUpdate = new RecPay();
+                        recPayUpdate.setFlgLock(true).setRpId(recPayForUpdate.getRpId());
+                        receiptService.updateByUuid(recPayUpdate);
+
+                        // 账款明细解锁
+                        List<RecPayItem> recPayItemList = recPayItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
+                        for (RecPayItem recPayItem : recPayItemList) {
+                            AccountItem accountItemUpdate = new AccountItem();
+                            accountItemUpdate.setFlgLock(true).setItemId(recPayItem.getAccItemId());
+                            accountItemService.updateByUuid(accountItemUpdate);
+                        }
 
-                // 钱进到锁定金额中
-                accountUpdate = new Account();
-                accountUpdate.setReceipt(accountForUpdate.getReceipt().subtract(recPayForUpdate.getSumAmtRec()))
-                        .setReceiptResidue(accountForUpdate.getReceiptResidue().subtract(recPayForUpdate.getSumAmtRec()))
-                        .setReceiptLock(accountForUpdate.getReceiptLock().add(recPayForUpdate.getSumAmtRec()))
-                        .setObjectId(objectId);
-                super.updateByUuid(accountUpdate);
+                        // 钱进到锁定金额中
+                        accountUpdate = new Account();
+                        accountUpdate.setReceipt(accountForUpdate.getReceipt().subtract(recPayForUpdate.getSumAmtRec()))
+                                .setReceiptResidue(accountForUpdate.getReceiptResidue().subtract(recPayForUpdate.getSumAmtRec()))
+                                .setReceiptLock(accountForUpdate.getReceiptLock().add(recPayForUpdate.getSumAmtRec()))
+                                .setObjectId(objectId);
+                        super.updateByUuid(accountUpdate);
+                    }
+                }
             }
 
             accountItemForUpdate = accountItemMapper.selectByIdForUpdate(outbound.getReceivableId());
@@ -737,7 +742,7 @@ public class AccountService extends BaseService<Account> {
             LambdaUpdateWrapper<Inbound> updateWrapper = new LambdaUpdateWrapper<>();
             updateWrapper.set(Inbound::getReceivableId, null).eq(Inbound::getIntoId, UUID.fromString(invoiceId));
             inboundMapper.update(null, updateWrapper);
-        } 
+        }
         // 其他支出单
         else if ("t_mac_other_payable".equals(biznisType)) {
             OtherPayable otherPayable = otherPayableMapper.selectByIdForUpdate(invoiceId);
@@ -777,8 +782,8 @@ public class AccountService extends BaseService<Account> {
      * @author : 周兴
      * @date : 2024-04-03 16:32
      */
-    public ResponseResultVO<?> getReceivableAccountSum(AccountItemQuery accountItemQuery){
-        Map<String, Object> receivableAccountMap= accountItemMapper.getReceivableAccountSum(accountItemQuery);
+    public ResponseResultVO<?> getReceivableAccountSum(AccountItemQuery accountItemQuery) {
+        Map<String, Object> receivableAccountMap = accountItemMapper.getReceivableAccountSum(accountItemQuery);
         return ResponseResultUtil.success(receivableAccountMap);
     }