|
@@ -1,12 +1,16 @@
|
|
|
package com.rongwei.bscommon.system.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.rongwei.bscommon.system.dao.QhseContractWorkersDao;
|
|
|
import com.rongwei.bscommon.system.service.PointService;
|
|
|
import com.rongwei.bscommon.system.service.QhsePointsRedemptionService;
|
|
|
import com.rongwei.bscommon.system.utils.QHSEUtils;
|
|
|
import com.rongwei.bsentity.domain.*;
|
|
|
+import com.rongwei.bsentity.dto.UserPointRegister;
|
|
|
import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
|
+import com.rongwei.rwcommon.base.BaseDo;
|
|
|
import com.rongwei.rwcommon.base.R;
|
|
|
import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
import com.rongwei.rwcommon.utils.StringUtils;
|
|
@@ -14,9 +18,14 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
import java.time.LocalDate;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* PointServiceImpl class
|
|
@@ -34,11 +43,8 @@ public class PointServiceImpl implements PointService {
|
|
|
private QhsePointsRecordUserServiceImpl qhsePointsRecordUserService;
|
|
|
@Autowired
|
|
|
private QhseContractWorkersDao qhseContractWorkersDao;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private QhsePointsDetailsUserServiceImpl qhsePointsDetailsUserService;
|
|
|
|
|
|
@Override
|
|
|
public R userPointExchange(String id) {
|
|
@@ -58,6 +64,10 @@ public class PointServiceImpl implements PointService {
|
|
|
log.error("无法根据ID:{}获取到用户积分信息", mainid);
|
|
|
return R.error("无法获取用户积分信息");
|
|
|
}
|
|
|
+ if (pointsRecordUserDo.getCurrentpoint() <= 100) {
|
|
|
+ log.error("当前可用积分为0");
|
|
|
+ return R.error("当前用户可用积分为0");
|
|
|
+ }
|
|
|
SysUserVo currentUser = QHSEUtils.getCurrentUser();
|
|
|
// 本次兑换使用的积分
|
|
|
int usepoints = redemptionDo.getUsepoints() == null ? 0 : redemptionDo.getUsepoints();
|
|
@@ -77,7 +87,7 @@ public class PointServiceImpl implements PointService {
|
|
|
}
|
|
|
SysUserVo currentUser = QHSEUtils.getCurrentUser();
|
|
|
QhsePointsRecordUserDo qhsePointsRecordUserDo;
|
|
|
- List<QhsePointsRecordUserDo> saveList= new ArrayList<>(uninitializedData.size());
|
|
|
+ List<QhsePointsRecordUserDo> saveList = new ArrayList<>(uninitializedData.size());
|
|
|
for (QhseContractWorkersDo uninitializedDatum : uninitializedData) {
|
|
|
qhsePointsRecordUserDo = new QhsePointsRecordUserDo();
|
|
|
QHSEUtils.initModelGeneralParameters(qhsePointsRecordUserDo, currentUser);
|
|
@@ -101,4 +111,131 @@ public class PointServiceImpl implements PointService {
|
|
|
return R.ok("生成成功");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 用户积分登记
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public R userPointEegister(List<String> ids) {
|
|
|
+ if (ids.isEmpty() || ids.stream().allMatch(StringUtils::isBlank)) {
|
|
|
+ log.error("加扣分信息ID为空");
|
|
|
+ return R.error("参数异常");
|
|
|
+ }
|
|
|
+ List<QhsePointsDetailsUserDo> pointsDetailsUserDos = qhsePointsDetailsUserService.list(new LambdaQueryWrapper<QhsePointsDetailsUserDo>()
|
|
|
+ .eq(QhsePointsDetailsUserDo::getState, 0).in(QhsePointsDetailsUserDo::getId, ids));
|
|
|
+ if (pointsDetailsUserDos.isEmpty()) {
|
|
|
+ log.error("无法通过id:{}获取到对应的加扣分记录", ids);
|
|
|
+ return R.error("无法获取加扣分信息");
|
|
|
+ }
|
|
|
+ // 按照人员积分记录分组
|
|
|
+ Map<String, List<QhsePointsDetailsUserDo>> dataGroupByMainId = pointsDetailsUserDos.stream()
|
|
|
+ .collect(Collectors.groupingBy(QhsePointsDetailsUserDo::getMainid));
|
|
|
+ List<UserPointRegister> saveList = new ArrayList<>();
|
|
|
+
|
|
|
+ dataGroupByMainId.forEach((mainId, ponitList) -> {
|
|
|
+ // 对相同用户的加扣分按照 大于0 小于0 等于0 分组
|
|
|
+ Map<Integer, Integer> dataGroupByPointType = ponitList.stream()
|
|
|
+ .collect(Collectors.groupingBy(item -> {
|
|
|
+ // 自定义分组规则
|
|
|
+ if (item.getPoints() > 0) return 1; // 大于0
|
|
|
+ else if (item.getPoints() < 0) return -1; // 小于0
|
|
|
+ else return 0; // 等于0
|
|
|
+ }, Collectors.summingInt(QhsePointsDetailsUserDo::getPoints)));
|
|
|
+ UserPointRegister userPointRegister = new UserPointRegister();
|
|
|
+ int currentUserPoint = ponitList.stream().mapToInt(QhsePointsDetailsUserDo::getPoints).sum();
|
|
|
+ userPointRegister.setId(mainId);
|
|
|
+ userPointRegister.setPoint(currentUserPoint);
|
|
|
+ userPointRegister.setBonusPoint(dataGroupByPointType.getOrDefault(1, 0));
|
|
|
+ userPointRegister.setDeductPoint(dataGroupByPointType.getOrDefault(-1, 0));
|
|
|
+ saveList.add(userPointRegister);
|
|
|
+ });
|
|
|
+ SysUserVo currentUser = QHSEUtils.getCurrentUser();
|
|
|
+ // 数据保存
|
|
|
+ qhsePointsRecordUserService.getBaseMapper().saveUserPoint(saveList, currentUser);
|
|
|
+ qhsePointsDetailsUserService.update(new LambdaUpdateWrapper<QhsePointsDetailsUserDo>()
|
|
|
+ .in(QhsePointsDetailsUserDo::getId, ids)
|
|
|
+ .set(QhsePointsDetailsUserDo::getState, 1)
|
|
|
+ .set(BaseDo::getModifydate, new Date())
|
|
|
+ .set(BaseDo::getModifyuserid, currentUser.getId())
|
|
|
+ .set(BaseDo::getModifyusername, currentUser.getName())
|
|
|
+ );
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户扣分记录删除
|
|
|
+ *
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public R userPointRemove(List<String> ids) {
|
|
|
+ List<QhsePointsDetailsUserDo> qhsePointsDetailsUserDos = qhsePointsDetailsUserService.list(new LambdaQueryWrapper<QhsePointsDetailsUserDo>()
|
|
|
+ .eq(QhsePointsDetailsUserDo::getState, 1).in(QhsePointsDetailsUserDo::getId, ids));
|
|
|
+ if (qhsePointsDetailsUserDos.isEmpty()) {
|
|
|
+ log.error("无法获取用户积分信息");
|
|
|
+ return R.error("参数异常");
|
|
|
+ }
|
|
|
+ // 获取用户所选择的扣分记录信息
|
|
|
+ List<String> userRecordId = qhsePointsDetailsUserDos.stream().map(QhsePointsDetailsUserDo::getMainid).distinct().collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<QhsePointsRecordUserDo> qhsePointsUnitRecordDos = qhsePointsRecordUserService.getBaseMapper().selectBatchIds(userRecordId);
|
|
|
+
|
|
|
+
|
|
|
+ // 需要处理用户积分的加扣分数据
|
|
|
+ List<QhsePointsDetailsUserDo> dataToModifyScore;
|
|
|
+ List<QhsePointsRecordUserDo> dataUpdateList = new ArrayList<>();
|
|
|
+ QhsePointsRecordUserDo updateDo;
|
|
|
+ SysUserVo currentUser = QHSEUtils.getCurrentUser();
|
|
|
+
|
|
|
+ for (QhsePointsRecordUserDo qhsePointsRecordUserDo : qhsePointsUnitRecordDos) {
|
|
|
+ // 最近一次积分重置时间
|
|
|
+ Date resetRime = qhsePointsRecordUserDo.getResettime();
|
|
|
+ updateDo = new QhsePointsRecordUserDo();
|
|
|
+ updateDo.setId(qhsePointsRecordUserDo.getId());
|
|
|
+ // 默认当前分数不变
|
|
|
+ updateDo.setCurrentpoint(0);
|
|
|
+ // 扣分
|
|
|
+ updateDo.setDeductpoints(0);
|
|
|
+ //加分
|
|
|
+ updateDo.setBonuspoints(0);
|
|
|
+ updateDo.setModifyuserid(currentUser.getId());
|
|
|
+ updateDo.setModifyusername(currentUser.getName());
|
|
|
+
|
|
|
+ dataToModifyScore = qhsePointsDetailsUserDos.stream().filter(data -> data.getMainid().equals(qhsePointsRecordUserDo.getId())).collect(Collectors.toList());
|
|
|
+ if (resetRime == null) {
|
|
|
+ // 1. 没有重置过的时候 更新 当前分数 以及对应用户的加扣分数量
|
|
|
+ updateDo.setCurrentpoint(dataToModifyScore.stream().mapToInt(data -> -data.getPoints()).sum());
|
|
|
+ updateDo.setDeductpoints(dataToModifyScore.stream().filter(data -> data.getPoints() < 0).mapToInt(data -> -data.getPoints()).sum());
|
|
|
+ updateDo.setBonuspoints(dataToModifyScore.stream().filter(data -> data.getPoints() > 0).mapToInt(data -> -data.getPoints()).sum());
|
|
|
+ } else {
|
|
|
+ // 2. 本次积分在重置之前 不更新当前分数 更新当前用户的加扣分记录
|
|
|
+ dataToModifyScore = dataToModifyScore.stream().filter(data -> resetRime.after(data.getCreatedate())).collect(Collectors.toList());
|
|
|
+ if (!dataToModifyScore.isEmpty()) {
|
|
|
+ // 重置时间 大于加扣分登记的创建时间
|
|
|
+ updateDo.setDeductpoints(dataToModifyScore.stream().filter(data -> data.getPoints() < 0).mapToInt(data -> -data.getPoints()).sum());
|
|
|
+ updateDo.setBonuspoints(dataToModifyScore.stream().filter(data -> data.getPoints() > 0).mapToInt(data -> -data.getPoints()).sum());
|
|
|
+ }
|
|
|
+
|
|
|
+ dataToModifyScore = dataToModifyScore.stream().filter(data -> resetRime.before(data.getCreatedate())).collect(Collectors.toList());
|
|
|
+ if (!dataToModifyScore.isEmpty()) {
|
|
|
+ // 重置时间 小于加扣分登记的创建时间
|
|
|
+ updateDo.setCurrentpoint(dataToModifyScore.stream().mapToInt(data -> -data.getPoints()).sum());
|
|
|
+ updateDo.setDeductpoints(dataToModifyScore.stream().filter(data -> data.getPoints() < 0).mapToInt(data -> -data.getPoints()).sum());
|
|
|
+ updateDo.setBonuspoints(dataToModifyScore.stream().filter(data -> data.getPoints() > 0).mapToInt(data -> -data.getPoints()).sum());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dataUpdateList.add(updateDo);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 用户扣分记录删除
|
|
|
+ qhsePointsDetailsUserService.removeByIds(ids);
|
|
|
+ if (!dataUpdateList.isEmpty()) {
|
|
|
+ qhsePointsRecordUserService.getBaseMapper().updateDataAfterDeletion(dataUpdateList);
|
|
|
+ }
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
}
|