Explorar o código

Merge remote-tracking branch 'origin/master'

姜永辉 %!s(int64=2) %!d(string=hai) anos
pai
achega
5e67999864

+ 1 - 1
src/main/java/com/dk/mdm/model/pojo/mac/AccountItem.java

@@ -40,7 +40,7 @@ public class AccountItem extends PageInfo<AccountItem> implements Serializable {
     /**
      * 账务明细ID
      */
-//    @TableId(value = "item_id", type = IdType.AUTO)
+    @TableId(value = "item_id", type = IdType.AUTO)
     @ApiModelProperty(value = "账务明细ID")
     @TableField(typeHandler = UuidTypeHandler.class)
     private String itemId;

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

@@ -1,5 +1,6 @@
 package com.dk.mdm.service.mac;
 
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.dk.common.exception.BaseBusinessException;
 import com.dk.common.infrastructure.annotaiton.Pagination;
 import com.dk.common.infrastructure.constant.Constant;
@@ -7,16 +8,23 @@ import com.dk.common.infrastructure.enums.ErrorCodeEnum;
 import com.dk.common.response.ResponseCodeEnum;
 import com.dk.common.response.ResponseResultUtil;
 import com.dk.common.response.ResponseResultVO;
+import com.dk.mdm.mapper.ivt.InboundMapper;
+import com.dk.mdm.mapper.ivt.OutboundMapper;
 import com.dk.mdm.mapper.mac.AccountItemMapper;
 import com.dk.mdm.mapper.mst.MoneyAccountItemMapper;
+import com.dk.mdm.model.pojo.ivt.Inbound;
+import com.dk.mdm.model.pojo.ivt.Outbound;
 import com.dk.mdm.model.pojo.mac.Account;
 import com.dk.mdm.mapper.mac.AccountMapper;
 import com.dk.common.service.BaseService;
 import com.dk.common.mapper.BaseMapper;
+import com.dk.mdm.model.pojo.mac.AccountItem;
 import com.dk.mdm.model.pojo.mst.MoneyAccount;
 import com.dk.mdm.model.query.mac.AccountItemQuery;
 import com.dk.mdm.model.response.mac.AccountItemResponse;
 import com.dk.mdm.model.response.mac.AccountResponse;
+import com.dk.mdm.service.ivt.inbound.InboundService;
+import com.dk.mdm.service.ivt.outbound.OutboundService;
 import com.dk.mdm.service.mst.MoneyAccountService;
 import org.springframework.stereotype.Service;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -25,6 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
 import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 
 @Service
 @Transactional
@@ -52,6 +61,17 @@ public class AccountService extends BaseService<Account> {
     @Autowired
     private MoneyAccountItemMapper moneyAccountItemMapper;
 
+    @Autowired
+    private OutboundService outboundService;
+
+    @Autowired
+    private OutboundMapper outboundMapper;
+
+    @Autowired
+    private InboundService inboundService;
+
+    @Autowired
+    private InboundMapper inboundMapper;
 
     /**
      * @desc : 查看来源单据,总单加明细
@@ -122,7 +142,7 @@ public class AccountService extends BaseService<Account> {
     }
 
     /**
-     * @desc : 获取账款总表,没有则新建(客户)
+     * @desc : 获取账款总表,没有则新建(供应商)
      * @author : 付斌
      * @date : 2024-03-23 16:32
      */
@@ -173,6 +193,183 @@ public class AccountService extends BaseService<Account> {
         moneyAccountUpdate.setBalance(sumAmtInflow).setMacId(macId);
         moneyAccountService.updateByUuid(moneyAccountUpdate);
     }
+
+    /**
+     * @desc : 应收记账
+     * @author : 付斌
+     * @date : 2024-03-22 11:08
+     */
+    public void accReceivable(String invoiceId, String biznisType) {
+        // 账款明细
+        AccountItem accountItemInsert = new AccountItem();
+        // 账务对象Id
+        String objectId = null;
+
+        if ("t_psi_outbound".equals(biznisType)) {
+            Outbound outbound = outboundMapper.selectByIdForUpdate(invoiceId);
+            objectId = outbound.getCusId();
+
+            // 当前单据已经记账
+            if (outbound.getReceivableId() != null) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.CURRENT_INVOICE_ISACC.getMessage());
+            }
+
+            // 插入账款明细
+            accountItemInsert.setAccItemType(Constant.accItemType.YING_SHOU.getName())
+                    .setObjectId(objectId).setOrgId(outbound.getOrgId()).setStaffId(outbound.getStaffId())
+                    .setAccDate(outbound.getOutDate()).setRecStatus(Constant.recStatuse.QUE_DING.getName())
+                    .setAmtShould(outbound.getOutAmt()).setAmtResidue(outbound.getOutAmt())
+                    .setBiznisType(biznisType).setBiznisId(outbound.getOutId()).setBiznisNo(outbound.getOutNo())
+                    .setMakeStaff(outbound.getMakeStaff()).setCpId(outbound.getCpId());
+            accountItemMapper.insert(accountItemInsert);
+
+            // 更新出库单上的账款明细Id
+            Outbound outboundUpdate = new Outbound();
+            outboundUpdate.setReceivableId(accountItemInsert.getItemId()).setOutId(invoiceId);
+            outboundService.updateByUuid(outboundUpdate);
+        }
+
+        // 更新账款总表上的总应收账款和总剩余应收
+        Account accountForUpdate = getCusAccountForUpdate(objectId);
+        Account accountUpdate = new Account();
+        accountUpdate.setReceivable(accountForUpdate.getReceivable().add(accountItemInsert.getAmtShould()))
+                .setReceivableResidue(accountForUpdate.getReceivableResidue().add(accountItemInsert.getAmtShould()))
+                .setObjectId(objectId);
+        super.updateByUuid(accountUpdate);
+    }
+
+    /**
+     * @desc : 应收反记账
+     * @author : 付斌
+     * @date : 2024-03-22 11:08
+     */
+    public void reverseReceivable(String invoiceId, String biznisType) {
+        // 更新账款明细应收收款
+        AccountItem accountItemForUpdate = null;
+        // 账务对象Id
+        String objectId = null;
+
+        if ("t_psi_outbound".equals(biznisType)) {
+            Outbound outbound = outboundMapper.selectByIdForUpdate(invoiceId);
+            objectId = outbound.getCusId();
+
+            // 当前单据已经记账
+            if (outbound.getReceivableId() == null) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.CURRENT_INVOICE_ISREVERSE.getMessage());
+            }
+
+            accountItemForUpdate = accountItemMapper.selectByIdForUpdate(outbound.getReceivableId());
+            // 当前单据已核销
+            if (accountItemForUpdate.getAmtShould().compareTo(accountItemForUpdate.getAmtResidue()) != 0) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.CURRENT_INVOICE_ISHANDLE.getMessage());
+            }
+
+            // 将出库单上的账款明细Id更为null
+            LambdaUpdateWrapper<Outbound> updateWrapper = new LambdaUpdateWrapper<>();
+            updateWrapper.set(Outbound::getReceivableId, null).eq(Outbound::getOutId, UUID.fromString(invoiceId));
+            outboundMapper.update(null, updateWrapper);
+        }
+
+        // 删除账款明细
+        accountItemMapper.deleteById(accountItemForUpdate.getItemId());
+
+        // 更新账款总表上的总应收账款和总剩余应收
+        Account accountForUpdate = getCusAccountForUpdate(objectId);
+        Account accountUpdate = new Account();
+        accountUpdate.setReceivable(accountForUpdate.getReceivable().subtract(accountItemForUpdate.getAmtShould()))
+                .setReceivableResidue(accountForUpdate.getReceivableResidue().subtract(accountItemForUpdate.getAmtShould()))
+                .setObjectId(objectId);
+        super.updateByUuid(accountUpdate);
+    }
+
+    /**
+     * @desc : 应付记账
+     * @author : 付斌
+     * @date : 2024-03-22 11:08
+     */
+    public void accPayable(String invoiceId, String biznisType) {
+        // 账款明细
+        AccountItem accountItemInsert = new AccountItem();
+        // 账务对象Id
+        String objectId = null;
+
+        if ("t_psi_inbound".equals(biznisType)) {
+            Inbound inbound = inboundMapper.selectByIdForUpdate(invoiceId);
+            objectId = inbound.getSupId();
+
+            // 当前单据已经记账
+            if (inbound.getReceivableId() != null) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.CURRENT_INVOICE_ISACC.getMessage());
+            }
+
+            // 插入账款明细
+            accountItemInsert.setAccItemType(Constant.accItemType.YING_SHOU.getName())
+                    .setObjectId(objectId).setOrgId(inbound.getOrgId()).setStaffId(inbound.getStaffId())
+                    .setAccDate(inbound.getIntoDate()).setRecStatus(Constant.recStatuse.QUE_DING.getName())
+                    .setAmtShould(inbound.getIntoAmt()).setAmtResidue(inbound.getIntoAmt())
+                    .setBiznisType(biznisType).setBiznisId(inbound.getIntoId()).setBiznisNo(inbound.getIntoNo())
+                    .setMakeStaff(inbound.getMakeStaff()).setCpId(inbound.getCpId());
+            accountItemMapper.insert(accountItemInsert);
+
+            // 更新出库单上的账款明细Id
+            Inbound inboundUpdate = new Inbound();
+            inboundUpdate.setReceivableId(accountItemInsert.getItemId()).setIntoId(invoiceId);
+            inboundService.updateByUuid(inboundUpdate);
+        }
+
+        // 更新账款总表上的总应收账款和总剩余应收
+        Account accountForUpdate = getSupAccountForUpdate(objectId);
+        Account accountUpdate = new Account();
+        accountUpdate.setPayable(accountForUpdate.getPayable().add(accountItemInsert.getAmtShould()))
+                .setPayableResidue(accountForUpdate.getPayableResidue().add(accountItemInsert.getAmtShould()))
+                .setObjectId(objectId);
+        super.updateByUuid(accountUpdate);
+    }
+
+    /**
+     * @desc : 应付反记账
+     * @author : 付斌
+     * @date : 2024-03-22 11:08
+     */
+    public void reversePayable(String invoiceId, String biznisType) {
+        // 更新账款明细应收收款
+        AccountItem accountItemForUpdate = null;
+        // 账务对象Id
+        String objectId = null;
+
+        if ("t_psi_inbound".equals(biznisType)) {
+            Inbound inbound = inboundMapper.selectByIdForUpdate(invoiceId);
+            objectId = inbound.getSupId();
+
+            // 当前单据已经记账
+            if (inbound.getReceivableId() == null) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.CURRENT_INVOICE_ISREVERSE.getMessage());
+            }
+
+            accountItemForUpdate = accountItemMapper.selectByIdForUpdate(inbound.getReceivableId());
+            // 当前单据已核销
+            if (accountItemForUpdate.getAmtShould().compareTo(accountItemForUpdate.getAmtResidue()) != 0) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.CURRENT_INVOICE_ISHANDLE.getMessage());
+            }
+
+            // 将出库单上的账款明细Id更为null
+            LambdaUpdateWrapper<Inbound> updateWrapper = new LambdaUpdateWrapper<>();
+            updateWrapper.set(Inbound::getReceivableId, null).eq(Inbound::getIntoId, UUID.fromString(invoiceId));
+            inboundMapper.update(null, updateWrapper);
+        }
+
+        // 删除账款明细
+        accountItemMapper.deleteById(accountItemForUpdate.getItemId());
+
+        // 更新账款总表上的总应收账款和总剩余应收
+        Account accountForUpdate = getSupAccountForUpdate(objectId);
+        Account accountUpdate = new Account();
+        accountUpdate.setPayable(accountForUpdate.getPayable().subtract(accountItemForUpdate.getAmtShould()))
+                .setPayableResidue(accountForUpdate.getPayableResidue().subtract(accountItemForUpdate.getAmtShould()))
+                .setObjectId(objectId);
+        super.updateByUuid(accountUpdate);
+    }
+
     /*********************  账款部分共通方法 end **********************/
 
 

+ 36 - 0
src/main/java/com/dk/mdm/test/Test.java

@@ -0,0 +1,36 @@
+package com.dk.mdm.test;
+
+import com.dk.mdm.MdmServer;
+import com.dk.mdm.service.mac.AccountService;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+
+/**
+ * @desc   : 测试类
+ * @author : 付斌
+ * @date   : 2024-03-26 12:50
+ */
+@SpringBootTest(classes = MdmServer.class)
+@RunWith(SpringRunner.class)//不加无法注入
+@Slf4j
+public class Test {
+
+
+    @Autowired
+    private AccountService accountService;
+
+
+    @org.junit.Test
+    public void testaccReceivable() {
+        accountService.accReceivable("10112024-0312-0000-0000-00000fd3a80b","t_psi_outbound");
+    }
+
+    @org.junit.Test
+    public void testreverseReceivable() {
+        accountService.reverseReceivable("10112024-0312-0000-0000-00000fd3a80b","t_psi_outbound");
+    }
+}