车辆信息
This commit is contained in:
parent
40bdd07c0b
commit
68aaa12c8b
@ -0,0 +1,95 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.controller.admin.carinfo;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
|
||||||
|
import javax.validation.constraints.*;
|
||||||
|
import javax.validation.*;
|
||||||
|
import javax.servlet.http.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||||
|
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.home.controller.admin.carinfo.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.home.dal.dataobject.carinfo.CarinfoDO;
|
||||||
|
import cn.iocoder.yudao.module.home.service.carinfo.CarinfoService;
|
||||||
|
|
||||||
|
@Tag(name = "管理后台 - 车辆信息录入")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/home/carinfo")
|
||||||
|
@Validated
|
||||||
|
public class CarinfoController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CarinfoService carinfoService;
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
@Operation(summary = "创建车辆信息录入")
|
||||||
|
@PreAuthorize("@ss.hasPermission('home:carinfo:create')")
|
||||||
|
public CommonResult<Long> createCarinfo(@Valid @RequestBody CarinfoSaveReqVO createReqVO) {
|
||||||
|
return success(carinfoService.createCarinfo(createReqVO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update")
|
||||||
|
@Operation(summary = "更新车辆信息录入")
|
||||||
|
@PreAuthorize("@ss.hasPermission('home:carinfo:update')")
|
||||||
|
public CommonResult<Boolean> updateCarinfo(@Valid @RequestBody CarinfoSaveReqVO updateReqVO) {
|
||||||
|
carinfoService.updateCarinfo(updateReqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
@Operation(summary = "删除车辆信息录入")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
|
@PreAuthorize("@ss.hasPermission('home:carinfo:delete')")
|
||||||
|
public CommonResult<Boolean> deleteCarinfo(@RequestParam("id") Long id) {
|
||||||
|
carinfoService.deleteCarinfo(id);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get")
|
||||||
|
@Operation(summary = "获得车辆信息录入")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||||
|
@PreAuthorize("@ss.hasPermission('home:carinfo:query')")
|
||||||
|
public CommonResult<CarinfoRespVO> getCarinfo(@RequestParam("id") Long id) {
|
||||||
|
CarinfoDO carinfo = carinfoService.getCarinfo(id);
|
||||||
|
return success(BeanUtils.toBean(carinfo, CarinfoRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/page")
|
||||||
|
@Operation(summary = "获得车辆信息录入分页")
|
||||||
|
@PreAuthorize("@ss.hasPermission('home:carinfo:query')")
|
||||||
|
public CommonResult<PageResult<CarinfoRespVO>> getCarinfoPage(@Valid CarinfoPageReqVO pageReqVO) {
|
||||||
|
PageResult<CarinfoDO> pageResult = carinfoService.getCarinfoPage(pageReqVO);
|
||||||
|
return success(BeanUtils.toBean(pageResult, CarinfoRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/export-excel")
|
||||||
|
@Operation(summary = "导出车辆信息录入 Excel")
|
||||||
|
@PreAuthorize("@ss.hasPermission('home:carinfo:export')")
|
||||||
|
@ApiAccessLog(operateType = EXPORT)
|
||||||
|
public void exportCarinfoExcel(@Valid CarinfoPageReqVO pageReqVO,
|
||||||
|
HttpServletResponse response) throws IOException {
|
||||||
|
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||||
|
List<CarinfoDO> list = carinfoService.getCarinfoPage(pageReqVO).getList();
|
||||||
|
// 导出 Excel
|
||||||
|
ExcelUtils.write(response, "车辆信息录入.xls", "数据", CarinfoRespVO.class,
|
||||||
|
BeanUtils.toBean(list, CarinfoRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.controller.admin.carinfo.vo;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 车辆信息录入分页 Request VO")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class CarinfoPageReqVO extends PageParam {
|
||||||
|
|
||||||
|
@Schema(description = "id", example = "1270")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "车牌号")
|
||||||
|
private String licensePlate;
|
||||||
|
|
||||||
|
@Schema(description = "具体名称型号")
|
||||||
|
private String model;
|
||||||
|
|
||||||
|
@Schema(description = "车辆品牌")
|
||||||
|
private String brand;
|
||||||
|
|
||||||
|
@Schema(description = "车辆状态", example = "1")
|
||||||
|
private Integer carStatus;
|
||||||
|
|
||||||
|
@Schema(description = "车辆类型", example = "1")
|
||||||
|
private Integer carType;
|
||||||
|
|
||||||
|
@Schema(description = "车身主要颜色")
|
||||||
|
private String color;
|
||||||
|
|
||||||
|
@Schema(description = "购买日期")
|
||||||
|
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||||
|
private LocalDateTime[] purchaseDate;
|
||||||
|
|
||||||
|
@Schema(description = "购买金额(元)", example = "15575")
|
||||||
|
private Integer purchasePrice;
|
||||||
|
|
||||||
|
@Schema(description = "发动机号")
|
||||||
|
private String engineNumber;
|
||||||
|
|
||||||
|
@Schema(description = "备注", example = "你说的对")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间")
|
||||||
|
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||||
|
private LocalDateTime[] createTime;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.controller.admin.carinfo.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import com.alibaba.excel.annotation.*;
|
||||||
|
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||||
|
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 车辆信息录入 Response VO")
|
||||||
|
@Data
|
||||||
|
@ExcelIgnoreUnannotated
|
||||||
|
public class CarinfoRespVO {
|
||||||
|
|
||||||
|
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1270")
|
||||||
|
@ExcelProperty("id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "车牌号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("车牌号")
|
||||||
|
private String licensePlate;
|
||||||
|
|
||||||
|
@Schema(description = "具体名称型号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("具体名称型号")
|
||||||
|
private String model;
|
||||||
|
|
||||||
|
@Schema(description = "车辆品牌")
|
||||||
|
@ExcelProperty("车辆品牌")
|
||||||
|
private String brand;
|
||||||
|
|
||||||
|
@Schema(description = "车辆状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@ExcelProperty(value = "车辆状态", converter = DictConvert.class)
|
||||||
|
@DictFormat("clgl_car_status") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||||
|
private Integer carStatus;
|
||||||
|
|
||||||
|
@Schema(description = "车辆类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@ExcelProperty(value = "车辆类型", converter = DictConvert.class)
|
||||||
|
@DictFormat("clgl_car_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||||
|
private Integer carType;
|
||||||
|
|
||||||
|
@Schema(description = "车身主要颜色")
|
||||||
|
@ExcelProperty("车身主要颜色")
|
||||||
|
private String color;
|
||||||
|
|
||||||
|
@Schema(description = "购买日期")
|
||||||
|
@ExcelProperty("购买日期")
|
||||||
|
private LocalDateTime purchaseDate;
|
||||||
|
|
||||||
|
@Schema(description = "购买金额(元)", example = "15575")
|
||||||
|
@ExcelProperty("购买金额(元)")
|
||||||
|
private Integer purchasePrice;
|
||||||
|
|
||||||
|
@Schema(description = "发动机号")
|
||||||
|
@ExcelProperty("发动机号")
|
||||||
|
private String engineNumber;
|
||||||
|
|
||||||
|
@Schema(description = "备注", example = "你说的对")
|
||||||
|
@ExcelProperty("备注")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("创建时间")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.controller.admin.carinfo.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import javax.validation.constraints.*;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 车辆信息录入新增/修改 Request VO")
|
||||||
|
@Data
|
||||||
|
public class CarinfoSaveReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1270")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "车牌号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotEmpty(message = "车牌号不能为空")
|
||||||
|
private String licensePlate;
|
||||||
|
|
||||||
|
@Schema(description = "具体名称型号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotEmpty(message = "具体名称型号不能为空")
|
||||||
|
private String model;
|
||||||
|
|
||||||
|
@Schema(description = "车辆品牌")
|
||||||
|
private String brand;
|
||||||
|
|
||||||
|
@Schema(description = "车辆状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@NotNull(message = "车辆状态不能为空")
|
||||||
|
private Integer carStatus;
|
||||||
|
|
||||||
|
@Schema(description = "车辆类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@NotNull(message = "车辆类型不能为空")
|
||||||
|
private Integer carType;
|
||||||
|
|
||||||
|
@Schema(description = "车身主要颜色")
|
||||||
|
private String color;
|
||||||
|
|
||||||
|
@Schema(description = "购买日期")
|
||||||
|
private LocalDateTime purchaseDate;
|
||||||
|
|
||||||
|
@Schema(description = "购买金额(元)", example = "15575")
|
||||||
|
private Integer purchasePrice;
|
||||||
|
|
||||||
|
@Schema(description = "发动机号")
|
||||||
|
private String engineNumber;
|
||||||
|
|
||||||
|
@Schema(description = "备注", example = "你说的对")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.dal.dataobject.carinfo;
|
||||||
|
|
||||||
|
import com.sun.xml.bind.v2.TODO;
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆信息录入 DO
|
||||||
|
*
|
||||||
|
* @author 君风
|
||||||
|
*/
|
||||||
|
@TableName("oa_carinfo")
|
||||||
|
@KeySequence("oa_carinfo_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class CarinfoDO extends BaseDO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 车牌号
|
||||||
|
*/
|
||||||
|
private String licensePlate;
|
||||||
|
/**
|
||||||
|
* 具体名称型号
|
||||||
|
*/
|
||||||
|
private String model;
|
||||||
|
/**
|
||||||
|
* 车辆品牌
|
||||||
|
*/
|
||||||
|
private String brand;
|
||||||
|
/**
|
||||||
|
* 车辆状态
|
||||||
|
*
|
||||||
|
* 枚举 {@link TODO clgl_car_status 对应的类}
|
||||||
|
*/
|
||||||
|
private Integer carStatus;
|
||||||
|
/**
|
||||||
|
* 车辆类型
|
||||||
|
*
|
||||||
|
* 枚举 {@link TODO clgl_car_type 对应的类}
|
||||||
|
*/
|
||||||
|
private Integer carType;
|
||||||
|
/**
|
||||||
|
* 车身主要颜色
|
||||||
|
*/
|
||||||
|
private String color;
|
||||||
|
/**
|
||||||
|
* 购买日期
|
||||||
|
*/
|
||||||
|
private LocalDateTime purchaseDate;
|
||||||
|
/**
|
||||||
|
* 购买金额(元)
|
||||||
|
*/
|
||||||
|
private Integer purchasePrice;
|
||||||
|
/**
|
||||||
|
* 发动机号
|
||||||
|
*/
|
||||||
|
private String engineNumber;
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.dal.mysql.carinfo;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import cn.iocoder.yudao.module.home.dal.dataobject.carinfo.CarinfoDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import cn.iocoder.yudao.module.home.controller.admin.carinfo.vo.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆信息录入 Mapper
|
||||||
|
*
|
||||||
|
* @author 君风
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface CarinfoMapper extends BaseMapperX<CarinfoDO> {
|
||||||
|
|
||||||
|
default PageResult<CarinfoDO> selectPage(CarinfoPageReqVO reqVO) {
|
||||||
|
return selectPage(reqVO, new LambdaQueryWrapperX<CarinfoDO>()
|
||||||
|
.eqIfPresent(CarinfoDO::getId, reqVO.getId())
|
||||||
|
.eqIfPresent(CarinfoDO::getLicensePlate, reqVO.getLicensePlate())
|
||||||
|
.eqIfPresent(CarinfoDO::getModel, reqVO.getModel())
|
||||||
|
.eqIfPresent(CarinfoDO::getBrand, reqVO.getBrand())
|
||||||
|
.eqIfPresent(CarinfoDO::getCarStatus, reqVO.getCarStatus())
|
||||||
|
.eqIfPresent(CarinfoDO::getCarType, reqVO.getCarType())
|
||||||
|
.eqIfPresent(CarinfoDO::getColor, reqVO.getColor())
|
||||||
|
.betweenIfPresent(CarinfoDO::getPurchaseDate, reqVO.getPurchaseDate())
|
||||||
|
.eqIfPresent(CarinfoDO::getPurchasePrice, reqVO.getPurchasePrice())
|
||||||
|
.eqIfPresent(CarinfoDO::getEngineNumber, reqVO.getEngineNumber())
|
||||||
|
.eqIfPresent(CarinfoDO::getRemark, reqVO.getRemark())
|
||||||
|
.betweenIfPresent(CarinfoDO::getCreateTime, reqVO.getCreateTime())
|
||||||
|
.orderByDesc(CarinfoDO::getId));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.service.carinfo;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import javax.validation.*;
|
||||||
|
import cn.iocoder.yudao.module.home.controller.admin.carinfo.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.home.dal.dataobject.carinfo.CarinfoDO;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆信息录入 Service 接口
|
||||||
|
*
|
||||||
|
* @author 君风
|
||||||
|
*/
|
||||||
|
public interface CarinfoService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建车辆信息录入
|
||||||
|
*
|
||||||
|
* @param createReqVO 创建信息
|
||||||
|
* @return 编号
|
||||||
|
*/
|
||||||
|
Long createCarinfo(@Valid CarinfoSaveReqVO createReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新车辆信息录入
|
||||||
|
*
|
||||||
|
* @param updateReqVO 更新信息
|
||||||
|
*/
|
||||||
|
void updateCarinfo(@Valid CarinfoSaveReqVO updateReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除车辆信息录入
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
*/
|
||||||
|
void deleteCarinfo(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得车辆信息录入
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @return 车辆信息录入
|
||||||
|
*/
|
||||||
|
CarinfoDO getCarinfo(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得车辆信息录入分页
|
||||||
|
*
|
||||||
|
* @param pageReqVO 分页查询
|
||||||
|
* @return 车辆信息录入分页
|
||||||
|
*/
|
||||||
|
PageResult<CarinfoDO> getCarinfoPage(CarinfoPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.service.carinfo;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import cn.iocoder.yudao.module.home.controller.admin.carinfo.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.home.dal.dataobject.carinfo.CarinfoDO;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.home.dal.mysql.carinfo.CarinfoMapper;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static cn.iocoder.yudao.module.home.enums.ErrorCodeConstants.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆信息录入 Service 实现类
|
||||||
|
*
|
||||||
|
* @author 君风
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
public class CarinfoServiceImpl implements CarinfoService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CarinfoMapper carinfoMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long createCarinfo(CarinfoSaveReqVO createReqVO) {
|
||||||
|
// 插入
|
||||||
|
CarinfoDO carinfo = BeanUtils.toBean(createReqVO, CarinfoDO.class);
|
||||||
|
carinfoMapper.insert(carinfo);
|
||||||
|
// 返回
|
||||||
|
return carinfo.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateCarinfo(CarinfoSaveReqVO updateReqVO) {
|
||||||
|
// 校验存在
|
||||||
|
validateCarinfoExists(updateReqVO.getId());
|
||||||
|
// 更新
|
||||||
|
CarinfoDO updateObj = BeanUtils.toBean(updateReqVO, CarinfoDO.class);
|
||||||
|
carinfoMapper.updateById(updateObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteCarinfo(Long id) {
|
||||||
|
// 校验存在
|
||||||
|
validateCarinfoExists(id);
|
||||||
|
// 删除
|
||||||
|
carinfoMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateCarinfoExists(Long id) {
|
||||||
|
if (carinfoMapper.selectById(id) == null) {
|
||||||
|
throw exception(CARINFO_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CarinfoDO getCarinfo(Long id) {
|
||||||
|
return carinfoMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<CarinfoDO> getCarinfoPage(CarinfoPageReqVO pageReqVO) {
|
||||||
|
return carinfoMapper.selectPage(pageReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="cn.iocoder.yudao.module.home.dal.mysql.carinfo.CarinfoMapper">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||||
|
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||||
|
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||||
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
|
-->
|
||||||
|
|
||||||
|
</mapper>
|
@ -0,0 +1,174 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.service.carinfo;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.home.controller.admin.carinfo.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.home.dal.dataobject.carinfo.CarinfoDO;
|
||||||
|
import cn.iocoder.yudao.module.home.dal.mysql.carinfo.CarinfoMapper;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import java.util.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import static cn.hutool.core.util.RandomUtil.*;
|
||||||
|
import static cn.iocoder.yudao.module.home.enums.ErrorCodeConstants.*;
|
||||||
|
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
||||||
|
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link CarinfoServiceImpl} 的单元测试类
|
||||||
|
*
|
||||||
|
* @author 君风
|
||||||
|
*/
|
||||||
|
@Import(CarinfoServiceImpl.class)
|
||||||
|
public class CarinfoServiceImplTest extends BaseDbUnitTest {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CarinfoServiceImpl carinfoService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CarinfoMapper carinfoMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateCarinfo_success() {
|
||||||
|
// 准备参数
|
||||||
|
CarinfoSaveReqVO createReqVO = randomPojo(CarinfoSaveReqVO.class).setId(null);
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
Long carinfoId = carinfoService.createCarinfo(createReqVO);
|
||||||
|
// 断言
|
||||||
|
assertNotNull(carinfoId);
|
||||||
|
// 校验记录的属性是否正确
|
||||||
|
CarinfoDO carinfo = carinfoMapper.selectById(carinfoId);
|
||||||
|
assertPojoEquals(createReqVO, carinfo, "id");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateCarinfo_success() {
|
||||||
|
// mock 数据
|
||||||
|
CarinfoDO dbCarinfo = randomPojo(CarinfoDO.class);
|
||||||
|
carinfoMapper.insert(dbCarinfo);// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
CarinfoSaveReqVO updateReqVO = randomPojo(CarinfoSaveReqVO.class, o -> {
|
||||||
|
o.setId(dbCarinfo.getId()); // 设置更新的 ID
|
||||||
|
});
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
carinfoService.updateCarinfo(updateReqVO);
|
||||||
|
// 校验是否更新正确
|
||||||
|
CarinfoDO carinfo = carinfoMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||||
|
assertPojoEquals(updateReqVO, carinfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateCarinfo_notExists() {
|
||||||
|
// 准备参数
|
||||||
|
CarinfoSaveReqVO updateReqVO = randomPojo(CarinfoSaveReqVO.class);
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> carinfoService.updateCarinfo(updateReqVO), CARINFO_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteCarinfo_success() {
|
||||||
|
// mock 数据
|
||||||
|
CarinfoDO dbCarinfo = randomPojo(CarinfoDO.class);
|
||||||
|
carinfoMapper.insert(dbCarinfo);// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
Long id = dbCarinfo.getId();
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
carinfoService.deleteCarinfo(id);
|
||||||
|
// 校验数据不存在了
|
||||||
|
assertNull(carinfoMapper.selectById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteCarinfo_notExists() {
|
||||||
|
// 准备参数
|
||||||
|
Long id = randomLongId();
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> carinfoService.deleteCarinfo(id), CARINFO_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||||
|
public void testGetCarinfoPage() {
|
||||||
|
// mock 数据
|
||||||
|
CarinfoDO dbCarinfo = randomPojo(CarinfoDO.class, o -> { // 等会查询到
|
||||||
|
o.setId(null);
|
||||||
|
o.setLicensePlate(null);
|
||||||
|
o.setModel(null);
|
||||||
|
o.setBrand(null);
|
||||||
|
o.setCarStatus(null);
|
||||||
|
o.setCarType(null);
|
||||||
|
o.setColor(null);
|
||||||
|
o.setPurchaseDate(null);
|
||||||
|
o.setPurchasePrice(null);
|
||||||
|
o.setEngineNumber(null);
|
||||||
|
o.setRemark(null);
|
||||||
|
o.setCreateTime(null);
|
||||||
|
});
|
||||||
|
carinfoMapper.insert(dbCarinfo);
|
||||||
|
// 测试 id 不匹配
|
||||||
|
carinfoMapper.insert(cloneIgnoreId(dbCarinfo, o -> o.setId(null)));
|
||||||
|
// 测试 licensePlate 不匹配
|
||||||
|
carinfoMapper.insert(cloneIgnoreId(dbCarinfo, o -> o.setLicensePlate(null)));
|
||||||
|
// 测试 model 不匹配
|
||||||
|
carinfoMapper.insert(cloneIgnoreId(dbCarinfo, o -> o.setModel(null)));
|
||||||
|
// 测试 brand 不匹配
|
||||||
|
carinfoMapper.insert(cloneIgnoreId(dbCarinfo, o -> o.setBrand(null)));
|
||||||
|
// 测试 carStatus 不匹配
|
||||||
|
carinfoMapper.insert(cloneIgnoreId(dbCarinfo, o -> o.setCarStatus(null)));
|
||||||
|
// 测试 carType 不匹配
|
||||||
|
carinfoMapper.insert(cloneIgnoreId(dbCarinfo, o -> o.setCarType(null)));
|
||||||
|
// 测试 color 不匹配
|
||||||
|
carinfoMapper.insert(cloneIgnoreId(dbCarinfo, o -> o.setColor(null)));
|
||||||
|
// 测试 purchaseDate 不匹配
|
||||||
|
carinfoMapper.insert(cloneIgnoreId(dbCarinfo, o -> o.setPurchaseDate(null)));
|
||||||
|
// 测试 purchasePrice 不匹配
|
||||||
|
carinfoMapper.insert(cloneIgnoreId(dbCarinfo, o -> o.setPurchasePrice(null)));
|
||||||
|
// 测试 engineNumber 不匹配
|
||||||
|
carinfoMapper.insert(cloneIgnoreId(dbCarinfo, o -> o.setEngineNumber(null)));
|
||||||
|
// 测试 remark 不匹配
|
||||||
|
carinfoMapper.insert(cloneIgnoreId(dbCarinfo, o -> o.setRemark(null)));
|
||||||
|
// 测试 createTime 不匹配
|
||||||
|
carinfoMapper.insert(cloneIgnoreId(dbCarinfo, o -> o.setCreateTime(null)));
|
||||||
|
// 准备参数
|
||||||
|
CarinfoPageReqVO reqVO = new CarinfoPageReqVO();
|
||||||
|
reqVO.setId(null);
|
||||||
|
reqVO.setLicensePlate(null);
|
||||||
|
reqVO.setModel(null);
|
||||||
|
reqVO.setBrand(null);
|
||||||
|
reqVO.setCarStatus(null);
|
||||||
|
reqVO.setCarType(null);
|
||||||
|
reqVO.setColor(null);
|
||||||
|
reqVO.setPurchaseDate(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||||
|
reqVO.setPurchasePrice(null);
|
||||||
|
reqVO.setEngineNumber(null);
|
||||||
|
reqVO.setRemark(null);
|
||||||
|
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
PageResult<CarinfoDO> pageResult = carinfoService.getCarinfoPage(reqVO);
|
||||||
|
// 断言
|
||||||
|
assertEquals(1, pageResult.getTotal());
|
||||||
|
assertEquals(1, pageResult.getList().size());
|
||||||
|
assertPojoEquals(dbCarinfo, pageResult.getList().get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user