Commit 198b1ce6 authored by licc's avatar licc

优化月度任务接口

parent c3d4fb4a
......@@ -44,33 +44,40 @@ public interface UsersMapper extends BaseMapper<User> {
List<User> getList(Map<String, Object> map);
List<User> findAll();
User findByName(String name);
String findPswByName(String UserName);
void save(User user);
/**
* 获取用户信息
* 获取用户信息
*
* @param userId 用户id
* @return 用户信息
*/
User getByUserId(@Param("userId") String userId);
/**
* 获取用户信息
* 获取用户信息
*
* @param userId 用户id
* @return 用户信息
*/
Integer ByUserId(@Param("userId") String userId);
/**
* 获取用户信息
* 获取用户信息
*
* @param
* @return 用户信息
*/
Integer beInvitedCode1(@Param("beInvitedCode") String beInvitedCode);
/**
* 获取用户信息
* 获取用户信息
*
* @param beInvitedCode 用户被邀请码
* @return 用户信息
*/
......@@ -78,39 +85,46 @@ public interface UsersMapper extends BaseMapper<User> {
/**
* 获取黄金树以上会员用户
*
* @return
*/
List<User> getAllGoldUser();
/**
* 查询用户
*
* @param param
* @return
*/
public List<User> getUsersListByMap(Map<String,Object> param);
public List<User> getUsersListByMap(Map<String, Object> param);
//根据手机号查询用户Integer
User queryUsersByPhone(@Param("userId")String userId);
User queryUsersByPhone(@Param("userId") String userId);
//根据用户的推荐人邀请码比对推荐人的本人邀请码,查询推荐人的用户ID
Integer inviteCodeBeInvitedCode(@Param("beInvitedCode")Integer beInvitedCode);
Integer inviteCodeBeInvitedCode(@Param("beInvitedCode") Integer beInvitedCode);
/**
* 用户注册
*
* @param userId
* @param inviteCode
* @param beInvitedCode
* @param userLevel
*/
Integer save(@Param("userId")String userId, @Param("inviteCode") String inviteCode, @Param("beInvitedCode") String beInvitedCode, @Param("userLevel") Integer userLevel);
Integer insertbyint(@Param("userId")String userId, @Param("beInvitedCode") String beInvitedCode);
Integer save(@Param("userId") String userId, @Param("inviteCode") String inviteCode, @Param("beInvitedCode") String beInvitedCode, @Param("userLevel") Integer userLevel);
User edit1(int userLevel, String intiveCode,String userId);
Integer insertbyint(@Param("userId") String userId, @Param("beInvitedCode") String beInvitedCode);
User edit1(int userLevel, String intiveCode, String userId);
Integer getuserIdById(@Param("userId") String userId);
Integer BYQMById(@Param("userId") String userId);
Integer getuserIdById(@Param("userId")String userId);
Integer BYQMById(@Param("userId")String userId);
/**
* 根据userid获取获取所有的直接推荐人
*
* @param inviteCode 用户本人的邀请码
* @return 所有填写此人的邀请码的用户
*/
......@@ -118,8 +132,17 @@ public interface UsersMapper extends BaseMapper<User> {
/**
* 通过邀请码,获取用户信息
*
* @param inviteCode 邀请码
* @return 用户信息
*/
User queryByInviteCode(@Param("inviteCode") String inviteCode);
/**
* 通过用户等级,获取该等级用户列表
*
* @param userLevel 用户等级
* @return 等级用户列表
*/
List<User> getByLevel(@Param("userLevel") Integer userLevel);
}
......@@ -101,10 +101,10 @@
<include refid="table"/>
<where>
be_invited_code=1
<if test="createTime != null">
and(YEAR(create_time) = YEAR(#{createTime})
AND MONTH(create_time) = MONTH(#{createTime}))
</if>
<if test="createTime != null">
and(YEAR(create_time) = YEAR(#{createTime})
AND MONTH(create_time) = MONTH(#{createTime}))
</if>
</where>
order by create_time desc
</select>
......@@ -165,7 +165,8 @@
<!--用户注册-->
<insert id="save">
insert into user(user_id,invite_code,be_invited_code,user_level) value (#{userId},#{inviteCode},#{beInvitedCode},#{userLevel})
insert into user(user_id,invite_code,be_invited_code,user_level) value
(#{userId},#{inviteCode},#{beInvitedCode},#{userLevel})
</insert>
<insert id="insertbyint">
insert into user_info(user_id,be_invited_code) value (#{userId},#{beInvitedCode})
......@@ -173,7 +174,7 @@
<select id="queryUsersByPhone" resultType="cn.wisenergy.model.app.User">
select
<include refid="vals"/>
<include refid="vals"/>
from
<include refid="table"/>
<where>
......@@ -219,7 +220,7 @@
user_id=#{userId}
</where>
</select>
<update id="edit1" >
<update id="edit1">
update
user_info
<set>
......@@ -229,7 +230,7 @@
update_time =now()
</set>
<where>
user_id = #{userId}
user_id = #{userId}
</where>
</update>
......@@ -289,7 +290,7 @@
</if>
</select>
<!-- 获取当前用户的所有直接推荐人-->
<!-- 获取当前用户的所有直接推荐人-->
<select id="getByInviteCode" resultType="cn.wisenergy.model.app.User" parameterType="string">
select
<include refid="cols_all"/>
......@@ -311,5 +312,15 @@
</where>
</select>
<select id="getByLevel" resultType="cn.wisenergy.model.app.User">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
user_level=#{userLevel}
</where>
</select>
</mapper>
package cn.wisenergy.model.app;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......
......@@ -46,6 +46,9 @@ public class AccountManager {
@Autowired
private TradeRecordMapper tradeRecordMapper;
@Autowired
private MonthManureMapper monthManureMapper;
private static final String PATTERN = "yyyy-MM";
......@@ -229,4 +232,40 @@ public class AccountManager {
}
return true;
}
/**
* 更新账户信息和保存交易流水记录、保存上月剩余月度肥料奖金
*
* @param accountInfoList 账户列表
* @param recordList 交易流水信息
*/
@Transactional(rollbackFor = Exception.class)
public Boolean updateAccountAddRecordAndManure(List<AccountInfo> accountInfoList,
List<TradeRecord> recordList,
MonthManure manure) {
//更新月收益
if (!CollectionUtils.isEmpty(accountInfoList)) {
for (AccountInfo accountInfo : accountInfoList) {
int count = accountMapper.updateById(accountInfo);
if (count == 0) {
return false;
}
}
}
//新增交易流水记录
if (!CollectionUtils.isEmpty(recordList)) {
for (TradeRecord tradeRecord : recordList) {
int count = tradeRecordMapper.add(tradeRecord);
if (count == 0) {
return false;
}
}
}
//新增上月剩余月度肥料奖金
int count = monthManureMapper.add(manure);
return count != 0;
}
}
......@@ -50,9 +50,4 @@ public interface AccountService {
* @return true or false
*/
R<Boolean> progressPrizeCount();
/**
* 账户表镜像---每月更新一次,保存上一个的数据
*/
void mirrorImage();
}
package cn.wisenergy.service.app;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.OrderInfo;
import java.util.List;
/**
*@ Description: 月定时任务接口定义
*@ Author : 86187
......@@ -6,4 +12,30 @@ package cn.wisenergy.service.app;
* @author 86187
*/
public interface MonthTaskService {
/**
* 订单返佣-月任务
* @return true or false
*/
R<Boolean> orderRebate();
/**
* 收益和业绩统计(月度肥料)-月任务
*
* @param list 订单信息
* @return true or false
*/
R<Boolean> performanceCount(List<OrderInfo> list);
/**
* 进步奖收益统计(最大进步奖) -月任务
*
* @return true or false
*/
R<Boolean> progressPrizeCount();
/**
* 账户表镜像---每月更新一次,保存上一个的数据
*/
void mirrorImage();
}
......@@ -57,10 +57,10 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
private ProgressPrizeMapper progressPrizeMapper;
@Autowired
private LastAccountMapper lastAccountMapper;
private OrderMapper orderMapper;
@Autowired
private OrderMapper orderMapper;
private MonthManureMapper monthManureMapper;
private static final String PATTERN = "yyyy-MM";
......@@ -70,7 +70,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
public R<Boolean> orderRebate() {
//获取返佣订单
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());
if (CollectionUtils.isEmpty(list)) {
return R.ok(0, true);
......@@ -292,29 +292,6 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
return R.ok(0, true);
}
@Override
public void mirrorImage() {
//1、把账户表account_info复制给表account_image CREATE TABLE table_2 SELECT * FROM table_1;
lastAccountMapper.copyTable("account_info", "account_image");
//删除上月备份
lastAccountMapper.deleteTable("account_backup");
//备份
lastAccountMapper.copyTable("account_info", "account_backup");
//2、把上月账户表last_month_account 复制给month_account_image
lastAccountMapper.copyTable("last_month_account", "month_account_image");
//3、删除last_month_account
lastAccountMapper.deleteTable("last_month_account");
//4、把account_image 更名为 last_month_account rename table table_2 to table_1;
lastAccountMapper.updateTableName("account_image", "last_month_account");
//5、删除month_account_image DROP table table_2;
lastAccountMapper.deleteTable("month_account_image");
}
public void getUser(List<User> list, String userId) {
User user = usersMapper.getByUserId(userId);
......@@ -341,6 +318,17 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
double moneyMonth = Math.floor(total / 3980 / 12);
List<AccountInfo> accountInfoList = new ArrayList<>();
List<TradeRecord> tradeRecordList = new ArrayList<>();
//获取上月未分配完的奖金
double lastMonthAward;
Date last = DateUtil.getLastMonth(new Date());
String yearMonthTime = DateUtil.convertDateToStr(last, PATTERN);
MonthManure monthManure = monthManureMapper.queryByTime(yearMonthTime);
if (null == monthManure) {
lastMonthAward = 0.00;
} else {
lastMonthAward = monthManure.getManureAward();
}
for (User user : userList) {
if (moneyMonth != 0) {
//获取等级优惠百分比
......@@ -355,7 +343,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
double month = teamPerformance.getMonthTeamPerformance().doubleValue();
double percent = memberPercent.getPercent().doubleValue();
//计算收益
double income = moneyMonth * 3980 * percent * month / teamTotal;
double income = (moneyMonth + lastMonthAward) * 3980 * percent * month / teamTotal;
//获取账户信息
AccountInfo accountInfo = accountMapper.getByUserId(user.getUserId());
......@@ -371,7 +359,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
//5、添加交易流水记录
TradeRecord tradeRecord = new TradeRecord();
tradeRecord.setUserId(user.getUserId());
tradeRecord.setTradeType(TradeRecordEnum.ORDER_REBATE.getCode());
tradeRecord.setTradeType(TradeRecordEnum.MONTHLY_FERTILIZER.getCode());
tradeRecord.setTradeNo(null);
tradeRecord.setStatus(TradeStatusEnum.NO_SETTLE_ACCOUNTS.getCode());
tradeRecordList.add(tradeRecord);
......
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.*;
import cn.wisenergy.model.enums.MemberPercentEnum;
import cn.wisenergy.model.enums.TradeRecordEnum;
import cn.wisenergy.model.enums.TradeStatusEnum;
import cn.wisenergy.model.enums.UserLevelEnum;
import cn.wisenergy.service.Manager.AccountManager;
import cn.wisenergy.service.Manager.PublicManager;
import cn.wisenergy.service.app.AccountService;
import cn.wisenergy.service.app.MonthTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @author 86187
*/
@Slf4j
@Service
public class MonthTaskServiceImpl implements MonthTaskService {
@Autowired
private LastAccountMapper lastAccountMapper;
@Autowired
private UsersMapper usersMapper;
@Autowired
private AccountMapper accountMapper;
@Autowired
private MemberPercentMapper memberPercentMapper;
@Autowired
private AccountManager accountManager;
@Autowired
private PublicManager publicManager;
@Autowired
private TradeRecordMapper tradeRecordMapper;
@Autowired
private TeamPerformanceMapper teamPerformanceMapper;
@Autowired
private ProgressPrizeMapper progressPrizeMapper;
@Autowired
private AccountService accountService;
@Autowired
private MonthManureMapper monthManureMapper;
@Autowired
private OrderMapper orderMapper;
private static final String PATTERN = "yyyy-MM";
private static final Integer TWENTY = 20;
@Override
public R<Boolean> orderRebate() {
return null;
}
@Override
public R<Boolean> performanceCount(List<OrderInfo> list) {
log.info("shop-mall[]AccountServiceImpl[]performanceCount[]input.param.list:{}", list.size());
if (CollectionUtils.isEmpty(list)) {
return R.ok(0, true);
}
Date date = new Date();
String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
//计算当月所有订单成交额
BigDecimal totalMoney = new BigDecimal(0);
for (OrderInfo orderInfo : list) {
//判断是否是本月
boolean bool = publicManager.isThisMonth(orderInfo.getCreateTime(), PATTERN);
if (bool && orderInfo.getMonthlyTaskStatus() == 0) {
totalMoney = totalMoney.add(orderInfo.getPayment());
}
}
//遍历订单 订单状态创建时间,当月时间小于当前时间
for (OrderInfo orderInfo : list) {
long createTime = orderInfo.getCreated().getTime();
long time = System.currentTimeMillis();
if (createTime <= time) {
//获取用户信息
User user = usersMapper.selectById(orderInfo.getBuyerId());
if (null == user) {
continue;
}
List<TeamPerformance> teamPerformances = new ArrayList<>();
//获取团队业绩信息
TeamPerformance teamPerformance = teamPerformanceMapper.getByUserIdAndTime(user.getUserId(), yearMonth);
if (null == teamPerformance) {
continue;
}
//1、统计当前用户月度业绩
BigDecimal userCount = teamPerformance.getMonthTeamPerformance().add(orderInfo.getPayment());
teamPerformance.setMonthTeamPerformance(userCount);
teamPerformances.add(teamPerformance);
//2、获取当前用户的上级用户列表 todo 邀请码等于一个固定值,停止 等于两个值 七位XXXXXXX 和 7777777
List<User> userList = accountService.getByList(user.getUserId());
if (CollectionUtils.isEmpty(userList)) {
continue;
}
//3、统计当前用户上级月度绩效
for (User userInfo : userList) {
TeamPerformance team = teamPerformanceMapper.getByUserIdAndTime(userInfo.getUserId(), yearMonth);
if (null == team) {
continue;
}
//1)、统计当前用户月度绩效
BigDecimal monthCount = team.getMonthTeamPerformance().add(orderInfo.getPayment());
team.setMonthTeamPerformance(monthCount);
teamPerformances.add(team);
}
//4、更新账户月度绩效
accountManager.updateAccountPerformanceMonth(teamPerformances);
}
}
//5、获取所有用户,如果会员等级是黄金以上,计算月度收益
List<User> userList = usersMapper.getAllGoldUser();
if (CollectionUtils.isEmpty(userList)) {
//添加月度肥料剩余奖金
MonthManure monthManure = new MonthManure();
monthManure.setManureAward(totalMoney.doubleValue());
monthManure.setYearMonth(yearMonth);
int count = monthManureMapper.add(monthManure);
if (count == 0) {
return R.ok(1, false);
}
return R.ok(0, true);
}
//7、计算收益
boolean bool = monthlyIncome(totalMoney, userList);
if (!bool) {
return R.ok(1, false);
}
return R.ok(0, true);
}
@Override
public R<Boolean> progressPrizeCount() {
return null;
}
@Override
public void mirrorImage() {
//1、把账户表account_info复制给表account_image CREATE TABLE table_2 SELECT * FROM table_1;
lastAccountMapper.copyTable("account_info", "account_image");
//删除上月备份
lastAccountMapper.deleteTable("account_backup");
//备份
lastAccountMapper.copyTable("account_info", "account_backup");
//2、把上月账户表last_month_account 复制给month_account_image
lastAccountMapper.copyTable("last_month_account", "month_account_image");
//3、删除last_month_account
lastAccountMapper.deleteTable("last_month_account");
//4、把account_image 更名为 last_month_account rename table table_2 to table_1;
lastAccountMapper.updateTableName("account_image", "last_month_account");
//5、删除month_account_image DROP table table_2;
lastAccountMapper.deleteTable("month_account_image");
}
/**
* 如果会员等级是黄金以上,计算月度收益
*
* @param totalMoney 月金额总额
* @param userList 用户列表
* @return
*/
private boolean monthlyIncome(BigDecimal totalMoney, List<User> userList) {
double total = totalMoney.doubleValue();
Date date = new Date();
String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
//当月所有人订单成交总金额/3980/12 向下取整
double moneyMonth = Math.floor(total / 3980 / 12);
List<AccountInfo> accountInfoList = new ArrayList<>();
List<TradeRecord> tradeRecordList = new ArrayList<>();
//获取上月未分配完的奖金
double lastMonthAward;
Date last = DateUtil.getLastMonth(new Date());
String yearMonthTime = DateUtil.convertDateToStr(last, PATTERN);
MonthManure monthManure = monthManureMapper.queryByTime(yearMonthTime);
if (null == monthManure) {
lastMonthAward = 0.00;
} else {
lastMonthAward = monthManure.getManureAward();
}
moneyMonth = moneyMonth + lastMonthAward;
//判断每个等级是否都有用户,没有用户的,记录下剩余奖金
MonthManure manure = checkUserLevel(moneyMonth);
for (User user : userList) {
if (moneyMonth != 0) {
//获取等级优惠百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(user.getUserLevel(),
MemberPercentEnum.MONTH_MANURE.getCode());
if (null != memberPercent) {
//获取本月团队总金额
TeamPerformance teamPerformance = teamPerformanceMapper.getByUserIdAndTime(user.getUserId(), yearMonth);
//获取该等级团队总金额
Double teamTotal = teamPerformanceMapper.countTeamMoney(user.getUserLevel(), yearMonth);
if (null != teamPerformance && null != teamTotal) {
double month = teamPerformance.getMonthTeamPerformance().doubleValue();
double percent = memberPercent.getPercent().doubleValue();
//计算收益
double income = moneyMonth * 3980 * percent * month / teamTotal;
//获取账户信息
AccountInfo accountInfo = accountMapper.getByUserId(user.getUserId());
BigDecimal bigDecimal = new BigDecimal(income);
BigDecimal performanceMonth = accountInfo.getEarningsMonth().add(bigDecimal);
accountInfo.setEarningsMonth(performanceMonth);
BigDecimal performanceTotal = accountInfo.getEarningsMonth().add(bigDecimal);
accountInfo.setEarningsMonth(performanceTotal);
accountInfoList.add(accountInfo);
//5、添加交易流水记录
TradeRecord tradeRecord = new TradeRecord();
tradeRecord.setUserId(user.getUserId());
tradeRecord.setTradeType(TradeRecordEnum.MONTHLY_FERTILIZER.getCode());
tradeRecord.setTradeNo(null);
tradeRecord.setStatus(TradeStatusEnum.ALREADY_SETTLE_ACCOUNTS.getCode());
tradeRecordList.add(tradeRecord);
}
}
}
}
//更新账户信息,新增交易流水记录
return accountManager.updateAccountAddRecordAndManure(accountInfoList, tradeRecordList, manure);
}
/**
* 计算上月未分配完的月度肥料奖金
*
* @param moneyMonth 奖金总额
* @return 月度肥料奖金
*/
private MonthManure checkUserLevel(double moneyMonth) {
MonthManure monthManure = new MonthManure();
double total = 0.00;
//1、判断是否有黄金等级的用户
List<User> goldList = usersMapper.getByLevel(UserLevelEnum.GOLD_TREE.getCode());
if (CollectionUtils.isEmpty(goldList)) {
//获取等级优惠百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(UserLevelEnum.GOLD_TREE.getCode(),
MemberPercentEnum.MONTH_MANURE.getCode());
double percent = memberPercent.getPercent().doubleValue();
//计算该等级剩余奖金
double goldAward;
if (moneyMonth != 0) {
goldAward = moneyMonth * 3980 * percent;
total = total + goldAward;
}
}
//2、判断是否有农场主等级的用户
List<User> farmerList = usersMapper.getByLevel(UserLevelEnum.FARMER.getCode());
if (CollectionUtils.isEmpty(farmerList)) {
//获取等级优惠百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(UserLevelEnum.FARMER.getCode(),
MemberPercentEnum.MONTH_MANURE.getCode());
double percent = memberPercent.getPercent().doubleValue();
//计算该等级剩余奖金
double goldAward;
if (moneyMonth != 0) {
goldAward = moneyMonth * 3980 * percent;
total = total + goldAward;
}
}
//3、判断是否有森林之星等级的用户
List<User> startList = usersMapper.getByLevel(UserLevelEnum.FOREST_START.getCode());
if (CollectionUtils.isEmpty(startList)) {
//获取等级优惠百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(UserLevelEnum.FOREST_START.getCode(),
MemberPercentEnum.MONTH_MANURE.getCode());
double percent = memberPercent.getPercent().doubleValue();
//计算该等级剩余奖金
double goldAward;
if (moneyMonth != 0) {
goldAward = moneyMonth * 3980 * percent;
total = total + goldAward;
}
}
//4、判断是否有西田森等级的用户
List<User> partnerList = usersMapper.getByLevel(UserLevelEnum.PARTNER.getCode());
if (CollectionUtils.isEmpty(partnerList)) {
//获取等级优惠百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(UserLevelEnum.FOREST_START.getCode(),
MemberPercentEnum.MONTH_MANURE.getCode());
double percent = memberPercent.getPercent().doubleValue();
//计算该等级剩余奖金
double goldAward;
if (moneyMonth != 0) {
goldAward = moneyMonth * 3980 * percent;
total = total + goldAward;
}
}
//获取当前时间上一月
Date date = DateUtil.getLastMonth(new Date());
String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
monthManure.setYearMonth(yearMonth);
monthManure.setManureAward(total);
return monthManure;
}
}
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