|
@@ -47,6 +47,12 @@ import com.qunzhixinxi.hnqz.admin.enums.EnableEnum;
|
|
import com.qunzhixinxi.hnqz.admin.enums.PackageTypeEnum;
|
|
import com.qunzhixinxi.hnqz.admin.enums.PackageTypeEnum;
|
|
import com.qunzhixinxi.hnqz.admin.enums.SubjectLocation;
|
|
import com.qunzhixinxi.hnqz.admin.enums.SubjectLocation;
|
|
import com.qunzhixinxi.hnqz.admin.mapper.*;
|
|
import com.qunzhixinxi.hnqz.admin.mapper.*;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.recharge.entity.SysDeptRecharge;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.recharge.entity.SysDeptRechargeRecord;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.recharge.enums.RechargeRecordPackageType;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.recharge.enums.RechargeRecordType;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.recharge.mapper.SysDeptRechargeMapper;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.recharge.mapper.SysDeptRechargeRecordMapper;
|
|
import com.qunzhixinxi.hnqz.admin.service.*;
|
|
import com.qunzhixinxi.hnqz.admin.service.*;
|
|
import com.qunzhixinxi.hnqz.common.core.constant.CommonConstants;
|
|
import com.qunzhixinxi.hnqz.common.core.constant.CommonConstants;
|
|
import com.qunzhixinxi.hnqz.common.core.util.R;
|
|
import com.qunzhixinxi.hnqz.common.core.util.R;
|
|
@@ -112,6 +118,8 @@ public class WmScorePackageController {
|
|
private final WmDaAgentMapper wmDaAgentMapper;
|
|
private final WmDaAgentMapper wmDaAgentMapper;
|
|
private final WmTeamService wmTeamService;
|
|
private final WmTeamService wmTeamService;
|
|
private final WmScorePackageSettleNoteMapper settleNoteMapper;
|
|
private final WmScorePackageSettleNoteMapper settleNoteMapper;
|
|
|
|
+ private final SysDeptRechargeRecordMapper sysDeptRechargeRecordMapper;
|
|
|
|
+ private final SysDeptRechargeMapper sysDeptRechargeMapper;
|
|
private final StringRedisTemplate redisTemplate;
|
|
private final StringRedisTemplate redisTemplate;
|
|
private final Sequence pkgSequence;
|
|
private final Sequence pkgSequence;
|
|
|
|
|
|
@@ -1729,12 +1737,50 @@ public class WmScorePackageController {
|
|
@ApiOperation(value = "新增积分包", notes = "新增积分包")
|
|
@ApiOperation(value = "新增积分包", notes = "新增积分包")
|
|
@SysLog("新增积分包")
|
|
@SysLog("新增积分包")
|
|
@PostMapping("saves")
|
|
@PostMapping("saves")
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
public R saves(@RequestBody WmScorePackage wmScorePackage) {
|
|
public R saves(@RequestBody WmScorePackage wmScorePackage) {
|
|
|
|
|
|
if (wmScorePackage.getScore() <= 0) {
|
|
if (wmScorePackage.getScore() <= 0) {
|
|
return R.failed("积分包分值必须大于0");
|
|
return R.failed("积分包分值必须大于0");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ Integer deptId = SecurityUtils.getUser().getDeptId();
|
|
|
|
+ Integer userId = SecurityUtils.getUser().getId();
|
|
|
|
+
|
|
|
|
+ // 校验 满足以下任一条件,则可以发包
|
|
|
|
+ // 1.存在积分充值配置,并且 发包积分 < 积分充值分配的积分
|
|
|
|
+ // 2.关联了上级积分包
|
|
|
|
+ boolean relatedScoreId = StrUtil.isNotBlank(wmScorePackage.getRelationScoreId()) && Integer.parseInt(wmScorePackage.getRelationScoreId()) > 0;
|
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
|
+ SysDeptRecharge deptRecharge = null;
|
|
|
|
+ int currentScore = 0;
|
|
|
|
+ if (!relatedScoreId) {
|
|
|
|
+ // 校验 发包积分 < 积分充值分配的积分 则可以发包
|
|
|
|
+ deptRecharge = sysDeptRechargeMapper.selectOne(Wrappers.<SysDeptRecharge>lambdaQuery()
|
|
|
|
+ .eq(SysDeptRecharge::getDeptId, deptId));
|
|
|
|
+ if (deptRecharge == null) {
|
|
|
|
+ log.warn("未配置积分充值信息");
|
|
|
|
+ throw new RuntimeException("积分余额:0。积分不足");
|
|
|
|
+ }
|
|
|
|
+ if (wmScorePackage.getScore() > deptRecharge.getScore()) {
|
|
|
|
+ log.warn("已分配积分不足,发包积分={},剩余积分={}", wmScorePackage.getScore(), deptRecharge.getScore());
|
|
|
|
+ throw new RuntimeException(String.format("积分余额:%s。积分不足", deptRecharge.getScore()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 更新积分充值信息
|
|
|
|
+ currentScore = deptRecharge.getScore() - wmScorePackage.getScore();
|
|
|
|
+ int updateRecharge = sysDeptRechargeMapper.update(null, Wrappers.<SysDeptRecharge>lambdaUpdate()
|
|
|
|
+ .eq(SysDeptRecharge::getId, deptRecharge.getId())
|
|
|
|
+ .eq(SysDeptRecharge::getVersion, deptRecharge.getVersion())
|
|
|
|
+ .set(SysDeptRecharge::getScore, currentScore)
|
|
|
|
+ .set(SysDeptRecharge::getVersion, deptRecharge.getVersion() + 1)
|
|
|
|
+ .set(SysDeptRecharge::getUpdateTime, now)
|
|
|
|
+ .set(SysDeptRecharge::getUpdateUser, userId));
|
|
|
|
+ if (updateRecharge <= 0) {
|
|
|
|
+ log.warn("更新积分充值信息失败");
|
|
|
|
+ throw new RuntimeException("操作失败,请重试");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
wmScorePackage.setTypeid("");
|
|
wmScorePackage.setTypeid("");
|
|
wmScorePackage.setPackageType1("1");
|
|
wmScorePackage.setPackageType1("1");
|
|
@@ -1742,11 +1788,11 @@ public class WmScorePackageController {
|
|
wmScorePackage.setEnableFlag("0");
|
|
wmScorePackage.setEnableFlag("0");
|
|
wmScorePackage.setPackageIsConduct("0");
|
|
wmScorePackage.setPackageIsConduct("0");
|
|
wmScorePackage.setDrugEntId("");//药企ID
|
|
wmScorePackage.setDrugEntId("");//药企ID
|
|
- wmScorePackage.setCreateUser(SecurityUtils.getUser().getId());//用户ID
|
|
|
|
|
|
+ wmScorePackage.setCreateUser(userId);//用户ID
|
|
// SysDept sysDeptId = new SysDept();
|
|
// SysDept sysDeptId = new SysDept();
|
|
// sysDeptId.setDeptId(SecurityUtils.getUser().getDeptId());
|
|
// sysDeptId.setDeptId(SecurityUtils.getUser().getDeptId());
|
|
// SysDept sysDept = sysDeptMapper.selectDeptId(sysDeptId);
|
|
// SysDept sysDept = sysDeptMapper.selectDeptId(sysDeptId);
|
|
- SysDept sysDept = sysDeptService.getById(SecurityUtils.getUser().getDeptId());
|
|
|
|
|
|
+ SysDept sysDept = sysDeptService.getById(deptId);
|
|
|
|
|
|
// SysDept sysDeptRelatedServiceId = new SysDept();
|
|
// SysDept sysDeptRelatedServiceId = new SysDept();
|
|
// sysDeptRelatedServiceId.setDeptId(Integer.valueOf(wmScorePackage.getRelatedService()));
|
|
// sysDeptRelatedServiceId.setDeptId(Integer.valueOf(wmScorePackage.getRelatedService()));
|
|
@@ -1994,6 +2040,23 @@ public class WmScorePackageController {
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (!relatedScoreId) {
|
|
|
|
+ // 查询关联操作对象
|
|
|
|
+ // 更新积分充值记录
|
|
|
|
+ SysDeptRechargeRecord rechargeRecord = new SysDeptRechargeRecord();
|
|
|
|
+ rechargeRecord.setDeptId(deptId);
|
|
|
|
+ rechargeRecord.setChangeScore(-wmScorePackage.getScore());
|
|
|
|
+ rechargeRecord.setRechargeId(deptRecharge.getId());
|
|
|
|
+ rechargeRecord.setPackageId(wmScorePackage.getId());
|
|
|
|
+ rechargeRecord.setPackageType(RechargeRecordPackageType.TO_ENTERPRISE);
|
|
|
|
+ rechargeRecord.setType(RechargeRecordType.SEND_PACKAGE_DEPT);
|
|
|
|
+ rechargeRecord.setCurrentScore(currentScore);
|
|
|
|
+ rechargeRecord.setCreateUser(userId);
|
|
|
|
+ rechargeRecord.setCreateTime(now);
|
|
|
|
+ sysDeptRechargeRecordMapper.insert(rechargeRecord);
|
|
|
|
+ }
|
|
|
|
+
|
|
return R.ok();
|
|
return R.ok();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2004,6 +2067,7 @@ public class WmScorePackageController {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@PostMapping("/stopWmScorePackage")
|
|
@PostMapping("/stopWmScorePackage")
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
public R stopWmScorePackage(@RequestBody WmScorePackage wmScorePackage) {
|
|
public R stopWmScorePackage(@RequestBody WmScorePackage wmScorePackage) {
|
|
if (StringUtils.isEmpty(wmScorePackage.getId())) {
|
|
if (StringUtils.isEmpty(wmScorePackage.getId())) {
|
|
return R.failed("参数异常");
|
|
return R.failed("参数异常");
|
|
@@ -2037,6 +2101,73 @@ public class WmScorePackageController {
|
|
updateEntity.setScorePackageStatus("6");
|
|
updateEntity.setScorePackageStatus("6");
|
|
wmScorePackageService.updateById(updateEntity);
|
|
wmScorePackageService.updateById(updateEntity);
|
|
|
|
|
|
|
|
+ // 暂定为 回收可分配积分值
|
|
|
|
+ int recoveryScore = wmScorePackage.getKfpjf();
|
|
|
|
+ Integer userId = SecurityUtils.getUser().getId();
|
|
|
|
+ Integer deptId = SecurityUtils.getUser().getDeptId();
|
|
|
|
+ // 如果是通过积分充值的积分发的包,则回收积分
|
|
|
|
+ SysDeptRechargeRecord rechargeRecord = sysDeptRechargeRecordMapper.selectOne(Wrappers.<SysDeptRechargeRecord>lambdaQuery()
|
|
|
|
+ .eq(SysDeptRechargeRecord::getPackageId, wmScorePackage.getId())
|
|
|
|
+ .in(SysDeptRechargeRecord::getType, RechargeRecordType.SEND_PACKAGE_DEPT, RechargeRecordType.SEND_PACKAGE_PERSONAL));
|
|
|
|
+ if (rechargeRecord != null) {
|
|
|
|
+ log.info("终止积分包,更新积分配置信息");
|
|
|
|
+ SysDeptRecharge deptRecharge = sysDeptRechargeMapper.selectById(rechargeRecord.getRechargeId());
|
|
|
|
+ int currentScore = deptRecharge.getScore() + recoveryScore;
|
|
|
|
+ // 更新企业配置的积分信息
|
|
|
|
+ int update = sysDeptRechargeMapper.update(null, Wrappers.<SysDeptRecharge>lambdaUpdate()
|
|
|
|
+ .eq(SysDeptRecharge::getId, rechargeRecord.getRechargeId())
|
|
|
|
+ .eq(SysDeptRecharge::getVersion, deptRecharge.getVersion())
|
|
|
|
+ .set(SysDeptRecharge::getScore, currentScore)
|
|
|
|
+ .set(SysDeptRecharge::getVersion, deptRecharge.getVersion() + 1)
|
|
|
|
+ .set(SysDeptRecharge::getUpdateUser, userId)
|
|
|
|
+ .set(SysDeptRecharge::getUpdateTime, LocalDateTime.now()));
|
|
|
|
+ if (update <= 0) {
|
|
|
|
+ throw new RuntimeException("更新失败");
|
|
|
|
+ }
|
|
|
|
+ // 新增积分记录
|
|
|
|
+ SysDeptRechargeRecord newRechargeRecord = new SysDeptRechargeRecord();
|
|
|
|
+ newRechargeRecord.setRechargeId(deptRecharge.getId());
|
|
|
|
+ newRechargeRecord.setChangeScore(recoveryScore);
|
|
|
|
+ newRechargeRecord.setCurrentScore(currentScore);
|
|
|
|
+ newRechargeRecord.setType(RechargeRecordType.RECOVERY);
|
|
|
|
+ newRechargeRecord.setDeptId(deptRecharge.getDeptId());
|
|
|
|
+ newRechargeRecord.setRelationDeptId(rechargeRecord.getRelationDeptId());
|
|
|
|
+ newRechargeRecord.setPackageId(wmScorePackage.getId());
|
|
|
|
+ newRechargeRecord.setCreateUser(userId);
|
|
|
|
+ sysDeptRechargeRecordMapper.insert(newRechargeRecord);
|
|
|
|
+ } else {
|
|
|
|
+ // 数据历史处理:如果是源头包,则回收积分包到积分充值余额
|
|
|
|
+ boolean relatedScoreId = StrUtil.isNotBlank(wmScorePackage.getRelationScoreId()) && Integer.parseInt(wmScorePackage.getRelationScoreId()) > 0;
|
|
|
|
+ if (!relatedScoreId) {
|
|
|
|
+ log.info("终止积分包,更新积分配置信息(历史积分包处理)");
|
|
|
|
+ SysDeptRecharge deptRecharge = sysDeptRechargeMapper.selectOne(Wrappers.<SysDeptRecharge>lambdaQuery()
|
|
|
|
+ .eq(SysDeptRecharge::getDeptId, deptId));
|
|
|
|
+ int currentScore = deptRecharge.getScore() + recoveryScore;
|
|
|
|
+ // 更新企业配置的积分信息
|
|
|
|
+ int update = sysDeptRechargeMapper.update(null, Wrappers.<SysDeptRecharge>lambdaUpdate()
|
|
|
|
+ .eq(SysDeptRecharge::getId, deptRecharge.getId())
|
|
|
|
+ .eq(SysDeptRecharge::getVersion, deptRecharge.getVersion())
|
|
|
|
+ .set(SysDeptRecharge::getScore, currentScore)
|
|
|
|
+ .set(SysDeptRecharge::getVersion, deptRecharge.getVersion() + 1)
|
|
|
|
+ .set(SysDeptRecharge::getUpdateUser, userId)
|
|
|
|
+ .set(SysDeptRecharge::getUpdateTime, LocalDateTime.now()));
|
|
|
|
+ if (update <= 0) {
|
|
|
|
+ throw new RuntimeException("更新失败");
|
|
|
|
+ }
|
|
|
|
+ // 新增积分记录
|
|
|
|
+ SysDeptRechargeRecord newRechargeRecord = new SysDeptRechargeRecord();
|
|
|
|
+ newRechargeRecord.setRechargeId(deptRecharge.getId());
|
|
|
|
+ newRechargeRecord.setChangeScore(recoveryScore);
|
|
|
|
+ newRechargeRecord.setCurrentScore(currentScore);
|
|
|
|
+ newRechargeRecord.setType(RechargeRecordType.RECOVERY);
|
|
|
|
+ newRechargeRecord.setDeptId(deptRecharge.getDeptId());
|
|
|
|
+ newRechargeRecord.setPackageId(wmScorePackage.getId());
|
|
|
|
+ newRechargeRecord.setCreateUser(userId);
|
|
|
|
+ sysDeptRechargeRecordMapper.insert(newRechargeRecord);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
return R.ok();
|
|
return R.ok();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2169,6 +2300,7 @@ public class WmScorePackageController {
|
|
@ApiOperation(value = "修改积分包", notes = "修改积分包")
|
|
@ApiOperation(value = "修改积分包", notes = "修改积分包")
|
|
@SysLog("修改积分包")
|
|
@SysLog("修改积分包")
|
|
@PostMapping("/updateByIds")
|
|
@PostMapping("/updateByIds")
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
public R updateByIds(@RequestBody WmScorePackage wmScorePackage) {
|
|
public R updateByIds(@RequestBody WmScorePackage wmScorePackage) {
|
|
if (wmScorePackage.getScore() <= 0) {
|
|
if (wmScorePackage.getScore() <= 0) {
|
|
return R.failed("积分包分值必须大于0");
|
|
return R.failed("积分包分值必须大于0");
|
|
@@ -2507,8 +2639,65 @@ public class WmScorePackageController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 查询原积分包值
|
|
|
|
+ int oldPackageScore = wmScorePackageService.getById(wmScorePackage.getId()).getScore();
|
|
|
|
|
|
- return R.ok(wmScorePackageService.updateById(wmScorePackage));
|
|
|
|
|
|
+ wmScorePackageService.updateById(wmScorePackage);
|
|
|
|
+
|
|
|
|
+ Integer deptId = SecurityUtils.getUser().getDeptId();
|
|
|
|
+ Integer userId = SecurityUtils.getUser().getId();
|
|
|
|
+ // 如果是通过积分充值的积分发的包,则回收积分
|
|
|
|
+ SysDeptRechargeRecord rechargeRecord = sysDeptRechargeRecordMapper.selectOne(Wrappers.<SysDeptRechargeRecord>lambdaQuery()
|
|
|
|
+ .eq(SysDeptRechargeRecord::getPackageId, wmScorePackage.getId())
|
|
|
|
+ .in(SysDeptRechargeRecord::getType, RechargeRecordType.SEND_PACKAGE_DEPT, RechargeRecordType.SEND_PACKAGE_PERSONAL));
|
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
|
+ if (rechargeRecord != null) {
|
|
|
|
+ log.info("修改积分包,更新积分配置信息");
|
|
|
|
+ // 校验 发包积分 < 积分充值分配的积分 则可以发包
|
|
|
|
+ SysDeptRecharge deptRecharge = sysDeptRechargeMapper.selectOne(Wrappers.<SysDeptRecharge>lambdaQuery()
|
|
|
|
+ .eq(SysDeptRecharge::getDeptId, deptId));
|
|
|
|
+ if (deptRecharge == null) {
|
|
|
|
+ log.warn("未配置积分充值信息");
|
|
|
|
+ throw new RuntimeException("积分余额:0。积分不足");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 积分值相比修改前的变动(相对于积分余额,增加则为负-消耗,减少则为正-回收)
|
|
|
|
+ int changeScore = oldPackageScore - wmScorePackage.getScore();
|
|
|
|
+ int currentScore = deptRecharge.getScore() + changeScore;
|
|
|
|
+
|
|
|
|
+ if (changeScore > deptRecharge.getScore()) {
|
|
|
|
+ log.warn("已分配积分不足,发包积分={},剩余积分={}", wmScorePackage.getScore(), deptRecharge.getScore());
|
|
|
|
+ throw new RuntimeException(String.format("积分余额:%s。积分不足", deptRecharge.getScore()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 更新积分充值信息
|
|
|
|
+ int updateRecharge = sysDeptRechargeMapper.update(null, Wrappers.<SysDeptRecharge>lambdaUpdate()
|
|
|
|
+ .eq(SysDeptRecharge::getId, deptRecharge.getId())
|
|
|
|
+ .eq(SysDeptRecharge::getVersion, deptRecharge.getVersion())
|
|
|
|
+ .set(SysDeptRecharge::getScore, currentScore)
|
|
|
|
+ .set(SysDeptRecharge::getVersion, deptRecharge.getVersion() + 1)
|
|
|
|
+ .set(SysDeptRecharge::getUpdateTime, now)
|
|
|
|
+ .set(SysDeptRecharge::getUpdateUser, userId));
|
|
|
|
+ if (updateRecharge <= 0) {
|
|
|
|
+ log.warn("更新大包积分充值信息失败");
|
|
|
|
+ throw new RuntimeException("操作失败,请重试");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 更新积分充值记录
|
|
|
|
+ SysDeptRechargeRecord newRechargeRecord = new SysDeptRechargeRecord();
|
|
|
|
+ newRechargeRecord.setRechargeId(deptRecharge.getId());
|
|
|
|
+ newRechargeRecord.setChangeScore(changeScore);
|
|
|
|
+ newRechargeRecord.setCurrentScore(currentScore);
|
|
|
|
+ newRechargeRecord.setType(RechargeRecordType.RECOVERY);
|
|
|
|
+ newRechargeRecord.setDeptId(deptRecharge.getDeptId());
|
|
|
|
+ newRechargeRecord.setRelationDeptId(rechargeRecord.getRelationDeptId());
|
|
|
|
+ newRechargeRecord.setPackageType(RechargeRecordPackageType.TO_ENTERPRISE);
|
|
|
|
+ newRechargeRecord.setPackageId(wmScorePackage.getId());
|
|
|
|
+ newRechargeRecord.setCreateUser(userId);
|
|
|
|
+ sysDeptRechargeRecordMapper.insert(newRechargeRecord);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return R.ok(Boolean.TRUE);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|