|
|
@@ -1,6 +1,7 @@
|
|
|
package com.zhongzheng.framework.web.service;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.lang.Validator;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
@@ -29,6 +30,7 @@ import com.zhongzheng.modules.user.vo.UserVo;
|
|
|
import io.swagger.models.auth.In;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.sql.Timestamp;
|
|
|
import java.util.*;
|
|
|
@@ -53,10 +55,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
private CollectNoteMapper collectNoteMapper;
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
@Override
|
|
|
- public UserVo queryById(Long userId){
|
|
|
+ public UserVo queryById(Long userId) {
|
|
|
User db = this.baseMapper.selectById(userId);
|
|
|
return BeanUtil.toBean(db, UserVo.class);
|
|
|
}
|
|
|
@@ -64,7 +64,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
@Override
|
|
|
public User queryByUnionId(String unionId) {
|
|
|
User user = getOne(new LambdaQueryWrapper<User>()
|
|
|
- .eq(User::getUnionId,unionId)
|
|
|
+ .eq(User::getUnionId, unionId)
|
|
|
.last("limit 1"));
|
|
|
if (Validator.isNotNull(user)) {
|
|
|
return user;
|
|
|
@@ -73,7 +73,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public List<UserVo> queryList(UserQueryBo bo) {
|
|
|
LambdaQueryWrapper<User> lqw = Wrappers.lambdaQuery();
|
|
|
@@ -102,19 +101,19 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 实体类转化成视图对象
|
|
|
- *
|
|
|
- * @param collection 实体类集合
|
|
|
- * @return
|
|
|
- */
|
|
|
+ * 实体类转化成视图对象
|
|
|
+ *
|
|
|
+ * @param collection 实体类集合
|
|
|
+ * @return
|
|
|
+ */
|
|
|
private List<UserVo> entity2Vo(Collection<User> collection) {
|
|
|
List<UserVo> voList = collection.stream()
|
|
|
.map(any -> BeanUtil.toBean(any, UserVo.class))
|
|
|
.collect(Collectors.toList());
|
|
|
if (collection instanceof Page) {
|
|
|
- Page<User> page = (Page<User>)collection;
|
|
|
+ Page<User> page = (Page<User>) collection;
|
|
|
Page<UserVo> pageVo = new Page<>();
|
|
|
- BeanUtil.copyProperties(page,pageVo);
|
|
|
+ BeanUtil.copyProperties(page, pageVo);
|
|
|
pageVo.addAll(voList);
|
|
|
voList = pageVo;
|
|
|
}
|
|
|
@@ -143,13 +142,13 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
*
|
|
|
* @param entity 实体类数据
|
|
|
*/
|
|
|
- private void validEntityBeforeSave(User entity){
|
|
|
+ private void validEntityBeforeSave(User entity) {
|
|
|
//TODO 做一些数据校验,如唯一约束
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
- if(isValid){
|
|
|
+ if (isValid) {
|
|
|
//TODO 做一些业务上的校验,判断是否需要校验
|
|
|
}
|
|
|
return this.removeByIds(ids);
|
|
|
@@ -158,12 +157,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
@Override
|
|
|
public Integer getCollectTotal(Long userId) {
|
|
|
Integer collectCourse = collectCourseMapper.selectCount(new LambdaQueryWrapper<CollectCourse>()
|
|
|
- .eq(CollectCourse::getUserId,userId));
|
|
|
+ .eq(CollectCourse::getUserId, userId));
|
|
|
Integer collectBank = collectBankMapper.selectCount(new LambdaQueryWrapper<CollectBank>()
|
|
|
- .eq(CollectBank::getUserId,userId));
|
|
|
+ .eq(CollectBank::getUserId, userId));
|
|
|
Integer collectNote = collectNoteMapper.selectCount(new LambdaQueryWrapper<CollectNote>()
|
|
|
- .eq(CollectNote::getUserId,userId));
|
|
|
- return collectCourse+collectBank+collectNote;
|
|
|
+ .eq(CollectNote::getUserId, userId));
|
|
|
+ return collectCourse + collectBank + collectNote;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -178,46 +177,68 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
long tt = calendar.getTime().getTime() / 1000;
|
|
|
query.setStartTime(zero);
|
|
|
query.setEndTime(tt);
|
|
|
- ranKingUser= baseMapper.selectByRank(query);
|
|
|
+ ranKingUser = baseMapper.selectByRank(query);
|
|
|
if (ranKingUser != null && ranKingUser.getHourse() != null) {
|
|
|
- Integer rank = baseMapper.selectByRankOne(ranKingUser.getHourse());
|
|
|
+ Integer rank = baseMapper.selectByRankOne(Convert.toInt(ranKingUser.getHourse()));
|
|
|
ranKingUser.setRank(rank);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
ranKingUser = baseMapper.selectByOneRank(query);
|
|
|
ranKingUser.setRank(0);
|
|
|
}
|
|
|
List<RanKingUser> ranKingUsers = baseMapper.selectByRanks(query);
|
|
|
if (ranKingUsers != null && ranKingUsers.size() != 0) {
|
|
|
ranKingUser.setRanKingUsers(ranKingUsers);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
ranKingUser.setRanKingUsers(new ArrayList<>());
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
int month = cal.get(Calendar.MONTH) + 1;
|
|
|
Long firstDayOfMonth = getFirstDayOfMonth(month);
|
|
|
Long lastDayOfMonth = getLastDayOfMonth(month);
|
|
|
query.setStartTime(firstDayOfMonth);
|
|
|
query.setEndTime(lastDayOfMonth);
|
|
|
- ranKingUser= baseMapper.selectByRank(query);
|
|
|
- if (ranKingUser != null && ranKingUser.getHourse() != null) {
|
|
|
- Integer rank = baseMapper.selectByRankOne(ranKingUser.getHourse());
|
|
|
+ ranKingUser = baseMapper.selectByRank(query);
|
|
|
+ if (ranKingUser != null && ranKingUser.getHourse() != null) {
|
|
|
+ Integer rank = baseMapper.selectByRankOne(Convert.toInt(ranKingUser.getHourse()));
|
|
|
ranKingUser.setRank(rank);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
ranKingUser = baseMapper.selectByOneRank(query);
|
|
|
ranKingUser.setRank(0);
|
|
|
}
|
|
|
List<RanKingUser> ranKingUsers = baseMapper.selectByRanks(query);
|
|
|
if (ranKingUsers != null && ranKingUsers.size() != 0) {
|
|
|
ranKingUser.setRanKingUsers(ranKingUsers);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
ranKingUser.setRanKingUsers(new ArrayList<>());
|
|
|
}
|
|
|
}
|
|
|
+ if (ranKingUser.getHourse() != null){
|
|
|
+ ranKingUser.setHourse(getHour(ranKingUser.getHourse()));
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(ranKingUser.getRanKingUsers())){
|
|
|
+ ranKingUser.getRanKingUsers().stream().forEach(c -> {
|
|
|
+ c.setHourse(getHour(c.getHourse()));
|
|
|
+ });
|
|
|
+ }
|
|
|
return ranKingUser;
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ //Util.java
|
|
|
+ public static String getHour(String date) {
|
|
|
+ //秒数
|
|
|
+ Integer dt = Integer.parseInt(date) ;
|
|
|
+ if (dt < 3600) return Math.round(dt / 60) + "分钟";
|
|
|
+ int hour = Math.round(dt / 3600);
|
|
|
+ int minute = Math.round((dt - (hour * 3600)) / 60);
|
|
|
+ return hour + "h" + (minute == 0 ? "" : minute + "m");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public Integer getRank(Long userId) {
|
|
|
RanKingUserQuery query = new RanKingUserQuery();
|
|
|
@@ -232,7 +253,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
query.setEndTime(tt);
|
|
|
RanKingUser ranKingUser = baseMapper.selectByRank(query);
|
|
|
if (ranKingUser != null && ranKingUser.getHourse() != null) {
|
|
|
- Integer rank = baseMapper.selectByRankOne(ranKingUser.getHourse());
|
|
|
+ Integer rank = baseMapper.selectByRankOne(Convert.toInt(ranKingUser.getHourse()));
|
|
|
return rank;
|
|
|
}
|
|
|
return 0;
|
|
|
@@ -251,7 +272,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
int firstDay = calendar.getActualMinimum(Calendar.DAY_OF_MONTH);
|
|
|
// 设置日历中月份的最小天数
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, firstDay);
|
|
|
-
|
|
|
+ //将小时至0
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ //将分钟至0
|
|
|
+ calendar.set(Calendar.MINUTE, 0);
|
|
|
+ //将秒至0
|
|
|
+ calendar.set(Calendar.SECOND,0);
|
|
|
Date time = calendar.getTime();
|
|
|
return time.getTime() / 1000;
|
|
|
}
|
|
|
@@ -270,6 +296,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
}
|
|
|
// 设置日历中月份的最大天数
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, lastDay);
|
|
|
+ //将小时至0
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 24);
|
|
|
+ //将分钟至0
|
|
|
+ calendar.set(Calendar.MINUTE, 0);
|
|
|
+ //将秒至0
|
|
|
+ calendar.set(Calendar.SECOND,0);
|
|
|
Date time = calendar.getTime();
|
|
|
return time.getTime() / 1000;
|
|
|
}
|