Commit 05d51a6e authored by licc's avatar licc

优化月度奖励计算接口

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