Browse Source

公路信息管理和路段基本增删改功能

tags/v1.0.0^2
chengwang 2 years ago
parent
commit
e9d9191b3c
23 changed files with 931 additions and 153 deletions
  1. +25
    -25
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/config/AdminMvcConfig.java
  2. +73
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/RoadInformationController.java
  3. +83
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/SectionController.java
  4. +18
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/StructureController.java
  5. +35
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/RoadDept.java
  6. +70
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/RoadInformation.java
  7. +68
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/Section.java
  8. +33
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/SectionDept.java
  9. +61
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/Structure.java
  10. +42
    -42
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/interceptor/UserInterceptor.java
  11. +13
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/mapper/RoadInformationMapper.java
  12. +11
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/mapper/SectionMapper.java
  13. +11
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/mapper/StructureMapper.java
  14. +13
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/query/RoadInformationQuery.java
  15. +14
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/query/SectionQuery.java
  16. +20
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/ISectionService.java
  17. +11
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/IStructureService.java
  18. +19
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/RoadInformationService.java
  19. +116
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/RoadInformationServiceImpl.java
  20. +119
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/SectionServiceImpl.java
  21. +15
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/StructureServiceImpl.java
  22. +61
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/vo/SectionInfoVo.java
  23. +0
    -86
      tuoheng-service/tuoheng-api/src/main/java/com/tuoheng/api/filter/AuthenticationFilter.java

+ 25
- 25
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/config/AdminMvcConfig.java View File

@@ -1,7 +1,7 @@

package com.tuoheng.admin.config;

import com.tuoheng.admin.interceptor.UserInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -16,27 +16,27 @@ import java.nio.charset.StandardCharsets;
* @Date 2022/10/31 14:06
*/
//web相关配置
@Configuration
public class AdminMvcConfig implements WebMvcConfigurer {
@Bean
public UserInterceptor setBean(){
//System.out.println("注入了handler");
return new UserInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
//添加拦截器
registry.addInterceptor(setBean())
//设置拦截的请求
.addPathPatterns("/**")
//排除拦截的请求
.excludePathPatterns(
"/user/login", //登录
"/user/loginout", //退出
"/error" //springBoot异常处理的默认请求
);
}
}
//@Configuration
//public class AdminMvcConfig implements WebMvcConfigurer {
//
// @Bean
// public UserInterceptor setBean(){
// //System.out.println("注入了handler");
// return new UserInterceptor();
// }
//
// @Override
// public void addInterceptors(InterceptorRegistry registry) {
// //添加拦截器
// registry.addInterceptor(setBean())
// //设置拦截的请求
// .addPathPatterns("/**")
// //排除拦截的请求
// .excludePathPatterns(
// "/user/login", //登录
// "/user/loginout", //退出
// "/error" //springBoot异常处理的默认请求
//
// );
// }
//}

+ 73
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/RoadInformationController.java View File

@@ -0,0 +1,73 @@
package com.tuoheng.admin.controller;

import com.tuoheng.admin.entity.RoadInformation;
import com.tuoheng.admin.query.RoadInformationQuery;
import com.tuoheng.admin.service.RoadInformationService;
import com.tuoheng.common.core.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
* @Author ChengWang
* @Date 2022/11/17
*/
@RestController
@RequestMapping("/roadInformation")
public class RoadInformationController {

@Autowired
private RoadInformationService roadInformationService;

/**
* 获取公路信息列表(分页)
* @param query
* @return
*/
@GetMapping("/index")
public JsonResult index(RoadInformationQuery query){
return roadInformationService.queryPage(query);
}

/**
* 获取公路信息列表
* @param query
* @return
*/
@GetMapping("/getList")
public JsonResult getList(RoadInformationQuery query){
return roadInformationService.getListInfo(query);
}

/**
* 公路新增
* @param entity
* @return
*/
@PostMapping("/add")
public JsonResult add(@RequestBody RoadInformation entity){
return roadInformationService.editInfo(entity);
}

/**
* 编辑公路
* @param entity
* @return
*/
@PutMapping("/edit")
public JsonResult edit(@RequestBody RoadInformation entity){
return roadInformationService.editInfo(entity);
}

/**
* 删除公路
* @param ids
* @return
*/
@DeleteMapping("/delete/{ids}")
public JsonResult delete(@PathVariable("ids") String[] ids){
return roadInformationService.deleteByIds(ids);
}



}

+ 83
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/SectionController.java View File

@@ -0,0 +1,83 @@
package com.tuoheng.admin.controller;

import com.tuoheng.admin.entity.Section;
import com.tuoheng.admin.query.SectionQuery;
import com.tuoheng.admin.service.ISectionService;
import com.tuoheng.common.core.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
* @Author ChengWang
* @Date 2022/11/17
*/
@RestController
@RequestMapping("/section")
public class SectionController {

@Autowired
private ISectionService sectionService;

/**
* 获取路段列表(分页)
* @param query
* @return
*/
@GetMapping("/index")
public JsonResult index(SectionQuery query){
return sectionService.queryPage(query);
}

/**
* 获取路段列表
* @param query
* @return
*/
@GetMapping("/getList")
public JsonResult getList(SectionQuery query){
return sectionService.getListInfo(query);
}

/**
* 根据id获取路段详情
* @param sectionId
* @return
*/
@GetMapping("/info/{sectionId}")
public JsonResult info(@PathVariable("sectionId") String sectionId){
return sectionService.getSectionInfo(sectionId);
}

/**
* 新增路段
* @param entity
* @return
*/
@PostMapping("/add")
public JsonResult add(@RequestBody Section entity){
return sectionService.editInfo(entity);
}

/**
* 编辑路段
* @param section
* @return
*/
@PutMapping("/edit")
public JsonResult edit(@RequestBody Section section){
return sectionService.editInfo(section);
}

/**
* 删除路段
* @param ids
* @return
*/
@DeleteMapping("/delete/{ids}")
public JsonResult delete(@PathVariable("ids") String[] ids){
return sectionService.deleteByIds(ids);
}



}

+ 18
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/StructureController.java View File

@@ -0,0 +1,18 @@
package com.tuoheng.admin.controller;

import com.tuoheng.admin.service.IStructureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* @Author ChengWang
* @Date 2022/11/17
*/
@RestController
@RequestMapping("/structure")
public class StructureController {

@Autowired
private IStructureService structureService;
}

+ 35
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/RoadDept.java View File

@@ -0,0 +1,35 @@
package com.tuoheng.admin.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
* @Author ChengWang
* @Date 2022/11/17
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("th_road_dept")
public class RoadDept {
private static final long serialVersionUID = 1L;

/**
* 租户id
*/
private String tenantId;

/**
* 公路id
*/
private String roadId;

/**
* 部门id
*/
private String deptId;


}

+ 70
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/RoadInformation.java View File

@@ -0,0 +1,70 @@
package com.tuoheng.admin.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.tuoheng.common.core.common.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
* @Author ChengWang
* @Date 2022/11/16
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("th_road")
public class RoadInformation extends BaseEntity {
private static final long serialVersionUID = 1L;

/**
* 租户id
*/
private String tenantId;

/**
* 公路名称
*/
private String name;

/**
* 公路代号
*/
private String code;

/**
* 起点经度
*/
private String startLongitude;

/**
* 起点纬度
*/
private String startLatitude;

/**
* 终点经度
*/
private String endLongitude;

/**
* 终点纬度
*/
private String endLatitude;

/**
* 备注
*/
private String remark;

/**
* 是否关联路段 true:关联 false:未关联
*/
@TableField(exist = false)
private boolean relation;




}

+ 68
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/Section.java View File

@@ -0,0 +1,68 @@
package com.tuoheng.admin.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.tuoheng.common.core.common.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
* @Author ChengWang
* @Date 2022/11/16
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("th_section")
public class Section extends BaseEntity {
private static final long serialVersionUID = 1L;

/**
* 租户id
*/
private String tenantId;

/**
* 公路id
*/
private String roadId;

/**
* 路段范围
*/
private String sectionRange;

/**
* 起点经度
*/
private String startLongitude;

/**
* 起点纬度
*/
private String startLatitude;

/**
* 终点经度
*/
private String endLongitude;

/**
* 终点纬度
*/
private String endLatitude;

/**
* 备注
*/
private String remark;

/**
* 是否绑定部门 true:绑定 false:未绑定
*/
@TableField(exist = false)
private boolean relation;


}

+ 33
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/SectionDept.java View File

@@ -0,0 +1,33 @@
package com.tuoheng.admin.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
* @Author ChengWang
* @Date 2022/11/17
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("th_section_dept")
public class SectionDept {
private static final long serialVersionUID = 1L;

/**
* 租户id
*/
private String tenantId;

/**
* 路段id
*/
private String sectionId;

/**
* 部门id
*/
private String deptId;
}

+ 61
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/Structure.java View File

@@ -0,0 +1,61 @@
package com.tuoheng.admin.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.tuoheng.common.core.common.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
* @Author ChengWang
* @Date 2022/11/16
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("th_structure")
public class Structure extends BaseEntity {
private static final long serialVersionUID = 1L;

/**
* 租户id
*/
private String tenantId;

/**
* 构造物种类 1桥梁 2涵洞 3通道 4互通 5服务区 6收费站 7匝道 8机场
*/
private Integer structureType;

/**
* 构造物名称
*/
private String structureName;

/**
* 公路id
*/
private String roadId;

/**
* 路段id
*/
private String sectionId;

/**
* 经度
*/
private String longitude;

/**
* 纬度
*/
private String latitude;

/**
* 构造物图片,多个用,拼接
*/
private String imageUrl;


}

+ 42
- 42
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/interceptor/UserInterceptor.java View File

@@ -20,46 +20,46 @@ import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
@Slf4j
public class UserInterceptor implements HandlerInterceptor {
@Autowired
private IUserService userService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
log.info("开始执行过滤器");
String username = SecurityUserUtils.username();
if (StringUtils.isEmpty(username)) {
throw new ServiceException(HttpStatus.BAD_REQUEST.value(),"username不能为空");
}
if(userService==null){
log.info("userService is null!!!");
BeanFactory factory = WebApplicationContextUtils
.getRequiredWebApplicationContext(request.getServletContext());
userService = (IUserService) factory
.getBean("UserServiceImpl");
}
User user = userService.getOne(Wrappers.<User>lambdaQuery()
.eq(User::getMark, 1)
.eq(User::getStatus, 1)
.eq(StringUtils.isNotEmpty(username), User::getUsername, username));
if (StringUtils.isNull(user)) {
log.error("用户信息不存在:{}", user);
return false;
}
ThreadLocalUtil.set(user);
log.info("执行完毕");
return true;
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
//结束方法清理内存
ThreadLocalUtil.remove();
log.info("清理ThreadLocal内存完毕");
}
}
//@Component
//@Slf4j
//public class UserInterceptor implements HandlerInterceptor {
//
// @Autowired
// private IUserService userService;
//
// @Override
// public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// log.info("开始执行过滤器");
// String username = SecurityUserUtils.username();
//
// if (StringUtils.isEmpty(username)) {
// throw new ServiceException(HttpStatus.BAD_REQUEST.value(),"username不能为空");
// }
//
// if(userService==null){
// log.info("userService is null!!!");
// BeanFactory factory = WebApplicationContextUtils
// .getRequiredWebApplicationContext(request.getServletContext());
// userService = (IUserService) factory
// .getBean("UserServiceImpl");
// }
// User user = userService.getOne(Wrappers.<User>lambdaQuery()
// .eq(User::getMark, 1)
// .eq(User::getStatus, 1)
// .eq(StringUtils.isNotEmpty(username), User::getUsername, username));
// if (StringUtils.isNull(user)) {
// log.error("用户信息不存在:{}", user);
// return false;
// }
// ThreadLocalUtil.set(user);
// log.info("执行完毕");
// return true;
// }
// @Override
// public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
// //结束方法清理内存
// ThreadLocalUtil.remove();
// log.info("清理ThreadLocal内存完毕");
// }
//}


+ 13
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/mapper/RoadInformationMapper.java View File

@@ -0,0 +1,13 @@
package com.tuoheng.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tuoheng.admin.entity.RoadInformation;

/**
* @Author ChengWang
* @Date 2022/11/16
*/
public interface RoadInformationMapper extends BaseMapper<RoadInformation> {


}

+ 11
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/mapper/SectionMapper.java View File

@@ -0,0 +1,11 @@
package com.tuoheng.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tuoheng.admin.entity.Section;

/**
* @Author ChengWang
* @Date 2022/11/17
*/
public interface SectionMapper extends BaseMapper<Section> {
}

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

@@ -0,0 +1,11 @@
package com.tuoheng.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tuoheng.admin.entity.Structure;

/**
* @Author ChengWang
* @Date 2022/11/17
*/
public interface StructureMapper extends BaseMapper<Structure> {
}

+ 13
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/query/RoadInformationQuery.java View File

@@ -0,0 +1,13 @@
package com.tuoheng.admin.query;

import com.tuoheng.common.core.common.BaseQuery;
import lombok.Data;

/**
* @Author ChengWang
* @Date 2022/11/17
*/
@Data
public class RoadInformationQuery extends BaseQuery {

}

+ 14
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/query/SectionQuery.java View File

@@ -0,0 +1,14 @@
package com.tuoheng.admin.query;


import com.tuoheng.common.core.common.BaseQuery;
import lombok.Data;

/**
* @Author ChengWang
* @Date 2022/11/17
*/
@Data
public class SectionQuery extends BaseQuery {

}

+ 20
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/ISectionService.java View File

@@ -0,0 +1,20 @@
package com.tuoheng.admin.service;

import com.tuoheng.admin.entity.Section;
import com.tuoheng.admin.query.SectionQuery;
import com.tuoheng.common.core.common.IBaseService;
import com.tuoheng.common.core.utils.JsonResult;

/**
* @Author ChengWang
* @Date 2022/11/17
*/
public interface ISectionService extends IBaseService<Section> {
JsonResult queryPage(SectionQuery query);

JsonResult getListInfo(SectionQuery query);

JsonResult editInfo(Section entity);

JsonResult getSectionInfo(String sectionId);
}

+ 11
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/IStructureService.java View File

@@ -0,0 +1,11 @@
package com.tuoheng.admin.service;

import com.tuoheng.admin.entity.Structure;
import com.tuoheng.common.core.common.IBaseService;

/**
* @Author ChengWang
* @Date 2022/11/17
*/
public interface IStructureService extends IBaseService<Structure> {
}

+ 19
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/RoadInformationService.java View File

@@ -0,0 +1,19 @@
package com.tuoheng.admin.service;

import com.tuoheng.admin.entity.RoadInformation;
import com.tuoheng.admin.query.RoadInformationQuery;
import com.tuoheng.common.core.common.IBaseService;
import com.tuoheng.common.core.utils.JsonResult;


/**
* @Author ChengWang
* @Date 2022/11/16
*/
public interface RoadInformationService extends IBaseService<RoadInformation> {
JsonResult queryPage(RoadInformationQuery query);

JsonResult getListInfo(RoadInformationQuery query);

JsonResult editInfo(RoadInformation entity);
}

+ 116
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/RoadInformationServiceImpl.java View File

@@ -0,0 +1,116 @@
package com.tuoheng.admin.service.impl;

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.User;
import com.tuoheng.admin.mapper.RoadInformationMapper;
import com.tuoheng.admin.mapper.SectionMapper;
import com.tuoheng.admin.query.RoadInformationQuery;
import com.tuoheng.admin.service.RoadInformationService;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @Author ChengWang
* @Date 2022/11/17
*/
@Service
public class RoadInformationServiceImpl extends BaseServiceImpl<RoadInformationMapper, RoadInformation> implements RoadInformationService {

@Autowired
private RoadInformationMapper roadInformationMapper;

@Autowired
private SectionMapper sectionMapper;

@Override
public JsonResult queryPage(RoadInformationQuery query) {
if(query.getLimit()==null && query.getPage()==null){
return JsonResult.error(ServiceExceptionEnum.PARAMETER_IS_NULL);
}
//获取登录人信息id
//Long userId = SecurityUserUtils.getLoginUser().getUserId();
//获取分页数据
IPage<RoadInformation> page = new Page<>(query.getPage(),query.getLimit());
IPage<RoadInformation> pageData = roadInformationMapper.selectPage(page, Wrappers.<RoadInformation>lambdaQuery()
.eq(RoadInformation::getMark, 1)
.eq(RoadInformation::getTenantId, 1)
.orderByDesc(RoadInformation::getCreateTime));
List<RoadInformation> records = pageData.getRecords();
List<RoadInformation> list = new ArrayList<>();
for (RoadInformation record : records) {
//判断公路关联路段信息
RoadRelation(record);
list.add(record);
}
pageData.setRecords(list);

return JsonResult.success(pageData);
}

@Override
public JsonResult getListInfo(RoadInformationQuery query) {
//当前租户下所有公路信息
List<RoadInformation> roadInformationList = roadInformationMapper.selectList(new LambdaQueryWrapper<RoadInformation>()
.eq(RoadInformation::getMark, 1)
.eq(RoadInformation::getTenantId, 1));
List<RoadInformation> list = new ArrayList<>();
for (RoadInformation roadInformation : roadInformationList) {
RoadRelation(roadInformation);
list.add(roadInformation);
}

return JsonResult.success(list);
}

@Override
public JsonResult editInfo(RoadInformation entity) {
// User user = (User) ThreadLocalUtil.get();
// if (StringUtils.isNull(user)) {
// return JsonResult.error("获取不到用户信息");
// }
if(StringUtils.isEmpty(entity.getId())){
//新增
entity.setCreateUser("cw");
entity.setCreateTime(DateUtils.now());
}else {
//更新
entity.setUpdateUser("cw");
entity.setUpdateTime(DateUtils.now());
}
super.edit(entity);

return JsonResult.success();
}

/**
* 判断公路是否关联路段
* @param roadInformation
*/
private void RoadRelation(RoadInformation roadInformation) {
List<Section> sectionList = sectionMapper.selectList(new LambdaQueryWrapper<Section>()
.eq(Section::getMark, 1)
.eq(Section::getTenantId, 1)
.eq(Section::getRoadId, roadInformation.getId()));
if(StringUtils.isNotEmpty(sectionList)){
//公路绑定路段,关联字段设置为true
roadInformation.setRelation(true);
}else {
//公路未绑定路段,关联字段设置为false
roadInformation.setRelation(false);
}
}
}

+ 119
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/SectionServiceImpl.java View File

@@ -0,0 +1,119 @@
package com.tuoheng.admin.service.impl;


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.mapper.RoadInformationMapper;
import com.tuoheng.admin.mapper.SectionMapper;
import com.tuoheng.admin.query.SectionQuery;
import com.tuoheng.admin.service.ISectionService;
import com.tuoheng.admin.vo.SectionInfoVo;
import com.tuoheng.common.core.common.BaseServiceImpl;
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 org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
* @Author ChengWang
* @Date 2022/11/17
*/
@Service
public class SectionServiceImpl extends BaseServiceImpl<SectionMapper, Section> implements ISectionService {

@Autowired
private SectionMapper sectionMapper;

@Autowired
private RoadInformationMapper roadInformationMapper;


@Override
public JsonResult queryPage(SectionQuery query) {
if(null==query.getLimit() && null == query.getPage()){
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL);
}
//获取分页数据
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, 1)
.orderByDesc(Section::getCreateTime));
return JsonResult.success(pageData);
}

@Override
public JsonResult getListInfo(SectionQuery query) {
List<Section> sectionList = sectionMapper.selectList(new LambdaQueryWrapper<Section>()
.eq(Section::getMark, 1)
.eq(Section::getTenantId, 1)
.orderByDesc(Section::getCreateTime));

return JsonResult.success(sectionList);
}

@Override
public JsonResult editInfo(Section entity) {
// User user = (User) ThreadLocalUtil.get();
// if (StringUtils.isNull(user)) {
// return JsonResult.error("获取不到用户信息");
// }
if(StringUtils.isEmpty(entity.getId())){
//新增
entity.setCreateTime(DateUtils.now());
entity.setCreateUser("ca");
}else {
//更新
entity.setUpdateTime(DateUtils.now());
entity.setUpdateUser("ca");
}
super.edit(entity);

return JsonResult.success();
}

@Override
public JsonResult getSectionInfo(String sectionId) {
if(StringUtils.isEmpty(sectionId)){
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL);
}
//根据id查询路段
Section section = sectionMapper.selectOne(Wrappers.<Section>lambdaQuery()
.eq(Section::getMark, 1).eq(Section::getId, sectionId));
String roadId = section.getRoadId();
if(StringUtils.isEmpty(roadId)){
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL);
}
//根据roadId查询对应的公路
RoadInformation roadInformation = roadInformationMapper.selectOne(new LambdaQueryWrapper<RoadInformation>()
.eq(RoadInformation::getId, roadId)
.eq(RoadInformation::getMark, 1));
//获取公路代号
if(StringUtils.isNull(roadInformation)){
return JsonResult.error("对应的公路为空");
}
String code = roadInformation.getCode();
if(StringUtils.isEmpty(code)){
return JsonResult.error("公路代号为空");
}
SectionInfoVo sectionInfoVo = new SectionInfoVo();
BeanUtils.copyProperties(section,sectionInfoVo);
sectionInfoVo.setCode(code);

return JsonResult.success(sectionInfoVo);
}


}

+ 15
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/StructureServiceImpl.java View File

@@ -0,0 +1,15 @@
package com.tuoheng.admin.service.impl;

import com.tuoheng.admin.entity.Structure;
import com.tuoheng.admin.mapper.StructureMapper;
import com.tuoheng.admin.service.IStructureService;
import com.tuoheng.common.core.common.BaseServiceImpl;
import org.springframework.stereotype.Service;

/**
* @Author ChengWang
* @Date 2022/11/17
*/
@Service
public class StructureServiceImpl extends BaseServiceImpl<StructureMapper, Structure> implements IStructureService {
}

+ 61
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/vo/SectionInfoVo.java View File

@@ -0,0 +1,61 @@
package com.tuoheng.admin.vo;


import lombok.Data;

/**
* @Author ChengWang
* @Date 2022/11/17
*/
@Data
public class SectionInfoVo {

/**
* 租户id
*/
private String tenantId;

/**
* 公路id
*/
private String roadId;

/**
* 路段范围
*/
private String sectionRange;

/**
* 起点经度
*/
private String startLongitude;

/**
* 起点纬度
*/
private String startLatitude;

/**
* 终点经度
*/
private String endLongitude;

/**
* 终点纬度
*/
private String endLatitude;

/**
* 备注
*/
private String remark;

/**
* 公路代号
*/
private String code;




}

+ 0
- 86
tuoheng-service/tuoheng-api/src/main/java/com/tuoheng/api/filter/AuthenticationFilter.java View File

@@ -1,86 +0,0 @@
package com.tuoheng.api.filter;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.tuoheng.common.core.constant.SecurityHeadConstant;
import com.tuoheng.common.core.entity.UserEntity;
import com.tuoheng.common.core.utils.EncryptUtil;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.system.feign.feign.UserClient;
import com.tuoheng.system.feign.vo.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* @Author: 吴彬
* @CreateTime: 2022-09-13 08:40
* @Description: 获取gateway携带的身份信息前置过滤器
* @Version: 1.0
*/
@Component
@Slf4j
public class AuthenticationFilter extends OncePerRequestFilter {

@Autowired
private UserClient userClient;

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
String token = request.getHeader(SecurityHeadConstant.JSON_TOKEN);
if (StringUtils.isNotBlank(token)){
String json = EncryptUtil.decodeUTF8StringBase64(token);
JSONObject jsonObject = JSON.parseObject(json);
Object principal = jsonObject.getObject("principal",Object.class);
//获取用户身份信息、权限信息
UserEntity user = null;
String[] authorities = null;
/**
* 判断携带的身份信息是用户实体还是client_id
*/
if(principal instanceof UserEntity){//用户实体
//获取用户身份信息、权限信息
user = (UserEntity)principal;
JSONArray tempJsonArray = jsonObject.getJSONArray("authorities");
authorities = tempJsonArray.toArray(new String[0]);
}else{//client_id
//根据client_id调用system服务获取用户实体信息
JsonResult<UserInfo> result = userClient.getInfoByClientId(principal.toString());
if (result.getCode() != JsonResult.SUCCESS || result.getData() == null || result.getData().getUserEntity() == null) {
log.error("未获取到【{}】对应的用户信息",principal.toString());
//解决response中writer乱码方案
response.setHeader("Content-Type", "application/json;charset=utf-8");
response.getWriter().print(JSON.toJSONString(result, SerializerFeature.WriteMapNullValue));
response.getWriter().flush();
return;
}
user = result.getData().getUserEntity();
authorities = result.getData().getPermissions().toArray(new String[0]);
}
//身份信息、权限信息填充到用户身份token对象中
UsernamePasswordAuthenticationToken authenticationToken=new UsernamePasswordAuthenticationToken(user,null,
AuthorityUtils.createAuthorityList(authorities));
//创建details
authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
//将authenticationToken填充到安全上下文
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
}
filterChain.doFilter(request,response);
}

}

Loading…
Cancel
Save