车辆三检,附件字段正常时改为非必填。检查项中有异常项时才必填。
This commit is contained in:
@@ -89,7 +89,6 @@ public class HotVehicleThreeInspectBo extends BaseEntity {
|
||||
/**
|
||||
* 检查附件图片url
|
||||
*/
|
||||
@NotBlank(message = "检查附件图片url不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String attachImgUrl;
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,11 +3,14 @@ package com.hotwj.platform.config.vehicleThreeInspect.service.impl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.hotwj.platform.common.helper.DriverLoginContextHelper;
|
||||
import com.hotwj.platform.config.vehicleThreeInspect.domain.HotVehicleThreeInspect;
|
||||
import com.hotwj.platform.config.vehicleThreeInspect.domain.bo.HotVehicleThreeInspectBatchAuditBo;
|
||||
import com.hotwj.platform.config.vehicleThreeInspect.domain.bo.HotVehicleThreeInspectBo;
|
||||
import com.hotwj.platform.config.vehicleThreeInspect.domain.vo.HotVehicleThreeInspectVo;
|
||||
import com.hotwj.platform.config.vehicleThreeInspectConfig.domain.HotVehicleThreeInspectConfig;
|
||||
import com.hotwj.platform.config.vehicleThreeInspectConfig.mapper.HotVehicleThreeInspectConfigMapper;
|
||||
import com.hotwj.platform.config.vehicleThreeInspect.mapper.HotVehicleThreeInspectMapper;
|
||||
import com.hotwj.platform.config.vehicleThreeInspect.service.IHotVehicleThreeInspectService;
|
||||
import com.hotwj.platform.flow.service.ISysFlowService;
|
||||
@@ -22,13 +25,16 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.json.utils.JsonUtils;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -50,6 +56,7 @@ public class HotVehicleThreeInspectServiceImpl implements IHotVehicleThreeInspec
|
||||
private final ISysFlowService flowService;
|
||||
private final IHotSystemNotificationService notificationService;
|
||||
private final SignatureVerifyService signatureVerifyService;
|
||||
private final HotVehicleThreeInspectConfigMapper hotVehicleThreeInspectConfigMapper;
|
||||
|
||||
/**
|
||||
* 查询可进行三检的车辆列表(无历史记录或上一轮已完结)
|
||||
@@ -203,6 +210,7 @@ public class HotVehicleThreeInspectServiceImpl implements IHotVehicleThreeInspec
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertByBo(HotVehicleThreeInspectBo bo) {
|
||||
validateAttachImgUrlRequiredWhenAbnormal(bo);
|
||||
HotVehicleThreeInspect add = MapstructUtils.convert(bo, HotVehicleThreeInspect.class);
|
||||
validEntityBeforeSave(add);
|
||||
|
||||
@@ -374,12 +382,85 @@ public class HotVehicleThreeInspectServiceImpl implements IHotVehicleThreeInspec
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean updateByBo(HotVehicleThreeInspectBo bo) {
|
||||
validateAttachImgUrlRequiredWhenAbnormal(bo);
|
||||
HotVehicleThreeInspect update = MapstructUtils.convert(bo, HotVehicleThreeInspect.class);
|
||||
validEntityBeforeSave(update);
|
||||
boolean flag = baseMapper.updateById(update) > 0;
|
||||
return flag;
|
||||
}
|
||||
|
||||
private void validateAttachImgUrlRequiredWhenAbnormal(HotVehicleThreeInspectBo bo) {
|
||||
if (!hasAbnormalInspectItem(bo)) {
|
||||
return;
|
||||
}
|
||||
if (StringUtils.isBlank(bo.getAttachImgUrl())) {
|
||||
throw new ServiceException("检查项存在异常时,检查附件不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasAbnormalInspectItem(HotVehicleThreeInspectBo bo) {
|
||||
if (bo == null || StringUtils.isBlank(bo.getInspectResultJson())) {
|
||||
return false;
|
||||
}
|
||||
Map<String, Object> inspectResultMap;
|
||||
try {
|
||||
inspectResultMap = JsonUtils.parseObject(bo.getInspectResultJson(), new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
} catch (RuntimeException e) {
|
||||
throw new ServiceException("检查项目结果JSON格式错误");
|
||||
}
|
||||
if (inspectResultMap == null || inspectResultMap.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Map<Long, String> abnormalTextMap = queryAbnormalTextMap(bo, inspectResultMap);
|
||||
for (Map.Entry<String, Object> entry : inspectResultMap.entrySet()) {
|
||||
String resultText = StringUtils.trimToNull(Objects.toString(entry.getValue(), null));
|
||||
if (resultText == null) {
|
||||
continue;
|
||||
}
|
||||
Long configId = parseConfigId(entry.getKey());
|
||||
String abnormalText = configId == null ? "异常" : abnormalTextMap.getOrDefault(configId, "异常");
|
||||
if (StringUtils.equals(resultText, abnormalText)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Map<Long, String> queryAbnormalTextMap(HotVehicleThreeInspectBo bo, Map<String, Object> inspectResultMap) {
|
||||
List<Long> configIds = inspectResultMap.keySet().stream()
|
||||
.map(this::parseConfigId)
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
if (configIds.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
List<HotVehicleThreeInspectConfig> configList = hotVehicleThreeInspectConfigMapper.selectList(
|
||||
Wrappers.<HotVehicleThreeInspectConfig>lambdaQuery()
|
||||
.in(HotVehicleThreeInspectConfig::getId, configIds)
|
||||
.eq(bo.getCompanyId() != null, HotVehicleThreeInspectConfig::getCompanyId, bo.getCompanyId())
|
||||
.eq(bo.getInspectPhase() != null, HotVehicleThreeInspectConfig::getInspectType, bo.getInspectPhase())
|
||||
);
|
||||
if (configList == null || configList.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Map<Long, String> abnormalTextMap = new HashMap<>(configList.size());
|
||||
for (HotVehicleThreeInspectConfig config : configList) {
|
||||
String abnormalText = StringUtils.trimToNull(config.getAbnormalText());
|
||||
abnormalTextMap.put(config.getId(), abnormalText == null ? "异常" : abnormalText);
|
||||
}
|
||||
return abnormalTextMap;
|
||||
}
|
||||
|
||||
private Long parseConfigId(String configIdText) {
|
||||
String value = StringUtils.trimToNull(configIdText);
|
||||
if (value == null || !value.matches("\\d+")) {
|
||||
return null;
|
||||
}
|
||||
return Long.parseLong(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user