Commit 8da9308c authored by licc's avatar licc

代码优化2

parent e47f419e
......@@ -4,6 +4,9 @@ import cn.wisenergy.model.app.ProgressPrize;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
/**
* @author 86187
*/
......@@ -14,4 +17,12 @@ public interface ProgressPrizeMapper extends BaseMapper<ProgressPrize> {
int edit(ProgressPrize progressPrize);
int delById(@Param("id") Integer id);
/**
* 根据 年月 获取月的最大进步奖用户列表
*
* @param yearMonth 年月
* @return 最大进步奖用户列表
*/
List<ProgressPrize> getByYearMonth(@Param("yearMonth") String yearMonth);
}
......@@ -25,7 +25,7 @@ public interface TeamPerformanceMapper extends BaseMapper<TeamPerformance> {
* @param yearMonth 时间
* @return 用户月业绩
*/
TeamPerformance getByUserIdAndTime(@Param("userId") String userId, @Param("yearMonth") Date yearMonth);
TeamPerformance getByUserIdAndTime(@Param("userId") String userId, @Param("yearMonth") String yearMonth);
/**
* 统计 等级月业绩和
......@@ -34,7 +34,7 @@ public interface TeamPerformanceMapper extends BaseMapper<TeamPerformance> {
* @param yearMonth 年月
* @return 等级总金额
*/
Double countTeamMoney(@Param("userLevel") Integer userLevel, @Param("yearMonth") Date yearMonth);
Double countTeamMoney(@Param("userLevel") Integer userLevel, @Param("yearMonth") String yearMonth);
/**
* 获取时间前的 月业绩列表
......@@ -42,7 +42,7 @@ public interface TeamPerformanceMapper extends BaseMapper<TeamPerformance> {
* @param yearMonth 时间
* @return 月业绩列表
*/
List<TeamPerformance> getByBeforeTime(@Param("yearMonth") Date yearMonth);
List<TeamPerformance> getByBeforeTime(@Param("yearMonth") String yearMonth);
/**
* 根据时间统计 所有用户业绩和
......@@ -50,14 +50,14 @@ public interface TeamPerformanceMapper extends BaseMapper<TeamPerformance> {
* @param yearMonth 时间
* @return 所有用户业绩和
*/
Double countByTime(@Param("yearMonth") Date yearMonth);
Double countByTime(@Param("yearMonth") String yearMonth);
/**
* 月业绩排名前20人 业绩和
* @param yearMonth 时间
* @return 业绩和
*/
Double countTwenty(@Param("yearMonth") Date yearMonth);
Double countTwenty(@Param("yearMonth") String yearMonth);
List<TeamPerformance> userTwenty(@Param("yearMonth") Date yearMonth);
List<TeamPerformance> userTwenty(@Param("yearMonth") String yearMonth);
}
......@@ -12,7 +12,7 @@
</resultMap>
<sql id="table">
month_award
progress_prize
</sql>
<sql id="cols_all">
......@@ -72,4 +72,18 @@
where id = #{id}
</delete>
<select id="getByYearMonth" resultType="cn.wisenergy.model.app.ProgressPrize">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
<if test="yearMonth != null">
AND(
YEAR(year_month) = YEAR(#{yearMonth})
AND MONTH(year_month) = MONTH(#{yearMonth}))
</if>
</where>
</select>
</mapper>
\ No newline at end of file
......@@ -40,7 +40,7 @@ public class AccountInfo implements Serializable {
* 年月
*/
@ApiModelProperty(name = "yearMonth", value = "年月")
private Date yearMonth;
private String yearMonth;
/**
......
......@@ -29,7 +29,7 @@ public class MonthAward implements Serializable {
* 年月
*/
@ApiModelProperty(name = "yearMonth", value = "年月")
private Date yearMonth;
private String yearMonth;
/**
* 本月月度肥料总额
......
......@@ -8,10 +8,10 @@ import java.math.BigDecimal;
import java.util.Date;
/**
*@ Description: 每月进步奖实体类
*@ Author : 86187
*@ Date : 2021/3/1 9:31
* @author 86187
* @ Description: 每月进步奖实体类
* @ Author : 86187
* @ Date : 2021/3/1 9:31
*/
@Data
public class ProgressPrize implements Serializable {
......@@ -20,43 +20,43 @@ public class ProgressPrize implements Serializable {
/**
* 主键id
*/
@ApiModelProperty(value = "主键id",name = "id")
@ApiModelProperty(value = "主键id", name = "id")
private Integer id;
/**
* 用户id
*/
@ApiModelProperty(value = "用户id",name = "userId")
@ApiModelProperty(value = "用户id", name = "userId")
private String userId;
/**
* 年月
*/
@ApiModelProperty(value = "年月",name = "yearMonth")
private Date yearMonth;
@ApiModelProperty(value = "年月", name = "yearMonth")
private String yearMonth;
/**
* 本月增长率
*/
@ApiModelProperty(value = "本月增长率",name = "growthRate")
private BigDecimal growthRate;
@ApiModelProperty(value = "本月增长率", name = "growthRate")
private Double growthRate;
/**
* 进步奖奖金
*/
@ApiModelProperty(value = "进步奖奖金",name = "awardMoney")
private BigDecimal awardMoney;
@ApiModelProperty(value = "进步奖奖金", name = "awardMoney")
private Double awardMoney;
/**
* 创建时间
*/
@ApiModelProperty(value = "创建时间",name = "createTime")
@ApiModelProperty(value = "创建时间", name = "createTime")
private Date createTime;
/**
* 更新时间
*/
@ApiModelProperty(value = "更新时间",name = "updateTime")
@ApiModelProperty(value = "更新时间", name = "updateTime")
private Date updateTime;
}
......@@ -41,7 +41,7 @@ public class TeamPerformance implements Serializable {
* 年-月
*/
@ApiModelProperty(value = "年-月", name = "yearMonth")
private Date yearMonth;
private String yearMonth;
/**
* 本月团队业绩
......
......@@ -20,7 +20,9 @@ public enum TradeRecordEnum {
CULTIVATING_PRIZE(5, "培育奖"),
SALARY_REWARD(6, "工资奖励");
SALARY_REWARD(6, "工资奖励"),
PROGRESS_PRIZE(7, "最大进步奖");
private Integer code;
private String desc;
......
......@@ -8,9 +8,23 @@ import lombok.Data;
*/
@Data
public class TeamPerformanceSortVo {
/**
* 增长率
*/
private Double growthRate;
/**
* 用户id
*/
private String userId;
/**
* 月团队业绩
*/
private Double monthPerformance;
/**
* 月团队业绩 类
*/
private TeamPerformance teamPerformance;
}
package cn.wisenergy.service.Manager;
import cn.wisenergy.mapper.AccountMapper;
import cn.wisenergy.mapper.OrderMapper;
import cn.wisenergy.mapper.TeamPerformanceMapper;
import cn.wisenergy.mapper.TradeRecordMapper;
import cn.wisenergy.common.utils.DateUtil;
import cn.wisenergy.mapper.*;
import cn.wisenergy.model.app.*;
import cn.wisenergy.model.enums.RebateStatusEnum;
import cn.wisenergy.model.enums.TradeRecordEnum;
import cn.wisenergy.model.vo.TeamPerformanceSortVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
......@@ -37,6 +39,15 @@ public class AccountManager {
@Autowired
private TeamPerformanceMapper teamPerformanceMapper;
@Autowired
private ProgressPrizeMapper progressPrizeMapper;
@Autowired
private TradeRecordMapper tradeRecordMapper;
private static final String PATTERN = "yyyy-MM";
/**
* 保存用户佣金
*
......@@ -78,4 +89,26 @@ public class AccountManager {
teamPerformanceMapper.updateById(teamPerformance);
}
}
@Transactional(rollbackFor = Exception.class)
public void updateOrSavePrize(List<TeamPerformanceSortVo> listVo, List<AccountInfo> accountInfos, List<ProgressPrize> prizes) {
Date date = new Date();
String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
//判断 prizes 是否为空集合,是新增
//新增
if (CollectionUtils.isEmpty(prizes)) {
for (TeamPerformanceSortVo sortVo : listVo) {
String userId = sortVo.getTeamPerformance().getUserId();
ProgressPrize progressPrize = new ProgressPrize();
progressPrize.setUserId(userId);
progressPrize.setGrowthRate(sortVo.getGrowthRate());
progressPrize.setAwardMoney(sortVo.getMonthPerformance());
progressPrize.setYearMonth(yearMonth);
progressPrizeMapper.add(progressPrize);
}
} else {
}
}
}
package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.utils.DateUtil;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.*;
import cn.wisenergy.model.app.*;
......@@ -50,7 +51,10 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
@Autowired
private TeamPerformanceMapper teamPerformanceMapper;
private static final String PATTERN = "yyyy-mm";
@Autowired
private ProgressPrizeMapper progressPrizeMapper;
private static final String PATTERN = "yyyy-MM";
@Override
public R<Boolean> orderRebate(List<OrderInfo> list) {
......@@ -102,6 +106,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
return R.ok(0, true);
}
Date date = new Date();
String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
//计算当月所有订单成交额
BigDecimal totalMoney = new BigDecimal(0);
for (OrderInfo orderInfo : list) {
......@@ -126,7 +133,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
List<TeamPerformance> teamPerformances = new ArrayList<>();
//获取团队业绩信息
TeamPerformance teamPerformance = teamPerformanceMapper.getByUserIdAndTime(user.getUserId(), new Date());
TeamPerformance teamPerformance = teamPerformanceMapper.getByUserIdAndTime(user.getUserId(), yearMonth);
if (null == teamPerformance) {
continue;
}
......@@ -144,7 +151,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
for (User userInfo : userList) {
//3、统计当前用户上级月度绩效
TeamPerformance team = teamPerformanceMapper.getByUserIdAndTime(userInfo.getUserId(), new Date());
TeamPerformance team = teamPerformanceMapper.getByUserIdAndTime(userInfo.getUserId(), yearMonth);
if (null == team) {
continue;
}
......@@ -188,24 +195,26 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
@Override
public R<Boolean> progressPrizeCount() {
log.info("shop-mall[]AccountServiceImpl[]performanceCount[]input.method");
Date date = new Date();
String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
//1、判断当前月是否是业绩开始的第一个月
List<TeamPerformance> teamPerformances = teamPerformanceMapper.getByBeforeTime(new Date());
List<TeamPerformance> teamPerformances = teamPerformanceMapper.getByBeforeTime(yearMonth);
//获取当月所有人业绩总额
Double totalMoney = teamPerformanceMapper.countByTime(new Date());
Double totalMoney = teamPerformanceMapper.countByTime(yearMonth);
double number = Math.floor(totalMoney / 3980 / 12);
//2、集合为空 是业绩开始的第一个月
if (CollectionUtils.isEmpty(teamPerformances)) {
if (number != 0) {
//获取月业绩前20用户
List<TeamPerformance> list = teamPerformanceMapper.userTwenty(new Date());
List<TeamPerformance> list = teamPerformanceMapper.userTwenty(yearMonth);
if (CollectionUtils.isEmpty(list)) {
return R.ok(0, true);
}
//获取20名进步最大的月业绩和
Double twentyTotal = teamPerformanceMapper.countTwenty(new Date());
Double twentyTotal = teamPerformanceMapper.countTwenty(yearMonth);
for (TeamPerformance user : list) {
//获取最大进步奖 百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(user.getUserLevel(), 3);
......@@ -222,7 +231,6 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
//更新用户账户表
accountMapper.updateById(accountInfo);
}
}
return R.ok(0, true);
......@@ -235,92 +243,22 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
return R.ok(0, true);
}
//遍历 计算业绩增长率
List<TeamPerformanceSortVo> listVo = new ArrayList<>();
for (User user : userList) {
TeamPerformanceSortVo teamVo = new TeamPerformanceSortVo();
double growthRate;
//获取当月业绩
TeamPerformance teamPerformance = teamPerformanceMapper.getByUserIdAndTime(user.getUserId(), new Date());
//获取上月业绩
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.MONTH, -1);
Date date = cal.getTime();
TeamPerformance lastMonth = teamPerformanceMapper.getByUserIdAndTime(user.getUserId(), date);
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;
if (null == teamPerformance.getMonthTeamPerformance()) {
monthPerformance = 0.00;
} else {
monthPerformance = teamPerformance.getMonthTeamPerformance().doubleValue();
}
teamVo.setMonthPerformance(monthPerformance);
teamVo.setTeamPerformance(teamPerformance);
listVo.add(teamVo);
}
//对集合进行排序
listVo.sort(Comparator.comparing(TeamPerformanceSortVo::getGrowthRate).reversed());
//4计算每个用户本月的业绩增长率
List<TeamPerformanceSortVo> listVo = progressPrizeStatistics(userList);
//计算前20的总业绩
double total = listVo.stream().mapToDouble(TeamPerformanceSortVo::getMonthPerformance).sum();
//5、如果集合大于20 ,取前二十名,小于,取全部
if (listVo.size() >= 20) {
//取排名前20的
listVo.subList(0, 20);
for (TeamPerformanceSortVo sortVo : listVo) {
String userId = sortVo.getTeamPerformance().getUserId();
Integer userLevel = sortVo.getTeamPerformance().getUserLevel();
//获取最大进步奖 百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(userLevel, 3);
//计算收益
double userTeamPerformance = sortVo.getTeamPerformance().getMonthTeamPerformance().doubleValue();
double percent = memberPercent.getPercent().doubleValue();
double income = number * 3980 * percent * userTeamPerformance / total;
//获取账户信息
AccountInfo accountInfo = accountMapper.getByUserId(userId);
accountInfo.setEarningsMonth(new BigDecimal(income));
//更新用户账户表
accountMapper.updateById(accountInfo);
}
//计算前20的总业绩
double total = listVo.stream().mapToDouble(TeamPerformanceSortVo::getMonthPerformance).sum();
totalPerformanceIncome(listVo, number, total);
return R.ok(0, true);
} else {
//计算总业绩
for (TeamPerformanceSortVo sortVo : listVo) {
String userId = sortVo.getTeamPerformance().getUserId();
Integer userLevel = sortVo.getTeamPerformance().getUserLevel();
//获取最大进步奖 百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(userLevel, 3);
//计算收益
double userTeamPerformance = sortVo.getTeamPerformance().getMonthTeamPerformance().doubleValue();
double percent = memberPercent.getPercent().doubleValue();
double income = number * 3980 * percent * userTeamPerformance / total;
//获取账户信息
AccountInfo accountInfo = accountMapper.getByUserId(userId);
accountInfo.setEarningsMonth(new BigDecimal(income));
//更新用户账户表
accountMapper.updateById(accountInfo);
}
//计算用户数少于20的总业绩
double total = listVo.stream().mapToDouble(TeamPerformanceSortVo::getMonthPerformance).sum();
totalPerformanceIncome(listVo, number, total);
}
return R.ok(0, true);
}
......@@ -344,17 +282,21 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
private boolean monthlyIncome(BigDecimal totalMoney, User user) {
double total = totalMoney.doubleValue();
BigDecimal money;
Date date = new Date();
String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
//当月所有人订单成交总金额/3980/12 向下整
double moneyMonth = Math.floor(total / 3980 / 12);
if (moneyMonth != 0) {
//获取等级优惠百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(user.getUserLevel(), 2);
if (null != memberPercent) {
//获取本月团队总金额
TeamPerformance teamPerformance = teamPerformanceMapper.getByUserIdAndTime(user.getUserId(), new Date());
TeamPerformance teamPerformance = teamPerformanceMapper.getByUserIdAndTime(user.getUserId(), yearMonth);
//获取该等级团队总金额
Double teamTotal = teamPerformanceMapper.countTeamMoney(user.getUserLevel(), new Date());
Double teamTotal = teamPerformanceMapper.countTeamMoney(user.getUserLevel(), yearMonth);
if (null != teamPerformance && null != teamTotal) {
double month = teamPerformance.getMonthTeamPerformance().doubleValue();
double percent = memberPercent.getPercent().doubleValue();
......@@ -392,4 +334,95 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
return false;
}
/**
* 统计每个用户本月业绩增长率
*
* @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;
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<>();
for (TeamPerformanceSortVo sortVo : listVo) {
String userId = sortVo.getTeamPerformance().getUserId();
Integer userLevel = sortVo.getTeamPerformance().getUserLevel();
//获取最大进步奖 百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(userLevel, 3);
//计算收益
double userTeamPerformance = sortVo.getTeamPerformance().getMonthTeamPerformance().doubleValue();
double percent = memberPercent.getPercent().doubleValue();
double income = number * 3980 * percent * userTeamPerformance / total;
//获取账户信息
AccountInfo accountInfo = accountMapper.getByUserId(userId);
BigDecimal bigDecimal = accountInfo.getEarningsMonth().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);
}
}
package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.common.utils.FileUtils;
import cn.wisenergy.model.app.shopZx;
import cn.wisenergy.service.app.UploadService;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.*;
import java.util.stream.Collectors;
/**
......
......@@ -18,6 +18,7 @@ import java.util.Map;
/**
* shiro配置类
* @author 86187
*/
@Configuration
public class ShiroConfig {
......
......@@ -47,30 +47,3 @@ mybatis-plus:
cache-enabled: false
call-setters-on-nulls: true
jdbc-type-for-null: 'null'
camera:
ysy: #萤石云
api:
appKey: 53ff83088a8b445ea1b30c0ba85f7653
appSecret: 0274e379003912b7ec1f3ef18a169624
isc: #海康威视
api:
host: 172.18.1.51:4443
#host: 111.203.232.172:4443
appKey: 23756916
appSecret: TDrCbqQXe9XSt7SimYDO
path: /artemis
absoluteImgPath: d://Pictures/img/
sonImgPath : d://img/
sms:
accessKeyId: LTAI4G6xmYPhjrS18Bxz5Kqu
secret: l3ZuSn2XjsFZXaB3yb8O5ASRJh3DDe
regionId: cn-hangzhou
domain: dysmsapi.aliyuncs.com
version: 2017-05-25
action: SendSms
signName: 西田森生物科技
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