@@ -61,12 +61,12 @@ public class AccidentController { | |||
} | |||
/** | |||
* 查询事故卡片分页列表 | |||
* 查询事件分页列表 | |||
*/ | |||
@GetMapping("/card/page/list") | |||
public JsonResult getAccidentCardPageList(QueryAccidentCardPageListRequest request) { | |||
@GetMapping("/page/list") | |||
public JsonResult getAccidentPageList(QueryAccidentPageListRequest request) { | |||
// log.info("进入查询事故分页列表接口"); | |||
return accidentService.getAccidentCardPageList(request); | |||
return accidentService.getAccidentPageList(request); | |||
} | |||
/** |
@@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import com.tuoheng.admin.entity.Accident; | |||
import com.tuoheng.admin.request.accident.QueryAccidentRealtimeInfoListRequest; | |||
import com.tuoheng.admin.request.accident.QueryAccidentCardPageListRequest; | |||
import com.tuoheng.admin.request.accident.QueryAccidentPageListRequest; | |||
import com.tuoheng.admin.request.accident.QueryHistoryPageListRequest; | |||
import org.apache.ibatis.annotations.Param; | |||
@@ -23,7 +23,7 @@ public interface AccidentMapper extends BaseMapper<Accident> { | |||
* @param request 事故查询实体 | |||
* @return 事故集合 | |||
*/ | |||
Page<Accident> selectPageList(@Param("page") IPage page, @Param("request") QueryAccidentCardPageListRequest request); | |||
Page<Accident> selectPageList(@Param("page") IPage page, @Param("request") QueryAccidentPageListRequest request); | |||
/** | |||
* 查询实时事件信息列表 |
@@ -16,7 +16,7 @@ import java.util.List; | |||
* @date 2022-11-17 | |||
*/ | |||
@Data | |||
public class QueryAccidentCardPageListRequest extends BaseQuery { | |||
public class QueryAccidentPageListRequest extends BaseQuery { | |||
/** | |||
* 公路名称 |
@@ -31,9 +31,6 @@ public class AccidentServiceImpl extends BaseServiceImpl<AccidentMapper, Acciden | |||
@Autowired | |||
private AddAccidentService addAccidentService; | |||
@Autowired | |||
private QueryAccidentCardPageListService queryAccidentCardPageListService; | |||
@Autowired | |||
private QueryAccidentRealtimeInfoListService queryAccidentRealtimeInfoListService; | |||
@@ -98,12 +95,10 @@ public class AccidentServiceImpl extends BaseServiceImpl<AccidentMapper, Acciden | |||
} | |||
@Override | |||
public JsonResult getAccidentCardPageList(QueryAccidentCardPageListRequest request) { | |||
return queryAccidentCardPageListService.getPageList(request); | |||
public JsonResult getAccidentPageList(QueryAccidentPageListRequest request) { | |||
return queryAccidentPageListService.getPageList(request); | |||
} | |||
@Override | |||
public JsonResult getAccidentInfo(String id) { | |||
return queryAccidentByIdService.getInfoById(id); |
@@ -44,7 +44,7 @@ public interface IAccidentService extends IBaseService<Accident> { | |||
* @param request 事故分页列表查询实体 | |||
* @return 巡检任务集合 | |||
*/ | |||
JsonResult getAccidentCardPageList(QueryAccidentCardPageListRequest request); | |||
JsonResult getAccidentPageList(QueryAccidentPageListRequest request); | |||
/** | |||
* 查询事故信息 |
@@ -1,218 +0,0 @@ | |||
package com.tuoheng.admin.service.accident.query; | |||
import cn.hutool.core.util.ObjectUtil; | |||
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.conver.AccidentConverMapper; | |||
import com.tuoheng.admin.entity.Accident; | |||
import com.tuoheng.admin.entity.Dept; | |||
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.mapper.AccidentMapper; | |||
import com.tuoheng.admin.mapper.DeptMapper; | |||
import com.tuoheng.admin.mapper.UserMapper; | |||
import com.tuoheng.admin.query.AccidentQuery; | |||
import com.tuoheng.admin.request.accident.QueryAccidentCardPageListRequest; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.admin.vo.accident.AccidentVo; | |||
import com.tuoheng.admin.vo.accident.QueryAccidentPageVO; | |||
import com.tuoheng.common.core.enums.ServiceExceptionEnum; | |||
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.BeanUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.*; | |||
import java.util.stream.Collectors; | |||
/** | |||
* 查询事故卡片分页列表业务层处理 | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2023-03-03 | |||
*/ | |||
@Slf4j | |||
@Service | |||
public class QueryAccidentCardPageListService { | |||
@Autowired | |||
private DeptMapper deptMapper; | |||
@Autowired | |||
private UserMapper userMapper; | |||
@Autowired | |||
private AccidentMapper accidentMapper; | |||
public JsonResult getPageList(QueryAccidentCardPageListRequest request) { | |||
// log.info("进入查询事件分页列表业务"); | |||
String tenantId = CurrentUserUtil.getTenantId(); | |||
request.setTenantId(tenantId); | |||
JsonResult result = this.check(tenantId, request); | |||
if (0 != result.getCode()) { | |||
log.info("进入查询事故卡片分页列表业务:校验失败:{}", result.getMsg()); | |||
return result; | |||
} | |||
// 设置分页参数 | |||
IPage<Accident> page = new Page<>(request.getPage(), request.getLimit()); | |||
IPage<Accident> pageData = accidentMapper.selectPageList(page, request); | |||
// 构造返回结果对象 | |||
List<AccidentVo> accidentVoList = this.buildAccidentVoList(pageData.getRecords()); | |||
// 重写返回结果对象 | |||
IPage<AccidentVo> accidentVoPageData = new Page<>(); | |||
accidentVoPageData.setPages(pageData.getPages()); | |||
accidentVoPageData.setCurrent(pageData.getCurrent()); | |||
accidentVoPageData.setSize(pageData.getSize()); | |||
accidentVoPageData.setTotal(pageData.getTotal()); | |||
accidentVoPageData.setRecords(accidentVoList); | |||
return JsonResult.success(accidentVoPageData); | |||
} | |||
/** | |||
* 检查参数 | |||
* | |||
* @param tenantId | |||
* @param request | |||
* @return | |||
*/ | |||
private JsonResult check(String tenantId, QueryAccidentCardPageListRequest request) { | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* @param accidentList | |||
* @return | |||
*/ | |||
private List<AccidentVo> buildAccidentVoList(List<Accident> accidentList) { | |||
Map<String, String> deptNameMap = this.getDeptMap(accidentList); | |||
Map<String, User> userMap = this.getUserMap(deptNameMap); | |||
List<AccidentVo> accidentVoList = AccidentConverMapper.INSTANCE.accidentListToAccidentVoList(accidentList); | |||
String deptName; | |||
User user; | |||
for (AccidentVo accidentVo : accidentVoList) { | |||
if (ObjectUtil.isNotNull(deptNameMap)) { | |||
deptName = deptNameMap.get(accidentVo.getDeptId()); | |||
accidentVo.setDeptName(deptName); | |||
} | |||
} | |||
return accidentVoList; | |||
} | |||
/** | |||
* 设置列表中每一个的部门名称 | |||
* 查询到的列表中的部门Id,作为部门id列表,查询所有的部门,该结果数据量不会太大,放到map中 | |||
* | |||
* @param accidentList | |||
* @return | |||
*/ | |||
private Map<String, String> getDeptMap(List<Accident> accidentList) { | |||
List<String> deptIdList = accidentList.stream().map(o -> o.getDeptId()).collect(Collectors.toList()); | |||
List<Dept> deptList = deptMapper.selectListByIdList(deptIdList); | |||
Map<String, String> deptNameMap = deptList.stream().collect(HashMap::new, (m, v) -> m.put(v.getId(), v.getName()), HashMap::putAll); | |||
return deptNameMap; | |||
} | |||
private Map<String, User> getUserMap(Map<String, String> deptMap) { | |||
if (ObjectUtil.isNull(deptMap)) { | |||
return null; | |||
} | |||
List<String> deptIdList = deptMap.keySet().stream().collect(Collectors.toList()); | |||
List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>() | |||
.in(User::getDeptId, deptIdList) | |||
.eq(User::getRoleId, DataPermissionEnum.DEPT_AND_SUB_DEPT.getCode())); | |||
Map<String, User> userMap = userList.stream().collect(HashMap::new, (m, v) -> m.put(v.getDeptId(), v), HashMap::putAll); | |||
return userMap; | |||
} | |||
public JsonResult index(AccidentQuery query) { | |||
//校验 | |||
if (query.getLimit() == null && query.getPage() == null) { | |||
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL); | |||
} | |||
//当前租户下 | |||
User user = CurrentUserUtil.getUserInfo(); | |||
String tenantId = user.getTenantId(); | |||
List<String> deptIdList = this.getDeptIdList(user, query.getDeptId()); | |||
query.setDeptIdList(deptIdList); | |||
query.setTenantId(tenantId); | |||
IPage<Accident> page = new Page<>(query.getPage(), query.getLimit()); | |||
IPage<QueryAccidentPageVO> pageData = new Page<>(query.getPage(), query.getLimit()); | |||
//搜索时间 | |||
Date startTime = null; | |||
Date endTime = null; | |||
if (StringUtils.isNotEmpty(query.getStartTime()) && StringUtils.isNotEmpty(query.getEndTime())) { | |||
startTime = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, query.getStartTime() + " 00:00:00"); | |||
endTime = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, query.getEndTime() + " 23:59:59"); | |||
} | |||
query.setAccidentStartTime(startTime); | |||
query.setAccidentEndTime(endTime); | |||
//获取分页数据 | |||
IPage<Accident> accidentPageData = accidentMapper.selectPage(page, Wrappers.<Accident>lambdaQuery() | |||
.eq(null != query.getCode(), Accident::getRoadCode, query.getCode()) | |||
.in(CollectionUtils.isNotEmpty(deptIdList), Accident::getDeptId, deptIdList) | |||
.between(null != query.getAccidentStartTime() && null != query.getAccidentEndTime(), | |||
Accident::getCreateTime, query.getAccidentStartTime(), query.getAccidentEndTime()) | |||
.eq(Accident::getFlag, FlagEnum.INSPECTION_ACCIDENT.getCode()) | |||
.eq(Accident::getMark, MarkEnum.VALID.getCode()) | |||
.orderByDesc(Accident::getCreateTime)); | |||
//属性复制 | |||
List<QueryAccidentPageVO> result = accidentPageData.getRecords().stream().map(x -> { | |||
QueryAccidentPageVO vo = new QueryAccidentPageVO(); | |||
BeanUtils.copyProperties(x, vo); | |||
//公路代号 | |||
if (StringUtils.isNotEmpty(x.getRoadCode())) { | |||
vo.setCode(x.getRoadCode()); | |||
} | |||
//监管部门 | |||
if (StringUtils.isNotEmpty(x.getDeptId())) { | |||
//根据当前部门id查询对应的部门名称 | |||
Dept dept = deptMapper.selectById(x.getDeptId()); | |||
vo.setName(dept.getName() != null ? dept.getName() : ""); | |||
} | |||
return vo; | |||
}).collect(Collectors.toList()); | |||
pageData.setPages(accidentPageData.getPages()); | |||
pageData.setRecords(result); | |||
pageData.setTotal(accidentPageData.getTotal()); | |||
pageData.setCurrent(accidentPageData.getCurrent()); | |||
return JsonResult.success(pageData); | |||
} | |||
/** | |||
* 根据用户自己的数据权限,查询对应部门的数据 | |||
* | |||
* @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; | |||
} | |||
} |
@@ -1,9 +1,12 @@ | |||
package com.tuoheng.admin.service.accident.query; | |||
import cn.hutool.core.util.ObjectUtil; | |||
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.conver.AccidentConverMapper; | |||
import com.tuoheng.admin.entity.Accident; | |||
import com.tuoheng.admin.entity.Dept; | |||
import com.tuoheng.admin.entity.User; | |||
@@ -14,7 +17,9 @@ import com.tuoheng.admin.mapper.AccidentMapper; | |||
import com.tuoheng.admin.mapper.DeptMapper; | |||
import com.tuoheng.admin.mapper.UserMapper; | |||
import com.tuoheng.admin.query.AccidentQuery; | |||
import com.tuoheng.admin.request.accident.QueryAccidentPageListRequest; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.admin.vo.accident.AccidentVo; | |||
import com.tuoheng.admin.vo.accident.QueryAccidentPageVO; | |||
import com.tuoheng.common.core.enums.ServiceExceptionEnum; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
@@ -26,9 +31,7 @@ import org.springframework.beans.BeanUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.ArrayList; | |||
import java.util.Date; | |||
import java.util.List; | |||
import java.util.*; | |||
import java.util.stream.Collectors; | |||
/** | |||
@@ -51,19 +54,99 @@ public class QueryAccidentPageListService { | |||
@Autowired | |||
private AccidentMapper accidentMapper; | |||
public JsonResult getPageList(QueryAccidentPageListRequest request) { | |||
// log.info("进入查询事件分页列表业务"); | |||
String tenantId = CurrentUserUtil.getTenantId(); | |||
request.setTenantId(tenantId); | |||
JsonResult result = this.check(tenantId, request); | |||
if (0 != result.getCode()) { | |||
log.info("进入查询事件分页列表业务:校验失败:{}", result.getMsg()); | |||
return result; | |||
} | |||
// 设置分页参数 | |||
IPage<Accident> page = new Page<>(request.getPage(), request.getLimit()); | |||
IPage<Accident> pageData = accidentMapper.selectPageList(page, request); | |||
// 构造返回结果对象 | |||
List<AccidentVo> accidentVoList = this.buildAccidentVoList(pageData.getRecords()); | |||
// 重写返回结果对象 | |||
IPage<AccidentVo> accidentVoPageData = new Page<>(); | |||
accidentVoPageData.setPages(pageData.getPages()); | |||
accidentVoPageData.setCurrent(pageData.getCurrent()); | |||
accidentVoPageData.setSize(pageData.getSize()); | |||
accidentVoPageData.setTotal(pageData.getTotal()); | |||
accidentVoPageData.setRecords(accidentVoList); | |||
return JsonResult.success(accidentVoPageData); | |||
} | |||
/** | |||
* 检查参数 | |||
* | |||
* @param tenantId | |||
* @param request | |||
* @return | |||
*/ | |||
private JsonResult check(String tenantId, QueryAccidentPageListRequest request) { | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* @param accidentList | |||
* @return | |||
*/ | |||
private List<AccidentVo> buildAccidentVoList(List<Accident> accidentList) { | |||
Map<String, String> deptNameMap = this.getDeptMap(accidentList); | |||
List<AccidentVo> accidentVoList = AccidentConverMapper.INSTANCE.accidentListToAccidentVoList(accidentList); | |||
String deptName; | |||
for (AccidentVo accidentVo : accidentVoList) { | |||
if (ObjectUtil.isNotNull(deptNameMap)) { | |||
deptName = deptNameMap.get(accidentVo.getDeptId()); | |||
accidentVo.setDeptName(deptName); | |||
} | |||
} | |||
return accidentVoList; | |||
} | |||
/** | |||
* 设置列表中每一个的部门名称 | |||
* 查询到的列表中的部门Id,作为部门id列表,查询所有的部门,该结果数据量不会太大,放到map中 | |||
* | |||
* @param accidentList | |||
* @return | |||
*/ | |||
private Map<String, String> getDeptMap(List<Accident> accidentList) { | |||
List<String> deptIdList = accidentList.stream().map(o -> o.getDeptId()).collect(Collectors.toList()); | |||
List<Dept> deptList = deptMapper.selectListByIdList(deptIdList); | |||
Map<String, String> deptNameMap = deptList.stream().collect(HashMap::new, (m, v) -> m.put(v.getId(), v.getName()), HashMap::putAll); | |||
return deptNameMap; | |||
} | |||
private Map<String, User> getUserMap(Map<String, String> deptMap) { | |||
if (ObjectUtil.isNull(deptMap)) { | |||
return null; | |||
} | |||
List<String> deptIdList = deptMap.keySet().stream().collect(Collectors.toList()); | |||
List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>() | |||
.in(User::getDeptId, deptIdList) | |||
.eq(User::getRoleId, DataPermissionEnum.DEPT_AND_SUB_DEPT.getCode())); | |||
Map<String, User> userMap = userList.stream().collect(HashMap::new, (m, v) -> m.put(v.getDeptId(), v), HashMap::putAll); | |||
return userMap; | |||
} | |||
public JsonResult index(AccidentQuery query) { | |||
//校验 | |||
if (query.getLimit() == null && query.getPage() == null) { | |||
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL); | |||
} | |||
//当前租户下 | |||
User user = CurrentUserUtil.getUserInfo(); | |||
String tenantId = user.getTenantId(); | |||
List<String> deptIdList = this.getDeptIdList(user, query.getDeptId()); | |||
query.setDeptIdList(deptIdList); | |||
query.setTenantId(tenantId); | |||
IPage<Accident> page = new Page<>(query.getPage(), query.getLimit()); | |||
IPage<QueryAccidentPageVO> pageData = new Page<>(query.getPage(), query.getLimit()); | |||
//搜索时间 | |||
@@ -77,9 +160,8 @@ public class QueryAccidentPageListService { | |||
query.setAccidentEndTime(endTime); | |||
//获取分页数据 | |||
IPage<Accident> accidentPageData = accidentMapper.selectPage(page, Wrappers.<Accident>lambdaQuery() | |||
.eq(Accident::getTenantId, tenantId) | |||
.in(CollectionUtils.isNotEmpty(deptIdList), Accident::getDeptId, deptIdList) | |||
.eq(null != query.getCode(), Accident::getRoadCode, query.getCode()) | |||
.in(CollectionUtils.isNotEmpty(deptIdList), Accident::getDeptId, deptIdList) | |||
.between(null != query.getAccidentStartTime() && null != query.getAccidentEndTime(), | |||
Accident::getCreateTime, query.getAccidentStartTime(), query.getAccidentEndTime()) | |||
.eq(Accident::getFlag, FlagEnum.INSPECTION_ACCIDENT.getCode()) |
@@ -55,7 +55,7 @@ | |||
from th_accident | |||
</sql> | |||
<select id="selectPageList" parameterType="com.tuoheng.admin.request.accident.QueryAccidentCardPageListRequest" resultMap="AccidentResult"> | |||
<select id="selectPageList" parameterType="com.tuoheng.admin.request.accident.QueryAccidentPageListRequest" resultMap="AccidentResult"> | |||
select <include refid="Base_Column_List"/> | |||
from th_accident | |||
<where> |