驾驶员信息
Some checks failed
Java CI with Maven / build (11) (push) Has been cancelled
Java CI with Maven / build (17) (push) Has been cancelled
Java CI with Maven / build (8) (push) Has been cancelled
yudao-ui-admin CI / build (14.x) (push) Has been cancelled
yudao-ui-admin CI / build (16.x) (push) Has been cancelled

This commit is contained in:
XaoLi717 2024-11-29 13:48:31 +08:00
parent ab1292db48
commit 3d3ee4a5ce
10 changed files with 675 additions and 0 deletions

View File

@ -0,0 +1,95 @@
package cn.iocoder.yudao.module.home.controller.admin.driver;
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.driver.vo.*;
import cn.iocoder.yudao.module.home.dal.dataobject.driver.DriverDO;
import cn.iocoder.yudao.module.home.service.driver.DriverService;
@Tag(name = "管理后台 - 驾驶员信息")
@RestController
@RequestMapping("/home/driver")
@Validated
public class DriverController {
@Resource
private DriverService driverService;
@PostMapping("/create")
@Operation(summary = "创建驾驶员信息")
@PreAuthorize("@ss.hasPermission('home:driver:create')")
public CommonResult<Long> createDriver(@Valid @RequestBody DriverSaveReqVO createReqVO) {
return success(driverService.createDriver(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新驾驶员信息")
@PreAuthorize("@ss.hasPermission('home:driver:update')")
public CommonResult<Boolean> updateDriver(@Valid @RequestBody DriverSaveReqVO updateReqVO) {
driverService.updateDriver(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除驾驶员信息")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('home:driver:delete')")
public CommonResult<Boolean> deleteDriver(@RequestParam("id") Long id) {
driverService.deleteDriver(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得驾驶员信息")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('home:driver:query')")
public CommonResult<DriverRespVO> getDriver(@RequestParam("id") Long id) {
DriverDO driver = driverService.getDriver(id);
return success(BeanUtils.toBean(driver, DriverRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得驾驶员信息分页")
@PreAuthorize("@ss.hasPermission('home:driver:query')")
public CommonResult<PageResult<DriverRespVO>> getDriverPage(@Valid DriverPageReqVO pageReqVO) {
PageResult<DriverDO> pageResult = driverService.getDriverPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, DriverRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出驾驶员信息 Excel")
@PreAuthorize("@ss.hasPermission('home:driver:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportDriverExcel(@Valid DriverPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<DriverDO> list = driverService.getDriverPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "驾驶员信息.xls", "数据", DriverRespVO.class,
BeanUtils.toBean(list, DriverRespVO.class));
}
}

View File

@ -0,0 +1,52 @@
package cn.iocoder.yudao.module.home.controller.admin.driver.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 DriverPageReqVO extends PageParam {
@Schema(description = "id", example = "2356")
private Long id;
@Schema(description = "驾驶员名字", example = "张三")
private String name;
@Schema(description = "性别")
private Integer gender;
@Schema(description = "驾驶员状态", example = "2")
private Integer driverStatus;
@Schema(description = "联系方式")
private String contactInfo;
@Schema(description = "驾驶证号")
private String license;
@Schema(description = "驾驶证类型", example = "2")
private String licenseType;
@Schema(description = "健康状态", example = "1")
private String healthStatus;
@Schema(description = "驾驶经验")
private String experience;
@Schema(description = "备注")
private String remarks;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,63 @@
package cn.iocoder.yudao.module.home.controller.admin.driver.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 DriverRespVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "2356")
@ExcelProperty("id")
private Long id;
@Schema(description = "驾驶员名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
@ExcelProperty("驾驶员名字")
private String name;
@Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty(value = "性别", converter = DictConvert.class)
@DictFormat("driver_Gender") // TODO 代码优化建议设置到对应的 DictTypeConstants 枚举类中
private Integer gender;
@Schema(description = "驾驶员状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@ExcelProperty(value = "驾驶员状态", converter = DictConvert.class)
@DictFormat("driver_status") // TODO 代码优化建议设置到对应的 DictTypeConstants 枚举类中
private Integer driverStatus;
@Schema(description = "联系方式", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("联系方式")
private String contactInfo;
@Schema(description = "驾驶证号", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("驾驶证号")
private String license;
@Schema(description = "驾驶证类型", example = "2")
@ExcelProperty("驾驶证类型")
private String licenseType;
@Schema(description = "健康状态", example = "1")
@ExcelProperty("健康状态")
private String healthStatus;
@Schema(description = "驾驶经验")
@ExcelProperty("驾驶经验")
private String experience;
@Schema(description = "备注")
@ExcelProperty("备注")
private String remarks;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -0,0 +1,47 @@
package cn.iocoder.yudao.module.home.controller.admin.driver.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 驾驶员信息新增/修改 Request VO")
@Data
public class DriverSaveReqVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "2356")
private Long id;
@Schema(description = "驾驶员名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
@NotEmpty(message = "驾驶员名字不能为空")
private String name;
@Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "性别不能为空")
private Integer gender;
@Schema(description = "驾驶员状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotNull(message = "驾驶员状态不能为空")
private Integer driverStatus;
@Schema(description = "联系方式", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "联系方式不能为空")
private String contactInfo;
@Schema(description = "驾驶证号", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "驾驶证号不能为空")
private String license;
@Schema(description = "驾驶证类型", example = "2")
private String licenseType;
@Schema(description = "健康状态", example = "1")
private String healthStatus;
@Schema(description = "驾驶经验")
private String experience;
@Schema(description = "备注")
private String remarks;
}

View File

@ -0,0 +1,71 @@
package cn.iocoder.yudao.module.home.dal.dataobject.driver;
import lombok.*;
import java.util.*;
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_driver")
@KeySequence("oa_driver_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DriverDO extends BaseDO {
/**
* id
*/
@TableId
private Long id;
/**
* 驾驶员名字
*/
private String name;
/**
* 性别
*
* 枚举 {@link TODO driver_Gender 对应的类}
*/
private Integer gender;
/**
* 驾驶员状态
*
* 枚举 {@link TODO driver_status 对应的类}
*/
private Integer driverStatus;
/**
* 联系方式
*/
private String contactInfo;
/**
* 驾驶证号
*/
private String license;
/**
* 驾驶证类型
*/
private String licenseType;
/**
* 健康状态
*/
private String healthStatus;
/**
* 驾驶经验
*/
private String experience;
/**
* 备注
*/
private String remarks;
}

View File

@ -0,0 +1,36 @@
package cn.iocoder.yudao.module.home.dal.mysql.driver;
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.driver.DriverDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.home.controller.admin.driver.vo.*;
/**
* 驾驶员信息 Mapper
*
* @author 君风
*/
@Mapper
public interface DriverMapper extends BaseMapperX<DriverDO> {
default PageResult<DriverDO> selectPage(DriverPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<DriverDO>()
.eqIfPresent(DriverDO::getId, reqVO.getId())
.likeIfPresent(DriverDO::getName, reqVO.getName())
.eqIfPresent(DriverDO::getGender, reqVO.getGender())
.eqIfPresent(DriverDO::getDriverStatus, reqVO.getDriverStatus())
.eqIfPresent(DriverDO::getContactInfo, reqVO.getContactInfo())
.eqIfPresent(DriverDO::getLicense, reqVO.getLicense())
.eqIfPresent(DriverDO::getLicenseType, reqVO.getLicenseType())
.eqIfPresent(DriverDO::getHealthStatus, reqVO.getHealthStatus())
.eqIfPresent(DriverDO::getExperience, reqVO.getExperience())
.eqIfPresent(DriverDO::getRemarks, reqVO.getRemarks())
.betweenIfPresent(DriverDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(DriverDO::getId));
}
}

View File

@ -0,0 +1,55 @@
package cn.iocoder.yudao.module.home.service.driver;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.home.controller.admin.driver.vo.*;
import cn.iocoder.yudao.module.home.dal.dataobject.driver.DriverDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* 驾驶员信息 Service 接口
*
* @author 君风
*/
public interface DriverService {
/**
* 创建驾驶员信息
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createDriver(@Valid DriverSaveReqVO createReqVO);
/**
* 更新驾驶员信息
*
* @param updateReqVO 更新信息
*/
void updateDriver(@Valid DriverSaveReqVO updateReqVO);
/**
* 删除驾驶员信息
*
* @param id 编号
*/
void deleteDriver(Long id);
/**
* 获得驾驶员信息
*
* @param id 编号
* @return 驾驶员信息
*/
DriverDO getDriver(Long id);
/**
* 获得驾驶员信息分页
*
* @param pageReqVO 分页查询
* @return 驾驶员信息分页
*/
PageResult<DriverDO> getDriverPage(DriverPageReqVO pageReqVO);
}

View File

@ -0,0 +1,74 @@
package cn.iocoder.yudao.module.home.service.driver;
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.driver.vo.*;
import cn.iocoder.yudao.module.home.dal.dataobject.driver.DriverDO;
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.driver.DriverMapper;
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 DriverServiceImpl implements DriverService {
@Resource
private DriverMapper driverMapper;
@Override
public Long createDriver(DriverSaveReqVO createReqVO) {
// 插入
DriverDO driver = BeanUtils.toBean(createReqVO, DriverDO.class);
driverMapper.insert(driver);
// 返回
return driver.getId();
}
@Override
public void updateDriver(DriverSaveReqVO updateReqVO) {
// 校验存在
validateDriverExists(updateReqVO.getId());
// 更新
DriverDO updateObj = BeanUtils.toBean(updateReqVO, DriverDO.class);
driverMapper.updateById(updateObj);
}
@Override
public void deleteDriver(Long id) {
// 校验存在
validateDriverExists(id);
// 删除
driverMapper.deleteById(id);
}
private void validateDriverExists(Long id) {
if (driverMapper.selectById(id) == null) {
throw exception(DRIVER_NOT_EXISTS);
}
}
@Override
public DriverDO getDriver(Long id) {
return driverMapper.selectById(id);
}
@Override
public PageResult<DriverDO> getDriverPage(DriverPageReqVO pageReqVO) {
return driverMapper.selectPage(pageReqVO);
}
}

View File

@ -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.driver.DriverMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

View File

@ -0,0 +1,170 @@
package cn.iocoder.yudao.module.home.service.driver;
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.driver.vo.*;
import cn.iocoder.yudao.module.home.dal.dataobject.driver.DriverDO;
import cn.iocoder.yudao.module.home.dal.mysql.driver.DriverMapper;
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 DriverServiceImpl} 的单元测试类
*
* @author 君风
*/
@Import(DriverServiceImpl.class)
public class DriverServiceImplTest extends BaseDbUnitTest {
@Resource
private DriverServiceImpl driverService;
@Resource
private DriverMapper driverMapper;
@Test
public void testCreateDriver_success() {
// 准备参数
DriverSaveReqVO createReqVO = randomPojo(DriverSaveReqVO.class).setId(null);
// 调用
Long driverId = driverService.createDriver(createReqVO);
// 断言
assertNotNull(driverId);
// 校验记录的属性是否正确
DriverDO driver = driverMapper.selectById(driverId);
assertPojoEquals(createReqVO, driver, "id");
}
@Test
public void testUpdateDriver_success() {
// mock 数据
DriverDO dbDriver = randomPojo(DriverDO.class);
driverMapper.insert(dbDriver);// @Sql: 先插入出一条存在的数据
// 准备参数
DriverSaveReqVO updateReqVO = randomPojo(DriverSaveReqVO.class, o -> {
o.setId(dbDriver.getId()); // 设置更新的 ID
});
// 调用
driverService.updateDriver(updateReqVO);
// 校验是否更新正确
DriverDO driver = driverMapper.selectById(updateReqVO.getId()); // 获取最新的
assertPojoEquals(updateReqVO, driver);
}
@Test
public void testUpdateDriver_notExists() {
// 准备参数
DriverSaveReqVO updateReqVO = randomPojo(DriverSaveReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> driverService.updateDriver(updateReqVO), DRIVER_NOT_EXISTS);
}
@Test
public void testDeleteDriver_success() {
// mock 数据
DriverDO dbDriver = randomPojo(DriverDO.class);
driverMapper.insert(dbDriver);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbDriver.getId();
// 调用
driverService.deleteDriver(id);
// 校验数据不存在了
assertNull(driverMapper.selectById(id));
}
@Test
public void testDeleteDriver_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> driverService.deleteDriver(id), DRIVER_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetDriverPage() {
// mock 数据
DriverDO dbDriver = randomPojo(DriverDO.class, o -> { // 等会查询到
o.setId(null);
o.setName(null);
o.setGender(null);
o.setDriverStatus(null);
o.setContactInfo(null);
o.setLicense(null);
o.setLicenseType(null);
o.setHealthStatus(null);
o.setExperience(null);
o.setRemarks(null);
o.setCreateTime(null);
});
driverMapper.insert(dbDriver);
// 测试 id 不匹配
driverMapper.insert(cloneIgnoreId(dbDriver, o -> o.setId(null)));
// 测试 name 不匹配
driverMapper.insert(cloneIgnoreId(dbDriver, o -> o.setName(null)));
// 测试 gender 不匹配
driverMapper.insert(cloneIgnoreId(dbDriver, o -> o.setGender(null)));
// 测试 driverStatus 不匹配
driverMapper.insert(cloneIgnoreId(dbDriver, o -> o.setDriverStatus(null)));
// 测试 contactInfo 不匹配
driverMapper.insert(cloneIgnoreId(dbDriver, o -> o.setContactInfo(null)));
// 测试 license 不匹配
driverMapper.insert(cloneIgnoreId(dbDriver, o -> o.setLicense(null)));
// 测试 licenseType 不匹配
driverMapper.insert(cloneIgnoreId(dbDriver, o -> o.setLicenseType(null)));
// 测试 healthStatus 不匹配
driverMapper.insert(cloneIgnoreId(dbDriver, o -> o.setHealthStatus(null)));
// 测试 experience 不匹配
driverMapper.insert(cloneIgnoreId(dbDriver, o -> o.setExperience(null)));
// 测试 remarks 不匹配
driverMapper.insert(cloneIgnoreId(dbDriver, o -> o.setRemarks(null)));
// 测试 createTime 不匹配
driverMapper.insert(cloneIgnoreId(dbDriver, o -> o.setCreateTime(null)));
// 准备参数
DriverPageReqVO reqVO = new DriverPageReqVO();
reqVO.setId(null);
reqVO.setName(null);
reqVO.setGender(null);
reqVO.setDriverStatus(null);
reqVO.setContactInfo(null);
reqVO.setLicense(null);
reqVO.setLicenseType(null);
reqVO.setHealthStatus(null);
reqVO.setExperience(null);
reqVO.setRemarks(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
PageResult<DriverDO> pageResult = driverService.getDriverPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbDriver, pageResult.getList().get(0));
}
}