|
|
@@ -1,30 +1,32 @@ |
|
|
|
package com.tuoheng.admin.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.tuoheng.admin.entity.RoadInformation; |
|
|
|
import com.tuoheng.admin.entity.Section; |
|
|
|
import com.tuoheng.admin.entity.User; |
|
|
|
import com.tuoheng.admin.mapper.RoadInformationMapper; |
|
|
|
import com.tuoheng.admin.mapper.SectionMapper; |
|
|
|
import com.tuoheng.admin.entity.*; |
|
|
|
import com.tuoheng.admin.enums.UserTypeEnum; |
|
|
|
import com.tuoheng.admin.mapper.*; |
|
|
|
import com.tuoheng.admin.query.RoadInformationQuery; |
|
|
|
import com.tuoheng.admin.service.RoadInformationService; |
|
|
|
import com.tuoheng.admin.service.road.query.QueryRoadListByDeptIdService; |
|
|
|
import com.tuoheng.common.core.common.BaseServiceImpl; |
|
|
|
import com.tuoheng.common.core.enums.ServiceExceptionEnum; |
|
|
|
import com.tuoheng.common.core.utils.DateUtils; |
|
|
|
import com.tuoheng.common.core.utils.JsonResult; |
|
|
|
import com.tuoheng.common.core.utils.StringUtils; |
|
|
|
import com.tuoheng.common.core.utils.ThreadLocalUtil; |
|
|
|
import com.tuoheng.common.core.exception.ServiceException; |
|
|
|
import com.tuoheng.common.core.utils.*; |
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
|
import org.jetbrains.annotations.Nullable; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author ChengWang |
|
|
@@ -42,6 +44,15 @@ public class RoadInformationServiceImpl extends BaseServiceImpl<RoadInformationM |
|
|
|
@Autowired |
|
|
|
private QueryRoadListByDeptIdService queryRoadListByDeptIdService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private UserMapper userMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private DeptMapper deptMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RoadDeptMapper roadDeptMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public JsonResult queryPage(RoadInformationQuery query) { |
|
|
|
if (query.getLimit() == null && query.getPage() == null) { |
|
|
@@ -112,34 +123,97 @@ public class RoadInformationServiceImpl extends BaseServiceImpl<RoadInformationM |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
// @Override |
|
|
|
// public JsonResult deleteRoadByIds(String[] ids) { |
|
|
|
// if (StringUtils.isNull(ids)) { |
|
|
|
// return JsonResult.error("公路ID不能为空"); |
|
|
|
// } |
|
|
|
// for (String id : ids) { |
|
|
|
// RoadInformation roadInformation = roadInformationMapper.selectById(id); |
|
|
|
// //判断公路是否关联路段 |
|
|
|
// List<Section> sectionList = sectionMapper.selectList(new LambdaQueryWrapper<Section>() |
|
|
|
// .eq(Section::getMark, 1) |
|
|
|
// .eq(Section::getTenantId, 1) |
|
|
|
// .eq(Section::getRoadId, roadInformation.getId())); |
|
|
|
// if (StringUtils.isEmpty(sectionList)) { |
|
|
|
// super.deleteById(id); |
|
|
|
// } |
|
|
|
// //公路关联路段不为空,删除公路对应的路段 |
|
|
|
// for (Section section : sectionList) { |
|
|
|
// LambdaUpdateWrapper<Section> qw = new LambdaUpdateWrapper<>(); |
|
|
|
// qw.set(Section::getMark, 0); |
|
|
|
// qw.eq(Section::getId, section.getId()); |
|
|
|
// int update = sectionMapper.update(section, qw); |
|
|
|
// if (update <= 0) { |
|
|
|
// return JsonResult.error(); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
// return JsonResult.success("删除成功"); |
|
|
|
// } |
|
|
|
/** |
|
|
|
* 根据登录人角色获取该部门下公路信息列表 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public JsonResult getListByUserType() { |
|
|
|
//获取当前登录人信息 登录用户名 |
|
|
|
//String username = SecurityUserUtils.username(); |
|
|
|
String username="admin"; |
|
|
|
if(StringUtils.isEmpty(username)){ |
|
|
|
return JsonResult.error("登录用户名不存在"); |
|
|
|
} |
|
|
|
User user = userMapper.selectOne(Wrappers.<User>lambdaQuery() |
|
|
|
.eq(User::getMark, 1) |
|
|
|
.eq(User::getUsername, username)); |
|
|
|
if(null == user){ |
|
|
|
return JsonResult.error("用户不存在"); |
|
|
|
} |
|
|
|
//获取租户id |
|
|
|
String tenantId = user.getTenantId(); |
|
|
|
//用户类型角色判断 1超级管理员 2 部门管理员 3普通用户 |
|
|
|
if(null == user.getType()){ |
|
|
|
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL); |
|
|
|
} |
|
|
|
//登录用户若为部门管理员或普通用户需要查询所在部门 |
|
|
|
String deptId = user.getDeptId(); |
|
|
|
//获取公路列表 |
|
|
|
List<RoadInformation> roadInformationList = new ArrayList<>(); |
|
|
|
if(null == deptId){ |
|
|
|
//超级管理员 |
|
|
|
if(UserTypeEnum.SUPER_ADMIN.getCode()== user.getType()){ |
|
|
|
roadInformationList = this.getAllRoadInformationList(tenantId); |
|
|
|
} |
|
|
|
} |
|
|
|
//部门管理员 |
|
|
|
if(UserTypeEnum.ADMIN.getCode() == user.getType()){ |
|
|
|
//根据当前用户对应的部门id获取该部门及子部门的id集合 |
|
|
|
List<String> deptIdList = deptMapper.selectAllChildListById(deptId); |
|
|
|
if(CollectionUtil.isEmpty(deptIdList)){ |
|
|
|
return null; |
|
|
|
} |
|
|
|
List<RoadDept> list = roadDeptMapper.selectListByDeptIdList(deptIdList); |
|
|
|
roadInformationList = this.getRoadInformationList(tenantId, list); |
|
|
|
} |
|
|
|
|
|
|
|
//普通用户 |
|
|
|
if(UserTypeEnum.ORDINARY_USER.getCode() == user.getType()){ |
|
|
|
List<RoadDept> roadDeptList = roadDeptMapper.selectList(new LambdaQueryWrapper<RoadDept>() |
|
|
|
.eq(RoadDept::getTenantId, tenantId) |
|
|
|
.eq(RoadDept::getDeptId, deptId)); |
|
|
|
if (CollectionUtil.isEmpty(roadDeptList)) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
roadInformationList =this.getRoadInformationList(tenantId,roadDeptList); |
|
|
|
} |
|
|
|
|
|
|
|
return JsonResult.success(roadInformationList); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据部门列表获取公路列表 |
|
|
|
* @param tenantId |
|
|
|
* @param list |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private List<RoadInformation> getRoadInformationList(String tenantId, List<RoadDept> list) { |
|
|
|
List<RoadInformation> roadInformationList; |
|
|
|
List<String> roadIdList = list.stream().map(o -> o.getRoadId()).collect(Collectors.toList()); |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
map.put("tenantId", tenantId); |
|
|
|
map.put("roadIdList", roadIdList); |
|
|
|
map.put("mark",1); |
|
|
|
roadInformationList = roadInformationMapper.getListByMap(map); |
|
|
|
return roadInformationList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 如果是顶级部门,则查询所有公路列表 |
|
|
|
* |
|
|
|
* @param tenantId |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private List<RoadInformation> getAllRoadInformationList(String tenantId) { |
|
|
|
List<RoadInformation> roadList = roadInformationMapper.selectList(new LambdaQueryWrapper<RoadInformation>() |
|
|
|
.eq(RoadInformation::getTenantId, tenantId) |
|
|
|
.eq(RoadInformation::getMark, 1)); |
|
|
|
if (CollectionUtil.isEmpty(roadList)) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
return roadList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 判断公路是否关联路段 |