Commit dbb6000361d8715e8f8adb583a39dd8e5e6f747b

Authored by 胡翰林
1 parent 93fdda6f

可视化看板数据接口

  1 +package com.ash.base;
  2 +
  3 +import lombok.Data;
  4 +
  5 +@Data
  6 +public class BarChartVo {
  7 +
  8 + private String name;
  9 +
  10 + private String value;
  11 +
  12 + public BarChartVo(){
  13 +
  14 + }
  15 +
  16 + public BarChartVo(String name, String value) {
  17 + this.name = name;
  18 + this.value = value;
  19 + }
  20 +}
... ...
  1 +package com.ash.base;
  2 +
  3 +import lombok.Data;
  4 +
  5 +@Data
  6 +public class PieChartVo {
  7 + private String name;
  8 + private Object value;
  9 +
  10 + public PieChartVo(String name, Object value) {
  11 + this.name = name;
  12 + this.value = value;
  13 + }
  14 +}
... ...
  1 +package com.ash.base;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonFormat;
  4 +import lombok.Data;
  5 +
  6 +import java.util.Date;
  7 +
  8 +@Data
  9 +public class StatisticsParams {
  10 + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
  11 + private Date startTime;
  12 +
  13 + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
  14 + private Date endTime;
  15 +}
... ...
  1 +package com.ash.controller;
  2 +
  3 +import com.ash.base.*;
  4 +import com.ash.entity.Case;
  5 +import com.ash.entity.WarningInstance;
  6 +import com.ash.service.CaseService;
  7 +import com.ash.service.WarningInstanceAnalysisService;
  8 +import com.ash.service.WarningInstanceService;
  9 +import com.ash.util.DateUtils;
  10 +import lombok.extern.slf4j.Slf4j;
  11 +import org.apache.commons.collections.CollectionUtils;
  12 +import org.apache.commons.lang3.StringUtils;
  13 +import org.springframework.web.bind.annotation.RequestBody;
  14 +import org.springframework.web.bind.annotation.RequestMapping;
  15 +import org.springframework.web.bind.annotation.RequestMethod;
  16 +import org.springframework.web.bind.annotation.RestController;
  17 +
  18 +import javax.annotation.Resource;
  19 +import java.util.*;
  20 +import java.util.stream.Collectors;
  21 +import java.util.stream.Stream;
  22 +
  23 +@RestController
  24 +@RequestMapping("/statistics")
  25 +@Slf4j
  26 +public class StatisticsController extends BaseController {
  27 +
  28 + @Resource
  29 + private WarningInstanceService warningInstanceService;
  30 +
  31 + @Resource
  32 + private WarningInstanceAnalysisService warningInstanceAnalysisService;
  33 +
  34 + @Resource
  35 + private CaseService caseService;
  36 +
  37 + /**
  38 + * 各地市警情分布top7
  39 + *
  40 + * @param statisticsParams 参数
  41 + * @return 数据
  42 + */
  43 + @RequestMapping(value = "/wiStatisticsByArea", method = RequestMethod.POST)
  44 + public JsonResult wiStatisticsByArea(@RequestBody StatisticsParams statisticsParams) {
  45 + try {
  46 + List<BarChartVo> dataList = warningInstanceService.statisticsByArea(statisticsParams);
  47 + return JsonResult.ok(OptionStatus.OPT_SUCCESS.getName(), dataList);
  48 + } catch (Exception ex) {
  49 + ex.printStackTrace();
  50 + return JsonResult.error(OptionStatus.OPT_ERROR.getName());
  51 + }
  52 + }
  53 +
  54 +
  55 + /**
  56 + * 各地市案件分布top7
  57 + *
  58 + * @param statisticsParams 参数
  59 + * @return 数据
  60 + */
  61 + @RequestMapping(value = "/caseStatisticsByArea", method = RequestMethod.POST)
  62 + public JsonResult caseStatisticsByArea(@RequestBody StatisticsParams statisticsParams) {
  63 + try {
  64 + List<BarChartVo> dataList = caseService.statisticsByArea(statisticsParams);
  65 + return JsonResult.ok(OptionStatus.OPT_SUCCESS.getName(), dataList);
  66 + } catch (Exception ex) {
  67 + ex.printStackTrace();
  68 + return JsonResult.error(OptionStatus.OPT_ERROR.getName());
  69 + }
  70 + }
  71 +
  72 + /**
  73 + * 警情趋势
  74 + *
  75 + * @param statisticsParams 参数
  76 + * @return 数据
  77 + */
  78 + @RequestMapping(value = "/wiStatisticsByDate", method = RequestMethod.POST)
  79 + public JsonResult wiStatisticsByDate(@RequestBody StatisticsParams statisticsParams) {
  80 + try {
  81 + List<BarChartVo> dataList = warningInstanceService.statisticsByDate(statisticsParams);
  82 + return JsonResult.ok(OptionStatus.OPT_SUCCESS.getName(), dataList);
  83 + } catch (Exception ex) {
  84 + ex.printStackTrace();
  85 + return JsonResult.error(OptionStatus.OPT_ERROR.getName());
  86 + }
  87 + }
  88 +
  89 + /**
  90 + * 诈骗类型分布
  91 + *
  92 + * @param statisticsParams 参数
  93 + * @return 数据
  94 + */
  95 + @RequestMapping(value = "/caseStatisticsByFraudType", method = RequestMethod.POST)
  96 + public JsonResult caseStatisticsByFraudType(@RequestBody StatisticsParams statisticsParams) {
  97 + try {
  98 + List<PieChartVo> dataList = caseService.statisticsByFraudType(statisticsParams);
  99 + return JsonResult.ok(OptionStatus.OPT_SUCCESS.getName(), dataList);
  100 + } catch (Exception ex) {
  101 + ex.printStackTrace();
  102 + return JsonResult.error(OptionStatus.OPT_ERROR.getName());
  103 + }
  104 + }
  105 +
  106 + /**
  107 + * 各地市top高损案件数
  108 + *
  109 + * @param statisticsParams 参数
  110 + * @return 数据
  111 + */
  112 + @RequestMapping(value = "/caseStatisticsTotalAmountByArea", method = RequestMethod.POST)
  113 + public JsonResult caseStatisticsTotalAmountByArea(@RequestBody StatisticsParams statisticsParams) {
  114 + try {
  115 + List<BarChartVo> dataList = caseService.statisticsTotalAmountByArea(statisticsParams);
  116 + return JsonResult.ok(OptionStatus.OPT_SUCCESS.getName(), dataList);
  117 + } catch (Exception ex) {
  118 + ex.printStackTrace();
  119 + return JsonResult.error(OptionStatus.OPT_ERROR.getName());
  120 + }
  121 + }
  122 +
  123 + /**
  124 + * 各地市警情数量环比变化
  125 + *
  126 + * @param statisticsParams 参数
  127 + * @return 数据
  128 + */
  129 + @RequestMapping(value = "/wiStatisticsSequentialByArea", method = RequestMethod.POST)
  130 + public JsonResult wiStatisticsSequentialByArea(@RequestBody StatisticsParams statisticsParams) {
  131 + try {
  132 + statisticsParams.setStartTime(DateUtils.weeHours(statisticsParams.getStartTime(), 0));
  133 + statisticsParams.setEndTime(DateUtils.weeHours(statisticsParams.getEndTime(), 1));
  134 + List<BarChartVo> currentDataList = warningInstanceService.statisticsSequentialByArea(statisticsParams);
  135 + long daysBetween = DateUtils.getDaysBetween(statisticsParams.getEndTime(), statisticsParams.getStartTime());
  136 + StatisticsParams lp = new StatisticsParams();
  137 + lp.setStartTime(DateUtils.getFrontDay(statisticsParams.getStartTime(), (int) daysBetween));
  138 + lp.setEndTime(DateUtils.getFrontDay(statisticsParams.getEndTime(), (int) daysBetween));
  139 +
  140 + List<BarChartVo> lastDataList = warningInstanceService.statisticsSequentialByArea(lp);
  141 + List<String> currentAreaList = currentDataList.stream().map(BarChartVo::getName).collect(Collectors.toList());
  142 + List<String> lastAreaList = lastDataList.stream().map(BarChartVo::getName).collect(Collectors.toList());
  143 + List<String> areaList = Stream.concat(currentAreaList.stream(), lastAreaList.stream())
  144 + .distinct()
  145 + .collect(Collectors.toList());
  146 + Map<String, String> currentMap = currentDataList.stream()
  147 + .collect(Collectors.toMap(BarChartVo::getName, BarChartVo::getValue));
  148 + Map<String, String> lastMap = lastDataList.stream()
  149 + .collect(Collectors.toMap(BarChartVo::getName, BarChartVo::getValue));
  150 +
  151 + List<PieChartVo> dataList = new ArrayList<>();
  152 + for (String area : areaList) {
  153 + String currentValue = currentMap.get(area);
  154 + String lastValue = lastMap.get(area);
  155 + int cv = StringUtils.isNotBlank(currentValue) ? Integer.parseInt(currentValue) : 0;
  156 + int lv = StringUtils.isNotBlank(lastValue) ? Integer.parseInt(lastValue) : 0;
  157 +
  158 + String sequential = "--";
  159 + if (lv != 0) {
  160 + sequential = String.format("%.1f", (cv - lv) * 1.0 / lv * 100.0);
  161 + PieChartVo cd = new PieChartVo(area, Double.parseDouble(sequential));
  162 + dataList.add(cd);
  163 + } else {
  164 + //为了图表展示先用0
  165 + PieChartVo cd = new PieChartVo(area, 0);
  166 + dataList.add(cd);
  167 + }
  168 +
  169 + }
  170 +
  171 +
  172 + return JsonResult.ok(OptionStatus.OPT_SUCCESS.getName(), dataList);
  173 + } catch (Exception ex) {
  174 + ex.printStackTrace();
  175 + return JsonResult.error(OptionStatus.OPT_ERROR.getName());
  176 + }
  177 + }
  178 +
  179 + /**
  180 + * 各地市电诈案件环比变化
  181 + *
  182 + * @param statisticsParams 参数
  183 + * @return 数据
  184 + */
  185 + @RequestMapping(value = "/caseStatisticsSequentialByArea", method = RequestMethod.POST)
  186 + public JsonResult caseStatisticsSequentialByArea(@RequestBody StatisticsParams statisticsParams) {
  187 + try {
  188 + statisticsParams.setStartTime(DateUtils.weeHours(statisticsParams.getStartTime(), 0));
  189 + statisticsParams.setEndTime(DateUtils.weeHours(statisticsParams.getEndTime(), 1));
  190 + List<BarChartVo> currentDataList = caseService.statisticsSequentialByArea(statisticsParams);
  191 + long daysBetween = DateUtils.getDaysBetween(statisticsParams.getEndTime(), statisticsParams.getStartTime());
  192 + StatisticsParams lp = new StatisticsParams();
  193 + lp.setStartTime(DateUtils.getFrontDay(statisticsParams.getStartTime(), (int) daysBetween));
  194 + lp.setEndTime(DateUtils.getFrontDay(statisticsParams.getEndTime(), (int) daysBetween));
  195 +
  196 + List<BarChartVo> lastDataList = caseService.statisticsSequentialByArea(lp);
  197 + List<String> currentAreaList = currentDataList.stream().map(BarChartVo::getName).collect(Collectors.toList());
  198 + List<String> lastAreaList = lastDataList.stream().map(BarChartVo::getName).collect(Collectors.toList());
  199 + List<String> areaList = Stream.concat(currentAreaList.stream(), lastAreaList.stream())
  200 + .distinct()
  201 + .collect(Collectors.toList());
  202 + Map<String, String> currentMap = currentDataList.stream()
  203 + .collect(Collectors.toMap(BarChartVo::getName, BarChartVo::getValue));
  204 + Map<String, String> lastMap = lastDataList.stream()
  205 + .collect(Collectors.toMap(BarChartVo::getName, BarChartVo::getValue));
  206 +
  207 + List<PieChartVo> dataList = new ArrayList<>();
  208 + for (String area : areaList) {
  209 + String currentValue = currentMap.get(area);
  210 + String lastValue = lastMap.get(area);
  211 + int cv = StringUtils.isNotBlank(currentValue) ? Integer.parseInt(currentValue) : 0;
  212 + int lv = StringUtils.isNotBlank(lastValue) ? Integer.parseInt(lastValue) : 0;
  213 +
  214 + String sequential = "--";
  215 + if (lv != 0) {
  216 + sequential = String.format("%.1f", (cv - lv) * 1.0 / lv * 100.0);
  217 + PieChartVo cd = new PieChartVo(area, Double.parseDouble(sequential));
  218 + dataList.add(cd);
  219 + } else {
  220 + //为了图表展示先用0
  221 + PieChartVo cd = new PieChartVo(area, 0);
  222 + dataList.add(cd);
  223 + }
  224 +
  225 + }
  226 +
  227 +
  228 + return JsonResult.ok(OptionStatus.OPT_SUCCESS.getName(), dataList);
  229 + } catch (Exception ex) {
  230 + ex.printStackTrace();
  231 + return JsonResult.error(OptionStatus.OPT_ERROR.getName());
  232 + }
  233 + }
  234 +
  235 + /**
  236 + * 全省接电诈警情
  237 + *
  238 + * @param statisticsParams 参数
  239 + * @return 数据
  240 + */
  241 + @RequestMapping(value = "/totalWiInfo", method = RequestMethod.POST)
  242 + public JsonResult totalWiInfo(@RequestBody StatisticsParams statisticsParams) {
  243 + try {
  244 + statisticsParams.setStartTime(DateUtils.weeHours(statisticsParams.getStartTime(), 0));
  245 + statisticsParams.setEndTime(DateUtils.weeHours(statisticsParams.getEndTime(), 1));
  246 + int count = warningInstanceService.getCount(statisticsParams);
  247 + long daysBetween = DateUtils.getDaysBetween(statisticsParams.getEndTime(), statisticsParams.getStartTime());
  248 + StatisticsParams lp = new StatisticsParams();
  249 + lp.setStartTime(DateUtils.getFrontDay(statisticsParams.getStartTime(), (int) daysBetween));
  250 + lp.setEndTime(DateUtils.getFrontDay(statisticsParams.getEndTime(), (int) daysBetween));
  251 + int lastCount = warningInstanceService.getCount(lp);
  252 + String sequential = "--";
  253 + if (lastCount != 0) {
  254 + sequential = String.format("%.1f", (count - lastCount) * 1.0 / lastCount * 100.0) + "%";
  255 + }
  256 +
  257 + Map<String, Object> result = new HashMap<>();
  258 + result.put("value", count);
  259 + result.put("sequential", sequential);
  260 +
  261 + return JsonResult.ok(OptionStatus.OPT_SUCCESS.getName(), result);
  262 + } catch (Exception ex) {
  263 + ex.printStackTrace();
  264 + return JsonResult.error(OptionStatus.OPT_ERROR.getName());
  265 + }
  266 + }
  267 +
  268 + /**
  269 + * 全省立案电诈件
  270 + *
  271 + * @param statisticsParams 参数
  272 + * @return 数据
  273 + */
  274 + @RequestMapping(value = "/totalCaseInfo", method = RequestMethod.POST)
  275 + public JsonResult totalCaseInfo(@RequestBody StatisticsParams statisticsParams) {
  276 + try {
  277 + statisticsParams.setStartTime(DateUtils.weeHours(statisticsParams.getStartTime(), 0));
  278 + statisticsParams.setEndTime(DateUtils.weeHours(statisticsParams.getEndTime(), 1));
  279 + int count = caseService.getCount(statisticsParams);
  280 + long daysBetween = DateUtils.getDaysBetween(statisticsParams.getEndTime(), statisticsParams.getStartTime());
  281 + StatisticsParams lp = new StatisticsParams();
  282 + lp.setStartTime(DateUtils.getFrontDay(statisticsParams.getStartTime(), (int) daysBetween));
  283 + lp.setEndTime(DateUtils.getFrontDay(statisticsParams.getEndTime(), (int) daysBetween));
  284 + int lastCount = caseService.getCount(lp);
  285 + String sequential = "--";
  286 + if (lastCount != 0) {
  287 + sequential = String.format("%.1f", (count - lastCount) * 1.0 / lastCount * 100.0) + "%";
  288 + }
  289 +
  290 + Map<String, Object> result = new HashMap<>();
  291 + result.put("value", count);
  292 + result.put("sequential", sequential);
  293 +
  294 + return JsonResult.ok(OptionStatus.OPT_SUCCESS.getName(), result);
  295 + } catch (Exception ex) {
  296 + ex.printStackTrace();
  297 + return JsonResult.error(OptionStatus.OPT_ERROR.getName());
  298 + }
  299 + }
  300 +
  301 + /**
  302 + * 总损失
  303 + *
  304 + * @param statisticsParams 参数
  305 + * @return 数据
  306 + */
  307 + @RequestMapping(value = "/totalLoss", method = RequestMethod.POST)
  308 + public JsonResult totalLoss(@RequestBody StatisticsParams statisticsParams) {
  309 + try {
  310 + List<Case> dataList = caseService.getCaseLoss(statisticsParams);
  311 + int caseTopLoss = caseService.getCaseTopLoss(statisticsParams);
  312 + Double totalLoss = 0d;
  313 + Double avgLoss = 0d;
  314 + if (CollectionUtils.isNotEmpty(dataList)) {
  315 + for (Case caseInfo : dataList) {
  316 + if (caseInfo.getTotalAmount() == null) {
  317 + continue;
  318 + }
  319 + totalLoss += caseInfo.getTotalAmount();
  320 + }
  321 + avgLoss = totalLoss * 1.0 / dataList.size();
  322 + }
  323 +
  324 +
  325 + Map<String, Object> result = new HashMap<>();
  326 + result.put("totalLoss", String.format("%.1f", totalLoss));
  327 + result.put("avgLoss", String.format("%.1f", avgLoss));
  328 + result.put("caseValue", caseTopLoss);
  329 +
  330 + return JsonResult.ok(OptionStatus.OPT_SUCCESS.getName(), result);
  331 + } catch (Exception ex) {
  332 + ex.printStackTrace();
  333 + return JsonResult.error(OptionStatus.OPT_ERROR.getName());
  334 + }
  335 + }
  336 +
  337 +
  338 +}
... ...
... ... @@ -85,4 +85,7 @@ public class Case extends BaseModel {
85 85
86 86 @Transient
87 87 private transient CaseAnalysis analysis;
  88 +
  89 + @Transient
  90 + private transient Double totalAmount;
88 91 }
... ...
... ... @@ -3,20 +3,20 @@ package com.ash.service;
3 3 import com.alibaba.excel.EasyExcel;
4 4 import com.alibaba.excel.exception.ExcelAnalysisException;
5 5 import com.alibaba.excel.exception.ExcelDataConvertException;
6   -import com.ash.base.AshErrorCode;
7   -import com.ash.base.AshException;
8   -import com.ash.base.BaseModel;
  6 +import com.ash.base.*;
9 7 import com.ash.base.excelOpt.ExcelErrorMessage;
10 8 import com.ash.entity.Case;
11   -import com.ash.entity.CaseAnalysis;
12 9 import com.ash.entity.dao.CaseMapper;
13 10 import com.ash.excelData.CaseExcelData;
14 11 import com.ash.listener.CaseExcelListener;
  12 +import com.ash.util.DateUtils;
15 13 import com.ash.util.MultipartFileToFileUtils;
  14 +import com.ash.util.ObjectValueOption;
16 15 import com.ash.util.UUIDGenerator;
17 16 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
18 17 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
19 18 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  19 +import com.github.yulichang.query.MPJQueryWrapper;
20 20 import lombok.extern.slf4j.Slf4j;
21 21 import org.apache.commons.lang3.StringUtils;
22 22 import org.springframework.stereotype.Service;
... ... @@ -26,10 +26,12 @@ import org.springframework.web.multipart.MultipartFile;
26 26 import javax.annotation.Resource;
27 27 import java.text.ParseException;
28 28 import java.text.SimpleDateFormat;
  29 +import java.util.ArrayList;
29 30 import java.util.Date;
30   -import java.util.HashMap;
31 31 import java.util.List;
32 32 import java.util.Map;
  33 +import java.util.concurrent.atomic.AtomicReference;
  34 +import java.util.stream.Collectors;
33 35
34 36 @Slf4j
35 37 @Service
... ... @@ -50,7 +52,6 @@ public class CaseService {
50 52 }
51 53
52 54
53   -
54 55 public Boolean saveAll(List<Case> dataList) {
55 56 if (CollectionUtils.isEmpty(dataList)) {
56 57 throw new AshException(AshErrorCode.ILLEGAL_PARAM, "dataList is empty!");
... ... @@ -109,6 +110,204 @@ public class CaseService {
109 110 return caseMapper.selectPage(page, queryWrapper);
110 111 }
111 112
  113 + public int getCount(StatisticsParams params) {
  114 + QueryWrapper<Case> queryWrapper = new QueryWrapper<>();
  115 + LambdaQueryWrapper<Case> lambda = queryWrapper.lambda();
  116 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  117 + if (params.getStartTime() != null) {
  118 + Date start = DateUtils.weeHours(params.getStartTime(), 0);
  119 + lambda.ge(Case::getAlarmDate, sdf.format(start));
  120 + }
  121 +
  122 + if (params.getEndTime() != null) {
  123 + Date end = DateUtils.weeHours(params.getEndTime(), 1);
  124 + lambda.le(Case::getAlarmDate, sdf.format(end));
  125 +
  126 + }
  127 + return caseMapper.selectCount(queryWrapper);
  128 + }
  129 +
  130 + public List<Case> getCaseLoss(StatisticsParams params) {
  131 + MPJQueryWrapper<Case> mpjQueryWrapper = new MPJQueryWrapper<Case>();
  132 + mpjQueryWrapper.select("t.id,ca.total_amount as totalAmount")
  133 + .leftJoin("t_ash_case_analysis ca on t.id=ca.case_id");
  134 +
  135 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  136 + if (params.getStartTime() != null) {
  137 + mpjQueryWrapper.ge("t.alarm_date", sdf.format(DateUtils.weeHours(params.getStartTime(), 0)));
  138 +
  139 + }
  140 +
  141 + if (params.getEndTime() != null) {
  142 + mpjQueryWrapper.le("t.alarm_date", sdf.format(DateUtils.weeHours(params.getEndTime(), 1)));
  143 + }
  144 +
  145 + return caseMapper.selectJoinList(Case.class, mpjQueryWrapper);
  146 + }
  147 +
  148 + public int getCaseTopLoss(StatisticsParams params) {
  149 + MPJQueryWrapper<Case> mpjQueryWrapper = new MPJQueryWrapper<Case>();
  150 + mpjQueryWrapper.select("t.id,ca.total_amount as totalAmount")
  151 + .leftJoin("t_ash_case_analysis ca on t.id=ca.case_id");
  152 +
  153 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  154 + if (params.getStartTime() != null) {
  155 + mpjQueryWrapper.ge("t.alarm_date", sdf.format(DateUtils.weeHours(params.getStartTime(), 0)));
  156 +
  157 + }
  158 +
  159 + if (params.getEndTime() != null) {
  160 + mpjQueryWrapper.le("t.alarm_date", sdf.format(DateUtils.weeHours(params.getEndTime(), 1)));
  161 + }
  162 +
  163 + mpjQueryWrapper.ge("ca.total_amount", 500000);
  164 + List<Case> caseList = caseMapper.selectJoinList(Case.class, mpjQueryWrapper);
  165 + if (CollectionUtils.isEmpty(caseList)) {
  166 + return 0;
  167 + } else {
  168 + return caseList.size();
  169 + }
  170 + }
  171 +
  172 +
  173 + public List<BarChartVo> statisticsByArea(StatisticsParams params) {
  174 + MPJQueryWrapper<Case> mpjQueryWrapper = new MPJQueryWrapper<Case>();
  175 + mpjQueryWrapper.select("ca.area,count(t.id) as field_count")
  176 + .leftJoin("t_ash_case_analysis ca on t.id=ca.case_id");
  177 +
  178 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  179 + if (params.getStartTime() != null) {
  180 + mpjQueryWrapper.ge("t.alarm_date", sdf.format(DateUtils.weeHours(params.getStartTime(), 0)));
  181 +
  182 + }
  183 +
  184 + if (params.getEndTime() != null) {
  185 + mpjQueryWrapper.le("t.alarm_date", sdf.format(DateUtils.weeHours(params.getEndTime(), 1)));
  186 + }
  187 +
  188 + mpjQueryWrapper.groupBy("ca.area");
  189 + mpjQueryWrapper.orderByDesc("field_count");
  190 +
  191 + List<Map<String, Object>> dataList = caseMapper.selectJoinMaps(mpjQueryWrapper);
  192 + List<BarChartVo> resultList = new ArrayList<>();
  193 + if (!CollectionUtils.isEmpty(dataList)) {
  194 +
  195 + AtomicReference<Integer> total = new AtomicReference<>(0);
  196 + resultList = dataList.stream().map(e -> {
  197 + Integer fieldCount = ObjectValueOption.getObjInt(e.get("field_count"));
  198 + total.updateAndGet(v -> v + fieldCount);
  199 + return new BarChartVo(ObjectValueOption.getObjString(e.get("area")), fieldCount.toString());
  200 + }
  201 + ).collect(Collectors.toList());
  202 + resultList = resultList.stream().filter(e -> StringUtils.isNotBlank(e.getName())).collect(Collectors.toList());
  203 + if (resultList.size() > 7) {
  204 + resultList = resultList.subList(0, 7);
  205 + }
  206 +
  207 + resultList.forEach(e -> {
  208 + String value = e.getValue();
  209 + Integer iv = Integer.parseInt(value);
  210 + e.setValue(String.format("%.2f", iv * 1.0 / total.get() * 100.0));
  211 + });
  212 + }
  213 + return resultList;
  214 + }
  215 +
  216 + public List<PieChartVo> statisticsByFraudType(StatisticsParams params) {
  217 + MPJQueryWrapper<Case> mpjQueryWrapper = new MPJQueryWrapper<Case>();
  218 + mpjQueryWrapper.select("ca.fraud_type as fraudType,count(t.id) as field_count")
  219 + .leftJoin("t_ash_case_analysis ca on t.id=ca.case_id");
  220 +
  221 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  222 + if (params.getStartTime() != null) {
  223 + mpjQueryWrapper.ge("t.alarm_date", sdf.format(DateUtils.weeHours(params.getStartTime(), 0)));
  224 +
  225 + }
  226 +
  227 + if (params.getEndTime() != null) {
  228 + mpjQueryWrapper.le("t.alarm_date", sdf.format(DateUtils.weeHours(params.getEndTime(), 1)));
  229 + }
  230 +
  231 + mpjQueryWrapper.groupBy("ca.fraud_type");
  232 + mpjQueryWrapper.orderByDesc("field_count");
  233 +
  234 + List<Map<String, Object>> dataList = caseMapper.selectJoinMaps(mpjQueryWrapper);
  235 + List<PieChartVo> resultList = new ArrayList<>();
  236 + if (!CollectionUtils.isEmpty(dataList)) {
  237 + resultList = dataList.stream().map(e ->
  238 + new PieChartVo(ObjectValueOption.getObjString(e.get("fraudType"))
  239 + , ObjectValueOption.getObjInt(e.get("field_count"))))
  240 + .filter(e -> StringUtils.isNotBlank(e.getName())).collect(Collectors.toList());
  241 + }
  242 + return resultList;
  243 + }
  244 +
  245 + public List<BarChartVo> statisticsTotalAmountByArea(StatisticsParams params) {
  246 + MPJQueryWrapper<Case> mpjQueryWrapper = new MPJQueryWrapper<Case>();
  247 + mpjQueryWrapper.select("ca.area,count(t.id) as field_count")
  248 + .leftJoin("t_ash_case_analysis ca on t.id=ca.case_id");
  249 +
  250 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  251 + if (params.getStartTime() != null) {
  252 + mpjQueryWrapper.ge("t.alarm_date", sdf.format(DateUtils.weeHours(params.getStartTime(), 0)));
  253 +
  254 + }
  255 +
  256 + if (params.getEndTime() != null) {
  257 + mpjQueryWrapper.le("t.alarm_date", sdf.format(DateUtils.weeHours(params.getEndTime(), 1)));
  258 + }
  259 +
  260 + mpjQueryWrapper.ge("ca.total_amount", 500000);
  261 +
  262 + mpjQueryWrapper.groupBy("ca.area");
  263 + mpjQueryWrapper.orderByDesc("field_count");
  264 +
  265 + List<Map<String, Object>> dataList = caseMapper.selectJoinMaps(mpjQueryWrapper);
  266 + List<BarChartVo> resultList = new ArrayList<>();
  267 + if (!CollectionUtils.isEmpty(dataList)) {
  268 + resultList = dataList.stream().map(e -> {
  269 + return new BarChartVo(ObjectValueOption.getObjString(e.get("area"))
  270 + , ObjectValueOption.getObjString(e.get("field_count")));
  271 + }
  272 + ).filter(e -> StringUtils.isNotBlank(e.getName())).collect(Collectors.toList());
  273 + if (resultList.size() > 7) {
  274 + resultList = resultList.subList(0, 7);
  275 + }
  276 + }
  277 + return resultList;
  278 + }
  279 +
  280 + public List<BarChartVo> statisticsSequentialByArea(StatisticsParams params) {
  281 + MPJQueryWrapper<Case> mpjQueryWrapper = new MPJQueryWrapper<Case>();
  282 + mpjQueryWrapper.select("ca.area,count(t.id) as field_count")
  283 + .leftJoin("t_ash_case_analysis ca on t.id=ca.case_id");
  284 +
  285 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  286 + if (params.getStartTime() != null) {
  287 + mpjQueryWrapper.ge("t.alarm_date", sdf.format(DateUtils.weeHours(params.getStartTime(), 0)));
  288 +
  289 + }
  290 +
  291 + if (params.getEndTime() != null) {
  292 + mpjQueryWrapper.le("t.alarm_date", sdf.format(DateUtils.weeHours(params.getEndTime(), 1)));
  293 + }
  294 +
  295 + mpjQueryWrapper.groupBy("ca.area");
  296 + mpjQueryWrapper.orderByDesc("field_count");
  297 +
  298 + List<Map<String, Object>> dataList = caseMapper.selectJoinMaps(mpjQueryWrapper);
  299 + List<BarChartVo> resultList = new ArrayList<>();
  300 + if (!CollectionUtils.isEmpty(dataList)) {
  301 + resultList = dataList.stream().map(e -> {
  302 + Integer fieldCount = ObjectValueOption.getObjInt(e.get("field_count"));
  303 + return new BarChartVo(ObjectValueOption.getObjString(e.get("area")), fieldCount.toString());
  304 + }
  305 + ).filter(e -> StringUtils.isNotBlank(e.getName())).collect(Collectors.toList());
  306 +
  307 + }
  308 + return resultList;
  309 + }
  310 +
112 311 private QueryWrapper<Case> getCondition(Case params) {
113 312 QueryWrapper<Case> queryWrapper = new QueryWrapper<>();
114 313 LambdaQueryWrapper<Case> lambda = queryWrapper.lambda();
... ...
... ... @@ -3,19 +3,20 @@ package com.ash.service;
3 3 import com.alibaba.excel.EasyExcel;
4 4 import com.alibaba.excel.exception.ExcelAnalysisException;
5 5 import com.alibaba.excel.exception.ExcelDataConvertException;
6   -import com.ash.base.AshErrorCode;
7   -import com.ash.base.AshException;
8   -import com.ash.base.BaseModel;
  6 +import com.ash.base.*;
9 7 import com.ash.base.excelOpt.ExcelErrorMessage;
10 8 import com.ash.entity.WarningInstance;
11 9 import com.ash.entity.dao.WarningInstanceMapper;
12 10 import com.ash.excelData.WarningInstanceExcelData;
13 11 import com.ash.listener.WarningInstanceExcelListener;
  12 +import com.ash.util.DateUtils;
14 13 import com.ash.util.MultipartFileToFileUtils;
  14 +import com.ash.util.ObjectValueOption;
15 15 import com.ash.util.UUIDGenerator;
16 16 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
17 17 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
18 18 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  19 +import com.github.yulichang.query.MPJQueryWrapper;
19 20 import lombok.extern.slf4j.Slf4j;
20 21 import org.apache.commons.lang3.StringUtils;
21 22 import org.springframework.stereotype.Service;
... ... @@ -25,8 +26,12 @@ import org.springframework.web.multipart.MultipartFile;
25 26 import javax.annotation.Resource;
26 27 import java.text.ParseException;
27 28 import java.text.SimpleDateFormat;
  29 +import java.util.ArrayList;
28 30 import java.util.Date;
29 31 import java.util.List;
  32 +import java.util.Map;
  33 +import java.util.concurrent.atomic.AtomicReference;
  34 +import java.util.stream.Collectors;
30 35
31 36 @Slf4j
32 37 @Service
... ... @@ -103,6 +108,123 @@ public class WarningInstanceService {
103 108 return warningInstanceMapper.selectPage(page, queryWrapper);
104 109 }
105 110
  111 + public int getCount(StatisticsParams params) {
  112 + QueryWrapper<WarningInstance> queryWrapper = new QueryWrapper<>();
  113 + LambdaQueryWrapper<WarningInstance> lambda = queryWrapper.lambda();
  114 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  115 + if (params.getStartTime() != null) {
  116 + Date start = DateUtils.weeHours(params.getStartTime(), 0);
  117 + lambda.ge(WarningInstance::getAlarmDate, sdf.format(start));
  118 + }
  119 +
  120 + if (params.getEndTime() != null) {
  121 + Date end = DateUtils.weeHours(params.getEndTime(), 1);
  122 + lambda.le(WarningInstance::getAlarmDate, sdf.format(end));
  123 +
  124 + }
  125 + return warningInstanceMapper.selectCount(queryWrapper);
  126 + }
  127 +
  128 + public List<BarChartVo> statisticsByArea(StatisticsParams params) {
  129 + MPJQueryWrapper<WarningInstance> mpjQueryWrapper = new MPJQueryWrapper<WarningInstance>();
  130 + mpjQueryWrapper.select("wia.area,count(t.id) as field_count")
  131 + .leftJoin("t_ash_warning_instance_analysis wia on t.id=wia.wi_id");
  132 +
  133 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  134 + if (params.getStartTime() != null) {
  135 + mpjQueryWrapper.ge("t.alarm_date", sdf.format(DateUtils.weeHours(params.getStartTime(), 0)));
  136 +
  137 + }
  138 +
  139 + if (params.getEndTime() != null) {
  140 + mpjQueryWrapper.le("t.alarm_date", sdf.format(DateUtils.weeHours(params.getEndTime(), 1)));
  141 + }
  142 +
  143 + mpjQueryWrapper.groupBy("wia.area");
  144 + mpjQueryWrapper.orderByDesc("field_count");
  145 +
  146 + List<Map<String, Object>> dataList = warningInstanceMapper.selectJoinMaps(mpjQueryWrapper);
  147 + List<BarChartVo> resultList = new ArrayList<>();
  148 + if (!CollectionUtils.isEmpty(dataList)) {
  149 + AtomicReference<Integer> total = new AtomicReference<>(0);
  150 + resultList = dataList.stream().map(e -> {
  151 + Integer fieldCount = ObjectValueOption.getObjInt(e.get("field_count"));
  152 + total.updateAndGet(v -> v + fieldCount);
  153 + return new BarChartVo(ObjectValueOption.getObjString(e.get("area")), fieldCount.toString());
  154 + }
  155 + ).collect(Collectors.toList());
  156 + resultList = resultList.stream().filter(e -> StringUtils.isNotBlank(e.getName())).collect(Collectors.toList());
  157 + if (resultList.size() > 7) {
  158 + resultList = resultList.subList(0, 7);
  159 + }
  160 +
  161 + resultList.forEach(e -> {
  162 + String value = e.getValue();
  163 + Integer iv = Integer.parseInt(value);
  164 + e.setValue(String.format("%.2f", iv * 1.0 / total.get() * 100.0));
  165 + });
  166 + }
  167 + return resultList;
  168 + }
  169 +
  170 + public List<BarChartVo> statisticsByDate(StatisticsParams params) {
  171 + MPJQueryWrapper<WarningInstance> mpjQueryWrapper = new MPJQueryWrapper<WarningInstance>();
  172 + mpjQueryWrapper.select("DATE_FORMAT(t.alarm_date, '%Y-%m-%d') as alarmDate,count(0) as field_count");
  173 +
  174 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  175 + if (params.getStartTime() != null) {
  176 + mpjQueryWrapper.ge("t.alarm_date", sdf.format(DateUtils.weeHours(params.getStartTime(), 0)));
  177 +
  178 + }
  179 +
  180 + if (params.getEndTime() != null) {
  181 + mpjQueryWrapper.le("t.alarm_date", sdf.format(DateUtils.weeHours(params.getEndTime(), 1)));
  182 + }
  183 +
  184 + mpjQueryWrapper.groupBy("DATE_FORMAT(t.alarm_date, '%Y-%m-%d')");
  185 + mpjQueryWrapper.orderByAsc("DATE_FORMAT(t.alarm_date, '%Y-%m-%d')");
  186 + List<Map<String, Object>> dataList = warningInstanceMapper.selectJoinMaps(mpjQueryWrapper);
  187 + List<BarChartVo> resultList = new ArrayList<>();
  188 + resultList = dataList.stream().map(e -> {
  189 + Integer fieldCount = ObjectValueOption.getObjInt(e.get("field_count"));
  190 + return new BarChartVo(ObjectValueOption.getObjString(e.get("alarmDate")), fieldCount.toString());
  191 + }
  192 + ).filter(e -> StringUtils.isNotBlank(e.getName())).collect(Collectors.toList());
  193 + return resultList;
  194 + }
  195 +
  196 +
  197 + public List<BarChartVo> statisticsSequentialByArea(StatisticsParams params) {
  198 + MPJQueryWrapper<WarningInstance> mpjQueryWrapper = new MPJQueryWrapper<WarningInstance>();
  199 + mpjQueryWrapper.select("wia.area,count(t.id) as field_count")
  200 + .leftJoin("t_ash_warning_instance_analysis wia on t.id=wia.wi_id");
  201 +
  202 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  203 + if (params.getStartTime() != null) {
  204 + mpjQueryWrapper.ge("t.alarm_date", sdf.format(DateUtils.weeHours(params.getStartTime(), 0)));
  205 +
  206 + }
  207 +
  208 + if (params.getEndTime() != null) {
  209 + mpjQueryWrapper.le("t.alarm_date", sdf.format(DateUtils.weeHours(params.getEndTime(), 1)));
  210 + }
  211 +
  212 + mpjQueryWrapper.groupBy("wia.area");
  213 + mpjQueryWrapper.orderByDesc("field_count");
  214 +
  215 + List<Map<String, Object>> dataList = warningInstanceMapper.selectJoinMaps(mpjQueryWrapper);
  216 + List<BarChartVo> resultList = new ArrayList<>();
  217 + if (!CollectionUtils.isEmpty(dataList)) {
  218 + resultList = dataList.stream().map(e -> {
  219 + Integer fieldCount = ObjectValueOption.getObjInt(e.get("field_count"));
  220 + return new BarChartVo(ObjectValueOption.getObjString(e.get("area")), fieldCount.toString());
  221 + }
  222 + ).filter(e -> StringUtils.isNotBlank(e.getName())).collect(Collectors.toList());
  223 +
  224 + }
  225 + return resultList;
  226 + }
  227 +
106 228 private QueryWrapper<WarningInstance> getCondition(WarningInstance params) {
107 229 QueryWrapper<WarningInstance> queryWrapper = new QueryWrapper<>();
108 230 LambdaQueryWrapper<WarningInstance> lambda = queryWrapper.lambda();
... ... @@ -138,7 +260,7 @@ public class WarningInstanceService {
138 260 }
139 261 }
140 262
141   - lambda.orderByDesc(BaseModel::getCreateTime);
  263 + lambda.orderByDesc(BaseModel::getCreateTime, WarningInstance::getCode);
142 264 return queryWrapper;
143 265 }
144 266
... ...
  1 +package com.ash.util;
  2 +
  3 +
  4 +import org.apache.commons.lang3.math.NumberUtils;
  5 +
  6 +import java.sql.Timestamp;
  7 +import java.text.ParseException;
  8 +import java.text.SimpleDateFormat;
  9 +import java.time.*;
  10 +import java.util.*;
  11 +import java.util.concurrent.TimeUnit;
  12 +
  13 +public class DateUtils {
  14 + public static final String FORMAT_YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
  15 + public static final String FORMAT_YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm";
  16 + public static final String FORMAT_YYYY_MM_DD = "yyyy-MM-dd";
  17 + public static final String FORMAT_YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
  18 + public static final String FORMAT_YYYYMMDD = "yyyy/MM/dd";
  19 +
  20 + public static String format(Date date, String formatStr) {
  21 + SimpleDateFormat dateFormat = new SimpleDateFormat(formatStr);
  22 + return dateFormat.format(date);
  23 + }
  24 +
  25 + public static Date parse(long timescap) {
  26 + SimpleDateFormat format = new SimpleDateFormat(FORMAT_YYYY_MM_DD_HH_MM_SS);
  27 + Long time = timescap;
  28 + String dateString = format.format(time);
  29 + return parse(dateString, FORMAT_YYYY_MM_DD_HH_MM_SS);
  30 + }
  31 +
  32 + public static Date parse(String dateString, String formatStr) {
  33 + SimpleDateFormat dateFormat = new SimpleDateFormat(formatStr);
  34 + try {
  35 + return dateFormat.parse(dateString);
  36 + } catch (ParseException e) {
  37 + return null;
  38 + }
  39 + }
  40 +
  41 +
  42 + public static Date parse(Date date, String formatStr) {
  43 + String dateString = format(date, formatStr);
  44 + return parse(dateString, formatStr);
  45 + }
  46 +
  47 +
  48 + public static long reduceDate(Date date, Date reduceDate) {
  49 + if (date == null || reduceDate == null) {
  50 + return NumberUtils.INTEGER_ZERO;
  51 + }
  52 +
  53 + return (date.getTime() - reduceDate.getTime()) / 1000;
  54 + }
  55 +
  56 + public static String secToTime(int time) {
  57 + String timeStr = "00:00";
  58 + if (time <= 0) {
  59 + return timeStr;
  60 + }
  61 +
  62 + int minute = time / 60;
  63 + if (minute < 60) {
  64 + int second = time % 60;
  65 + timeStr = unitFormat(minute) + ":" + unitFormat(second);
  66 + } else {
  67 + int hour = minute / 60;
  68 + if (hour > 99) {
  69 + return "99:59:59";
  70 + }
  71 +
  72 + minute = minute % 60;
  73 + int second = time - hour * 3600 - minute * 60;
  74 + timeStr = unitFormat(hour) + ":" + unitFormat(minute) + ":" + unitFormat(second);
  75 + }
  76 +
  77 + return timeStr;
  78 + }
  79 +
  80 + private static String unitFormat(int i) {
  81 + if (i >= 0 && i < 10) {
  82 + return "0" + i;
  83 + }
  84 +
  85 + return "" + i;
  86 + }
  87 +
  88 + /**
  89 + * 凌晨
  90 + *
  91 + * @param date
  92 + * @return
  93 + * @flag 0 返回yyyy-MM-dd 00:00:00日期<br>
  94 + * 1 返回yyyy-MM-dd 23:59:59日期
  95 + */
  96 + public static Date weeHours(Date date, int flag) {
  97 + Calendar cal = Calendar.getInstance();
  98 + cal.setTime(date);
  99 + int hour = cal.get(Calendar.HOUR_OF_DAY);
  100 + int minute = cal.get(Calendar.MINUTE);
  101 + int second = cal.get(Calendar.SECOND);
  102 + //时分秒(毫秒数)
  103 + long millisecond = hour * 60 * 60 * 1000 + minute * 60 * 1000 + second * 1000;
  104 + //凌晨00:00:00
  105 + cal.setTimeInMillis(cal.getTimeInMillis() - millisecond);
  106 +
  107 + if (flag == 0) {
  108 + cal.set(Calendar.HOUR_OF_DAY, 0);
  109 + cal.set(Calendar.MINUTE, 0);
  110 + cal.set(Calendar.SECOND, 0);
  111 + cal.set(Calendar.MILLISECOND, 0);
  112 + return cal.getTime();
  113 + } else if (flag == 1) {
  114 + //凌晨23:59:59
  115 + cal.setTimeInMillis(cal.getTimeInMillis() + 23 * 60 * 60 * 1000 + 59 * 60 * 1000 + 59 * 1000);
  116 + }
  117 + return cal.getTime();
  118 + }
  119 +
  120 + public static void main(String[] args) {
  121 +
  122 + System.out.println(weeHours(new Date(),0));
  123 + System.out.println(weeHours(new Date(),1));
  124 +
  125 +
  126 + }
  127 +
  128 + public static long getDiffTime(Date date) {
  129 + long nowTime = System.currentTimeMillis();
  130 + long endTime = date.getTime();
  131 + long time = endTime - nowTime;
  132 + long dateTemp1 = time / 1000; //秒
  133 + long dateTemp2 = dateTemp1 / 60; //分钟
  134 + long dateTemp3 = dateTemp2 / 60; //小时
  135 + long dateTemp4 = dateTemp3 / 24; //天数
  136 + long dateTemp5 = dateTemp4 / 30; //月数
  137 + return dateTemp5;
  138 + }
  139 +
  140 + /**
  141 + * 获取指定时间的前一天
  142 + *
  143 + * @param date
  144 + * @return
  145 + */
  146 + public static Date getSpecifiedDayBefore(Date date, int index) {
  147 + Calendar calendar = Calendar.getInstance();
  148 + calendar.setTime(date);
  149 + int day = calendar.get(Calendar.DATE);
  150 + calendar.set(Calendar.DATE, day + index);
  151 + calendar.set(Calendar.HOUR_OF_DAY, 0);
  152 + calendar.set(Calendar.MINUTE, 0);
  153 + calendar.set(Calendar.SECOND, 0);
  154 + calendar.set(Calendar.MILLISECOND, 0);
  155 + return calendar.getTime();
  156 + }
  157 +
  158 + /**
  159 + * 获取每天的开始时间
  160 + *
  161 + * @param date date
  162 + * @return 当天的开始时间
  163 + */
  164 + public static Date getStartOfDate(Date date) {
  165 + Calendar calendar = Calendar.getInstance();
  166 + calendar.setTime(date);
  167 + calendar.set(Calendar.HOUR_OF_DAY, 0);
  168 + calendar.set(Calendar.MINUTE, 0);
  169 + calendar.set(Calendar.SECOND, 0);
  170 + calendar.set(Calendar.MILLISECOND, 0);
  171 +
  172 + return calendar.getTime();
  173 + }
  174 +
  175 + /**
  176 + * 获取每天的开始时间
  177 + *
  178 + * @param date date
  179 + * @return 当天的结束时间
  180 + */
  181 + public static Date getEndOfDate(Date date) {
  182 + Calendar calendar = Calendar.getInstance();
  183 + calendar.setTime(date);
  184 + calendar.set(Calendar.HOUR_OF_DAY, 23);
  185 + calendar.set(Calendar.MINUTE, 59);
  186 + calendar.set(Calendar.SECOND, 59);
  187 + calendar.set(Calendar.MILLISECOND, 59);
  188 +
  189 + return calendar.getTime();
  190 + }
  191 +
  192 +
  193 + /**
  194 + * 获取当天的过去一周的时间
  195 + *
  196 + * @param toDay
  197 + * @return
  198 + */
  199 + public static List<Date> getLastWeek(Date toDay) {
  200 + List<Date> weeks = new LinkedList<Date>();
  201 + Calendar calendar = Calendar.getInstance();
  202 + for (int i = 1; i <= 7; i++) {
  203 + calendar.setTime(toDay);
  204 + int day = calendar.get(Calendar.DATE);
  205 + calendar.set(Calendar.DATE, day - i);
  206 + calendar.set(Calendar.HOUR_OF_DAY, 0);
  207 + calendar.set(Calendar.MINUTE, 0);
  208 + calendar.set(Calendar.SECOND, 0);
  209 + calendar.set(Calendar.MILLISECOND, 0);
  210 + weeks.add(calendar.getTime());
  211 + }
  212 +
  213 + return weeks;
  214 + }
  215 +
  216 + /**
  217 + * 获取某一天的前一周时间
  218 + *
  219 + * @param toDay
  220 + * @return 返回封装好的时间集合
  221 + */
  222 + public static List<String> getLastWeekTime(Date toDay) {
  223 + List<String> weeks = new LinkedList<String>();
  224 + SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_YYYY_MM_DD);
  225 + Calendar calendar = Calendar.getInstance();
  226 + for (int i = 1; i <= 7; i++) {
  227 + calendar.setTime(toDay);
  228 + int day = calendar.get(Calendar.DATE);
  229 + calendar.set(Calendar.DATE, day - i);
  230 + calendar.set(Calendar.HOUR_OF_DAY, 0);
  231 + calendar.set(Calendar.MINUTE, 0);
  232 + calendar.set(Calendar.SECOND, 0);
  233 + calendar.set(Calendar.MILLISECOND, 0);
  234 + Date time = calendar.getTime();
  235 + String format = sdf.format(time);
  236 + weeks.add(format);
  237 + }
  238 +
  239 + return weeks;
  240 + }
  241 +
  242 +
  243 + //获取当天的开始时间
  244 + public static Date getDayBegin() {
  245 + Calendar cal = new GregorianCalendar();
  246 + cal.set(Calendar.HOUR_OF_DAY, 0);
  247 + cal.set(Calendar.MINUTE, 0);
  248 + cal.set(Calendar.SECOND, 0);
  249 + cal.set(Calendar.MILLISECOND, 0);
  250 + return cal.getTime();
  251 + }
  252 +
  253 + //获取当天的结束时间
  254 + public static Date getDayEnd() {
  255 + Calendar cal = new GregorianCalendar();
  256 + cal.set(Calendar.HOUR_OF_DAY, 23);
  257 + cal.set(Calendar.MINUTE, 59);
  258 + cal.set(Calendar.SECOND, 59);
  259 + return cal.getTime();
  260 + }
  261 +
  262 + //获取昨天的开始时间
  263 + public static Date getBeginDayOfYesterday() {
  264 + Calendar cal = new GregorianCalendar();
  265 + cal.setTime(getDayBegin());
  266 + cal.add(Calendar.DAY_OF_MONTH, -1);
  267 + return cal.getTime();
  268 + }
  269 +
  270 + //获取昨天的结束时间
  271 + public static Date getEndDayOfYesterDay() {
  272 + Calendar cal = new GregorianCalendar();
  273 + cal.setTime(getDayEnd());
  274 + cal.add(Calendar.DAY_OF_MONTH, -1);
  275 + return cal.getTime();
  276 + }
  277 +
  278 + //获取明天的开始时间
  279 + public static Date getBeginDayOfTomorrow() {
  280 + Calendar cal = new GregorianCalendar();
  281 + cal.setTime(getDayBegin());
  282 + cal.add(Calendar.DAY_OF_MONTH, 1);
  283 +
  284 + return cal.getTime();
  285 + }
  286 +
  287 + //获取明天的结束时间
  288 + public static Date getEndDayOfTomorrow() {
  289 + Calendar cal = new GregorianCalendar();
  290 + cal.setTime(getDayEnd());
  291 + cal.add(Calendar.DAY_OF_MONTH, 1);
  292 + return cal.getTime();
  293 + }
  294 +
  295 + //获取本周的开始时间
  296 + @SuppressWarnings("unused")
  297 + public static Date getBeginDayOfWeek() {
  298 + Date date = new Date();
  299 + if (date == null) {
  300 + return null;
  301 + }
  302 + Calendar cal = Calendar.getInstance();
  303 + cal.setTime(date);
  304 + int dayofweek = cal.get(Calendar.DAY_OF_WEEK);
  305 + if (dayofweek == 1) {
  306 + dayofweek += 7;
  307 + }
  308 + cal.add(Calendar.DATE, 2 - dayofweek);
  309 + return getDayStartTime(cal.getTime());
  310 + }
  311 +
  312 + //获取本周的结束时间
  313 + public static Date getEndDayOfWeek() {
  314 + Calendar cal = Calendar.getInstance();
  315 + cal.setTime(getBeginDayOfWeek());
  316 + cal.add(Calendar.DAY_OF_WEEK, 6);
  317 + Date weekEndSta = cal.getTime();
  318 + return getDayEndTime(weekEndSta);
  319 + }
  320 +
  321 + //获取上周的开始时间
  322 + @SuppressWarnings("unused")
  323 + public static Date getBeginDayOfLastWeek(int n) {
  324 + Date date = new Date();
  325 + if (date == null) {
  326 + return null;
  327 + }
  328 + Calendar cal = Calendar.getInstance();
  329 + cal.setTime(date);
  330 + int dayofweek = cal.get(Calendar.DAY_OF_WEEK);
  331 + if (dayofweek == 1) {
  332 + dayofweek += 7;
  333 + }
  334 + cal.add(Calendar.DATE, 2 - dayofweek - 7 * n);
  335 + return getDayStartTime(cal.getTime());
  336 + }
  337 +
  338 + /**
  339 + * @return
  340 + */
  341 + public static String[] getLast12Months() {
  342 + Date date = new Date();
  343 +
  344 + String[] last12Months = new String[13];
  345 + Calendar cal = Calendar.getInstance();
  346 + //设置输入条件时间
  347 + cal.setTime(date);
  348 +
  349 + cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + 1); //要先+1,才能把本月的算进去
  350 + for (int i = 0; i < 13; i++) {
  351 + cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) - 1); //逐次往前推1个月
  352 + last12Months[12 - i] = cal.get(Calendar.YEAR) + "-" + addZeroForNum(String.valueOf(cal.get(Calendar.MONTH) + 1), 2);
  353 + }
  354 +
  355 + return last12Months;
  356 + }
  357 +
  358 + public static String addZeroForNum(String str, int strLength) {
  359 + int strLen = str.length();
  360 + if (strLen < strLength) {
  361 + while (strLen < strLength) {
  362 + StringBuffer sb = new StringBuffer();
  363 + sb.append("0").append(str);// 左补0
  364 + // sb.append(str).append("0");//右补0
  365 + str = sb.toString();
  366 + strLen = str.length();
  367 + }
  368 + }
  369 + return str;
  370 + }
  371 +
  372 + //获取上周的结束时间
  373 + public static Date getEndDayOfLastWeek(int n) {
  374 + Calendar cal = Calendar.getInstance();
  375 + cal.setTime(getBeginDayOfLastWeek(n));
  376 + cal.add(Calendar.DAY_OF_WEEK, 6);
  377 + Date weekEndSta = cal.getTime();
  378 + return getDayEndTime(weekEndSta);
  379 + }
  380 +
  381 + //获取本月的开始时间
  382 + public static Date getBeginDayOfMonth() {
  383 + Calendar calendar = Calendar.getInstance();
  384 + calendar.set(getNowYear(), getNowMonth() - 1, 1);
  385 + return getDayStartTime(calendar.getTime());
  386 + }
  387 +
  388 + //获取本月的结束时间
  389 + public static Date getEndDayOfMonth() {
  390 + Calendar calendar = Calendar.getInstance();
  391 + calendar.set(getNowYear(), getNowMonth() - 1, 1);
  392 + int day = calendar.getActualMaximum(5);
  393 + calendar.set(getNowYear(), getNowMonth() - 1, day);
  394 + return getDayEndTime(calendar.getTime());
  395 + }
  396 +
  397 + //获取上月的开始时间
  398 + public static Date getBeginDayOfLastMonth() {
  399 + Calendar calendar = Calendar.getInstance();
  400 + calendar.set(getNowYear(), getNowMonth() - 2, 1);
  401 + return getDayStartTime(calendar.getTime());
  402 + }
  403 +
  404 + //获取上月的结束时间
  405 + public static Date getEndDayOfLastMonth() {
  406 + Calendar calendar = Calendar.getInstance();
  407 + calendar.set(getNowYear(), getNowMonth() - 2, 1);
  408 + int day = calendar.getActualMaximum(5);
  409 + calendar.set(getNowYear(), getNowMonth() - 2, day);
  410 + return getDayEndTime(calendar.getTime());
  411 + }
  412 +
  413 + //获取本年的开始时间
  414 + public static Date getBeginDayOfYear() {
  415 + Calendar cal = Calendar.getInstance();
  416 + cal.set(Calendar.YEAR, getNowYear());
  417 + // cal.set
  418 + cal.set(Calendar.MONTH, Calendar.JANUARY);
  419 + cal.set(Calendar.DATE, 1);
  420 +
  421 + return getDayStartTime(cal.getTime());
  422 + }
  423 +
  424 +
  425 + public static Date getBeginDayOfYear(Integer year) {
  426 + Calendar cal = Calendar.getInstance();
  427 + cal.set(Calendar.YEAR, year);
  428 + // cal.set
  429 + cal.set(Calendar.MONTH, Calendar.JANUARY);
  430 + cal.set(Calendar.DATE, 1);
  431 +
  432 + return getDayStartTime(cal.getTime());
  433 + }
  434 +
  435 + //获取本年的结束时间
  436 + public static Date getEndDayOfYear() {
  437 + Calendar cal = Calendar.getInstance();
  438 + cal.set(Calendar.YEAR, getNowYear());
  439 + cal.set(Calendar.MONTH, Calendar.DECEMBER);
  440 + cal.set(Calendar.DATE, 31);
  441 + return getDayEndTime(cal.getTime());
  442 + }
  443 +
  444 + public static Date getEndDayOfYear(Integer year) {
  445 + Calendar cal = Calendar.getInstance();
  446 + cal.set(Calendar.YEAR, year);
  447 + cal.set(Calendar.MONTH, Calendar.DECEMBER);
  448 + cal.set(Calendar.DATE, 31);
  449 + return getDayEndTime(cal.getTime());
  450 + }
  451 +
  452 +
  453 +
  454 + //获取某个日期的开始时间
  455 + public static Timestamp getDayStartTime(Date d) {
  456 + Calendar calendar = Calendar.getInstance();
  457 + if (null != d) calendar.setTime(d);
  458 + calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
  459 + calendar.set(Calendar.MILLISECOND, 0);
  460 + return new Timestamp(calendar.getTimeInMillis());
  461 + }
  462 +
  463 + //获取某个日期的结束时间
  464 + public static Timestamp getDayEndTime(Date d) {
  465 + Calendar calendar = Calendar.getInstance();
  466 + if (null != d) calendar.setTime(d);
  467 + calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), 23, 59, 59);
  468 + calendar.set(Calendar.MILLISECOND, 999);
  469 + return new Timestamp(calendar.getTimeInMillis());
  470 + }
  471 +
  472 + //获取今年是哪一年
  473 + public static Integer getNowYear() {
  474 + Date date = new Date();
  475 + GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
  476 + gc.setTime(date);
  477 + return Integer.valueOf(gc.get(1));
  478 + }
  479 +
  480 + //获取本月是哪一月
  481 + public static int getNowMonth() {
  482 + Date date = new Date();
  483 + GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
  484 + gc.setTime(date);
  485 + return gc.get(2) + 1;
  486 + }
  487 +
  488 + //两个日期相减得到的天数
  489 + public static int getDiffDays(Date beginDate, Date endDate) {
  490 +
  491 + if (beginDate == null || endDate == null) {
  492 + throw new IllegalArgumentException("getDiffDays param is null!");
  493 + }
  494 +
  495 + long diff = (endDate.getTime() - beginDate.getTime())
  496 + / (1000 * 60 * 60 * 24);
  497 +
  498 + int days = new Long(diff).intValue();
  499 +
  500 + return days;
  501 + }
  502 +
  503 + //两个日期相减得到的毫秒数
  504 + public static long dateDiff(Date beginDate, Date endDate) {
  505 + long date1ms = beginDate.getTime();
  506 + long date2ms = endDate.getTime();
  507 + return date2ms - date1ms;
  508 + }
  509 +
  510 + //获取两个日期中的最大日期
  511 + public static Date max(Date beginDate, Date endDate) {
  512 + if (beginDate == null) {
  513 + return endDate;
  514 + }
  515 + if (endDate == null) {
  516 + return beginDate;
  517 + }
  518 + if (beginDate.after(endDate)) {
  519 + return beginDate;
  520 + }
  521 + return endDate;
  522 + }
  523 +
  524 + //获取两个日期中的最小日期
  525 + public static Date min(Date beginDate, Date endDate) {
  526 + if (beginDate == null) {
  527 + return endDate;
  528 + }
  529 + if (endDate == null) {
  530 + return beginDate;
  531 + }
  532 + if (beginDate.after(endDate)) {
  533 + return endDate;
  534 + }
  535 + return beginDate;
  536 + }
  537 +
  538 + //返回某月该季度的第一个月
  539 + public static Date getFirstSeasonDate(Date date) {
  540 + final int[] SEASON = {1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4};
  541 + Calendar cal = Calendar.getInstance();
  542 + cal.setTime(date);
  543 + int sean = SEASON[cal.get(Calendar.MONTH)];
  544 + cal.set(Calendar.MONTH, sean * 3 - 3);
  545 + return cal.getTime();
  546 + }
  547 +
  548 + //返回某个日期下几天的日期
  549 + public static Date getNextDay(Date date, int i) {
  550 + Calendar cal = new GregorianCalendar();
  551 + cal.setTime(date);
  552 + cal.set(Calendar.DATE, cal.get(Calendar.DATE) + i);
  553 + return cal.getTime();
  554 + }
  555 +
  556 + //返回某个日期前几天的日期
  557 + public static Date getFrontDay(Date date, int i) {
  558 + Calendar cal = new GregorianCalendar();
  559 + cal.setTime(date);
  560 + cal.set(Calendar.DATE, cal.get(Calendar.DATE) - i);
  561 + return cal.getTime();
  562 + }
  563 +
  564 + //获取某年某月到某年某月按天的切片日期集合(间隔天数的集合)
  565 + @SuppressWarnings({"rawtypes", "unchecked"})
  566 + public static List getTimeList(int beginYear, int beginMonth, int endYear,
  567 + int endMonth, int k) {
  568 + List list = new ArrayList();
  569 + if (beginYear == endYear) {
  570 + for (int j = beginMonth; j <= endMonth; j++) {
  571 + list.add(getTimeList(beginYear, j, k));
  572 +
  573 + }
  574 + } else {
  575 + {
  576 + for (int j = beginMonth; j < 12; j++) {
  577 + list.add(getTimeList(beginYear, j, k));
  578 + }
  579 +
  580 + for (int i = beginYear + 1; i < endYear; i++) {
  581 + for (int j = 0; j < 12; j++) {
  582 + list.add(getTimeList(i, j, k));
  583 + }
  584 + }
  585 + for (int j = 0; j <= endMonth; j++) {
  586 + list.add(getTimeList(endYear, j, k));
  587 + }
  588 + }
  589 + }
  590 + return list;
  591 + }
  592 +
  593 + //获取某年某月按天切片日期集合(某个月间隔多少天的日期集合)
  594 + @SuppressWarnings({"unchecked", "rawtypes"})
  595 + public static List getTimeList(int beginYear, int beginMonth, int k) {
  596 + List list = new ArrayList();
  597 + Calendar begincal = new GregorianCalendar(beginYear, beginMonth, 1);
  598 + int max = begincal.getActualMaximum(Calendar.DATE);
  599 + for (int i = 1; i < max; i = i + k) {
  600 + list.add(begincal.getTime());
  601 + begincal.add(Calendar.DATE, k);
  602 + }
  603 + begincal = new GregorianCalendar(beginYear, beginMonth, max);
  604 + list.add(begincal.getTime());
  605 + return list;
  606 + }
  607 +
  608 + public static Date getBeginTime(int year, int month) {
  609 + YearMonth yearMonth = YearMonth.of(year, month);
  610 + LocalDate localDate = yearMonth.atDay(1);
  611 + LocalDateTime startOfDay = localDate.atStartOfDay();
  612 + ZonedDateTime zonedDateTime = startOfDay.atZone(ZoneId.of("Asia/Shanghai"));
  613 + return Date.from(zonedDateTime.toInstant());
  614 + }
  615 +
  616 + public static Date getEndTime(int year, int month) {
  617 + YearMonth yearMonth = YearMonth.of(year, month);
  618 + LocalDate endOfMonth = yearMonth.atEndOfMonth();
  619 + LocalDateTime localDateTime = endOfMonth.atTime(23, 59, 59, 999);
  620 + ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.of("Asia/Shanghai"));
  621 + return Date.from(zonedDateTime.toInstant());
  622 + }
  623 +
  624 + public static Date addTimeByUpdate(int type, long n, Date time) {
  625 + Calendar calendar = Calendar.getInstance();
  626 + calendar.setTime(time);
  627 + calendar.add(type, Math.toIntExact(n));
  628 + return calendar.getTime();
  629 + }
  630 +
  631 + public static Date getAddMinuDate(Date date,Integer min){
  632 + long time = min*60*1000;//30分钟
  633 +
  634 + Date afterDate = new Date(date.getTime() + time);
  635 + return afterDate;
  636 + }
  637 +
  638 + public static Date addMonth(Date date, Integer range){
  639 + Calendar calendar=Calendar.getInstance();
  640 + calendar.setTime(date);
  641 + calendar.add(Calendar.MONTH,range);
  642 + return calendar.getTime();
  643 + }
  644 +
  645 + /**
  646 + * 计算两个日期之间相差的天数
  647 + * @param date1 第一个日期
  648 + * @param date2 第二个日期
  649 + * @return 两个日期相差的天数,date1在date2之后则返回正数,否则返回负数
  650 + */
  651 + public static long getDaysBetween(Date date1, Date date2) {
  652 + // 检查输入是否为空
  653 + if (date1 == null || date2 == null) {
  654 + throw new IllegalArgumentException("日期不能为null");
  655 + }
  656 +
  657 + // 获取两个日期的时间戳(毫秒数)
  658 + long time1 = date1.getTime();
  659 + long time2 = date2.getTime();
  660 +
  661 + // 计算时间差(毫秒)
  662 + long diffInMillies = time1 - time2+1000;
  663 +
  664 + // 转换为天数
  665 + return TimeUnit.DAYS.convert(diffInMillies, TimeUnit.MILLISECONDS);
  666 + }
  667 +
  668 +
  669 +
  670 +
  671 +}
... ...
  1 +package com.ash.util;
  2 +
  3 +public class ObjectValueOption {
  4 +
  5 + public static String getObjString(Object ojb) {
  6 + if (ojb == null) {
  7 + return null;
  8 + }
  9 + return ojb.toString();
  10 +
  11 + }
  12 +
  13 + public static Integer getObjInt(Object ojb) {
  14 + if (ojb == null) {
  15 + return 0;
  16 + }
  17 + return Integer.parseInt(ojb.toString());
  18 +
  19 + }
  20 +}
... ...
... ... @@ -33,9 +33,18 @@ spring:
33 33 multipart:
34 34 max-file-size: 100MB
35 35 max-request-size: 100MB
  36 +#logging:
  37 +# level:
  38 +# root: INFO
  39 +mybatis-plus:
  40 + mapper-locations: classpath:mapper/*.xml
  41 + type-aliases-package: com.ash.entity
  42 + configuration:
  43 + log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
  44 + map-underscore-to-camel-case: true
36 45 logging:
37 46 level:
38   - root: INFO
  47 + com.ash.entity.dao: debug
39 48 file:
40 49 name: logs/ash.log
41 50 ash:
... ...