Commit 05d51a6e authored by licc's avatar licc

优化月度奖励计算接口

parent d5e60650
......@@ -40,5 +40,5 @@ public interface MonthAwardMapper extends BaseMapper<MonthAward> {
* @param yearMonth 年月
* @return 月度奖金
*/
MonthAward getByTime(@Param("yearMonth")Date yearMonth);
MonthAward getByTime(@Param("yearMonth") String yearMonth);
}
......@@ -11,6 +11,7 @@
<result column="farmer_award" property="farmerAward"/>
<result column="forest_start_award" property="forestStartAward"/>
<result column="partner_award" property="partnerAward"/>
<result column="year_month" property="yearMonth"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
</resultMap>
......@@ -26,12 +27,12 @@
<sql id="cols_exclude_id">
growth_award,award_total,month_award_total,month_increased,gold_award,farmer_award, forest_start_award,
partner_award,create_time,update_time
partner_award,year_month,create_time,update_time
</sql>
<sql id="vals">
#{growthAward},#{awardTotal},#{monthAwardTotal},#{monthIncreased},#{goldAward},#{farmerAward},
#{forestStartAward}, #{partnerAward},now(),now()
#{forestStartAward}, #{partnerAward},#{yearMonth},now(),now()
</sql>
<sql id="updateCondition">
......@@ -43,6 +44,7 @@
<if test="farmerAward != null">farmer_award =#{farmerAward},</if>
<if test="forestStartAward != null">forest_start_award =#{forestStartAward},</if>
<if test="partnerAward != null">partner_award =#{partnerAward},</if>
<if test="yearMonth != null">year_month =#{yearMonth},</if>
update_time =now()
</sql>
......@@ -56,6 +58,7 @@
<if test="farmerAward != null">and farmer_award =#{farmerAward}</if>
<if test="forestStartAward != null">and forest_start_award =#{forestStartAward}</if>
<if test="partnerAward != null">and partner_award =#{partnerAward}</if>
<if test="yearMonth != null">and year_month =#{yearMonth}</if>
<if test="createTime != null">and create_time &gt;= #{createTime}</if>
<if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
</sql>
......@@ -93,12 +96,11 @@
<include refid="table"/>
<where>
<if test="yearMonth != null">
YEAR(create_time) = YEAR(#{yearMonth})
AND MONTH(create_time) = MONTH(#{yearMonth})
year_month=#{yearMonth}
</if>
order by create_time desc
limit 1
</where>
order by create_time desc
limit 1
</select>
</mapper>
\ No newline at end of file
......@@ -73,6 +73,11 @@ public class MonthAward implements Serializable {
@ApiModelProperty(value = "森田合伙人月奖励总额",name="partnerAward")
private Double partnerAward;
/**
* 时间 :yyyy-MM
*/
@ApiModelProperty(value = "时间 :yyyy-MM",name="yearMonth")
private String yearMonth;
private Date createTime;
......
package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.utils.DateUtil;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.MonthAwardMapper;
import cn.wisenergy.mapper.TradeRecordMapper;
......@@ -33,8 +34,9 @@ public class MonthAwardServiceImpl extends ServiceImpl<MonthAwardMapper, MonthAw
}
//获取本月最新的一条数据
String yearMonth = DateUtil.convertDateToStr(new Date(), "yyyy-MM");
MonthAwardVo monthAwardVo = new MonthAwardVo();
MonthAward monthAward = baseMapper.getByTime(new Date());
MonthAward monthAward = baseMapper.getByTime(yearMonth);
if (null == monthAward) {
return R.ok(monthAwardVo);
}
......
......@@ -63,9 +63,15 @@ public class TradeRecordServiceImpl extends ServiceImpl<TradeRecordMapper, Trade
result.setMonthAwardTotal(monthAwardTotal);
//4、较上月增长奖金 本月累计奖金-上月累计奖金
//获取上月 累计奖金
//本月
String currentMonth=DateUtil.convertDateToStr(new Date(),"yyyy-MM");
Date lastDate=DateUtil.getLastMonth(new Date());
String lastMonth=DateUtil.convertDateToStr(lastDate,"yyyy-MM");
Double growthAward;
MonthAward monthAward = monthAwardMapper.getByTime(date);
//获取上月 累计奖金
MonthAward monthAward = monthAwardMapper.getByTime(lastMonth);
if (null == monthAward) {
growthAward = monthAwardTotal;
} else {
......@@ -75,23 +81,39 @@ public class TradeRecordServiceImpl extends ServiceImpl<TradeRecordMapper, Trade
//5、获取黄金树本月奖金
Double goldAward = baseMapper.queryByUserLevel(UserLevelEnum.GOLD_TREE.getCode(), new Date());
result.setGoldAward(goldAward);
if (null == goldAward) {
result.setGoldAward(0.00);
} else {
result.setGoldAward(goldAward);
}
//6、获取农场主本月奖金
Double farmerAward = baseMapper.queryByUserLevel(UserLevelEnum.FARMER.getCode(), new Date());
result.setFarmerAward(farmerAward);
if (null == farmerAward) {
result.setFarmerAward(0.00);
} else {
result.setFarmerAward(farmerAward);
}
//7、森林之星月奖金
Double startAward = baseMapper.queryByUserLevel(UserLevelEnum.FOREST_START.getCode(), new Date());
result.setForestStartAward(startAward);
if (null == startAward) {
result.setForestStartAward(0.00);
} else {
result.setForestStartAward(startAward);
}
//8、森田合伙人月奖金
Double partnerAward = baseMapper.queryByUserLevel(UserLevelEnum.PARTNER.getCode(), new Date());
result.setPartnerAward(partnerAward);
if (null == partnerAward) {
result.setPartnerAward(0.00);
} else {
result.setPartnerAward(partnerAward);
}
//9、 判断是否有本月奖金这条数据,没有,新增,有更新值
MonthAward currentMonth = monthAwardMapper.getByTime(new Date());
if (null == currentMonth) {
MonthAward currentMonthAward = monthAwardMapper.getByTime(currentMonth);
if (null == currentMonthAward) {
int count = monthAwardMapper.add(result);
if (count == 0) {
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