Commit 1c3070c3 authored by licc's avatar licc

优化月度任务

parent 1504d2d1
......@@ -35,4 +35,13 @@ public interface ProgressPrizeMapper extends BaseMapper<ProgressPrize> {
* @return 最大进步奖用户列表
*/
List<ProgressPrizeVo> getByTime(@Param("yearMonth") String yearMonth);
/**
* 根据 userId 年月 获取月的最大进步奖用户
*
* @param yearMonth 年月
* @return 最大进步奖用户列表
*/
ProgressPrize getByUserIdYearMonth(@Param("userId") String userId,@Param("yearMonth") String yearMonth);
}
......@@ -79,9 +79,7 @@
<include refid="table"/>
<where>
<if test="yearMonth != null">
AND(
YEAR(`year_month`) = YEAR(#{yearMonth})
AND MONTH(`year_month`) = MONTH(#{yearMonth}))
`year_month` = #{yearMonth}
</if>
</where>
</select>
......@@ -96,4 +94,19 @@
order by p.`growth_rate` desc,p.award_money desc,u.create_time desc
</select>
<select id="getByUserIdYearMonth" resultType="cn.wisenergy.model.app.ProgressPrize">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
<if test="userId != null and userId != ''">
user_id=#{userId}
</if>
<if test="yearMonth != null">
and `year_month`= #{yearMonth}
</if>
</where>
</select>
</mapper>
\ No newline at end of file
......@@ -263,7 +263,7 @@ public class AccountManager {
*/
@Transactional(rollbackFor = Exception.class)
public Boolean updateAccountAddRecordAddPrize(List<AccountInfo> accountInfoList, List<TradeRecord> recordList,
List<ProgressPrize> prizeList) {
List<ProgressPrize> addPrizeList,List<ProgressPrize> updatePrizeList) {
//更新月收益
if (!CollectionUtils.isEmpty(accountInfoList)) {
......@@ -286,14 +286,24 @@ public class AccountManager {
}
//新增最大进步奖信息
if (!CollectionUtils.isEmpty(prizeList)) {
for (ProgressPrize progressPrize : prizeList) {
if (!CollectionUtils.isEmpty(addPrizeList)) {
for (ProgressPrize progressPrize : addPrizeList) {
int count = progressPrizeMapper.add(progressPrize);
if (count == 0) {
return false;
}
}
}
//编辑最大进步奖信息
if (!CollectionUtils.isEmpty(updatePrizeList)) {
for (ProgressPrize progressPrize : updatePrizeList) {
int count = progressPrizeMapper.edit(progressPrize);
if (count == 0) {
return false;
}
}
}
return true;
}
......
......@@ -267,7 +267,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
Double twentyTotal = teamPerformanceMapper.countTwenty(yearMonth);
List<AccountInfo> accountInfoList = new ArrayList<>();
List<TradeRecord> tradeRecordList = new ArrayList<>();
List<ProgressPrize> prizeList = new ArrayList<>();
List<ProgressPrize> addPrizeList = new ArrayList<>();
List<ProgressPrize> updatePrizeList = new ArrayList<>();
for (TeamPerformance user : list) {
//获取最大进步奖 百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(user.getUserLevel(),
......@@ -290,14 +291,21 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
accountInfo.setEarningsTotal(earningsTotal);
accountInfoList.add(accountInfo);
//添加最大进步奖信息
ProgressPrize prize = new ProgressPrize();
//添加最大进步奖信息 不存在:新增 存在,修改
BigDecimal awardMoney = new BigDecimal(income).setScale(2, RoundingMode.HALF_UP);
prize.setAwardMoney(awardMoney.doubleValue());
prize.setUserId(user.getUserId());
prize.setGrowthRate(0.0);
prize.setYearMonth(yearMonth);
prizeList.add(prize);
ProgressPrize progressPrize = progressPrizeMapper.getByUserIdYearMonth(user.getUserId(), yearMonth);
if (null == progressPrize) {
ProgressPrize prize = new ProgressPrize();
prize.setAwardMoney(awardMoney.doubleValue());
prize.setUserId(user.getUserId());
prize.setGrowthRate(0.0);
prize.setYearMonth(yearMonth);
addPrizeList.add(prize);
} else {
progressPrize.setYearMonth(yearMonth);
progressPrize.setAwardMoney(awardMoney.doubleValue());
updatePrizeList.add(progressPrize);
}
//添加交易流水记录
TradeRecord tradeRecord = new TradeRecord();
......@@ -310,7 +318,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
}
//更新账户信息,添加交易流水记录
boolean bool = accountManager.updateAccountAddRecordAddPrize(accountInfoList, tradeRecordList, prizeList);
boolean bool = accountManager.updateAccountAddRecordAddPrize(accountInfoList, tradeRecordList,
addPrizeList,updatePrizeList);
if (!bool) {
return R.ok(1, false);
}
......@@ -399,8 +408,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
double percent = memberPercent.getPercent().doubleValue();
//计算收益
double teamMoney = (moneyMonth + lastMonthAward) * 3980 * percent * month;
DecimalFormat df = new DecimalFormat("######0.00");
double income=Double.parseDouble(df.format(teamMoney/teamTotal));
DecimalFormat df = new DecimalFormat("######0.00");
double income = Double.parseDouble(df.format(teamMoney / teamTotal));
//获取账户信息
AccountInfo accountInfo = accountMapper.getByUserId(user.getUserId());
......
......@@ -219,7 +219,8 @@ public class MonthTaskServiceImpl implements MonthTaskService {
Double twentyTotal = teamPerformanceMapper.countTwenty(lastMonth);
List<AccountInfo> accountInfoList = new ArrayList<>();
List<TradeRecord> tradeRecordList = new ArrayList<>();
List<ProgressPrize> prizeList = new ArrayList<>();
List<ProgressPrize> addPrizeList = new ArrayList<>();
List<ProgressPrize> updatePrizeList = new ArrayList<>();
for (TeamPerformance user : list) {
//获取最大进步奖 百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(user.getUserLevel(), 3);
......@@ -239,14 +240,21 @@ public class MonthTaskServiceImpl implements MonthTaskService {
accountInfo.setEarningsTotal(earningsTotal.setScale(2, RoundingMode.HALF_UP));
accountInfoList.add(accountInfo);
//添加最大进步奖信息
ProgressPrize prize = new ProgressPrize();
//添加最大进步奖信息 不存在:新增 存在,修改
BigDecimal awardMoney = new BigDecimal(income).setScale(2, RoundingMode.HALF_UP);
prize.setAwardMoney(awardMoney.doubleValue());
prize.setUserId(user.getUserId());
prize.setGrowthRate(0.0);
prize.setYearMonth(lastMonth);
prizeList.add(prize);
ProgressPrize progressPrize = progressPrizeMapper.getByUserIdYearMonth(user.getUserId(), lastMonth);
if (null == progressPrize) {
ProgressPrize prize = new ProgressPrize();
prize.setAwardMoney(awardMoney.doubleValue());
prize.setUserId(user.getUserId());
prize.setGrowthRate(0.0);
prize.setYearMonth(lastMonth);
addPrizeList.add(prize);
} else {
progressPrize.setYearMonth(lastMonth);
progressPrize.setAwardMoney(awardMoney.doubleValue());
updatePrizeList.add(progressPrize);
}
//添加交易流水记录
TradeRecord tradeRecord = new TradeRecord();
......@@ -259,7 +267,8 @@ public class MonthTaskServiceImpl implements MonthTaskService {
}
//更新账户信息,添加交易流水记录
boolean bool = accountManager.updateAccountAddRecordAddPrize(accountInfoList, tradeRecordList, prizeList);
boolean bool = accountManager.updateAccountAddRecordAddPrize(accountInfoList, tradeRecordList,
addPrizeList,updatePrizeList);
if (!bool) {
return R.ok(1, false);
}
......
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