Commit b40c071e authored by huangcb's avatar huangcb

承运商接口:编辑车辆信息

parent 9bd9c019
...@@ -137,4 +137,13 @@ public class ErrorMessageComponent { ...@@ -137,4 +137,13 @@ public class ErrorMessageComponent {
private String carrierVehicleAdd1003; private String carrierVehicleAdd1003;
@Value("${error-message.carrier.vehicle.add.1004}") @Value("${error-message.carrier.vehicle.add.1004}")
private String carrierVehicleAdd1004; private String carrierVehicleAdd1004;
@Value("${error-message.carrier.vehicle.edit.1001}")
private String carrierVehicleEdit1001;
@Value("${error-message.carrier.vehicle.edit.1002}")
private String carrierVehicleEdit1002;
@Value("${error-message.carrier.vehicle.edit.1003}")
private String carrierVehicleEdit1003;
@Value("${error-message.carrier.vehicle.edit.1004}")
private String carrierVehicleEdit1004;
} }
...@@ -5,6 +5,7 @@ import com.esv.freight.customer.common.exception.EException; ...@@ -5,6 +5,7 @@ import com.esv.freight.customer.common.exception.EException;
import com.esv.freight.customer.common.response.ECode; import com.esv.freight.customer.common.response.ECode;
import com.esv.freight.customer.common.response.EResponse; import com.esv.freight.customer.common.response.EResponse;
import com.esv.freight.customer.common.validator.groups.ValidatorInsert; import com.esv.freight.customer.common.validator.groups.ValidatorInsert;
import com.esv.freight.customer.common.validator.groups.ValidatorUpdate;
import com.esv.freight.customer.module.vehicle.form.VehicleInfoForm; import com.esv.freight.customer.module.vehicle.form.VehicleInfoForm;
import com.esv.freight.customer.module.vehicle.service.VehicleService; import com.esv.freight.customer.module.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -66,4 +67,17 @@ public class VehicleController { ...@@ -66,4 +67,17 @@ public class VehicleController {
data.put("id", id); data.put("id", id);
return EResponse.ok(data); return EResponse.ok(data);
} }
/**
* description 更新车辆信息
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/27 11:05
**/
@PostMapping("/edit")
public EResponse edit(@RequestBody @Validated(ValidatorUpdate.class) VehicleInfoForm form) throws EException {
vehicleService.updateVehicle(form);
return EResponse.ok();
}
} }
...@@ -22,5 +22,14 @@ public interface VehicleService extends IService<VehicleEntity> { ...@@ -22,5 +22,14 @@ public interface VehicleService extends IService<VehicleEntity> {
**/ **/
Long insertVehicle(VehicleInfoForm form); Long insertVehicle(VehicleInfoForm form);
/**
* description 更新车辆信息
* param [form]
* return java.lang.Integer
* author Administrator
* createTime 2020/04/27 9:23
**/
Integer updateVehicle(VehicleInfoForm form);
} }
package com.esv.freight.customer.module.vehicle.service.impl; package com.esv.freight.customer.module.vehicle.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.esv.freight.customer.common.component.ErrorMessageComponent; import com.esv.freight.customer.common.component.ErrorMessageComponent;
import com.esv.freight.customer.common.exception.EException; import com.esv.freight.customer.common.exception.EException;
import com.esv.freight.customer.common.response.ECode;
import com.esv.freight.customer.common.util.ReqUtils; import com.esv.freight.customer.common.util.ReqUtils;
import com.esv.freight.customer.module.carrier.entity.CarrierAccountEntity; import com.esv.freight.customer.module.carrier.entity.CarrierAccountEntity;
import com.esv.freight.customer.module.carrier.service.CarrierAccountService; import com.esv.freight.customer.module.carrier.service.CarrierAccountService;
...@@ -17,11 +19,14 @@ import com.esv.freight.customer.module.vehicle.service.AttachmentService; ...@@ -17,11 +19,14 @@ import com.esv.freight.customer.module.vehicle.service.AttachmentService;
import com.esv.freight.customer.module.vehicle.service.VehicleAuditHistoryService; import com.esv.freight.customer.module.vehicle.service.VehicleAuditHistoryService;
import com.esv.freight.customer.module.vehicle.service.VehicleService; import com.esv.freight.customer.module.vehicle.service.VehicleService;
import com.esv.gateway.common.GatewayHeaders; import com.esv.gateway.common.GatewayHeaders;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
@Service("vehicleService") @Service("vehicleService")
public class VehicleServiceImpl extends ServiceImpl<VehicleDao, VehicleEntity> implements VehicleService { public class VehicleServiceImpl extends ServiceImpl<VehicleDao, VehicleEntity> implements VehicleService {
...@@ -71,6 +76,7 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleDao, VehicleEntity> i ...@@ -71,6 +76,7 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleDao, VehicleEntity> i
// 2:新增车辆 // 2:新增车辆
VehicleEntity vehicleEntity = new VehicleEntity(); VehicleEntity vehicleEntity = new VehicleEntity();
BeanUtils.copyProperties(form, vehicleEntity); BeanUtils.copyProperties(form, vehicleEntity);
vehicleEntity.setId(null);
vehicleEntity.setVehicleStatus(VehicleConstants.VEHICLE_ACCOUNT_STATUS_UNBLOCK); vehicleEntity.setVehicleStatus(VehicleConstants.VEHICLE_ACCOUNT_STATUS_UNBLOCK);
vehicleEntity.setAuditStatus(VehicleConstants.VEHICLE_AUDIT_STATUS_SUCCESS); vehicleEntity.setAuditStatus(VehicleConstants.VEHICLE_AUDIT_STATUS_SUCCESS);
vehicleEntity.setSourceType(VehicleConstants.VEHICLE_SOURCE_TYPE_PLATFORM); vehicleEntity.setSourceType(VehicleConstants.VEHICLE_SOURCE_TYPE_PLATFORM);
...@@ -95,4 +101,63 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleDao, VehicleEntity> i ...@@ -95,4 +101,63 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleDao, VehicleEntity> i
return vehicleId; return vehicleId;
} }
@Override
public Integer updateVehicle(VehicleInfoForm form) {
// 1:校验
// 1.1校验车辆ID是否有效
VehicleEntity vehicleEntity = this.baseMapper.selectById(form.getId());
if (null == vehicleEntity) {
throw new EException(1001, errorMessageComponent.getCarrierVehicleEdit1001());
}
// 1.2校验车牌号是否存在
int count = 0;
if (StringUtils.isNotBlank(form.getLicenseNumber())) {
this.baseMapper.selectCount(new QueryWrapper<VehicleEntity>().lambda()
.ne(VehicleEntity::getId, form.getId())
.eq(VehicleEntity::getLicenseNumber, form.getLicenseNumber()));
if (0 < count) {
throw new EException(1002, errorMessageComponent.getCarrierVehicleEdit1002());
}
}
// 1.3校验行驶证档案编号是否存在
if (StringUtils.isNotBlank(form.getVehicleLicenseNumber())) {
count = this.baseMapper.selectCount(new QueryWrapper<VehicleEntity>().lambda()
.ne(VehicleEntity::getId, form.getId())
.eq(VehicleEntity::getVehicleLicenseNumber, form.getVehicleLicenseNumber()));
if (0 < count) {
throw new EException(1003, errorMessageComponent.getCarrierVehicleEdit1003());
}
}
// 1.4校验道路运输证号是否存在
if (StringUtils.isNotBlank(form.getRoadCertificateNumber())) {
count = this.baseMapper.selectCount(new QueryWrapper<VehicleEntity>().lambda()
.ne(VehicleEntity::getId, form.getId())
.eq(VehicleEntity::getRoadCertificateNumber, form.getRoadCertificateNumber()));
if (0 < count) {
throw new EException(1004, errorMessageComponent.getCarrierVehicleEdit1004());
}
}
// 道路运输证号,4.5吨及以下普货车辆可以为空
BigDecimal bigDecimal4_5 = new BigDecimal("4.5");
if (-1 == bigDecimal4_5.compareTo(form.getLoadCapacity())
&& StringUtils.isBlank(form.getRoadCertificateNumber())
&& StringUtils.isBlank(vehicleEntity.getRoadCertificateNumber())) {
throw new EException(ECode.PARAM_ERROR.code(), "4.5顿以上载重的车辆,道路运输证号不能为空");
}
// 2:更新车辆信息
int flag = 0;
vehicleEntity = new VehicleEntity();
BeanUtils.copyProperties(form, vehicleEntity);
flag += this.baseMapper.updateById(vehicleEntity);
// 3:更新车辆附件
AttachmentEntity attachmentEntity = new AttachmentEntity();
BeanUtils.copyProperties(form, attachmentEntity);
flag += this.attachmentService.getBaseMapper().update(attachmentEntity,
new UpdateWrapper<AttachmentEntity>().lambda().eq(AttachmentEntity::getVehicleId, form.getId()));
return flag;
}
} }
\ No newline at end of file
...@@ -126,3 +126,8 @@ error-message: ...@@ -126,3 +126,8 @@ error-message:
1002: 车牌号已存在 1002: 车牌号已存在
1003: 行驶证档案编号已存在 1003: 行驶证档案编号已存在
1004: 道路运输证号已存在 1004: 道路运输证号已存在
edit:
1001: 无效的车辆ID
1002: 车牌号已存在
1003: 行驶证档案编号已存在
1004: 道路运输证号已存在
\ No newline at end of file
...@@ -25,7 +25,7 @@ import java.math.BigDecimal; ...@@ -25,7 +25,7 @@ import java.math.BigDecimal;
/** /**
* @description: * @description:
* @project: freight-customer-service * @project: freight-customer-service
* @name: com.esv.freight.customer.module.vehicle.controller.VehicleControllerTest * @name: com.esv.freight.customer.module.vehicle.controller.VehicleControllerAddTest
* @author: 黄朝斌 * @author: 黄朝斌
* @email: huangchaobin@esvtek.com * @email: huangchaobin@esvtek.com
* @createTime: 2020/04/26 15:27 * @createTime: 2020/04/26 15:27
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment