|
@@ -1,11 +1,34 @@
|
|
|
package com.bizmatics.mhfire.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.bizmatics.common.core.bean.CommonPage;
|
|
|
+import com.bizmatics.common.core.util.BeanMapperUtils;
|
|
|
+import com.bizmatics.common.core.util.DateUtils;
|
|
|
+import com.bizmatics.common.core.util.StringUtils;
|
|
|
+import com.bizmatics.common.mvc.base.AbstractCrudService;
|
|
|
import com.bizmatics.mhfire.model.JcjAjxx;
|
|
|
+import com.bizmatics.mhfire.model.JcjZzclxx;
|
|
|
import com.bizmatics.mhfire.persistence.mapper.JcjAjxxMapper;
|
|
|
+import com.bizmatics.mhfire.persistence.mapper.po.FireStatisticsPO;
|
|
|
+import com.bizmatics.mhfire.persistence.mapper.vo.LocateInfo;
|
|
|
+import com.bizmatics.mhfire.service.FireStatisticsService;
|
|
|
import com.bizmatics.mhfire.service.JcjAjxxService;
|
|
|
-import com.bizmatics.common.mvc.base.AbstractCrudService;
|
|
|
+import com.bizmatics.mhfire.service.JcjZzclxxService;
|
|
|
+import com.bizmatics.mhfire.service.util.Arith;
|
|
|
+import com.bizmatics.mhfire.service.util.GouldUtil;
|
|
|
+import com.bizmatics.mhfire.service.vo.AlertMapVO;
|
|
|
+import com.bizmatics.mhfire.service.vo.AlertStatisticsVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 服务实现类
|
|
@@ -17,4 +40,184 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class JcjAjxxServiceImpl extends AbstractCrudService<JcjAjxxMapper, JcjAjxx> implements JcjAjxxService {
|
|
|
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FireStatisticsService fireStatisticsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private JcjZzclxxService jcjZzclxxService;
|
|
|
+
|
|
|
+
|
|
|
+ private static final String[] ALERT_TYPE = {"火灾","社会救助","抢险救援"};
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, List<AlertStatisticsVO>> getAlertStatisticsByHouse(Date startTime, Date endTime) {
|
|
|
+ QueryWrapper<JcjAjxx> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.select("HOUR(lasj) monthTime","COUNT(id) as aCount","ajlx as aType")
|
|
|
+ .between("lasj",startTime,endTime)
|
|
|
+ .groupBy("monthTime","ajlx");
|
|
|
+ Map<String, List<AlertStatisticsVO>> typeMap = enhanceList(this.listMaps(queryWrapper));
|
|
|
+ int distanceOfTwoDate = DateUtils.getDistanceOfTwoDateNew(startTime, endTime);
|
|
|
+ perfect(typeMap,24,distanceOfTwoDate,0);
|
|
|
+ return typeMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void perfect(Map<String, List<AlertStatisticsVO>> typeMap,Integer times,Integer subTime,Integer defaultTime){
|
|
|
+ for (String type:ALERT_TYPE) {
|
|
|
+ if (!typeMap.containsKey(type)){
|
|
|
+ typeMap.put(type,new ArrayList<>());
|
|
|
+ }
|
|
|
+ perfectDate(typeMap.get(type), times,subTime,defaultTime);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void perfectDate(List<AlertStatisticsVO> list,Integer times,Integer subTime,Integer defaultTime){
|
|
|
+ for (int i = defaultTime; i < times; i++) {
|
|
|
+ int finalI = i;
|
|
|
+ list.stream()
|
|
|
+ .filter(asv -> Integer.parseInt(asv.getMonth()) == finalI)
|
|
|
+ .findFirst()
|
|
|
+ .map(asv -> {
|
|
|
+ asv.setAvg(Arith.div(asv.getNumber(), subTime));
|
|
|
+ return asv;
|
|
|
+ })
|
|
|
+ .orElseGet(() -> {
|
|
|
+ AlertStatisticsVO asv = new AlertStatisticsVO();
|
|
|
+ asv.setMonth(Integer.toString(finalI));
|
|
|
+ asv.setNumber(0);
|
|
|
+ asv.setAvg(0.00);
|
|
|
+ list.add(asv);
|
|
|
+ return asv;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ list.sort(Comparator.comparingInt(x -> Integer.parseInt(x.getMonth())));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, List<AlertStatisticsVO>> enhanceList(List<Map<String,Object>> mapList){
|
|
|
+ List<AlertStatisticsVO> list = new ArrayList<>();
|
|
|
+ for (Map<String, Object> map:mapList) {
|
|
|
+ AlertStatisticsVO alertStatisticsVo = new AlertStatisticsVO();
|
|
|
+ alertStatisticsVo.setType(map.get("aType").toString());
|
|
|
+ alertStatisticsVo.setMonth(map.get("monthTime").toString());
|
|
|
+ alertStatisticsVo.setNumber(Integer.parseInt(map.get("aCount").toString()));
|
|
|
+ list.add(alertStatisticsVo);
|
|
|
+ }
|
|
|
+ return list.stream().collect(Collectors.groupingBy(AlertStatisticsVO::getType));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, List<AlertStatisticsVO>> getAlertStatisticsByMonth(Date startTime,Date endTime) {
|
|
|
+ QueryWrapper<JcjAjxx> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.select("month(lasj) monthTime","COUNT(id) as aCount","ajlx as aType")
|
|
|
+ .between("lasj",startTime,endTime)
|
|
|
+ .groupBy("monthTime","ajlx");
|
|
|
+ Map<String, List<AlertStatisticsVO>> typeMap = enhanceList(this.listMaps(queryWrapper));
|
|
|
+ int distanceOfTwoDate =Integer.parseInt(DateUtils.getYear(endTime)) - Integer.parseInt(DateUtils.getYear(startTime)) + 1;
|
|
|
+ perfect(typeMap,13,distanceOfTwoDate,1);
|
|
|
+ return typeMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonPage<JcjAjxx> page(Integer current, Integer size, Date startTime, Date endTime) {
|
|
|
+ IPage<JcjAjxx> page = new Page<>(current, size);
|
|
|
+ LambdaQueryWrapper<JcjAjxx> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ if (null != startTime && null != endTime){
|
|
|
+ queryWrapper.between(JcjAjxx::getDcsj,startTime,endTime);
|
|
|
+ }
|
|
|
+ page = this.page(page, queryWrapper);
|
|
|
+ return this.ToCommonPage(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonPage<AlertMapVO> pageMap(Integer current, Integer size, Date startTime, Date endTime) {
|
|
|
+
|
|
|
+ LambdaQueryWrapper<JcjAjxx> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.select(JcjAjxx::getId,JcjAjxx::getGisX,JcjAjxx::getGisY);
|
|
|
+ if (null != startTime && null != endTime){
|
|
|
+ queryWrapper.between(JcjAjxx::getDcsj,startTime,endTime);
|
|
|
+ }
|
|
|
+ CommonPage<AlertMapVO> commonPage;
|
|
|
+ if (null != current && size != null){
|
|
|
+ IPage<JcjAjxx> page = new Page<>(current,size);
|
|
|
+ page = this.page(page,queryWrapper);
|
|
|
+ commonPage = new CommonPage<>(BeanMapperUtils.mapList(page.getRecords(),JcjAjxx.class,AlertMapVO.class),page.getTotal(),page.getSize(),page.getCurrent());
|
|
|
+ }else {
|
|
|
+ List<JcjAjxx> list = this.list(queryWrapper);
|
|
|
+ commonPage = new CommonPage<>(BeanMapperUtils.mapList(list,JcjAjxx.class,AlertMapVO.class),list.size(),list.size(),1);
|
|
|
+ }
|
|
|
+ return commonPage;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JcjAjxx getOne(String id) {
|
|
|
+ JcjAjxx jcjAjxx = this.getById(id);
|
|
|
+ if (jcjAjxx.getAjlx().equals(ALERT_TYPE[0])){
|
|
|
+ Date startTime = DateUtils.addMonths(jcjAjxx.getLasj(), -30);
|
|
|
+ Date endTime = DateUtils.addMonths(jcjAjxx.getLasj(), 30);
|
|
|
+ List<LocateInfo> lonLat = GouldUtil.getLonLat(jcjAjxx.getAfdz());
|
|
|
+ LocateInfo locateInfo = lonLat.get(0);
|
|
|
+ //计算精度维度在一定范围内的数据和火灾关联
|
|
|
+ List<FireStatisticsPO> list = fireStatisticsService.distanceList(locateInfo.getLongitude(), locateInfo.getLatitude(), startTime, endTime);
|
|
|
+ if (CollectionUtils.isNotEmpty(list)){
|
|
|
+ FireStatisticsPO fireStatisticsPo = list.get(0);
|
|
|
+ jcjAjxx.setPropertyLoss(fireStatisticsPo.getPropertyLoss());
|
|
|
+ jcjAjxx.setDeathToll(fireStatisticsPo.getDeathToll());
|
|
|
+ jcjAjxx.setNonFatal(fireStatisticsPo.getNonFatal());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //查询车辆和人员信息
|
|
|
+ List<JcjZzclxx> carLit = jcjZzclxxService.getByAjId(jcjAjxx.getId());
|
|
|
+ jcjAjxx.setCarList(carLit);
|
|
|
+ return jcjAjxx;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AlertStatisticsVO> getAlertStatistics(Date startTime, Date endTime) {
|
|
|
+
|
|
|
+ //获取同比
|
|
|
+ Date upStartTime = DateUtils.addYears(startTime, -1);
|
|
|
+ Date upEndTime = DateUtils.addYears(endTime, -1);
|
|
|
+ List<AlertStatisticsVO> list = new ArrayList<>();
|
|
|
+ list.add(getAsV(startTime, endTime, ALERT_TYPE[0]));
|
|
|
+ list.add(getAsV(startTime, endTime, ALERT_TYPE[1]));
|
|
|
+ list.add(getAsV(startTime, endTime, ALERT_TYPE[2]));
|
|
|
+ list.forEach(alertStatisticsVO -> {
|
|
|
+ AlertStatisticsVO upAsv = getAsV(upStartTime, upEndTime, alertStatisticsVO.getType());
|
|
|
+ Integer number = alertStatisticsVO.getNumber();
|
|
|
+ Integer upNumber = upAsv.getNumber();
|
|
|
+ if (number.equals(upNumber)) {
|
|
|
+ alertStatisticsVO.setSameStatus(0);
|
|
|
+ } else if (number > upNumber) {
|
|
|
+ alertStatisticsVO.setSameStatus(1);
|
|
|
+ } else {
|
|
|
+ alertStatisticsVO.setSameStatus(2);
|
|
|
+ }
|
|
|
+ if (0 != upNumber) {
|
|
|
+ double radio = Arith.div(Arith.sub(number, upNumber), upNumber);
|
|
|
+ alertStatisticsVO.setRadio(Math.abs(radio));
|
|
|
+ } else {
|
|
|
+ if (number != 0){
|
|
|
+ alertStatisticsVO.setRadio(1.00);
|
|
|
+ }else {
|
|
|
+ alertStatisticsVO.setRadio(0.00);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ public AlertStatisticsVO getAsV(Date startTime, Date endTime, String type){
|
|
|
+ AlertStatisticsVO alertStatisticsVo = new AlertStatisticsVO();
|
|
|
+ LambdaQueryWrapper<JcjAjxx> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(StringUtils.isNotBlank(type),JcjAjxx::getAjlx,type);
|
|
|
+ if (null != startTime && null != endTime){
|
|
|
+ queryWrapper.between(JcjAjxx::getDcsj,startTime,endTime);
|
|
|
+ }
|
|
|
+ alertStatisticsVo.setType(type);
|
|
|
+ alertStatisticsVo.setNumber(this.count(queryWrapper));
|
|
|
+ return alertStatisticsVo;
|
|
|
+ }
|
|
|
}
|