|
@@ -1,211 +0,0 @@
|
|
|
-package com.bizmatics.mhfire.service.impl;
|
|
|
-
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-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.Alert;
|
|
|
-import com.bizmatics.mhfire.model.CarPerson;
|
|
|
-import com.bizmatics.mhfire.persistence.mapper.AlertMapper;
|
|
|
-import com.bizmatics.mhfire.persistence.mapper.po.FireStatisticsPO;
|
|
|
-import com.bizmatics.mhfire.persistence.mapper.vo.LocateInfo;
|
|
|
-import com.bizmatics.mhfire.service.AlertService;
|
|
|
-import com.bizmatics.mhfire.service.CarPersonService;
|
|
|
-import com.bizmatics.mhfire.service.FireStatisticsService;
|
|
|
-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;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author yq
|
|
|
- * @date 2021/5/28 14:53
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class AlertServiceImpl extends AbstractCrudService<AlertMapper, Alert> implements AlertService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private FireStatisticsService fireStatisticsService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CarPersonService carPersonService;
|
|
|
-
|
|
|
-
|
|
|
- private static final String[] ALERT_TYPE = {"火灾","社会救助","抢险救援"};
|
|
|
-
|
|
|
- @Override
|
|
|
- public Map<String, List<AlertStatisticsVO>> getAlertStatisticsByHouse(Date startTime,Date endTime) {
|
|
|
- Map<String, List<AlertStatisticsVO>> typeMap = enhanceList(baseMapper.getCountByHorse(startTime, endTime));
|
|
|
- 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()));
|
|
|
- alertStatisticsVo.setType(map.get("aType").toString());
|
|
|
- list.add(alertStatisticsVo);
|
|
|
- }
|
|
|
- return list.stream().collect(Collectors.groupingBy(AlertStatisticsVO::getType));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public Map<String, List<AlertStatisticsVO>> getAlertStatisticsByMonth(Date startTime,Date endTime) {
|
|
|
- Map<String, List<AlertStatisticsVO>> typeMap = enhanceList(baseMapper.getCountByMonth(startTime, endTime));
|
|
|
- int distanceOfTwoDate =Integer.parseInt(DateUtils.getYear(endTime)) - Integer.parseInt(DateUtils.getYear(startTime)) + 1;
|
|
|
- perfect(typeMap,13,distanceOfTwoDate,1);
|
|
|
- return typeMap;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public CommonPage<Alert> page(Integer current, Integer size, Date startTime, Date endTime) {
|
|
|
- IPage<Alert> page = new Page<>(current, size);
|
|
|
- LambdaQueryWrapper<Alert> queryWrapper = Wrappers.lambdaQuery();
|
|
|
- if (null != startTime && null != endTime){
|
|
|
- queryWrapper.between(Alert::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<Alert> queryWrapper = Wrappers.lambdaQuery();
|
|
|
- queryWrapper.select(Alert::getId,Alert::getGisX,Alert::getGisY);
|
|
|
- if (null != startTime && null != endTime){
|
|
|
- queryWrapper.between(Alert::getDcsj,startTime,endTime);
|
|
|
- }
|
|
|
- CommonPage<AlertMapVO> commonPage;
|
|
|
- if (null != current && size != null){
|
|
|
- IPage<Alert> page = new Page<>(current,size);
|
|
|
- page = this.page(page,queryWrapper);
|
|
|
- commonPage = new CommonPage<>(BeanMapperUtils.mapList(page.getRecords(),Alert.class,AlertMapVO.class),page.getTotal(),page.getSize(),page.getCurrent());
|
|
|
- }else {
|
|
|
- List<Alert> list = this.list(queryWrapper);
|
|
|
- commonPage = new CommonPage<>(BeanMapperUtils.mapList(list,Alert.class,AlertMapVO.class),list.size(),list.size(),1);
|
|
|
- }
|
|
|
- return commonPage;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public Alert getOne(String id) {
|
|
|
- Alert alert = this.getById(id);
|
|
|
- if (alert.getAjlx().equals(ALERT_TYPE[0])){
|
|
|
- Date startTime = DateUtils.addMonths(alert.getLasj(), -30);
|
|
|
- Date endTime = DateUtils.addMonths(alert.getLasj(), 30);
|
|
|
- List<LocateInfo> lonLat = GouldUtil.getLonLat(alert.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);
|
|
|
- alert.setPropertyLoss(fireStatisticsPo.getPropertyLoss());
|
|
|
- alert.setDeathToll(fireStatisticsPo.getDeathToll());
|
|
|
- alert.setNonFatal(fireStatisticsPo.getNonFatal());
|
|
|
- }
|
|
|
- }
|
|
|
- //查询车辆和人员信息
|
|
|
- List<CarPerson> carLit = carPersonService.getByAjId(alert.getId());
|
|
|
- alert.setCarList(carLit);
|
|
|
- return alert;
|
|
|
- }
|
|
|
-
|
|
|
- @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<Alert> queryWrapper = Wrappers.lambdaQuery();
|
|
|
- queryWrapper.eq(StringUtils.isNotBlank(type),Alert::getAjlx,type);
|
|
|
- if (null != startTime && null != endTime){
|
|
|
- queryWrapper.between(Alert::getDcsj,startTime,endTime);
|
|
|
- }
|
|
|
- alertStatisticsVo.setType(type);
|
|
|
- alertStatisticsVo.setNumber(this.count(queryWrapper));
|
|
|
- return alertStatisticsVo;
|
|
|
- }
|
|
|
-
|
|
|
-}
|