查询排行榜列表

master
kanade 3 years ago
parent 98c1115223
commit f6f82a79e3

@ -3,22 +3,37 @@ package com.zh.project0512.controller;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zh.project0512.mapper.QywxDepartmentUserLinkMapper;
import com.zh.project0512.mapper.RankMapper;
import com.zh.project0512.model.Rank;
import com.zh.project0512.model.Task;
import com.zh.project0512.model.dto.RankListDTO;
import com.zh.project0512.model.vo.RankListVo;
import com.zh.project0512.service.ITaskService;
import com.zh.project0512.utils.PropertyUtils;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@Tag(name = "定时任务")
@RestController
public class ScheduleController {
@Autowired
private ITaskService taskService;
@Autowired
private ITaskService taskService;
@Resource
QywxDepartmentUserLinkMapper qywxDepartmentUserLinkMapper;
@Resource
RankMapper rankMapper;
@Scheduled(cron = "0 0 0 * * ?")
public void taskBegin() {
UpdateWrapper<Task> ew = new UpdateWrapper<>();
@ -35,4 +50,42 @@ private ITaskService taskService;
.set("status",2).set("updateAt",now);
taskService.update(ew);
}
@Scheduled(cron = "0 0 0 1 1/1 ?")
public void taskRank() {
//获取员工排名进排名数据库
QueryWrapper<RankListDTO> queryWrapper = new QueryWrapper<>();
queryWrapper.groupBy("u.id");
queryWrapper.orderByDesc("value");
List<RankListVo> rankList = qywxDepartmentUserLinkMapper.getUserRankList(queryWrapper);
if (rankList != null && rankList.size()>0){
for (RankListVo rankListVo : rankList) {
//查询是否有上一月记录,如果有就减去上一月传播值,没有则直接添加
QueryWrapper<Rank> queryWrapper2 = new QueryWrapper<>();
queryWrapper2.eq("link_id",rankListVo.getLinkId());
queryWrapper2.eq("type",2);//2.员工
queryWrapper2.orderByDesc("date_start");
queryWrapper2.last("limit 1");
Rank rank = rankMapper.selectOne(queryWrapper2);
if (rank != null){
rankListVo.setValue(rankListVo.getValue() - rank.getValue());
}
Rank rank2 = new Rank();
PropertyUtils.copyProperties(rankListVo,rank2);
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DAY_OF_MONTH,-1);
cal.set(Calendar.DAY_OF_MONTH,1);
Date timeStart = cal.getTime();
cal.getActualMaximum(Calendar.DAY_OF_MONTH);
Date timeEnd = cal.getTime();
rank2.setDateStart(timeStart);
rank2.setDateEnd(timeEnd);
rankMapper.insert(rank2);
}
}
//计算经销商排名进排名数据库
}
}

@ -4,6 +4,7 @@ import com.zh.project0512.model.dto.RankListDTO;
import com.zh.project0512.model.vo.RankListVo;
import com.zh.project0512.service.IRankService;
import com.zh.project0512.utils.result.ResultList;
import com.zh.project0512.utils.result.ResultPageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
@ -19,7 +20,7 @@ import javax.annotation.Resource;
*/
@Tag(name = "首页")
@RestController
@RequestMapping("/wxApp/ks")
@RequestMapping("/wxApp/rank")
public class RankController {
@Resource
IRankService rankService;
@ -31,8 +32,8 @@ public class RankController {
*/
@Operation(summary = "排行列表")
@PostMapping("/list")
public ResultList<RankListVo> rankList(@Validated RankListDTO rankListDTO){
return ResultList.success(rankService.rankList(rankListDTO),"请求成功");
public ResultPageInfo<RankListVo> rankList(@Validated RankListDTO rankListDTO){
return ResultPageInfo.success(rankService.rankList(rankListDTO),"请求成功");
}

@ -2,9 +2,7 @@ package com.zh.project0512.mapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zh.project0512.model.QywxDepartmentUserLink;
import com.zh.project0512.model.Reference;
import com.zh.project0512.model.dto.RankListDTO;
import com.zh.project0512.model.vo.RankListVo;
import org.apache.ibatis.annotations.Param;
@ -12,6 +10,6 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface QywxDepartmentUserLinkMapper extends BaseMapper<QywxDepartmentUserLink> {
List<RankListVo> rankListPage(IPage<Reference> page, @Param("ew") Wrapper<RankListDTO> queryWrapper);
List<RankListVo> getUserRankList( @Param("ew") Wrapper<RankListDTO> queryWrapper);
}

@ -0,0 +1,7 @@
package com.zh.project0512.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zh.project0512.model.Rank;
public interface RankMapper extends BaseMapper<Rank> {
}

@ -0,0 +1,48 @@
package com.zh.project0512.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Date;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Rank implements Serializable {
private static final long serialVersionUID = 1L;
/**
* id
*/
private Integer id;
/**
* idid,id
*/
private Integer linkId;
/**
* 1.2.
*/
private Integer type;
/**
*
*/
private String title;
/**
*
*/
private String subtitle;
/**
*
*/
private Integer value;
/**
*
*/
private Date dateStart;
/**
*
*/
private Date dateEnd;
}

@ -33,5 +33,6 @@ public class RankListDTO implements Serializable {
* 1.2.
*/
@Schema(title = "排行榜类型")
@NotNull(message = "排行榜类型不能为空")
private int type;
}

@ -16,9 +16,9 @@ public class RankListVo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* id
* idid,id
*/
private Integer id;
private Integer linkId;
/**
*
*/

@ -2,8 +2,8 @@ package com.zh.project0512.service;
import com.zh.project0512.model.dto.RankListDTO;
import com.zh.project0512.model.vo.RankListVo;
import com.zh.project0512.utils.page.PageInfo;
import java.util.List;
public interface IRankService {
/**
@ -11,5 +11,5 @@ public interface IRankService {
* @param rankListDTO DTO
* @return Vo
*/
List<RankListVo> rankList(RankListDTO rankListDTO);
PageInfo<RankListVo> rankList(RankListDTO rankListDTO);
}

@ -1,29 +1,50 @@
package com.zh.project0512.serviceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zh.project0512.mapper.QywxDepartmentUserLinkMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zh.project0512.mapper.RankMapper;
import com.zh.project0512.model.Rank;
import com.zh.project0512.model.dto.RankListDTO;
import com.zh.project0512.model.vo.RankListVo;
import com.zh.project0512.service.IRankService;
import com.zh.project0512.utils.MybatisPlusUtil;
import com.zh.project0512.utils.PropertyUtils;
import com.zh.project0512.utils.page.PageInfo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@Service
public class RankServiceImpl implements IRankService {
@Resource
QywxDepartmentUserLinkMapper qywxDepartmentUserLinkMapper;
RankMapper rankMapper;
@Override
public List<RankListVo> rankList(RankListDTO rankListDTO) {
QueryWrapper<RankListDTO> queryWrapper = new QueryWrapper<>();
queryWrapper.groupBy("u.id");
queryWrapper.orderByDesc("value");
List<RankListVo> rankListVoList = qywxDepartmentUserLinkMapper.rankListPage(MybatisPlusUtil.SetNumPage(rankListDTO.getPageNum(), rankListDTO.getSize()),queryWrapper);
public PageInfo<RankListVo> rankList(RankListDTO rankListDTO) {
ArrayList<RankListVo> rankListVoList = new ArrayList<>();
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DAY_OF_MONTH,-1);
cal.set(Calendar.DAY_OF_MONTH,1);
Date time = cal.getTime();
return null;
QueryWrapper<Rank> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("type",rankListDTO.getType());
queryWrapper.eq("date_start",time);
Page<Rank> page = new Page<>(rankListDTO.getPageNum(), rankListDTO.getSize());
IPage<Rank> rankIPage = rankMapper.selectPage(page, queryWrapper);
List<Rank> records = rankIPage.getRecords();
if (records != null && records.size()>0){
for (Rank record : records) {
RankListVo rankListVo = new RankListVo();
PropertyUtils.copyProperties(record,rankListVo);
rankListVoList.add(rankListVo);
}
}
return new PageInfo<>(rankIPage.getPages(), rankListVoList, rankIPage.getTotal());
}
}

@ -0,0 +1,97 @@
package com.zh.project0512.utils;
import com.zh.project0512.utils.result.HttpStatusEnum;
import java.lang.reflect.Field;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* sourcedestination
* get set
* @author w1251314@sohu.com
*/
public class PropertyUtils {
/**
* sourcedestination
* @param source
* @param destination
*/
public static <S,D> void copyProperties(S source, D destination) {
Class clsDestination;
try {
clsDestination = Class.forName(destination.getClass().getName());
Class clsSource = Class.forName(source.getClass().getName());
Field[] declaredFields = clsDestination.getDeclaredFields();
for (Field field : declaredFields){
field.setAccessible(true);
String fieldName = field.getName();
try{
//跳过serialVersionUID
if("serialVersionUID".equals(fieldName)){
continue;
}
Field sourceField = clsSource.getDeclaredField(fieldName);
sourceField.setAccessible(true);
field.set(destination,sourceField.get(source));
}catch (NoSuchFieldException e){
// continue;
}
}
} catch (Exception e) {
throw new RuntimeException("PropertyUtils 属性转换错误");
// throw new BizException(HttpStatusEnum.CUSTOM_EXCEPTION,"PropertyUtils 属性转换错误");
}
}
/**
* sourcedestination
* @param source
* @param destination
* @param ignoreProperties
*/
public static <S,D> void copyProperties(S source, D destination,String... ignoreProperties) {
Class clsDestination ;
try {
clsDestination = Class.forName(destination.getClass().getName());
Class clsSource = Class.forName(source.getClass().getName());
Field[] declaredFields = clsDestination.getDeclaredFields();
for (Field field : declaredFields){
String fieldName = field.getName();
Set<String> collect = Stream.of(ignoreProperties).collect(Collectors.toSet());
//跳过serialVersionUID
collect.add("serialVersionUID");
if(collect.contains(fieldName)){
continue;
}
try{
field.setAccessible(true);
Field sourceField = clsSource.getDeclaredField(fieldName);
sourceField.setAccessible(true);
field.set(destination,sourceField.get(source));
}catch (NoSuchFieldException e){
// 没有对应属性跳过;
}
}
} catch (Exception e) {
throw new RuntimeException("PropertyUtils 属性转换错误");
// throw new BizException(HttpStatusEnum.CUSTOM_EXCEPTION,"PropertyUtils 属性转换错误");
}
}
}

@ -1,13 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zh.project0512.mapper.QywxDepartmentUserLinkMapper">
<select id="rankListPage" resultType="com.zh.project0512.model.vo.RankListVo">
<select id="getUserRankList" resultType="com.zh.project0512.model.vo.RankListVo">
select u.id,u.name as title,
(sum(IFNULL(v.playNum,0))+sum(IFNULL(v.commendNum,0))+sum(IFNULL(v.collectionNum,0))+sum(IFNULL(v.commentNum,0))) as value
(sum(IFNULL(v.playNum,0))+sum(IFNULL(v.commendNum,0))+sum(IFNULL(v.collectionNum,0))+sum(IFNULL(v.commentNum,0))) as value
from user as u
LEFT JOIN video as v ON u.id = v.userId
<if test='ew != null'>
${ew.SqlSegment}
</if>
${ew.SqlSegment}
</select>
</mapper>

Loading…
Cancel
Save