Commit affff088 by 章家宝

feat:检测工单 绑定改为批量绑定,解绑也是

1 parent c17f48a5
...@@ -9,6 +9,7 @@ import com.glsx.usedcar.module.inspect.entity.InspectionReport; ...@@ -9,6 +9,7 @@ import com.glsx.usedcar.module.inspect.entity.InspectionReport;
import com.glsx.usedcar.module.inspect.service.InspectionReportService; import com.glsx.usedcar.module.inspect.service.InspectionReportService;
import com.glsx.usedcar.module.inspect.vo.*; import com.glsx.usedcar.module.inspect.vo.*;
import com.glsx.usedcar.module.security.entity.User; import com.glsx.usedcar.module.security.entity.User;
import com.glsx.usedcar.req.CommonLongIdListReq;
import com.glsx.usedcar.resp.BaseResp; import com.glsx.usedcar.resp.BaseResp;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
...@@ -86,14 +87,14 @@ public class InspectionReportController { ...@@ -86,14 +87,14 @@ public class InspectionReportController {
} }
@Operation(summary = "检测报告绑定", description = "绑定报告到车辆(同一车辆仅允许绑定一个报告)") @Operation(summary = "检测报告绑定", description = "绑定报告到车辆(同一车辆仅允许绑定一个报告)")
@GetMapping("/bind/{id}") @PostMapping("/bind")
public BaseResp<Void> bind( public BaseResp<Void> bind(
@Parameter(description = "检测报告ID", required = true) @PathVariable("id") Long id, @Valid @RequestBody CommonLongIdListReq req,
Authentication authentication) { Authentication authentication) {
log.info("【接口请求】检测报告绑定,操作人={},报告ID={}", getUserName(authentication), id); log.info("【接口请求】检测报告绑定,操作人={},报告ID={}", getUserName(authentication), req.getIdList());
try { try {
User user = (User) authentication.getPrincipal(); User user = (User) authentication.getPrincipal();
inspectionReportService.bindInspectionReport(id, (long)user.getUserId(), user.getUserName(), InspectionPlatTypeEnum.BACKEND.getCode()); inspectionReportService.bindInspectionReport(req.getIdList(), (long)user.getUserId(), user.getUserName(), InspectionPlatTypeEnum.BACKEND.getCode());
return BaseResp.success(); return BaseResp.success();
} catch (BusinessCodeException be) { } catch (BusinessCodeException be) {
log.error("【接口响应】检测报告绑定失败!操作人={},业务异常!", getUserName(authentication), be); log.error("【接口响应】检测报告绑定失败!操作人={},业务异常!", getUserName(authentication), be);
...@@ -105,14 +106,14 @@ public class InspectionReportController { ...@@ -105,14 +106,14 @@ public class InspectionReportController {
} }
@Operation(summary = "检测报告解绑", description = "解除报告与车辆的绑定关系") @Operation(summary = "检测报告解绑", description = "解除报告与车辆的绑定关系")
@GetMapping("/unbind/{id}") @PostMapping("/unbind")
public BaseResp<Void> unbind( public BaseResp<Void> unbind(
@Parameter(description = "检测报告ID", required = true) @PathVariable("id") Long id, @Valid @RequestBody CommonLongIdListReq req,
Authentication authentication) { Authentication authentication) {
log.info("【接口请求】检测报告解绑,操作人={},报告ID={}", getUserName(authentication), id); log.info("【接口请求】检测报告解绑,操作人={},报告ID={}", getUserName(authentication), req.getIdList());
try { try {
User user = (User) authentication.getPrincipal(); User user = (User) authentication.getPrincipal();
inspectionReportService.unbindInspectionReport(id, (long)user.getUserId(), user.getUserName(), InspectionPlatTypeEnum.BACKEND.getCode()); inspectionReportService.unbindInspectionReport(req.getIdList(), (long)user.getUserId(), user.getUserName(), InspectionPlatTypeEnum.BACKEND.getCode());
return BaseResp.success(); return BaseResp.success();
} catch (BusinessCodeException be) { } catch (BusinessCodeException be) {
log.error("【接口响应】检测报告解绑失败!操作人={},业务异常!", getUserName(authentication), be); log.error("【接口响应】检测报告解绑失败!操作人={},业务异常!", getUserName(authentication), be);
......
...@@ -53,9 +53,13 @@ public interface JpaQueryConstants { ...@@ -53,9 +53,13 @@ public interface JpaQueryConstants {
* 关键字,检测师名称或手机号,模糊查询 * 关键字,检测师名称或手机号,模糊查询
*/ */
String KEYWORD = "keyword"; String KEYWORD = "keyword";
/**
* 关键字,检测师名称或手机号,模糊查询
*/
String INSPECTOR_ID = "inspectorId";
/** /**
* 账号状态,精确匹配 * 精确匹配
*/ */
String STATUS = "status"; String STATUS = "status";
......
...@@ -269,9 +269,9 @@ public class InspectionReportService { ...@@ -269,9 +269,9 @@ public class InspectionReportService {
* 绑定检测报告(接收操作人参数,核心规则:同一车辆仅绑定一个报告) * 绑定检测报告(接收操作人参数,核心规则:同一车辆仅绑定一个报告)
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void bindInspectionReport(Long id, Long operatorId, String operatorName, Integer platType) { public void bindInspectionReport(List<Long> idList, Long operatorId, String operatorName, Integer platType) {
log.info("【报告绑定】操作人={},开始处理,报告ID={}", operatorName, id); List<String> bindSourceNoList = new ArrayList<>();
for (Long id : idList) {
// 1. 查找报告并校验 // 1. 查找报告并校验
InspectionReport report = inspectionReportRepository.findById(id) InspectionReport report = inspectionReportRepository.findById(id)
.orElseThrow(() -> new BusinessCodeException(ErrorCodeEnum.DATA_NOT_EXIST, "检测报告不存在,ID:" + id)); .orElseThrow(() -> new BusinessCodeException(ErrorCodeEnum.DATA_NOT_EXIST, "检测报告不存在,ID:" + id));
...@@ -279,20 +279,23 @@ public class InspectionReportService { ...@@ -279,20 +279,23 @@ public class InspectionReportService {
// 已绑定则直接返回 // 已绑定则直接返回
if (Objects.equals(report.getBindStatus(), 1)) { if (Objects.equals(report.getBindStatus(), 1)) {
log.info("【报告绑定】操作人={},报告已绑定,无需重复操作,报告编号={}", operatorName, report.getReportNo()); log.info("【报告绑定】操作人={},报告已绑定,无需重复操作,报告编号={}", operatorName, report.getReportNo());
return; continue;
} }
// 2. 检查该车辆是否已绑定其他报告 // 2. 检查该车辆是否已绑定其他报告
Vehicle vehicle = report.getVehicle(); Vehicle vehicle = report.getVehicle();
List<InspectionReport> bindedReports = inspectionReportRepository.findByVehicleAndBindStatusAndDeleteFlag( List<InspectionReport> bindedReports = inspectionReportRepository.findByVehicleAndBindStatusAndDeleteFlag(vehicle, 1, DeleteFlag.NOT_DELETED.getCode());
vehicle, 1, DeleteFlag.NOT_DELETED.getCode()
);
if (!bindedReports.isEmpty()) { if (!bindedReports.isEmpty()) {
String bindedReportNos = bindedReports.stream().map(InspectionReport::getReportNo).reduce((a, b) -> a + "," + b).get(); bindSourceNoList.add(vehicle.getBaseInfo().getSourceNo());
throw new BusinessCodeException(ErrorCodeEnum.OPERATION_ERROR, continue;
String.format("该车辆已绑定其他检测报告(报告编号:%s),不允许重复绑定", bindedReportNos));
} }
bindInspectionReport(report, vehicle, operatorId, operatorName, platType);
}
if (!bindSourceNoList.isEmpty()) {
throw new BusinessCodeException(ErrorCodeEnum.VEHICLE_ALREADY_BIND, String.join(",", bindSourceNoList));
}
}
private void bindInspectionReport(InspectionReport report, Vehicle vehicle, Long operatorId, String operatorName, Integer platType) {
log.info("【报告绑定】操作人={},开始处理,报告ID={}", operatorName, report.getId());
// 3. 保存绑定前的原始数据 // 3. 保存绑定前的原始数据
String originalData = ""; String originalData = "";
try { try {
...@@ -325,7 +328,12 @@ public class InspectionReportService { ...@@ -325,7 +328,12 @@ public class InspectionReportService {
* 解绑检测报告(接收操作人参数) * 解绑检测报告(接收操作人参数)
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void unbindInspectionReport(Long id, Long operatorId, String operatorName, Integer platType) { public void unbindInspectionReport(List<Long> idList, Long operatorId, String operatorName, Integer platType) {
idList.forEach(reportId -> {
unbindInspectionReport(reportId, operatorId, operatorName, platType);
});
}
private void unbindInspectionReport(Long id, Long operatorId, String operatorName, Integer platType) {
log.info("【报告解绑】操作人={},开始处理,报告ID={}", operatorName, id); log.info("【报告解绑】操作人={},开始处理,报告ID={}", operatorName, id);
// 1. 查找报告并校验 // 1. 查找报告并校验
......
...@@ -281,9 +281,9 @@ public class InspectionWorkOrderService { ...@@ -281,9 +281,9 @@ public class InspectionWorkOrderService {
} }
public Page<InspectionWORespVO> pageList(Pagination<InspectionWorkOrder> pagination) { public Page<InspectionWORespVO> pageList(Pagination<InspectionWorkOrder> pagination) {
Object keyword = pagination.getFilterValueOrElseNull(JpaQueryConstants.Inspector.KEYWORD); Object keyword = pagination.getFilterValueOrElseNull(JpaQueryConstants.InspectionWorkOrder.KEYWORD);
if (keyword instanceof String kw && StrUtil.isNotBlank(kw)) { if (keyword instanceof String kw && StrUtil.isNotBlank(kw)) {
pagination.removeFilter(JpaQueryConstants.Inspector.KEYWORD); pagination.removeFilter(JpaQueryConstants.InspectionWorkOrder.KEYWORD);
String likePattern = SymbolConsts.PERCENT + kw + SymbolConsts.PERCENT; String likePattern = SymbolConsts.PERCENT + kw + SymbolConsts.PERCENT;
pagination.addCondition((root, query, builder) -> builder.or( pagination.addCondition((root, query, builder) -> builder.or(
// 工单表:woId // 工单表:woId
...@@ -295,6 +295,11 @@ public class InspectionWorkOrderService { ...@@ -295,6 +295,11 @@ public class InspectionWorkOrderService {
// 车辆表:baseInfo.vin // 车辆表:baseInfo.vin
builder.like(root.get(InspectionWorkOrder_.vehicle).get(Vehicle_.baseInfo).get(BaseInfo_.vin), likePattern))); builder.like(root.get(InspectionWorkOrder_.vehicle).get(Vehicle_.baseInfo).get(BaseInfo_.vin), likePattern)));
} }
Object inspectorId = pagination.getFilterValueOrElseNull(JpaQueryConstants.InspectionWorkOrder.INSPECTOR_ID);
if (inspectorId != null) {
pagination.removeFilter(JpaQueryConstants.InspectionWorkOrder.INSPECTOR_ID);
pagination.addCondition((root, query, builder) -> builder.equal(root.get(InspectionWorkOrder_.inspector).get(Inspector_.id), inspectorId));
}
Page<InspectionWorkOrder> resultPage = inspectionWorkOrderRepository.findAll(pagination, pagination.getPageRequest()); Page<InspectionWorkOrder> resultPage = inspectionWorkOrderRepository.findAll(pagination, pagination.getPageRequest());
return resultPage.map(inspectionWorkOrderConverter::inspectorMapRespVO); return resultPage.map(inspectionWorkOrderConverter::inspectorMapRespVO);
} }
......
package com.glsx.usedcar.req;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Size;
import lombok.Data;
import java.util.List;
/**
* 通用的id列表请求参数
*/
@Data
public class CommonLongIdListReq {
@Size(min = 1)
@Schema(description = "id列表", example = "[1,2,3]")
private List<Long> idList;
}
package com.glsx.usedcar.req;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* 通用的id列表请求参数
*/
@Data
public class CommonLongIdReq {
@Schema(description = "id", example = "3")
private Long id;
}
...@@ -33,6 +33,7 @@ public enum ErrorCodeEnum { ...@@ -33,6 +33,7 @@ public enum ErrorCodeEnum {
VEHICLE_ALREADY_INSPECTED(1001006, "车辆已经创建检测工单"), VEHICLE_ALREADY_INSPECTED(1001006, "车辆已经创建检测工单"),
OPERATION_ERROR(1001007, "已绑定的检测报告不允许删除"), OPERATION_ERROR(1001007, "已绑定的检测报告不允许删除"),
DATA_NOT_FOUND(1001008, "{0}"), DATA_NOT_FOUND(1001008, "{0}"),
VEHICLE_ALREADY_BIND(1001009, "{0}"),
/* 检测模版 */ /* 检测模版 */
......
...@@ -48,7 +48,8 @@ public class InspectionWorkOrderController { ...@@ -48,7 +48,8 @@ public class InspectionWorkOrderController {
int page = req.getPage() == null || req.getPage() < 1 ? 1 : req.getPage(); int page = req.getPage() == null || req.getPage() < 1 ? 1 : req.getPage();
int size = req.getSize() == null || req.getSize() < 1 ? 20 : req.getSize(); int size = req.getSize() == null || req.getSize() < 1 ? 20 : req.getSize();
Pagination<InspectionWorkOrder> pagination = new Pagination<>((page - 1) * size, size); Pagination<InspectionWorkOrder> pagination = new Pagination<>((page - 1) * size, size);
pagination.addFilter("status", req.getStatus(), Operator.eq); pagination.addFilter(JpaQueryConstants.InspectionWorkOrder.STATUS, req.getStatus(), Operator.eq);
pagination.addFilter(JpaQueryConstants.InspectionWorkOrder.INSPECTOR_ID, InspectorContext.getInspectorId(), Operator.eq);
if (StringUtils.isNotBlank(req.getKeyword())) { if (StringUtils.isNotBlank(req.getKeyword())) {
pagination.addFilter(JpaQueryConstants.InspectionWorkOrder.KEYWORD, req.getKeyword(), Operator.eq); pagination.addFilter(JpaQueryConstants.InspectionWorkOrder.KEYWORD, req.getKeyword(), Operator.eq);
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!