Browse Source

王公峰:定时更新排行榜

feature/dangjian
wanggongfeng 6 years ago
parent
commit
9070bdf030
  1. 7
      esua-epdc/epdc-module/epdc-heart/epdc-heart-client/pom.xml
  2. 30
      esua-epdc/epdc-module/epdc-heart/epdc-heart-server/src/main/java/com/elink/esua/epdc/modules/feign/UserFeignClient.java
  3. 29
      esua-epdc/epdc-module/epdc-heart/epdc-heart-server/src/main/java/com/elink/esua/epdc/modules/feign/fallback/UserFeignClientFallback.java
  4. 10
      esua-epdc/epdc-module/epdc-heart/epdc-heart-server/src/main/java/com/elink/esua/epdc/modules/volunteer/service/VolunteerRankService.java
  5. 26
      esua-epdc/epdc-module/epdc-heart/epdc-heart-server/src/main/java/com/elink/esua/epdc/modules/volunteer/service/impl/VolunteerRankServiceImpl.java
  6. 31
      esua-epdc/epdc-module/epdc-heart/epdc-heart-server/src/main/java/com/elink/esua/epdc/modules/volunteer/task/UpdateVolunteerRankTask.java
  7. 42
      esua-epdc/epdc-module/epdc-heart/epdc-heart-server/src/main/java/com/elink/esua/epdc/modules/volunteer/task/UpdateVolunteerRankTaskImpl.java
  8. 122
      esua-epdc/epdc-module/epdc-user/epdc-user-client/src/main/java/com/elink/esua/epdc/dto/epdc/result/EpdcGetVolunteerRankDTO.java
  9. 13
      esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/controller/EpdcAppVolunteerInfoController.java
  10. 7
      esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/dao/VolunteerInfoDao.java
  11. 7
      esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/service/VolunteerInfoService.java
  12. 12
      esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/service/impl/VolunteerInfoServiceImpl.java
  13. 19
      esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/resources/mapper/VolunteerInfoDao.xml

7
esua-epdc/epdc-module/epdc-heart/epdc-heart-client/pom.xml

@ -18,6 +18,13 @@
<artifactId>epdc-demo-client</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.esua.epdc</groupId>
<artifactId>epdc-user-client</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>

30
esua-epdc/epdc-module/epdc-heart/epdc-heart-server/src/main/java/com/elink/esua/epdc/modules/feign/UserFeignClient.java

@ -0,0 +1,30 @@
package com.elink.esua.epdc.modules.feign;
import com.elink.esua.epdc.commons.tools.constant.ServiceConstant;
import com.elink.esua.epdc.commons.tools.utils.Result;
import com.elink.esua.epdc.dto.epdc.result.EpdcGetVolunteerRankDTO;
import com.elink.esua.epdc.modules.feign.fallback.UserFeignClientFallback;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;
/**
*
* 调用用户模块
*
* @Authorwanggongfeng
* @Date2019/12/16 17:36
*/
@FeignClient(name = ServiceConstant.EPDC_USER_SERVER, fallback = UserFeignClientFallback.class)
public interface UserFeignClient {
/**
* 获取排行榜
*
* @return
*/
@GetMapping("app-user/epdc-app/volunteerinfo/getRankingList")
Result<List<EpdcGetVolunteerRankDTO>> getRankingList();
}

29
esua-epdc/epdc-module/epdc-heart/epdc-heart-server/src/main/java/com/elink/esua/epdc/modules/feign/fallback/UserFeignClientFallback.java

@ -0,0 +1,29 @@
package com.elink.esua.epdc.modules.feign.fallback;
import com.elink.esua.epdc.commons.tools.constant.ServiceConstant;
import com.elink.esua.epdc.commons.tools.utils.ModuleUtils;
import com.elink.esua.epdc.commons.tools.utils.Result;
import com.elink.esua.epdc.dto.epdc.result.EpdcGetVolunteerRankDTO;
import com.elink.esua.epdc.modules.feign.UserFeignClient;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @Authorwanggongfeng
* @Date2019/12/16 15:11
*/
@Component
public class UserFeignClientFallback implements UserFeignClient {
/**
* 获取排行榜
*
* @return
*/
@Override
public Result<List<EpdcGetVolunteerRankDTO>> getRankingList() {
return ModuleUtils.feignConError(ServiceConstant.EPDC_USER_SERVER, "getRankingList");
}
}

10
esua-epdc/epdc-module/epdc-heart/epdc-heart-server/src/main/java/com/elink/esua/epdc/modules/volunteer/service/VolunteerRankService.java

@ -19,6 +19,7 @@ package com.elink.esua.epdc.modules.volunteer.service;
import com.elink.esua.epdc.commons.mybatis.service.BaseService;
import com.elink.esua.epdc.commons.tools.page.PageData;
import com.elink.esua.epdc.commons.tools.utils.Result;
import com.elink.esua.epdc.modules.volunteer.entity.VolunteerRankEntity;
import com.elink.esua.epdc.volunteer.EpdcVolunteerRankDTO;
import com.elink.esua.epdc.volunteer.VolunteerRankDTO;
@ -100,4 +101,13 @@ public interface VolunteerRankService extends BaseService<VolunteerRankEntity> {
* @return
*/
List<EpdcVolunteerRankDTO> leaderboard();
/**
* 生成排行榜
* @Author wanggongfeng
* @return
*/
Result generateRankingList();
}

26
esua-epdc/epdc-module/epdc-heart/epdc-heart-server/src/main/java/com/elink/esua/epdc/modules/volunteer/service/impl/VolunteerRankServiceImpl.java

@ -23,6 +23,9 @@ import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl;
import com.elink.esua.epdc.commons.tools.constant.FieldConstant;
import com.elink.esua.epdc.commons.tools.page.PageData;
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils;
import com.elink.esua.epdc.commons.tools.utils.Result;
import com.elink.esua.epdc.dto.epdc.result.EpdcGetVolunteerRankDTO;
import com.elink.esua.epdc.modules.feign.UserFeignClient;
import com.elink.esua.epdc.modules.volunteer.dao.VolunteerRankDao;
import com.elink.esua.epdc.modules.volunteer.entity.VolunteerRankEntity;
import com.elink.esua.epdc.modules.volunteer.redis.VolunteerRankRedis;
@ -50,6 +53,9 @@ public class VolunteerRankServiceImpl extends BaseServiceImpl<VolunteerRankDao,
@Autowired
private VolunteerRankRedis volunteerRankRedis;
@Autowired
private UserFeignClient userFeignClient;
@Override
public PageData<VolunteerRankDTO> page(Map<String, Object> params) {
IPage<VolunteerRankEntity> page = baseDao.selectPage(
@ -113,4 +119,24 @@ public class VolunteerRankServiceImpl extends BaseServiceImpl<VolunteerRankDao,
return list;
}
/**
* 更新排行榜
* @Author wanggongfeng
* @return
*/
@Override
public Result generateRankingList(){
Result<List<EpdcGetVolunteerRankDTO>> result = userFeignClient.getRankingList();
List<EpdcGetVolunteerRankDTO> list = result.getData();
if(list != null && list.size() > 0){
for(int i = 0 ; i < list.size(); i++ ){
EpdcGetVolunteerRankDTO epdcGetVolunteerRankDTO = list.get(i);
VolunteerRankEntity entity = ConvertUtils.sourceToTarget(epdcGetVolunteerRankDTO, VolunteerRankEntity.class);
insert(entity);
}
return new Result().ok("排名更新成功");
}
return new Result().error("更新排名错误");
}
}

31
esua-epdc/epdc-module/epdc-heart/epdc-heart-server/src/main/java/com/elink/esua/epdc/modules/volunteer/task/UpdateVolunteerRankTask.java

@ -0,0 +1,31 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.elink.esua.epdc.modules.volunteer.task;
/**
* 志愿者排名
*
* @author qu qu@elink-cn.com
* @since v1.0.0 2019-12-19
*/
public interface UpdateVolunteerRankTask {
void run();
}

42
esua-epdc/epdc-module/epdc-heart/epdc-heart-server/src/main/java/com/elink/esua/epdc/modules/volunteer/task/UpdateVolunteerRankTaskImpl.java

@ -0,0 +1,42 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.elink.esua.epdc.modules.volunteer.task;
import com.elink.esua.epdc.modules.volunteer.service.VolunteerRankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* 志愿者排名
*
* @author qu qu@elink-cn.com
* @since v1.0.0 2019-12-19
*/
@Component("UpdateVolunteerRank")
public class UpdateVolunteerRankTaskImpl implements UpdateVolunteerRankTask {
@Autowired
private VolunteerRankService volunteerRankService;
@Override
public void run(){
volunteerRankService.generateRankingList();
}
}

122
esua-epdc/epdc-module/epdc-user/epdc-user-client/src/main/java/com/elink/esua/epdc/dto/epdc/result/EpdcGetVolunteerRankDTO.java

@ -0,0 +1,122 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.elink.esua.epdc.dto.epdc.result;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* 志愿者排名
*
* @author qu qu@elink-cn.com
* @since v1.0.0 2019-12-19
*/
@Data
public class EpdcGetVolunteerRankDTO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
private String id;
/**
* 排名
*/
private Integer sort;
/**
* 志愿者ID
*/
private String volunteerId;
/**
* 用户ID
*/
private String userId;
/**
* 头像
*/
private String faceImg;
/**
* 用户名
*/
private String nickname;
/**
* 是否党员(0-1-)
*/
private String partyFlag;
/**
* 爱心时长(单位小时)
*/
private BigDecimal kindnessTime;
/**
* 参加次数
*/
private Integer participationNum;
/**
* 排行生成日期
*/
private Date generateDate;
/**
* 是否显示(0-不显示1-显示)
*/
private String showFlag;
/**
* 乐观锁
*/
private Integer revision;
/**
* 创建人
*/
private String createdBy;
/**
* 创建时间
*/
private Date createdTime;
/**
* 更新人
*/
private String updatedBy;
/**
* 更新时间
*/
private Date updatedTime;
/**
* 删除标志
*/
private String delFlag;
}

13
esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/controller/EpdcAppVolunteerInfoController.java

@ -6,6 +6,7 @@ import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils;
import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup;
import com.elink.esua.epdc.commons.tools.validator.group.UpdateGroup;
import com.elink.esua.epdc.dto.epdc.form.EpdcCompleteVolunteerInfoFormDTO;
import com.elink.esua.epdc.dto.epdc.result.EpdcGetVolunteerRankDTO;
import com.elink.esua.epdc.service.VolunteerInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@ -13,6 +14,8 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 对移动端开放
*
@ -50,6 +53,16 @@ public class EpdcAppVolunteerInfoController {
return result;
}
/**
* 获取排行榜数据
*
* @return
*/
@GetMapping("getRankingList")
public Result<List<EpdcGetVolunteerRankDTO>> getRankingList() {
return volunteerInfoService.getRankingList();
}
}

7
esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/dao/VolunteerInfoDao.java

@ -21,6 +21,7 @@ import com.elink.esua.epdc.commons.mybatis.dao.BaseDao;
import com.elink.esua.epdc.dto.UserTagDTO;
import com.elink.esua.epdc.dto.VolunteerInfoDTO;
import com.elink.esua.epdc.dto.epdc.result.EpdcAdjustVolunteerPointsDTO;
import com.elink.esua.epdc.dto.epdc.result.EpdcGetVolunteerRankDTO;
import com.elink.esua.epdc.entity.VolunteerInfoEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -99,5 +100,11 @@ public interface VolunteerInfoDao extends BaseDao<VolunteerInfoEntity> {
**/
EpdcAdjustVolunteerPointsDTO selectAdjustVolunteerPointsDTO(String id);
/**
* 获取排行榜
* @author wanggongfeng
* @return
*/
List<EpdcGetVolunteerRankDTO> getRankingList();
}

7
esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/service/VolunteerInfoService.java

@ -24,6 +24,7 @@ import com.elink.esua.epdc.dto.UserTagDTO;
import com.elink.esua.epdc.dto.VolunteerInfoDTO;
import com.elink.esua.epdc.dto.epdc.form.EpdcCompleteVolunteerInfoFormDTO;
import com.elink.esua.epdc.dto.epdc.result.EpdcAdjustVolunteerPointsDTO;
import com.elink.esua.epdc.dto.epdc.result.EpdcGetVolunteerRankDTO;
import com.elink.esua.epdc.entity.VolunteerInfoEntity;
import java.util.List;
@ -163,6 +164,12 @@ public interface VolunteerInfoService extends BaseService<VolunteerInfoEntity> {
**/
Result<EpdcAdjustVolunteerPointsDTO> getAdjustVolunteerPointsDTO(String userId);
/**
* 获取排行榜
* @author wanggongfeng
* @return
*/
Result<List<EpdcGetVolunteerRankDTO>> getRankingList();
}

12
esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/java/com/elink/esua/epdc/service/impl/VolunteerInfoServiceImpl.java

@ -32,6 +32,7 @@ import com.elink.esua.epdc.dto.VolunteerInfoDTO;
import com.elink.esua.epdc.dto.epdc.form.EpdcCompleteVolunteerInfoFormDTO;
import com.elink.esua.epdc.dto.epdc.form.EpdcInformationFormDTO;
import com.elink.esua.epdc.dto.epdc.result.EpdcAdjustVolunteerPointsDTO;
import com.elink.esua.epdc.dto.epdc.result.EpdcGetVolunteerRankDTO;
import com.elink.esua.epdc.entity.VolunteerInfoEntity;
import com.elink.esua.epdc.redis.VolunteerInfoRedis;
import com.elink.esua.epdc.service.UserService;
@ -242,4 +243,15 @@ public class VolunteerInfoServiceImpl extends BaseServiceImpl<VolunteerInfoDao,
return new Result<EpdcAdjustVolunteerPointsDTO>().ok(adjustVolunteerPointsDTO);
}
/**
* 获取排行榜
* @author wanggongfeng
* @return
*/
@Override
public Result<List<EpdcGetVolunteerRankDTO>> getRankingList() {
List<EpdcGetVolunteerRankDTO> list = baseDao.getRankingList();
return new Result<List<EpdcGetVolunteerRankDTO>>().ok(list);
}
}

19
esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/resources/mapper/VolunteerInfoDao.xml

@ -168,4 +168,23 @@
AND m.ID = #{id}
</select>
<select id="getRankingList" resultType="com.elink.esua.epdc.dto.epdc.result.EpdcGetVolunteerRankDTO">
select volunteerInfo.* from (
select (@i:=@i+1) sort, info.*
from (select
'1' show_flag,
DATE_FORMAT(NOW(),'%Y-%m-%d') generate_date,
vi.ID volunteer_id,
vi.USER_ID,
eu.FACE_IMG,
eu.NICKNAME,
eu.PARTY_FLAG,
vi.KINDNESS_TIME,
vi.PARTICIPATION_NUM
from epdc_volunteer_info vi
left join epdc_user eu on eu.id = vi.USER_ID
order by vi.KINDNESS_TIME desc,vi.PARTICIPATION_NUM desc,vi.REGIST_TIME ) as info, (select @i:=0) j ) volunteerInfo
where sort lt; 11
</select>
</mapper>

Loading…
Cancel
Save