Browse Source

region and bug fixed

master
zhangyeguang 3 months ago
parent
commit
84b2413220
  1. 2
      common/src/main/java/com/jiagutech/ams/mapper/RegionMapper.java
  2. 2
      common/src/main/java/com/jiagutech/ams/mapper/UserMapper.java
  3. 3
      common/src/main/java/com/jiagutech/ams/model/UserDetail.java
  4. 17
      social/src/main/java/com/jiagutech/ams/controller/RegionController.java
  5. 27
      social/src/main/java/com/jiagutech/ams/event/JobFinishEvent.java
  6. 31
      social/src/main/java/com/jiagutech/ams/listener/JobFinishListener.java
  7. 5
      social/src/main/java/com/jiagutech/ams/model/dto/DeviceDTO.java
  8. 3
      social/src/main/java/com/jiagutech/ams/model/dto/TrackImageDTO.java
  9. 3
      social/src/main/java/com/jiagutech/ams/service/DeviceServiceImpl.java
  10. 18
      social/src/main/java/com/jiagutech/ams/service/JobServiceImpl.java
  11. 9
      social/src/main/java/com/jiagutech/ams/service/RegionService.java
  12. 24
      social/src/main/java/com/jiagutech/ams/service/RegionServiceImpl.java
  13. 15
      system/src/main/java/com/jiagutech/ams/controller/UserController.java
  14. 4
      system/src/main/java/com/jiagutech/ams/model/UserMapping.java
  15. 2
      system/src/main/java/com/jiagutech/ams/model/request/LoginRequest.java
  16. 55
      system/src/main/java/com/jiagutech/ams/model/request/UserFarmerRequest.java
  17. 1
      system/src/main/java/com/jiagutech/ams/model/request/UserRequest.java
  18. 5
      system/src/main/java/com/jiagutech/ams/service/UserService.java
  19. 35
      system/src/main/java/com/jiagutech/ams/service/UserServiceImpl.java
  20. 16
      system/src/main/resources/mapper/UserMapper.xml
  21. 6
      web/pom.xml
  22. 30
      web/src/main/java/com/jiagutech/ams/common/GlobalExceptionHandler.java
  23. 4
      web/src/main/resources/application.yml

2
common/src/main/java/com/jiagutech/ams/mapper/RegionMapper.java

@ -17,7 +17,7 @@ import java.util.List;
* @Version 1.0
* @description:
**/
public interface RegionMapper extends BaseMapper<UserDTO> {
public interface RegionMapper extends BaseMapper<RegionDTO> {
List<RegionDTO> getRegionsByParentCode(@Param("regionCode") long regionCode, @Param("level") int level);

2
common/src/main/java/com/jiagutech/ams/mapper/UserMapper.java

@ -31,4 +31,6 @@ public interface UserMapper extends BaseMapper<UserDTO> {
Page<UserDetail> userPage(Page<UserDetail> page,@Param("ew") QueryWrapper<UserDetail> queryWrapper);
List<UserDetail> selectFarmersByRegionCode(@Param("ew") QueryWrapper<UserDetail> query);
}

3
common/src/main/java/com/jiagutech/ams/model/UserDetail.java

@ -8,6 +8,7 @@ package com.jiagutech.ams.model;
* @description:
**/
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.jiagutech.ams.model.dto.DeptDTO;
@ -19,6 +20,7 @@ import lombok.experimental.Accessors;
public class UserDetail {
@JsonSerialize(using = ToStringSerializer.class)
private Long userId;
@JsonIgnore
private String userName;
private String email;
private String phone;
@ -27,4 +29,5 @@ public class UserDetail {
private Long regionCode;
private String regionName;
private String userIdStr;
private String contactPhone;
}

17
social/src/main/java/com/jiagutech/ams/controller/RegionController.java

@ -1,10 +1,17 @@
package com.jiagutech.ams.controller;
import com.jiagutech.ams.model.common.R;
import com.jiagutech.ams.model.dto.RegionDTO;
import com.jiagutech.ams.service.RegionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @ClassName RegionController
* @author: zhangyeguang
@ -19,4 +26,14 @@ import org.springframework.web.bind.annotation.RestController;
public class RegionController {
private final RegionService regionService;
@Operation(summary = "获取下一级的所有区域列表")
@GetMapping("getChildren")
public R<List<RegionDTO>> getChildren(Long regionCode) {
List<RegionDTO> regionDTOList = regionService.getChildren(regionCode);
return R.ok(regionDTOList);
}
}

27
social/src/main/java/com/jiagutech/ams/event/JobFinishEvent.java

@ -0,0 +1,27 @@
package com.jiagutech.ams.event;
import lombok.Getter;
import lombok.Setter;
import org.springframework.context.ApplicationEvent;
/**
* @ClassName JobFinishEvent
* @author: zhangyeguang
* @create: 2024-09-12 11:15
* @Version 1.0
* @description:
**/
public class JobFinishEvent extends ApplicationEvent {
@Setter
@Getter
private Long jobId;
public JobFinishEvent(Object source, Long jobId) {
super(source);
this.jobId = jobId;
}
}

31
social/src/main/java/com/jiagutech/ams/listener/JobFinishListener.java

@ -0,0 +1,31 @@
package com.jiagutech.ams.listener;
import com.jiagutech.ams.event.JobFinishEvent;
import com.jiagutech.ams.model.TrackItem;
import com.jiagutech.ams.service.JobService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @ClassName JobFinishListener
* @author: zhangyeguang
* @create: 2024-09-12 11:17
* @Version 1.0
* @description:
**/
@Slf4j
@Component
@RequiredArgsConstructor
public class JobFinishListener {
private final JobService jobService;
@EventListener(JobFinishEvent.class)
public void finishJob(JobFinishEvent event) {
log.info("JobFinishListener:{}", event.getJobId());
List<TrackItem> trackList = jobService.getTrackList(event.getJobId());
}
}

5
social/src/main/java/com/jiagutech/ams/model/dto/DeviceDTO.java

@ -1,5 +1,7 @@
package com.jiagutech.ams.model.dto;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@ -14,7 +16,8 @@ import lombok.Data;
@TableName("ams_device_info")
public class DeviceDTO {
private Long id;
@TableId(type = IdType.AUTO)
private Integer id;
private String deviceNum;

3
social/src/main/java/com/jiagutech/ams/model/dto/TrackImageDTO.java

@ -2,6 +2,7 @@ package com.jiagutech.ams.model.dto;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import org.springframework.data.relational.core.sql.In;
/**
* @ClassName TrackImageDTO
@ -16,7 +17,7 @@ public class TrackImageDTO {
private Long id;
private Long deviceId;
private Integer deviceId;
private Long ts;

3
social/src/main/java/com/jiagutech/ams/service/DeviceServiceImpl.java

@ -45,6 +45,9 @@ public class DeviceServiceImpl implements DeviceService {
public List<DeviceInfo> onlineAndRound(double maxLng, double maxLat, double minLng, double minLat) {
Set<String> keys = stringRedisTemplate.keys(TRACK_PREFIX_REDIS_KEY);
List<DeviceInfo> deviceInfos = new ArrayList<>();
DeviceInfo deviceInfo1 = new DeviceInfo().setBoxNum("0").setStatus(2).setDeviceId(321).setBoxNum("5ds3a22w").setLng(118.73929470486111).setLat(31.9823046875);
deviceInfos.add(deviceInfo1);
if (CollectionUtils.isNotEmpty(keys)) {
List<String> values = stringRedisTemplate.opsForValue().multiGet(keys);
List<TrackDataJG> trackDataJGS = JSON.parseArray(JSON.toJSONString(values), TrackDataJG.class);

18
social/src/main/java/com/jiagutech/ams/service/JobServiceImpl.java

@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiagutech.ams.constant.UserConstants;
import com.jiagutech.ams.event.JobFinishEvent;
import com.jiagutech.ams.exception.BizCode;
import com.jiagutech.ams.exception.BusinessException;
import com.jiagutech.ams.mapper.*;
@ -25,9 +26,12 @@ import com.jiagutech.ams.utils.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
@ -57,6 +61,8 @@ public class JobServiceImpl implements JobService {
private final TrackImageMapper trackImageMapper;
private final ApplicationContext applicationContext;
@Override
public JobCreateResponse createJob(JobCreateRequest jobCreateRequest) {
@ -80,7 +86,9 @@ public class JobServiceImpl implements JobService {
public void updateJobStatus(Long jobId, Integer status) {
JobDTO jobDTO = new JobDTO().setId(jobId).setStatus(status).setEndTime(System.currentTimeMillis());
jobMapper.updateById(jobDTO);
if (ObjectUtil.isNotNull(status) && status == 2) {
applicationContext.publishEvent(new JobFinishEvent(this, jobId));
}
}
@ -88,6 +96,7 @@ public class JobServiceImpl implements JobService {
public PageResult<JobItem> getPages(PageRequest<JobPageRequest> pageRequest) {
JobPageRequest requestParam = pageRequest.getRequest();
QueryWrapper<JobItem> queryWrapper = buildQueryWrapper(requestParam);
queryWrapper.orderByDesc("j.start_time");
Page<JobItem> page = new Page(pageRequest.getPageNum(), pageRequest.getPageSize());
Page<JobItem> result = jobMapper.jobPage(page, queryWrapper);
return PageResult.of((int) result.getTotal(), (int) result.getSize(), (int) result.getCurrent(), result.getRecords());
@ -128,12 +137,19 @@ public class JobServiceImpl implements JobService {
if (jobId != null) {
JobDTO job = jobMapper.selectById(jobId);
DeviceDTO deviceDTO = deviceMapper.selectById(job.getDeviceId());
if (ObjectUtil.isEmpty(job) || ObjectUtil.isEmpty(deviceDTO)) {
return Collections.emptyList();
}
List<Locus> locusList = trackRestClient.getTractorByDroneIdAndTime(deviceDTO.getBoxNum(), job.getStartTime(), job.getEndTime());
QueryWrapper<TrackImageDTO> query = Wrappers.query();
List<TrackImageDTO> trackImageDTOS = trackImageMapper.selectList(
query.eq("device_id", job.getDeviceId())
.between("ts", job.getStartTime(), job.getEndTime())
);
if (locusList == null && CollectionUtil.isEmpty(locusList)) {
return Collections.emptyList();
}
List<TrackItem> trackItems = new ArrayList<>(locusList.size());
for (Locus locus : locusList) {
TrackItem trackItem = TrackMapping.INSTANCE.convertToTrackItemByLocus(locus);

9
social/src/main/java/com/jiagutech/ams/service/RegionService.java

@ -0,0 +1,9 @@
package com.jiagutech.ams.service;
import com.jiagutech.ams.model.dto.RegionDTO;
import java.util.List;
public interface RegionService {
List<RegionDTO> getChildren(Long regionCode);
}

24
social/src/main/java/com/jiagutech/ams/service/RegionServiceImpl.java

@ -0,0 +1,24 @@
package com.jiagutech.ams.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jiagutech.ams.mapper.RegionMapper;
import com.jiagutech.ams.model.dto.RegionDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@RequiredArgsConstructor
public class RegionServiceImpl implements RegionService {
private final RegionMapper regionMapper;
@Override
public List<RegionDTO> getChildren(Long regionCode) {
QueryWrapper<RegionDTO> query = Wrappers.query();
return regionMapper.selectList(query.eq("parent_code", regionCode).orderByAsc("region_code"));
}
}

15
system/src/main/java/com/jiagutech/ams/controller/UserController.java

@ -8,6 +8,7 @@ import com.jiagutech.ams.model.common.PageResult;
import com.jiagutech.ams.model.common.R;
import com.jiagutech.ams.model.request.LoginRequest;
import com.jiagutech.ams.model.request.PageUserRequest;
import com.jiagutech.ams.model.request.UserFarmerRequest;
import com.jiagutech.ams.model.request.UserRequest;
import com.jiagutech.ams.model.response.LoginResponse;
import com.jiagutech.ams.model.UserDetail;
@ -61,6 +62,7 @@ public class UserController {
@RequestParam(value = "phone", required = false) String phone) {
return R.ok(userService.getUserDetail(userId, phone));
}
@Operation(summary = "更新用户信息")
@PutMapping("/update")
public R<Void> updateUser(@Validated @RequestBody UserRequest user) {
@ -68,9 +70,22 @@ public class UserController {
return R.ok();
}
@Operation(summary = "更新农户人员信息")
@PutMapping("/updateFarmer")
public R<Void> updateFarmerUser(@Validated @RequestBody UserFarmerRequest user) {
userService.updateFarmerUser(user);
return R.ok();
}
@Operation(summary = "分页获取用户列表")
@PostMapping("/page")
public R<PageResult<UserDetail>> getUserList(@RequestBody PageRequest<PageUserRequest> pageRequest) {
return R.ok(userService.getUserPage(pageRequest));
}
@Operation(summary = "根据区域码获取农户列表")
@GetMapping("/listFarmerByRegionCode")
public R<List<UserDetail>> getAllFarmersByRegionCode(Long regionCode) {
return R.ok(userService.getAllFarmersByRegionCode(regionCode));
}
}

4
system/src/main/java/com/jiagutech/ams/model/UserMapping.java

@ -1,6 +1,7 @@
package com.jiagutech.ams.model;
import com.jiagutech.ams.model.dto.UserDTO;
import com.jiagutech.ams.model.request.UserFarmerRequest;
import com.jiagutech.ams.model.request.UserRequest;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
@ -21,6 +22,9 @@ public interface UserMapping {
@Mapping(source = "userId", target = "id")
UserDTO userToUserDTO(UserRequest user);
@Mapping(source = "userId", target = "id")
UserDTO userFarmerToUserDTO(UserFarmerRequest userFarmer);
LoginUser userDTOToLoginUser(UserDTO userDTO);
}

2
system/src/main/java/com/jiagutech/ams/model/request/LoginRequest.java

@ -54,6 +54,6 @@ public class LoginRequest implements Serializable {
private String phone;
private Integer clientType = 1;
private int clientType = 1;
}

55
system/src/main/java/com/jiagutech/ams/model/request/UserFarmerRequest.java

@ -0,0 +1,55 @@
package com.jiagutech.ams.model.request;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.jiagutech.ams.utils.StringToLongDeserializer;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Data;
/**
* @ClassName UserRequest
* @author: zhangyeguang
* @create: 2024-08-31 10:00
* @Version 1.0
* @description:
**/
@Data
public class UserFarmerRequest {
/**
* 用户ID
*/
private Long userId;
/**
* 用户昵称
*/
@Size(min = 2, max = 30, message = "用户昵称长度不能超过{max}个字符")
private String nickName;
/**
* 用户邮箱
*/
@Email(message = "邮箱格式不正确")
@Size(min = 0, max = 50, message = "邮箱长度不能超过{max}个字符")
private String email;
/**
* 手机号码
*/
@Pattern(regexp = "^1[34578]\\d{9}$", message = "手机号码格式不正确")
private String phone;
/**
* 密码
*/
private String password;
private Long regionCode;
private String contactPhone;
}

1
system/src/main/java/com/jiagutech/ams/model/request/UserRequest.java

@ -39,7 +39,6 @@ public class UserRequest {
/**
* 用户昵称
*/
@NotBlank(message = "用户昵称不能为空")
@Size(min = 2, max = 30, message = "用户昵称长度不能超过{max}个字符")
private String nickName;

5
system/src/main/java/com/jiagutech/ams/service/UserService.java

@ -6,6 +6,7 @@ import com.jiagutech.ams.model.common.PageRequest;
import com.jiagutech.ams.model.common.PageResult;
import com.jiagutech.ams.model.request.LoginRequest;
import com.jiagutech.ams.model.request.PageUserRequest;
import com.jiagutech.ams.model.request.UserFarmerRequest;
import com.jiagutech.ams.model.request.UserRequest;
import com.jiagutech.ams.model.response.LoginResponse;
@ -21,7 +22,11 @@ public interface UserService {
void updateUser(UserRequest user);
void updateFarmerUser(UserFarmerRequest userFarmer);
List<UserDetail> getUserList(String roleKey);
PageResult<UserDetail> getUserPage(PageRequest<PageUserRequest> pageRequest);
List<UserDetail> getAllFarmersByRegionCode(Long regionCode);
}

35
system/src/main/java/com/jiagutech/ams/service/UserServiceImpl.java

@ -27,6 +27,7 @@ import com.jiagutech.ams.model.dto.UserDeptDTO;
import com.jiagutech.ams.model.dto.UserRoleDTO;
import com.jiagutech.ams.model.request.LoginRequest;
import com.jiagutech.ams.model.request.PageUserRequest;
import com.jiagutech.ams.model.request.UserFarmerRequest;
import com.jiagutech.ams.model.request.UserRequest;
import com.jiagutech.ams.model.response.LoginResponse;
import lombok.RequiredArgsConstructor;
@ -64,10 +65,15 @@ public class UserServiceImpl implements UserService {
String password = loginRequest.getPassword();
String code = loginRequest.getCode();
String uuid = loginRequest.getUuid();
// validateCaptcha(code, uuid);
if (loginRequest.getClientType() == 1) {
validateCaptcha(code, uuid);
}
Integer clientType = loginRequest.getClientType();
LoginUser user = userMapper.selectLoginUserByPhone(phone);
if (user == null) {
throw new BusinessException(BizCode.USER_NOT_FOUND);
}
Predicate<RoleDTO> predicate = role -> role.getKey().equals("manager") || role.getKey().equals("machinist");
if (clientType == 2 && user.getRoles().stream().noneMatch(predicate)) {
throw new BusinessException(BizCode.LOGIN_TYPE_ERROR);
@ -77,6 +83,7 @@ public class UserServiceImpl implements UserService {
throw new BusinessException(BizCode.PASSWORD_ERROR);
}
StpUtil.login(user.getUserId());
user.setLoginTime(System.currentTimeMillis());
StpUtil.getSession().set(UserConstants.SYS_SESSION, user);
LoginResponse loginVO = new LoginResponse();
loginVO.setAccessToken(StpUtil.getTokenValue());
@ -111,10 +118,22 @@ public class UserServiceImpl implements UserService {
@Override
public void updateUser(UserRequest user) {
UserDTO userDTO = UserMapping.INSTANCE.userToUserDTO(user);
if (StringUtils.isNotBlank(user.getPassword())) {
userDTO.setPassword(BCrypt.hashpw(user.getPassword()));
}
userMapper.updateById(userDTO);
updateUserRoleAndDept(user);
}
@Override
public void updateFarmerUser(UserFarmerRequest userFarmer) {
UserDTO userDTO = UserMapping.INSTANCE.userFarmerToUserDTO(userFarmer);
if (StringUtils.isNotBlank(userFarmer.getPassword())) {
userDTO.setPassword(BCrypt.hashpw(userFarmer.getPassword()));
}
userMapper.updateById(userDTO);
}
private void insertUserRoleAndDept(UserDTO user, String roleKey, Long deptId) {
if (StringUtils.isNotBlank(roleKey)) {
userRoleMapper.insertUserRole(user.getId(), roleKey);
@ -154,6 +173,18 @@ public class UserServiceImpl implements UserService {
return PageResult.of((int) result.getTotal(), (int) result.getSize(), (int) result.getCurrent(), result.getRecords());
}
@Override
public List<UserDetail> getAllFarmersByRegionCode(Long regionCode) {
QueryWrapper<UserDetail> query = Wrappers.query();
query.eq("u.region_code", regionCode);
query.eq("u.del_flag", 0);
query.eq("r.key", "farmer");
return userMapper.selectFarmersByRegionCode(query);
}
private QueryWrapper<UserDetail> buildQueryWrapper(PageUserRequest requestParam) {
QueryWrapper<UserDetail> queryWrapper = new QueryWrapper<>();
if (requestParam != null) {

16
system/src/main/resources/mapper/UserMapper.xml

@ -64,7 +64,7 @@
</select>
<select id="getUsersByLikeRegionPath" resultType="UserDTO">
<select id="getUsersByLikeRegionPath" resultType="com.jiagutech.ams.model.dto.UserDTO">
select id, nick_name, region_code
from ams_user
where region_path like CONCAT(#{regionPath}, '%')
@ -85,5 +85,19 @@
left join ams_user_dept ud on u.id=ud.user_id
${ew.getCustomSqlSegment}
</select>
<select id="selectFarmersByRegionCode" resultType="com.jiagutech.ams.model.UserDetail">
select u.id as user_id,
u.username,
u.nick_name,
u.email,
u.phone,
u.create_time,
u.avatar,
u.region_code
from ams_user u
left join ams_user_role ur on u.id = ur.user_id
left join ams_role r on ur.role_id = r.id
${ew.getCustomSqlSegment}
</select>
</mapper>

6
web/pom.xml

@ -84,9 +84,13 @@
</dependency>
<!-- <dependency>-->
<!-- <groupId>cn.dev33</groupId>-->
<!-- <artifactId>sa-token-redis</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-redis</artifactId>
<artifactId>sa-token-redis-jackson</artifactId>
</dependency>
<!-- 添加 MapStruct 依赖 -->
<dependency>

30
web/src/main/java/com/jiagutech/ams/common/GlobalExceptionHandler.java

@ -8,6 +8,8 @@ import com.jiagutech.ams.exception.BizCode;
import com.jiagutech.ams.exception.BusinessException;
import com.jiagutech.ams.model.common.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindException;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
@ -24,51 +26,51 @@ import java.util.Map;
public class GlobalExceptionHandler {
@ExceptionHandler(BindException.class)
public R handleBindExceptions(BindException ex) {
public ResponseEntity<R> handleBindExceptions(BindException ex) {
log.error("参数绑定失败", ex);
Map<String, String> errorMap = new HashMap<>();
for (FieldError fieldError : ex.getFieldErrors()) {
errorMap.put(fieldError.getField(), fieldError.getDefaultMessage());
}
return R.fail(BizCode.General_ParameterInvalid.getCode(), JSON.toJSONString(errorMap));
return new ResponseEntity<>(R.fail(BizCode.General_ParameterInvalid.getCode(), JSON.toJSONString(errorMap)), HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(MethodArgumentNotValidException.class)
public R handleValidationExceptions(MethodArgumentNotValidException ex) {
public ResponseEntity<R> handleValidationExceptions(MethodArgumentNotValidException ex) {
log.error("参数校验失败", ex);
Map<String, String> errorMap = new HashMap<>();
for (FieldError fieldError : ex.getBindingResult().getFieldErrors()) {
errorMap.put(fieldError.getField(), fieldError.getDefaultMessage());
}
return R.fail(BizCode.General_ParameterInvalid.getCode(), JSON.toJSONString(errorMap));
return new ResponseEntity<>(R.fail(BizCode.General_ParameterInvalid.getCode(), JSON.toJSONString(errorMap)), HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(BusinessException.class)
public R handleBusinessException(BusinessException ex) {
return R.fail(ex.getCode(), ex.getMessage());
public ResponseEntity<R> handleBusinessException(BusinessException ex) {
return new ResponseEntity<>(R.fail(ex.getCode(), ex.getMessage()), HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
public R handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException ex) {
public ResponseEntity<R> handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException ex) {
log.error("参数类型错误", ex);
return R.fail(new BusinessException("参数类型错误"));
return new ResponseEntity<>(R.fail(new BusinessException("参数类型错误")), HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(NotLoginException.class)
public R handleLoginException(Exception ex) {
public ResponseEntity<R> handleLoginException(Exception ex) {
log.error("系统异常", ex);
return R.fail(BizCode.USER_NOT_LOGIN.getCode(), BizCode.USER_NOT_LOGIN.getMsg());
return new ResponseEntity<>(R.fail(BizCode.USER_NOT_LOGIN.getCode(), BizCode.USER_NOT_LOGIN.getMsg()), HttpStatus.UNAUTHORIZED);
}
@ExceptionHandler(NotRoleException.class)
public R handlePermissionException(Exception ex) {
public ResponseEntity<R> handlePermissionException(Exception ex) {
log.error("鉴权失败", ex);
return R.fail(BizCode.PERMISSION_NOT_FOUND.getCode(), BizCode.PERMISSION_NOT_FOUND.getMsg());
return new ResponseEntity<>(R.fail(BizCode.PERMISSION_NOT_FOUND.getCode(), BizCode.PERMISSION_NOT_FOUND.getMsg()), HttpStatus.FORBIDDEN);
}
@ExceptionHandler(SQLIntegrityConstraintViolationException.class)
public R handleDuplicateException(Exception ex){
public ResponseEntity<R> handleDuplicateException(Exception ex) {
log.error("数据重复", ex);
return R.fail(BizCode.USER_PHONE_EXIST.getCode(), BizCode.USER_PHONE_EXIST.getMsg());
return new ResponseEntity<>(R.fail(BizCode.USER_PHONE_EXIST.getCode(), BizCode.USER_PHONE_EXIST.getMsg()), HttpStatus.BAD_REQUEST);
}
}

4
web/src/main/resources/application.yml

@ -21,9 +21,9 @@ spring:
# 空闲连接存活最大时间,默认10分钟
idleTimeout: 600000
# 此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认30分钟
maxLifetime: 1800000
maxLifetime: 600000
# 多久检查一次连接的活性
keepaliveTime: 30000
keepaliveTime: 60000
connection-test-query: SELECT 1
data:
redis:

Loading…
Cancel
Save