package com.tuoheng.admin.config; | package com.tuoheng.admin.config; | ||||
import com.tuoheng.admin.interceptor.UserInterceptor; | |||||
import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
import org.springframework.context.annotation.Bean; | import org.springframework.context.annotation.Bean; | ||||
import org.springframework.context.annotation.Configuration; | import org.springframework.context.annotation.Configuration; | ||||
* @Date 2022/10/31 14:06 | * @Date 2022/10/31 14:06 | ||||
*/ | */ | ||||
//web相关配置 | //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异常处理的默认请求 | |||||
// | |||||
// ); | |||||
// } | |||||
//} |
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); | |||||
} | |||||
} |
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); | |||||
} | |||||
} |
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; | |||||
} |
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; | |||||
} |
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; | |||||
} |
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; | |||||
} |
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; | |||||
} |
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; | |||||
} |
import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||
import javax.servlet.http.HttpServletResponse; | 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内存完毕"); | |||||
// } | |||||
//} | |||||
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> { | |||||
} |
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> { | |||||
} |
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> { | |||||
} |
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 { | |||||
} |
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 { | |||||
} |
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); | |||||
} |
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> { | |||||
} |
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); | |||||
} |
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); | |||||
} | |||||
} | |||||
} |
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); | |||||
} | |||||
} |
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 { | |||||
} |
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; | |||||
} |
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); | |||||
} | |||||
} |