|
@@ -1,12 +1,18 @@
|
|
|
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.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.bizmatics.common.core.bean.CommonPage;
|
|
|
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.persistence.mapper.AlertMapper;
|
|
|
import com.bizmatics.mhfire.service.AlertService;
|
|
|
+import com.bizmatics.mhfire.service.util.Arith;
|
|
|
import com.bizmatics.mhfire.service.vo.AlertStatisticsVO;
|
|
|
-import com.bizmatics.mhfire.service.vo.AlertVO;
|
|
|
-import com.bizmatics.mhfire.service.vo.FireSiteVO;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
@@ -19,52 +25,72 @@ import java.util.Map;
|
|
|
* @date 2021/5/28 14:53
|
|
|
*/
|
|
|
@Service
|
|
|
-public class AlertServiceImpl implements AlertService {
|
|
|
+public class AlertServiceImpl extends AbstractCrudService<AlertMapper, Alert> implements AlertService {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public List<AlertStatisticsVO> getAlertStatisticsByHouse() {
|
|
|
- List<AlertStatisticsVO> list = new ArrayList<>();
|
|
|
Date date = new Date();
|
|
|
- for (int i = 0; i < 24; i++) {
|
|
|
- date = DateUtils.setHours(date, i);
|
|
|
- date.setMinutes(0);
|
|
|
- date.setSeconds(0);
|
|
|
- date.setMinutes(59);
|
|
|
- date.setSeconds(59);
|
|
|
+ Date startTime = DateUtils.getDayStartTime(date);
|
|
|
+ return enhanceList(baseMapper.getCountByHorse(startTime, date));
|
|
|
+ }
|
|
|
+
|
|
|
+ public 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);
|
|
|
}
|
|
|
- //TODO 没有找见对应数据,数据来源其他平台
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public List<AlertStatisticsVO> getAlertStatisticsByMonth() {
|
|
|
- List<AlertStatisticsVO> list = new ArrayList<>();
|
|
|
Date date = new Date();
|
|
|
- for (int i = 0; i < 12; i++) {
|
|
|
- date = DateUtils.setDays(date,1);
|
|
|
- DateUtils.setMonths(date,i);
|
|
|
- Date firstDayOfMonth = DateUtils.getFirstDayOfMonth(date);
|
|
|
- Date lastDayOfMonth = DateUtils.getLastDayOfMonth(date);
|
|
|
- }
|
|
|
- //TODO 没有找见对应数据,数据来源其他平台
|
|
|
- return list;
|
|
|
+ Date startTime = DateUtils.getDayStartTime(date);
|
|
|
+ return enhanceList(baseMapper.getCountByMonth(startTime, date));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public CommonPage<AlertVO> page(Integer current, Integer size, Date startTime, Date endTime) {
|
|
|
- Page<Map<String, Object>> page = new Page<>(current, size);
|
|
|
-
|
|
|
- List<AlertVO> list = new ArrayList<>();
|
|
|
- //TODO 站点信息调用其他平台接口
|
|
|
- return new CommonPage<>(list, page.getTotal(), page.getSize(), page.getCurrent());
|
|
|
+ public CommonPage<Alert> page(Integer current, Integer size, Date startTime, Date endTime) {
|
|
|
+ IPage<Alert> page = new Page<>(current, size);
|
|
|
+ LambdaQueryWrapper<Alert> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.between(Alert::getDcsj,startTime,endTime);
|
|
|
+ page = this.page(page, queryWrapper);
|
|
|
+ return this.ToCommonPage(page);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<AlertStatisticsVO> getAlertStatistics(Date startTime, Date endTime) {
|
|
|
List<AlertStatisticsVO> list = new ArrayList<>();
|
|
|
- //TODO 数据来源于其他平台
|
|
|
+ list.add(getAsV(startTime, endTime, "火灾"));
|
|
|
+ list.add(getAsV(startTime, endTime, "社会救援"));
|
|
|
+ list.add(getAsV(startTime, endTime, "抢险救援"));
|
|
|
+ int sum = list.stream().mapToInt(AlertStatisticsVO::getNumber).sum();
|
|
|
+ list.forEach(alertStatisticsVO -> {
|
|
|
+ if (0 == sum){
|
|
|
+ alertStatisticsVO.setRadio(0.00);
|
|
|
+ }else {
|
|
|
+ alertStatisticsVO.setRadio(Arith.div(alertStatisticsVO.getNumber(), sum));
|
|
|
+ }
|
|
|
+ });
|
|
|
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;
|
|
|
+ }
|
|
|
+
|
|
|
}
|