Browse Source

修改获取应急事故卡片列表

tags/V1.3.3
wanjing 1 year ago
parent
commit
4d2f4c2898
1 changed files with 37 additions and 24 deletions
  1. +37
    -24
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/accident/query/QueryAccidentCardPageListService.java

+ 37
- 24
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/accident/query/QueryAccidentCardPageListService.java View File

import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; 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.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tuoheng.admin.conver.AccidentConverMapper; import com.tuoheng.admin.conver.AccidentConverMapper;
import com.tuoheng.admin.entity.Accident; import com.tuoheng.admin.entity.Accident;
import com.tuoheng.admin.entity.Dept; import com.tuoheng.admin.entity.Dept;
import com.tuoheng.admin.entity.User; import com.tuoheng.admin.entity.User;
import com.tuoheng.admin.enums.AccidentEnum;
import com.tuoheng.admin.enums.DataPermissionEnum;
import com.tuoheng.admin.enums.FlagEnum; import com.tuoheng.admin.enums.FlagEnum;
import com.tuoheng.admin.enums.MarkEnum; import com.tuoheng.admin.enums.MarkEnum;
import com.tuoheng.admin.enums.DataPermissionEnum;
import com.tuoheng.admin.mapper.AccidentMapper; import com.tuoheng.admin.mapper.AccidentMapper;
import com.tuoheng.admin.mapper.DeptMapper; import com.tuoheng.admin.mapper.DeptMapper;
import com.tuoheng.admin.mapper.UserMapper; import com.tuoheng.admin.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;


import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;


/** /**
} }


/** /**
* 设置列表中每一个的部门名称
* 查询到的列表中的部门Id,作为部门id列表,查询所有的部门,该结果数据量不会太大,放到map中
* 设置列表中每一个的部门名称
* 查询到的列表中的部门Id,作为部门id列表,查询所有的部门,该结果数据量不会太大,放到map中
* *
* @param accidentList * @param accidentList
* @return * @return
} }
List<String> deptIdList = deptMap.keySet().stream().collect(Collectors.toList()); List<String> deptIdList = deptMap.keySet().stream().collect(Collectors.toList());
List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>() List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>()
.in(User::getDeptId, deptIdList)
.eq(User::getRoleId, DataPermissionEnum.DEPT_AND_SUB_DEPT.getCode()));
.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); Map<String, User> userMap = userList.stream().collect(HashMap::new, (m, v) -> m.put(v.getDeptId(), v), HashMap::putAll);
return userMap; return userMap;
} }


public JsonResult index(AccidentQuery query) { public JsonResult index(AccidentQuery query) {
//校验 //校验
if(query.getLimit() == null && query.getPage() == null){
if (query.getLimit() == null && query.getPage() == null) {
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL); throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL);
} }


//当前租户下 //当前租户下
String tenantId = CurrentUserUtil.getTenantId();
if(tenantId == null){
return JsonResult.error(AccidentEnum.TENANT_ID_IS_NULL.getCode(),AccidentEnum.TENANT_ID_IS_NULL.getMsg());
}
User user = CurrentUserUtil.getUserInfo();
String tenantId = user.getTenantId();
List<String> deptIdList = this.getDeptIdList(user);
query.setDeptIdList(deptIdList);
query.setTenantId(tenantId); query.setTenantId(tenantId);
IPage<Accident> page = new Page<>(query.getPage(),query.getLimit());
IPage<QueryAccidentPageVO> pageData = new Page<>(query.getPage(),query.getLimit());
IPage<Accident> page = new Page<>(query.getPage(), query.getLimit());
IPage<QueryAccidentPageVO> pageData = new Page<>(query.getPage(), query.getLimit());
//搜索时间 //搜索时间
Date startTime = null; Date startTime = null;
Date endTime = 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");
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.setAccidentStartTime(startTime);
query.setAccidentEndTime(endTime); query.setAccidentEndTime(endTime);
//获取分页数据 //获取分页数据
IPage<Accident> accidentPageData = accidentMapper.selectPage(page, Wrappers.<Accident>lambdaQuery() IPage<Accident> accidentPageData = accidentMapper.selectPage(page, Wrappers.<Accident>lambdaQuery()
.eq(null != query.getCode(),Accident::getRoadCode,query.getCode())
.eq(null != query.getDeptId(),Accident::getDeptId,query.getDeptId())
.eq(null != query.getCode(), Accident::getRoadCode, query.getCode())
.in(CollectionUtils.isNotEmpty(deptIdList), Accident::getDeptId, deptIdList)
.between(null != query.getAccidentStartTime() && null != query.getAccidentEndTime(), .between(null != query.getAccidentStartTime() && null != query.getAccidentEndTime(),
Accident::getCreateTime, query.getAccidentStartTime(), query.getAccidentEndTime()) Accident::getCreateTime, query.getAccidentStartTime(), query.getAccidentEndTime())
.eq(Accident::getFlag, FlagEnum.INSPECTION_ACCIDENT.getCode()) .eq(Accident::getFlag, FlagEnum.INSPECTION_ACCIDENT.getCode())
if (StringUtils.isNotEmpty(x.getDeptId())) { if (StringUtils.isNotEmpty(x.getDeptId())) {
//根据当前部门id查询对应的部门名称 //根据当前部门id查询对应的部门名称
Dept dept = deptMapper.selectById(x.getDeptId()); Dept dept = deptMapper.selectById(x.getDeptId());
vo.setName(dept.getName() !=null?dept.getName():"");
vo.setName(dept.getName() != null ? dept.getName() : "");
} }


return vo; return vo;
pageData.setCurrent(accidentPageData.getCurrent()); pageData.setCurrent(accidentPageData.getCurrent());


return JsonResult.success(pageData); return JsonResult.success(pageData);
}



/**
* 根据用户自己的数据权限,查询对应部门的数据
*
* @param user
* @return
*/
private List<String> getDeptIdList(User user) {
List<String> deptIdList = new ArrayList<>();
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;
} }
} }

Loading…
Cancel
Save