Commit c18004a8 by 黄小葱

优化以及修改bug

1 parent ddf263bb
......@@ -29,6 +29,7 @@ public enum ResultEnum {
IMPORT_FILE_TYPE_ERROR(12120003, "导入文件类型错误"),
IMPORT_FAIL_NOT_FOUND(12120004, "未找到失败的文件"),
UN_BIND_DEVICE(12120005, "请先解绑设备"),
EXIST_VEHICLE(12120005, "该车辆已存在:vin %s"),
/**
* 拆除报警
......
......@@ -98,7 +98,7 @@ public class VehicleController {
if (StringUtils.isBlank(tempId)) {
return R.error("未选择数据");
}
vehicleService.deleteDriveVehicle(tempId);
vehicleService.deleteDriveVehicleAndUnBind(tempId);
return R.ok();
}
......
......@@ -35,4 +35,10 @@ public interface VehicleDeviceMapper extends CommonBaseMapper<VehicleDevice> {
* @return
*/
List<VehicleDevice> getVehicleDeviceByVehicleIdStatus(@Param("vehicleDevice") VehicleDevice param);
/**
* 根据设备号解绑和车辆的关系
* @param sn
*/
void unBindBySn(String sn);
}
......@@ -57,4 +57,10 @@ public interface VehicleMapper extends CommonBaseMapper<Vehicle> {
Vehicle selectById(@Param("vehicleId") Long vehicleId);
/**
* genuine车架号查找车辆
* @param vin
* @return
*/
Vehicle getVehicleByVin(@Param("vin") String vin);
}
\ No newline at end of file
......@@ -2,7 +2,6 @@ package cn.com.glsx.admin.modules.model.imports;
import cn.com.glsx.admin.common.enums.ResultEnum;
import cn.com.glsx.admin.common.exception.AdminException;
import cn.com.glsx.admin.modules.entity.VehicleDevice;
import cn.com.glsx.admin.modules.model.BaseImportInfo;
import cn.com.glsx.admin.modules.service.DeviceService;
import cn.com.glsx.admin.modules.service.VehicleService;
......@@ -162,6 +161,10 @@ public class TrialDriveVehicleImportListener extends AnalysisEventListener<Trial
if (userList.size() > 1) {
reason.append("该特约店存在多个;");
}
String vin = vehicleImport.getVin();
if (vehicleService.checkVehicleByVin(vin)) {
reason.append("该车辆已存在 vin:" + vin);
}
//如果存在设备号 校验设备号
String sn = vehicleImport.getSn();
if (StringUtils.isBlank(sn)) {
......@@ -172,8 +175,7 @@ public class TrialDriveVehicleImportListener extends AnalysisEventListener<Trial
reason.append("设备号不存在");
return reason.toString();
}
VehicleDevice vehicleDevice = deviceService.checkSnBind(sn);
if (vehicleDevice != null) {
if (vehicleService.checkSnIsBind(sn)) {
reason.append("该设备号已绑定车辆");
}
return reason.toString();
......
package cn.com.glsx.admin.modules.service;
import cn.com.glsx.admin.common.constants.ConstantsDevice;
import cn.com.glsx.admin.modules.entity.Device;
import cn.com.glsx.admin.modules.entity.VehicleDevice;
import cn.com.glsx.admin.modules.mapper.DeviceMapper;
import cn.com.glsx.admin.modules.mapper.VehicleDeviceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -17,8 +14,6 @@ import org.springframework.stereotype.Service;
public class DeviceService {
@Autowired
private DeviceMapper deviceMapper;
@Autowired
private VehicleDeviceMapper vdMapper;
public void insertDevice(Device device) {
deviceMapper.insert(device);
......@@ -29,7 +24,7 @@ public class DeviceService {
}
/**
* 检查设备号是否存在 false 不存在
* 检查设备号是否存在(入库) false 不存在
* @param sn
*/
public boolean checkSnExist(String sn) {
......@@ -40,16 +35,5 @@ public class DeviceService {
return true;
}
/**
* 检查设备号是否绑定
* @param sn
*/
public VehicleDevice checkSnBind(String sn) {
VehicleDevice param = new VehicleDevice();
param.setSn(sn);
param.setBindStatus(ConstantsDevice.BIND_VEHICLE_STATUS);
VehicleDevice vehicleDevice = vdMapper.getVehicleDeviceBySnStatus(param);
return vehicleDevice;
}
}
package cn.com.glsx.admin.modules.service;
import cn.com.glsx.admin.common.constants.ConstantsDevice;
import cn.com.glsx.admin.modules.entity.VehicleDevice;
import cn.com.glsx.admin.modules.mapper.VehicleDeviceMapper;
import cn.com.glsx.auth.utils.ShieldContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
* @Desc:车辆设备基础服务
* @Author huangxc
* @Date 2021/5/27
*/
@Slf4j
@Service
public class VehicleDeviceService {
@Autowired
private VehicleDeviceMapper vehicleDeviceMapper;
/**
* 新增
* @param vehicleDevice
*/
public void insert(VehicleDevice vehicleDevice) {
vehicleDeviceMapper.insert(vehicleDevice);
}
/**
* 更新
* @param vehicleDevice
*/
public void updateByPrimaryKey(VehicleDevice vehicleDevice) {
vehicleDeviceMapper.updateByPrimaryKey(vehicleDevice);
}
/**
* 根据设备号解绑
* @param sn
*/
public void unBindBySn(String sn) {
vehicleDeviceMapper.unBindBySn(sn);
}
/**
* 保存车辆设备绑定关系
* @param sn
* @param vehicleId
*/
public void saveSnToVehicleId(String sn, Long vehicleId) {
VehicleDevice vehicleDevice = new VehicleDevice();
vehicleDevice.setSn(sn);
vehicleDevice.setBindStatus(ConstantsDevice.BIND_VEHICLE_STATUS);
vehicleDevice.setVehicleId(vehicleId);
vehicleDevice.setCreatedBy(ShieldContextHolder.getUserId());
vehicleDevice.setCreatedDate(new Date());
vehicleDeviceMapper.insert(vehicleDevice);
}
/**
* 查询车辆绑定了哪些设备
* @param vehicleId
* @return
*/
public List<VehicleDevice> listVehicleDeviceByVehicleIdBind(Long vehicleId) {
VehicleDevice param = new VehicleDevice();
param.setBindStatus(ConstantsDevice.BIND_VEHICLE_STATUS);
param.setVehicleId(vehicleId);
//匹配设备
List<VehicleDevice> bindVehicleDevice = vehicleDeviceMapper.getVehicleDeviceByVehicleIdStatus(param);
return bindVehicleDevice;
}
/**
* 获取设备号绑定信息
* @param sn
*/
public VehicleDevice getVehicleDeviceBySnBind(String sn) {
VehicleDevice param = new VehicleDevice();
param.setSn(sn);
param.setBindStatus(ConstantsDevice.BIND_VEHICLE_STATUS);
VehicleDevice vehicleDevice = vehicleDeviceMapper.getVehicleDeviceBySnStatus(param);
return vehicleDevice;
}
/**
* 检查sn是否绑定
* @param sn
* @return
*/
public boolean checkSnIsBind(String sn) {
VehicleDevice vehicleDevice = getVehicleDeviceBySnBind(sn);
if (vehicleDevice != null) {
return true;
}
return false;
}
/**
* 根据VehicleDevice解绑
* @param vehicleDevice
*/
public void unBindSnByVehicleDevice(VehicleDevice vehicleDevice) {
vehicleDevice.setBindStatus(ConstantsDevice.UN_BIND_VEHICLE_STATUS);
vehicleDevice.setUpdatedBy(ShieldContextHolder.getUserId());
vehicleDevice.setUpdatedDate(new Date());
vehicleDeviceMapper.updateByPrimaryKey(vehicleDevice);
}
}
......@@ -51,5 +51,9 @@
<include refid="common_where_if_condition"></include>
</select>
<update id="unBindBySn">
update t_vehicle_device set bind_status=2 where sn=#{sn}
</update>
</mapper>
\ No newline at end of file
......@@ -177,4 +177,10 @@
<select id="selectById" resultMap="BaseResultMap">
select * from t_vehicle where id = #{vehicleId} and del_flag = 0
</select>
<select id="getVehicleByVin" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_vehicle tv where tv.vin = #{vin} and del_flag = 0
</select>
</mapper>
\ No newline at end of file
package cn.com.glsx.admin.modules.service;
import cn.com.glsx.Application;
import cn.com.glsx.auth.model.Department;
import cn.com.glsx.auth.model.Role;
import cn.com.glsx.auth.model.SyntheticUser;
import cn.com.glsx.auth.utils.ShieldContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.ArrayList;
import java.util.List;
/**
* @Desc:
* @Author huangxc
* @Date 2021/5/27
*/
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class VehicleDeviceServiceTest {
@Autowired
private VehicleDeviceService VehicleDeviceService;
@Before
public void runBeforeTestMethod() {
SyntheticUser user = new SyntheticUser();
user.setUserId(6551L);
user.setIsAdmin(false);
user.setAccount("DGD101");
Department department = new Department();
department.setDeptId(182L);
user.setDepartment(department);
List<Role> roleList=new ArrayList<>();
Role role=new Role();
role.setRoleId(38L);
roleList.add(role);
user.setRoles(roleList);
ShieldContextHolder.setUser(user);
}
@Test
public void testUnBindBySn() {
VehicleDeviceService.unBindBySn("8700922797");
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!