From 392687454701162a053957d72579cbb3897bfd63 Mon Sep 17 00:00:00 2001
From: "382696293@qq.com" <382696293@qq.com>
Date: Wed, 27 Dec 2023 14:11:33 +0800
Subject: [PATCH] =?UTF-8?q?=E8=AE=A1=E7=AE=97=E8=BF=87=E6=9C=9F=E7=A7=AF?=
=?UTF-8?q?=E5=88=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../mapper/WxUserIntegralLogMapper.xml | 3 +
.../WxUserIntegralLogController.java | 42 +++++-----
.../service/IWxUserIntegralLogService.java | 3 +
.../impl/WxUserIntegralLogServiceImpl.java | 82 +++++++++++++++----
4 files changed, 93 insertions(+), 37 deletions(-)
diff --git a/flossom-common/flossom-common-core/src/main/resources/mapper/WxUserIntegralLogMapper.xml b/flossom-common/flossom-common-core/src/main/resources/mapper/WxUserIntegralLogMapper.xml
index 81ff59f..088eb9c 100644
--- a/flossom-common/flossom-common-core/src/main/resources/mapper/WxUserIntegralLogMapper.xml
+++ b/flossom-common/flossom-common-core/src/main/resources/mapper/WxUserIntegralLogMapper.xml
@@ -31,6 +31,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and float_score = #{floatScore}
and soure_id = #{soureId}
and remark_content = #{remarkContent}
+
+ and create_time <= #{createTime}
+
diff --git a/flossom-modules/flossom-system/src/main/java/com/flossom/system/controller/WxUserIntegralLogController.java b/flossom-modules/flossom-system/src/main/java/com/flossom/system/controller/WxUserIntegralLogController.java
index 6f6486c..3eda269 100644
--- a/flossom-modules/flossom-system/src/main/java/com/flossom/system/controller/WxUserIntegralLogController.java
+++ b/flossom-modules/flossom-system/src/main/java/com/flossom/system/controller/WxUserIntegralLogController.java
@@ -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 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 list = wxUserIntegralLogService.selectWxUserIntegralLogList(wxUserIntegralLog);
ExcelUtil util = new ExcelUtil(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 idList) {
+ wxUserIntegralLogService.countUserExpireIntegral(idList);
+ return R.ok();
+ }
}
diff --git a/flossom-modules/flossom-system/src/main/java/com/flossom/system/service/IWxUserIntegralLogService.java b/flossom-modules/flossom-system/src/main/java/com/flossom/system/service/IWxUserIntegralLogService.java
index 1198613..9a35411 100644
--- a/flossom-modules/flossom-system/src/main/java/com/flossom/system/service/IWxUserIntegralLogService.java
+++ b/flossom-modules/flossom-system/src/main/java/com/flossom/system/service/IWxUserIntegralLogService.java
@@ -59,4 +59,7 @@ public interface IWxUserIntegralLogService
* @return 结果
*/
public int deleteWxUserIntegralLogById(Long id);
+
+ void countUserExpireIntegral(List idList);
+
}
diff --git a/flossom-modules/flossom-system/src/main/java/com/flossom/system/service/impl/WxUserIntegralLogServiceImpl.java b/flossom-modules/flossom-system/src/main/java/com/flossom/system/service/impl/WxUserIntegralLogServiceImpl.java
index f490869..b3be038 100644
--- a/flossom-modules/flossom-system/src/main/java/com/flossom/system/service/impl/WxUserIntegralLogServiceImpl.java
+++ b/flossom-modules/flossom-system/src/main/java/com/flossom/system/service/impl/WxUserIntegralLogServiceImpl.java
@@ -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 selectWxUserIntegralLogList(WxUserIntegralLog wxUserIntegralLog)
- {
+ public List 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 idList) {
+ // 1、获取所有用户
+ List 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 increaseUserIntegralLogList = wxUserIntegralLogMapper.selectWxUserIntegralLogList(query);
+ Long increaseIntegral = increaseUserIntegralLogList.stream().filter(wxUserIntegralLog ->
+ StringUtils.equals(wxUserIntegralLog.getSource(), "1")
+ ).mapToLong(WxUserIntegralLog::getFloatScore).sum();
+
+ // 扣减: 时间为当前
+ query.setCreateTime(null);
+ List 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);
+ }
+ }
}