|
|
@@ -1,6 +1,7 @@ |
|
|
|
package com.tuoheng.admin.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
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.Wrappers; |
|
|
@@ -9,6 +10,10 @@ import com.tuoheng.admin.entity.RoadInformation; |
|
|
|
import com.tuoheng.admin.entity.Section; |
|
|
|
|
|
|
|
import com.tuoheng.admin.entity.SectionDept; |
|
|
|
import com.tuoheng.admin.entity.User; |
|
|
|
import com.tuoheng.admin.enums.SectionEnum; |
|
|
|
import com.tuoheng.admin.enums.UserTypeEnum; |
|
|
|
import com.tuoheng.admin.mapper.DeptMapper; |
|
|
|
import com.tuoheng.admin.mapper.RoadInformationMapper; |
|
|
|
import com.tuoheng.admin.mapper.SectionDeptMapper; |
|
|
|
import com.tuoheng.admin.mapper.SectionMapper; |
|
|
@@ -30,6 +35,7 @@ import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
@@ -54,37 +60,97 @@ public class SectionServiceImpl extends BaseServiceImpl<SectionMapper, Section> |
|
|
|
@Autowired |
|
|
|
private QuerySectionListByRoadIdService querySectionListByRoadIdService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private DeptMapper deptMapper; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 获取路段列表(分页) |
|
|
|
* @param query |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public JsonResult queryPage(SectionQuery query) { |
|
|
|
if(null==query.getLimit() && null == query.getPage()){ |
|
|
|
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL); |
|
|
|
} |
|
|
|
//获取当前登录用户信息 |
|
|
|
User user = CurrentUserUtil.getUserInfo(); |
|
|
|
if(ObjectUtil.isNull(user)){ |
|
|
|
return JsonResult.error(SectionEnum.USER_IS_NOT_EXIST.getCode(),SectionEnum.USER_IS_NOT_EXIST.getMsg()); |
|
|
|
} |
|
|
|
String tenantId = CurrentUserUtil.getTenantId(); |
|
|
|
//获取分页数据 |
|
|
|
IPage<Section> page = new Page<>(query.getPage(),query.getLimit()); |
|
|
|
IPage<Section> pageData = sectionMapper.selectPage(page, Wrappers.<Section>lambdaQuery() |
|
|
|
.eq(Section::getMark, 1) |
|
|
|
.eq(Section::getTenantId, tenantId) |
|
|
|
.orderByDesc(Section::getCreateTime)); |
|
|
|
List<Section> records = pageData.getRecords(); |
|
|
|
List<Section> list = new ArrayList<>(); |
|
|
|
for (Section record : records) { |
|
|
|
//获取每条路段对应的公路id |
|
|
|
RoadInformation roadInformation = roadInformationMapper.selectOne(Wrappers.<RoadInformation>lambdaQuery() |
|
|
|
.eq(RoadInformation::getId, record.getRoadId()) |
|
|
|
.eq(RoadInformation::getMark, 1)); |
|
|
|
if(StringUtils.isNotNull(roadInformation)){ |
|
|
|
if(StringUtils.isNotEmpty(roadInformation.getCode())){ |
|
|
|
record.setCode(roadInformation.getCode()); |
|
|
|
IPage<Section> pageData = new Page<>(query.getPage(),query.getLimit()); |
|
|
|
//数据权限 超级管理员可以查看全部路段 |
|
|
|
if(UserTypeEnum.SUPER_ADMIN.getCode() == user.getType()){ |
|
|
|
//获取分页数据 |
|
|
|
IPage<Section> page = new Page<>(query.getPage(),query.getLimit()); |
|
|
|
pageData = sectionMapper.selectPage(page, Wrappers.<Section>lambdaQuery() |
|
|
|
.eq(Section::getMark, 1) |
|
|
|
.eq(Section::getTenantId, tenantId) |
|
|
|
.orderByDesc(Section::getCreateTime)); |
|
|
|
List<Section> records = pageData.getRecords(); |
|
|
|
List<Section> list = new ArrayList<>(); |
|
|
|
for (Section record : records) { |
|
|
|
//获取每条路段对应的公路id |
|
|
|
RoadInformation roadInformation = roadInformationMapper.selectOne(Wrappers.<RoadInformation>lambdaQuery() |
|
|
|
.eq(RoadInformation::getId, record.getRoadId()) |
|
|
|
.eq(RoadInformation::getMark, 1)); |
|
|
|
if(StringUtils.isNotNull(roadInformation)){ |
|
|
|
if(StringUtils.isNotEmpty(roadInformation.getCode())){ |
|
|
|
record.setCode(roadInformation.getCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
//判断路段是否关联部门 |
|
|
|
SectionRelation(record); |
|
|
|
list.add(record); |
|
|
|
} |
|
|
|
//判断路段是否关联部门 |
|
|
|
SectionRelation(record); |
|
|
|
list.add(record); |
|
|
|
pageData.setRecords(list); |
|
|
|
} |
|
|
|
//部门管理员和普通用户 查看本部门及下属部门 |
|
|
|
if(UserTypeEnum.ADMIN.getCode() == user.getType() || UserTypeEnum.ORDINARY_USER.getCode() == user.getType()){ |
|
|
|
//获取分页数据 |
|
|
|
IPage<Section> page = new Page<>(query.getPage(),query.getLimit()); |
|
|
|
//获取当前部门及其子部门列表 |
|
|
|
String deptId = user.getDeptId(); |
|
|
|
if(StringUtils.isEmpty(deptId)){ |
|
|
|
JsonResult.error(SectionEnum.DEPT_IS_NOT_EXIST.getCode(),SectionEnum.DEPT_IS_NOT_EXIST.getMsg()); |
|
|
|
} |
|
|
|
List<String> deptList = deptMapper.selectAllChildListById(deptId); |
|
|
|
//根据部门列表查对应的部门路段数据列表 |
|
|
|
List<SectionDept> sectionDeptList = sectionDeptMapper.selectList(Wrappers.<SectionDept>lambdaQuery() |
|
|
|
.eq(SectionDept::getTenantId, tenantId) |
|
|
|
.in(SectionDept::getDeptId, deptList)); |
|
|
|
//查询对应的路段列表 |
|
|
|
List<String> sectionIdList = sectionDeptList.stream().map(t -> t.getSectionId()).collect(Collectors.toList()); |
|
|
|
if(StringUtils.isEmpty(sectionIdList)){ |
|
|
|
JsonResult.error(SectionEnum.SECTION_ID_IS_NULL.getCode(),SectionEnum.SECTION_ID_IS_NULL.getMsg()); |
|
|
|
} |
|
|
|
//根据路段id列表获取对应的路段信息 |
|
|
|
List<Section> sectionList = sectionMapper.selectList(new LambdaQueryWrapper<Section>() |
|
|
|
.eq(Section::getMark, 1) |
|
|
|
.eq(Section::getTenantId, tenantId) |
|
|
|
.in(Section::getId, sectionIdList)); |
|
|
|
if(StringUtils.isEmpty(sectionList)){ |
|
|
|
JsonResult.error(SectionEnum.SECTION_LIST_IS_NULL.getCode(),SectionEnum.SECTION_LIST_IS_NULL.getMsg()); |
|
|
|
} |
|
|
|
List<Section> list = new ArrayList<>(); |
|
|
|
for (Section section : sectionList) { |
|
|
|
//获取每条路段对应的公路id |
|
|
|
RoadInformation roadInformation = roadInformationMapper.selectOne(Wrappers.<RoadInformation>lambdaQuery() |
|
|
|
.eq(RoadInformation::getId, section.getRoadId()) |
|
|
|
.eq(RoadInformation::getMark, 1)); |
|
|
|
if(ObjectUtil.isNotNull(roadInformation)){ |
|
|
|
if(StringUtils.isNotEmpty(roadInformation.getCode())){ |
|
|
|
section.setCode(roadInformation.getCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
//判断路段是否关联部门 |
|
|
|
SectionRelation(section); |
|
|
|
list.add(section); |
|
|
|
} |
|
|
|
pageData.setRecords(list); |
|
|
|
} |
|
|
|
pageData.setRecords(list); |
|
|
|
|
|
|
|
return JsonResult.success(pageData); |
|
|
|
} |
|
|
|
|