|
@@ -1,7 +1,11 @@
|
|
|
package cn.iselab.mooctest.user.web.logic.impl;
|
|
|
|
|
|
+import cn.iselab.mooctest.rpc.user.constants.IntegralEventConstants;
|
|
|
+import cn.iselab.mooctest.rpc.user.data.AddIntegralDTO;
|
|
|
import cn.iselab.mooctest.rpc.user.data.IntegralCaughtDTO;
|
|
|
import cn.iselab.mooctest.rpc.user.data.UserIntegralDTO;
|
|
|
+import cn.iselab.mooctest.user.configure.IntegralMap;
|
|
|
+import cn.iselab.mooctest.user.model.Integral;
|
|
|
import cn.iselab.mooctest.user.model.User2Integral;
|
|
|
import cn.iselab.mooctest.user.model.UserIntegral;
|
|
|
import cn.iselab.mooctest.user.service.IntegralService;
|
|
@@ -10,13 +14,12 @@ import cn.iselab.mooctest.user.web.logic.IntegralLogic;
|
|
|
import cn.iselab.mooctest.user.web.wrapper.IntegralCaughtWrapper;
|
|
|
import cn.iselab.mooctest.user.web.wrapper.UserIntegralWrapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.core.convert.converter.Converter;
|
|
|
-import org.springframework.data.domain.Page;
|
|
|
-import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.sql.Timestamp;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -37,23 +40,15 @@ public class IntegralLogicImpl extends BaseLogic implements IntegralLogic {
|
|
|
@Autowired
|
|
|
UserIntegralWrapper userIntegralWrapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ IntegralMap integralMap;
|
|
|
+
|
|
|
@Override
|
|
|
public IntegralCaughtDTO saveIntegralCaught(IntegralCaughtDTO dto){
|
|
|
User2Integral integral= integralCaughtWrapper.unwrap(dto);
|
|
|
integral.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
|
|
integral=integralService.saveUser2Integral(integral);
|
|
|
-
|
|
|
- UserIntegral userIntegral=integralService.findByUserId(dto.getUserId());
|
|
|
- if(userIntegral!=null) {
|
|
|
- userIntegral.setTotal(userIntegral.getTotal() + integral.getPoints());
|
|
|
- }else {
|
|
|
- UserIntegral integral1=new UserIntegral();
|
|
|
- integral1.setUserId(dto.getUserId());
|
|
|
- integral1.setTotal(integral.getPoints());
|
|
|
- integral1.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
|
|
- integral1.setEnabled(true);
|
|
|
- integralService.saveIntegral(integral1);
|
|
|
- }
|
|
|
+ addIntegral(integral);
|
|
|
return integralCaughtWrapper.wrap(integral);
|
|
|
}
|
|
|
|
|
@@ -72,4 +67,58 @@ public class IntegralLogicImpl extends BaseLogic implements IntegralLogic {
|
|
|
return integrals.parallelStream()
|
|
|
.map(userIntegral -> userIntegralWrapper.wrap(userIntegral)).collect(Collectors.toList());
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public UserIntegralDTO getUserIntegral(Long userId){
|
|
|
+ UserIntegral userIntegral=integralService.findByUserId(userId);
|
|
|
+ return userIntegralWrapper.wrap(userIntegral);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean addIntegral(AddIntegralDTO dto){
|
|
|
+ if (dto.getEvent()==null||dto.getUserId()==null){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Integral integral=integralMap.get(dto.getEvent());
|
|
|
+ if (integral==null){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (integral.getSource().equals(IntegralEventConstants.LOGIN)){
|
|
|
+ User2Integral user2Integral=integralService.findIntegralBySource(dto.getEvent(),dto.getUserId());
|
|
|
+ if (user2Integral!=null){
|
|
|
+ return false;
|
|
|
+ }else {
|
|
|
+ user2Integral=new User2Integral();
|
|
|
+ user2Integral.setType(1);
|
|
|
+ user2Integral.setPoints(integral.getPoint());
|
|
|
+ user2Integral.setSource(integral.getSource());
|
|
|
+ user2Integral.setUserId(dto.getUserId());
|
|
|
+ user2Integral.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
|
|
+
|
|
|
+ this.addIntegral(user2Integral);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String,Integral> reloadIntegralMap(){
|
|
|
+ return integralMap.reload();
|
|
|
+ }
|
|
|
+
|
|
|
+ public UserIntegral addIntegral(User2Integral integral){
|
|
|
+ UserIntegral userIntegral=integralService.findByUserId(integral.getUserId());
|
|
|
+ if(userIntegral!=null) {
|
|
|
+ userIntegral.setTotal(userIntegral.getTotal() + integral.getPoints());
|
|
|
+ }else {
|
|
|
+ userIntegral=new UserIntegral();
|
|
|
+ userIntegral.setUserId(integral.getUserId());
|
|
|
+ userIntegral.setTotal(integral.getPoints());
|
|
|
+ userIntegral.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
|
|
+ userIntegral.setEnabled(true);
|
|
|
+ }
|
|
|
+ integralService.saveUser2Integral(integral);
|
|
|
+ integralService.updateIntegral(userIntegral);
|
|
|
+ return userIntegral;
|
|
|
+ }
|
|
|
}
|