|
|
@@ -0,0 +1,87 @@
|
|
|
+package org.springblade.client.scheduled;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springblade.client.corps.service.IBasicCorpsProfitChangeService;
|
|
|
+import org.springblade.client.corps.service.ICorpsDescService;
|
|
|
+import org.springblade.client.entity.BasicCorpsProfitChange;
|
|
|
+import org.springblade.client.entity.CorpsDesc;
|
|
|
+import org.springblade.client.entity.Message;
|
|
|
+import org.springblade.client.feign.IMessageClient;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.purchase.sales.entity.Order;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 定时任务-客户每月返利-每月1自动计算
|
|
|
+ * */
|
|
|
+@Component
|
|
|
+@Configuration
|
|
|
+@EnableScheduling
|
|
|
+@Slf4j
|
|
|
+@AllArgsConstructor
|
|
|
+public class CorpsProfitTimer
|
|
|
+{
|
|
|
+ private final ICorpsDescService corpsDescService;
|
|
|
+
|
|
|
+ private final IBasicCorpsProfitChangeService basicCorpsProfitChangeService;
|
|
|
+
|
|
|
+ private final IMessageClient messageClient;
|
|
|
+
|
|
|
+ //每月1号凌晨 开始检查,累计计算,目前只统计租户681169的返利情况
|
|
|
+ @Scheduled(cron="0 0 0 1 * ?")
|
|
|
+ public void creditDateCheck() throws ParseException
|
|
|
+ {
|
|
|
+ LambdaQueryWrapper<CorpsDesc> corpsDescLambdaQueryWrapper=new LambdaQueryWrapper<>();
|
|
|
+ corpsDescLambdaQueryWrapper
|
|
|
+ .eq(CorpsDesc::getIsDeleted,0)
|
|
|
+ .eq(CorpsDesc::getTenantId,"681169");
|
|
|
+ List<CorpsDesc> corpsDescList = corpsDescService.list(corpsDescLambdaQueryWrapper);
|
|
|
+ if(CollectionUtils.isNotEmpty(corpsDescList))
|
|
|
+ {
|
|
|
+ List<CorpsDesc> descList = corpsDescList.stream().filter(e -> e.getMonthProfit() != null).collect(Collectors.toList());
|
|
|
+ if(CollectionUtils.isNotEmpty(descList))
|
|
|
+ {
|
|
|
+ log.info("=================开始处理返利================");
|
|
|
+ descList.forEach(e->{
|
|
|
+ //增加客户的总返利 和 可用返利,本月返利归零
|
|
|
+ BigDecimal monthProfit = e.getMonthProfit();
|
|
|
+ e.setProfitReturn(e.getProfitReturn().add(monthProfit==null?BigDecimal.ZERO:monthProfit));
|
|
|
+ e.setSurplusProfit(e.getSurplusProfit().add(monthProfit==null?BigDecimal.ZERO:monthProfit));
|
|
|
+ e.setMonthProfit(BigDecimal.ZERO);
|
|
|
+ corpsDescService.updateById(e);
|
|
|
+ //增加返利变动记录
|
|
|
+ BasicCorpsProfitChange basicCorpsProfitChange=new BasicCorpsProfitChange();
|
|
|
+ basicCorpsProfitChange.setOrderId(-1L);
|
|
|
+ basicCorpsProfitChange.setOrderNo("定时任务增加返利");
|
|
|
+ basicCorpsProfitChange.setChangeProfitReturn(monthProfit==null?BigDecimal.ZERO:monthProfit);
|
|
|
+ basicCorpsProfitChange.setChangeSurplusProfit(monthProfit==null?BigDecimal.ZERO:monthProfit);
|
|
|
+ basicCorpsProfitChange.setChangeMonthProfit(monthProfit.negate());
|
|
|
+ basicCorpsProfitChangeService.save(basicCorpsProfitChange);
|
|
|
+ });
|
|
|
+ log.info("=================处理返利结束================");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|