@ -34,29 +34,24 @@ import com.logpm.basicdata.service.IBasicdataVehicleService;
import com.logpm.basicdata.vo.BasicdataDriverArteryVO ;
import lombok.AllArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
import org.springblade.common.constant.driver.DriverTypeStatusConstant ;
import org.springblade.core.log.exception.ServiceException ;
import org.springblade.core.mp.base.BaseServiceImpl ;
import org.springblade.core.secure.BladeUser ;
import org.springblade.core.secure.utils.AuthUtil ;
import org.springblade.core.tool.api.R ;
import org.springblade.core.tool.utils.Func ;
import org.springblade.system.cache.DictBizCache ;
import org.springblade.system.entity.User ;
import org.springblade.system.feign.IUserClient ;
import org.springblade.system.feign.IUserSearchClient ;
import org.springframework.dao.DataAccessException ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.List ;
import java.util.function.Function ;
import java.util.stream.Collectors ;
import java.util.stream.Stream ;
import static com.alibaba.fastjson.JSONPatch.OperationType.copy ;
/ * *
* 司机信息表 服务实现类
*
@ -68,9 +63,9 @@ import static com.alibaba.fastjson.JSONPatch.OperationType.copy;
@Slf4j
public class BasicdataDriverArteryServiceImpl extends BaseServiceImpl < BasicdataDriverArteryMapper , BasicdataDriverArteryEntity > implements IBasicdataDriverArteryService {
private final BasicdataVehicleMapper basicdataVehicleMapper ;
private final BasicdataVehicleMapper basicdataVehicleMapper ;
private final IBasicdataVehicleService basicdataVehicleService ;
private final IBasicdataVehicleService basicdataVehicleService ;
private final BasicdataDrivermiddleMapper basicdataDrivermiddleMapper ;
@ -103,18 +98,18 @@ public class BasicdataDriverArteryServiceImpl extends BaseServiceImpl<BasicdataD
public Integer updateVehicle ( BasicdataDriverArteryDTO basicdataDriverArtery ) {
//删除原有绑定关系
int delete = basicdataDrivermiddleMapper . delete ( new QueryWrapper < BasicdataDrivermiddleEntity > ( ) . lambda ( ) . eq ( BasicdataDrivermiddleEntity : : getDriverId , basicdataDriverArtery . getId ( ) ) ) ;
if ( basicdataDriverArtery . getBindVehicles ( ) . equals ( "" ) ) return delete ;
if ( basicdataDriverArtery . getBindVehicles ( ) . equals ( "" ) ) return delete ;
//新增现有的数据
//if (delete>0){
List < String > bindVehicles = Arrays . asList ( basicdataDriverArtery . getBindVehicles ( ) . split ( "," ) ) ;
ArrayList < BasicdataDrivermiddleEntity > basicdataDrivermiddleEntities = new ArrayList < > ( ) ;
bindVehicles . forEach ( e - > {
BasicdataDrivermiddleEntity basicdataDrivermiddleEntity = new BasicdataDrivermiddleEntity ( ) ;
basicdataDrivermiddleEntity . setDriverId ( basicdataDriverArtery . getId ( ) ) ;
basicdataDrivermiddleEntity . setBrandId ( Long . valueOf ( e ) ) ;
basicdataDrivermiddleEntities . add ( basicdataDrivermiddleEntity ) ;
} ) ;
basicdataDrivermiddleService . saveBatch ( basicdataDrivermiddleEntities ) ;
List < String > bindVehicles = Arrays . asList ( basicdataDriverArtery . getBindVehicles ( ) . split ( "," ) ) ;
ArrayList < BasicdataDrivermiddleEntity > basicdataDrivermiddleEntities = new ArrayList < > ( ) ;
bindVehicles . forEach ( e - > {
BasicdataDrivermiddleEntity basicdataDrivermiddleEntity = new BasicdataDrivermiddleEntity ( ) ;
basicdataDrivermiddleEntity . setDriverId ( basicdataDriverArtery . getId ( ) ) ;
basicdataDrivermiddleEntity . setBrandId ( Long . valueOf ( e ) ) ;
basicdataDrivermiddleEntities . add ( basicdataDrivermiddleEntity ) ;
} ) ;
basicdataDrivermiddleService . saveBatch ( basicdataDrivermiddleEntities ) ;
//}
return delete ;
}
@ -127,23 +122,23 @@ public class BasicdataDriverArteryServiceImpl extends BaseServiceImpl<BasicdataD
@Override
public List < BasicdataDriverArteryVO > getDriverList ( ) {
BasicdataWarehouseEntity myCurrentWarehouse = warehouseClient . getMyCurrentWarehouse ( ) ;
if ( Func . isEmpty ( myCurrentWarehouse ) ) {
log . error ( "################getDriverList 无当前登录人仓库信息:{}" , myCurrentWarehouse ) ;
if ( Func . isEmpty ( myCurrentWarehouse ) ) {
log . error ( "################getDriverList 无当前登录人仓库信息:{}" , myCurrentWarehouse ) ;
return null ;
}
log . info ( "################ getDriverList 仓库信息:{}" , myCurrentWarehouse ) ;
log . info ( "################ getDriverList 仓库信息:{}" , myCurrentWarehouse ) ;
ArrayList < BasicdataDriverArteryVO > basicdataDriverArteryVOS = new ArrayList < > ( ) ;
List < BasicdataDriverArteryEntity > list = this . list ( ) ;
log . info ( "################getDriverList list:{}" , list ) ;
log . info ( "################getDriverList list:{}" , list ) ;
//Stream<BasicdataDriverArteryEntity> basicdataDriverArteryEntityStream = list.stream().filter(l -> l.getWarehouseId().contains(myCurrentWarehouse.getId().toString()));
Stream < BasicdataDriverArteryEntity > basicdataDriverArteryEntityStream = list . stream ( ) . filter ( l - > Func . isNotEmpty ( l . getWarehouseId ( ) ) & & l . getWarehouseId ( ) . contains ( myCurrentWarehouse . getId ( ) . toString ( ) ) ) ;
if ( Func . isNotEmpty ( basicdataDriverArteryEntityStream ) ) {
basicdataDriverArteryEntityStream . forEach ( l - > {
if ( Func . isNotEmpty ( basicdataDriverArteryEntityStream ) ) {
basicdataDriverArteryEntityStream . forEach ( l - > {
BasicdataDriverArteryVO driverArteryVO = Func . copy ( l , BasicdataDriverArteryVO . class ) ;
List < Long > vehicleIds = basicdataDrivermiddleService . list ( Wrappers . < BasicdataDrivermiddleEntity > query ( ) . lambda ( )
. eq ( BasicdataDrivermiddleEntity : : getDriverId , l . getId ( ) ) ) . stream ( ) . filter ( f - > Func . isNotEmpty ( f . getBrandId ( ) ) ) . map ( BasicdataDrivermiddleEntity : : getBrandId ) . collect ( Collectors . toList ( ) ) ;
if ( Func . isNotEmpty ( vehicleIds ) ) {
driverArteryVO . setVehicleVOList ( basicdataVehicleService . list ( Wrappers . < BasicdataVehicleEntity > query ( ) . lambda ( ) . in ( BasicdataVehicleEntity : : getId , vehicleIds ) ) ) ;
if ( Func . isNotEmpty ( vehicleIds ) ) {
driverArteryVO . setVehicleVOList ( basicdataVehicleService . list ( Wrappers . < BasicdataVehicleEntity > query ( ) . lambda ( ) . in ( BasicdataVehicleEntity : : getId , vehicleIds ) ) ) ;
}
basicdataDriverArteryVOS . add ( driverArteryVO ) ;
} ) ;
@ -157,89 +152,100 @@ public class BasicdataDriverArteryServiceImpl extends BaseServiceImpl<BasicdataD
* @param data
* /
@Override
public void importDriverArtery ( List < BasicdataDriverArteryImproterExcel > data ) {
log . info ( "传入参数>>>>>>>>>>>>>>>>>>>>>>>{}" , data ) ;
@Transactional
public void importDriverArtery ( List < BasicdataDriverArteryImproterExcel > data ) {
log . info ( "传入参数>>>>>>>>>>>>>>>>>>>>>>>{}" , data ) ;
outerLoop :
for ( BasicdataDriverArteryImproterExcel datum : data ) {
List < BasicdataDrivermiddleEntity > driverMiddleEntity = new ArrayList < > ( ) ;
//检查数据是否为空
if ( ObjectUtils . isEmpty ( datum . getPhone ( ) ) | | ObjectUtils . isEmpty ( datum . getName ( ) ) | | ObjectUtils . isEmpty ( datum . getWarehouseName ( ) ) | | ObjectUtils . isEmpty ( datum . getCarrierName ( ) ) ) {
try {
List < BasicdataDrivermiddleEntity > driverMiddleEntity = new ArrayList < > ( ) ;
//检查数据是否为空
if ( ObjectUtils . isEmpty ( datum . getPhone ( ) ) | | ObjectUtils . isEmpty ( datum . getName ( ) ) | | ObjectUtils . isEmpty ( datum . getWarehouseName ( ) ) | | ObjectUtils . isEmpty ( datum . getCarrierName ( ) ) ) {
// log.error("必填数据不能为空");
// continue;
throw new ServiceException ( "用户" + datum . getName ( ) + "必填数据不能为空!" ) ;
}
if ( ! ObjectUtils . isEmpty ( datum . getPhone ( ) ) ) {
R < User > userR = userClient . userInfoByPhone ( "627683" , datum . getPhone ( ) ) ;
if ( userR . getData ( ) = = null ) {
throw new ServiceException ( "必填数据不能为空!" ) ;
}
if ( ! ObjectUtils . isEmpty ( datum . getPhone ( ) ) ) {
R < User > userR = userClient . userInfoByPhone ( "627683" , datum . getPhone ( ) ) ;
if ( userR . getData ( ) = = null ) {
// log.error("未找到用户");
// continue;
throw new ServiceException ( "用户" + datum . getName ( ) + "未找到用户!" ) ;
} else {
datum . setUserId ( userR . getData ( ) . getId ( ) ) ;
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 ( ! ObjectUtils . isEmpty ( datum . getBindVehicle ( ) ) ) {
String [ ] car = datum . getBindVehicle ( ) . split ( "," ) ;
for ( String s : car ) {
List < BasicdataVehicleEntity > carListByName = basicdataVehicleService . findCarListByName ( s ) ;
if ( carListByName . isEmpty ( ) ) {
if ( carListByName . isEmpty ( ) ) {
// log.error("未找到可绑定的车辆");
throw new ServiceException ( "用户" + datum . getName ( ) + "未找到可绑定的车辆!" ) ;
} else {
BasicdataDrivermiddleEntity basicdataDrivermiddleEntity = new BasicdataDrivermiddleEntity ( ) ;
basicdataDrivermiddleEntity . setBrandId ( carListByName . get ( 0 ) . getId ( ) ) ;
driverMiddleEntity . add ( basicdataDrivermiddleEntity ) ;
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 ( datum . getCarrierName ( ) ) ) {
//找到数据库内的承运商
List < BasicdataCarrierEntity > basicdataCarrierEntities = basicdataCarrierService . list ( Wrappers . < BasicdataCarrierEntity > lambdaQuery ( ) . eq ( BasicdataCarrierEntity : : getCarrierName , datum . getCarrierName ( ) ) ) ;
if ( ObjectUtils . isEmpty ( basicdataCarrierEntities ) ) {
if ( ObjectUtils . isEmpty ( basicdataCarrierEntities ) ) {
// log.error("未找到承运商");
// continue;
throw new ServiceException ( "用户" + datum . getName ( ) + "未找到承运商!" ) ;
} else {
datum . setCarrierId ( basicdataCarrierEntities . get ( 0 ) . getId ( ) ) ;
throw new ServiceException ( "未找到承运商!" ) ;
} else {
datum . setCarrierId ( basicdataCarrierEntities . get ( 0 ) . getId ( ) ) ;
}
}
}
if ( ! ObjectUtils . isEmpty ( datum . getWarehouseName ( ) ) ) {
//在数据库找到仓库名字对应
BasicdataWarehouseEntity byName = warehouseClient . findByName ( datum . getWarehouseName ( ) ) ;
if ( ObjectUtils . isEmpty ( byName ) ) {
if ( ! ObjectUtils . isEmpty ( datum . getWarehouseName ( ) ) ) {
//在数据库找到仓库名字对应
BasicdataWarehouseEntity byName = warehouseClient . findByName ( datum . getWarehouseName ( ) ) ;
if ( ObjectUtils . isEmpty ( byName ) ) {
// log.error("未找到仓库");
// continue;
throw new ServiceException ( "用户" + datum . getName ( ) + "未找到仓库!" ) ;
} else {
datum . setWarehouseId ( String . valueOf ( byName . getId ( ) ) ) ;
throw new ServiceException ( "未找到仓库!" ) ;
} else {
datum . setWarehouseId ( String . valueOf ( byName . getId ( ) ) ) ;
}
}
}
//根据手机号去重 如果有手机号相同 就删除老数据
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 ( ) ) ;
//根据手机号去重 如果有手机号相同 就删除老数据
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 . setUserId ( user . getUserId ( ) ) ; // 创建人
copy . setUpdateUser ( user . getUserId ( ) ) ; // 更新人
log . info ( "复制后>>>>>>>>>>>>{}" , copy ) ;
BasicdataDriverArteryEntity copy = Func . copy ( datum , BasicdataDriverArteryEntity . class ) ;
//连接到前端后取消注释
BladeUser user = AuthUtil . getUser ( ) ;
copy . setTenantId ( user . getTenantId ( ) ) ; // 租户号
copy . setUserId ( user . getUserId ( ) ) ; // 创建人
copy . setUpdateUser ( user . getUserId ( ) ) ; // 更新人
log . info ( "复制后>>>>>>>>>>>>{}" , copy ) ;
this . save ( copy ) ;
//车辆和司机绑定关系
for ( BasicdataDrivermiddleEntity basicdataDrivermiddleEntity : driverMiddleEntity ) {
basicdataDrivermiddleEntity . setDriverId ( copy . getId ( ) ) ;
basicdataDrivermiddleServiceImpl . save ( basicdataDrivermiddleEntity ) ;
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 ( ) ) ;
}
}
}