|
@@ -3,6 +3,7 @@ package cn.com.ty.lift.batch.applet.util;
|
|
|
import cn.com.ty.lift.batch.applet.constants.DataStatisticsConstants;
|
|
|
import cn.com.ty.lift.batch.applet.dao.model.BaseDataModel;
|
|
|
import cn.com.ty.lift.batch.applet.dao.model.request.CommonRequest;
|
|
|
+import cn.hutool.core.date.DatePattern;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
@@ -26,44 +27,6 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
public class DataStatisticsUtil {
|
|
|
|
|
|
- /**
|
|
|
- * @param
|
|
|
- * @return
|
|
|
- * @description 将数据通过公司id分组并放入到redis中
|
|
|
- * @date 2020/2/5 3:22 下午
|
|
|
- */
|
|
|
- public static void putStatisticsDataToRedis(List<? extends BaseDataModel> dataList, RedisTemplate redisTemplate,
|
|
|
- String dataKey) {
|
|
|
- Map<Long, ? extends List<? extends BaseDataModel>> mtCompanyIdToData = new HashMap<>();
|
|
|
- if (dataList != null && dataList.size() > 0) {
|
|
|
- //通过公司id对数据进行分组
|
|
|
- mtCompanyIdToData = dataList.stream().collect(Collectors.groupingBy(baseDataModel -> {
|
|
|
- if (baseDataModel.getMtCompanyId() != null) {
|
|
|
- return baseDataModel.getMtCompanyId();
|
|
|
- }
|
|
|
- return 123456789L;
|
|
|
- }));
|
|
|
- }
|
|
|
- //存放缓存时间为1天
|
|
|
- redisTemplate.opsForValue().set(dataKey, mtCompanyIdToData, 3L, TimeUnit.DAYS);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param
|
|
|
- * @return
|
|
|
- * @description 获取当前公司的数据
|
|
|
- * @date 2020/2/5 3:26 下午
|
|
|
- */
|
|
|
- public static List<? extends BaseDataModel> getStatisticsDataFromRedis(RedisTemplate redisTemplate, String dataKey,
|
|
|
- Long mtCompanyId) {
|
|
|
- Map<Long, ? extends List<? extends BaseDataModel>> mtCompanyIdToData =
|
|
|
- (Map<Long, ? extends List<? extends BaseDataModel>>) redisTemplate.opsForValue().get(dataKey);
|
|
|
- if (mtCompanyIdToData != null) {
|
|
|
- return mtCompanyIdToData.get(mtCompanyId.toString());
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* @param
|
|
|
* @return
|
|
@@ -114,7 +77,6 @@ public class DataStatisticsUtil {
|
|
|
|
|
|
/**
|
|
|
* @param localDateTime 时间数据
|
|
|
- * @return
|
|
|
* @description 获取时间的月份值(数字)
|
|
|
* @date 2020/2/7 3:06 下午
|
|
|
*/
|
|
@@ -126,6 +88,19 @@ public class DataStatisticsUtil {
|
|
|
return localDateTime.getMonthValue();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param localDate 时间数据
|
|
|
+ * @description 获取时间的月份值(数字)
|
|
|
+ * @date 2020/2/7 3:06 下午
|
|
|
+ */
|
|
|
+ public static int getMonth(LocalDate localDate) {
|
|
|
+ //为空返回0
|
|
|
+ if (localDate == null) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ return localDate.getMonthValue();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param afterTime 较大时间
|
|
|
* @param beforeTime 较小时间
|
|
@@ -294,4 +269,37 @@ public class DataStatisticsUtil {
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return 初始化 map
|
|
|
+ * @description 初始化map数据
|
|
|
+ * @date 2020/5/22 10:38 上午
|
|
|
+ */
|
|
|
+ public static Map<Integer, Map<Integer, Long>> initMaintenanceNum() {
|
|
|
+ Map<Integer, Map<Integer, Long>> monthToMaintenance = new HashMap<>();
|
|
|
+ int nowMonth = LocalDate.now().getMonthValue();
|
|
|
+ for (int month = 1; month <= nowMonth; month++) {
|
|
|
+ Map<Integer, Long> maintenanceStatusToNum = new HashMap<>();
|
|
|
+ //计划维保总数量
|
|
|
+ maintenanceStatusToNum.put(0, 0L);
|
|
|
+ //维保完成数量
|
|
|
+ maintenanceStatusToNum.put(1, 0L);
|
|
|
+ monthToMaintenance.put(month, maintenanceStatusToNum);
|
|
|
+ }
|
|
|
+ return monthToMaintenance;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param commonRequest commonRequest
|
|
|
+ * @description 初始化时间 年初 - 当前时间
|
|
|
+ * @date 2020/5/22 11:24 上午
|
|
|
+ */
|
|
|
+ public static void initCommonRequest(CommonRequest commonRequest) {
|
|
|
+ //设置年初时间
|
|
|
+ String yearStartTime = getYearFirstTime().format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN));
|
|
|
+ //设置当前时间
|
|
|
+ String nowEndTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN));
|
|
|
+ commonRequest.setStartTimeDateStr(yearStartTime);
|
|
|
+ commonRequest.setEndTimeDateStr(nowEndTime);
|
|
|
+ }
|
|
|
}
|