Sfoglia il codice sorgente

同步实收款和实收款认领数据

wucl 1 anno fa
parent
commit
a874817e27

+ 1 - 1
biz-base/src/test/java/history/SyncHistoryTest.java

@@ -113,6 +113,6 @@ public class SyncHistoryTest {
 
     @Test
     public void getLandTargetMajorTest() throws NoSuchFieldException, IllegalAccessException {
-       dyoaHistoryService.fetchRealAmount();
+       dyoaHistoryService.fetchRealAmountClaimData();
     }
 }

+ 4 - 0
dao/src/main/java/com/dayou/mapper/DyoaHistoryMapper.java

@@ -28,4 +28,8 @@ public interface DyoaHistoryMapper {
     Map<String, Object> getRealAmountInfo(@Param("id") String max);
 
     List<String> getNewRealAmount(@Param("max") Date max);
+
+    List<String> getNewClaimRecordIds(@Param("max") Date max);
+
+    Map<String, Object> getNewClaimRecord(@Param("id") String id);
 }

+ 8 - 0
dao/src/main/java/com/dayou/mapper/DyoaRecordMapper.java

@@ -2,9 +2,12 @@ package com.dayou.mapper;
 
 import com.dayou.entity.DyoaRecord;
 import com.dayou.dao.CustomBaseMapper;
+import com.dayou.entity.OrderFund;
 
 import java.time.LocalDate;
 import java.util.Date;
+import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
@@ -19,4 +22,9 @@ public interface DyoaRecordMapper extends CustomBaseMapper<DyoaRecord> {
     Date getMaxOrderTime();
 
     Date getMaxRealAmountCreatedTime();
+
+    Date getMaxClaimDate();
+
+    List<DyoaRecord> selectOrderFundIdByDyoaOrderId();
+
 }

+ 3 - 0
dao/src/main/java/com/dayou/mapper/FinanceClaimMapper.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.dayou.dto.RealFundAssetsStatDTO;
 import com.dayou.entity.FinanceClaim;
 import com.dayou.dao.CustomBaseMapper;
+import com.dayou.entity.OrderFund;
 import com.dayou.vo.FinanceClaimVO;
 import com.dayou.vo.RealFundAssetsStatVO;
 import com.dayou.vo.RealFundMajorStatVO;
@@ -51,4 +52,6 @@ public interface FinanceClaimMapper extends CustomBaseMapper<FinanceClaim> {
     Page<RealFundPersonalVO> personalStat(Page page, @Param("dto")RealFundPersonalVO personalVO);
 
     List<RealFundPersonalVO> personalStatExport(@Param("dto") RealFundPersonalVO personalVO);
+
+    List<OrderFund> queryOrderTotalAmount();
 }

+ 28 - 2
dao/src/main/resources/mapper/DyoaHistoryMapper.xml

@@ -43,7 +43,8 @@
                description,
                 standardPrice,
                createdDatetime,
-               needPay
+               needPay,
+                 bankContactName
         from dy_order where id = #{id}
     </select>
 
@@ -223,7 +224,8 @@
             finished,
             finishTime,
             files,
-            createdDatetime
+            createdDatetime,
+            bankContactName
         FROM
             dy_order_loan where id = #{id}
     </select>
@@ -252,4 +254,28 @@
         from dy_finance_income
       where id = #{id}
     </select>
+
+    <select id="getNewClaimRecordIds" parameterType="java.util.Date" resultType="java.lang.String">
+        SELECT
+           id
+        FROM
+            dy_finance_income_order
+        <where>
+            <if test="max!=null">
+                and createdDatetime &gt; #{max}
+            </if>
+        </where>
+    </select>
+
+    <select id="getNewClaimRecord" parameterType="java.lang.String" resultType="map">
+        SELECT
+            orderId,
+            incomeId,
+            money,
+            takeEmpName,
+            orderType,
+            createdDatetime
+        FROM
+            dy_finance_income_order where id = #{id}
+    </select>
 </mapper>

+ 23 - 0
dao/src/main/resources/mapper/DyoaRecordMapper.xml

@@ -31,5 +31,28 @@
         select max(order_datetime) from dyoa_record where mbs_type = 'REAL_AMOUNT'
     </select>
 
+    <select id="getMaxClaimDate" resultType="java.util.Date">
+        select max(order_datetime) from dyoa_record where mbs_type = 'REAL_AMOUNT_CLAIM'
+    </select>
+
+    <select id="selectOrderFundIdByDyoaOrderId" resultType="com.dayou.entity.DyoaRecord">
+        SELECT
+            m.dyoa_id,
+            f.id as mbsId
+        FROM
+            (
+                SELECT
+                    mbs_id,
+                    dyoa_id,
+                    ( CASE mbs_type WHEN 'MAJOR_ORDER' THEN 'MAJOR_BUSINESS' WHEN 'PERSONAL_ORDER' THEN 'PERSONAL_BUSINESS' END ) AS mbs_type
+                FROM
+                    dyoa_record
+                WHERE
+                    mbs_type IN ( 'MAJOR_ORDER','PERSONAL_ORDER' )) m
+                LEFT JOIN order_fund f ON (
+                f.business_id = m.mbs_id
+                    AND f.business_type = m.mbs_type)
+    </select>
+
 
 </mapper>

+ 10 - 0
dao/src/main/resources/mapper/FinanceClaimMapper.xml

@@ -335,4 +335,14 @@
     <select id="personalStatExport" parameterType="com.dayou.vo.RealFundPersonalVO" resultType="com.dayou.vo.RealFundPersonalVO">
         <include refid="personalStatSql" />
     </select>
+
+    <select id="queryOrderTotalAmount" resultType="com.dayou.entity.OrderFund">
+        SELECT
+            fc.order_fund_id as id,
+            realAmount,
+            oof.business_type
+        FROM
+            ( SELECT order_fund_id, sum( claim_amount ) realAmount FROM finance_claim WHERE deleted = 0 GROUP BY order_fund_id ) fc
+                LEFT JOIN order_fund oof ON oof.id = fc.order_fund_id
+    </select>
 </mapper>

+ 3 - 1
domain/src/main/java/com/dayou/enums/MainBusinessEnum.java

@@ -35,7 +35,9 @@ public enum MainBusinessEnum implements CodeMsgEnumInterface<String,String> {
 
     PERSONAL_ORDER("PERSONAL_ORDER","个贷订单"),
 
-    REAL_AMOUNT("REAL_AMOUNT","实收款")
+    REAL_AMOUNT("REAL_AMOUNT","实收款"),
+
+    REAL_AMOUNT_CLAIM("REAL_AMOUNT_CLAIM","实收款认领")
     ;
 
    MainBusinessEnum(String code, String name) {

+ 179 - 7
service/src/main/java/com/dayou/dyoa/DyoaHistoryServiceImpl.java

@@ -24,6 +24,8 @@ import com.dayou.enums.MainBusinessEnum;
 import com.dayou.enums.ProductionEnum;
 import com.dayou.exception.ErrorCode;
 import com.dayou.mapper.DyoaHistoryMapper;
+import com.dayou.mapper.DyoaRecordMapper;
+import com.dayou.mapper.FinanceClaimMapper;
 import com.dayou.service.*;
 import com.dayou.utils.DateUtils;
 import com.dayou.utils.HttpKit;
@@ -65,6 +67,10 @@ public class DyoaHistoryServiceImpl implements IDyoaHistoryService{
 
     private Map<String,Long> departments = new HashMap<>();
 
+    private Map<String,Long> realAmounts = new HashMap<>();
+
+    private Map<String,Long> orderFundIds = new HashMap<>();
+
 
     private static final Map<String,String> MAJOR_ORDER_COLUM = new HashMap<>();
 
@@ -74,6 +80,9 @@ public class DyoaHistoryServiceImpl implements IDyoaHistoryService{
 
     private static final Map<String,String> REAL_AMOUNT_COLUM = new HashMap<>();
 
+    private static final Map<String,String> REAL_AMOUNT_CLAIM_COLUM = new HashMap<>();
+
+
 
     @Autowired
     private IUserService userService;
@@ -111,6 +120,12 @@ public class DyoaHistoryServiceImpl implements IDyoaHistoryService{
 
     @Autowired
     private ICustomerLinkmanService customerLinkmanService;
+
+    @Autowired
+    private FinanceClaimMapper financeClaimMapper;
+
+    @Autowired
+    private IFinanceClaimService financeClaimService;
     static {
 //        MAJOR_ORDER_COLUM.put("id","id");
         MAJOR_ORDER_COLUM.put("name","name");
@@ -148,6 +163,7 @@ public class DyoaHistoryServiceImpl implements IDyoaHistoryService{
         MAJOR_ORDER_COLUM.put("description","remark");
         MAJOR_ORDER_COLUM.put("customerName","clienteleId");
         MAJOR_ORDER_COLUM.put("customerName2","clienteleSubId");
+        MAJOR_ORDER_COLUM.put("bankContactName","clienteleContactId");
         MAJOR_ORDER_COLUM.put("terminalName","terminalClienteleId");
         MAJOR_ORDER_COLUM.put("terminalContactName","terminalClienteleContactId");
 
@@ -199,6 +215,7 @@ public class DyoaHistoryServiceImpl implements IDyoaHistoryService{
         PERSONAL_ORDER_COLUM.put("customerType","clienteleType");
         PERSONAL_ORDER_COLUM.put("customerName","clienteleId");
         PERSONAL_ORDER_COLUM.put("customerName2","clienteleSubId");
+        PERSONAL_ORDER_COLUM.put("bankContactName","clienteleContactId");
         PERSONAL_ORDER_COLUM.put("terminalType","terminalClienteleType");
         PERSONAL_ORDER_COLUM.put("terminalName","terminalClienteleId");
         PERSONAL_ORDER_COLUM.put("terminalContactName","terminalClienteleContactId");
@@ -215,8 +232,18 @@ public class DyoaHistoryServiceImpl implements IDyoaHistoryService{
         REAL_AMOUNT_COLUM.put("description","remark");
         REAL_AMOUNT_COLUM.put("creatorName","creatorId");
 
+        //实收款认领记录
+        REAL_AMOUNT_CLAIM_COLUM.put("orderId","orderFundId");
+        REAL_AMOUNT_CLAIM_COLUM.put("incomeId","realFundId");
+        REAL_AMOUNT_CLAIM_COLUM.put("money","claimAmount");
+        REAL_AMOUNT_CLAIM_COLUM.put("takeEmpName","claimUserId");
+        REAL_AMOUNT_CLAIM_COLUM.put("createdDatetime","claimDatetime");
+
     }
 
+    @Autowired
+    private DyoaRecordMapper dyoaRecordMapper;
+
     @Override
     public Page<HisMajorOrder> hisMajorPage(HisOrderParam param) {
         checkCookie();
@@ -368,11 +395,105 @@ public class DyoaHistoryServiceImpl implements IDyoaHistoryService{
         });
     }
 
+    @DSTransactional
     @Override
     public void fetchRealAmountClaimData() {
+        Date max = dyoaRecordService.getMaxClaimDate();
+        List<String> claimIds = dyoaHistoryMapper.getNewClaimRecordIds(max);
+        claimIds.stream().forEach(x->{
+            fetchClaimRecord(x);
+        });
+        //更新订单实收款金额
+        List<OrderFund> orderTotalAmount = financeClaimMapper.queryOrderTotalAmount();
+        orderFundService.updateBatchById(orderTotalAmount);
+
+        //分配认领金额到产品收款表
+        List<OrderFund> majorOrderFund = orderTotalAmount.stream().filter(x -> x.getBusinessType().equals(MAJOR_BUSINESS.name())).collect(Collectors.toList());
+        majorOrderFund.stream().forEach(x->{
+            List<ProductionFund> prods = productionFundService.list(new LambdaQueryWrapper<ProductionFund>()
+                    .eq(ProductionFund::getOrderFundId, x.getId()).select(ProductionFund::getProductionType));
+            if (CollectionUtil.isNotEmpty(prods)){
+                if (prods.size()>1){
+                    List<ProductionFund> noStatement = prods.stream().filter(p -> !p.getProductionType().equals(ProductionEnum.STATEMENT.name())).collect(Collectors.toList());
+                    if (noStatement.size()>1){
+                        productionFundService.update(new LambdaUpdateWrapper<ProductionFund>()
+                                .eq(ProductionFund::getOrderFundId,x.getId())
+                                .eq(ProductionFund::getProductionType,ProductionEnum.REPORT.name())
+                                .set(ProductionFund::getRealAmount,x.getRealAmount()));
+                    }else {
+                        productionFundService.update(new LambdaUpdateWrapper<ProductionFund>()
+                                .eq(ProductionFund::getOrderFundId,x.getId())
+                                .eq(ProductionFund::getProductionType,noStatement.get(0).getProductionType())
+                                .set(ProductionFund::getRealAmount,x.getRealAmount()));
+                    }
+                }else{
+                    productionFundService.update(new LambdaUpdateWrapper<ProductionFund>()
+                            .eq(ProductionFund::getOrderFundId,x.getId()).set(ProductionFund::getRealAmount,x.getRealAmount()));
+                }
+            }
+        });
 
     }
 
+    private void fetchClaimRecord(String id) {
+        try{
+            Map<String, Object> resultMap = dyoaHistoryMapper.getNewClaimRecord(id);
+            FinanceClaim financeClaim = new FinanceClaim();
+            Class<FinanceClaim> fClass = FinanceClaim.class;
+            String dyoaId = (String) resultMap.get("id");
+            for (Map.Entry<String, String> entry : REAL_AMOUNT_CLAIM_COLUM.entrySet()){
+                Object columValue = resultMap.get(entry.getKey());
+                if (columValue!=null){
+                    String mbsColum = entry.getValue();
+                    Field field = fClass.getDeclaredField(mbsColum);
+                    field.setAccessible(true);
+                    switch (mbsColum){
+                        case "realFundId":
+                            Long realAmountMbsId = findRealAmountMbsId((String) columValue);
+                            if (realAmountMbsId==null){
+                                return;
+                            }
+                            field.set(financeClaim, realAmountMbsId);break;
+                        case "orderFundId":
+                            Long orderFundMbsId = findOrderFundId((String) columValue);
+                            if (orderFundMbsId==null){
+                                return;
+                            }
+                            field.set(financeClaim, orderFundMbsId);break;
+                        case "claimUserId":
+                            field.set(financeClaim,getMbsUserId((String) columValue));break;
+                        case "claimAmount":
+                            field.set(financeClaim, BigDecimal.valueOf((Double) columValue));break;
+                        case "claimDatetime":
+                            field.set(financeClaim, DateUtils.dateToLocalDate((Date) columValue));break;
+                        default:
+                            field.set(financeClaim,columValue);
+                    }
+
+                }
+                Date createdDatetime = (Date) resultMap.get("createdDatetime");
+                financeClaim.setCreated(createdDatetime);
+                financeClaimService.save(financeClaim);
+                //插入同步记录表
+                Long mbsId = financeClaim.getId();
+                dyoaRecordService.insert(MainBusinessEnum.REAL_AMOUNT_CLAIM, mbsId, dyoaId,createdDatetime);
+            }
+        }catch (NoSuchFieldException e) {
+            throw new RuntimeException(e);
+        } catch (IllegalAccessException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+
+    private Long findRealAmountMbsId(String columValue) {
+        if (CollectionUtil.isEmpty(realAmounts)){
+            realAmounts = dyoaRecordService.list(new LambdaQueryWrapper<DyoaRecord>().select(DyoaRecord::getMbsId, DyoaRecord::getDyoaId)
+                    .eq(DyoaRecord::getMbsType, REAL_AMOUNT.name())).stream().collect(Collectors.toMap(DyoaRecord::getDyoaId, DyoaRecord::getMbsId));
+        }
+        return realAmounts.get(columValue);
+    }
+
     @Override
     public void fetchRealAmount() {
         Date max = dyoaRecordService.getMaxRealAmountCreatedTime();
@@ -414,7 +535,6 @@ public class DyoaHistoryServiceImpl implements IDyoaHistoryService{
             //插入同步记录表
             Long mbsId = realFund.getId();
             dyoaRecordService.insert(MainBusinessEnum.REAL_AMOUNT, mbsId, dyoaId,createdDatetime);
-
         }catch (NoSuchFieldException e) {
             throw new RuntimeException(e);
         } catch (IllegalAccessException e) {
@@ -459,7 +579,7 @@ public class DyoaHistoryServiceImpl implements IDyoaHistoryService{
                 switch (mbsColum){
                     case "purpose":
                     case "credentials":
-                        field.set(personal,toJsonString((String) columValue));break;
+                        field.set(personal,covertData((String) columValue,mbsColum));break;
                     case "clientManagerId":
                     case "outwardStaff":
                     case "inwardStaff":
@@ -471,9 +591,17 @@ public class DyoaHistoryServiceImpl implements IDyoaHistoryService{
                         field.set(personal, BigDecimal.valueOf((Integer) columValue));break;
                     case "clienteleSubId":
                     case "clienteleId":
-                    case "terminalClienteleId":
                         field.set(personal, getCompanyId((String) columValue));break;
+                    case "terminalClienteleId":
+                        String terminalType = (String) dyoaPersonalOrder.get("terminalType");
+                        if ("企业".equals(terminalType)){
+                            field.set(personal, getCompanyId((String) columValue));
+                        }else {
+                            field.set(personal, getCompanyLinkmanId((String) columValue));
+                        }
+                        break;
                     case "terminalClienteleContactId":
+                    case "clienteleContactId":
                         field.set(personal, getCompanyLinkmanId((String) columValue));break;
                     default:
                         field.set(personal,columValue);
@@ -490,6 +618,44 @@ public class DyoaHistoryServiceImpl implements IDyoaHistoryService{
         return personal;
     }
 
+    private static String covertData(String columValue, String mbsColum) {
+        List<String> list = Arrays.asList(columValue.split(","));
+        List<String> ret = new ArrayList<>();
+        if (mbsColum.equals("purpose")){
+            list.stream().forEach(x->{
+                if (x.equals("住宅")){
+                    ret.add("HOUSE");
+                }else if (x.equals("商业")){
+                    ret.add("BUSINESS");
+                }else if (x.equals("办公")){
+                    ret.add("OFFICE");
+                }else if (x.equals("工业")){
+                    ret.add("INDUSTRIAL");
+                }else if (x.equals("其他")){
+                    ret.add("OTHER");
+                }
+            });
+        }
+        if (mbsColum.equals("credentials")){
+            list.stream().forEach(x->{
+                if (x.equals("房产证")){
+                    ret.add("HOUSE_CERTIFICATE");
+                }else if (x.equals("国土证")){
+                    ret.add("LAND_CERTIFICATE");
+                }else if (x.equals("不动产权证")){
+                    ret.add("IMMOVABLE_CERTIFICATE");
+                }
+            });
+        }
+        return JSON.toJSONString(ret);
+    }
+
+    public static void main(String[] args) {
+        String credentials = covertData("房产证,国土证,不动产权证,租赁合同", "credentials");
+        System.out.println(credentials);
+    }
+
+
     private Long getCompanyId(String columValue) {
         List<CustomerCompany> list = customerCompanyService.list(new LambdaQueryWrapper<CustomerCompany>().eq(CustomerCompany::getName, columValue)
                 .select(BaseEntity::getId));
@@ -533,13 +699,12 @@ public class DyoaHistoryServiceImpl implements IDyoaHistoryService{
 
     public void doCreateMajorProduction(Double shouldAmount ,String id,Long majorId) throws NoSuchFieldException, IllegalAccessException {
         List<HisMajorTarget> majorProductions = dyoaHistoryMapper.queryMajorProduction(id);
+        //创建产品收款记录
         if (CollectionUtil.isNotEmpty(majorProductions)){
-
+            //创建订单收款记录
             OrderFund orderFund = orderFundService.getOne(new LambdaQueryWrapper<OrderFund>().eq(OrderFund::getBusinessType, MAJOR_BUSINESS.name())
                     .eq(OrderFund::getBusinessId, majorId).eq(OrderFund::getOrderId, majorProductions.get(0).getCode()));
-
             if (orderFund==null){
-                //创建订单收款记录
                 orderFund = new OrderFund();
                 orderFund.setBusinessId(majorId);
                 orderFund.setBusinessType(MAJOR_BUSINESS.name());
@@ -548,7 +713,6 @@ public class DyoaHistoryServiceImpl implements IDyoaHistoryService{
                 orderFund.setShouldAmount(BigDecimal.valueOf(shouldAmount));
                 orderFundService.save(orderFund);
             }
-
             for (HisMajorTarget production :majorProductions){
                 if (StrUtil.isNotBlank(production.getPId())){
                     MajorProduction majorProduction = new MajorProduction();
@@ -672,6 +836,7 @@ public class DyoaHistoryServiceImpl implements IDyoaHistoryService{
                     case "terminalClienteleId":
                         field.set(major, getCompanyId((String) columValue));break;
                     case "terminalClienteleContactId":
+                    case "clienteleContactId":
                         field.set(major, getCompanyLinkmanId((String) columValue));break;
                     default:
                         field.set(major,columValue);
@@ -724,6 +889,13 @@ public class DyoaHistoryServiceImpl implements IDyoaHistoryService{
         return JSON.toJSONString(userIds);
     }
 
+    private Long findOrderFundId(String columValue){
+        if (CollectionUtil.isEmpty(orderFundIds)){
+            orderFundIds = dyoaRecordMapper.selectOrderFundIdByDyoaOrderId().stream().collect(Collectors.toMap(DyoaRecord::getDyoaId,DyoaRecord::getMbsId));
+        }
+        return orderFundIds.get(columValue);
+    }
+
 //    private Long getMbsWorkFlows(String flowCode){
 //        if (CollectionUtil.isEmpty(workFlows)){
 //            List<WorkFlow> list = workFlowService.list(new LambdaQueryWrapper<WorkFlow>().select(BaseEntity::getId, WorkFlow::getCode));

+ 2 - 0
service/src/main/java/com/dayou/service/IDyoaRecordService.java

@@ -28,5 +28,7 @@ public interface IDyoaRecordService extends IService<DyoaRecord> {
         Date getMaxOrderTime();
 
         Date getMaxRealAmountCreatedTime();
+
+        Date getMaxClaimDate();
 }
 

+ 4 - 0
service/src/main/java/com/dayou/service/impl/DyoaRecordServiceImpl.java

@@ -70,5 +70,9 @@ public class DyoaRecordServiceImpl extends ServiceImpl<DyoaRecordMapper, DyoaRec
         return dyoaRecordMapper.getMaxRealAmountCreatedTime();
     }
 
+    @Override
+    public Date getMaxClaimDate() {
+        return dyoaRecordMapper.getMaxClaimDate();
+    }
 
 }