feat(management):管理后台-开通城市管理
| New file |
| | |
| | | package com.xiaopeng.vehicleConvoy.config; |
| | | |
| | | import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; |
| | | import com.xiaopeng.common.core.utils.StringUtils; |
| | | import com.xiaopeng.common.security.utils.SecurityUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.ibatis.reflection.MetaObject; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | | import java.time.LocalDateTime; |
| | | |
| | | /** |
| | | * @author xiaochen |
| | | * @ClassName DataUpdateInterceptor |
| | | * @Description 数据更新操作处理 |
| | | * @date 2021-12-15 |
| | | * <p> |
| | | * 注意,之前在此处注入了 JwtTokenUtils |
| | | * <p> |
| | | * 造成spring循环依赖,项目支棱不起来 |
| | | */ |
| | | @Slf4j |
| | | @Configuration |
| | | public class DataUpdateHandlerConfig implements MetaObjectHandler { |
| | | |
| | | /** |
| | | * 新增数据执行 |
| | | * |
| | | * @param metaObject |
| | | */ |
| | | @Override |
| | | public void insertFill(MetaObject metaObject) { |
| | | String userName = ""; |
| | | try{ |
| | | // 获取登录信息 |
| | | userName = SecurityUtils.getLoginUser().getSysUser().getNickName(); |
| | | log.info("DataUpdateInterceptor insertFill"); |
| | | } catch (Exception e) { |
| | | log.error("DataUpdateInterceptor insertFill error:{}", e.getMessage()); |
| | | } |
| | | if (StringUtils.isNotBlank(userName)) { |
| | | this.setFieldValByName("createBy", userName, metaObject); |
| | | this.setFieldValByName("updateBy", userName, metaObject); |
| | | } else { |
| | | this.setFieldValByName("createBy", userName, metaObject); |
| | | this.setFieldValByName("updateBy", userName, metaObject); |
| | | } |
| | | this.setFieldValByName("createTime", LocalDateTime.now(), metaObject); |
| | | this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject); |
| | | this.setFieldValByName("createBy", userName, metaObject); |
| | | } |
| | | |
| | | /** |
| | | * 修改数据执行 |
| | | * |
| | | * @param metaObject |
| | | */ |
| | | @Override |
| | | public void updateFill(MetaObject metaObject) { |
| | | String userName = ""; |
| | | try{ |
| | | // 获取登录信息 |
| | | userName = SecurityUtils.getLoginUser().getSysUser().getNickName(); |
| | | log.info("DataUpdateInterceptor insertFill"); |
| | | } catch (Exception e) { |
| | | log.error("DataUpdateInterceptor insertFill error:{}", e.getMessage()); |
| | | } |
| | | this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject); |
| | | this.setFieldValByName("updateBy", userName, metaObject); |
| | | |
| | | } |
| | | } |
| | |
| | | * @param dto 添加车队DTO |
| | | * @return 操作结果 |
| | | */ |
| | | @ApiOperation(value = "添加车队", tags = {"管理后台-车队管理"}) |
| | | @ApiOperation(value = "添加车队", tags = {"管理后台-车队管理"}, notes = "打卡地列表接口在xp-robotaxi-maintenance-boot,人员列表在xp-robotaxi-account-boot") |
| | | @PostMapping("/api/v1/fleet/add") |
| | | public R<Void> add(@Valid @RequestBody FleetAddDTO dto) { |
| | | return xpFleetService.add(dto); |
| | |
| | | |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.vehicleConvoy.service.IXpFleetVehicleService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | |
| | | * @since 2026-02-03 |
| | | */ |
| | | @RestController |
| | | @Api(tags = "车队车辆管理") |
| | | public class XpFleetVehicleController { |
| | | |
| | | @Resource |
| | |
| | | // 2. 校验运维人员绑定 |
| | | validateUserBinding(dto.getOperationsUserIds(), null); |
| | | |
| | | // 3. 校验车辆绑定 |
| | | validateVehicleBinding(dto.getVehicleIds(), null); |
| | | // 3. 处理车辆绑定(自动解绑已绑定的车辆) |
| | | handleVehicleBinding(dto.getVehicleIds(), null); |
| | | |
| | | // 4. 插入车队主表记录 |
| | | XpFleet fleet = new XpFleet(); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 校验车辆绑定 |
| | | * 处理车辆绑定(自动解绑已绑定的车辆) |
| | | * |
| | | * @param vehicleIds 车辆ID列表 |
| | | * @param excludeFleetId 排除的车队ID(编辑时使用) |
| | | */ |
| | | private void validateVehicleBinding(List<Long> vehicleIds, Long excludeFleetId) { |
| | | private void handleVehicleBinding(List<Long> vehicleIds, Long excludeFleetId) { |
| | | if (CollectionUtils.isEmpty(vehicleIds)) { |
| | | return; |
| | | } |
| | |
| | | } |
| | | XpFleetVehicle fleetVehicle = xpFleetVehicleService.getOne(wrapper); |
| | | if (fleetVehicle != null) { |
| | | // 查询车牌号和车队名称 |
| | | R<XpVehicle> vehicleResult = xpVehicleClient.queryById(vehicleId); |
| | | XpFleet fleet = this.getById(fleetVehicle.getFleetId()); |
| | | String plateNumber = vehicleResult.getData() != null ? vehicleResult.getData().getPlateNumber() : "未知"; |
| | | String fleetName = fleet != null ? fleet.getFleetName() : "未知"; |
| | | List<Object> argList = new ArrayList<>(); |
| | | argList.add(plateNumber); |
| | | argList.add(fleetName); |
| | | throw new ServiceException("车辆[" + plateNumber + "]已绑定车队[" + fleetName + "]", I18nKeyConstant.FLEET_VEHICLE_BOUND_V1, argList.toArray()); |
| | | // 车辆已绑定其他车队,自动解绑 |
| | | xpFleetVehicleService.removeById(fleetVehicle.getId()); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void addVehicle(Long fleetId, Long vehicleId) { |
| | | // 查询是否已关联 |
| | | // 1. 检查是否已关联当前车队 |
| | | Long count = xpFleetVehicleService.lambdaQuery().eq(XpFleetVehicle::getFleetId, fleetId) |
| | | .eq(XpFleetVehicle::getVehicleId, vehicleId).count(); |
| | | if (count > 0) { |
| | | throw new ServiceException("当前车队已和该车辆关联", I18nKeyConstant.FLEET_VEHICLE_BOUND_V2); |
| | | } |
| | | //保存关联关系 |
| | | |
| | | // 2. 检查是否已绑定其他车队,如果是则自动解绑 |
| | | XpFleetVehicle existingBinding = xpFleetVehicleService.lambdaQuery() |
| | | .eq(XpFleetVehicle::getVehicleId, vehicleId) |
| | | .ne(XpFleetVehicle::getFleetId, fleetId) |
| | | .one(); |
| | | if (existingBinding != null) { |
| | | // 车辆已绑定其他车队,自动解绑 |
| | | xpFleetVehicleService.removeById(existingBinding.getId()); |
| | | } |
| | | |
| | | // 3. 保存新的关联关系 |
| | | XpFleetVehicle xpFleetVehicle = new XpFleetVehicle(); |
| | | xpFleetVehicle.setFleetId(fleetId); |
| | | xpFleetVehicle.setVehicleId(vehicleId); |
| | |
| | | ORDER BY create_time DESC |
| | | </select> |
| | | <select id="getList" resultType="com.xiaopeng.vehicleConvoy.model.vo.XpVehicleVO"> |
| | | |
| | | select xv.id, |
| | | xv.vehicle_code, |
| | | xv.vehicle_vin, |
| | | xv.plate_number, |
| | | xv.vehicle_model, |
| | | xv.vehicle_color, |
| | | xv.vehicle_pictures, |
| | | xv.procurement_source, |
| | | xv.remarks, |
| | | xv.annual_inspection_date, |
| | | xv.insurance_company, |
| | | xv.insurance_phone, |
| | | xv.insurance_end_time, |
| | | xv.inspection_attachments, |
| | | xv.policy_information, |
| | | xv.electronic_id, |
| | | xv.operation_qualification, |
| | | xv.qualification_expire_time, |
| | | xv.state, |
| | | xv.status, |
| | | xv.operating_status, |
| | | xv.warehousing_time, |
| | | xv.vehicle_type, |
| | | xv.accept_or_test, |
| | | xv.accept_or_test_status, |
| | | xv.current_electricity, |
| | | xv.is_deleted, |
| | | xv.create_time, |
| | | xv.update_time, |
| | | xv.create_by, |
| | | xv.update_by, |
| | | xf.fleet_name |
| | | from xp_vehicle xv |
| | | left join xp_fleet_vehicle xfv on xv.id = xfv.vehicle_id |
| | | left join xp_fleet xf on xfv.fleet_id = xf.id |
| | | <where> |
| | | xv.is_deleted = 0 |
| | | <if test="plateNumber != null and plateNumber != ''"> |
| | | and xv.plate_number like concat('%', #{plateNumber}, '%') |
| | | </if> |
| | | <if test="fleetName != null and fleetName != ''"> |
| | | and xf.fleet_name like concat('%', #{fleetName}, '%') |
| | | </if> |
| | | </where> |
| | | order by xv.create_time desc |
| | | </select> |
| | | |
| | | </mapper> |