Commit 484c2c74 by 田超

Merge branch 'feature/1003881-1' into 'master'

feat: [none] 读书报告bug修改

See merge request rays/pcloud-book!1121
parents acb2a77f a3e5efb8
......@@ -28,6 +28,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
......@@ -149,14 +150,13 @@ public class AppletRecordStatisBizImpl implements AppletRecordStatisBiz {
private List<AppletRecordBookDTO> getAllUserBookRecordList(Long wechatUserId) {
String userBooksRedisKey = AppletConstants.APPLET_RECORD_USER_BOOK_LIST + "_" + wechatUserId+"_" + DateUtils.getShortDateStr();
List<AppletRecordBookDTO> userBooks = JedisClusterUtils.getJsonList(userBooksRedisKey, AppletRecordBookDTO.class);
// 测试时临时取消缓存
// if(CollectionUtils.isEmpty(userBooks)){
if(CollectionUtils.isEmpty(userBooks)){
userBooks = appletRecordDao.getBooksByWechatUserId(wechatUserId);
if(CollectionUtils.isEmpty(userBooks)){
return Lists.newArrayList();
}
JedisClusterUtils.setJsonList(userBooksRedisKey, userBooks, 3600 * 24);
// }
}
return userBooks;
}
......@@ -222,6 +222,10 @@ public class AppletRecordStatisBizImpl implements AppletRecordStatisBiz {
if(dto.getRecordType() == null){
continue;
}
if(StringUtil.isEmpty(dto.getSourceType())){
dto.setSourceTypeName("浏览资源");
continue;
}
if(dto.getRecordType() == 5){
ProductTypeDto productTypeDto = productTypeDtoMap.get(dto.getSourceType());
if(productTypeDto == null || StringUtil.isEmpty(productTypeDto.getTypeName())){
......@@ -293,7 +297,7 @@ public class AppletRecordStatisBizImpl implements AppletRecordStatisBiz {
public void addWeekAppletRecordStatis(String mondayDate) {
// 获取7天前的日期
Date prevWeekDay = DateUtils.addDay(new Date(), -7);
if(mondayDate != null){
if(StringUtil.isNotEmpty(mondayDate)){
prevWeekDay = DateUtils.getDateByStr(mondayDate);
}
// 校准日期为上周一(加一天是因为这里它把周日当成是一周的起点)
......@@ -315,6 +319,7 @@ public class AppletRecordStatisBizImpl implements AppletRecordStatisBiz {
// 每次更新1000个用户
Long limitNumber = 1000L;
long limitTotalPage = statisUserCount % limitNumber == 0 ? (statisUserCount / limitNumber) : (statisUserCount / limitNumber + 1);
try {
for (int i = 0; i < limitTotalPage; i++) {
long startTime = System.currentTimeMillis();
LOGGER.info(MessageFormat.format("addWeekAppletRecordStatis-startTime:{0};i:{1}", startTime, i));
......@@ -329,5 +334,8 @@ public class AppletRecordStatisBizImpl implements AppletRecordStatisBiz {
endTime = System.currentTimeMillis();
LOGGER.info("addWeekAppletRecordStatis4News-startTime:"+startTime+";endTime:" + endTime + ";间隔:"+ (startTime - endTime));
}
} catch (DuplicateKeyException e){
throw new BizException(BizException.DB_UPDATE_RESULT_0.getCode(), "该周的统计数据已存在,如需重新执行,请先删除相关统计数据");
}
}
}
......@@ -215,11 +215,10 @@ public class AppletRecordStatisReportBizImpl implements AppletRecordStatisReport
String redisKey = AppletConstants.APPLET_RECORD_HISTORY_STATIS_REPORT_LAST_DATE + wechatUserId;
String lastDate = JedisClusterUtils.get(redisKey);
String monday = DateUtils.getReqDate(DateUtils.addDay(DateUtils.getWeekStart(new Date()), 1));
// 测试时临时取消缓存
// 如果本周已经生成过,则return
// if(monday.equals(lastDate)){
// return;
// }
if(monday.equals(lastDate)){
return;
}
// 本周已经生成记录标识
JedisClusterUtils.set(redisKey, monday, 3600 * 24 * 7);
// 获取开始时间到上周所有的周一
......@@ -239,7 +238,7 @@ public class AppletRecordStatisReportBizImpl implements AppletRecordStatisReport
AppletRecordStatisReport statisReport;
Date sunday;
for (Date _monday : allMonday) {
sunday = DateUtils.addDay(_monday, 7);
sunday = DateUtils.addDay(_monday, 6);
statisReport = new AppletRecordStatisReport();
// 计算本周分数结果
BigDecimal score = getReportScore(wechatUserId, _monday, sunday);
......
......@@ -67,7 +67,7 @@ public class AppletConstants {
/**
* 阅读报告开始时间
*/
public static final Date APPLET_RECORD_STATIS_REPORT_START_DATE = DateUtils.getDateByStr("2020-11-30");
public static final Date APPLET_RECORD_STATIS_REPORT_START_DATE = DateUtils.getDateByStr("2021-01-04");
/**
* 最后一次历史统计报告的时间
......
......@@ -134,7 +134,7 @@ public class AppletServiceImpl implements AppletService {
@Override
@ApiOperation("统计指定周的数据")
@GetMapping("addWeekAppletRecordStatis")
public void addWeekAppletRecordStatis(@RequestParam("mondayDate")String mondayDate) {
public void addWeekAppletRecordStatis(@RequestParam(value = "mondayDate",required = false)String mondayDate) {
appletRecordStatisBiz.addWeekAppletRecordStatis(mondayDate);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment