计算过期积分

master
382696293@qq.com 2 years ago
parent 28f97a96ee
commit 3926874547

@ -31,6 +31,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="floatScore != null "> and float_score = #{floatScore}</if>
<if test="soureId != null "> and soure_id = #{soureId}</if>
<if test="remarkContent != null and remarkContent != ''"> and remark_content = #{remarkContent}</if>
<if test="createTime != null">
and create_time &lt;= #{createTime}
</if>
</where>
</select>

@ -4,6 +4,7 @@ import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import com.flossom.common.core.domain.R;
import com.flossom.common.core.domain.entity.WxUserIntegralLog;
import com.flossom.common.core.utils.poi.ExcelUtil;
import com.flossom.common.core.web.controller.BaseController;
@ -13,14 +14,7 @@ import com.flossom.common.log.annotation.Log;
import com.flossom.common.log.enums.BusinessType;
import com.flossom.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.flossom.system.service.IWxUserIntegralLogService;
/**
@ -31,8 +25,7 @@ import com.flossom.system.service.IWxUserIntegralLogService;
*/
@RestController
@RequestMapping("/integralLog")
public class WxUserIntegralLogController extends BaseController
{
public class WxUserIntegralLogController extends BaseController {
@Autowired
private IWxUserIntegralLogService wxUserIntegralLogService;
@ -41,8 +34,7 @@ public class WxUserIntegralLogController extends BaseController
*/
@RequiresPermissions("system:integralLog:list")
@GetMapping("/list")
public TableDataInfo list(WxUserIntegralLog wxUserIntegralLog)
{
public TableDataInfo list(WxUserIntegralLog wxUserIntegralLog) {
startPage();
List<WxUserIntegralLog> list = wxUserIntegralLogService.selectWxUserIntegralLogList(wxUserIntegralLog);
return getDataTable(list);
@ -54,8 +46,7 @@ public class WxUserIntegralLogController extends BaseController
@RequiresPermissions("system:integralLog:export")
@Log(title = "微信用户积分流水", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, WxUserIntegralLog wxUserIntegralLog)
{
public void export(HttpServletResponse response, WxUserIntegralLog wxUserIntegralLog) {
List<WxUserIntegralLog> list = wxUserIntegralLogService.selectWxUserIntegralLogList(wxUserIntegralLog);
ExcelUtil<WxUserIntegralLog> util = new ExcelUtil<WxUserIntegralLog>(WxUserIntegralLog.class);
util.exportExcel(response, list, "微信用户积分流水数据");
@ -66,8 +57,7 @@ public class WxUserIntegralLogController extends BaseController
*/
@RequiresPermissions("system:integralLog:query")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
public AjaxResult getInfo(@PathVariable("id") Long id) {
return success(wxUserIntegralLogService.selectWxUserIntegralLogById(id));
}
@ -77,8 +67,7 @@ public class WxUserIntegralLogController extends BaseController
@RequiresPermissions("system:integralLog:add")
@Log(title = "微信用户积分流水", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody WxUserIntegralLog wxUserIntegralLog)
{
public AjaxResult add(@RequestBody WxUserIntegralLog wxUserIntegralLog) {
return toAjax(wxUserIntegralLogService.insertWxUserIntegralLog(wxUserIntegralLog));
}
@ -88,8 +77,7 @@ public class WxUserIntegralLogController extends BaseController
@RequiresPermissions("system:integralLog:edit")
@Log(title = "微信用户积分流水", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody WxUserIntegralLog wxUserIntegralLog)
{
public AjaxResult edit(@RequestBody WxUserIntegralLog wxUserIntegralLog) {
return toAjax(wxUserIntegralLogService.updateWxUserIntegralLog(wxUserIntegralLog));
}
@ -98,9 +86,17 @@ public class WxUserIntegralLogController extends BaseController
*/
@RequiresPermissions("system:integralLog:remove")
@Log(title = "微信用户积分流水", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(wxUserIntegralLogService.deleteWxUserIntegralLogByIds(ids));
}
/**
*
*/
@GetMapping("/countUserExpireIntegral")
public R countUserExpireIntegral(@RequestParam(required = false, value = "idList") List<Long> idList) {
wxUserIntegralLogService.countUserExpireIntegral(idList);
return R.ok();
}
}

@ -59,4 +59,7 @@ public interface IWxUserIntegralLogService
* @return
*/
public int deleteWxUserIntegralLogById(Long id);
void countUserExpireIntegral(List<Long> idList);
}

@ -1,10 +1,20 @@
package com.flossom.system.service.impl;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.flossom.common.core.domain.entity.WxUserIntegralLog;
import com.flossom.common.core.domain.entity.WxUserMember;
import com.flossom.common.core.enums.Status;
import com.flossom.common.core.mapper.WxUserIntegralLogMapper;
import com.flossom.common.core.mapper.WxUserMemberMapper;
import com.flossom.common.core.utils.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.flossom.system.service.IWxUserIntegralLogService;
@ -16,11 +26,13 @@ import com.flossom.system.service.IWxUserIntegralLogService;
* @date 2023-12-14
*/
@Service
public class WxUserIntegralLogServiceImpl implements IWxUserIntegralLogService
{
public class WxUserIntegralLogServiceImpl implements IWxUserIntegralLogService {
@Autowired
private WxUserIntegralLogMapper wxUserIntegralLogMapper;
@Autowired
private WxUserMemberMapper wxUserMemberMapper;
/**
*
*
@ -28,8 +40,7 @@ public class WxUserIntegralLogServiceImpl implements IWxUserIntegralLogService
* @return
*/
@Override
public WxUserIntegralLog selectWxUserIntegralLogById(Long id)
{
public WxUserIntegralLog selectWxUserIntegralLogById(Long id) {
return wxUserIntegralLogMapper.selectWxUserIntegralLogById(id);
}
@ -40,8 +51,7 @@ public class WxUserIntegralLogServiceImpl implements IWxUserIntegralLogService
* @return
*/
@Override
public List<WxUserIntegralLog> selectWxUserIntegralLogList(WxUserIntegralLog wxUserIntegralLog)
{
public List<WxUserIntegralLog> selectWxUserIntegralLogList(WxUserIntegralLog wxUserIntegralLog) {
return wxUserIntegralLogMapper.selectWxUserIntegralLogList(wxUserIntegralLog);
}
@ -52,8 +62,7 @@ public class WxUserIntegralLogServiceImpl implements IWxUserIntegralLogService
* @return
*/
@Override
public int insertWxUserIntegralLog(WxUserIntegralLog wxUserIntegralLog)
{
public int insertWxUserIntegralLog(WxUserIntegralLog wxUserIntegralLog) {
wxUserIntegralLog.setCreateTime(DateUtils.getNowDate());
return wxUserIntegralLogMapper.insertWxUserIntegralLog(wxUserIntegralLog);
}
@ -65,8 +74,7 @@ public class WxUserIntegralLogServiceImpl implements IWxUserIntegralLogService
* @return
*/
@Override
public int updateWxUserIntegralLog(WxUserIntegralLog wxUserIntegralLog)
{
public int updateWxUserIntegralLog(WxUserIntegralLog wxUserIntegralLog) {
return wxUserIntegralLogMapper.updateWxUserIntegralLog(wxUserIntegralLog);
}
@ -77,8 +85,7 @@ public class WxUserIntegralLogServiceImpl implements IWxUserIntegralLogService
* @return
*/
@Override
public int deleteWxUserIntegralLogByIds(Long[] ids)
{
public int deleteWxUserIntegralLogByIds(Long[] ids) {
return wxUserIntegralLogMapper.deleteWxUserIntegralLogByIds(ids);
}
@ -89,8 +96,55 @@ public class WxUserIntegralLogServiceImpl implements IWxUserIntegralLogService
* @return
*/
@Override
public int deleteWxUserIntegralLogById(Long id)
{
public int deleteWxUserIntegralLogById(Long id) {
return wxUserIntegralLogMapper.deleteWxUserIntegralLogById(id);
}
@Override
public void countUserExpireIntegral(List<Long> idList) {
// 1、获取所有用户
List<WxUserMember> wxUserMembers = new ArrayList<>();
if (idList != null && idList.size() > 0) {
for (Long aLong : idList) {
WxUserMember wxUserMember = wxUserMemberMapper.selectWxUserMemberById(aLong);
if (wxUserMember != null) {
wxUserMembers.add(wxUserMember);
}
}
} else {
WxUserMember wxUserMember = new WxUserMember();
wxUserMember.setUserType(1); // 会员
wxUserMember.setStatus(Status.OK.getCode());
wxUserMembers = wxUserMemberMapper.selectWxUserMemberList(wxUserMember);
}
for (WxUserMember userMember : wxUserMembers) {
WxUserIntegralLog query = new WxUserIntegralLog();
query.setUserId(userMember.getId());
// 2、根据用户id获取用户的历史积分记录
// 增加: 时间为 当前时间上一年的最后一天的最后一刻
LocalDateTime queryTime = LocalDateTime.now().minusYears(1).with(TemporalAdjusters.lastDayOfYear()).with(LocalTime.MAX);
query.setCreateTime(Date.from(queryTime.atZone(ZoneId.systemDefault()).toInstant()));
List<WxUserIntegralLog> increaseUserIntegralLogList = wxUserIntegralLogMapper.selectWxUserIntegralLogList(query);
Long increaseIntegral = increaseUserIntegralLogList.stream().filter(wxUserIntegralLog ->
StringUtils.equals(wxUserIntegralLog.getSource(), "1")
).mapToLong(WxUserIntegralLog::getFloatScore).sum();
// 扣减: 时间为当前
query.setCreateTime(null);
List<WxUserIntegralLog> reduceUserIntegralLogList = wxUserIntegralLogMapper.selectWxUserIntegralLogList(query);
Long reduceIntegral = reduceUserIntegralLogList.stream().filter(wxUserIntegralLog ->
StringUtils.equals(wxUserIntegralLog.getSource(), "2")
).mapToLong(WxUserIntegralLog::getFloatScore).sum();
// 3、计算该用户得过期积分并保存到用户信息表得过期积分中
// 当增加的大于扣除的就直接扣减
if (increaseIntegral > reduceIntegral) {
userMember.setExpireCredit(increaseIntegral.intValue() - reduceIntegral.intValue());
} else {
userMember.setExpireCredit(0);
}
wxUserMemberMapper.updateWxUserMember(userMember);
}
}
}

Loading…
Cancel
Save