Commit 972f23e9 by “Kongxiangkun”

增加积分商城相关代码

parent 5f0b83f7
...@@ -43,4 +43,10 @@ public interface PointApiFeignClients { ...@@ -43,4 +43,10 @@ public interface PointApiFeignClients {
boolean readFinished( boolean readFinished(
@RequestParam(name = "accountId" ,required = false ) Long accountId, @RequestParam(name = "accountId" ,required = false ) Long accountId,
@RequestParam(name = "infoId" ,required = false ) String infoId); @RequestParam(name = "infoId" ,required = false ) String infoId);
@GetMapping("/addPoint")
boolean addPoint(
@RequestParam(name = "accountId" ,required = false ) Long accountId,
@RequestParam(name = "type" ,required = false ) String type,
@RequestParam(name = "sourceId" ,required = false ) String sourceId);
} }
...@@ -21,4 +21,10 @@ public interface PointFeignClients { ...@@ -21,4 +21,10 @@ public interface PointFeignClients {
@PostMapping("/manage/point/strategy/update") @PostMapping("/manage/point/strategy/update")
boolean updateList(@RequestBody PointVo point); boolean updateList(@RequestBody PointVo point);
@GetMapping("/manage/point/addPoint")
boolean addPoint(
@RequestParam(name = "accountId" ,required = false ) Long accountId,
@RequestParam(name = "type" ,required = false ) String type,
@RequestParam(name = "sourceId" ,required = false ) String sourceId);
} }
...@@ -25,7 +25,7 @@ public enum PointTypeEnum { ...@@ -25,7 +25,7 @@ public enum PointTypeEnum {
/** /**
* 参加活动 * 参加活动
*/ */
ACITVITY("point_acitvity", "参加活动", 3), ACITVITY("point_activity", "参加活动", 3),
/** /**
* 培训测试 * 培训测试
......
...@@ -79,5 +79,18 @@ public class PointApiController { ...@@ -79,5 +79,18 @@ public class PointApiController {
pointService.addPoint(accountId, "point_read", infoId); pointService.addPoint(accountId, "point_read", infoId);
return true; return true;
} }
@GetMapping("/addPoint")
public boolean addPoint(
@RequestParam(name = "accountId" ,required = false ) Long accountId,
@RequestParam(name = "type" ,required = false ) String type,
@RequestParam(name = "sourceId" ,required = false ) String sourceId) {
try {
pointService.addPoint(accountId, type, sourceId);
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
} }
...@@ -147,6 +147,13 @@ public class PointController { ...@@ -147,6 +147,13 @@ public class PointController {
return page; return page;
} }
@GetMapping("/addPoint")
public boolean addPoint(
@RequestParam(name = "accountId" ,required = false ) Long accountId,
@RequestParam(name = "type" ,required = false ) String type,
@RequestParam(name = "sourceId" ,required = false ) String sourceId) {
pointService.addPoint(accountId, type, sourceId);
return true;
}
} }
...@@ -83,113 +83,113 @@ public class PointListenerController { ...@@ -83,113 +83,113 @@ public class PointListenerController {
// 处理积分 // 处理积分
public boolean handPoint(MqPointParam vo) { public boolean handPoint(MqPointParam vo) {
if (vo == null) { // if (vo == null) {
LOGGER.info("消息ID{}获取不到缓存信息"); // LOGGER.info("消息ID{}获取不到缓存信息");
return false; // return false;
} // }
String pointId = vo.getId(); // String pointId = vo.getId();
try { // try {
if (null == pointId) { // if (null == pointId) {
LOGGER.info("积分MQId为空"); // LOGGER.info("积分MQId为空");
return false; // return false;
} // }
//
LOGGER.info("开始处理消息ID{},业务ID{} 的积分", pointId, vo.getSourceId()); // LOGGER.info("开始处理消息ID{},业务ID{} 的积分", pointId, vo.getSourceId());
Map<String, Object> map = new HashMap<String, Object>(); // Map<String, Object> map = new HashMap<String, Object>();
map.put("learn_source_id", vo.getSourceId()); // map.put("learn_source_id", vo.getSourceId());
map.put("account_id", vo.getAccountId()); // map.put("account_id", vo.getAccountId());
List<PointDetails> selectByMap = pointDetailsService.selectByMap(map); // List<PointDetails> selectByMap = pointDetailsService.selectByMap(map);
String eventName = vo.getEventName(); // String eventName = vo.getEventName();
if (vo.getOperatingPoint() == null || vo.getOperatingPoint() == 0) { // if (vo.getOperatingPoint() == null || vo.getOperatingPoint() == 0) {
LOGGER.info("不产生0或空的积分,学员ID{},业务单据{}", vo.getAccountId(), vo.getSourceId()); // LOGGER.info("不产生0或空的积分,学员ID{},业务单据{}", vo.getAccountId(), vo.getSourceId());
return false; // return false;
} // }
if (eventName.equals(PointEventEnum.POINTCOURSE.getKey())) { // 课程 // if (eventName.equals(PointEventEnum.POINTCOURSE.getKey())) { // 课程
if (selectByMap.size() == 0 || selectByMap == null) { // if (selectByMap.size() == 0 || selectByMap == null) {
addHandPoint(pointId, vo); // addHandPoint(pointId, vo);
} // }
} else if (eventName.equals(PointEventEnum.POINTEXAM.getKey())) { // 考试 // } else if (eventName.equals(PointEventEnum.POINTEXAM.getKey())) { // 考试
if (selectByMap.size() == 0 || selectByMap == null) { // if (selectByMap.size() == 0 || selectByMap == null) {
addHandPoint(pointId, vo); // addHandPoint(pointId, vo);
} else { // } else {
addExamPoint(pointId, vo, selectByMap); // addExamPoint(pointId, vo, selectByMap);
} // }
} else if (eventName.equals(PointEventEnum.POINTRESEARCH.getKey())) { // 调研 // } else if (eventName.equals(PointEventEnum.POINTRESEARCH.getKey())) { // 调研
if (selectByMap.size() == 0 || selectByMap == null) { // if (selectByMap.size() == 0 || selectByMap == null) {
addHandPoint(pointId, vo); // addHandPoint(pointId, vo);
} // }
} else if (eventName.equals(PointEventEnum.POINTVOTE.getKey())) { // 投票 // } else if (eventName.equals(PointEventEnum.POINTVOTE.getKey())) { // 投票
if (selectByMap.size() == 0 || selectByMap == null) { // if (selectByMap.size() == 0 || selectByMap == null) {
addHandPoint(pointId, vo); // addHandPoint(pointId, vo);
} // }
} else if (eventName.equals(PointEventEnum.POINTASSIGNMENT.getKey())) { // 作业 // } else if (eventName.equals(PointEventEnum.POINTASSIGNMENT.getKey())) { // 作业
if (selectByMap.size() == 0 || selectByMap == null) { // if (selectByMap.size() == 0 || selectByMap == null) {
addHandPoint(pointId, vo); // addHandPoint(pointId, vo);
} // }
} else if (eventName.equals(PointEventEnum.POINTCOURSETEST.getKey())) { // 测验 // } else if (eventName.equals(PointEventEnum.POINTCOURSETEST.getKey())) { // 测验
if (selectByMap.size() == 0 || selectByMap == null) { // if (selectByMap.size() == 0 || selectByMap == null) {
addHandPoint(pointId, vo); // addHandPoint(pointId, vo);
} // }
} else if (eventName.equals(PointEventEnum.POINTOFFLINECOURSE.getKey())) { // 线下课程 // } else if (eventName.equals(PointEventEnum.POINTOFFLINECOURSE.getKey())) { // 线下课程
// 获得对应的记录以及积分,多则补总积分,少则减积分,并删除这条记录,添加导入的记录 // // 获得对应的记录以及积分,多则补总积分,少则减积分,并删除这条记录,添加导入的记录
addCoursePoint(pointId, vo, selectByMap); // addCoursePoint(pointId, vo, selectByMap);
} else if (eventName.equals(PointEventEnum.POINTTRAININGPROJECT.getKey())) { // 培训项目 // } else if (eventName.equals(PointEventEnum.POINTTRAININGPROJECT.getKey())) { // 培训项目
if (selectByMap.size() == 0 || selectByMap == null) { // if (selectByMap.size() == 0 || selectByMap == null) {
addHandPoint(pointId, vo); // addHandPoint(pointId, vo);
} // }
/** // /**
* 案例活动 // * 案例活动
*/ // */
} else if (eventName.equals(PointEventEnum.POINTCASELIBRARY.getKey())) { // } else if (eventName.equals(PointEventEnum.POINTCASELIBRARY.getKey())) {
if (selectByMap.size() == 0 || selectByMap == null) { // if (selectByMap.size() == 0 || selectByMap == null) {
addHandPoint(pointId, vo); // addHandPoint(pointId, vo);
} // }
/** // /**
* 签到打卡 // * 签到打卡
*/ // */
} else if (eventName.equals(PointEventEnum.POINTSIGN.getKey())) { // } else if (eventName.equals(PointEventEnum.POINTSIGN.getKey())) {
if (selectByMap.size() == 0 || selectByMap == null) { // if (selectByMap.size() == 0 || selectByMap == null) {
addHandPoint(pointId, vo); // addHandPoint(pointId, vo);
} // }
/** // /**
* 论坛发贴/评论 // * 论坛发贴/评论
*/ // */
} else if (eventName.equals(PointEventEnum.POINTFORUM.getKey())) { // } else if (eventName.equals(PointEventEnum.POINTFORUM.getKey())) {
if (selectByMap.size() == 0 || selectByMap == null) { // if (selectByMap.size() == 0 || selectByMap == null) {
addHandPoint(pointId, vo); // addHandPoint(pointId, vo);
} // }
/** // /**
* 项目签到 // * 项目签到
*/ // */
} else if (eventName.equals(PointEventEnum.POINTPROJECTSIGN.getKey())) { // } else if (eventName.equals(PointEventEnum.POINTPROJECTSIGN.getKey())) {
if (selectByMap.size() == 0 || selectByMap == null) { // if (selectByMap.size() == 0 || selectByMap == null) {
addHandPoint(pointId, vo); // addHandPoint(pointId, vo);
} // }
/** // /**
* 智能演练 // * 智能演练
*/ // */
} else if (eventName.equals(PointEventEnum.CHAPPRACTICE.getKey())) { // } else if (eventName.equals(PointEventEnum.CHAPPRACTICE.getKey())) {
if (selectByMap.size() == 0 || selectByMap == null) { // if (selectByMap.size() == 0 || selectByMap == null) {
addHandPoint(pointId, vo); // addHandPoint(pointId, vo);
} // }
}else{ // }else{
if (selectByMap.size() == 0 || selectByMap == null) { // if (selectByMap.size() == 0 || selectByMap == null) {
addHandPoint(pointId, vo); // addHandPoint(pointId, vo);
} // }
} // }
try { // try {
vo.setState(0); // vo.setState(0);
mqPointParamService.updateById(vo); // mqPointParamService.updateById(vo);
redisUtils.remove(pointId); // redisUtils.remove(pointId);
} catch (Exception e) { // } catch (Exception e) {
LOGGER.error("删除积分缓存失败{}", pointId); // LOGGER.error("删除积分缓存失败{}", pointId);
e.printStackTrace(); // e.printStackTrace();
} // }
LOGGER.info("完成处理消息ID{},业务ID{} 的积分", pointId, vo.getSourceId()); // LOGGER.info("完成处理消息ID{},业务ID{} 的积分", pointId, vo.getSourceId());
} catch (Exception e) { // } catch (Exception e) {
LOGGER.error("添加积分异常消息ID{}, 业务单据ID{},异常信息{}", pointId, vo.getSourceId(), e); // LOGGER.error("添加积分异常消息ID{}, 业务单据ID{},异常信息{}", pointId, vo.getSourceId(), e);
// e.printStackTrace(); // // e.printStackTrace();
} // }
return true; return true;
} }
......
...@@ -24,4 +24,5 @@ public class PointTypeStrategy { ...@@ -24,4 +24,5 @@ public class PointTypeStrategy {
private String learnSource; private String learnSource;
private int point;
} }
...@@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
...@@ -95,6 +96,7 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements ...@@ -95,6 +96,7 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void addPoint(Long accountId, String type, String sourceId){ public void addPoint(Long accountId, String type, String sourceId){
log.info("增加积分入参: accountId:{}, type:{}, sourceId:{}", accountId, type, sourceId);
Long companyId = ContextHolder.get().getCompanyId(); Long companyId = ContextHolder.get().getCompanyId();
Long orgId = ContextHolder.get().getOrgId(); Long orgId = ContextHolder.get().getOrgId();
Long siteId = ContextHolder.get().getSiteId(); Long siteId = ContextHolder.get().getSiteId();
...@@ -112,13 +114,13 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements ...@@ -112,13 +114,13 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements
pu = new PointUser(); pu = new PointUser();
pu.setId(id); pu.setId(id);
pu.setUserId(accountId); pu.setUserId(accountId);
pu.setTotalPoint(strategy.getPointTypeEnum().getPoint()); pu.setTotalPoint(strategy.getPoint());
pu.setState(1); pu.setState(1);
pu.setCreateById(accountId); pu.setCreateById(accountId);
pu.setCreateByName(accountName); pu.setCreateByName(accountName);
pu.setCreateTime(new Date()); pu.setCreateTime(new Date());
} else { } else {
pu.setTotalPoint(pu.getTotalPoint() + strategy.getPointTypeEnum().getPoint()); pu.setTotalPoint(pu.getTotalPoint() + strategy.getPoint());
pu.setUpdateById(accountId); pu.setUpdateById(accountId);
pu.setUpdateByName(accountName); pu.setUpdateByName(accountName);
pu.setUpdateTime(new Date()); pu.setUpdateTime(new Date());
...@@ -132,8 +134,8 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements ...@@ -132,8 +134,8 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements
pd.setId(idGenerator.generate()); pd.setId(idGenerator.generate());
pd.setTime(new Date()); pd.setTime(new Date());
pd.setChangeBefore(pu.getTotalPoint()); pd.setChangeBefore(pu.getTotalPoint());
pd.setPoint(strategy.getPointTypeEnum().getPoint()); pd.setPoint(strategy.getPoint());
pd.setChangeAfter(pu.getTotalPoint() + strategy.getPointTypeEnum().getPoint()); pd.setChangeAfter(pu.getTotalPoint() + strategy.getPoint());
pd.setMultiple(1); pd.setMultiple(1);
pd.setAccountId(accountId); pd.setAccountId(accountId);
pd.setLearnName(strategy.getPointTypeEnum().getDesc()); pd.setLearnName(strategy.getPointTypeEnum().getDesc());
...@@ -164,26 +166,62 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements ...@@ -164,26 +166,62 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements
int cnt = pointDetailsService.selectCount(wrapper); int cnt = pointDetailsService.selectCount(wrapper);
log.info("登录 赠送积分判断是否为首次登录:{}", cnt); log.info("登录 赠送积分判断是否为首次登录:{}", cnt);
if(cnt <= 0) { if(cnt <= 0) {
return new PointTypeStrategy(PointTypeEnum.LOGIN, date); return new PointTypeStrategy(PointTypeEnum.LOGIN, date, PointTypeEnum.LOGIN.getPoint());
} }
} }
if(type.equals(PointTypeEnum.READ.getKey())){ if(type.equals(PointTypeEnum.READ.getKey())){
int cnt = pointDetailsMapper.getCountTodayByLearnType(accountId, type); int cnt = pointDetailsMapper.getCountTodayByLearnType(accountId, type);
log.info("阅读文章 赠送积分判断当日是否超过次数:{}", cnt); log.info("阅读文章 赠送积分判断当日是否超过次数:{}", cnt);
if(cnt < 5){ if(cnt < 5){
return new PointTypeStrategy(PointTypeEnum.READ, sourceId); return new PointTypeStrategy(PointTypeEnum.READ, sourceId, PointTypeEnum.READ.getPoint());
} }
} }
if(type.equals(PointTypeEnum.PUBLICATION.getKey())){ if(type.equals(PointTypeEnum.PUBLICATION.getKey())){
PointDetails pd = new PointDetails();
pd.setAccountId(accountId);
pd.setLearnType(PointTypeEnum.PUBLICATION.getKey());
pd.setLearnSource(sourceId);
EntityWrapper<PointDetails> wrapper = new EntityWrapper<PointDetails>(pd);
int cnt = pointDetailsService.selectCount(wrapper);
log.info("投稿发布 赠送积分判断此投稿是不是首次发布:{}", cnt);
if(cnt <= 0) {
return new PointTypeStrategy(PointTypeEnum.PUBLICATION, sourceId, PointTypeEnum.PUBLICATION.getPoint());
}
return null; return null;
} }
if(type.equals(PointTypeEnum.COMMENT.getKey())){ if(type.equals(PointTypeEnum.COMMENT.getKey())){
return null; return null;
} }
if(type.equals(PointTypeEnum.ACITVITY.getKey())){ if(type.equals(PointTypeEnum.ACITVITY.getKey())){
PointDetails pd = new PointDetails();
pd.setAccountId(accountId);
pd.setLearnType(PointTypeEnum.ACITVITY.getKey());
pd.setLearnSource(sourceId);
EntityWrapper<PointDetails> wrapper = new EntityWrapper<PointDetails>(pd);
int cnt = pointDetailsService.selectCount(wrapper);
log.info("活动报名 赠送积分判断此活动是不是首次参加:{}", cnt);
if(cnt <= 0) {
return new PointTypeStrategy(PointTypeEnum.ACITVITY, sourceId, PointTypeEnum.ACITVITY.getPoint());
}
return null; return null;
} }
if(type.equals(PointTypeEnum.EXAM.getKey())){ if(type.equals(PointTypeEnum.EXAM.getKey())){
sourceId = sourceId.split("|")[0];
int score = Integer.valueOf(sourceId.split("|")[1]) / 10;
PointDetails pd = new PointDetails();
pd.setAccountId(accountId);
pd.setLearnType(PointTypeEnum.EXAM.getKey());
pd.setLearnSource(sourceId);
EntityWrapper<PointDetails> wrapper = new EntityWrapper<PointDetails>(pd);
int cnt = pointDetailsService.selectCount(wrapper);
log.info("考试结束 赠送积分判断此考试是否赠送过积分:{}", cnt);
if(cnt <= 0) {
return new PointTypeStrategy(PointTypeEnum.EXAM, sourceId, score);
}
return null; return null;
} }
return null; return null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment