|
|
|
@ -198,132 +198,131 @@ public class BasicdataDriverArteryServiceImpl extends BaseServiceImpl<BasicdataD
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public void importDriverArtery(List<BasicdataDriverArteryImproterExcel> data) { |
|
|
|
|
log.info("传入参数>>>>>>>>>>>>>>>>>>>>>>>{}", data); |
|
|
|
|
outerLoop: |
|
|
|
|
for (BasicdataDriverArteryImproterExcel datum : data) { |
|
|
|
|
for (BasicdataDriverArteryImproterExcel datum : data) { |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
List<BasicdataDrivermiddleEntity> driverMiddleEntity = new ArrayList<>(); |
|
|
|
|
try { |
|
|
|
|
List<BasicdataDrivermiddleEntity> driverMiddleEntity = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
//检查数据是否为空
|
|
|
|
|
if (ObjectUtils.isEmpty(datum.getPhone()) || ObjectUtils.isEmpty(datum.getName()) || ObjectUtils.isEmpty(datum.getWarehouseName()) || ObjectUtils.isEmpty(datum.getCarrierName())) { |
|
|
|
|
//检查数据是否为空
|
|
|
|
|
if (ObjectUtils.isEmpty(datum.getPhone()) || ObjectUtils.isEmpty(datum.getName()) || ObjectUtils.isEmpty(datum.getWarehouseName()) || ObjectUtils.isEmpty(datum.getCarrierName())) { |
|
|
|
|
|
|
|
|
|
// log.error("必填数据不能为空");
|
|
|
|
|
// continue;
|
|
|
|
|
throw new ServiceException("必填数据不能为空!"); |
|
|
|
|
} |
|
|
|
|
if (!ObjectUtils.isEmpty(datum.getPhone())) { |
|
|
|
|
String phone = datum.getPhone(); |
|
|
|
|
BasicdataDriverArteryEntity arteryEntity = baseMapper.findEntityByPhone(phone); |
|
|
|
|
if(!Objects.isNull(arteryEntity)){ |
|
|
|
|
throw new ServiceException(phone+"手机号码已存在!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
R<User> userR = userClient.userInfoByPhone("627683", datum.getPhone()); |
|
|
|
|
if (userR.getData() == null) { |
|
|
|
|
throw new ServiceException("必填数据不能为空!"); |
|
|
|
|
} |
|
|
|
|
if (!ObjectUtils.isEmpty(datum.getPhone())) { |
|
|
|
|
String phone = datum.getPhone(); |
|
|
|
|
BasicdataDriverArteryEntity arteryEntity = baseMapper.findEntityByPhone(phone); |
|
|
|
|
if (!Objects.isNull(arteryEntity)) { |
|
|
|
|
throw new ServiceException(phone + "手机号码已存在!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
R<User> userR = userClient.userInfoByPhone("627683", datum.getPhone()); |
|
|
|
|
if (userR.getData() == null) { |
|
|
|
|
// log.error("未找到用户");
|
|
|
|
|
// continue;
|
|
|
|
|
throw new ServiceException("未找到用户!"); |
|
|
|
|
} else { |
|
|
|
|
datum.setUserId(userR.getData().getId()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!ObjectUtils.isEmpty(datum.getBindVehicle())) { |
|
|
|
|
String[] car = datum.getBindVehicle().split(","); |
|
|
|
|
for (String s : car) { |
|
|
|
|
List<BasicdataVehicleEntity> carListByName = basicdataVehicleService.findCarListByName(s); |
|
|
|
|
|
|
|
|
|
if (carListByName.isEmpty()) { |
|
|
|
|
throw new ServiceException("未找到用户!"); |
|
|
|
|
} else { |
|
|
|
|
datum.setUserId(userR.getData().getId()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!ObjectUtils.isEmpty(datum.getBindVehicle())) { |
|
|
|
|
String[] car = datum.getBindVehicle().split(","); |
|
|
|
|
for (String s : car) { |
|
|
|
|
List<BasicdataVehicleEntity> carListByName = basicdataVehicleService.findCarListByName(s); |
|
|
|
|
|
|
|
|
|
if (carListByName.isEmpty()) { |
|
|
|
|
// log.error("未找到可绑定的车辆");
|
|
|
|
|
throw new ServiceException("未找到可绑定的车辆!"); |
|
|
|
|
} else { |
|
|
|
|
BasicdataDrivermiddleEntity basicdataDrivermiddleEntity = new BasicdataDrivermiddleEntity(); |
|
|
|
|
basicdataDrivermiddleEntity.setBrandId(carListByName.get(0).getId()); |
|
|
|
|
driverMiddleEntity.add(basicdataDrivermiddleEntity); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!ObjectUtils.isEmpty(datum.getCarrierName())) { |
|
|
|
|
//找到数据库内的承运商
|
|
|
|
|
List<BasicdataCarrierEntity> basicdataCarrierEntities = basicdataCarrierService.list(Wrappers.<BasicdataCarrierEntity>lambdaQuery().eq(BasicdataCarrierEntity::getCarrierName, datum.getCarrierName())); |
|
|
|
|
|
|
|
|
|
if (ObjectUtils.isEmpty(basicdataCarrierEntities)) { |
|
|
|
|
throw new ServiceException("未找到可绑定的车辆!"); |
|
|
|
|
} else { |
|
|
|
|
BasicdataDrivermiddleEntity basicdataDrivermiddleEntity = new BasicdataDrivermiddleEntity(); |
|
|
|
|
basicdataDrivermiddleEntity.setBrandId(carListByName.get(0).getId()); |
|
|
|
|
driverMiddleEntity.add(basicdataDrivermiddleEntity); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!ObjectUtils.isEmpty(datum.getCarrierName())) { |
|
|
|
|
//找到数据库内的承运商
|
|
|
|
|
List<BasicdataCarrierEntity> basicdataCarrierEntities = basicdataCarrierService.list(Wrappers.<BasicdataCarrierEntity>lambdaQuery().eq(BasicdataCarrierEntity::getCarrierName, datum.getCarrierName())); |
|
|
|
|
|
|
|
|
|
if (ObjectUtils.isEmpty(basicdataCarrierEntities)) { |
|
|
|
|
// log.error("未找到承运商");
|
|
|
|
|
// continue;
|
|
|
|
|
throw new ServiceException("未找到承运商!"); |
|
|
|
|
} else { |
|
|
|
|
datum.setCarrierId(basicdataCarrierEntities.get(0).getId()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
List<JSONObject> warehouseList = new ArrayList<>(); |
|
|
|
|
if (!ObjectUtils.isEmpty(datum.getWarehouseName())) { |
|
|
|
|
String warehouseNames = datum.getWarehouseName(); |
|
|
|
|
warehouseNames = warehouseNames.replaceAll(",",","); |
|
|
|
|
List<String> warehouseNameList = new ArrayList<>(); |
|
|
|
|
if(warehouseNames.contains(",")){ |
|
|
|
|
warehouseNameList = Arrays.asList(warehouseNames.split(",")); |
|
|
|
|
}else{ |
|
|
|
|
warehouseNameList.add(warehouseNames); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (String wn : warehouseNameList) { |
|
|
|
|
//在数据库找到仓库名字对应
|
|
|
|
|
BasicdataWarehouseEntity byName = warehouseClient.findByName(wn); |
|
|
|
|
if (ObjectUtils.isEmpty(byName)) { |
|
|
|
|
throw new ServiceException("未找到仓库!"); |
|
|
|
|
} else { |
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
|
jsonObject.put("warehouseId",byName.getId()); |
|
|
|
|
jsonObject.put("warehouseName",wn); |
|
|
|
|
warehouseList.add(jsonObject); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//根据手机号去重 如果有手机号相同 就删除老数据
|
|
|
|
|
if (ObjectUtils.isNotNull(datum) && ObjectUtils.isNotNull(datum.getPhone())) { |
|
|
|
|
List<BasicdataDriverArteryEntity> basicdataVehicleEntities = baseMapper.selectList(new QueryWrapper<BasicdataDriverArteryEntity>().lambda() |
|
|
|
|
.eq(BasicdataDriverArteryEntity::getPhone, datum.getPhone())); |
|
|
|
|
if (!basicdataVehicleEntities.isEmpty()) { |
|
|
|
|
basicdataDriverArteryMapper.updateIsdeletedByPhone(datum.getPhone()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
BasicdataDriverArteryEntity copy = Func.copy(datum, BasicdataDriverArteryEntity.class); |
|
|
|
|
//连接到前端后取消注释
|
|
|
|
|
BladeUser user = AuthUtil.getUser(); |
|
|
|
|
copy.setTenantId(user.getTenantId());// 租户号
|
|
|
|
|
copy.setCreateUser(user.getUserId()); // 创建人
|
|
|
|
|
copy.setUpdateUser(user.getUserId());// 更新人
|
|
|
|
|
log.info("复制后>>>>>>>>>>>>{}", copy); |
|
|
|
|
|
|
|
|
|
this.save(copy); |
|
|
|
|
|
|
|
|
|
List<BasicdataDriverWarehouseEntity> driverWarehouseEntities = new ArrayList<>(); |
|
|
|
|
for (JSONObject jsonObject : warehouseList) { |
|
|
|
|
Long warehouseId = jsonObject.getLong("warehouseId"); |
|
|
|
|
BasicdataDriverWarehouseEntity basicdataDriverWarehouseEntity = new BasicdataDriverWarehouseEntity(); |
|
|
|
|
basicdataDriverWarehouseEntity.setTenantId(AuthUtil.getTenantId()); |
|
|
|
|
basicdataDriverWarehouseEntity.setCreateUser(AuthUtil.getUserId()); |
|
|
|
|
basicdataDriverWarehouseEntity.setUpdateUser(AuthUtil.getUserId()); |
|
|
|
|
basicdataDriverWarehouseEntity.setCreateDept(Func.firstLong(AuthUtil.getDeptId())); |
|
|
|
|
basicdataDriverWarehouseEntity.setDriverId(copy.getId()); |
|
|
|
|
basicdataDriverWarehouseEntity.setWarehouseId(warehouseId); |
|
|
|
|
driverWarehouseEntities.add(basicdataDriverWarehouseEntity); |
|
|
|
|
} |
|
|
|
|
basicdataDriverWarehouseService.saveBatch(driverWarehouseEntities); |
|
|
|
|
|
|
|
|
|
//车辆和司机绑定关系
|
|
|
|
|
for (BasicdataDrivermiddleEntity basicdataDrivermiddleEntity : driverMiddleEntity) { |
|
|
|
|
basicdataDrivermiddleEntity.setDriverId(copy.getId()); |
|
|
|
|
basicdataDrivermiddleServiceImpl.save(basicdataDrivermiddleEntity); |
|
|
|
|
} |
|
|
|
|
} catch (DataAccessException e) { |
|
|
|
|
throw new ServiceException("用户" + datum.getName() + "数据长度异常"); |
|
|
|
|
} catch (ServiceException e) { |
|
|
|
|
throw new ServiceException("用户" + datum.getName() + e.getMessage()); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
throw new RuntimeException("用户" + datum.getName() + "数据错误" + e.getMessage()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
throw new ServiceException("未找到承运商!"); |
|
|
|
|
} else { |
|
|
|
|
datum.setCarrierId(basicdataCarrierEntities.get(0).getId()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
List<JSONObject> warehouseList = new ArrayList<>(); |
|
|
|
|
if (!ObjectUtils.isEmpty(datum.getWarehouseName())) { |
|
|
|
|
String warehouseNames = datum.getWarehouseName(); |
|
|
|
|
warehouseNames = warehouseNames.replaceAll(",", ","); |
|
|
|
|
List<String> warehouseNameList = new ArrayList<>(); |
|
|
|
|
if (warehouseNames.contains(",")) { |
|
|
|
|
warehouseNameList = Arrays.asList(warehouseNames.split(",")); |
|
|
|
|
} else { |
|
|
|
|
warehouseNameList.add(warehouseNames); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (String wn : warehouseNameList) { |
|
|
|
|
//在数据库找到仓库名字对应
|
|
|
|
|
BasicdataWarehouseEntity byName = warehouseClient.findByName(wn); |
|
|
|
|
if (ObjectUtils.isEmpty(byName)) { |
|
|
|
|
throw new ServiceException("未找到仓库!"); |
|
|
|
|
} else { |
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
|
jsonObject.put("warehouseId", byName.getId()); |
|
|
|
|
jsonObject.put("warehouseName", wn); |
|
|
|
|
warehouseList.add(jsonObject); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//根据手机号去重 如果有手机号相同 就删除老数据
|
|
|
|
|
if (ObjectUtils.isNotNull(datum) && ObjectUtils.isNotNull(datum.getPhone())) { |
|
|
|
|
List<BasicdataDriverArteryEntity> basicdataVehicleEntities = baseMapper.selectList(new QueryWrapper<BasicdataDriverArteryEntity>().lambda() |
|
|
|
|
.eq(BasicdataDriverArteryEntity::getPhone, datum.getPhone())); |
|
|
|
|
if (!basicdataVehicleEntities.isEmpty()) { |
|
|
|
|
basicdataDriverArteryMapper.updateIsdeletedByPhone(datum.getPhone()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
BasicdataDriverArteryEntity copy = Func.copy(datum, BasicdataDriverArteryEntity.class); |
|
|
|
|
//连接到前端后取消注释
|
|
|
|
|
BladeUser user = AuthUtil.getUser(); |
|
|
|
|
copy.setTenantId(user.getTenantId());// 租户号
|
|
|
|
|
copy.setCreateUser(user.getUserId()); // 创建人
|
|
|
|
|
copy.setUpdateUser(user.getUserId());// 更新人
|
|
|
|
|
log.info("复制后>>>>>>>>>>>>{}", copy); |
|
|
|
|
|
|
|
|
|
this.save(copy); |
|
|
|
|
|
|
|
|
|
List<BasicdataDriverWarehouseEntity> driverWarehouseEntities = new ArrayList<>(); |
|
|
|
|
for (JSONObject jsonObject : warehouseList) { |
|
|
|
|
Long warehouseId = jsonObject.getLong("warehouseId"); |
|
|
|
|
BasicdataDriverWarehouseEntity basicdataDriverWarehouseEntity = new BasicdataDriverWarehouseEntity(); |
|
|
|
|
basicdataDriverWarehouseEntity.setTenantId(AuthUtil.getTenantId()); |
|
|
|
|
basicdataDriverWarehouseEntity.setCreateUser(AuthUtil.getUserId()); |
|
|
|
|
basicdataDriverWarehouseEntity.setUpdateUser(AuthUtil.getUserId()); |
|
|
|
|
basicdataDriverWarehouseEntity.setCreateDept(Func.firstLong(AuthUtil.getDeptId())); |
|
|
|
|
basicdataDriverWarehouseEntity.setDriverId(copy.getId()); |
|
|
|
|
basicdataDriverWarehouseEntity.setWarehouseId(warehouseId); |
|
|
|
|
driverWarehouseEntities.add(basicdataDriverWarehouseEntity); |
|
|
|
|
} |
|
|
|
|
basicdataDriverWarehouseService.saveBatch(driverWarehouseEntities); |
|
|
|
|
|
|
|
|
|
//车辆和司机绑定关系
|
|
|
|
|
for (BasicdataDrivermiddleEntity basicdataDrivermiddleEntity : driverMiddleEntity) { |
|
|
|
|
basicdataDrivermiddleEntity.setDriverId(copy.getId()); |
|
|
|
|
basicdataDrivermiddleServiceImpl.save(basicdataDrivermiddleEntity); |
|
|
|
|
} |
|
|
|
|
} catch (DataAccessException e) { |
|
|
|
|
throw new ServiceException("用户" + datum.getName() + "数据长度异常"); |
|
|
|
|
} catch (ServiceException e) { |
|
|
|
|
throw new ServiceException("用户" + datum.getName() + e.getMessage()); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
throw new RuntimeException("用户" + datum.getName() + "数据错误" + e.getMessage()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|