Ver código fonte

1、新增手动上报应急事件;2、新增按月统计应急事件;

develop
wanjing 9 meses atrás
pai
commit
f748a45733
10 arquivos alterados com 479 adições e 0 exclusões
  1. +1
    -0
      tuoheng-service/tuoheng-admin/sql/sql_change_v1.3.7.sql
  2. +17
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/AccidentController.java
  3. +3
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/conver/AccidentConverMapper.java
  4. +48
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/request/accident/AddAccidentRequest.java
  5. +35
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/request/accident/QuestionTypeStatisticsVo.java
  6. +29
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/accident/AccidentServiceImpl.java
  7. +16
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/accident/IAccidentService.java
  8. +93
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/accident/add/AddAccidentService.java
  9. +204
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/accident/statistics/StatisticsByMonthService.java
  10. +33
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/vo/accident/AccidentStatisticsVo.java

+ 1
- 0
tuoheng-service/tuoheng-admin/sql/sql_change_v1.3.7.sql Ver arquivo

@@ -5,5 +5,6 @@ use tuoheng_freeway;


-- 事件表
alter table tuoheng_freeway.th_accident add name varchar(20) default '' not null comment '事件名称' after dept_id;
alter table tuoheng_freeway.th_accident add report_type tinyint(1) default 1 not null comment '上报类型:1:自动上报(默认);2:手动上报' after dept_id;


+ 17
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/AccidentController.java Ver arquivo

@@ -2,6 +2,7 @@ package com.tuoheng.admin.controller;

import com.tuoheng.admin.query.AccidentQuery;
import com.tuoheng.admin.request.accident.*;
import com.tuoheng.admin.request.dept.AddDeptRequest;
import com.tuoheng.admin.service.accident.IAccidentService;
import com.tuoheng.common.core.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
@@ -139,4 +140,20 @@ public class AccidentController {
public JsonResult ignore(@PathVariable("id") String id){
return accidentService.ignore(id);
}

/**
* 新增应急事件
*/
@PostMapping("/add")
public JsonResult add(@RequestBody AddAccidentRequest request) {
return accidentService.insert(request);
}

/**
* 统计月份数据
*/
@GetMapping("/statistics/month")
public JsonResult statisticsByMonth() {
return accidentService.statisticsByMonth();
}
}

+ 3
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/conver/AccidentConverMapper.java Ver arquivo

@@ -2,6 +2,7 @@ package com.tuoheng.admin.conver;

import com.tuoheng.admin.entity.Accident;
import com.tuoheng.admin.entity.Dept;
import com.tuoheng.admin.request.accident.AddAccidentRequest;
import com.tuoheng.admin.vo.accident.AccidentVo;
import com.tuoheng.admin.vo.dept.DeptInfoVo;
import com.tuoheng.admin.vo.dept.DeptTreeVo;
@@ -23,4 +24,6 @@ public interface AccidentConverMapper {
*/
List<AccidentVo> accidentListToAccidentVoList(List<Accident> accidentList);

Accident addAccidentRequestToAccident(AddAccidentRequest request);

}

+ 48
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/request/accident/AddAccidentRequest.java Ver arquivo

@@ -0,0 +1,48 @@
package com.tuoheng.admin.request.accident;

import lombok.Data;

/**
*
* @author wanjing
* @team tuoheng
* @date 2024-01-19
*/
@Data
public class AddAccidentRequest {

/**
* 经度
*/
private String name;

/**
* 经度
*/
private String longitude;

/**
* 纬度
*/
private String latitude;

/**
* 公路id
*/
private String roadId;

/**
* 公路编码
*/
private String roadCode;

/**
* 路段ID
*/
private String sectionId;

/**
* 图片
*/
private String image;
}

+ 35
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/request/accident/QuestionTypeStatisticsVo.java Ver arquivo

@@ -0,0 +1,35 @@
package com.tuoheng.admin.request.accident;

import lombok.Data;

/**
* 事件月份统计 返回实体类
*
* @author wanjing
* @team tuoheng
* @date 2024-01-19
*/
@Data
public class QuestionTypeStatisticsVo {

/**
* 问题Id
*/
private String questionId;

/**
* 问题编码
*/
private String questionCode;

/**
* 问题名称
*/
private String questionName;

/**
* 问题数量
*/
private Integer count;

}

+ 29
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/accident/AccidentServiceImpl.java Ver arquivo

@@ -4,10 +4,12 @@ import com.tuoheng.admin.entity.Accident;
import com.tuoheng.admin.mapper.AccidentMapper;
import com.tuoheng.admin.query.AccidentQuery;
import com.tuoheng.admin.request.accident.*;
import com.tuoheng.admin.service.accident.add.AddAccidentService;
import com.tuoheng.admin.service.accident.ignore.AccidentIgnoreService;
import com.tuoheng.admin.service.accident.query.*;
import com.tuoheng.admin.service.accident.reoprt.ReportAccidentService;
import com.tuoheng.admin.service.accident.reoprt.ReportNoAccidentService;
import com.tuoheng.admin.service.accident.statistics.StatisticsByMonthService;
import com.tuoheng.admin.service.accident.verify.AccidentVerifyCompletedService;
import com.tuoheng.admin.service.accident.verify.AccidentVerifyService;
import com.tuoheng.common.core.common.BaseServiceImpl;
@@ -24,6 +26,9 @@ import org.springframework.stereotype.Service;
@Slf4j
public class AccidentServiceImpl extends BaseServiceImpl<AccidentMapper, Accident> implements IAccidentService {

@Autowired
private AddAccidentService addAccidentService;

@Autowired
private QueryAccidentCardPageListService queryAccidentCardPageListService;

@@ -63,6 +68,20 @@ public class AccidentServiceImpl extends BaseServiceImpl<AccidentMapper, Acciden
@Autowired
private AccidentIgnoreService accidentIgnoreService;

@Autowired
private StatisticsByMonthService statisticsByMonthService;

/**
* 新增应急事件
*
* @param request 应急事件对象
* @return 结果
*/
@Override
public JsonResult insert(AddAccidentRequest request) {
return addAccidentService.add(request);
}

@Override
public JsonResult getAccidentCardPageList(QueryAccidentCardPageListRequest request) {
return queryAccidentCardPageListService.getPageList(request);
@@ -157,4 +176,14 @@ public class AccidentServiceImpl extends BaseServiceImpl<AccidentMapper, Acciden
public JsonResult ignore(String id) {
return accidentIgnoreService.ignore(id);
}

/**
* 统计月份数据
*
* @return 结果
*/
@Override
public JsonResult statisticsByMonth() {
return statisticsByMonthService.statistics();
}
}

+ 16
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/accident/IAccidentService.java Ver arquivo

@@ -3,6 +3,7 @@ package com.tuoheng.admin.service.accident;
import com.tuoheng.admin.entity.Accident;
import com.tuoheng.admin.query.AccidentQuery;
import com.tuoheng.admin.request.accident.*;
import com.tuoheng.admin.request.dept.AddDeptRequest;
import com.tuoheng.common.core.common.IBaseService;
import com.tuoheng.common.core.utils.JsonResult;

@@ -12,6 +13,14 @@ import com.tuoheng.common.core.utils.JsonResult;
*/
public interface IAccidentService extends IBaseService<Accident> {

/**
* 新增应急事件
*
* @param request 应急事件对象
* @return 结果
*/
JsonResult insert(AddAccidentRequest request);

/**
* 查询事故列表(分页)
*
@@ -115,4 +124,11 @@ public interface IAccidentService extends IBaseService<Accident> {
*/
JsonResult ignore(String id);

/**
* 统计月份数据
*
* @return 结果
*/
JsonResult statisticsByMonth();

}

+ 93
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/accident/add/AddAccidentService.java Ver arquivo

@@ -0,0 +1,93 @@
package com.tuoheng.admin.service.accident.add;

import com.tuoheng.admin.conver.AccidentConverMapper;
import com.tuoheng.admin.entity.Accident;
import com.tuoheng.admin.entity.User;
import com.tuoheng.admin.enums.AccidentStatusEnum;
import com.tuoheng.admin.enums.accident.AccidentReportTypeEnum;
import com.tuoheng.admin.mapper.AccidentMapper;
import com.tuoheng.admin.request.accident.AddAccidentRequest;
import com.tuoheng.admin.utils.CurrentUserUtil;
import com.tuoheng.common.core.exception.ServiceException;
import com.tuoheng.common.core.utils.DateUtils;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* 添加应急事故业务层处理
*
* @author wanjing
* @team tuoheng
* @date 2024-01-19
*/
@Slf4j
@Service
public class AddAccidentService {

@Autowired
private AccidentMapper accidentMapper;

public JsonResult add(AddAccidentRequest request) {
// log.info("进入添加应急事件业务, id={}", id);
User user = CurrentUserUtil.getUserInfo();
String userId = user.getId();
JsonResult result = this.check(request);
if (0 != result.getCode()) {
log.info("添加应急事件:校验失败:{}", result.getMsg());
return result;
}
Accident accident = this.buildAccident(userId, request);
accident.setTenantId(user.getTenantId());
accident.setDeptId(user.getDeptId());
Integer count = accidentMapper.insert(accident);
if (count <= 0) {
log.info("事故忽略,修改预警信息失败");
}

return JsonResult.success();
}

/**
* 检查参数
*
* @param request
* @return
*/
private JsonResult check(AddAccidentRequest request) {
if (StringUtils.isEmpty(request.getName())) {
throw new ServiceException("应急事件名称为空");
}
if (StringUtils.isEmpty(request.getLatitude()) || StringUtils.isNull(request.getLongitude())) {
throw new ServiceException("应急事件位置为空");
}
if (StringUtils.isEmpty(request.getRoadId())) {
throw new ServiceException("应急事件公路为空");
}
if (StringUtils.isEmpty(request.getSectionId())) {
throw new ServiceException("应急事件路段为空");
}
if (StringUtils.isEmpty(request.getImage())) {
throw new ServiceException("应急事件图片为空");
}
return JsonResult.success();
}

/**
* 修改预警记录信息
*
* @param userId
* @param userId
*/
private Accident buildAccident(String userId, AddAccidentRequest request) {
Accident accident = AccidentConverMapper.INSTANCE.addAccidentRequestToAccident(request);
accident.setReportType(AccidentReportTypeEnum.MANUAL.getCode());
accident.setStatus(AccidentStatusEnum.UNTREATED.getCode());
accident.setCreateUser(userId);
accident.setCreateTime(DateUtils.now());
accident.setIgnoreTime(DateUtils.now());
return accident;
}
}

+ 204
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/accident/statistics/StatisticsByMonthService.java Ver arquivo

@@ -0,0 +1,204 @@
package com.tuoheng.admin.service.accident.statistics;

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.tuoheng.admin.entity.Accident;
import com.tuoheng.admin.entity.Dept;
import com.tuoheng.admin.entity.QuestionType;
import com.tuoheng.admin.entity.User;
import com.tuoheng.admin.enums.DataPermissionEnum;
import com.tuoheng.admin.enums.FlagEnum;
import com.tuoheng.admin.enums.MarkEnum;
import com.tuoheng.admin.enums.accident.AccidentReportTypeEnum;
import com.tuoheng.admin.mapper.AccidentMapper;
import com.tuoheng.admin.mapper.DeptMapper;
import com.tuoheng.admin.mapper.QuestionTypeMapper;
import com.tuoheng.admin.mapper.UserMapper;
import com.tuoheng.admin.request.accident.QuestionTypeStatisticsVo;
import com.tuoheng.admin.utils.CurrentUserUtil;
import com.tuoheng.admin.vo.accident.AccidentPromptlyLookVo;
import com.tuoheng.admin.vo.accident.AccidentStatisticsVo;
import com.tuoheng.admin.vo.accident.QueryAccidentPageVO;
import com.tuoheng.common.core.utils.DateUtils;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
* 查询事故卡片分页列表业务层处理
*
* @author wanjing
* @team tuoheng
* @date 2024-01-20
*/
@Slf4j
@Service
public class StatisticsByMonthService {

@Autowired
private DeptMapper deptMapper;

@Autowired
private QuestionTypeMapper questionTypeMapper;

@Autowired
private AccidentMapper accidentMapper;

public JsonResult statistics() {
User user = CurrentUserUtil.getUserInfo();
String tenantId = user.getTenantId();
List<String> deptIdList = this.getDeptIdList(user, user.getDeptId());
List<QuestionType> questionTypeList = questionTypeMapper.selectList(new LambdaQueryWrapper<QuestionType>()
.eq(QuestionType::getMark, MarkEnum.VALID.getCode()));
List<SearchTime> searchTimeList = this.getSearchTimeList();
List<AccidentStatisticsVo> accidentStatisticsVoList = new ArrayList<>();
AccidentStatisticsVo accidentStatisticsVo;
List<QuestionTypeStatisticsVo> questionTypeStatisticsVoList = new ArrayList<>();
QuestionTypeStatisticsVo questionTypeStatisticsVo;
for (SearchTime searchTime : searchTimeList) {
List<Accident> accidentList = accidentMapper.selectList(Wrappers.<Accident>lambdaQuery()
.eq(Accident::getTenantId, tenantId)
.eq(Accident::getReportType, AccidentReportTypeEnum.AUTO.getCode())
.in(CollectionUtils.isNotEmpty(deptIdList), Accident::getDeptId, deptIdList)
.between(Accident::getCreateTime, searchTime.getBeginTime(), searchTime.getEndTime())
.eq(Accident::getMark, MarkEnum.VALID.getCode())
.orderByDesc(Accident::getCreateTime));
Integer questionCount = 0;
for (QuestionType questionType : questionTypeList) {
questionTypeStatisticsVo = new QuestionTypeStatisticsVo();
questionTypeStatisticsVo.setQuestionId(questionType.getId());
questionTypeStatisticsVo.setQuestionCode(questionType.getCode());
questionTypeStatisticsVo.setQuestionName(questionType.getContent());
for (Accident accident : accidentList) {
if (questionType.getCode().equals(accident.getQuestionCode())) {
questionCount++;
}
}
questionTypeStatisticsVo.setCount(questionCount);
questionTypeStatisticsVoList.add(questionTypeStatisticsVo);
}
accidentStatisticsVo = new AccidentStatisticsVo();
accidentStatisticsVo.setYear(searchTime.getYear());
accidentStatisticsVo.setMonth(searchTime.getMonth());
accidentStatisticsVo.setQuestionTypeStatisticsList(questionTypeStatisticsVoList);
accidentStatisticsVoList.add(accidentStatisticsVo);
}
return JsonResult.success(accidentStatisticsVoList);
}

/**
* 根据用户自己的数据权限,查询对应部门的数据
*
* @param user
* @return
*/
private List<String> getDeptIdList(User user, String deptId) {
List<String> deptIdList = new ArrayList<>();
if (StringUtils.isNotEmpty(deptId)) {
deptIdList.add(deptId);
return deptIdList;
}
if (DataPermissionEnum.ALL.getCode() == user.getDataPermission()) {
return null;
} else if (DataPermissionEnum.DEPT_AND_SUB_DEPT.getCode() == user.getDataPermission()) {
deptIdList = deptMapper.selectAllChildListById(user.getDeptId());
} else if (DataPermissionEnum.DEPT.getCode() == user.getDataPermission()) {
deptIdList.add(user.getDeptId());
}
return deptIdList;
}

private List<SearchTime> getSearchTimeList() {
List<SearchTime> searchTimeList = new ArrayList<>();
Integer currentYear = DateUtils.getYear();
Integer currentMonth = DateUtils.getMonth();
SearchTime searchTime1 = new SearchTime();
SearchTime searchTime2 = new SearchTime();
SearchTime searchTime3 = new SearchTime();
Integer year1;
Integer year2;
Integer year3;
Integer month1;
Integer month2;
Integer month3;
Integer day = 1;
if (1 == currentMonth) {
year1 = currentYear - 1;
year2 = currentYear - 1;
year3 = currentYear;
month1 = 11;
month2 = 12;
month3 = currentMonth;
} else if (2 == currentMonth) {
year1 = currentYear - 1;
year2 = currentYear;
year3 = currentYear;
month1 = 12;
month2 = currentMonth - 1;
month3 = currentMonth;
} else {
year1 = currentYear;
year2 = currentYear;
year3 = currentYear;
month1 = currentMonth - 2;
month2 = currentMonth - 1;
month3 = currentMonth;
}

LocalDate localDate1 = LocalDate.of(year1, month1, day);
LocalDate firstDayOfMonth1 = localDate1.with(TemporalAdjusters.firstDayOfMonth());
LocalDate lastDayOfMonth1 = localDate1.with(TemporalAdjusters.lastDayOfMonth());
searchTime1.setYear(year1);
searchTime1.setMonth(month1);
searchTime1.setBeginTime(firstDayOfMonth1 + " 00:00:00");
searchTime1.setEndTime(lastDayOfMonth1 + " 23:59:59");

LocalDate localDate2 = LocalDate.of(year2, month2, day);
LocalDate firstDayOfMonth2 = localDate2.with(TemporalAdjusters.firstDayOfMonth());
LocalDate lastDayOfMonth2 = localDate2.with(TemporalAdjusters.lastDayOfMonth());
searchTime2.setYear(year2);
searchTime2.setMonth(month2);
searchTime2.setBeginTime(firstDayOfMonth2 + " 00:00:00");
searchTime2.setEndTime(lastDayOfMonth2 + " 23:59:59");

LocalDate localDate3 = LocalDate.of(year3, month3, day);
LocalDate firstDayOfMonth3 = localDate3.with(TemporalAdjusters.firstDayOfMonth());
LocalDate lastDayOfMonth3 = localDate3.with(TemporalAdjusters.lastDayOfMonth());
searchTime3.setYear(year3);
searchTime3.setMonth(month3);
searchTime3.setBeginTime(firstDayOfMonth3 + " 00:00:00");
searchTime3.setEndTime(lastDayOfMonth3 + " 23:59:59");

searchTimeList.add(searchTime1);
searchTimeList.add(searchTime2);
searchTimeList.add(searchTime3);
return searchTimeList;
}
}

@Data
class SearchTime {

private Integer year;

private Integer month;

private String beginTime;

private String endTime;

}

+ 33
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/vo/accident/AccidentStatisticsVo.java Ver arquivo

@@ -0,0 +1,33 @@
package com.tuoheng.admin.vo.accident;

import com.tuoheng.admin.request.accident.QuestionTypeStatisticsVo;
import lombok.Data;

import java.util.List;

/**
* 事件月份统计 返回实体类
*
* @author wanjing
* @team tuoheng
* @date 2024-01-19
*/
@Data
public class AccidentStatisticsVo {

/**
* 年
*/
private Integer year;

/**
* 月份
*/
private Integer month;

/**
* 问题类型统计
*/
private List<QuestionTypeStatisticsVo> questionTypeStatisticsList;

}

Carregando…
Cancelar
Salvar