wucl пре 2 година
родитељ
комит
8809011303

+ 2 - 2
biz-base/src/main/java/com/dayou/controller/ItemBrokerageSequenceController.java

@@ -38,7 +38,7 @@ public class ItemBrokerageSequenceController extends BaseController {
     /**
     * 项目提成流水列表
     */
-    @DataPermission(postChild = false)
+    @DataPermission
     @GetMapping("")
     public RestResponse<Page<BrokerageSequenceVO>> page(BrokerageSequenceVO brokerageSequenceVO, Page page){
         Page<BrokerageSequenceVO> pages=itemBrokerageSequenceService.selectPage(page,brokerageSequenceVO);
@@ -48,7 +48,7 @@ public class ItemBrokerageSequenceController extends BaseController {
     /**
      * 项目提成结算抵扣
      */
-    @DataPermission(postChild = false)
+    @DataPermission
     @GetMapping("/deduction")
     public RestResponse<List<BrokerageSequenceVO>> deduction(BrokerageSequenceVO brokerageSequenceVO){
         List<BrokerageSequenceVO> list = itemBrokerageSequenceService.deduction(brokerageSequenceVO);

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

@@ -33,4 +33,8 @@ public interface ItemMapper extends CustomBaseMapper<Item> {
 
     List<Item> xSelectList(@Param("item")ItemStageVO item);
 
+    List<ItemBrokerageGeneral> getLastMonthItems(@Param("lastMonth23") LocalDate lastMonth23, @Param("userId") Long userId,@Param("marketerStatus") String marketerStatus );
+
+
+    List<ItemBrokerageGeneral> getLastMonthItemsInStatus(@Param("lastMonth23") LocalDate lastMonth23, @Param("userId") Long userId);
 }

+ 8 - 1
dao/src/main/resources/mapper/ItemBrokerageSequenceMapper.xml

@@ -67,7 +67,14 @@
     </select>
 
     <select id="deduction" parameterType="com.dayou.vo.BrokerageSequenceVO" resultType="com.dayou.vo.BrokerageSequenceVO">
-        select ibs.*,u.name as userName from item_brokerage_sequence ibs left join user u on u.id = ibs.user_id
+        SELECT
+        ibs.id,
+        ibs.created,
+        (case ibs.cate when 'DEFAULT_AHEAD' then
+        - ibs.brokerage_amount else ibs.brokerage_amount end) brokerageAmount,
+        ibs.embody,
+        ibs.cate,
+        u.NAME AS userName  from item_brokerage_sequence ibs left join user u on u.id = ibs.user_id
         where u.deleted = 0 and ibs.deleted = 0
         <if test="vo!=null and vo.userName!=null and vo.userName!='' ">
             and u.name like concat ('%',#{vo.userName},'%')

+ 29 - 0
dao/src/main/resources/mapper/ItemMapper.xml

@@ -189,4 +189,33 @@
         </if>
     </select>
 
+
+    <select id="getLastMonthItems" resultType="com.dayou.entity.ItemBrokerageGeneral">
+        select ibg.*
+        FROM
+        item i
+        left join item_brokerage_general ibg on ibg.item_id = i.id
+        WHERE
+        i.deleted = 0
+        and i.upload_date is not null
+        AND i.upload_date &gt;= #{lastMonth23}
+        AND i.upload_date &lt;= concat( date_format( LAST_DAY( now()), '%Y-%m-' ), '22' )
+        AND i.user_id = #{userId}
+        and ibg.marketer_status=#{marketerStatus}
+    </select>
+
+    <select id="getLastMonthItemsInStatus"  resultType="com.dayou.entity.ItemBrokerageGeneral">
+        select ibg.*
+        FROM
+            item i
+                left join item_brokerage_general ibg on ibg.item_id = i.id
+        WHERE
+            i.deleted = 0
+          and i.upload_date is not null
+          AND i.upload_date &gt;= #{lastMonth23}
+          AND i.upload_date &lt;= concat( date_format( LAST_DAY( now()), '%Y-%m-' ), '22' )
+          AND i.user_id = #{userId}
+          and ibg.marketer_status in ('TO_PREDICTING','NOT_PAYMENT')
+    </select>
+
 </mapper>

+ 29 - 6
service/src/main/java/com/dayou/brokerage/BrokerageCalculateSupport.java

@@ -109,15 +109,38 @@ public class BrokerageCalculateSupport implements BrokerageCalculateFactory,Brok
         try {
             @NotNull
             BigDecimal paymentTarget = brokerageDetailBo.getPaymentTarget();
-            BigDecimal avgMonthTarget = paymentTarget.divide(globalConfigCache.get(GlobalConfigEnum.Finance.MONTH_OF_YEAR.getCode()), 2, RoundingMode.HALF_UP);
-            int month = DateUtils.getMonth(new Date());
-            //当月应完成回款金额
-            BigDecimal brokerageTarget = avgMonthTarget.multiply(new BigDecimal(month));
-            return brokerageValidator.checkMarketerPredictBrokerage(brokerageDetailBo,brokerageTarget);
+            if (paymentTarget.compareTo(BigDecimal.ZERO)!=0){
+                BigDecimal currentPayment = brokerageDetailBo.getCurrentPayment();
+                BigDecimal avgMonthTarget = paymentTarget.divide(globalConfigCache.get(GlobalConfigEnum.Finance.MONTH_OF_YEAR.getCode()), 2, RoundingMode.HALF_UP);
+                int month = DateUtils.getMonth(new Date());
+                //当月应完成回款金额
+                BigDecimal brokerageTarget = avgMonthTarget.multiply(new BigDecimal(month));
+                return brokerageValidator.checkMarketerPredictBrokerage(currentPayment,brokerageTarget);
+            }
         } catch (ExecutionException e) {
             log.error("获取提成缓存数据失败");
-            return Boolean.FALSE;
         }
+        return Boolean.FALSE;
+    }
+
+    /**
+     * 市场人员预提校验
+     * @param paymentDone
+     * @param paymentTarget
+     * @return
+     */
+    public Boolean checkMarketerPredictBrokerage(BigDecimal paymentDone,BigDecimal paymentTarget){
+        try {
+            if (paymentTarget.compareTo(BigDecimal.ZERO)!=0){
+                BigDecimal avgMonthTarget = paymentTarget.divide(globalConfigCache.get(GlobalConfigEnum.Finance.MONTH_OF_YEAR.getCode()), 2, RoundingMode.HALF_UP);
+                int month = DateUtils.getMonth(new Date());
+                BigDecimal brokerageTarget = avgMonthTarget.multiply(new BigDecimal(month));
+                return brokerageValidator.checkMarketerPredictBrokerage(paymentDone,brokerageTarget);
+            }
+        } catch (ExecutionException e) {
+            log.error("获取提成缓存数据失败");
+        }
+        return Boolean.FALSE;
     }
 
     /**

+ 2 - 2
service/src/main/java/com/dayou/brokerage/validator/BrokerageValidator.java

@@ -27,8 +27,8 @@ import java.math.BigDecimal;
 public class BrokerageValidator {
 
     //校验客户经理对此单是否可以预提
-    public Boolean checkMarketerPredictBrokerage(BrokerageDetailBO brokerageDetailBo, BigDecimal brokerageTarget){
-        if (brokerageDetailBo.getCurrentPayment().compareTo(brokerageTarget)== -1){
+    public Boolean checkMarketerPredictBrokerage(BigDecimal brokerageCurrent, BigDecimal brokerageTarget){
+        if (brokerageCurrent.compareTo(brokerageTarget)== -1){
             log.info(ErrorCode.BROKERAGE_ITEM_STATE_ERROR2.getErrorMsg());
             return Boolean.FALSE;
         }

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

@@ -68,4 +68,6 @@ public interface IItemBrokerageGeneralService extends IService<ItemBrokerageGene
     void beforeToSettleMarketerBrokerage(Long paymentId);
 
     void toSettleMarketerBrokerage(Long paymentId);
+
+    void updateAheadStatus(Long userId);
 }

+ 66 - 2
service/src/main/java/com/dayou/service/impl/ItemBrokerageGeneralServiceImpl.java

@@ -19,6 +19,7 @@ import com.dayou.exception.ErrorCode;
 import com.dayou.mapper.*;
 import com.dayou.service.*;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.dayou.utils.DateUtils;
 import com.dayou.vo.BrokerageGeneralVO;
 import com.dayou.vo.ItemStageVO;
 import com.google.common.collect.Sets;
@@ -30,6 +31,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 
 import java.math.BigDecimal;
+import java.time.LocalDate;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -116,9 +118,9 @@ public class ItemBrokerageGeneralServiceImpl extends ServiceImpl<ItemBrokerageGe
         MarketerBrokerageCalculator calculator = (MarketerBrokerageCalculator) brokerageCalculateSupport.getCalculator(BrokerageRule.LAND_MARKETER_RULE);
             Long userId = bo.getUserId();
         UserTarget userTarget = getUserTarget(userId);
-        BigDecimal currentMonthPayment = marketStatService.currentYearPayment(userId);
+        BigDecimal currentYearPayment = marketStatService.currentYearPayment(userId);
         BigDecimal paymentTarget = new BigDecimal(userTarget.getPaymentTarget());
-        bo.setCurrentPayment(currentMonthPayment);
+        bo.setCurrentPayment(currentYearPayment);
         bo.setPaymentTarget(paymentTarget);
         Set<LeaderRatioBO> leaderRatioBO = userService.getLeaderRatioBO(userId).stream().filter(x->x.getRatio()!=null).collect(Collectors.toSet());
         bo = calculator.predictPersonalAmount(bo);
@@ -327,6 +329,7 @@ public class ItemBrokerageGeneralServiceImpl extends ServiceImpl<ItemBrokerageGe
 
     }
 
+    @Transactional
     @Override
     public void toSettleMarketerBrokerage(PaymentCollection payment) {
         ItemBrokerageGeneral general = this.getOne(new LambdaQueryWrapper<ItemBrokerageGeneral>().eq(ItemBrokerageGeneral::getItemId, payment.getItemId()).eq(BaseEntity::getDeleted, Boolean.FALSE));
@@ -335,6 +338,24 @@ public class ItemBrokerageGeneralServiceImpl extends ServiceImpl<ItemBrokerageGe
                 .eq(PaymentCollection::getItemId, payment.getItemId()).eq(BaseEntity::getDeleted, Boolean.FALSE));
         BigDecimal payDone = BigDecimal.valueOf(paymentList.stream().mapToDouble(PaymentCollection::getAmount).sum());
         brokerageCalculateSupport.checkItemBrokerageStatusOnMarketerPredict(general.getMarketerStatus());
+
+        //如果此笔回款满足当月回款目标,则需要将上月签订的合同的预提状态改为 可预提
+        //获取此笔回款项目的客户经理本年回款总额
+        Long userId = itemMapper.selectById(payment.getItemId()).getUserId();
+        BigDecimal currentYearPaymentAmount = marketStatService.currentYearPayment(userId);
+        BigDecimal userTarget = new BigDecimal(getUserTarget(userId).getPaymentTarget());
+        if (brokerageCalculateSupport.checkMarketerPredictBrokerage(currentYearPaymentAmount, userTarget)){
+            //则需要将上月签订的合同的预提状态改为 可预提
+            List<ItemBrokerageGeneral> lastMonthItemsBrokerages = itemMapper.getLastMonthItems(DateUtils.getLastMonth23(LocalDate.now().getYear(), LocalDate.now().getMonthValue() - 1),userId,BrokerageState.NOT_PAYMENT.getCode());
+            if (CollectionUtils.isNotEmpty(lastMonthItemsBrokerages)){
+                lastMonthItemsBrokerages.stream().forEach(
+                        i->{i.setMarketerAdvanceBrokerageAble(Boolean.TRUE);
+                            i.setMarketerStatus(BrokerageState.TO_PREDICTING.getCode());
+                        });
+                this.updateBatchById(lastMonthItemsBrokerages);
+                log.info("更新了客户经理预提状态待预提");
+            }
+        }
         if (item.getAmount()!=null && item.getAmount().compareTo(payDone)==0){
             general.setMarketerStatus(BrokerageState.NOT_SETTLE.getCode());
             this.updateById(general);
@@ -410,9 +431,29 @@ public class ItemBrokerageGeneralServiceImpl extends ServiceImpl<ItemBrokerageGe
         beforeToSettleMarketerBrokerage(payment);
     }
 
+    @Transactional
     @Override
     public void toSettleMarketerBrokerage(Long paymentId) {
         PaymentCollection payment = paymentCollectionMapper.getDeleted(paymentId);
+
+        //如果此笔回款满足当月回款目标,则需要将上月签订的合同的预提状态改为 可预提
+        //获取此笔回款项目的客户经理本年回款总额
+        Long userId = itemMapper.selectById(payment.getItemId()).getUserId();
+        BigDecimal currentYearPaymentAmount = marketStatService.currentYearPayment(userId);
+        BigDecimal userTarget = new BigDecimal(getUserTarget(userId).getPaymentTarget());
+        if (!brokerageCalculateSupport.checkMarketerPredictBrokerage(currentYearPaymentAmount, userTarget)){
+            //则需要将上月签订的合同的预提状态改为 不可预提
+            List<ItemBrokerageGeneral> lastMonthItemsBrokerages = itemMapper.getLastMonthItems(DateUtils.getLastMonth23(LocalDate.now().getYear(), LocalDate.now().getMonthValue() - 1),userId,BrokerageState.TO_PREDICTING.getCode());
+            if (CollectionUtils.isNotEmpty(lastMonthItemsBrokerages)){
+                lastMonthItemsBrokerages.stream().forEach(
+                        i->{i.setMarketerAdvanceBrokerageAble(Boolean.FALSE);
+                            i.setMarketerStatus(BrokerageState.NOT_PAYMENT.getCode());
+                        });
+                this.updateBatchById(lastMonthItemsBrokerages);
+                log.info("更新了客户经理预提状态为回款中");
+            }
+        }
+
         ItemBrokerageGeneral general = this.getOne(new LambdaQueryWrapper<ItemBrokerageGeneral>().eq(ItemBrokerageGeneral::getItemId, payment.getItemId()).eq(BaseEntity::getDeleted, Boolean.FALSE));
         if (general.getMarketerStatus().equals(BrokerageState.NOT_SETTLE.getCode())){
             general.setMarketerStatus(BrokerageState.NOT_PAYMENT.getCode());
@@ -420,6 +461,27 @@ public class ItemBrokerageGeneralServiceImpl extends ServiceImpl<ItemBrokerageGe
         }
     }
 
+    @Override
+    public void updateAheadStatus(Long userId) {
+        BigDecimal currentYearPaymentAmount = marketStatService.currentYearPayment(userId);
+        BigDecimal userTarget = new BigDecimal(getUserTarget(userId).getPaymentTarget());
+        List<ItemBrokerageGeneral> lastMonthItemsBrokerages = itemMapper.getLastMonthItemsInStatus(DateUtils.getLastMonth23(LocalDate.now().getYear(), LocalDate.now().getMonthValue() - 1),userId);
+        if (brokerageCalculateSupport.checkMarketerPredictBrokerage(currentYearPaymentAmount, userTarget) && CollectionUtils.isNotEmpty(lastMonthItemsBrokerages)){
+            lastMonthItemsBrokerages.stream().forEach(
+                    i->{i.setMarketerAdvanceBrokerageAble(Boolean.TRUE);
+                        i.setMarketerStatus(BrokerageState.TO_PREDICTING.getCode());
+                    });
+            this.updateBatchById(lastMonthItemsBrokerages);
+        }
+        if (!brokerageCalculateSupport.checkMarketerPredictBrokerage(currentYearPaymentAmount, userTarget) && CollectionUtils.isNotEmpty(lastMonthItemsBrokerages)){
+            lastMonthItemsBrokerages.stream().forEach(
+                    i->{i.setMarketerAdvanceBrokerageAble(Boolean.FALSE);
+                        i.setMarketerStatus(BrokerageState.NOT_PAYMENT.getCode());
+                    });
+            this.updateBatchById(lastMonthItemsBrokerages);
+        }
+    }
+
     /**
      * 获取客户经理年回款目标
      * @param userId
@@ -434,4 +496,6 @@ public class ItemBrokerageGeneralServiceImpl extends ServiceImpl<ItemBrokerageGe
         }
         return userTarget;
     }
+
+
 }

+ 4 - 2
service/src/main/java/com/dayou/service/impl/PaymentCollectionServiceImpl.java

@@ -1,5 +1,7 @@
 package com.dayou.service.impl;
 
+import com.dayou.brokerage.BrokerageCalculateSupport;
+import com.dayou.brokerage.MarketerBrokerageCalculator;
 import com.dayou.brokerage.annotation.DoBrokerage;
 import com.dayou.brokerage.constants.BrokerageBusiness;
 import com.dayou.brokerage.constants.BrokerageRule;
@@ -55,7 +57,7 @@ public class PaymentCollectionServiceImpl extends ServiceImpl<PaymentCollectionM
 
     @Autowired
     private IItemService iItemService;
-    
+
     @Override
     @SuppressWarnings("unchecked")
     public Page<PaymentCollectionVO> selectPage(Page page, PaymentCollectionVO paymentCollection){
@@ -84,7 +86,7 @@ public class PaymentCollectionServiceImpl extends ServiceImpl<PaymentCollectionM
         if (add.compareTo(totalAmount)==1){
             ErrorCode.throwBusinessException(ErrorCode.CUSTOM_ERROR,"新增回款金额已大于合同签订金额,请检查.");
         }
-        return  this.save(paymentCollection);
+        return this.save(paymentCollection);
     }
 
     @Override

+ 8 - 1
service/src/main/java/com/dayou/service/impl/UserTargetServiceImpl.java

@@ -2,6 +2,7 @@ package com.dayou.service.impl;
 
 import com.dayou.entity.UserTarget;
 import com.dayou.mapper.UserTargetMapper;
+import com.dayou.service.IItemBrokerageGeneralService;
 import com.dayou.service.IUserTargetService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.dayou.utils.LoginContext;
@@ -41,6 +42,10 @@ public class UserTargetServiceImpl extends ServiceImpl<UserTargetMapper, UserTar
 
     @Autowired
     private UserTargetMapper userTargetMapper;
+
+    @Autowired
+    private IItemBrokerageGeneralService iItemBrokerageGeneralService;
+
     @Override
     public UserTarget detail(Long id){
         return this.getById(id);
@@ -56,7 +61,9 @@ public class UserTargetServiceImpl extends ServiceImpl<UserTargetMapper, UserTar
         }
         ut.setSaleTarget(userTarget.getSaleTarget());
         ut.setPaymentTarget(userTarget.getPaymentTarget());
-        return  this.updateById(ut);
+        this.updateById(ut);
+        iItemBrokerageGeneralService.updateAheadStatus(userId);
+        return  Boolean.TRUE;
     }
 
     @Override