use of com.bc.pmpheep.back.po.WriterPointLog in project pmph by BCSquad.
the class WriterPointLogServiceImpl method addWriterPointLogByRuleName.
@Override
public void addWriterPointLogByRuleName(String ruleName, Long userId) throws CheckedServiceException {
if (StringUtil.isEmpty(ruleName)) {
throw new CheckedServiceException(CheckedExceptionBusiness.WRITER_POINT_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "规则名称为空");
}
if (ObjectUtil.isNull(userId)) {
throw new CheckedServiceException(CheckedExceptionBusiness.WRITER_POINT_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "作者Id为空");
}
// 获取积分规则
WriterPointRule writerPointRuleVOs = writerPointRuleService.getWriterPointRuleByName(ruleName);
if (null != writerPointRuleVOs) {
if (writerPointRuleVOs.getIsDisabled() == false) {
// 查询用户之前的积分值
List<WriterPointLog> writerPointLog2 = this.getWriterPointLogByUserId(userId);
WriterPointLog writerPointLog = new WriterPointLog();
// 现在的规则的积分值+以前的积分
// 获取的总积分
Integer temp = 0;
if (!writerPointLog2.isEmpty()) {
// 以前的总积分
Integer newTemp = 0;
// 遍历以前获取的积分
for (WriterPointLog writerPointLogNew : writerPointLog2) {
newTemp += writerPointLogNew.getPoint();
}
temp = writerPointRuleVOs.getPoint() + newTemp;
} else {
temp = writerPointRuleVOs.getPoint();
}
writerPointLog.setPoint(writerPointRuleVOs.getPoint());
// 积分规则id
writerPointLog.setRuleId(writerPointRuleVOs.getId());
writerPointLog.setUserId(userId);
// 增加积分记录
this.add(writerPointLog);
// 查询用户积分
WriterPoint point = writerPointService.getWriterPointByUserId(userId);
if (ObjectUtil.notNull(point)) {
writerPointService.updateWriterPoint(new WriterPoint(point.getId(), userId, temp + point.getLoss(), temp, point.getLoss()));
} else {
writerPointService.addWriterPoint(new WriterPoint(userId, temp, temp, 0));
}
}
}
}
Aggregations