Commit 9d79da1b authored by wujiang's avatar wujiang

提交统计代码

parent 19a522e2
...@@ -3,7 +3,12 @@ package com.yeejoin.amos.knowledgebase.controller; ...@@ -3,7 +3,12 @@ package com.yeejoin.amos.knowledgebase.controller;
import com.yeejoin.amos.knowledgebase.face.service.StatisticsRecordService; import com.yeejoin.amos.knowledgebase.face.service.StatisticsRecordService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
...@@ -15,76 +20,159 @@ import org.typroject.tyboot.core.restful.utils.ResponseHelper; ...@@ -15,76 +20,159 @@ import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
@RestController @RestController
//@TycloudResource(module = "knowledgebase", value = "docstatistics") @TycloudResource(module = "knowledgebase", value = "docstatistics")
//@RequestMapping(value = "/v1/doccontent/docstatistics") @RequestMapping(value = "/v1/doccontent/docstatistics")
//@Api(tags = "knowledgebase-文档统计报表") @Api(tags = "knowledgebase-文档统计报表")
public class DocStatisticsResource { public class DocStatisticsResource {
@Autowired @Autowired
private StatisticsRecordService statisticsRecordService; private StatisticsRecordService statisticsRecordService;
/*@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false) /*
@ApiOperation(value = "耗时* 刷新统计数据") * @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@RequestMapping(value = "/record/init", method = RequestMethod.PUT) *
public ResponseModel init() { * @ApiOperation(value = "耗时* 刷新统计数据")
return ResponseHelper.buildResponse(statisticsRecordService.init()); *
} * @RequestMapping(value = "/record/init", method = RequestMethod.PUT) public
* ResponseModel init() { return
* ResponseHelper.buildResponse(statisticsRecordService.init()); }
*
*
* @TycloudOperation(ApiLevel = UserType.AGENCY)
*
* @ApiOperation(value = "灾情统计")
*
* @RequestMapping(value = "/count/disaster", method = RequestMethod.GET) public
* ResponseModel selectDisasterCount() { return
* ResponseHelper.buildResponse(statisticsRecordService.selectDisasterCount());
* }
*
* @TycloudOperation(ApiLevel = UserType.AGENCY)
*
* @ApiOperation(value = "燃烧物质统计分类")
*
* @RequestMapping(value = "/count/burning", method = RequestMethod.GET) public
* ResponseModel selectBurningCategory() { return
* ResponseHelper.buildResponse(statisticsRecordService.selectCategoryByName(
* StatisticsRecordService.STATISTICS_BURNING_CATEGORY)); }
*
* @TycloudOperation(ApiLevel = UserType.AGENCY)
*
* @ApiOperation(value = "到场时间统计分类")
*
* @RequestMapping(value = "/count/present", method = RequestMethod.GET) public
* ResponseModel selectPresentCategory() { return
* ResponseHelper.buildResponse(statisticsRecordService.selectCategoryByName(
* StatisticsRecordService.STATISTICS_PRESENT_CATEGORY)); }
*
* @TycloudOperation(ApiLevel = UserType.AGENCY)
*
* @ApiOperation(value = "伤亡人数趋势统计")
*
* @RequestMapping(value = "/count/casualties", method = RequestMethod.GET)
* public ResponseModel selectCasualtiesSum(@RequestParam(value = "dateType")
* String dateType,
*
* @RequestParam(value = "dateRangeLeft", required = false) String
* dateRangeLeft,
*
* @RequestParam(value = "dateRangeRight", required = false) String
* dateRangeRight) { return
* ResponseHelper.buildResponse(statisticsRecordService.
* selectCountByTypeAndDateRange(dateType, dateRangeLeft, dateRangeRight,
* StatisticsRecordService.STATISTICS_CASUALTIES_SUM)); }
*
* @TycloudOperation(ApiLevel = UserType.AGENCY)
*
* @ApiOperation(value = "参战车辆数量统计")
*
* @RequestMapping(value = "/count/power", method = RequestMethod.GET) public
* ResponseModel selectPowerSum(@RequestParam(value = "dateType") String
* dateType,
*
* @RequestParam(value = "dateRangeLeft", required = false) String
* dateRangeLeft,
*
* @RequestParam(value = "dateRangeRight", required = false) String
* dateRangeRight) { return
* ResponseHelper.buildResponse(statisticsRecordService.
* selectCountByTypeAndDateRange(dateType, dateRangeLeft, dateRangeRight,
* StatisticsRecordService.STATISTICS_POWER_SUM)); }
*
* @TycloudOperation(ApiLevel = UserType.AGENCY)
*
* @ApiOperation(value = "过火面积统计")
*
* @RequestMapping(value = "/count/area", method = RequestMethod.GET) public
* ResponseModel selectAreaSum(@RequestParam(value = "dateType") String
* dateType,
*
* @RequestParam(value = "dateRangeLeft", required = false) String
* dateRangeLeft,
*
* @RequestParam(value = "dateRangeRight", required = false) String
* dateRangeRight) { return
* ResponseHelper.buildResponse(statisticsRecordService.
* selectCountByTypeAndDateRange(dateType, dateRangeLeft, dateRangeRight,
* StatisticsRecordService.STATISTICS_AREA_COUNT)); }
*
* @TycloudOperation(ApiLevel = UserType.AGENCY)
*
* @ApiOperation(value = "灭火药剂统计")
*
* @RequestMapping(value = "/count/extinguishing", method = RequestMethod.GET)
* public ResponseModel selectExtinguishingSum(@RequestParam(value = "dateType")
* String dateType,
*
* @RequestParam(value = "dateRangeLeft", required = false) String
* dateRangeLeft,
*
* @RequestParam(value = "dateRangeRight", required = false) String
* dateRangeRight) { return
* ResponseHelper.buildResponse(statisticsRecordService.
* selectCountByTypeAndDateRange(dateType, dateRangeLeft, dateRangeRight,
* StatisticsRecordService.STATISTICS_EXTINGUISHING_SUM)); }
*/
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@TycloudOperation(ApiLevel = UserType.AGENCY) @ApiOperation(value = "标签总数统计")
@ApiOperation(value = "灾情统计") @RequestMapping(value = "/tag/statistics", method = RequestMethod.GET)
@RequestMapping(value = "/count/disaster", method = RequestMethod.GET) public ResponseModel tagStatistics(@RequestParam(value = "tag") String tag,
public ResponseModel selectDisasterCount() { @RequestParam(value = "startDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
return ResponseHelper.buildResponse(statisticsRecordService.selectDisasterCount()); @RequestParam(value = "endDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
@RequestParam(value = "mode", required = false) String mode) {
return ResponseHelper.buildResponse(statisticsRecordService.tagStatistics(tag, startDate, endDate, mode));
} }
@TycloudOperation(ApiLevel = UserType.AGENCY) @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@ApiOperation(value = "燃烧物质统计分类") @ApiOperation(value = "文档总数统计")
@RequestMapping(value = "/count/burning", method = RequestMethod.GET) @RequestMapping(value = "/doc/statistics", method = RequestMethod.GET)
public ResponseModel selectBurningCategory() { public ResponseModel docStatistics(@RequestParam(value = "categoryName") String categoryName,
return ResponseHelper.buildResponse(statisticsRecordService.selectCategoryByName(StatisticsRecordService.STATISTICS_BURNING_CATEGORY)); @RequestParam(value = "startDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
@RequestParam(value = "endDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
@RequestParam(value = "mode", required = false) String mode) {
return ResponseHelper
.buildResponse(statisticsRecordService.docStatistics(categoryName, startDate, endDate, mode));
} }
@TycloudOperation(ApiLevel = UserType.AGENCY) @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@ApiOperation(value = "到场时间统计分类") @ApiOperation(value = "标签总数统计")
@RequestMapping(value = "/count/present", method = RequestMethod.GET) @RequestMapping(value = "/tag-chart/statistics", method = RequestMethod.GET)
public ResponseModel selectPresentCategory() { public ResponseModel tagChartStatistics(@RequestParam(value = "tag") String tag,
return ResponseHelper.buildResponse(statisticsRecordService.selectCategoryByName(StatisticsRecordService.STATISTICS_PRESENT_CATEGORY)); @RequestParam(value = "startDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
@RequestParam(value = "endDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
@RequestParam(value = "split") List<Integer> split, @RequestParam(value = "unit") String unit) {
return ResponseHelper
.buildResponse(statisticsRecordService.tagChartStatistics(tag, startDate, endDate, split, unit));
} }
@TycloudOperation(ApiLevel = UserType.AGENCY) @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@ApiOperation(value = "伤亡人数趋势统计") @ApiOperation(value = "文档总数统计")
@RequestMapping(value = "/count/casualties", method = RequestMethod.GET) @RequestMapping(value = "/doc-chart/statistics", method = RequestMethod.GET)
public ResponseModel selectCasualtiesSum(@RequestParam(value = "dateType") String dateType, public ResponseModel docChartStatistics(
@RequestParam(value = "dateRangeLeft", required = false) String dateRangeLeft, @RequestParam(value = "startDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
@RequestParam(value = "dateRangeRight", required = false) String dateRangeRight) { @RequestParam(value = "endDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
return ResponseHelper.buildResponse(statisticsRecordService.selectCountByTypeAndDateRange(dateType, dateRangeLeft, dateRangeRight, StatisticsRecordService.STATISTICS_CASUALTIES_SUM)); return ResponseHelper
.buildResponse(statisticsRecordService.docChartStatistics(startDate, endDate));
} }
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(value = "参战车辆数量统计")
@RequestMapping(value = "/count/power", method = RequestMethod.GET)
public ResponseModel selectPowerSum(@RequestParam(value = "dateType") String dateType,
@RequestParam(value = "dateRangeLeft", required = false) String dateRangeLeft,
@RequestParam(value = "dateRangeRight", required = false) String dateRangeRight) {
return ResponseHelper.buildResponse(statisticsRecordService.selectCountByTypeAndDateRange(dateType, dateRangeLeft, dateRangeRight, StatisticsRecordService.STATISTICS_POWER_SUM));
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(value = "过火面积统计")
@RequestMapping(value = "/count/area", method = RequestMethod.GET)
public ResponseModel selectAreaSum(@RequestParam(value = "dateType") String dateType,
@RequestParam(value = "dateRangeLeft", required = false) String dateRangeLeft,
@RequestParam(value = "dateRangeRight", required = false) String dateRangeRight) {
return ResponseHelper.buildResponse(statisticsRecordService.selectCountByTypeAndDateRange(dateType, dateRangeLeft, dateRangeRight, StatisticsRecordService.STATISTICS_AREA_COUNT));
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(value = "灭火药剂统计")
@RequestMapping(value = "/count/extinguishing", method = RequestMethod.GET)
public ResponseModel selectExtinguishingSum(@RequestParam(value = "dateType") String dateType,
@RequestParam(value = "dateRangeLeft", required = false) String dateRangeLeft,
@RequestParam(value = "dateRangeRight", required = false) String dateRangeRight) {
return ResponseHelper.buildResponse(statisticsRecordService.selectCountByTypeAndDateRange(dateType, dateRangeLeft, dateRangeRight, StatisticsRecordService.STATISTICS_EXTINGUISHING_SUM));
}*/
} }
...@@ -3,6 +3,7 @@ package com.yeejoin.amos.knowledgebase.face.orm.dao; ...@@ -3,6 +3,7 @@ package com.yeejoin.amos.knowledgebase.face.orm.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.knowledgebase.face.orm.entity.KnowlegeStatisticsRecord; import com.yeejoin.amos.knowledgebase.face.orm.entity.KnowlegeStatisticsRecord;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -18,12 +19,14 @@ public interface StatisticsRecordMapper extends BaseMapper<KnowlegeStatisticsRec ...@@ -18,12 +19,14 @@ public interface StatisticsRecordMapper extends BaseMapper<KnowlegeStatisticsRec
/** /**
* 表清空 * 表清空
*
* @return * @return
*/ */
void deleteAll(); void deleteAll();
/** /**
* 查询灾情总计 * 查询灾情总计
*
* @return * @return
*/ */
Map<String, Object> selectDisasterCount(); Map<String, Object> selectDisasterCount();
...@@ -38,4 +41,15 @@ public interface StatisticsRecordMapper extends BaseMapper<KnowlegeStatisticsRec ...@@ -38,4 +41,15 @@ public interface StatisticsRecordMapper extends BaseMapper<KnowlegeStatisticsRec
*/ */
List<Map<String, Object>> selectCountByNameAndDateRange(Map<String, Object> queryMap); List<Map<String, Object>> selectCountByNameAndDateRange(Map<String, Object> queryMap);
List<Map<String, Object>> tagStatisticsMonth(String tag, Date startDate, Date endDate);
List<Map<String, Object>> tagStatisticsYear(String tag, Date startDate, Date endDate);
List<Map<String, Object>> docStatisticsMonth(String categoryName, Date startDate, Date endDate);
List<Map<String, Object>> docStatisticsYear(String categoryName, Date startDate, Date endDate);
List<Map<String, Object>> tagChartStatistics(String tag, Date startDate, Date endDate,String splitSQL);
List<Map<String, Object>> docChartStatistics(Date startDate, Date endDate);
} }
\ No newline at end of file
package com.yeejoin.amos.knowledgebase.face.service; package com.yeejoin.amos.knowledgebase.face.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ctc.wstx.util.StringUtil;
import com.yeejoin.amos.knowledgebase.face.model.KnowledgeDocContentModel; import com.yeejoin.amos.knowledgebase.face.model.KnowledgeDocContentModel;
import com.yeejoin.amos.knowledgebase.face.model.KnowledgeTagInstanceModel; import com.yeejoin.amos.knowledgebase.face.model.KnowledgeTagInstanceModel;
import com.yeejoin.amos.knowledgebase.face.model.KnowlegeStatisticsRecordModel; import com.yeejoin.amos.knowledgebase.face.model.KnowlegeStatisticsRecordModel;
import com.yeejoin.amos.knowledgebase.face.orm.dao.StatisticsRecordMapper; import com.yeejoin.amos.knowledgebase.face.orm.dao.StatisticsRecordMapper;
import com.yeejoin.amos.knowledgebase.face.orm.entity.KnowledgeDocContent; import com.yeejoin.amos.knowledgebase.face.orm.entity.KnowledgeDocContent;
import com.yeejoin.amos.knowledgebase.face.orm.entity.KnowlegeStatisticsRecord; import com.yeejoin.amos.knowledgebase.face.orm.entity.KnowlegeStatisticsRecord;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -23,9 +25,9 @@ import org.typroject.tyboot.core.foundation.utils.ValidationUtil; ...@@ -23,9 +25,9 @@ import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService; import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest; import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
/** /**
* <p> * <p>
* 标签分组 服务类 * 标签分组 服务类
...@@ -35,278 +37,299 @@ import java.util.*; ...@@ -35,278 +37,299 @@ import java.util.*;
* @since 2020-08-05 * @since 2020-08-05
*/ */
@Component @Component
public class StatisticsRecordService extends BaseService<KnowlegeStatisticsRecordModel, KnowlegeStatisticsRecord, StatisticsRecordMapper> { public class StatisticsRecordService
extends BaseService<KnowlegeStatisticsRecordModel, KnowlegeStatisticsRecord, StatisticsRecordMapper> {
/*@Autowired
private DocContentService docContentService;
private final Logger logger = LogManager.getLogger(StatisticsRecordService.class);
/*
* @Autowired private DocContentService docContentService;
*
* private final Logger logger =
* LogManager.getLogger(StatisticsRecordService.class);
*
*//** *//**
* 灾情标记 * 灾情标记
*//* */
public static final String TAG_NAME_TIME = "时间"; /*
public static final String STATISTICS_DISASTER_COUNT = "DISASTER_RECORD"; * public static final String TAG_NAME_TIME = "时间"; public static final String
* STATISTICS_DISASTER_COUNT = "DISASTER_RECORD";
*
*//** *//**
* 燃烧物质分类 * 燃烧物质分类
*//* */
public static final String TAG_NAME_BURNING = "燃烧物质"; /*
public static final String STATISTICS_BURNING_CATEGORY = "BURNING_RECORD"; * public static final String TAG_NAME_BURNING = "燃烧物质"; public static final
* String STATISTICS_BURNING_CATEGORY = "BURNING_RECORD";
*
*//** *//**
* 参战车辆统计 * 参战车辆统计
*//* */
public static final String TAG_NAME_POWER = "参战车辆"; /*
public static final String STATISTICS_POWER_SUM = "POWER_RECORD"; * public static final String TAG_NAME_POWER = "参战车辆"; public static final
* String STATISTICS_POWER_SUM = "POWER_RECORD";
*
*//** *//**
* 伤亡人数统计 * 伤亡人数统计
*//* */
public static final String TAG_NAME_CASUALTIES = "人员伤亡情况 含亡人"; /*
public static final String STATISTICS_CASUALTIES_SUM = "CASUALTIES_RECORD"; * public static final String TAG_NAME_CASUALTIES = "人员伤亡情况 含亡人"; public static
* final String STATISTICS_CASUALTIES_SUM = "CASUALTIES_RECORD";
*
*//** *//**
* 灭火药剂统计 * 灭火药剂统计
*//* */
public static final String TAG_NAME_EXTINGUISHING = "使用的灭火药剂数量"; /*
public static final String STATISTICS_EXTINGUISHING_SUM = "EXTINGUISHING_RECORD"; * public static final String TAG_NAME_EXTINGUISHING = "使用的灭火药剂数量"; public
* static final String STATISTICS_EXTINGUISHING_SUM = "EXTINGUISHING_RECORD";
*
*//** *//**
* 过火面积统计 * 过火面积统计
*//* */
public static final String TAG_NAME_AREA = "过火面积"; /*
public static final String STATISTICS_AREA_COUNT = "FIRE_AREA_RECORD"; * public static final String TAG_NAME_AREA = "过火面积"; public static final String
* STATISTICS_AREA_COUNT = "FIRE_AREA_RECORD";
*
*//** *//**
* 到场时间分类 * 到场时间分类
*//* */
public static final String TAG_NAME_PICKUP = "接警时间"; /*
public static final String TAG_NAME_PRESENT = "到场时间"; * public static final String TAG_NAME_PICKUP = "接警时间"; public static final
public static final String STATISTICS_PRESENT_CATEGORY = "PRESENT_TIME_RECORD"; * String TAG_NAME_PRESENT = "到场时间"; public static final String
* STATISTICS_PRESENT_CATEGORY = "PRESENT_TIME_RECORD";
*
public static final String DATE_GROUP_BY_DAY = "day"; *
public static final String DATE_GROUP_BY_MONTH = "month"; * public static final String DATE_GROUP_BY_DAY = "day"; public static final
* String DATE_GROUP_BY_MONTH = "month";
@Value("${diy-config.report.record-data}") *
private boolean needRecord; * @Value("${diy-config.report.record-data}") private boolean needRecord;
*
*//** 根据文档标签添加对应的记录 *//* *//** 根据文档标签添加对应的记录 */
private void addRecordWithDocValueTag(List<KnowledgeTagInstanceModel> docTags, Long docSeq) { /*
//找出预定义的所有标签 * private void addRecordWithDocValueTag(List<KnowledgeTagInstanceModel>
Map<Object, KnowledgeTagInstanceModel> tagMap = Bean.listToMap(docTags, "tagName", KnowledgeTagInstanceModel.class); * docTags, Long docSeq) { //找出预定义的所有标签 Map<Object, KnowledgeTagInstanceModel>
KnowledgeTagInstanceModel tagTime = tagMap.get(TAG_NAME_TIME); * tagMap = Bean.listToMap(docTags, "tagName", KnowledgeTagInstanceModel.class);
if (ValidationUtil.isEmpty(tagTime)) { * KnowledgeTagInstanceModel tagTime = tagMap.get(TAG_NAME_TIME); if
return; * (ValidationUtil.isEmpty(tagTime)) { return; } Object timeObj =
} * getValueFromTag(tagTime); if (ValidationUtil.isEmpty(timeObj) || !(timeObj
Object timeObj = getValueFromTag(tagTime); * instanceof Date)) { return; } Date disasterTime = (Date) timeObj; //记录灾情
if (ValidationUtil.isEmpty(timeObj) || !(timeObj instanceof Date)) { * insertSumTypeRecord(docSeq, disasterTime, STATISTICS_DISASTER_COUNT, 1.0, 1);
return; * //记录燃烧物质 KnowledgeTagInstanceModel tagBurning = tagMap.get(TAG_NAME_BURNING);
} * if (!ValidationUtil.isEmpty(tagBurning)) { insertCategoryTypeRecord(docSeq,
Date disasterTime = (Date) timeObj; * disasterTime, STATISTICS_BURNING_CATEGORY, getValueFromTag(tagBurning)); }
//记录灾情 * //记录参战车辆 KnowledgeTagInstanceModel tagPower = tagMap.get(TAG_NAME_POWER); if
insertSumTypeRecord(docSeq, disasterTime, STATISTICS_DISASTER_COUNT, 1.0, 1); * (!ValidationUtil.isEmpty(tagPower)) { insertSumTypeRecord(docSeq,
//记录燃烧物质 * disasterTime, STATISTICS_POWER_SUM, getValueFromTag(tagPower), 1); } //记录伤亡人数
KnowledgeTagInstanceModel tagBurning = tagMap.get(TAG_NAME_BURNING); * KnowledgeTagInstanceModel tagCasualties = tagMap.get(TAG_NAME_CASUALTIES); if
if (!ValidationUtil.isEmpty(tagBurning)) { * (!ValidationUtil.isEmpty(tagCasualties)) { insertSumTypeRecord(docSeq,
insertCategoryTypeRecord(docSeq, disasterTime, STATISTICS_BURNING_CATEGORY, getValueFromTag(tagBurning)); * disasterTime, STATISTICS_CASUALTIES_SUM, getValueFromTag(tagCasualties), 1);
} * } //记录灭火药剂数量 KnowledgeTagInstanceModel tagExtinguishing =
//记录参战车辆 * tagMap.get(TAG_NAME_EXTINGUISHING); if
KnowledgeTagInstanceModel tagPower = tagMap.get(TAG_NAME_POWER); * (!ValidationUtil.isEmpty(tagExtinguishing)) { insertSumTypeRecord(docSeq,
if (!ValidationUtil.isEmpty(tagPower)) { * disasterTime, STATISTICS_EXTINGUISHING_SUM,
insertSumTypeRecord(docSeq, disasterTime, STATISTICS_POWER_SUM, getValueFromTag(tagPower), 1); * getValueFromTag(tagExtinguishing), 1); } //记录过火面积 KnowledgeTagInstanceModel
} * tagArea = tagMap.get(TAG_NAME_AREA); if (!ValidationUtil.isEmpty(tagArea)) {
//记录伤亡人数 * insertSumTypeRecord(docSeq, disasterTime, STATISTICS_AREA_COUNT,
KnowledgeTagInstanceModel tagCasualties = tagMap.get(TAG_NAME_CASUALTIES); * getValueFromTag(tagArea), 1); } //记录到场时间 KnowledgeTagInstanceModel tagPickup
if (!ValidationUtil.isEmpty(tagCasualties)) { * = tagMap.get(TAG_NAME_PICKUP); KnowledgeTagInstanceModel tagPresent =
insertSumTypeRecord(docSeq, disasterTime, STATISTICS_CASUALTIES_SUM, getValueFromTag(tagCasualties), 1); * tagMap.get(TAG_NAME_PRESENT); if (!ValidationUtil.isEmpty(tagPickup) &&
} * !ValidationUtil.isEmpty(tagPresent)) { Object pickTimeObj =
//记录灭火药剂数量 * getValueFromTag(tagPickup); Object presentTimeObj =
KnowledgeTagInstanceModel tagExtinguishing = tagMap.get(TAG_NAME_EXTINGUISHING); * getValueFromTag(tagPresent); if (!ValidationUtil.isEmpty(pickTimeObj) &&
if (!ValidationUtil.isEmpty(tagExtinguishing)) { * pickTimeObj instanceof Date && !ValidationUtil.isEmpty(presentTimeObj) &&
insertSumTypeRecord(docSeq, disasterTime, STATISTICS_EXTINGUISHING_SUM, getValueFromTag(tagExtinguishing), 1); * presentTimeObj instanceof Date) { long presentTimeByMinute = (long)
} * Math.ceil((((Date) presentTimeObj).getTime() - ((Date)
//记录过火面积 * pickTimeObj).getTime()) / 1000.0 / 60.0); insertCategoryTypeRecord(docSeq,
KnowledgeTagInstanceModel tagArea = tagMap.get(TAG_NAME_AREA); * disasterTime, STATISTICS_PRESENT_CATEGORY, presentTimeByMinute); } } }
if (!ValidationUtil.isEmpty(tagArea)) { *
insertSumTypeRecord(docSeq, disasterTime, STATISTICS_AREA_COUNT, getValueFromTag(tagArea), 1); *//** 获取标签值 */
} /*
//记录到场时间 * private Object getValueFromTag(KnowledgeTagInstanceModel tag) { if
KnowledgeTagInstanceModel tagPickup = tagMap.get(TAG_NAME_PICKUP); * (ValidationUtil.isEmpty(tag) || !ValidationUtil.equals(tag.getTagType(),
KnowledgeTagInstanceModel tagPresent = tagMap.get(TAG_NAME_PRESENT); * TagService.TAG_TYPE_VALUE) || ValidationUtil.isEmpty(tag.getTagValues())) {
if (!ValidationUtil.isEmpty(tagPickup) && !ValidationUtil.isEmpty(tagPresent)) { * return null; } String fieldName = tag.getTagValues().get(0).getFieldName();
Object pickTimeObj = getValueFromTag(tagPickup); * String tagValue = tag.getTagValues().get(0).getTagValue(); if
Object presentTimeObj = getValueFromTag(tagPresent); * (ValidationUtil.isEmpty(fieldName) || ValidationUtil.isEmpty(tagValue)) {
if (!ValidationUtil.isEmpty(pickTimeObj) && pickTimeObj instanceof Date * return null; } switch (fieldName) { case
&& !ValidationUtil.isEmpty(presentTimeObj) && presentTimeObj instanceof Date) { * TagValueService.VALUE_TAG_FIELD_DATE_H: try { return
long presentTimeByMinute = (long) Math.ceil((((Date) presentTimeObj).getTime() - ((Date) pickTimeObj).getTime()) / 1000.0 / 60.0); * DateUtil.formatStringToDate(tagValue, null); } catch (Exception e) {
insertCategoryTypeRecord(docSeq, disasterTime, STATISTICS_PRESENT_CATEGORY, presentTimeByMinute); * logger.error("报表统计:时间格式标签值解析出错"); return null; } case
} * TagValueService.VALUE_TAG_FIELD_SINGLEVALUE: try { return
} * Double.parseDouble(tagValue); } catch (Exception e) {
} * logger.error("报表统计:数字格式标签值解析出错"); return null; } case
* TagValueService.VALUE_TAG_FIELD_TEXT: return tagValue; default: return null;
*//** 获取标签值 *//* * } }
private Object getValueFromTag(KnowledgeTagInstanceModel tag) { *
if (ValidationUtil.isEmpty(tag) *//** 插入分类统计记录 */
|| !ValidationUtil.equals(tag.getTagType(), TagService.TAG_TYPE_VALUE) /*
|| ValidationUtil.isEmpty(tag.getTagValues())) { * private void insertCategoryTypeRecord(Long docSeq, Date disasterTime, String
return null; * recordName, Object category) { KnowlegeStatisticsRecordModel recordModel =
} * new KnowlegeStatisticsRecordModel(); recordModel.setDocSeq(docSeq);
String fieldName = tag.getTagValues().get(0).getFieldName(); * recordModel.setDisasterTime(disasterTime);
String tagValue = tag.getTagValues().get(0).getTagValue(); * recordModel.setRecordName(recordName);
if (ValidationUtil.isEmpty(fieldName) * recordModel.setCategoryValue(String.valueOf(category));
|| ValidationUtil.isEmpty(tagValue)) { * recordModel.setValueWeight(1); recordModel.setCountValue(1L);
return null; * this.createWithModel(recordModel); }
} *
switch (fieldName) { *
case TagValueService.VALUE_TAG_FIELD_DATE_H: *//** 插入数量统计记录 */
try { /*
return DateUtil.formatStringToDate(tagValue, null); * private void insertSumTypeRecord(Long docSeq, Date disasterTime, String
} catch (Exception e) { * recordName, Object numObj, Integer weight) { if
logger.error("报表统计:时间格式标签值解析出错"); * (!ValidationUtil.isEmpty(numObj) && numObj instanceof Double) { Long num =
return null; * ((Double) numObj).longValue(); KnowlegeStatisticsRecordModel recordModel =
} * new KnowlegeStatisticsRecordModel(); recordModel.setDocSeq(docSeq);
case TagValueService.VALUE_TAG_FIELD_SINGLEVALUE: * recordModel.setDisasterTime(disasterTime);
try { * recordModel.setRecordName(recordName); recordModel.setCountValue(num);
return Double.parseDouble(tagValue); * recordModel.setValueWeight(weight); this.createWithModel(recordModel); } }
} catch (Exception e) { *
logger.error("报表统计:数字格式标签值解析出错");
return null;
}
case TagValueService.VALUE_TAG_FIELD_TEXT:
return tagValue;
default:
return null;
}
}
*//** 插入分类统计记录 *//*
private void insertCategoryTypeRecord(Long docSeq, Date disasterTime, String recordName, Object category) {
KnowlegeStatisticsRecordModel recordModel = new KnowlegeStatisticsRecordModel();
recordModel.setDocSeq(docSeq);
recordModel.setDisasterTime(disasterTime);
recordModel.setRecordName(recordName);
recordModel.setCategoryValue(String.valueOf(category));
recordModel.setValueWeight(1);
recordModel.setCountValue(1L);
this.createWithModel(recordModel);
}
*//** 插入数量统计记录 *//*
private void insertSumTypeRecord(Long docSeq, Date disasterTime, String recordName, Object numObj, Integer weight) {
if (!ValidationUtil.isEmpty(numObj) && numObj instanceof Double) {
Long num = ((Double) numObj).longValue();
KnowlegeStatisticsRecordModel recordModel = new KnowlegeStatisticsRecordModel();
recordModel.setDocSeq(docSeq);
recordModel.setDisasterTime(disasterTime);
recordModel.setRecordName(recordName);
recordModel.setCountValue(num);
recordModel.setValueWeight(weight);
this.createWithModel(recordModel);
}
}
*//** *//**
* 根据文档id删除相关记录 * 根据文档id删除相关记录
*//* */
public void deleteRecordsByDocIds(List<KnowledgeDocContentModel> docs) { /*
if (!ValidationUtil.isEmpty(docs)) { * public void deleteRecordsByDocIds(List<KnowledgeDocContentModel> docs) { if
Set ids = Bean.listToMap(docs, "sequenceNbr", KnowledgeDocContentModel.class).keySet(); * (!ValidationUtil.isEmpty(docs)) { Set ids = Bean.listToMap(docs,
QueryWrapper<KnowlegeStatisticsRecord> wrapper = new QueryWrapper<>(); * "sequenceNbr", KnowledgeDocContentModel.class).keySet();
wrapper.in("doc_seq", ids); * QueryWrapper<KnowlegeStatisticsRecord> wrapper = new QueryWrapper<>();
this.getBaseMapper().delete(wrapper); * wrapper.in("doc_seq", ids); this.getBaseMapper().delete(wrapper); } }
} *
}
*//** *//**
* 初始化统计数据记录 * 初始化统计数据记录
* *
* @return * @return
*/
/*
* @Transactional(rollbackFor = {Exception.class, BaseException.class}) public
* boolean init() { this.getBaseMapper().deleteAll(); //扫描所有已发布文档相关的统计型标签
* QueryWrapper<KnowledgeDocContent> wrapper = new QueryWrapper<>();
* wrapper.eq("doc_status", DocContentService.DOC_STATUS_PUBLISHED); int count =
* docContentService.count(wrapper); int finishNmu = 0; int current = 0; while
* (count > finishNmu) { Page page = new Page(current++, 30); IPage resPage =
* docContentService.page(page, wrapper); List<KnowledgeDocContent> records =
* resPage.getRecords(); Set ids = Bean.listToMap(records, "sequenceNbr",
* KnowledgeDocContent.class).keySet(); saveRecordsByDocIds(ids); finishNmu +=
* records.size(); } return true; }
*
* public boolean addDocRecords(List<KnowledgeDocContentModel> docs) { if
* (!ValidationUtil.isEmpty(docs)) { Set ids = Bean.listToMap(docs,
* "sequenceNbr", KnowledgeDocContentModel.class).keySet();
* saveRecordsByDocIds(ids); } return true; }
*
* private void saveRecordsByDocIds(Collection ids) { if (!needRecord) { return;
* } for (Object id : ids) { KnowledgeDocContentModel docContentModel =
* docContentService.queryOneDocDetail((Long) id); if
* (ValidationUtil.isEmpty(docContentModel)) { continue; }
* addRecordWithDocValueTag(docContentModel.getDocTags(),
* docContentModel.getSequenceNbr()); } }
*
*//**
* 查询灾情统计/同比/环比
*
* @return
*/
/*
* public Map<String, Object> selectDisasterCount() { return
* this.getBaseMapper().selectDisasterCount(); }
*
* public List<Map<String, Object>> selectCategoryByName(String recordName) {
* return this.getBaseMapper().selectCategoryByName(recordName); }
*
*//**
* 分类汇总
*//* *//*
@Transactional(rollbackFor = {Exception.class, BaseException.class}) * public List<Map<String, Object>> selectCountByTypeAndDateRange(String
public boolean init() { * dateType, String dateRangeLeft, String dateRangeRight, String recordName) {
this.getBaseMapper().deleteAll(); * Map<String, Object> queryMap = new HashMap<>(); switch (dateType) { case
//扫描所有已发布文档相关的统计型标签 * DATE_GROUP_BY_MONTH: queryMap.put("format", "%Y-%m"); break; default:
QueryWrapper<KnowledgeDocContent> wrapper = new QueryWrapper<>(); * queryMap.put("format", "%Y-%m-%d"); break; }
wrapper.eq("doc_status", DocContentService.DOC_STATUS_PUBLISHED); * if(!ValidationUtil.isEmpty(dateRangeLeft)){ try {
int count = docContentService.count(wrapper); * queryMap.put("dateRangeLeft", DateUtil.formatStringToDate(dateRangeLeft,
int finishNmu = 0; * null)); } catch (Exception e) { throw new BadRequest("时间参数格式有误"); } }
int current = 0; * if(!ValidationUtil.isEmpty(dateRangeRight)){ try {
while (count > finishNmu) { * queryMap.put("dateRangeRight", DateUtil.formatStringToDate(dateRangeRight,
Page page = new Page(current++, 30); * null)); } catch (Exception e) { throw new BadRequest("时间参数格式有误"); } }
IPage resPage = docContentService.page(page, wrapper); * queryMap.put("recordName", recordName); return
List<KnowledgeDocContent> records = resPage.getRecords(); * this.getBaseMapper().selectCountByNameAndDateRange(queryMap); }
Set ids = Bean.listToMap(records, "sequenceNbr", KnowledgeDocContent.class).keySet(); */
saveRecordsByDocIds(ids);
finishNmu += records.size();
}
return true;
}
public boolean addDocRecords(List<KnowledgeDocContentModel> docs) { public Map<String, Object> tagStatistics(String tag, Date startDate, Date endDate, String mode) {
if (!ValidationUtil.isEmpty(docs)) { endDate = getLastDayOfMonth(endDate);
Set ids = Bean.listToMap(docs, "sequenceNbr", KnowledgeDocContentModel.class).keySet(); List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
saveRecordsByDocIds(ids); Map<String, Object> map = new HashMap<String, Object>();
if ("year".equals(mode)) {
list = this.baseMapper.tagStatisticsYear(tag, startDate, endDate);
} }
return true; {
list = this.baseMapper.tagStatisticsMonth(tag, startDate, endDate);
} }
list.forEach(i -> {
private void saveRecordsByDocIds(Collection ids) { map.put((String) i.get("date"), i.get("datas"));
if (!needRecord) { });
return; return map;
} }
for (Object id : ids) {
KnowledgeDocContentModel docContentModel = docContentService.queryOneDocDetail((Long) id); public Map<String, Object> docStatistics(String categoryName, Date startDate, Date endDate, String mode) {
if (ValidationUtil.isEmpty(docContentModel)) { endDate = getLastDayOfMonth(endDate);
continue; List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
if ("year".equals(mode)) {
list = this.baseMapper.docStatisticsYear(categoryName, startDate, endDate);
} }
addRecordWithDocValueTag(docContentModel.getDocTags(), docContentModel.getSequenceNbr()); {
list = this.baseMapper.docStatisticsMonth(categoryName, startDate, endDate);
} }
list.forEach(i -> {
map.put((String) i.get("date"), i.get("datas"));
});
return map;
} }
*//** public Map<String, Object> tagChartStatistics(String tag, Date startDate, Date endDate, List<Integer> split,
* 查询灾情统计/同比/环比 String unit) {
* endDate = getLastDayOfMonth(endDate);
* @return List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
*//* Map<String, Object> map = new HashMap<String, Object>();
public Map<String, Object> selectDisasterCount() { StringBuffer sb = new StringBuffer();
return this.getBaseMapper().selectDisasterCount(); sb.append("elt(interval(ktv.TAG_VALUE");
for (int s : split) {
sb.append(",").append(s);
}
sb.append(")");
String last = "";
for (int s : split) {
if (StringUtils.isNotEmpty(last)) {
sb.append(",'").append(last).append("-").append(s).append(unit).append("'");
}
last = String.valueOf(s);
}
sb.append(",'").append(last).append(unit).append("以上'").append(")");
// String sql="elt(interval(ktv.TAG_VALUE,0, 5, 10, 40), 'less100', '100to500',
// '500to1000', 'more1000K')";
list = this.baseMapper.tagChartStatistics(tag, startDate, endDate, sb.toString());
list.forEach(i -> {
map.put((String) i.get("level"), i.get("datas"));
});
return map;
} }
public List<Map<String, Object>> selectCategoryByName(String recordName) { public Map<String, Object> docChartStatistics(Date startDate, Date endDate) {
return this.getBaseMapper().selectCategoryByName(recordName); endDate = getLastDayOfMonth(endDate);
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
list = this.baseMapper.docChartStatistics(startDate, endDate);
list.forEach(i -> {
if (i.get("categoryName") != null) {
map.put((String) i.get("categoryName"), i.get("datas"));
}
});
return map;
} }
*//** private static Date getLastDayOfMonth(Date date) {
* 分类汇总 Calendar cal = Calendar.getInstance();
*//* cal.setTime(date);
public List<Map<String, Object>> selectCountByTypeAndDateRange(String dateType, String dateRangeLeft, String dateRangeRight, String recordName) { // 获取某月最大天数
Map<String, Object> queryMap = new HashMap<>(); int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
switch (dateType) { // 设置日历中月份的最大天数
case DATE_GROUP_BY_MONTH: cal.set(Calendar.DAY_OF_MONTH, lastDay);
queryMap.put("format", "%Y-%m"); return cal.getTime();
break;
default:
queryMap.put("format", "%Y-%m-%d");
break;
}
if(!ValidationUtil.isEmpty(dateRangeLeft)){
try {
queryMap.put("dateRangeLeft", DateUtil.formatStringToDate(dateRangeLeft, null));
} catch (Exception e) {
throw new BadRequest("时间参数格式有误");
}
}
if(!ValidationUtil.isEmpty(dateRangeRight)){
try {
queryMap.put("dateRangeRight", DateUtil.formatStringToDate(dateRangeRight, null));
} catch (Exception e) {
throw new BadRequest("时间参数格式有误");
}
} }
queryMap.put("recordName", recordName);
return this.getBaseMapper().selectCountByNameAndDateRange(queryMap);
}*/
} }
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