fubin 2 лет назад
Родитель
Сommit
a2896fbcad

+ 21 - 0
src/main/java/com/dk/mdm/controller/mac/OtherReceivableController.java

@@ -70,4 +70,25 @@ public class OtherReceivableController{
         return otherReceivableService.update(otherReceivableVO);
     }
 
+    /**
+     * @desc :查询其它收入明细(明细附件)
+     * @author : 付斌
+     * @date : 2024-02-28 13:24
+     */
+    @PostMapping({"get_other_receivable_for_update/{id}"})
+    public ResponseResultVO<?> getOtherReceivableForUpdate(@PathVariable String id) {
+        return otherReceivableService.getOtherReceivableForUpdate(id);
+    }
+
+    /**
+     * @desc : 作废
+     * @author : 付斌
+     * @date : 2024-03-08 16:36
+     */
+    @ApiOperation(value = "作废", notes = "作废")
+    @PostMapping({"invalid/{id}"})
+    public ResponseResultVO<?> invalid(@PathVariable String id) {
+        return otherReceivableService.invalid(id);
+    }
+
 }

+ 7 - 0
src/main/java/com/dk/mdm/mapper/mac/OtherReceivableItemMapper.java

@@ -19,5 +19,12 @@ public interface OtherReceivableItemMapper extends BaseMapper<OtherReceivableIte
      * @date : 2024-02-28 10:18
      */
     List<OtherReceivableItemResponse> selectByCond(OtherReceivableItemQuery otherReceivableQuery);
+
+    /**
+     * @desc : 根据条件进行查询
+     * @author : 付斌
+     * @date : 2024-02-28 10:18
+     */
+    List<OtherReceivableItem> selectByZIdForUpdate(String id);
 }
 

+ 15 - 0
src/main/java/com/dk/mdm/mapper/mac/OtherReceivableItemMapper.xml

@@ -102,6 +102,15 @@
         WHERE item_id = #{itemId}::uuid
     </select>
 
+    <!-- 根据主表主键锁定表t_psi_outbound_item的多行数据 -->
+    <select id="selectByZIdForUpdate" resultMap="BaseResultMap">
+        SELECT
+        <include refid="Base_Column_List"/>
+        FROM dkic_b.t_mac_other_receivable_item
+        WHERE receivable_id = #{id}::uuid
+        for update
+    </select>
+
     <!-- 根据主键锁定表t_mac_other_receivable_item的一行数据 -->
     <select id="selectByIdForUpdate" resultMap="BaseResultMap">
         SELECT
@@ -146,4 +155,10 @@
             )
         </foreach>
     </insert>
+
+    <delete id="deleteById">
+        DELETE
+        FROM dkic_b.t_mac_other_receivable_item
+        WHERE item_id = #{id}::uuid;
+    </delete>
 </mapper>

+ 7 - 0
src/main/java/com/dk/mdm/mapper/mac/OtherReceivableMapper.java

@@ -26,5 +26,12 @@ public interface OtherReceivableMapper extends BaseMapper<OtherReceivable>{
      * @date   : 2024-02-28 10:19
      */
     Long countByCond(OtherReceivableQuery otherReceivableQuery);
+
+    /**
+     * @desc   : 根据Id进行查询
+     * @author : 付斌
+     * @date   : 2024-03-03 9:25
+     */
+    OtherReceivableResponse selectById(String id);
 }
 

+ 31 - 5
src/main/java/com/dk/mdm/mapper/mac/OtherReceivableMapper.xml

@@ -175,11 +175,37 @@
     </select>
 
     <!-- 根据主键查询表t_mac_other_receivable的一行数据 -->
-    <select id="selectById" resultMap="BaseResultMap">
-        SELECT
-        <include refid="Base_Column_List"/>
-        FROM dkic_b.t_mac_other_receivable
-        WHERE receivable_id = #{receivableId}::uuid
+    <select id="selectById" resultMap="BaseResultMapResponse">
+        SELECT t.receivable_id,
+               t.receivable_no,
+               t.object_type,
+               sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "objectTypeName",
+               t.object_id,
+               tmc.cus_code         as "cusCode",
+               tmc.cus_name         as "cusName",
+               tmc.cus_phone        as "cusPhone",
+               t.org_id,
+               tmo.org_name         as "orgName",
+               t.staff_id,
+               tms.staff_name       as "staffName",
+               t.sum_amt_receivable,
+               t.acc_item_id,
+               t.acc_date,
+               t.remarks,
+               t.annex_paths,
+               t.make_staff,
+               makestaff.staff_name as "makeStaffName",
+               t.make_time,
+               t.flg_valid,
+               t.cp_id
+        FROM dkic_b.t_mac_other_receivable as t
+                 left join dkic_b.t_mst_customer tmc
+                           on tmc.cus_id = t.object_id and t.object_type in ('对象类型-客户')
+                 left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
+                 left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
+                 left join dkic_b.t_mst_staff as makestaff on makestaff.staff_id = t.make_staff
+                 left join sys.t_data_kind as tdk1 on tdk1.kind_code = t.object_type
+        WHERE receivable_id = #{id}::uuid
     </select>
 
     <!-- 根据主键锁定表t_mac_other_receivable的一行数据 -->

+ 67 - 28
src/main/java/com/dk/mdm/service/mac/OtherReceivableService.java

@@ -1,9 +1,12 @@
 package com.dk.mdm.service.mac;
 
 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.model.pojo.PageList;
+import com.dk.common.response.ResponseCodeEnum;
 import com.dk.common.response.ResponseResultUtil;
 import com.dk.common.response.ResponseResultVO;
 import com.dk.mdm.infrastructure.convert.mac.OtherReceivableConvert;
@@ -25,7 +28,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
-import java.util.stream.Collectors;
 
 @Service
 @Transactional
@@ -74,7 +76,7 @@ public class OtherReceivableService extends BaseService<OtherReceivable> {
 	}
 
 	/**
-	 * @desc : 查询订单明细(货物、收款、附件)
+	 * @desc : 查询明细(货物、收款、附件)
 	 * @author : 付斌
 	 * @date : 2024-02-28 13:25
 	 */
@@ -105,10 +107,10 @@ public class OtherReceivableService extends BaseService<OtherReceivable> {
 				.setObjectType(Constant.ObjectType.CUS.getName());
 		// 转化实体
 		OtherReceivable otherReceivable = otherReceivableConvert.convertToPo(otherReceivableVO);
-		// 订单总单保存
+		// 总单保存
 		super.insert(otherReceivable);
 
-		// 订单明细保存
+		// 明细保存
 		if (otherReceivableVO.getItemList() != null && otherReceivableVO.getItemList().size() > 0) {
 			for (OtherReceivableItemVO otherReceivableItemVO : otherReceivableVO.getItemList()) {
 				OtherReceivableItem otherReceivableItem = otherReceivableItemConvert.convertToPo(otherReceivableItemVO);
@@ -117,6 +119,7 @@ public class OtherReceivableService extends BaseService<OtherReceivable> {
 			}
 		}
 
+		// 应收记账
 		accountService.accReceivable(otherReceivable.getReceivableId(),"t_mac_other_receivable");
 		return ResponseResultUtil.success();
 	}
@@ -130,35 +133,71 @@ public class OtherReceivableService extends BaseService<OtherReceivable> {
 			rollbackFor = {Exception.class}
 	)
 	public ResponseResultVO<?> update(OtherReceivableVO otherReceivableVO) {
-		// 明细实体(避免并发,需要再查一遍)
-		OtherReceivableItem otherReceivableItemForUpdate;
-		// 转化实体
+
+		// 先更新收款单总表,否则id又更错了
 		OtherReceivable otherReceivable = otherReceivableConvert.convertToPo(otherReceivableVO);
-		//删除的
-		List<OtherReceivableItemVO> deleteOtherReceivableItemVOList = otherReceivableVO.getDeleteItemList().stream().filter(it -> it.getItemId() != null).collect(Collectors.toList());
-		if (deleteOtherReceivableItemVOList.size() > 0) {
-			for (OtherReceivableItemVO otherReceivableItemVO : deleteOtherReceivableItemVOList) {
-				otherReceivableItemMapper.deleteById(otherReceivableItemVO.getItemId());
-			}
-		}
-		// 新增的
-		List<OtherReceivableItemVO> insertOtherReceivableItemVOList = otherReceivableVO.getItemList().stream().filter(it -> it.getItemId() == null).collect(Collectors.toList());
-		for (OtherReceivableItemVO otherReceivableItemVO : insertOtherReceivableItemVOList) {
-			OtherReceivableItem otherReceivableItem = otherReceivableItemConvert.convertToPo(otherReceivableItemVO);
-			otherReceivableItem.setReceivableId(otherReceivable.getReceivableId()).setCpId(otherReceivable.getCpId());
-			otherReceivableItemMapper.insert(otherReceivableItem);
+		super.update(otherReceivable, new UpdateWrapper<OtherReceivable>().lambda().eq(OtherReceivable::getReceivableId,
+				UUID.fromString(otherReceivable.getReceivableId())));
+
+		// 应收反记账
+		accountService.reverseReceivable(otherReceivableVO.getReceivableId(),"t_mac_other_receivable");
+
+		// 将之前的明细全部删除
+		List<OtherReceivableItem> otherReceivableItemOriginalList = otherReceivableItemMapper.selectByZIdForUpdate(otherReceivableVO.getReceivableId());
+		for (OtherReceivableItem otherReceivableItem : otherReceivableItemOriginalList) {
+			otherReceivableItemMapper.deleteById(otherReceivableItem.getItemId());
 		}
-		// 编辑的
-		List<OtherReceivableItemVO> editOtherReceivableItemVOList = otherReceivableVO.getItemList().stream().filter(it -> it.getItemId() != null).collect(Collectors.toList());
-		for (OtherReceivableItemVO otherReceivableItemVO : editOtherReceivableItemVOList) {
-			otherReceivableItemForUpdate = otherReceivableItemMapper.selectByIdForUpdate(otherReceivableItemVO.getItemId());
-			OtherReceivableItem otherReceivableItem = otherReceivableItemConvert.convertToPo(otherReceivableItemVO);
-			otherReceivableItemService.updateByUuid(otherReceivableItem);
+
+		// 明细保存
+		if (otherReceivableVO.getItemList() != null && otherReceivableVO.getItemList().size() > 0) {
+			for (OtherReceivableItemVO otherReceivableItemVO : otherReceivableVO.getItemList()) {
+				OtherReceivableItem otherReceivableItem = otherReceivableItemConvert.convertToPo(otherReceivableItemVO);
+				otherReceivableItem.setItemId(null).setReceivableId(otherReceivableVO.getReceivableId()).setCpId(otherReceivableVO.getCpId());
+				otherReceivableItemMapper.insert(otherReceivableItem);
+			}
 		}
 
+		// 应收记账
+		accountService.accReceivable(otherReceivableVO.getReceivableId(),"t_mac_other_receivable");
+		return ResponseResultUtil.success();
+	}
 
-		return ResponseResultUtil.success(super.update(otherReceivable, new UpdateWrapper<OtherReceivable>().lambda().eq(OtherReceivable::getReceivableId,
-				UUID.fromString(otherReceivable.getReceivableId()))));
+	/**
+	 * @desc : 获取信息(编辑用)
+	 * @author : 付斌
+	 * @date : 2024-03-02 17:27
+	 */
+	public ResponseResultVO<?> getOtherReceivableForUpdate(String id) {
+		Map<String, Object> dataInfo = new HashMap<>();
+		OtherReceivableResponse otherReceivableResponse = otherReceivableMapper.selectById(id);
+		dataInfo.put("data", otherReceivableResponse);
+
+		// 商品明细
+		List<OtherReceivableItemResponse> otherReceivableItemResponse = otherReceivableItemMapper.selectByCond(new OtherReceivableItemQuery().setReceivableId(id));
+		dataInfo.put("dataItem", otherReceivableItemResponse);
+		return ResponseResultUtil.success(dataInfo);
 	}
 
+	/**
+	 * @desc : 作废
+	 * @author : 付斌
+	 * @date : 2024-03-08 16:38
+	 */
+	public ResponseResultVO<?> invalid(String id) {
+		OtherReceivable otherReceivableForUpdate = otherReceivableMapper.selectByIdForUpdate(id);
+		// 并发校验
+		if (!otherReceivableForUpdate.getFlgValid()) {
+			throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISFLGVALID_FALSE.getMessage());
+		}
+		// 如果所在月份已结账,则不能作废 todo
+
+		// 应收反记账
+		accountService.reverseReceivable(id,"t_mac_other_receivable");
+
+		// 作废
+		OtherReceivable otherReceivableUpdate = new OtherReceivable();
+		otherReceivableUpdate.setFlgValid(false).setReceivableId(id);
+		super.updateByUuid(otherReceivableUpdate);
+		return ResponseResultUtil.success();
+	}
 }

+ 1 - 1
src/main/java/com/dk/mdm/service/mac/RecPayService.java

@@ -301,7 +301,7 @@ public class RecPayService extends BaseService<RecPay> {
         // 新增明细
         for (RecPayItemVO recPayItemVO : recPayVO.getItemList()) {
             RecPayItem recPayItem = recPayItemConvert.convertToPo(recPayItemVO);
-            recPayItem.setRpId(recPayVO.getRpId()).setCpId(recPayVO.getCpId());
+            recPayItem.setItemId(null).setRpId(recPayVO.getRpId()).setCpId(recPayVO.getCpId());
             recPayItemMapper.insert(recPayItem);
 
             // 插入账款明细