Browse Source

土规部实收款认领

wucl 6 tháng trước cách đây
mục cha
commit
a121d62066

+ 1 - 1
biz-base/src/main/java/com/dayou/controller/PaymentCollectionController.java

@@ -80,7 +80,7 @@ public class PaymentCollectionController extends BaseController {
      */
     @OperLog(title = "新增回款")
     @PostMapping("")
-    public RestResponse<Boolean> save(@RequestBody PaymentCollection paymentCollection) {
+    public synchronized RestResponse<Boolean> save(@RequestBody PaymentCollection paymentCollection) {
         Boolean ret = paymentCollectionService.add(paymentCollection);
         return RestResponse.data(ret);
     }

+ 1 - 1
dao/src/main/resources/mapper/FinanceClaimMapper.xml

@@ -28,7 +28,7 @@
         SELECT
             fc.id,
             fc.real_fund_id,
-            ( CASE orf.business_type WHEN 'MAJOR_BUSINESS' THEN '大中型业务' WHEN 'PERSONAL_BUSINESS' THEN '个贷业务' WHEN 'ASSET_BUSINESS' THEN '资产业务' ELSE '-' END ) AS businessType,
+            ( CASE orf.business_type WHEN 'MAJOR_BUSINESS' THEN '大中型业务' WHEN 'PERSONAL_BUSINESS' THEN '个贷业务' WHEN 'ASSET_BUSINESS' THEN '资产业务' WHEN 'ITEM_BUSINESS' THEN '土规业务' ELSE '-' END ) AS businessType,
             orf.should_amount,
             fc.claim_amount,
             u.NAME AS claimName,

+ 7 - 3
dao/src/main/resources/mapper/MajorProductionMapper.xml

@@ -706,7 +706,7 @@
             major_production mp
                 left join major m on m.id = mp.major_id
                 INNER JOIN ( SELECT id,business_id,should_amount FROM order_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) orf ON orf.business_id = m.id
-                LEFT JOIN ( SELECT id,business_id,production_no,real_amount,standard_amount,production_should_amount,production_type FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0) off  ON (off.business_id = m.id and off.production_no = mp.report_no and off.production_type = mp.production)
+                LEFT JOIN ( SELECT id,business_id,production_no,real_amount,standard_amount,production_should_amount,production_type FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 and production_should_amount>0 ) off  ON (off.business_id = m.id and off.production_no = mp.report_no and off.production_type = mp.production)
                 LEFT JOIN user u ON u.id = m.principal_id
                 LEFT JOIN user u1 ON u1.id = m.client_manager_id
                 LEFT JOIN customer_company cc ON cc.id = m.clientele_id
@@ -715,8 +715,12 @@
             m.deleted = 0
           AND	mp.deleted = 0
           AND m.client_manager_id = #{vo.clientManagerId}
-          AND IF(#{vo.hasRealAmount}, off.real_amount IS NOT NULL, off.real_amount IS NULL)
-            and off.production_should_amount>0
+        <if test="vo!=null and vo.hasRealAmount!=null and vo.hasRealAmount==true">
+            and off.real_amount IS NOT NULL
+        </if>
+        <if test="vo!=null and vo.hasRealAmount!=null and vo.hasRealAmount==false">
+            and off.real_amount IS NULL
+        </if>
         <if test="vo!=null and vo.name!=null and vo.name !=''">
             and mp.name like concat ('%',#{vo.name},'%')
         </if>

+ 4 - 1
dao/src/main/resources/mapper/PaymentCollectionMapper.xml

@@ -80,12 +80,15 @@
         u.name as client_manager,
         i.sign_date,
         i.amount,
+        off.id as orderFundId,
         ifnull(( SELECT sum( amount ) FROM payment_collection WHERE item_id = i.id AND deleted = 0 ), 0 ) AS payedAmount,
         (
         i.amount -(
         ifnull(( SELECT sum( amount ) FROM payment_collection WHERE item_id = i.id AND deleted = 0 ), 0 ))) AS NotPayedAmount
         FROM
-        item i left join user u on u.id = i.user_id
+        item i
+        left join (select id,business_id from order_fund where business_type='ITEM_BUSINESS' AND deleted = 0) off on off.business_id = i.id
+        left join user u on u.id = i.user_id
         WHERE
         i.deleted =0
         <if test="dto!=null and dto.itemName!=null and dto.itemName!=''">

+ 6 - 2
dao/src/main/resources/mapper/PersonalMapper.xml

@@ -503,10 +503,11 @@
         u2.NAME AS inwardStaffName,
         u3.NAME AS pricingStaffName,
         p.created,
-        p.created as xCreated
+        p.created as xCreated,
+        pt.productions
         FROM
         personal p
-        LEFT JOIN (select personal_id,acreage,price,amount,created from personal_target where deleted = 0) pt ON pt.personal_id = p.id
+        LEFT JOIN (select personal_id,acreage,price,amount,created,productions from personal_target where deleted = 0) pt ON pt.personal_id = p.id
         LEFT JOIN (
         SELECT
         f.business_id,
@@ -573,6 +574,9 @@
         <if test="personal!=null and personal.handlerName!=null and personal.handlerName!='' ">
             and u4.name like concat('%',#{personal.handlerName},'%')
         </if>
+        <if test="personal!=null and personal.productions!=null and personal.productions!='' ">
+            and pt.productions like concat('%',#{personal.productions},'%')
+        </if>
         order by p.created desc
     </select>
 

+ 13 - 0
domain/src/main/java/com/dayou/entity/PaymentCollection.java

@@ -1,4 +1,5 @@
 package com.dayou.entity;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.dayou.common.BaseEntity;
 import java.time.LocalDate;
 import lombok.Data;
@@ -47,5 +48,17 @@ public class PaymentCollection extends BaseEntity {
     @ExportCell(columnName = "回款日期")
     private LocalDate paymentDate;
 
+    /**
+     * 订单收款id
+     */
+    @TableField(exist = false)
+    private Long orderFundId;
+
+    /**
+     * 实收款id
+     */
+    @TableField(exist = false)
+    private Long realAmountId;
+
 
 }

+ 1 - 0
domain/src/main/java/com/dayou/entity/PersonalProduction.java

@@ -88,4 +88,5 @@ public class PersonalProduction extends BaseEntity {
      */
     private Boolean isOnline;
 
+
 }

+ 4 - 0
domain/src/main/java/com/dayou/entity/PersonalTarget.java

@@ -120,6 +120,10 @@ public class PersonalTarget extends BaseEntity {
      * 出入库二维码路经
      */
     private String qrCode;
+    /**
+     * 已出产品类型
+     */
+    private String productions;
 
     @TableField(exist = false)
     private String bailorA;

+ 5 - 0
domain/src/main/java/com/dayou/vo/ItemPaymentVO.java

@@ -25,4 +25,9 @@ public class ItemPaymentVO extends Item {
      * 未回款
      */
     private BigDecimal NotPayedAmount;
+
+    /**
+     * 订单收款id
+     */
+    private Long orderFundId;
 }

+ 5 - 0
domain/src/main/java/com/dayou/vo/PersonalVO.java

@@ -202,6 +202,11 @@ public class PersonalVO extends Personal {
     private LocalDate valueTiming;
 
     /**
+     * 已出产品
+     */
+    private String productions;
+
+    /**
      * 下单日期
      */
     private LocalDate xCreated;

+ 18 - 1
service/src/main/java/com/dayou/service/impl/ItemServiceImpl.java

@@ -8,6 +8,7 @@ import com.dayou.dto.ItemDTO;
 import com.dayou.dto.ItemStateUpdateDTO;
 import com.dayou.entity.Item;
 import com.dayou.entity.ItemUser;
+import com.dayou.entity.OrderFund;
 import com.dayou.enums.ItemStateEnum;
 import com.dayou.enums.UnitEnum;
 import com.dayou.exception.ErrorCode;
@@ -32,6 +33,7 @@ import java.util.stream.Collectors;
 
 import org.springframework.transaction.annotation.Transactional;
 
+import static com.dayou.enums.MainBusinessEnum.ITEM_BUSINESS;
 import static com.dayou.enums.OperationTypeEnum.*;
 
 /**
@@ -55,7 +57,7 @@ public class ItemServiceImpl extends ServiceImpl<ItemMapper, Item> implements II
     private IItemStageService itemStageService;
 
     @Autowired
-    private IResourceTransferService resourceTransferService;
+    private IOrderFundService orderFundService;
 
     @Override
     @SuppressWarnings("unchecked")
@@ -89,6 +91,14 @@ public class ItemServiceImpl extends ServiceImpl<ItemMapper, Item> implements II
             itemDTO.setOaNo(itemDTO.getBusinessNo());
         }
         this.save(itemDTO);
+        //创建订单收款记录
+        OrderFund orderFund = new OrderFund();
+        orderFund.setShouldAmount(itemDTO.getAmount());
+        orderFund.setOrderName(itemDTO.getName());
+        orderFund.setOrderId(itemDTO.getBusinessNo());
+        orderFund.setBusinessId(itemDTO.getId());
+        orderFund.setBusinessType(ITEM_BUSINESS.name());
+        orderFundService.add(orderFund);
         Set<Long> userIds = itemDTO.getUserIds();
         if (CollectionUtils.isNotEmpty(userIds)){
             Set<ItemUser> itemUsers = userIds.stream().map(x -> {
@@ -109,6 +119,13 @@ public class ItemServiceImpl extends ServiceImpl<ItemMapper, Item> implements II
         if (itemDTO.getId()==null){
             ErrorCode.throwBusinessException(ErrorCode.PARAM_ERROR);
         }
+        //更新订单 应收款表
+        OrderFund orderFund = orderFundService.getOne(new LambdaQueryWrapper<OrderFund>().eq(OrderFund::getBusinessId, itemDTO.getId())
+                .eq(OrderFund::getBusinessType, ITEM_BUSINESS.name()));
+        if (orderFund != null){
+            orderFund.setShouldAmount(itemDTO.getAmount());
+            orderFundService.updateById(orderFund);
+        }
         this.updateById(itemDTO);
         Set<Long> userIds = itemDTO.getUserIds();
         iItemUserService.remove(new LambdaQueryWrapper<ItemUser>().eq(ItemUser::getItemId,itemDTO.getId()));

+ 49 - 18
service/src/main/java/com/dayou/service/impl/PaymentCollectionServiceImpl.java

@@ -8,15 +8,14 @@ import com.dayou.brokerage.constants.BrokerageRule;
 import com.dayou.common.BaseEntity;
 import com.dayou.dto.PaymentDetailDTO;
 import com.dayou.dto.PaymentExportDTO;
-import com.dayou.entity.PaymentCollection;
-import com.dayou.entity.UserTarget;
+import com.dayou.entity.*;
 import com.dayou.enums.OperationTypeEnum;
 import com.dayou.exception.ErrorCode;
 import com.dayou.mapper.PaymentCollectionMapper;
-import com.dayou.service.IItemService;
-import com.dayou.service.IPaymentCollectionService;
+import com.dayou.service.*;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.dayou.utils.DateUtils;
+import com.dayou.utils.LoginContext;
 import com.dayou.vo.ItemPaymentVO;
 import com.dayou.vo.PaymentCollectionVO;
 import com.sun.org.apache.xpath.internal.operations.Bool;
@@ -46,6 +45,8 @@ import java.util.stream.Collectors;
 import org.springframework.transaction.annotation.Transactional;
 import com.dayou.enums.BatchTaskTypeEnum;
 
+import static com.dayou.enums.MainBusinessEnum.ITEM_BUSINESS;
+
 /**
  * <p>
  * 回款记录 服务实现类
@@ -63,6 +64,15 @@ public class PaymentCollectionServiceImpl extends ServiceImpl<PaymentCollectionM
     @Autowired
     private IItemService iItemService;
 
+    @Autowired
+    private IFinanceRealFundService financeRealFundService;
+
+    @Autowired
+    private IOrderFundService orderFundService;
+
+    @Autowired
+    private IFinanceClaimService financeClaimService;
+
     @Override
     @SuppressWarnings("unchecked")
     public Page<PaymentCollectionVO> selectPage(Page page, PaymentCollectionVO paymentCollection){
@@ -90,29 +100,50 @@ public class PaymentCollectionServiceImpl extends ServiceImpl<PaymentCollectionM
     }
 
     @DoBrokerage(operation = OperationTypeEnum.SETTLE,rule = BrokerageRule.LAND_MARKETER_RULE)
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public Boolean add(PaymentCollection paymentCollection){
         Double amount = paymentCollection.getAmount();
+        //检查实收款余额
+        Long realAmountId = paymentCollection.getRealAmountId();
+        BigDecimal notClaimAmount = financeRealFundService.getNotClaimAmount(realAmountId);
+        if (notClaimAmount.compareTo(BigDecimal.valueOf(amount)) < 0){
+            ErrorCode.throwBusinessException(ErrorCode.CUSTOM_ERROR,"抱歉!实收款金额小于认领金额");
+        }
+        //检查是否有订单收款记录
+        Item item = iItemService.getById(paymentCollection.getItemId());
+        Long orderFundId = paymentCollection.getOrderFundId();
+        if (orderFundId ==null){
+            //创建订单收款记录
+            OrderFund orderFund = new OrderFund();
+            orderFund.setShouldAmount(item.getAmount());
+            orderFund.setOrderName(item.getName());
+            orderFund.setOrderId(item.getBusinessNo());
+            orderFund.setBusinessId(item.getId());
+            orderFund.setBusinessType(ITEM_BUSINESS.name());
+            orderFundService.add(orderFund);
+            orderFundId = orderFund.getId();
+        }
         if (amount==null || amount<0){
             ErrorCode.throwBusinessException(ErrorCode.CUSTOM_ERROR,"抱歉!回款金额不能小于0");
         }
-        BigDecimal totalAmount = iItemService.getById(paymentCollection.getItemId()).getAmount();
+        BigDecimal totalAmount = item.getAmount();
         if (totalAmount==null){
             ErrorCode.throwBusinessException(ErrorCode.CUSTOM_ERROR,"抱歉!该项目合同金额未填写,请先完善合同金额再操作。");
         }
-        List<Double> doneAmount = this.list(new LambdaQueryWrapper<PaymentCollection>()
-                .select(PaymentCollection::getAmount)
-                .eq(PaymentCollection::getItemId, paymentCollection.getItemId())
-                .eq(BaseEntity::getDeleted, Boolean.FALSE)).stream().map(PaymentCollection::getAmount).collect(Collectors.toList());
-
-
-        BigDecimal sum = BigDecimal.valueOf(doneAmount.stream().reduce(0D, Double::sum));
-
-        BigDecimal payment = BigDecimal.valueOf(amount);
-        BigDecimal add = sum.add(payment);
-        if (add.compareTo(totalAmount)==1){
-            ErrorCode.throwBusinessException(ErrorCode.CUSTOM_ERROR,"新增回款金额已大于合同签订金额,请检查.");
-        }
+        //创建认领记录流水表
+        FinanceClaim financeClaim = new FinanceClaim();
+        financeClaim.setRealFundId(realAmountId);
+        financeClaim.setClaimUserId(LoginContext.getCurrentUserId());
+        financeClaim.setOrderFundId(orderFundId);
+        financeClaim.setClaimAmount(BigDecimal.valueOf(amount));
+        financeClaim.setClaimDatetime(DateUtils.localDateToDate(paymentCollection.getPaymentDate()));
+        financeClaimService.save(financeClaim);
+
+        //更新订单收款表实收款信息
+        BigDecimal totalClaimAmountByOrderFundId = financeClaimService.getTotalClaimAmountByOrderFundId(orderFundId);
+        orderFundService.update(new LambdaUpdateWrapper<OrderFund>()
+                .eq(OrderFund::getId, orderFundId).set(OrderFund::getRealAmount,totalClaimAmountByOrderFundId));
         return this.save(paymentCollection);
     }
 

+ 22 - 2
service/src/main/java/com/dayou/service/impl/PersonalProductionServiceImpl.java

@@ -2,6 +2,8 @@ package com.dayou.service.impl;
 
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.dayou.common.BaseEntity;
@@ -569,16 +571,22 @@ public class PersonalProductionServiceImpl extends ServiceImpl<PersonalProductio
     private Boolean createPro(Long targetId,NameUrlDTO nameUrlDTO,Integer tag,Boolean isOnline){
         PersonalProduction pp = null;
         String productionType = null;
+        String productionTypeName = null;
+        PersonalTarget target = personalTargetService.getOne(new LambdaQueryWrapper<PersonalTarget>().eq(PersonalTarget::getId,targetId).select(PersonalTarget::getProductions,BaseEntity::getId));
         if (tag ==1){
             productionType = ProductionEnum.STATEMENT.name();
+            productionTypeName = ProductionEnum.STATEMENT.getMsg();
         }
         else if (tag ==2){
             productionType = ProductionEnum.TECHNIC.name();
+            productionTypeName = ProductionEnum.TECHNIC.getMsg();
         }
         else if (tag ==3){
             productionType = ProductionEnum.FINAL.name();
+            productionTypeName = ProductionEnum.FINAL.getMsg();
         }else if (tag ==4){
             productionType = ProductionEnum.LETTER.name();
+            productionTypeName = ProductionEnum.LETTER.getMsg();
         }
         else {
             return Boolean.FALSE;
@@ -593,14 +601,26 @@ public class PersonalProductionServiceImpl extends ServiceImpl<PersonalProductio
             personalProduction.setProduction(productionType);
             personalProduction.setUserId(LoginContext.getCurrentUserId());
             personalProduction.setIsOnline(isOnline);
-            return this.add(personalProduction);
+            this.add(personalProduction);
         }else {
             if (nameUrlDTO!=null){
                 pp.setFilePath(JSON.toJSONString(nameUrlDTO));
             }
             pp.setModified(DateUtils.getNowDate());
-            return this.update(pp);
+            this.update(pp);
         }
+
+        if (target!=null){
+            String productions = target.getProductions();
+            if (StrUtil.isBlank(productions)){
+                productions = productionTypeName;
+            }else {
+                productions += ","+productionTypeName;
+            }
+            personalTargetService.update(new LambdaUpdateWrapper<PersonalTarget>()
+                    .set(PersonalTarget::getProductions, productions).eq(BaseEntity::getId,targetId));
+        }
+        return Boolean.TRUE;
     }