|
|
@@ -10,18 +10,21 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.github.pagehelper.Page;
|
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
|
import com.zhongzheng.common.utils.DateUtils;
|
|
|
+import com.zhongzheng.modules.activity.bo.ActivityTaskUserAddBo;
|
|
|
import com.zhongzheng.modules.activity.domain.ActivityTaskUser;
|
|
|
+import com.zhongzheng.modules.activity.service.IActivityGradeService;
|
|
|
+import com.zhongzheng.modules.activity.service.IActivityTaskService;
|
|
|
import com.zhongzheng.modules.activity.service.IActivityTaskUserService;
|
|
|
+import com.zhongzheng.modules.activity.service.impl.ActivityTaskUserServiceImpl;
|
|
|
+import com.zhongzheng.modules.activity.vo.ActivityGradeVo;
|
|
|
+import com.zhongzheng.modules.activity.vo.ActivityTaskVo;
|
|
|
import com.zhongzheng.modules.collect.domain.CollectBank;
|
|
|
import com.zhongzheng.modules.collect.domain.CollectCourse;
|
|
|
import com.zhongzheng.modules.collect.domain.CollectNote;
|
|
|
import com.zhongzheng.modules.collect.mapper.CollectBankMapper;
|
|
|
import com.zhongzheng.modules.collect.mapper.CollectCourseMapper;
|
|
|
import com.zhongzheng.modules.collect.mapper.CollectNoteMapper;
|
|
|
-import com.zhongzheng.modules.user.bo.RanKingUserQuery;
|
|
|
-import com.zhongzheng.modules.user.bo.UserAddBo;
|
|
|
-import com.zhongzheng.modules.user.bo.UserEditBo;
|
|
|
-import com.zhongzheng.modules.user.bo.UserQueryBo;
|
|
|
+import com.zhongzheng.modules.user.bo.*;
|
|
|
import com.zhongzheng.modules.user.domain.User;
|
|
|
import com.zhongzheng.modules.user.domain.UserBankRecord;
|
|
|
import com.zhongzheng.modules.user.entity.ClientLoginUser;
|
|
|
@@ -31,9 +34,13 @@ import com.zhongzheng.modules.user.vo.RanKingUser;
|
|
|
import com.zhongzheng.modules.user.vo.UserVo;
|
|
|
import io.swagger.models.auth.In;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.sql.Timestamp;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -62,6 +69,15 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
@Autowired
|
|
|
private IActivityTaskUserService activityTaskUserService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IActivityTaskService activityTaskService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IUserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IActivityGradeService activityGradeService;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public UserVo queryById(Long userId) {
|
|
|
@@ -149,13 +165,74 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean updateByEditBo(UserEditBo bo) {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean updateByEditBo(UserEditBo bo) throws IllegalAccessException {
|
|
|
User update = BeanUtil.toBean(bo, User.class);
|
|
|
validEntityBeforeSave(update);
|
|
|
update.setUpdateTime(DateUtils.getNowTime());
|
|
|
+
|
|
|
+ //增加客户端信息进行添加积分
|
|
|
+ information(bo);
|
|
|
+
|
|
|
return this.updateById(update);
|
|
|
}
|
|
|
|
|
|
+ public void information(UserEditBo bo) throws IllegalAccessException {
|
|
|
+ //判断是否是完善信息
|
|
|
+ ActivityTaskVo activityTaskVo = activityTaskService.queryByTaskId(1L);
|
|
|
+ if (activityTaskVo == null){
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ //得出已领取的分数是多少
|
|
|
+ LambdaQueryWrapper<ActivityTaskUser> lqw =Wrappers.lambdaQuery();;
|
|
|
+ lqw.eq(bo.getUserId() != null,ActivityTaskUser::getUserId,bo.getUserId());
|
|
|
+ lqw.eq(ActivityTaskUser::getTaskType, 1);
|
|
|
+ List<ActivityTaskUser> list = activityTaskUserService.list(lqw);
|
|
|
+ BigDecimal bigDecimal = new BigDecimal("0");
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
+ for (ActivityTaskUser activityTaskUser : list) {
|
|
|
+ bigDecimal = bigDecimal.add(new BigDecimal(activityTaskUser.getScore()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (bigDecimal.compareTo(new BigDecimal(activityTaskVo.getStartIntegral())) == 0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ UserSchoolInfoEditBo userSchoolInfoEditBo = new UserSchoolInfoEditBo();
|
|
|
+ //userVO用户 有参值/总数 得出比例 乘以分数 四舍五入
|
|
|
+ Field[] field = bo.getClass().getDeclaredFields();
|
|
|
+ Integer integer = countUser(bo);
|
|
|
+ String num = String.valueOf(new BigDecimal(Convert.toStr(field.length-6)).divide(new BigDecimal(integer.toString())));
|
|
|
+ BigDecimal result5 = new BigDecimal(Convert.toStr(activityTaskVo.getStartIntegral()*0.8)).divide(new BigDecimal(num),BigDecimal.ROUND_HALF_UP);
|
|
|
+
|
|
|
+ //增加用户领取记录
|
|
|
+ ActivityTaskUser add = BeanUtil.toBean(bo, ActivityTaskUser.class);
|
|
|
+ add.setScore(result5.toString());
|
|
|
+ add.setCreateTime(DateUtils.getNowTime());
|
|
|
+ add.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ add.setUserId(bo.getUserId());
|
|
|
+ add.setTaskType(activityTaskVo.getTaskType());
|
|
|
+ add.setTaskId(activityTaskVo.getId());
|
|
|
+ //增加用户积分
|
|
|
+ UserVo userVo = userService.queryById(bo.getUserId());
|
|
|
+ if (userVo.getIntegral() == null){
|
|
|
+ userVo.setIntegral(0L);
|
|
|
+ }
|
|
|
+ //增加用户积分更新等级
|
|
|
+ Long Integer = userVo.getIntegral()+ Convert.toLong(result5);
|
|
|
+ ActivityGradeVo list1 = activityGradeService.queryByInteger(Integer);
|
|
|
+ userVo.setUserLevel(list1.getGrade());
|
|
|
+ increaseUser(userVo,Integer);
|
|
|
+ activityTaskUserService.save(add);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private Boolean increaseUser(UserVo userVo,Long score){
|
|
|
+ User user = BeanUtil.toBean(userVo, User.class);
|
|
|
+ user.setIntegral(score);
|
|
|
+ user.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return userService.updateById(user);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 保存前的数据校验
|
|
|
*
|
|
|
@@ -165,6 +242,20 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
//TODO 做一些数据校验,如唯一约束
|
|
|
}
|
|
|
|
|
|
+ public Integer countUser(UserEditBo userVo) throws IllegalAccessException {
|
|
|
+ // Java的反射
|
|
|
+ Field[] field = userVo.getClass().getDeclaredFields();
|
|
|
+ int count = 0;
|
|
|
+ for(int i=0; i<field.length; i++){
|
|
|
+ Field f = field[i];
|
|
|
+ f.setAccessible(true);
|
|
|
+ if (f.get(userVo) != null){
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
if (isValid) {
|
|
|
@@ -240,6 +331,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
c.setHourse(getHour(c.getHourse()));
|
|
|
});
|
|
|
}
|
|
|
+ ranKingUser.setRank(ranKingUser.getRank()+1);
|
|
|
return ranKingUser;
|
|
|
|
|
|
}
|
|
|
@@ -249,7 +341,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
public static String getHour(String date) {
|
|
|
//秒数
|
|
|
Integer dt = Integer.parseInt(date) ;
|
|
|
- if (dt < 3600) return Math.round(dt / 60) + "分钟";
|
|
|
+ if (dt < 3600) return Math.round(dt / 60) + "m";
|
|
|
int hour = Math.round(dt / 3600);
|
|
|
int minute = Math.round((dt - (hour * 3600)) / 60);
|
|
|
return hour + "h" + (minute == 0 ? "" : minute + "m");
|