|
@@ -8,11 +8,14 @@ import com.qmrb.system.common.exception.BusinessException;
|
|
|
import com.qmrb.system.common.result.PageResult;
|
|
|
import com.qmrb.system.common.result.Result;
|
|
|
import com.qmrb.system.common.result.ResultCode;
|
|
|
+import com.qmrb.system.framework.security.util.SecurityUtils;
|
|
|
import com.qmrb.system.pojo.entity.MyCarPlateNumber;
|
|
|
+import com.qmrb.system.pojo.entity.UserPlateNumRelHis;
|
|
|
import com.qmrb.system.pojo.form.MyCarPlateNumberForm;
|
|
|
import com.qmrb.system.pojo.query.MyCarPlateNumberQuery;
|
|
|
import com.qmrb.system.pojo.vo.MyCarPlateNumberVO;
|
|
|
import com.qmrb.system.service.IMyCarPlateNumberService;
|
|
|
+import com.qmrb.system.service.IUserPlateNumRelHisService;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
|
@@ -24,8 +27,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -45,6 +50,9 @@ public class MyCarPlateNumberController{
|
|
|
|
|
|
@Autowired
|
|
|
private IMyCarPlateNumberService myCarPlateNumberService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IUserPlateNumRelHisService userPlateNumRelHisService;
|
|
|
|
|
|
@Operation(summary = "我的车牌分页列表", security = {@SecurityRequirement(name = "Authorization")})
|
|
|
@GetMapping("/page")
|
|
@@ -61,9 +69,10 @@ public class MyCarPlateNumberController{
|
|
|
public PageResult<MyCarPlateNumberVO> getPageByUserId(
|
|
|
@ParameterObject MyCarPlateNumberQuery queryParams
|
|
|
) {
|
|
|
- if(queryParams.getUserId() == null){
|
|
|
- throw new BusinessException("用户id不能为空");
|
|
|
+ if(SecurityUtils.getUserId() == null){
|
|
|
+ return PageResult.success(null);
|
|
|
}
|
|
|
+ queryParams.setUserId(SecurityUtils.getUserId());
|
|
|
Page<MyCarPlateNumberVO> result = myCarPlateNumberService.getPage(queryParams);
|
|
|
return PageResult.success(result);
|
|
|
}
|
|
@@ -73,15 +82,30 @@ public class MyCarPlateNumberController{
|
|
|
public Result<MyCarPlateNumberForm> saveForm(
|
|
|
@RequestBody @Valid MyCarPlateNumberForm form
|
|
|
) {
|
|
|
+ form.setUserId(SecurityUtils.getUserId());
|
|
|
log.info("user_id:"+form.getUserId());
|
|
|
log.info("plateNumber:"+form.getPlateNumber());
|
|
|
log.info("cardType:"+form.getCarType());
|
|
|
- if(form.getUserId() == null){
|
|
|
+ if(SecurityUtils.getUserId() == null){
|
|
|
return Result.failed("用户id不能为空");
|
|
|
}
|
|
|
List<MyCarPlateNumber> list = myCarPlateNumberService.list(new LambdaQueryWrapper<MyCarPlateNumber>().eq(MyCarPlateNumber::getUserId, form.getUserId()));
|
|
|
if(CollectionUtil.isNotEmpty(list)){
|
|
|
myCarPlateNumberService.removeByIds(list);
|
|
|
+ Set<String> plateNumberSet = list.stream().map(item -> {
|
|
|
+ return item.getPlateNumber();
|
|
|
+ }).collect(Collectors.toSet());
|
|
|
+ // 删除之前已存在的历史记录
|
|
|
+ userPlateNumRelHisService.remove(new LambdaQueryWrapper<UserPlateNumRelHis>().in(UserPlateNumRelHis::getPlateNumber,plateNumberSet).eq(UserPlateNumRelHis::getUserId,form.getUserId()));
|
|
|
+ ArrayList<UserPlateNumRelHis> hisPlateNumberList = new ArrayList<>();
|
|
|
+ //添加到历史车牌中
|
|
|
+ for (MyCarPlateNumber myCarPlateNumber : list) {
|
|
|
+ UserPlateNumRelHis userPlateNumRelHis = new UserPlateNumRelHis();
|
|
|
+ userPlateNumRelHis.setUserId(myCarPlateNumber.getUserId());
|
|
|
+ userPlateNumRelHis.setPlateNumber(myCarPlateNumber.getPlateNumber());
|
|
|
+ hisPlateNumberList.add(userPlateNumRelHis);
|
|
|
+ }
|
|
|
+ userPlateNumRelHisService.saveBatch(hisPlateNumberList);
|
|
|
}
|
|
|
MyCarPlateNumberForm result = myCarPlateNumberService.saveForm(form);
|
|
|
return Result.success(result);
|
|
@@ -97,14 +121,13 @@ public class MyCarPlateNumberController{
|
|
|
}
|
|
|
|
|
|
@Operation(summary = "我的车牌表单数据", security = {@SecurityRequirement(name = "Authorization")})
|
|
|
- @GetMapping("/{userId}/formByUserId")
|
|
|
+ @GetMapping("/formByUserId")
|
|
|
public Result<?> getFormByUserId(
|
|
|
- @Parameter(description = "用户ID") @PathVariable Long userId
|
|
|
) {
|
|
|
- if(userId == null){
|
|
|
+ if(SecurityUtils.getUserId() == null){
|
|
|
return Result.failed("用户id不能为空");
|
|
|
}
|
|
|
- List<MyCarPlateNumber> list = myCarPlateNumberService.list(new LambdaQueryWrapper<MyCarPlateNumber>().eq(MyCarPlateNumber::getUserId, userId));
|
|
|
+ List<MyCarPlateNumber> list = myCarPlateNumberService.list(new LambdaQueryWrapper<MyCarPlateNumber>().eq(MyCarPlateNumber::getUserId, SecurityUtils.getUserId()));
|
|
|
return Result.success(list);
|
|
|
}
|
|
|
|
|
@@ -129,7 +152,27 @@ public class MyCarPlateNumberController{
|
|
|
// 逻辑删除
|
|
|
List<Long> idList = Arrays.asList(ids.split(",")).stream()
|
|
|
.map(idStr -> Long.parseLong(idStr)).collect(Collectors.toList());
|
|
|
+ List<MyCarPlateNumber> list = myCarPlateNumberService.listByIds(idList);
|
|
|
boolean result = myCarPlateNumberService.removeByIds(idList);
|
|
|
+
|
|
|
+ if(CollectionUtil.isNotEmpty(list)){
|
|
|
+
|
|
|
+ Set<String> plateNumberSet = list.stream().map(item -> {
|
|
|
+ return item.getPlateNumber();
|
|
|
+ }).collect(Collectors.toSet());
|
|
|
+ // 删除之前已存在的历史记录
|
|
|
+ userPlateNumRelHisService.remove(new LambdaQueryWrapper<UserPlateNumRelHis>().in(UserPlateNumRelHis::getPlateNumber,plateNumberSet).eq(UserPlateNumRelHis::getUserId, SecurityUtils.getUserId()));
|
|
|
+ ArrayList<UserPlateNumRelHis> hisPlateNumberList = new ArrayList<>();
|
|
|
+ //添加到历史车牌中
|
|
|
+ for (MyCarPlateNumber myCarPlateNumber : list) {
|
|
|
+ UserPlateNumRelHis userPlateNumRelHis = new UserPlateNumRelHis();
|
|
|
+ userPlateNumRelHis.setUserId(myCarPlateNumber.getUserId());
|
|
|
+ userPlateNumRelHis.setPlateNumber(myCarPlateNumber.getPlateNumber());
|
|
|
+ hisPlateNumberList.add(userPlateNumRelHis);
|
|
|
+ }
|
|
|
+ userPlateNumRelHisService.saveBatch(hisPlateNumberList);
|
|
|
+ }
|
|
|
+
|
|
|
return Result.judge(result);
|
|
|
}
|
|
|
|