Commit aa408647 authored by licc's avatar licc

测试定时任务 2

parent b6f153c9
package cn.wisenergy.service.app; package cn.wisenergy.service.app;
import cn.wisenergy.common.utils.R; import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.OrderInfo;
import java.util.List;
/** /**
*@ Description: 月定时任务接口定义 *@ Description: 月定时任务接口定义
...@@ -13,11 +10,6 @@ import java.util.List; ...@@ -13,11 +10,6 @@ import java.util.List;
*/ */
public interface MonthTaskService { public interface MonthTaskService {
/**
* 订单返佣-月任务
* @return true or false
*/
R<Boolean> orderRebate();
/** /**
* 收益和业绩统计(月度肥料)-月任务 * 收益和业绩统计(月度肥料)-月任务
......
...@@ -70,8 +70,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo> ...@@ -70,8 +70,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
@XxlJob(value = "orderRebateDayTask") @XxlJob(value = "orderRebateDayTask")
@Override @Override
public R<Boolean> orderRebate() { public R<Boolean> orderRebate() {
log.info("测试执行定时任务,三分钟执行一次"); log.info("订单返佣接口定时-日任务");
//获取返佣订单 // //获取返佣订单
List<OrderInfo> list = orderMapper.getListBySuccessTime(new Date()); List<OrderInfo> list = orderMapper.getListBySuccessTime(new Date());
log.info("shop-mall[]AccountServiceImpl[]orderRebate[]input.param.list:{}", list.size()); log.info("shop-mall[]AccountServiceImpl[]orderRebate[]input.param.list:{}", list.size());
if (CollectionUtils.isEmpty(list)) { if (CollectionUtils.isEmpty(list)) {
...@@ -114,9 +114,11 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo> ...@@ -114,9 +114,11 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
return R.ok(accountInfo); return R.ok(accountInfo);
} }
@XxlJob(value = "monthManureDayTask")
@Override @Override
public R<Boolean> performanceCount() { public R<Boolean> performanceCount() {
//获取本月订单 //获取本月订单
log.info("月度肥料定时-日任务");
List<OrderInfo> list = orderMapper.getByCreateTime(new Date()); List<OrderInfo> list = orderMapper.getByCreateTime(new Date());
log.info("shop-mall[]AccountServiceImpl[]performanceCount[]input.param.list:{}", list.size()); log.info("shop-mall[]AccountServiceImpl[]performanceCount[]input.param.list:{}", list.size());
if (CollectionUtils.isEmpty(list)) { if (CollectionUtils.isEmpty(list)) {
...@@ -211,6 +213,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo> ...@@ -211,6 +213,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
return list; return list;
} }
@XxlJob(value = "growthAwardDayTask")
@Override @Override
public R<Boolean> progressPrizeCount() { public R<Boolean> progressPrizeCount() {
log.info("shop-mall[]AccountServiceImpl[]performanceCount[]input.method"); log.info("shop-mall[]AccountServiceImpl[]performanceCount[]input.method");
......
...@@ -8,19 +8,19 @@ import cn.wisenergy.model.enums.MemberPercentEnum; ...@@ -8,19 +8,19 @@ import cn.wisenergy.model.enums.MemberPercentEnum;
import cn.wisenergy.model.enums.TradeRecordEnum; import cn.wisenergy.model.enums.TradeRecordEnum;
import cn.wisenergy.model.enums.TradeStatusEnum; import cn.wisenergy.model.enums.TradeStatusEnum;
import cn.wisenergy.model.enums.UserLevelEnum; import cn.wisenergy.model.enums.UserLevelEnum;
import cn.wisenergy.model.vo.TeamPerformanceSortVo;
import cn.wisenergy.service.Manager.AccountManager; import cn.wisenergy.service.Manager.AccountManager;
import cn.wisenergy.service.Manager.PublicManager; import cn.wisenergy.service.Manager.PublicManager;
import cn.wisenergy.service.app.AccountService; import cn.wisenergy.service.app.AccountService;
import cn.wisenergy.service.app.MonthTaskService; import cn.wisenergy.service.app.MonthTaskService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.List;
/** /**
* @author 86187 * @author 86187
...@@ -70,17 +70,13 @@ public class MonthTaskServiceImpl implements MonthTaskService { ...@@ -70,17 +70,13 @@ public class MonthTaskServiceImpl implements MonthTaskService {
private static final Integer TWENTY = 20; private static final Integer TWENTY = 20;
@Override @XxlJob(value = "monthManureMonthTask")
public R<Boolean> orderRebate() {
return null;
}
@Override @Override
public R<Boolean> performanceCount() { public R<Boolean> performanceCount() {
//获取上月订单 //获取上月订单
Date lastMonth = DateUtil.getLastMonth(new Date()); Date lastMonth = DateUtil.getLastMonth(new Date());
List<OrderInfo> list = orderMapper.getByCreateTime(lastMonth); List<OrderInfo> list = orderMapper.getByCreateTime(lastMonth);
log.info("shop-mall[]AccountServiceImpl[]performanceCount[]input.param.list:{}", list.size()); log.info("shop-mall[]MonthTaskServiceImpl[]performanceCount[]input.param.list:{}", list.size());
if (CollectionUtils.isEmpty(list)) { if (CollectionUtils.isEmpty(list)) {
return R.ok(0, true); return R.ok(0, true);
} }
...@@ -165,11 +161,93 @@ public class MonthTaskServiceImpl implements MonthTaskService { ...@@ -165,11 +161,93 @@ public class MonthTaskServiceImpl implements MonthTaskService {
return R.ok(0, true); return R.ok(0, true);
} }
@XxlJob(value = "growthAwardMonthTask")
@Override @Override
public R<Boolean> progressPrizeCount() { public R<Boolean> progressPrizeCount() {
return null; log.info("shop-mall[]MonthTaskServiceImpl[]performanceCount[]input.method");
Date date = DateUtil.getLastMonth(new Date());
String lastMonth = DateUtil.convertDateToStr(date, PATTERN);
//1、判断上月是否是业绩开始的第一个月
List<TeamPerformance> teamPerformances = teamPerformanceMapper.getByBeforeTime(lastMonth);
//获取上月月所有人业绩总额
Double totalMoney = teamPerformanceMapper.countByTime(lastMonth);
double number = Math.floor(totalMoney / 3980 / 12);
//2、集合为空 是业绩开始的第一个月
if (CollectionUtils.isEmpty(teamPerformances)) {
if (number != 0) {
//获取上月业绩前20用户
List<TeamPerformance> list = teamPerformanceMapper.userTwenty(lastMonth);
if (CollectionUtils.isEmpty(list)) {
return R.ok(0, true);
}
//获取20名进步最大的月业绩和
Double twentyTotal = teamPerformanceMapper.countTwenty(lastMonth);
List<AccountInfo> accountInfoList = new ArrayList<>();
List<TradeRecord> tradeRecordList = new ArrayList<>();
for (TeamPerformance user : list) {
//获取最大进步奖 百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(user.getUserLevel(), 3);
//计算收益
double userTeamPerformance = user.getMonthTeamPerformance().doubleValue();
double percent = memberPercent.getPercent().doubleValue();
double income = number * 3980 * percent * userTeamPerformance / twentyTotal;
//获取账户信息
AccountInfo accountInfo = accountMapper.getByUserId(user.getUserId());
accountInfo.setEarningsMonth(new BigDecimal(income));
accountInfoList.add(accountInfo);
//添加交易流水记录
TradeRecord tradeRecord = new TradeRecord();
tradeRecord.setUserId(user.getUserId());
tradeRecord.setTradeType(TradeRecordEnum.PROGRESS_PRIZE.getCode());
tradeRecord.setTradeNo(null);
tradeRecord.setStatus(TradeStatusEnum.ALREADY_SETTLE_ACCOUNTS.getCode());
tradeRecordList.add(tradeRecord);
} }
//更新账户信息,添加交易流水记录
boolean bool = accountManager.updateAccountAddRecord(accountInfoList, tradeRecordList);
if (!bool) {
return R.ok(1, false);
}
}
return R.ok(0, true);
}
//3、集合不为空 不是业绩开始的第一个月
//获取用户列表
List<User> userList = usersMapper.findAll();
if (CollectionUtils.isEmpty(userList)) {
return R.ok(0, true);
}
//4计算每个用户本月的业绩增长率
List<TeamPerformanceSortVo> listVo = progressPrizeStatistics(userList);
//5、如果集合大于20 ,取前二十名,小于,取全部
if (listVo.size() >= TWENTY) {
//取排名前20的
listVo.subList(0, TWENTY);
//计算前20的总业绩
double total = listVo.stream().mapToDouble(TeamPerformanceSortVo::getMonthPerformance).sum();
totalPerformanceIncome(listVo, number, total);
return R.ok(0, true);
} else {
//计算用户数少于20的总业绩
double total = listVo.stream().mapToDouble(TeamPerformanceSortVo::getMonthPerformance).sum();
totalPerformanceIncome(listVo, number, total);
}
return R.ok(0, true);
}
@XxlJob(value = "mirrorImageMonthTask")
@Override @Override
public void mirrorImage() { public void mirrorImage() {
//1、把账户表account_info复制给表account_image CREATE TABLE table_2 SELECT * FROM table_1; //1、把账户表account_info复制给表account_image CREATE TABLE table_2 SELECT * FROM table_1;
...@@ -350,4 +428,105 @@ public class MonthTaskServiceImpl implements MonthTaskService { ...@@ -350,4 +428,105 @@ public class MonthTaskServiceImpl implements MonthTaskService {
monthManure.setManureAward(total); monthManure.setManureAward(total);
return monthManure; return monthManure;
} }
/**
* 统计每个用户本月业绩增长率
*
* @param userList 用户列表
* @return 每个用户本月业绩增长率
*/
private List<TeamPerformanceSortVo> progressPrizeStatistics(List<User> userList) {
Date date = new Date();
String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
//遍历 计算业绩增长率
List<TeamPerformanceSortVo> listVo = new ArrayList<>();
for (User user : userList) {
TeamPerformanceSortVo teamVo = new TeamPerformanceSortVo();
double growthRate;
//获取当月业绩
TeamPerformance teamPerformance = teamPerformanceMapper.getByUserIdAndTime(user.getUserId(), yearMonth);
//获取上月业绩
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.MONTH, -1);
Date lastDate = cal.getTime();
String lastMonthTime = DateUtil.convertDateToStr(lastDate, PATTERN);
TeamPerformance lastMonth = teamPerformanceMapper.getByUserIdAndTime(user.getUserId(), lastMonthTime);
if (null == teamPerformance || null == lastMonth) {
growthRate = 0.00;
} else {
double month = teamPerformance.getMonthTeamPerformance().doubleValue();
double last = lastMonth.getMonthTeamPerformance().doubleValue();
if (last >= month) {
growthRate = 0.00;
} else {
growthRate = (month - last) / month;
}
}
teamVo.setGrowthRate(growthRate);
double monthPerformance;
assert teamPerformance != null;
if (null == teamPerformance.getMonthTeamPerformance()) {
monthPerformance = 0.00;
} else {
monthPerformance = teamPerformance.getMonthTeamPerformance().doubleValue();
}
teamVo.setMonthPerformance(monthPerformance);
teamVo.setUserId(user.getUserId());
teamVo.setTeamPerformance(teamPerformance);
listVo.add(teamVo);
}
//对集合进行排序
listVo.sort(Comparator.comparing(TeamPerformanceSortVo::getGrowthRate).reversed());
return listVo;
}
/**
* 统计用户最大进步奖收益
*
* @param listVo 用户增长率列表
* @param number 个人业绩
* @param total 总业绩
*/
private void totalPerformanceIncome(List<TeamPerformanceSortVo> listVo, double number, double total) {
//要更新的账户列表
List<AccountInfo> updateAccountList = new ArrayList<>();
BigDecimal sum = new BigDecimal(0);
for (int i = 0; i < listVo.size(); i++) {
String userId = listVo.get(i).getTeamPerformance().getUserId();
Integer userLevel = listVo.get(i).getTeamPerformance().getUserLevel();
//获取最大进步奖 百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(userLevel, 3);
//计算收益
double userTeamPerformance = listVo.get(i).getTeamPerformance().getMonthTeamPerformance().doubleValue();
double percent = memberPercent.getPercent().doubleValue();
double income = number * 3980 * percent * userTeamPerformance / total;
//获取账户信息
AccountInfo accountInfo = accountMapper.getByUserId(userId);
BigDecimal bigDecimal;
if (i == listVo.size() - 1) {
bigDecimal = new BigDecimal(total).subtract(sum);
} else {
bigDecimal = accountInfo.getEarningsMonth().add(new BigDecimal(income));
sum = sum.add(new BigDecimal(income));
}
accountInfo.setEarningsMonth(bigDecimal);
updateAccountList.add(accountInfo);
}
//判断本月是否有最大进步奖数据 无,新增 有,修改或删除
Date date = new Date();
String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
List<ProgressPrize> prizes = progressPrizeMapper.getByYearMonth(yearMonth);
//修改或保存最大进步奖信息
accountManager.updateOrSavePrize(listVo, updateAccountList, prizes);
}
} }
...@@ -19,7 +19,7 @@ import java.util.List; ...@@ -19,7 +19,7 @@ import java.util.List;
/** /**
* @author 86187 * @author 86187
*/ */
@Api(tags = "账户管") @Api(tags = "账户管")
@RestController @RestController
@RequestMapping("/account") @RequestMapping("/account")
@Slf4j @Slf4j
......
...@@ -2,6 +2,7 @@ package cn.wisenergy.web.admin.controller.app; ...@@ -2,6 +2,7 @@ package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.service.app.AccountService; import cn.wisenergy.service.app.AccountService;
import cn.wisenergy.service.app.MonthTaskService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -20,11 +21,11 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -20,11 +21,11 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j @Slf4j
public class LastAccountController { public class LastAccountController {
@Autowired @Autowired
private AccountService accountService; private MonthTaskService monthTaskService;
// @ApiOperation(value = "复制表-结构和数据", notes = "复制表-结构和数据", httpMethod = "PUT") @ApiOperation(value = "复制表-结构和数据", notes = "复制表-结构和数据", httpMethod = "PUT")
// @PutMapping("/add") @PutMapping("/add")
// public void copyTable(){ public void copyTable() {
// accountService.mirrorImage(); monthTaskService.mirrorImage();
// } }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment