车辆管理
Some checks are pending
Java CI with Maven / build (11) (push) Waiting to run
Java CI with Maven / build (17) (push) Waiting to run
Java CI with Maven / build (8) (push) Waiting to run
yudao-ui-admin CI / build (14.x) (push) Waiting to run
yudao-ui-admin CI / build (16.x) (push) Waiting to run
Some checks are pending
Java CI with Maven / build (11) (push) Waiting to run
Java CI with Maven / build (17) (push) Waiting to run
Java CI with Maven / build (8) (push) Waiting to run
yudao-ui-admin CI / build (14.x) (push) Waiting to run
yudao-ui-admin CI / build (16.x) (push) Waiting to run
This commit is contained in:
parent
7fe605adb1
commit
f1ba327fd6
@ -16,4 +16,6 @@ public interface ErrorCodeConstants {
|
|||||||
ErrorCode IMG_NOT_EXISTS = new ErrorCode(1_009_003_000, "公告内容不存在");
|
ErrorCode IMG_NOT_EXISTS = new ErrorCode(1_009_003_000, "公告内容不存在");
|
||||||
// ========== 公司新闻 1-011-003-000 ==========
|
// ========== 公司新闻 1-011-003-000 ==========
|
||||||
ErrorCode NEWS_NOT_EXISTS = new ErrorCode(1_011_003_000, "公司新闻不存在");
|
ErrorCode NEWS_NOT_EXISTS = new ErrorCode(1_011_003_000, "公司新闻不存在");
|
||||||
|
// ========== 车辆管理 1_011_004_000 ==========
|
||||||
|
ErrorCode CLGL_NOT_EXISTS = new ErrorCode(1_011_004_000, "车辆管理不存在");
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,95 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.controller.admin.clgl;
|
||||||
|
|
||||||
|
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.clgl.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.home.dal.dataobject.clgl.ClglDO;
|
||||||
|
import cn.iocoder.yudao.module.home.service.clgl.ClglService;
|
||||||
|
|
||||||
|
@Tag(name = "管理后台 - 车辆管理")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/home/clgl")
|
||||||
|
@Validated
|
||||||
|
public class ClglController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ClglService clglService;
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
@Operation(summary = "创建车辆管理")
|
||||||
|
@PreAuthorize("@ss.hasPermission('home:clgl:create')")
|
||||||
|
public CommonResult<Long> createClgl(@Valid @RequestBody ClglSaveReqVO createReqVO) {
|
||||||
|
return success(clglService.createClgl(createReqVO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update")
|
||||||
|
@Operation(summary = "更新车辆管理")
|
||||||
|
@PreAuthorize("@ss.hasPermission('home:clgl:update')")
|
||||||
|
public CommonResult<Boolean> updateClgl(@Valid @RequestBody ClglSaveReqVO updateReqVO) {
|
||||||
|
clglService.updateClgl(updateReqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
@Operation(summary = "删除车辆管理")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
|
@PreAuthorize("@ss.hasPermission('home:clgl:delete')")
|
||||||
|
public CommonResult<Boolean> deleteClgl(@RequestParam("id") Long id) {
|
||||||
|
clglService.deleteClgl(id);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get")
|
||||||
|
@Operation(summary = "获得车辆管理")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||||
|
@PreAuthorize("@ss.hasPermission('home:clgl:query')")
|
||||||
|
public CommonResult<ClglRespVO> getClgl(@RequestParam("id") Long id) {
|
||||||
|
ClglDO clgl = clglService.getClgl(id);
|
||||||
|
return success(BeanUtils.toBean(clgl, ClglRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/page")
|
||||||
|
@Operation(summary = "获得车辆管理分页")
|
||||||
|
@PreAuthorize("@ss.hasPermission('home:clgl:query')")
|
||||||
|
public CommonResult<PageResult<ClglRespVO>> getClglPage(@Valid ClglPageReqVO pageReqVO) {
|
||||||
|
PageResult<ClglDO> pageResult = clglService.getClglPage(pageReqVO);
|
||||||
|
return success(BeanUtils.toBean(pageResult, ClglRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/export-excel")
|
||||||
|
@Operation(summary = "导出车辆管理 Excel")
|
||||||
|
@PreAuthorize("@ss.hasPermission('home:clgl:export')")
|
||||||
|
@ApiAccessLog(operateType = EXPORT)
|
||||||
|
public void exportClglExcel(@Valid ClglPageReqVO pageReqVO,
|
||||||
|
HttpServletResponse response) throws IOException {
|
||||||
|
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||||
|
List<ClglDO> list = clglService.getClglPage(pageReqVO).getList();
|
||||||
|
// 导出 Excel
|
||||||
|
ExcelUtils.write(response, "车辆管理.xls", "数据", ClglRespVO.class,
|
||||||
|
BeanUtils.toBean(list, ClglRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.controller.admin.clgl.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 ClglPageReqVO extends PageParam {
|
||||||
|
|
||||||
|
@Schema(description = "id", example = "26309")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "申请人")
|
||||||
|
private Integer carUser;
|
||||||
|
|
||||||
|
@Schema(description = "部门")
|
||||||
|
private Integer dept;
|
||||||
|
|
||||||
|
@Schema(description = "用车类型", example = "1")
|
||||||
|
private Integer carType;
|
||||||
|
|
||||||
|
@Schema(description = "驾驶员")
|
||||||
|
private Integer carDriver;
|
||||||
|
|
||||||
|
@Schema(description = "用车开始时间")
|
||||||
|
private LocalDateTime carStart;
|
||||||
|
|
||||||
|
@Schema(description = "用车结束时间")
|
||||||
|
private LocalDateTime carEnd;
|
||||||
|
|
||||||
|
@Schema(description = "目的地")
|
||||||
|
private String carAddress;
|
||||||
|
|
||||||
|
@Schema(description = "车辆开始里程")
|
||||||
|
private String carStartMileage;
|
||||||
|
|
||||||
|
@Schema(description = "车辆结束里程")
|
||||||
|
private String carEndMileage;
|
||||||
|
|
||||||
|
@Schema(description = "用车状态", example = "2")
|
||||||
|
private Integer carStatus;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间")
|
||||||
|
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||||
|
private LocalDateTime[] createTime;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.controller.admin.clgl.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 ClglRespVO {
|
||||||
|
|
||||||
|
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "26309")
|
||||||
|
@ExcelProperty("id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "申请人", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("申请人")
|
||||||
|
private Integer carUser;
|
||||||
|
|
||||||
|
@Schema(description = "部门", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("部门")
|
||||||
|
private Integer dept;
|
||||||
|
|
||||||
|
@Schema(description = "用车类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@ExcelProperty(value = "用车类型", converter = DictConvert.class)
|
||||||
|
@DictFormat("clgl_car_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||||
|
private Integer carType;
|
||||||
|
|
||||||
|
@Schema(description = "驾驶员", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("驾驶员")
|
||||||
|
private Integer carDriver;
|
||||||
|
|
||||||
|
@Schema(description = "用车开始时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("用车开始时间")
|
||||||
|
private LocalDateTime carStart;
|
||||||
|
|
||||||
|
@Schema(description = "用车结束时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("用车结束时间")
|
||||||
|
private LocalDateTime carEnd;
|
||||||
|
|
||||||
|
@Schema(description = "目的地", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("目的地")
|
||||||
|
private String carAddress;
|
||||||
|
|
||||||
|
@Schema(description = "车辆信息")
|
||||||
|
@ExcelProperty("车辆信息")
|
||||||
|
private String carInfo;
|
||||||
|
|
||||||
|
@Schema(description = "车辆开始里程")
|
||||||
|
@ExcelProperty("车辆开始里程")
|
||||||
|
private String carStartMileage;
|
||||||
|
|
||||||
|
@Schema(description = "车辆结束里程")
|
||||||
|
@ExcelProperty("车辆结束里程")
|
||||||
|
private String carEndMileage;
|
||||||
|
|
||||||
|
@Schema(description = "用车状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||||
|
@ExcelProperty(value = "用车状态", converter = DictConvert.class)
|
||||||
|
@DictFormat("clgl_car_status") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||||
|
private Integer carStatus;
|
||||||
|
|
||||||
|
@Schema(description = "用车原因", requiredMode = Schema.RequiredMode.REQUIRED, example = "不喜欢")
|
||||||
|
@ExcelProperty("用车原因")
|
||||||
|
private String carReason;
|
||||||
|
|
||||||
|
@Schema(description = "备注", example = "随便")
|
||||||
|
@ExcelProperty("备注")
|
||||||
|
private String carRemark;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("创建时间")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.controller.admin.clgl.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 ClglSaveReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "26309")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "申请人", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotNull(message = "申请人不能为空")
|
||||||
|
private Integer carUser;
|
||||||
|
|
||||||
|
@Schema(description = "部门", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotNull(message = "部门不能为空")
|
||||||
|
private Integer dept;
|
||||||
|
|
||||||
|
@Schema(description = "用车类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@NotNull(message = "用车类型不能为空")
|
||||||
|
private Integer carType;
|
||||||
|
|
||||||
|
@Schema(description = "驾驶员", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotNull(message = "驾驶员不能为空")
|
||||||
|
private Integer carDriver;
|
||||||
|
|
||||||
|
@Schema(description = "用车开始时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotNull(message = "用车开始时间不能为空")
|
||||||
|
private LocalDateTime carStart;
|
||||||
|
|
||||||
|
@Schema(description = "用车结束时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotNull(message = "用车结束时间不能为空")
|
||||||
|
private LocalDateTime carEnd;
|
||||||
|
|
||||||
|
@Schema(description = "目的地", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotEmpty(message = "目的地不能为空")
|
||||||
|
private String carAddress;
|
||||||
|
|
||||||
|
@Schema(description = "车辆信息")
|
||||||
|
private String carInfo;
|
||||||
|
|
||||||
|
@Schema(description = "车辆开始里程")
|
||||||
|
private String carStartMileage;
|
||||||
|
|
||||||
|
@Schema(description = "车辆结束里程")
|
||||||
|
private String carEndMileage;
|
||||||
|
|
||||||
|
@Schema(description = "用车状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||||
|
@NotNull(message = "用车状态不能为空")
|
||||||
|
private Integer carStatus;
|
||||||
|
|
||||||
|
@Schema(description = "用车原因", requiredMode = Schema.RequiredMode.REQUIRED, example = "不喜欢")
|
||||||
|
@NotEmpty(message = "用车原因不能为空")
|
||||||
|
private String carReason;
|
||||||
|
|
||||||
|
@Schema(description = "备注", example = "随便")
|
||||||
|
private String carRemark;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,89 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.dal.dataobject.clgl;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
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_clgl")
|
||||||
|
@KeySequence("oa_clgl_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ClglDO extends BaseDO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 申请人
|
||||||
|
*/
|
||||||
|
private Integer carUser;
|
||||||
|
/**
|
||||||
|
* 部门
|
||||||
|
*/
|
||||||
|
private Integer dept;
|
||||||
|
/**
|
||||||
|
* 用车类型
|
||||||
|
*
|
||||||
|
* 枚举 {@link TODO clgl_car_type 对应的类}
|
||||||
|
*/
|
||||||
|
private Integer carType;
|
||||||
|
/**
|
||||||
|
* 驾驶员
|
||||||
|
*/
|
||||||
|
private Integer carDriver;
|
||||||
|
/**
|
||||||
|
* 用车开始时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime carStart;
|
||||||
|
/**
|
||||||
|
* 用车结束时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime carEnd;
|
||||||
|
/**
|
||||||
|
* 目的地
|
||||||
|
*/
|
||||||
|
private String carAddress;
|
||||||
|
/**
|
||||||
|
* 车辆信息
|
||||||
|
*/
|
||||||
|
private String carInfo;
|
||||||
|
/**
|
||||||
|
* 车辆开始里程
|
||||||
|
*/
|
||||||
|
private String carStartMileage;
|
||||||
|
/**
|
||||||
|
* 车辆结束里程
|
||||||
|
*/
|
||||||
|
private String carEndMileage;
|
||||||
|
/**
|
||||||
|
* 用车状态
|
||||||
|
*
|
||||||
|
* 枚举 {@link TODO clgl_car_status 对应的类}
|
||||||
|
*/
|
||||||
|
private Integer carStatus;
|
||||||
|
/**
|
||||||
|
* 用车原因
|
||||||
|
*/
|
||||||
|
private String carReason;
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String carRemark;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.dal.mysql.clgl;
|
||||||
|
|
||||||
|
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.clgl.ClglDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import cn.iocoder.yudao.module.home.controller.admin.clgl.vo.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆管理 Mapper
|
||||||
|
*
|
||||||
|
* @author 君风
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface ClglMapper extends BaseMapperX<ClglDO> {
|
||||||
|
|
||||||
|
default PageResult<ClglDO> selectPage(ClglPageReqVO reqVO) {
|
||||||
|
return selectPage(reqVO, new LambdaQueryWrapperX<ClglDO>()
|
||||||
|
.eqIfPresent(ClglDO::getId, reqVO.getId())
|
||||||
|
.eqIfPresent(ClglDO::getCarUser, reqVO.getCarUser())
|
||||||
|
.eqIfPresent(ClglDO::getDept, reqVO.getDept())
|
||||||
|
.eqIfPresent(ClglDO::getCarType, reqVO.getCarType())
|
||||||
|
.eqIfPresent(ClglDO::getCarDriver, reqVO.getCarDriver())
|
||||||
|
.eqIfPresent(ClglDO::getCarStart, reqVO.getCarStart())
|
||||||
|
.eqIfPresent(ClglDO::getCarEnd, reqVO.getCarEnd())
|
||||||
|
.eqIfPresent(ClglDO::getCarAddress, reqVO.getCarAddress())
|
||||||
|
.eqIfPresent(ClglDO::getCarStartMileage, reqVO.getCarStartMileage())
|
||||||
|
.eqIfPresent(ClglDO::getCarEndMileage, reqVO.getCarEndMileage())
|
||||||
|
.eqIfPresent(ClglDO::getCarStatus, reqVO.getCarStatus())
|
||||||
|
.betweenIfPresent(ClglDO::getCreateTime, reqVO.getCreateTime())
|
||||||
|
.orderByDesc(ClglDO::getId));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.service.clgl;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import javax.validation.*;
|
||||||
|
import cn.iocoder.yudao.module.home.controller.admin.clgl.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.home.dal.dataobject.clgl.ClglDO;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆管理 Service 接口
|
||||||
|
*
|
||||||
|
* @author 君风
|
||||||
|
*/
|
||||||
|
public interface ClglService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建车辆管理
|
||||||
|
*
|
||||||
|
* @param createReqVO 创建信息
|
||||||
|
* @return 编号
|
||||||
|
*/
|
||||||
|
Long createClgl(@Valid ClglSaveReqVO createReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新车辆管理
|
||||||
|
*
|
||||||
|
* @param updateReqVO 更新信息
|
||||||
|
*/
|
||||||
|
void updateClgl(@Valid ClglSaveReqVO updateReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除车辆管理
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
*/
|
||||||
|
void deleteClgl(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得车辆管理
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @return 车辆管理
|
||||||
|
*/
|
||||||
|
ClglDO getClgl(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得车辆管理分页
|
||||||
|
*
|
||||||
|
* @param pageReqVO 分页查询
|
||||||
|
* @return 车辆管理分页
|
||||||
|
*/
|
||||||
|
PageResult<ClglDO> getClglPage(ClglPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.service.clgl;
|
||||||
|
|
||||||
|
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.clgl.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.home.dal.dataobject.clgl.ClglDO;
|
||||||
|
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.clgl.ClglMapper;
|
||||||
|
|
||||||
|
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 ClglServiceImpl implements ClglService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ClglMapper clglMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long createClgl(ClglSaveReqVO createReqVO) {
|
||||||
|
// 插入
|
||||||
|
ClglDO clgl = BeanUtils.toBean(createReqVO, ClglDO.class);
|
||||||
|
clglMapper.insert(clgl);
|
||||||
|
// 返回
|
||||||
|
return clgl.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateClgl(ClglSaveReqVO updateReqVO) {
|
||||||
|
// 校验存在
|
||||||
|
validateClglExists(updateReqVO.getId());
|
||||||
|
// 更新
|
||||||
|
ClglDO updateObj = BeanUtils.toBean(updateReqVO, ClglDO.class);
|
||||||
|
clglMapper.updateById(updateObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteClgl(Long id) {
|
||||||
|
// 校验存在
|
||||||
|
validateClglExists(id);
|
||||||
|
// 删除
|
||||||
|
clglMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateClglExists(Long id) {
|
||||||
|
if (clglMapper.selectById(id) == null) {
|
||||||
|
throw exception(CLGL_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClglDO getClgl(Long id) {
|
||||||
|
return clglMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<ClglDO> getClglPage(ClglPageReqVO pageReqVO) {
|
||||||
|
return clglMapper.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.clgl.ClglMapper">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
一般情况下,尽可能使用 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.clgl;
|
||||||
|
|
||||||
|
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.clgl.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.home.dal.dataobject.clgl.ClglDO;
|
||||||
|
import cn.iocoder.yudao.module.home.dal.mysql.clgl.ClglMapper;
|
||||||
|
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 ClglServiceImpl} 的单元测试类
|
||||||
|
*
|
||||||
|
* @author 君风
|
||||||
|
*/
|
||||||
|
@Import(ClglServiceImpl.class)
|
||||||
|
public class ClglServiceImplTest extends BaseDbUnitTest {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ClglServiceImpl clglService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ClglMapper clglMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateClgl_success() {
|
||||||
|
// 准备参数
|
||||||
|
ClglSaveReqVO createReqVO = randomPojo(ClglSaveReqVO.class).setId(null);
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
Long clglId = clglService.createClgl(createReqVO);
|
||||||
|
// 断言
|
||||||
|
assertNotNull(clglId);
|
||||||
|
// 校验记录的属性是否正确
|
||||||
|
ClglDO clgl = clglMapper.selectById(clglId);
|
||||||
|
assertPojoEquals(createReqVO, clgl, "id");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateClgl_success() {
|
||||||
|
// mock 数据
|
||||||
|
ClglDO dbClgl = randomPojo(ClglDO.class);
|
||||||
|
clglMapper.insert(dbClgl);// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
ClglSaveReqVO updateReqVO = randomPojo(ClglSaveReqVO.class, o -> {
|
||||||
|
o.setId(dbClgl.getId()); // 设置更新的 ID
|
||||||
|
});
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
clglService.updateClgl(updateReqVO);
|
||||||
|
// 校验是否更新正确
|
||||||
|
ClglDO clgl = clglMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||||
|
assertPojoEquals(updateReqVO, clgl);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateClgl_notExists() {
|
||||||
|
// 准备参数
|
||||||
|
ClglSaveReqVO updateReqVO = randomPojo(ClglSaveReqVO.class);
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> clglService.updateClgl(updateReqVO), CLGL_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteClgl_success() {
|
||||||
|
// mock 数据
|
||||||
|
ClglDO dbClgl = randomPojo(ClglDO.class);
|
||||||
|
clglMapper.insert(dbClgl);// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
Long id = dbClgl.getId();
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
clglService.deleteClgl(id);
|
||||||
|
// 校验数据不存在了
|
||||||
|
assertNull(clglMapper.selectById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteClgl_notExists() {
|
||||||
|
// 准备参数
|
||||||
|
Long id = randomLongId();
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> clglService.deleteClgl(id), CLGL_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||||
|
public void testGetClglPage() {
|
||||||
|
// mock 数据
|
||||||
|
ClglDO dbClgl = randomPojo(ClglDO.class, o -> { // 等会查询到
|
||||||
|
o.setId(null);
|
||||||
|
o.setCarUser(null);
|
||||||
|
o.setDept(null);
|
||||||
|
o.setCarType(null);
|
||||||
|
o.setCarDriver(null);
|
||||||
|
o.setCarStart(null);
|
||||||
|
o.setCarEnd(null);
|
||||||
|
o.setCarAddress(null);
|
||||||
|
o.setCarStartMileage(null);
|
||||||
|
o.setCarEndMileage(null);
|
||||||
|
o.setCarStatus(null);
|
||||||
|
o.setCreateTime(null);
|
||||||
|
});
|
||||||
|
clglMapper.insert(dbClgl);
|
||||||
|
// 测试 id 不匹配
|
||||||
|
clglMapper.insert(cloneIgnoreId(dbClgl, o -> o.setId(null)));
|
||||||
|
// 测试 carUser 不匹配
|
||||||
|
clglMapper.insert(cloneIgnoreId(dbClgl, o -> o.setCarUser(null)));
|
||||||
|
// 测试 dept 不匹配
|
||||||
|
clglMapper.insert(cloneIgnoreId(dbClgl, o -> o.setDept(null)));
|
||||||
|
// 测试 carType 不匹配
|
||||||
|
clglMapper.insert(cloneIgnoreId(dbClgl, o -> o.setCarType(null)));
|
||||||
|
// 测试 carDriver 不匹配
|
||||||
|
clglMapper.insert(cloneIgnoreId(dbClgl, o -> o.setCarDriver(null)));
|
||||||
|
// 测试 carStart 不匹配
|
||||||
|
clglMapper.insert(cloneIgnoreId(dbClgl, o -> o.setCarStart(null)));
|
||||||
|
// 测试 carEnd 不匹配
|
||||||
|
clglMapper.insert(cloneIgnoreId(dbClgl, o -> o.setCarEnd(null)));
|
||||||
|
// 测试 carAddress 不匹配
|
||||||
|
clglMapper.insert(cloneIgnoreId(dbClgl, o -> o.setCarAddress(null)));
|
||||||
|
// 测试 carStartMileage 不匹配
|
||||||
|
clglMapper.insert(cloneIgnoreId(dbClgl, o -> o.setCarStartMileage(null)));
|
||||||
|
// 测试 carEndMileage 不匹配
|
||||||
|
clglMapper.insert(cloneIgnoreId(dbClgl, o -> o.setCarEndMileage(null)));
|
||||||
|
// 测试 carStatus 不匹配
|
||||||
|
clglMapper.insert(cloneIgnoreId(dbClgl, o -> o.setCarStatus(null)));
|
||||||
|
// 测试 createTime 不匹配
|
||||||
|
clglMapper.insert(cloneIgnoreId(dbClgl, o -> o.setCreateTime(null)));
|
||||||
|
// 准备参数
|
||||||
|
ClglPageReqVO reqVO = new ClglPageReqVO();
|
||||||
|
reqVO.setId(null);
|
||||||
|
reqVO.setCarUser(null);
|
||||||
|
reqVO.setDept(null);
|
||||||
|
reqVO.setCarType(null);
|
||||||
|
reqVO.setCarDriver(null);
|
||||||
|
reqVO.setCarStart(null);
|
||||||
|
reqVO.setCarEnd(null);
|
||||||
|
reqVO.setCarAddress(null);
|
||||||
|
reqVO.setCarStartMileage(null);
|
||||||
|
reqVO.setCarEndMileage(null);
|
||||||
|
reqVO.setCarStatus(null);
|
||||||
|
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
PageResult<ClglDO> pageResult = clglService.getClglPage(reqVO);
|
||||||
|
// 断言
|
||||||
|
assertEquals(1, pageResult.getTotal());
|
||||||
|
assertEquals(1, pageResult.getList().size());
|
||||||
|
assertPojoEquals(dbClgl, pageResult.getList().get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user