zhoux 1 год назад
Родитель
Сommit
b3f350d5ce

+ 5 - 2
src/main/java/com/dk/mdm/mapper/mst/CustomerMapper.xml

@@ -108,6 +108,8 @@
         <result column="outboundNotQuantity" property="outboundNotQuantity"/>
         <result column="outboundReturnQuantity" property="outboundReturnQuantity"/>
         <result column="outboundReturnAmount" property="outboundReturnAmount"/>
+
+        <result column="startAmount" property="startAmount"/>
     </resultMap>
 
     <!-- 通用条件列 -->
@@ -303,7 +305,8 @@
         tma.receipt,
         tma.receivable,
         tma.receivable_residue,
-        tma.receipt_residue
+        tma.receipt_residue,
+        tmor.sum_amt_receivable AS "startAmount"
         FROM dkic_b.t_mst_customer tmc
         LEFT JOIN dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tmc.cus_from
         LEFT JOIN dkic_b.t_mst_sale_channel tmsc on tmsc.channel_id = tmc.channel_id
@@ -312,7 +315,7 @@
         LEFT JOIN dkic_b.t_mst_staff tms2 on tms2.staff_id = tmc.report_staff
         LEFT JOIN sys.t_data_kind tdk on tdk.kind_code = tmc.sale_status
         LEFT JOIN  dkic_b.t_mac_account tma  on tma.object_id =  tmc.cus_id
-
+        LEFT JOIN dkic_b.t_mac_other_receivable tmor on tmor.object_id = tmc.cus_id and tmor.business_type = 0
         -- LEFT JOIN dkic_b.t_crm_cus_follow_staff tccfs on tccfs.follow_staff = any(tmc.follow_staffs)
         -- LEFT JOIN dkic_b.t_mst_staff tms1 on tms1.staff_id = tccfs.follow_staff
         WHERE tmc.cus_id = #{id}::uuid

+ 3 - 0
src/main/java/com/dk/mdm/model/response/mst/CustomerResponse.java

@@ -342,6 +342,9 @@ public class CustomerResponse extends PageInfo<CustomerResponse> implements Seri
     @ApiModelProperty(value = "退货金额")
     private BigDecimal outboundReturnAmount;
 
+    @ApiModelProperty(value = "初始欠款")
+    private BigDecimal startAmount;
+
 
 
 

+ 8 - 0
src/main/java/com/dk/mdm/model/vo/mst/CustomerVO.java

@@ -22,6 +22,7 @@ import lombok.NoArgsConstructor;
 import lombok.experimental.Accessors;
 
 import java.io.Serializable;
+import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.util.List;
 
@@ -336,6 +337,13 @@ public class CustomerVO extends PageInfo<CustomerVO> implements Serializable {
     @ApiModelProperty(value = "数据操作数据库用户 (触发器自动处理)")
     private String opDbUser;
 
+    /**
+     * 初始金额
+     */
+    @Excel(name = "初始金额")
+    @ApiModelProperty(value = "初始金额")
+    private BigDecimal startAmount;
+
 
     /*
      * 相关属性

+ 39 - 0
src/main/java/com/dk/mdm/service/mst/CustomerService.java

@@ -9,21 +9,31 @@ import com.dk.common.response.ResponseResultUtil;
 import com.dk.common.response.ResponseResultVO;
 import com.dk.mdm.infrastructure.convert.mst.CustomerConvert;
 import com.dk.mdm.infrastructure.util.AuthUtils;
+import com.dk.mdm.mapper.common.CommonMapper;
 import com.dk.mdm.model.pojo.mst.Customer;
 import com.dk.mdm.mapper.mst.CustomerMapper;
 import com.dk.common.service.BaseService;
 import com.dk.common.mapper.BaseMapper;
 import com.dk.mdm.model.query.mst.CustomerQuery;
 import com.dk.mdm.model.response.mst.CustomerResponse;
+import com.dk.mdm.model.vo.mac.OtherPayableItemVO;
+import com.dk.mdm.model.vo.mac.OtherPayableVO;
+import com.dk.mdm.model.vo.mac.OtherReceivableItemVO;
+import com.dk.mdm.model.vo.mac.OtherReceivableVO;
 import com.dk.mdm.model.vo.mst.CustomerVO;
 import com.dk.mdm.service.common.CommonService;
+import com.dk.mdm.service.mac.OtherPayableService;
+import com.dk.mdm.service.mac.OtherReceivableService;
 import org.springframework.stereotype.Service;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.PathVariable;
 
+import java.math.BigDecimal;
+import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -49,6 +59,11 @@ public class CustomerService extends BaseService<Customer> {
     @Autowired
     private OrgService orgService;
 
+    @Autowired
+    private CommonMapper commonMapper;
+
+    @Autowired
+    private OtherReceivableService otherReceivableService;
 
     @Autowired
     private AuthUtils authUtils;
@@ -112,6 +127,30 @@ public class CustomerService extends BaseService<Customer> {
         //报备日期
         customer.setReportTime(LocalDateTime.now());
         ResponseResultVO<?> insert = super.insert(customer);
+
+        if (customerVO!= null && customerVO.getStartAmount().compareTo(BigDecimal.ZERO) > 0) { //说明有起始欠款  需要插入其他支出
+            //先组装明细
+            List<OtherReceivableItemVO> itemList = new ArrayList<>();
+            OtherReceivableItemVO otherReceivableItemVO = new OtherReceivableItemVO();
+            Map<String, Object> param = new HashMap<>();
+            param.put("cpId", authUtils.getStaff().getCpId());
+            param.put("dictCode", "基础资料-收入");
+            param.put("dataValue", "期初");
+            Map<String, Object> data = commonMapper.selectDictionaryData(param);
+            if(data != null && data.size() > 0){
+                String dataId = String.valueOf(data.get("dataId"));
+                otherReceivableItemVO.setReceivableType(dataId);
+                otherReceivableItemVO.setAmtReceivable(customerVO.getStartAmount());
+                itemList.add(otherReceivableItemVO);
+                //调用 新建其他支出
+                OtherReceivableVO otherReceivableVO = new OtherReceivableVO().setBusinessType(0).setObjectId(customer.getCusId())
+                        .setSumAmtReceivable(customerVO.getStartAmount()).setStaffId(customer.getStaffId())
+                        .setOrgId(customer.getOrgId()).setAccDate(LocalDate.now()).setMakeStaff(customer.getReportStaff())
+                        .setItemList(itemList).setSumAmtRec(BigDecimal.ZERO);
+                otherReceivableService.insert(otherReceivableVO);
+            }
+        }
+
         if (insert.getCode() == ResponseCodeEnum.SUCCESS.getCode()) {
             return ResponseResultUtil.success(customer);
         } else {