fubin 2 سال پیش
والد
کامیت
0f76143b41

+ 61 - 4
src/main/java/com/dk/mdm/controller/mac/MacTransferController.java

@@ -1,18 +1,22 @@
 package com.dk.mdm.controller.mac;
 
-import com.dk.common.controller.BaseController;
+import com.dk.common.model.pojo.PageList;
+import com.dk.common.response.ResponseResultVO;
 import com.dk.mdm.model.pojo.mac.MacTransfer;
 import com.dk.common.service.BaseService;
-import org.springframework.web.bind.annotation.RequestMapping;
+import com.dk.mdm.model.query.mac.MacTransferQuery;
+import com.dk.mdm.model.response.mac.MacTransferResponse;
+import com.dk.mdm.model.vo.mac.MacTransferVO;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RestController;
 import io.swagger.annotations.Api;
 import com.dk.mdm.service.mac.MacTransferService;
 
 @Api(tags = "资金转账API接口")
 @RestController
 @RequestMapping("/mac/transfer")
-public class MacTransferController extends BaseController<MacTransfer> {
+public class MacTransferController {
 
     public BaseService<MacTransfer> getService() {
         return macTransferService;
@@ -21,4 +25,57 @@ public class MacTransferController extends BaseController<MacTransfer> {
     @Autowired
     private MacTransferService macTransferService;
 
+    /**
+     * @desc : 条件查询
+     * @author : 付斌
+     * @date : 2023/1/9 10:36
+     */
+    @ApiOperation(value = "分页、关联、条件查询", notes = "分页、关联、条件查询")
+    @PostMapping({"list_by"})
+    public ResponseResultVO<PageList<MacTransferResponse>> selectByCond(@RequestBody MacTransferQuery macTransferQuery) {
+        return macTransferService.selectByCond(macTransferQuery);
+    }
+
+    /**
+     * @desc   : 通过ID查询
+     * @author : 付斌
+     * @date   : 2024/3/1 16:01
+     */
+    @PostMapping({"/{id}"})
+    public ResponseResultVO selectById(@PathVariable String id) {
+        return macTransferService.selectById(id);
+    }
+
+    /**
+     * @desc : 新建
+     * @author : 付斌
+     * @date : 2023/1/9 10:48
+     */
+    @ApiOperation(value = "新建客户收款", notes = "新建客户收款")
+    @PostMapping({"insert"})
+    public ResponseResultVO<?> insert(@RequestBody MacTransferVO macTransferVO) {
+        return macTransferService.insert(macTransferVO);
+    }
+
+    /**
+     * @desc : 编辑
+     * @author : 付斌
+     * @date : 2023/1/9 10:49
+     */
+    @ApiOperation(value = "编辑客户收款/退款", notes = "编辑客户收款/退款")
+    @PostMapping({"update"})
+    public ResponseResultVO<?> update(@RequestBody MacTransferVO macTransferVO) {
+        return macTransferService.update(macTransferVO);
+    }
+
+    /**
+     * @desc : 作废
+     * @author : 付斌
+     * @date : 2024-03-08 16:36
+     */
+    @ApiOperation(value = "作废", notes = "作废")
+    @PostMapping({"invalid/{id}"})
+    public ResponseResultVO<?> invalid(@PathVariable String id) {
+        return macTransferService.invalid(id);
+    }
 }

+ 22 - 0
src/main/java/com/dk/mdm/infrastructure/convert/mac/MacTransferConvert.java

@@ -0,0 +1,22 @@
+package com.dk.mdm.infrastructure.convert.mac;
+
+import com.dk.mdm.model.pojo.mac.MacTransfer;
+import com.dk.mdm.model.vo.mac.MacTransferVO;
+import org.mapstruct.Mapper;
+
+/**
+ * @desc   : MacTransfer转换类
+ * @author : 付斌
+ * @date   : 2024-02-28 10:18
+ */
+@Mapper(componentModel = "spring")
+public interface MacTransferConvert {
+
+    /**
+     * @desc   : 转换vo为pojo
+     * @author : 付斌
+     * @date   : 2024-02-28 15:26
+     */
+    MacTransfer convertToPo(MacTransferVO macTransferVO);
+
+}

+ 29 - 0
src/main/java/com/dk/mdm/mapper/mac/MacTransferMapper.java

@@ -2,14 +2,43 @@ package com.dk.mdm.mapper.mac;
 
 import com.dk.mdm.model.pojo.mac.MacTransfer;
 import com.dk.common.mapper.BaseMapper;
+import com.dk.mdm.model.query.mac.MacTransferQuery;
+import com.dk.mdm.model.response.mac.MacTransferResponse;
 import org.springframework.stereotype.Repository;
 
+import java.util.List;
+
 /**
 *  资金转账 Mapper
 */
 @Repository
 public interface MacTransferMapper extends BaseMapper<MacTransfer>{
 
+    /**
+     * @desc   : 根据条件进行查询
+     * @author : 付斌
+     * @date   : 2024-02-28 10:18
+     */
+    List<MacTransferResponse> selectByCond(MacTransferQuery macTransferQuery);
+
+    /**
+     * @desc   : 根据条件进行查询(数量)
+     * @author : 付斌
+     * @date   : 2024-02-28 10:19
+     */
+    Long countByCond(MacTransferQuery macTransferQuery);
+
+    /**
+     * @desc   : 根据Id进行查询
+     * @author : 付斌
+     * @date   : 2024-03-03 9:25
+     */
+    MacTransferResponse selectById(String id);
+    /**
+     * @desc   : 
+     * @author : 付斌
+     * @date   : 2024-04-05 11:17
+     */
     MacTransfer selectByInMacIdForUpdate(String id);
 }
 

+ 2 - 1
src/main/java/com/dk/mdm/mapper/mst/MoneyAccountItemMapper.java

@@ -5,6 +5,7 @@ import com.dk.mdm.model.pojo.mst.MoneyAccountItem;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -31,6 +32,6 @@ public interface MoneyAccountItemMapper extends BaseMapper<MoneyAccountItem>{
      * @author : 付斌
      * @date   : 2024-04-04 14:48
      */
-    MoneyAccountItem selectByInvoiceIdForUpdate(String id);
+    List<MoneyAccountItem> selectByInvoiceIdForUpdate(String id);
 }
 

+ 2 - 1
src/main/java/com/dk/mdm/mapper/mst/MoneyAccountMapper.xml

@@ -86,7 +86,8 @@
                coalesce(tmt.amt_trf, 0) as "initBalance"
         FROM dkic_b.t_mst_money_account as t
                  left join dkic_b.t_mst_dictionary_data as dd on t.mac_type = dd.data_id
-                 left join dkic_b.t_mac_transfer as tmt on tmt.trf_in_mac = t.mac_id and tmt.trf_type = 0
+                 left join dkic_b.t_mac_transfer as tmt
+                     on tmt.trf_in_mac = t.mac_id and tmt.trf_type = 0 and tmt.flg_valid
         <include refid="Condition"/>
     </select>
 

+ 15 - 3
src/main/java/com/dk/mdm/service/mac/AccountService.java

@@ -14,6 +14,7 @@ import com.dk.mdm.mapper.mac.AccountItemMapper;
 import com.dk.mdm.mapper.mac.OtherPayableMapper;
 import com.dk.mdm.mapper.mac.OtherReceivableMapper;
 import com.dk.mdm.mapper.mst.MoneyAccountItemMapper;
+import com.dk.mdm.mapper.mst.MoneyAccountMapper;
 import com.dk.mdm.model.pojo.ivt.Inbound;
 import com.dk.mdm.model.pojo.ivt.Outbound;
 import com.dk.mdm.model.pojo.mac.Account;
@@ -61,6 +62,9 @@ public class AccountService extends BaseService<Account> {
     private MoneyAccountService moneyAccountService;
 
     @Autowired
+    private MoneyAccountMapper moneyAccountMapper;
+
+    @Autowired
     private MoneyAccountItemMapper moneyAccountItemMapper;
 
     @Autowired
@@ -204,13 +208,21 @@ public class AccountService extends BaseService<Account> {
      * @date : 2024-03-22 11:08
      */
     public void updateMac(String macId) {
+        if(macId == null){
+            return;
+        }
         // 查询当前账户流水合计
         Map<String, Object> mapSumAmtInflow = moneyAccountItemMapper.getSumAmtInflow(macId);
         BigDecimal sumAmtInflow = new BigDecimal(mapSumAmtInflow.get("sumAmtInflow").toString());
 
-        // 如果余额小于0 ,则提示余额不足
-        if (sumAmtInflow.compareTo(BigDecimal.ZERO) == -1) {
-            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.RESIDUE_NO_LESS.getMessage());
+        // 更新资金账户
+        MoneyAccount moneyAccountForUpdate = moneyAccountMapper.selectByIdForUpdate(macId);
+        // 如果账户不允许为负数
+        if(!moneyAccountForUpdate.getFlgNegative()) {
+            // 如果余额小于0 ,则提示余额不足
+            if (sumAmtInflow.compareTo(BigDecimal.ZERO) == -1) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.RESIDUE_NO_LESS.getMessage());
+            }
         }
 
         // 更新账款总表上的收款总额和可用金额

+ 195 - 0
src/main/java/com/dk/mdm/service/mac/MacTransferService.java

@@ -1,13 +1,35 @@
 package com.dk.mdm.service.mac;
 
+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.MacTransferConvert;
+import com.dk.mdm.mapper.mst.MoneyAccountItemMapper;
+import com.dk.mdm.mapper.mst.MoneyAccountMapper;
 import com.dk.mdm.model.pojo.mac.MacTransfer;
 import com.dk.mdm.mapper.mac.MacTransferMapper;
 import com.dk.common.service.BaseService;
 import com.dk.common.mapper.BaseMapper;
+import com.dk.mdm.model.pojo.mst.MoneyAccount;
+import com.dk.mdm.model.pojo.mst.MoneyAccountItem;
+import com.dk.mdm.model.query.mac.MacTransferQuery;
+import com.dk.mdm.model.response.mac.MacTransferResponse;
+import com.dk.mdm.model.vo.mac.MacTransferVO;
+import com.dk.mdm.service.common.CommonService;
+import com.dk.mdm.service.mst.MoneyAccountService;
 import org.springframework.stereotype.Service;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
 @Service
 @Transactional
 public class MacTransferService extends BaseService<MacTransfer> {
@@ -25,4 +47,177 @@ public class MacTransferService extends BaseService<MacTransfer> {
 	@Autowired
 	private MacTransferMapper macTransferMapper;
 
+	@Autowired
+	private MoneyAccountService moneyAccountService;
+
+	@Autowired
+	private MoneyAccountMapper moneyAccountMapper;
+
+	@Autowired
+	private MoneyAccountItemMapper moneyAccountItemMapper;
+
+	@Autowired
+	private AccountService accountService;
+
+	@Autowired
+	private CommonService commonService;
+
+	@Autowired
+	private MacTransferConvert macTransferConvert;
+
+	/**
+	 * @desc : 条件查询
+	 * @author : 付斌
+	 * @date : 2023/1/9 10:40
+	 */
+	@Pagination
+	public ResponseResultVO<PageList<MacTransferResponse>> selectByCond(MacTransferQuery macTransferQuery) {
+		return super.mergeListWithCount(macTransferQuery, macTransferMapper.selectByCond(macTransferQuery),
+				macTransferMapper.countByCond(macTransferQuery));
+	}
+
+	/**
+	 * @desc   : 条件查询
+	 * @author : 付斌
+	 * @date   : 2023/2/29 10:40
+	 */
+	@Pagination
+	public ResponseResultVO selectById(String id) {
+		MacTransferResponse macTransferResponse = macTransferMapper.selectById(id);
+		return ResponseResultUtil.success(macTransferResponse);
+	}
+
+	/**
+	 * @desc : 新建
+	 * @author : 付斌
+	 * @date : 2023/2/29 10:49
+	 */
+	@Transactional(
+			rollbackFor = {Exception.class}
+	)
+	public ResponseResultVO<?> insert(MacTransferVO macTransferVO) {
+		// 转化实体
+		MacTransfer macTransfer = macTransferConvert.convertToPo(macTransferVO);
+
+		// 获取编码和主键UuId
+		Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.MACTRANSFER.getName(),true);
+		macTransfer.setTrfId(codeMap.get("outId").toString()).setTrfNo(codeMap.get("outNote").toString());
+		macTransferMapper.insert(macTransfer);
+
+		// 更新资金账户
+		MoneyAccount moneyAccountForUpdate = moneyAccountMapper.selectByIdForUpdate(macTransfer.getTrfOutMac());
+		// 如果账户不允许为负数
+		if(!moneyAccountForUpdate.getFlgNegative()){
+			// 如果账户余额比转出金额小,就不允许转出
+			if(moneyAccountForUpdate.getBalance().compareTo(macTransfer.getAmtTrf()) == -1){
+				throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.RESIDUE_NO_LESS.getMessage());
+			}
+		}
+
+		// 插入转出流水
+		MoneyAccountItem moneyAccountItem = new MoneyAccountItem();
+		moneyAccountItem.setMacId(macTransfer.getTrfOutMac()).setFlowType(Constant.FlowType.ZHUAN_ZHANG.getName())
+				.setInvoiceId(macTransfer.getTrfId()).setAmtInflow(macTransfer.getAmtTrf().negate()).setAccDate(macTransfer.getAccDate())
+				.setMakeStaff(macTransferVO.getMakeStaff()).setCpId(macTransfer.getCpId());
+		moneyAccountItemMapper.insert(moneyAccountItem);
+
+		MoneyAccount moneyAccountUpdate = new MoneyAccount();
+		moneyAccountUpdate.setBalance(moneyAccountForUpdate.getBalance().subtract(macTransfer.getAmtTrf()))
+				.setMacId(moneyAccountForUpdate.getMacId());
+		moneyAccountService.updateByUuid(moneyAccountUpdate);
+
+		// 插入转入流水
+		moneyAccountItem = new MoneyAccountItem();
+		moneyAccountItem.setMacId(macTransfer.getTrfInMac()).setFlowType(Constant.FlowType.ZHUAN_ZHANG.getName())
+				.setInvoiceId(macTransfer.getTrfId()).setAmtInflow(macTransfer.getAmtTrf()).setAccDate(macTransfer.getAccDate())
+				.setMakeStaff(macTransferVO.getMakeStaff()).setCpId(macTransfer.getCpId());
+		moneyAccountItemMapper.insert(moneyAccountItem);
+
+		// 更新资金账户
+		moneyAccountForUpdate = moneyAccountMapper.selectByIdForUpdate(macTransfer.getTrfInMac());
+		moneyAccountUpdate = new MoneyAccount();
+		moneyAccountUpdate.setBalance(moneyAccountForUpdate.getBalance().add(macTransfer.getAmtTrf()))
+				.setMacId(moneyAccountForUpdate.getMacId());
+		moneyAccountService.updateByUuid(moneyAccountUpdate);
+
+		return ResponseResultUtil.success();
+	}
+
+	/**
+	 * @desc : 更新
+	 * @author : 付斌
+	 * @date : 2023/2/29 10:49
+	 */
+	@Transactional(
+			rollbackFor = {Exception.class}
+	)
+	public ResponseResultVO<?> update(MacTransferVO macTransferVO) {
+		MacTransfer macTransferForUpdate = macTransferMapper.selectByIdForUpdate(macTransferVO.getTrfId());
+		// 需要重新计算的资金账户
+		List<String> macList = new ArrayList<>();
+		macList.add(macTransferForUpdate.getTrfOutMac());
+		macList.add(macTransferForUpdate.getTrfInMac());
+
+		// 删除账户流水
+		moneyAccountItemMapper.deleteByInvoiceId(macTransferVO.getTrfId());
+
+		// 转化实体
+		MacTransfer macTransfer = macTransferConvert.convertToPo(macTransferVO);
+		super.updateByUuid(macTransfer);
+
+		// 插入转出流水
+		MoneyAccountItem moneyAccountItem = new MoneyAccountItem();
+		moneyAccountItem.setMacId(macTransfer.getTrfOutMac()).setFlowType(Constant.FlowType.ZHUAN_ZHANG.getName())
+				.setInvoiceId(macTransfer.getTrfId()).setAmtInflow(macTransfer.getAmtTrf().negate()).setAccDate(macTransfer.getAccDate())
+				.setMakeStaff(macTransferVO.getMakeStaff()).setCpId(macTransfer.getCpId());
+		moneyAccountItemMapper.insert(moneyAccountItem);
+
+		if (!macList.contains(macTransfer.getTrfOutMac())) {
+			macList.add(macTransfer.getTrfOutMac());
+		}
+
+		// 插入转入流水
+		moneyAccountItem = new MoneyAccountItem();
+		moneyAccountItem.setMacId(macTransfer.getTrfInMac()).setFlowType(Constant.FlowType.ZHUAN_ZHANG.getName())
+				.setInvoiceId(macTransfer.getTrfId()).setAmtInflow(macTransfer.getAmtTrf()).setAccDate(macTransfer.getAccDate())
+				.setMakeStaff(macTransferVO.getMakeStaff()).setCpId(macTransfer.getCpId());
+		moneyAccountItemMapper.insert(moneyAccountItem);
+
+		if (!macList.contains(macTransfer.getTrfInMac())) {
+			macList.add(macTransfer.getTrfInMac());
+		}
+
+		// 更新账户余额
+		for (String macId : macList) {
+			accountService.updateMac(macId);
+		}
+
+		return ResponseResultUtil.success();
+	}
+
+	/**
+	 * @desc : 作废
+	 * @author : 付斌
+	 * @date : 2024-03-08 16:38
+	 */
+	public ResponseResultVO<?> invalid(String id) {
+		MacTransfer macTransferForUpdate = macTransferMapper.selectByIdForUpdate(id);
+		// 并发校验
+		if (!macTransferForUpdate.getFlgValid()) {
+			throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISFLGVALID_FALSE.getMessage());
+		}
+
+		// 删除账户流水
+		moneyAccountItemMapper.deleteByInvoiceId(id);
+
+		// 需要重新计算的资金账户
+		accountService.updateMac(macTransferForUpdate.getTrfOutMac());
+		accountService.updateMac(macTransferForUpdate.getTrfInMac());
+
+		// 作废
+		MacTransfer macTransferUpdate = new MacTransfer();
+		macTransferUpdate.setFlgValid(false).setTrfId(id);
+		super.updateByUuid(macTransferUpdate);
+		return ResponseResultUtil.success();
+	}
 }

+ 2 - 2
src/main/java/com/dk/mdm/service/mst/MoneyAccountService.java

@@ -177,9 +177,9 @@ public class MoneyAccountService extends BaseService<MoneyAccount> {
 		macTransferService.updateByUuid(MacTransferUpdate);
 
 		// 更新资金流水
-		MoneyAccountItem moneyAccountItem = moneyAccountItemMapper.selectByInvoiceIdForUpdate(macTransfer.getTrfId());
+		List<MoneyAccountItem> moneyAccountItemList = moneyAccountItemMapper.selectByInvoiceIdForUpdate(macTransfer.getTrfId());
 		MoneyAccountItem moneyAccountItemUpdate = new MoneyAccountItem();
-		moneyAccountItemUpdate.setAmtInflow(moneyAccount.getBalance()).setAccDate(moneyAccount.getAccDate()).setItemId(moneyAccountItem.getItemId());
+		moneyAccountItemUpdate.setAmtInflow(moneyAccount.getBalance()).setAccDate(moneyAccount.getAccDate()).setItemId(moneyAccountItemList.get(0).getItemId());
 		moneyAccountItemService.updateByUuid(moneyAccountItemUpdate);
 
 		// 更新账户余额