Browse Source

修改构造物数据权限

tags/v1.0.0^2
chengwang 1 year ago
parent
commit
58d0596b03
4 changed files with 126 additions and 9 deletions
  1. +45
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/StructureEnum.java
  2. +1
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/mapper/StructureMapper.java
  3. +46
    -9
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/StructureServiceImpl.java
  4. +34
    -0
      tuoheng-service/tuoheng-admin/src/main/resources/mapper/StructureMapper.xml

+ 45
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/StructureEnum.java View File

@@ -0,0 +1,45 @@
package com.tuoheng.admin.enums;

/**
* @Author ChengWang
* @Date 2022/12/21
*/
public enum StructureEnum {

QUERY_IS_FAILED(1220500, "获取数据失败"),
USER_IS_NOT_EXIST(1220501, "用户为空"),
DEPT_IS_NOT_EXIST(1220502, "部门不存在"),
SECTION_ID_IS_NULL(1220503, "路段id为空"),
SECTION_LIST_IS_NULL(1220504, "路段列表为空");

/**
* 错误码
*/
private int code;

/**
* 错误信息
*/
private String msg;

StructureEnum(int code, String msg){
this.code = code;
this.msg = msg;
}

public int getCode() {
return code;
}

public void setCode(int code) {
this.code = code;
}

public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}
}

+ 1
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/mapper/StructureMapper.java View File

@@ -14,4 +14,5 @@ import org.apache.ibatis.annotations.Param;
public interface StructureMapper extends BaseMapper<Structure> {
IPage<StructureInfoVo> queryPage(@Param("page") IPage page,@Param("request") StructureQuery query);

IPage<StructureInfoVo> queryPageBySectionId(@Param("page") IPage<Structure> page,@Param("request") StructureQuery query);
}

+ 46
- 9
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/StructureServiceImpl.java View File

@@ -5,11 +5,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.Structure;
import com.tuoheng.admin.entity.User;
import com.tuoheng.admin.entity.*;
import com.tuoheng.admin.enums.RoleEnum;
import com.tuoheng.admin.enums.SectionEnum;
import com.tuoheng.admin.enums.StructureEnum;
import com.tuoheng.admin.mapper.*;
import com.tuoheng.admin.query.StructureQuery;
import com.tuoheng.admin.service.IStructureService;
@@ -51,6 +50,9 @@ public class StructureServiceImpl extends BaseServiceImpl<StructureMapper, Struc
@Autowired
private DeptMapper deptMapper;

@Autowired
private SectionDeptMapper sectionDeptMapper;


@Override
public JsonResult queryPage(StructureQuery query) {
@@ -62,13 +64,15 @@ public class StructureServiceImpl extends BaseServiceImpl<StructureMapper, Struc
if(ObjectUtil.isNull(user)){
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL);
}
//租户id
String tenantId = user.getTenantId();
//获取用户角色
Integer roleId = user.getRoleId();
IPage<Structure> page = new Page<>(query.getPage(),query.getLimit());
IPage<StructureInfoVo> pageData = null;
//如果是超级管理员,查看所有构造物
if(RoleEnum.SUPER_ADMIN.getCode() == roleId){
//数据分页
IPage<Structure> page = new Page<>(query.getPage(),query.getLimit());
pageData = structureMapper.queryPage(page,query);
List<StructureInfoVo> list = pageData.getRecords().stream().map((item) -> {
StructureInfoVo structureInfoVo = new StructureInfoVo();
@@ -96,11 +100,44 @@ public class StructureServiceImpl extends BaseServiceImpl<StructureMapper, Struc
}
//如果是部门管理员或普通用户,查询本部门及子部门包含的路段及路段对应的构造物
if(RoleEnum.ADMIN.getCode() == roleId || RoleEnum.ORDINARY_USER.getCode() == roleId){

String deptId = user.getDeptId();
if (StringUtils.isEmpty(deptId)){
return JsonResult.error(StructureEnum.DEPT_IS_NOT_EXIST.getCode(),StructureEnum.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());
}
List<StructureInfoVo> list = new ArrayList<>();
//根据路段id查询对应的构造物列表
for (String sectionId : sectionIdList) {
query.setSectionId(sectionId);
pageData = structureMapper.queryPageBySectionId(page,query);
List<StructureInfoVo> records = pageData.getRecords();
for (StructureInfoVo record : records) {
//获取构造物图片,对图片进行处理
if(StringUtils.isNotEmpty(record.getImageUrl())){
String[] imageUrls = record.getImageUrl().split(",");
if(StringUtils.isNotEmpty(imageUrls)){
for (int i = 0; i < imageUrls.length; i++) {
if(StringUtils.isNotEmpty(imageUrls[i])){
imageUrls[i]= CommonConfig.imageURL+imageUrls[i];
}
}
}
record.setImageUrl(StringUtils.join(imageUrls,","));
}
list.add(record);
}
}
pageData.setRecords(list);
}



+ 34
- 0
tuoheng-service/tuoheng-admin/src/main/resources/mapper/StructureMapper.xml View File

@@ -54,5 +54,39 @@
sr.create_time DESC
</select>

<select id="queryPageBySectionId" resultType="com.tuoheng.admin.vo.StructureInfoVo">
SELECT
sr.id,
sr.tenant_id as tenantId,
sr.road_id as roadId,
sr.section_id as sectionId,
sr.structure_type as structureType,
sr.structure_name as structureName,
sr.longitude as longitude,
sr.latitude as latitude,
sr.image_url as imageUrl,
se.section_range as sectionRange,
rd.code as code
from
th_structure sr
left JOIN th_section se ON sr.section_id=se.id
left JOIN th_road rd ON sr.road_id=rd.id
where sr.mark=1 and se.mark=1 and rd.mark=1
<if test="request.structureName !=null and request.structureName !=''">
AND sr.`structure_name` like concat('%',#{request.structureName},'%')
</if>
<if test="request.sectionId !=null">
AND sr.section_id = #{request.sectionId}
</if>
<if test="request.structureType !=null">
AND sr.structure_type = #{request.structureType}
</if>
<if test="request.roadId !=null">
AND sr.road_id = #{request.roadId}
</if>
ORDER BY
sr.create_time DESC
</select>


</mapper>

Loading…
Cancel
Save