mirror of
https://github.com/weizhiqiang1995/erp-pro.git
synced 2024-11-15 12:32:08 +08:00
定时任务拆分
This commit is contained in:
parent
a8b3bd8e5d
commit
eeec8c90f5
9 changed files with 3 additions and 426 deletions
|
@ -1,45 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 卫志强 QQ:598748873@qq.com Inc. All rights reserved. 开源地址:https://gitee.com/doc_wei01/skyeye
|
||||
******************************************************************************/
|
||||
|
||||
package com.skyeye.eve.entity.shop.store;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @ClassName: ShopStoreIntercourseEntity
|
||||
* @Description:
|
||||
* @author: skyeye云系列--卫志强
|
||||
* @date: 2022/3/10 21:51
|
||||
* @Copyright: 2021 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
|
||||
* 注意:本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
|
||||
*/
|
||||
@Data
|
||||
public class ShopStoreIntercourseMation {
|
||||
|
||||
/**
|
||||
* 保养门店id
|
||||
*/
|
||||
private String keepfitStoreId;
|
||||
|
||||
/**
|
||||
* 套餐购买门店
|
||||
*/
|
||||
private String mealByStoreId;
|
||||
|
||||
/**
|
||||
* 总的耗材费用
|
||||
*/
|
||||
private String mealAllSinglePrice;
|
||||
|
||||
/**
|
||||
* 创建日期,格式为:yyyy-MM-dd
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 状态 1.待套餐购买门店确认 2.待保养门店确认 3.已确认
|
||||
*/
|
||||
private Integer state;
|
||||
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 卫志强 QQ:598748873@qq.com Inc. All rights reserved. 开源地址:https://gitee.com/doc_wei01/skyeye
|
||||
******************************************************************************/
|
||||
|
||||
package com.skyeye.eve.entity.shop.store;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName: ShopStoreIntercourseEntity
|
||||
* @Description: 门店往来入参实体类
|
||||
* @author: skyeye云系列--卫志强
|
||||
* @date: 2022/3/10 21:51
|
||||
* @Copyright: 2021 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
|
||||
* 注意:本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
|
||||
*/
|
||||
@Data
|
||||
public class ShopStoreIntercourseMationRest {
|
||||
|
||||
private List<ShopStoreIntercourseMation> shopStoreIntercourseMationList;
|
||||
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 卫志强 QQ:598748873@qq.com Inc. All rights reserved. 开源地址:https://gitee.com/doc_wei01/skyeye
|
||||
******************************************************************************/
|
||||
|
||||
package com.skyeye.eve.rest.shop.store;
|
||||
|
||||
import com.skyeye.common.client.ClientConfiguration;
|
||||
import com.skyeye.eve.entity.shop.store.ShopStoreIntercourseMationRest;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* @ClassName: ShopStoreService
|
||||
* @Description: 商城门店
|
||||
* @author: skyeye云系列--卫志强
|
||||
* @date: 2022/2/2 15:24
|
||||
* @Copyright: 2021 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
|
||||
* 注意:本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
|
||||
*/
|
||||
@FeignClient(value = "${webroot.skyeye-shop}", configuration = ClientConfiguration.class)
|
||||
public interface ShopStoreService {
|
||||
|
||||
/**
|
||||
* 获取指定日期的支出/收入往来的数据
|
||||
*
|
||||
* @param day 日期,格式为yyyy-MM-dd
|
||||
* @return 指定日期的支出/收入往来的数据
|
||||
*/
|
||||
@GetMapping("/queryStoreIntercourseByDay")
|
||||
String queryStoreIntercourseByDay(@RequestParam("day") String day);
|
||||
|
||||
/**
|
||||
* 获取指定日期的支出/收入往来的数据---用于查指定日期的数据是否入库
|
||||
*
|
||||
* @param day 日期,格式为yyyy-MM-dd
|
||||
* @return 指定日期的支出/收入往来的数据
|
||||
*/
|
||||
@GetMapping("/queryStoreIntercourseListByDay")
|
||||
String queryStoreIntercourseListByDay(@RequestParam("day") String day);
|
||||
|
||||
/**
|
||||
* 新增支出/收入往来的数据
|
||||
*
|
||||
* @param shopStoreIntercourseMationRest 支出/收入往来的数据
|
||||
*/
|
||||
@PostMapping("/insertStoreIntercourse")
|
||||
String insertStoreIntercourse(ShopStoreIntercourseMationRest shopStoreIntercourseMationRest);
|
||||
|
||||
}
|
|
@ -27,8 +27,4 @@ public interface MainPageDao {
|
|||
|
||||
List<Map<String, Object>> queryKnowledgeContentPhoneList(Map<String, Object> map);
|
||||
|
||||
int insertForumHotByList(List<Map<String, Object>> list);
|
||||
|
||||
int insertForumStatisticsDayByList(List<Map<String, Object>> list);
|
||||
|
||||
}
|
||||
|
|
|
@ -95,7 +95,8 @@ public class MainPageServiceImpl implements MainPageService {
|
|||
String createTime = ToolUtil.timeFormat(m.get("createTime").toString());
|
||||
m.put("createTime", createTime);
|
||||
String key = ForumConstants.forumBrowseNumsByForumId(m.get("id").toString());
|
||||
if (ToolUtil.isBlank(jedisClient.get(key))) {//浏览量
|
||||
if (ToolUtil.isBlank(jedisClient.get(key))) {
|
||||
// 浏览量
|
||||
m.put("browseNum", 0);
|
||||
} else {
|
||||
String browseNum = jedisClient.get(key);
|
||||
|
@ -103,7 +104,7 @@ public class MainPageServiceImpl implements MainPageService {
|
|||
}
|
||||
}
|
||||
//按浏览量和评论数给集合排序
|
||||
beans.sort(new Comparator<Map<String, Object>>() {//Comparator 比较器. 需要实现比较方法
|
||||
beans.sort(new Comparator<Map<String, Object>>() {
|
||||
@Override
|
||||
public int compare(Map<String, Object> m1, Map<String, Object> m2) {
|
||||
Integer m1num = Integer.parseInt(m1.get("browseNum").toString()) + Integer.parseInt(m1.get("commentNum").toString());
|
||||
|
|
|
@ -138,22 +138,4 @@
|
|||
LIMIT 8
|
||||
</select>
|
||||
|
||||
<insert id="insertForumHotByList" parameterType="java.util.Map">
|
||||
insert into forum_hot
|
||||
(id, forum_id, update_time)
|
||||
values
|
||||
<foreach collection="list" item="item" index="index" separator="," >
|
||||
(#{item.id}, #{item.forumId}, #{item.time})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<insert id="insertForumStatisticsDayByList" parameterType="java.util.Map">
|
||||
insert into forum_statistics_day
|
||||
(id, forum_id, browse_num, comment_num, create_time)
|
||||
values
|
||||
<foreach collection="list" item="item" index="index" separator="," >
|
||||
(#{item.id}, #{item.forumId}, #{item.bnum}, #{item.cnum}, #{item.time})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
|
@ -1,189 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 卫志强 QQ:598748873@qq.com Inc. All rights reserved. 开源地址:https://gitee.com/doc_wei01/skyeye
|
||||
******************************************************************************/
|
||||
|
||||
package com.skyeye.sys.quartz;
|
||||
|
||||
import com.skyeye.common.constans.ForumConstants;
|
||||
import com.skyeye.common.util.DateAfterSpacePointTime;
|
||||
import com.skyeye.common.util.DateUtil;
|
||||
import com.skyeye.common.util.ToolUtil;
|
||||
import com.skyeye.eve.dao.MainPageDao;
|
||||
import com.skyeye.jedis.JedisClientService;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @ClassName: HotForumQuartz
|
||||
* @Description: 每天凌晨两点去计算每日热门贴
|
||||
* @author: skyeye云系列--卫志强
|
||||
* @date: 2021/7/6 23:09
|
||||
* @Copyright: 2021 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
|
||||
* 注意:本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
|
||||
*/
|
||||
@Component
|
||||
public class HotForumQuartz {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(HotForumQuartz.class);
|
||||
|
||||
@Autowired
|
||||
public JedisClientService jedisClient;
|
||||
|
||||
@Autowired
|
||||
public MainPageDao mainPageDao;
|
||||
|
||||
/**
|
||||
* 定时器计算每日热门贴
|
||||
*/
|
||||
@XxlJob("hotForumQuartz")
|
||||
public void editHotForumMation() {
|
||||
try {
|
||||
String yestoday = DateAfterSpacePointTime.getSpecifiedTime(
|
||||
DateAfterSpacePointTime.ONE_DAY.getType(), DateUtil.getTimeAndToString(), DateUtil.YYYY_MM_DD, DateAfterSpacePointTime.AroundType.BEFORE);
|
||||
String everydayBrowseKey = ForumConstants.forumEverydayBrowseIdsByTime(yestoday);
|
||||
if (!ToolUtil.isBlank(jedisClient.get(everydayBrowseKey))) {//获取昨天被浏览过的帖子
|
||||
String str = jedisClient.get(everydayBrowseKey);
|
||||
String[] forumarr = str.split(",");
|
||||
List<Map<String, Object>> beans = new LinkedList<>();
|
||||
List<Map<String, Object>> list = new LinkedList<>();
|
||||
for (int i = 0, len = forumarr.length; i < len; i++) {
|
||||
//计算一天的浏览量
|
||||
String browseNumsKey = ForumConstants.forumBrowseNumsByForumId(forumarr[i]);
|
||||
String ybrowseNumsKey = ForumConstants.forumYesterdayBrowseNumsByForumId(forumarr[i]);
|
||||
String bnownum = "0";
|
||||
if (!ToolUtil.isBlank(jedisClient.get(browseNumsKey))) {
|
||||
bnownum = jedisClient.get(browseNumsKey);//帖子当前的浏览量
|
||||
}
|
||||
String byestodaynum = "0";
|
||||
if (!ToolUtil.isBlank(jedisClient.get(ybrowseNumsKey))) {
|
||||
byestodaynum = jedisClient.get(ybrowseNumsKey);//帖子昨天的浏览量
|
||||
}
|
||||
String bnum = String.valueOf(Integer.parseInt(bnownum) - Integer.parseInt(byestodaynum));//帖子一天的浏览量
|
||||
|
||||
//计算一天的评论量
|
||||
String commentNumsKey = ForumConstants.forumCommentNumsByForumId(forumarr[i]);
|
||||
String ycommentNumsKey = ForumConstants.forumYesterdayCommentNumsByForumId(forumarr[i]);
|
||||
String cnownum = "0";
|
||||
if (!ToolUtil.isBlank(jedisClient.get(commentNumsKey))) {
|
||||
cnownum = jedisClient.get(commentNumsKey);//帖子当前的评论量
|
||||
}
|
||||
String cyestodaynum = "0";
|
||||
if (!ToolUtil.isBlank(jedisClient.get(ycommentNumsKey))) {
|
||||
cyestodaynum = jedisClient.get(ycommentNumsKey);//帖子昨天的评论量
|
||||
}
|
||||
String cnum = String.valueOf(Integer.parseInt(cnownum) - Integer.parseInt(cyestodaynum));//帖子一天的评论量
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", ToolUtil.getSurFaceId());
|
||||
map.put("forumId", forumarr[i]);
|
||||
map.put("bnum", bnum);
|
||||
map.put("cnum", cnum);
|
||||
map.put("time", yestoday);
|
||||
list.add(map);
|
||||
jedisClient.set(ybrowseNumsKey, bnownum);//更新浏览量
|
||||
jedisClient.set(ycommentNumsKey, cnownum);//更新评论量
|
||||
|
||||
String everyforumEverydayNums = ForumConstants.everyforumEverydayNumsByIdAndTime(forumarr[i], yestoday);
|
||||
jedisClient.set(everyforumEverydayNums, String.valueOf(Integer.parseInt(bnum) + Integer.parseInt(cnum)));//将每个帖子每天的浏览量+评论量存入redis中
|
||||
|
||||
if (list.size() >= 20) {//每20条数据保存一次
|
||||
mainPageDao.insertForumStatisticsDayByList(list);//将每天被浏览过的帖子存入统计表中
|
||||
if (!beans.isEmpty()) {
|
||||
list.addAll(beans);
|
||||
beans.clear();
|
||||
}
|
||||
list = sortListByNums(list, yestoday);//根据近七天的浏览量和评论量的算术平均值对list进行排序
|
||||
beans.addAll(list.subList(0, 6));//取前六条放入beans中
|
||||
list.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (!list.isEmpty()) {
|
||||
mainPageDao.insertForumStatisticsDayByList(list);//将每天被浏览过的帖子存入统计表中
|
||||
if (!beans.isEmpty()) {
|
||||
list.addAll(beans);
|
||||
beans.clear();
|
||||
}
|
||||
list = sortListByNums(list, yestoday);//根据近七天的浏览量和评论量的算术平均值对list进行排序
|
||||
int count = list.size();
|
||||
int pageMaxSize = 6;
|
||||
if (count < pageMaxSize) {
|
||||
pageMaxSize = count;
|
||||
}
|
||||
beans.addAll(list.subList(0, pageMaxSize));//取前六条放入beans中
|
||||
}
|
||||
|
||||
if (!beans.isEmpty()) {
|
||||
mainPageDao.insertForumHotByList(beans);
|
||||
}
|
||||
jedisClient.del(everydayBrowseKey);//清空每天被浏览过的帖子
|
||||
} else {
|
||||
jedisClient.del(everydayBrowseKey);//清空每天被浏览过的帖子
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("editHotForumMation error.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取过去7天内的日期数组
|
||||
*
|
||||
* @return 日期数组
|
||||
* @throws ParseException
|
||||
*/
|
||||
public static ArrayList<String> pastDay(String time) throws ParseException {
|
||||
ArrayList<String> pastDaysList = new ArrayList<>();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.YYYY_MM_DD);
|
||||
Date date = sdf.parse(time);
|
||||
for (int i = 6; i >= 0; i--) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - i);
|
||||
Date today = calendar.getTime();
|
||||
String result = sdf.format(today);
|
||||
pastDaysList.add(result);
|
||||
}
|
||||
return pastDaysList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据近七天的浏览量和评论量的算术平均值对list进行排序
|
||||
*
|
||||
* @return 日期数组
|
||||
* @throws ParseException
|
||||
*/
|
||||
public List<Map<String, Object>> sortListByNums(List<Map<String, Object>> list, String time) throws ParseException {
|
||||
DecimalFormat df = new DecimalFormat("0.00");//格式化小数
|
||||
for (Map<String, Object> m : list) {
|
||||
ArrayList<String> datelist = pastDay(time);//获取近七天的日期数组集合
|
||||
int nums = 0;
|
||||
for (String date : datelist) {
|
||||
String everyforumEverydayNum = ForumConstants.everyforumEverydayNumsByIdAndTime(m.get("forumId").toString(), date);
|
||||
if (!ToolUtil.isBlank(jedisClient.get(everyforumEverydayNum))) {//获取每个帖子每天的浏览量+评论量
|
||||
nums += Integer.parseInt(jedisClient.get(everyforumEverydayNum));
|
||||
}
|
||||
}
|
||||
m.put("nums", String.valueOf(df.format((float) nums / 7)));//将帖子近七天的评论量、浏览量的算术平均值保留两位小数放入map中
|
||||
}
|
||||
//按帖子近七天的评论量、浏览量的算术平均值给集合排序
|
||||
list.sort(new Comparator<Map<String, Object>>() {//Comparator 比较器. 需要实现比较方法
|
||||
@Override
|
||||
public int compare(Map<String, Object> m1, Map<String, Object> m2) {
|
||||
Integer m1num = (int) Float.parseFloat(m1.get("nums").toString()) * 100;
|
||||
Integer m2num = (int) Float.parseFloat(m2.get("nums").toString()) * 100;
|
||||
int flag = m1num.compareTo(m2num);
|
||||
return -flag; // 取反,按倒序排列
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 卫志强 QQ:598748873@qq.com Inc. All rights reserved. 开源地址:https://gitee.com/doc_wei01/skyeye
|
||||
******************************************************************************/
|
||||
|
||||
package com.skyeye.sys.quartz;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.skyeye.common.client.ExecuteFeignClient;
|
||||
import com.skyeye.common.util.DateAfterSpacePointTime;
|
||||
import com.skyeye.common.util.DateUtil;
|
||||
import com.skyeye.common.util.ToolUtil;
|
||||
import com.skyeye.eve.entity.shop.store.ShopStoreIntercourseMation;
|
||||
import com.skyeye.eve.entity.shop.store.ShopStoreIntercourseMationRest;
|
||||
import com.skyeye.eve.rest.shop.store.ShopStoreService;
|
||||
import com.skyeye.jedis.util.RedisLock;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: ShopStoreIntercourseQuartz
|
||||
* @Description: 门店昨日支出/收入往来计算
|
||||
* @author: skyeye云系列--卫志强
|
||||
* @date: 2022/3/10 21:13
|
||||
* @Copyright: 2021 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
|
||||
* 注意:本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
|
||||
*/
|
||||
@Component
|
||||
public class ShopStoreIntercourseQuartz {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(ShopStoreIntercourseQuartz.class);
|
||||
|
||||
@Autowired
|
||||
private ShopStoreService shopStoreService;
|
||||
|
||||
private static final String LOCK_KEY = "calcShopStoreIntercourse";
|
||||
|
||||
/**
|
||||
* 定时器计算门店昨日支出/收入往来信息,每天凌晨两点执行一次
|
||||
*/
|
||||
@XxlJob("shopStoreIntercourseQuartz")
|
||||
public void calcShopStoreIntercourse() {
|
||||
log.info("定时器计算门店昨日支出/收入往来信息执行 start");
|
||||
RedisLock lock = new RedisLock(LOCK_KEY);
|
||||
try {
|
||||
if (!lock.lock()) {
|
||||
// 加锁失败
|
||||
return;
|
||||
}
|
||||
// 得到昨天的时间
|
||||
String yesterdayTime = DateAfterSpacePointTime.getSpecifiedTime(
|
||||
DateAfterSpacePointTime.ONE_DAY.getType(), DateUtil.getTimeAndToString(), DateUtil.YYYY_MM_DD, DateAfterSpacePointTime.AroundType.BEFORE);
|
||||
log.info("yesterdayTime is {}.", yesterdayTime);
|
||||
// 判断昨天的数据是否已经统计过并入库,如果已经统计过,则不会进行下一次的统计
|
||||
List<Map<String, Object>> yesterdayData = ExecuteFeignClient.get(() -> shopStoreService.queryStoreIntercourseListByDay(yesterdayTime)).getRows();
|
||||
if (!CollectionUtils.isEmpty(yesterdayData)) {
|
||||
log.info("已统计过昨日数据,不再进行统计");
|
||||
return;
|
||||
}
|
||||
log.info("开始统计");
|
||||
// 获取昨天的往来数据信息
|
||||
yesterdayData = ExecuteFeignClient.get(() -> shopStoreService.queryStoreIntercourseByDay(yesterdayTime)).getRows();
|
||||
List<ShopStoreIntercourseMation> shopStoreIntercourse = JSONUtil.toList(JSON.toJSONString(yesterdayData), ShopStoreIntercourseMation.class);
|
||||
shopStoreIntercourse.forEach(bean -> {
|
||||
if (ToolUtil.isBlank(bean.getMealByStoreId())) {
|
||||
bean.setState(2);
|
||||
} else {
|
||||
bean.setState(1);
|
||||
}
|
||||
});
|
||||
log.info("解析数据为 {}.", JSON.toJSONString(shopStoreIntercourse));
|
||||
ShopStoreIntercourseMationRest shopStoreIntercourseVO = new ShopStoreIntercourseMationRest();
|
||||
shopStoreIntercourseVO.setShopStoreIntercourseMationList(shopStoreIntercourse);
|
||||
shopStoreService.insertStoreIntercourse(shopStoreIntercourseVO);
|
||||
log.info("保存数据完成");
|
||||
} catch (Exception e) {
|
||||
log.warn("calcShopStoreIntercourse error.", e);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
log.info("定时器计算门店昨日支出/收入往来信息 end");
|
||||
}
|
||||
|
||||
}
|
|
@ -29,8 +29,6 @@ logging:
|
|||
com.skyeye.eve.dao: debug
|
||||
|
||||
webroot:
|
||||
# 商城服务
|
||||
skyeye-shop: skyeye-shop-${spring.profiles.active}
|
||||
# 工作流相关的服务
|
||||
skyeye-flowable: skyeye-flowable-${spring.profiles.active}
|
||||
# xxl-job
|
||||
|
|
Loading…
Reference in a new issue