提交 8a732d77 作者: panda 提交者: 余乾开

根据新旧服务生成评论数量

上级 c32bef62
......@@ -19,17 +19,17 @@ import com.mmc.pms.page.PageResult;
import com.mmc.pms.service.BackstageTaskService;
import com.mmc.pms.service.InspComtService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
......@@ -84,7 +84,7 @@ public class BackstageTaskServiceImpl implements BackstageTaskService {
serviceDTO.setApplicationName(categoriesNameMap.get(serviceDTO.getApplicationId()));
serviceDTO.setIndustryName(categoriesNameMap.get(serviceDTO.getIndustryId()));
}
List<InspComtDO> inspComtList = RandomGetInspComt(id);
List<InspComtDO> inspComtList = RandomGetInspComt(id, 20, 200);
serviceDTO.setInspComtList(inspComtList);
serviceDTO.setInspComtAmount(inspComtList.size());
return ResultBody.success(serviceDTO);
......@@ -141,9 +141,6 @@ public class BackstageTaskServiceImpl implements BackstageTaskService {
@Override
public PageResult queryWorkServiceList(ServiceQO param, HttpServletRequest request) {
log.info(
"开始queryWorkServiceList==>{}",
JSONObject.toJSONString(DateFormatUtils.format(new Date(), DateConstant.YYYYMMDDHHMMSS)));
Integer pageNo = param.getPageNo();
param.buildCurrentPage();
List<Integer> userIds = null;
......@@ -163,9 +160,6 @@ public class BackstageTaskServiceImpl implements BackstageTaskService {
backstageTaskServiceDao.queryPageByLimit(param, categoriesIds, userIds);
List<WorkServiceDTO> workServiceDTOList = getWorkServiceDTOS(pageList);
log.info(
"结束queryWorkServiceList==>{}",
JSONObject.toJSONString(DateFormatUtils.format(new Date(), DateConstant.YYYYMMDDHHMMSS)));
return PageResult.buildPage(pageNo, param.getPageSize(), count, workServiceDTOList);
}
......@@ -195,6 +189,7 @@ public class BackstageTaskServiceImpl implements BackstageTaskService {
String companyName = "浙江科比特创新科技有限公司";
List<WorkServiceDTO> workServiceDTOList = new ArrayList<>();
for (ServiceDO item : pageList) {
List<InspComtDO> inspComtDOS = generateComments(item);
WorkServiceDTO workServiceDTO =
WorkServiceDTO.builder()
.id(item.getId())
......@@ -204,22 +199,47 @@ public class BackstageTaskServiceImpl implements BackstageTaskService {
.serviceIntroduction(item.getServiceIntroduction())
.video(item.getVideo())
.shareCard(item.getShareCard())
.inspComtList(inspComtDOS)
.inspComtAmount(inspComtDOS.size())
.build();
workServiceDTOList.add(workServiceDTO);
}
return workServiceDTOList;
}
/** 根据id随机获取50条以上的评论 */
private List<InspComtDO> RandomGetInspComt(Integer id) {
/**
* 生成评论
*
* @param item
* @return
*/
private List<InspComtDO> generateComments(ServiceDO item) {
Date newServiceHours = null;
try {
newServiceHours = DateUtils.parseDate("2023-06-26 23:59:59", DateConstant.YYYYMMDDHHMMSS);
} catch (ParseException e) {
e.printStackTrace();
}
List<InspComtDO> inspComtDOS;
// 在这个时间之后属于新服务,生成评论的数量在3-5个之间
if (item.getCreateTime().after(newServiceHours)) {
inspComtDOS = RandomGetInspComt(item.getId(), 3, 5);
} else {
inspComtDOS = RandomGetInspComt(item.getId(), 20, 200);
}
return inspComtDOS;
}
/** 根据id随机获取N条的评论 */
private List<InspComtDO> RandomGetInspComt(Integer id, Integer min, Integer max) {
String listStr = (String) redisTemplate.opsForValue().get(id);
List<InspComtDO> inspComtRandomList = null;
if (StringUtils.isNotBlank(listStr)) {
inspComtRandomList = JSONArray.parseArray(listStr, InspComtDO.class);
} else {
inspComtRandomList = inspComtService.randomGetInspComtList(RandomUtils.nextInt(50, 9999));
inspComtRandomList = inspComtService.randomGetInspComtList(RandomUtils.nextInt(min, max));
String toJSONString = JSONObject.toJSONString(inspComtRandomList);
redisTemplate.opsForValue().set(id, toJSONString, 2L, TimeUnit.DAYS);
redisTemplate.opsForValue().set(id, toJSONString);
}
return inspComtRandomList;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论