管理车辆上传

master
shaowenhao 2023-11-24 13:37:20 +08:00
parent 9dbcc973c2
commit 5e85548b01
11 changed files with 343 additions and 67 deletions

View File

@ -7,7 +7,6 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
*
*

View File

@ -1,28 +1,31 @@
package com.god.base.server.common.domain;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.god.base.server.common.domain.request.CarRequest;
import com.god.common.core.annotation.Excel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
*
* @ClassName Car
* @Author WenHao.Sao
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@NoArgsConstructor
@Builder
@TableName(value = "t_car")
public class Car {
public class Car {
/**
* Vin
*/
@Excel(name = "车辆carVibId")
private String carVinId;
/**
* id
@ -31,6 +34,7 @@ public class Car {
/**
* id
*/
@Excel(name = "车辆类型ID")
private long carTypeId;
/**
* id
@ -51,6 +55,7 @@ public class Car {
/**
* ID
*/
@Excel(name = "电子围栏ID")
private long fenceId;
/**
*
@ -71,6 +76,8 @@ public class Car {
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "开始时间" , width = 30, dateFormat = "yyyy-MM-dd")
private Date createTime;
/**
*
@ -79,7 +86,8 @@ public class Car {
/**
*
*/
@DateTimeFormat
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "结束时间" , width = 30, dateFormat = "yyyy-MM-dd")
private Date updateTime;
/**
*
@ -88,40 +96,43 @@ public class Car {
/**
*
*/
@Excel(name = "电池厂商")
private String batteryManufacturer;
/**
*
*/
@Excel(name = "电机厂商")
private String motorManufacturer;
/**
*
*/
@Excel(name = "电机编号")
private String motorNumber;
/**
*
*/
@Excel(name = "电池编号")
private String batteryNumber;
/**
*
*/
private int isDelete;
/**
*
*/
@Excel(name = "车辆状态")
private int status;
public static Car addReqBuild(CarRequest carRequest){
public static Car carBuildAdd(CarRequest carRequest){
return Car.builder()
//把所有的属性点都加上
.carVinId(carRequest.getCarVinId())
.carTypeId(carRequest.getCarTypeId())
.fenceId(carRequest.getFenceId())
.status(carRequest.getStatus())
.batteryManufacturer(carRequest.getBatteryManufacturer())
.motorManufacturer(carRequest.getMotorManufacturer())
.motorNumber(carRequest.getMotorNumber())
.batteryNumber(carRequest.getBatteryNumber())
.batteryNumber(carRequest.getBatteryNumber())
.build()
;
.build();
}
}

View File

@ -1,5 +1,7 @@
package com.god.base.server.common.domain.request;
import com.god.base.common.page.PageQuery;
import com.god.common.core.annotation.Excel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -14,42 +16,54 @@ import javax.validation.constraints.NotNull;
@NoArgsConstructor
@AllArgsConstructor
@NotNull
public class CarRequest {
public class CarRequest extends PageQuery {
/**
* Vin
*/
@NotEmpty(message = "车辆vin不能为空")
@Excel(name = "车辆carVibId")
private String carVinId;
/**
*
*/
@NotEmpty(message = "车辆类型不能为空")
@NotNull(message = "车辆类型不能为空")
@Excel(name = "车辆类型ID")
private long carTypeId;
/**
* ID
*/
@NotEmpty(message = "电子围栏不能为空")
@NotNull(message = "电子围栏不能为空")
@Excel(name = "电子围栏ID")
private long fenceId;
/**
* 线 /
*/
@Excel(name = "车辆状态")
private int status;
/**
*
*/
@NotEmpty(message = "电池厂商不能为空")
@Excel(name = "电池厂商")
private String batteryManufacturer;
/**
*
*/
@NotEmpty(message = "电机厂商不能为空")
@Excel(name = "电机厂商")
private String motorManufacturer;
/**
*
*/
@NotEmpty(message = "电机编号不能为空")
@Excel(name = "电机编号")
private String motorNumber;
/**
*
*/
@NotEmpty(message = "电池编号不能为空")
@Excel(name = "电池编号")
private String batteryNumber;

View File

@ -6,7 +6,7 @@ server:
spring:
application:
# 应用名称
name: god-car-base
name: god-car-management
profiles:
# 环境配置
active: dev

View File

@ -18,5 +18,22 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
public class GodCarBaseApplication {
public static void main (String[] args) {
SpringApplication.run(GodCarBaseApplication.class, args);
System.out.println("(♥◠‿◠)ノ゙ 车辆管理模块启动成功 ლ(´ڡ`ლ)゙ \n" +
" ,--, \n" +
" ,---.'| ,--. \n" +
" ,---, | | : ,---, ,--.'| \n" +
" ' .' \\ : : | ' .' \\ ,--,: : | \n" +
" / ; '. | ' : / ; '. ,`--.'`| ' : \n" +
": : \\ ; ; ' : : \\ | : : | | \n" +
": | /\\ \\ ' | |__ : | /\\ \\ : | \\ | : \n" +
"| : ' ;. : | | :.'|| : ' ;. : | : ' '; | \n" +
"| | ;/ \\ \\' : ;| | ;/ \\ \\' ' ;. ; \n" +
"' : | \\ \\ ,'| | ./ ' : | \\ \\ ,'| | | \\ | \n" +
"| | ' '--' ; : ; | | ' '--' ' : | ; .' \n" +
"| : : | ,/ | : : | | '`--' \n" +
"| | ,' '---' | | ,' ' : | \n" +
"`--'' `--'' ; |.' \n" +
" '---' \n" +
" ");
}
}

View File

@ -1,13 +1,23 @@
package com.god.base.server.controller;
import com.alibaba.fastjson.JSONObject;
import com.god.base.server.common.domain.Car;
import com.god.base.server.common.domain.request.CarRequest;
import com.god.base.server.service.CarService;
import com.god.common.core.domain.Result;
import com.god.common.core.utils.poi.ExcelUtil;
import com.god.common.core.web.controller.BaseController;
import com.god.common.core.web.page.TableDataInfo;
import com.god.common.log.annotation.Log;
import com.god.common.log.enums.BusinessType;
import com.god.common.security.annotation.RequiresPermissions;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.god.common.core.domain.Result;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
@ -16,55 +26,128 @@ import java.util.List;
@RestController
@RequestMapping("/car")
@Log4j2
public class CarController {
public class CarController extends BaseController {
@Autowired
private HttpServletRequest request; // 用于获取方法执行信息
@Autowired
private CarService carService;
/**
*
*/
@RequiresPermissions
@GetMapping("/list")
public Result<TableDataInfo<Car>> list(@RequestBody CarRequest carRequest){
log.info("功能介绍车辆信息列表查看,请求方式:{},请求路径:{},请求参数:{}",
request.getMethod(),
request.getRequestURL(),
JSONObject.toJSONString(carRequest));
startPage();//设置请求分页数据
List<Car> list = carService.selectCarInfoList(carRequest);
log.info("功能介绍车辆信息列表查看,响应方式:{},响应路径:{},响应参数:{}",
request.getMethod(),
request.getRequestURL(),
JSONObject.toJSONString(list));
return getDataTable(list);
}
/**
*
*/
@GetMapping("carList/{userId}")
public Result<?> carList(@PathVariable String userId){
log.info("请求参数" + userId);
log.info("功能介绍车辆信息列表查看,请求方式:{},请求路径:{},请求参数:{}",
request.getMethod(),
request.getRequestURL(),
JSONObject.toJSONString(userId));
startPage();//设置请求分页数据 继承方法
Result<List<Car>> carList = carService.carList(userId);
log.info("响应参数" + carList);
log.info("功能介绍车辆信息列表查看,响应方式:{},响应路径:{},响应参数:{}",
request.getMethod(),
request.getRequestURL(),
JSONObject.toJSONString(carList));
return Result.success(carList);
}
/**
*
*
*/
@Log(title = "车辆信息管理" , businessType = BusinessType.INSERT) // 添加
@PostMapping("/addCar")
public Result<String> addCarP(@RequestBody @Validated CarRequest carRequest){
log.info("请求参数" + carRequest);
boolean save = carService.save(Car.addReqBuild(carRequest));
log.info("响应参数" + save);
return Result.success();
}
/**
*
*/
@PostMapping("/updCar/{vinId}")
public Result updCat(@PathVariable @Validated String vinId){
log.info("请求参数" + vinId);
carService.updateById(vinId);
log.info("响应参数" + vinId);
carService.save(Car.carBuildAdd(carRequest));
return Result.success();
}
/**
*
*
*/
@PostMapping("/delCar/{vinId}")
public Result delCar(@PathVariable String vinId){
log.info("请求参数" + vinId);
boolean b = carService.removeById(vinId);
log.info("响应参数" + b);
@Log(title = "车辆信息管理" , businessType = BusinessType.UPDATE) //修改
@PostMapping("/updCar")
public Result<Car> updCar(@PathVariable @Validated Car car){
log.info("功能介绍修改车辆,请求方式:{},请求路径:{},请求参数:{}",
request.getMethod(),
request.getRequestURL(),
JSONObject.toJSONString(car));
carService.updateById(car);
log.info("功能介绍修改车辆,响应方式:{},响应路径:{},响应参数:{}",
request.getMethod(),
request.getRequestURL(),
JSONObject.toJSONString(car));
return Result.success();
}
/**
*
*/
@Log(title = "车辆信息管理" , businessType = BusinessType.DELETE) // 删除
@DeleteMapping("/delCar/{vinId}")
public Result delCar(@PathVariable String vinId){
log.info("功能介绍逻辑删除车辆信息,请求方式:{},请求路径:{},请求参数:{}",
request.getMethod(),
request.getRequestURL(),
JSONObject.toJSONString(vinId));
boolean b = carService.removeById(vinId);
log.info("功能介绍逻辑删除车辆信息,响应方式:{},响应路径:{},响应参数:{}",
request.getMethod(),
request.getRequestURL(),
JSONObject.toJSONString(b));
return Result.success();
}
/**
*
*/
@RequiresPermissions("car:car:export")
@Log(title = "车辆信息管理" , businessType = BusinessType.EXPORT) // 导出 跳转业务操作类型表中
@PostMapping("/export")
public void export(HttpServletResponse response , Car car , CarRequest carRequest)
{
List<Car> list = carService.selectCarInfoList(carRequest);
ExcelUtil<Car> util = new ExcelUtil<>(Car.class);
//对list数据源将其里面的数据导入到excel表单
util.exportExcel(response,list,"车辆信息管理");
}
/**
*
*/

View File

@ -1,10 +1,11 @@
package com.god.base.server.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.god.base.server.common.domain.Car;
import com.god.base.server.common.domain.request.CarRequest;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@ -15,5 +16,38 @@ import java.util.List;
@Mapper
public interface CarMapper extends BaseMapper<Car> {
List<Car> getList(int userId1);
@Select("SELECT\n" +
"t_car.car_vin_id ,\n" +
"t_car_type.car_type_name , \n" +
"t_fence.fence_name , \n" +
"t_car.battery_manufacturer ,\n" +
"t_car.motor_manufacturer ,\n" +
"t_car.motor_number , \n" +
"t_car.battery_number ,\n" +
"t_car.status \n" +
"\n" +
"FROM\n" +
"\tt_car\n" +
"\tJOIN t_fence ON t_car.fence_id = t_fence.fence_id\n" +
"\tJOIN t_car_type ON t_car.car_type_id = t_car_type.id where t_car.user_id = #{userId1}")
List<Car> getList(@Param("userId1") int userId);
@Select("select * from t_car where 1=1 " +
"<if test=\"carVinId != null and carVinId != ''\"> and car_vin_id = #{carVinId}</if>" +
"<if test=\"carTypeId != null \"> and car_type_id = #{carTypeId}</if>" +
"<if test=\"fenceId != null and fenceId != ''\"> and fence_id = #{fenceId}</if>" +
"<if test=\"status != null \"> and status = #{status}</if>" +
"<if test=\"motorManufacturer != null and motorManufacturer != ''\"> and motor_manufacturer = #{motorManufacturer}</if>" +
"<if test=\"batteryManufacturer != null and batteryManufacturer != ''\"> and battery_manufacturer = #{batteryManufacturer}</if>" +
"<if test=\"motorNumber != null and motorNumber != ''\"> and motor_number = #{motorNumber}</if>" +
"<if test=\"batteryNumber != null and batteryNumber != ''\"> and battery_number = #{batteryNumber}</if>"
)
List<Car> selectCarInfoList(Car car);
/**
*
* @param carRequest
* @return
*/
List<Car> selectVehicleInfoList(CarRequest carRequest);
}

View File

@ -1,8 +1,11 @@
package com.god.base.server.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.god.base.server.common.domain.Car;
import com.god.base.server.common.domain.request.CarRequest;
import com.god.common.core.domain.Result;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
@ -13,5 +16,9 @@ public interface CarService extends IService<Car> {
Result<List<Car>> carList(@Param("userId") String userId);
void updateById(@Param("vinId") String vinId);
List<Car> selectCarInfoList(CarRequest carRequest);
}

View File

@ -1,12 +1,18 @@
package com.god.base.server.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.god.base.server.common.domain.Car;
import com.god.base.server.common.domain.request.CarRequest;
import com.god.base.server.mapper.CarMapper;
import com.god.base.server.service.CarService;
import com.god.common.core.domain.Result;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.Serializable;
import java.util.List;
/**
@ -14,10 +20,18 @@ import java.util.List;
*/
@Log4j2
@Service
public class CarServiceImpl extends ServiceImpl<CarMapper,Car> implements CarService {
public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements CarService {
@Autowired
private CarMapper carMapper;
/**
*
*
* @param userId
* @return
*/
@Override
public Result<List<Car>> carList(String userId) {
// Long userId1 = SecurityUtils.getUserId();
@ -26,17 +40,93 @@ public class CarServiceImpl extends ServiceImpl<CarMapper,Car> implements CarSer
// }
int userId1 = 1;
List<Car> carList = carMapper.getList(userId1);
return Result.success(carList);
return Result.success(carList);
}
/**
*
* @param vinId
*
*
* @param carRequest
* @return
*/
@Override
public void updateById(String vinId) {
public List<Car> selectCarInfoList(CarRequest carRequest) {
LambdaQueryWrapper<Car> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//判断vin是否为空
if (StringUtils.isNotEmpty(carRequest.getCarVinId())){
//模糊查询 vin
lambdaQueryWrapper.like(Car::getCarVinId, carRequest.getCarVinId());
}
//模糊查询 车辆类型
lambdaQueryWrapper.like(Car::getCarTypeId, carRequest.getCarTypeId());
//模糊查询 电子围栏
lambdaQueryWrapper.like(Car::getFenceId, carRequest.getFenceId());
//模糊查询 车辆状态
lambdaQueryWrapper.like(Car::getStatus, carRequest.getStatus());
if (StringUtils.isNotEmpty(carRequest.getBatteryManufacturer())){
//模糊查询 电池厂商
lambdaQueryWrapper.like(Car::getBatteryManufacturer, carRequest.getBatteryManufacturer());
}
if (StringUtils.isNotEmpty(carRequest.getMotorManufacturer())){
//模糊查询 电机厂商
lambdaQueryWrapper.like(Car::getMotorManufacturer, carRequest.getMotorManufacturer());
}
if (StringUtils.isNotEmpty(carRequest.getMotorNumber())){
//模糊查询 电机编号
lambdaQueryWrapper.like(Car::getMotorNumber, carRequest.getMotorNumber());
}
if (StringUtils.isNotEmpty(carRequest.getBatteryNumber())){
//模糊查询 电池编号
lambdaQueryWrapper.like(Car::getBatteryNumber, carRequest.getBatteryNumber());
}
return carMapper.selectVehicleInfoList(carRequest);
}
/**
* VIN
* @param entity
* @return
*/
@Override
public boolean updateById(Car entity) {
boolean updatedById = super.updateById(entity);
if (!updatedById){
throw new RuntimeException("修改失败");
}
return true;
}
/**
*
* @param entity
* @return
*/
@Override
public boolean save(Car entity) {
boolean addCar = super.save(entity);
if (!addCar){
throw new RuntimeException("添加车辆管理失败失败");
}
return true;
}
/**
*
*
* @param id
* @return
*/
@Override
public boolean removeById(Serializable id) {
boolean remove = super.removeById(id);
if (!remove) {
log.warn("删除管理车辆数据:[/-{}-/]失败!", id);
throw new RuntimeException("删除管理车辆数据失败");
}
return true;
}

View File

@ -1,6 +1,6 @@
# Tomcat
server:
port: 9802
port: 9028
# Spring
spring:

View File

@ -3,20 +3,41 @@
<mapper namespace="com.god.base.server.mapper.CarMapper">
<!-- 车辆列表-->
<select id="getList" resultType="com.god.base.server.common.domain.Car">
SELECT
*
FROM
t_car
JOIN t_car_type ON t_car.car_type_id = t_car_type.id
JOIN t_battery_box ON t_car.battery_box_id = t_battery_box.battery_box_id
JOIN t_cell ON t_car.cell_id = t_cell.cell_id
JOIN t_batterycell ON t_car.battery_cell_id = t_batterycell.batterycell_id
JOIN t_batterypackinformation ON t_car.battery_pack_information_id = t_batterypackinformation.batterypackinformation_id
JOIN t_drive_motor ON t_car.drive_motor_id = t_drive_motor.drive_motor_id
<!-- <select id="getList" resultType="com.god.base.server.common.domain.Car">-->
<!-- SELECT-->
<!-- t_car.car_vin_id as vin ,-->
<!-- t_car.car_type_id as 车辆类型 ,-->
<!-- t_car.fence_id as 电子围栏ID ,-->
<!-- t_car.battery_manufacturer as 电池厂商 ,-->
<!-- t_car.motor_manufacturer as 电机厂商 ,-->
<!-- t_car.motor_number as 电机编号 ,-->
<!-- t_car.battery_number as 电池编号 ,-->
<!-- t_car.status as 车辆状态-->
<!-- FROM-->
<!-- t_car-->
<!-- JOIN t_fence ON t_car.fence_id = t_fence.fence_id-->
<!-- JOIN t_car_type ON t_car.car_type_id = t_car_type.id-->
<!-- where t_car.user_id = #{userId1}-->
<!-- </select>-->
<sql id="selectVehicleInfoVo">
select car_vin_id, car_type_id, fence_id, battery_manufacturer, motor_manufacturer, motor_numberr, battery_number,status from t_car
</sql>
<!--车辆列表查询-->
<select id="selectVehicleInfoList" resultType="com.god.base.server.common.domain.Car">
<include refid="selectVehicleInfoVo"/>
<where>
<if test="carVinId != null and carVinId != ''"> and car_vin_id = #{carVinId}</if>"
<if test="carTypeId != null"> and car_type_id = #{carTypeId}</if>"
<if test="fenceId != null and fenceId != ''"> and fence_id = #{fenceId}</if>"
<if test="status != null"> and status = #{status}</if>"
<if test="motorManufacturer != null and motorManufacturer != ''"> and motor_manufacturer = #{motorManufacturer}</if>"
<if test="batteryManufacturer != null and batteryManufacturer != ''"> and battery_manufacturer = #{batteryManufacturer}</if>"
<if test="motorNumber != null and motorNumber != ''"> and motor_number = #{motorNumber}</if>"
<if test="batteryNumber != null and batteryNumber != ''"> and battery_number = #{batteryNumber}</if>"
</where>
</select>
</mapper>