创建会议室管理
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
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:
parent
ea37444cb1
commit
b6715705a4
@ -0,0 +1,95 @@
|
||||
package cn.iocoder.yudao.module.home.controller.admin.hysgl;
|
||||
|
||||
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.hysgl.vo.*;
|
||||
import cn.iocoder.yudao.module.home.dal.dataobject.hysgl.HysglDO;
|
||||
import cn.iocoder.yudao.module.home.service.hysgl.HysglService;
|
||||
|
||||
@Tag(name = "管理后台 - 会议室管理")
|
||||
@RestController
|
||||
@RequestMapping("/home/hysgl")
|
||||
@Validated
|
||||
public class HysglController {
|
||||
|
||||
@Resource
|
||||
private HysglService hysglService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建会议室管理")
|
||||
@PreAuthorize("@ss.hasPermission('home:hysgl:create')")
|
||||
public CommonResult<Long> createHysgl(@Valid @RequestBody HysglSaveReqVO createReqVO) {
|
||||
return success(hysglService.createHysgl(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新会议室管理")
|
||||
@PreAuthorize("@ss.hasPermission('home:hysgl:update')")
|
||||
public CommonResult<Boolean> updateHysgl(@Valid @RequestBody HysglSaveReqVO updateReqVO) {
|
||||
hysglService.updateHysgl(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除会议室管理")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('home:hysgl:delete')")
|
||||
public CommonResult<Boolean> deleteHysgl(@RequestParam("id") Long id) {
|
||||
hysglService.deleteHysgl(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得会议室管理")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('home:hysgl:query')")
|
||||
public CommonResult<HysglRespVO> getHysgl(@RequestParam("id") Long id) {
|
||||
HysglDO hysgl = hysglService.getHysgl(id);
|
||||
return success(BeanUtils.toBean(hysgl, HysglRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得会议室管理分页")
|
||||
@PreAuthorize("@ss.hasPermission('home:hysgl:query')")
|
||||
public CommonResult<PageResult<HysglRespVO>> getHysglPage(@Valid HysglPageReqVO pageReqVO) {
|
||||
PageResult<HysglDO> pageResult = hysglService.getHysglPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, HysglRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出会议室管理 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('home:hysgl:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportHysglExcel(@Valid HysglPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<HysglDO> list = hysglService.getHysglPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "会议室管理.xls", "数据", HysglRespVO.class,
|
||||
BeanUtils.toBean(list, HysglRespVO.class));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package cn.iocoder.yudao.module.home.controller.admin.hysgl.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 HysglPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "会议室管理id", example = "11961")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "标题")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "会议室名", example = "赵六")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "会议室地址")
|
||||
private String location;
|
||||
|
||||
@Schema(description = "会议室类型", example = "2")
|
||||
private Integer roomType;
|
||||
|
||||
@Schema(description = "会议室管理员")
|
||||
private String manager;
|
||||
|
||||
@Schema(description = "会议室大小")
|
||||
private String roomMax;
|
||||
|
||||
@Schema(description = "容纳人数")
|
||||
private Integer capacity;
|
||||
|
||||
@Schema(description = "会议室设备")
|
||||
private String facilities;
|
||||
|
||||
@Schema(description = "使用状态", example = "1")
|
||||
private Integer roomStatus;
|
||||
|
||||
@Schema(description = "会议室照片")
|
||||
private String photo;
|
||||
|
||||
@Schema(description = "备注", example = "随便")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package cn.iocoder.yudao.module.home.controller.admin.hysgl.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 HysglRespVO {
|
||||
|
||||
@Schema(description = "会议室管理id", requiredMode = Schema.RequiredMode.REQUIRED, example = "11961")
|
||||
@ExcelProperty("会议室管理id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "标题", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("标题")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "会议室名", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
|
||||
@ExcelProperty("会议室名")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "会议室地址", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("会议室地址")
|
||||
private String location;
|
||||
|
||||
@Schema(description = "会议室类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@ExcelProperty(value = "会议室类型", converter = DictConvert.class)
|
||||
@DictFormat("hsgl_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
private Integer roomType;
|
||||
|
||||
@Schema(description = "会议室管理员", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("会议室管理员")
|
||||
private String manager;
|
||||
|
||||
@Schema(description = "会议室大小")
|
||||
@ExcelProperty("会议室大小")
|
||||
private String roomMax;
|
||||
|
||||
@Schema(description = "容纳人数")
|
||||
@ExcelProperty("容纳人数")
|
||||
private Integer capacity;
|
||||
|
||||
@Schema(description = "会议室设备")
|
||||
@ExcelProperty("会议室设备")
|
||||
private String facilities;
|
||||
|
||||
@Schema(description = "使用状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty(value = "使用状态", converter = DictConvert.class)
|
||||
@DictFormat("hsgl_status") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
private Integer roomStatus;
|
||||
|
||||
@Schema(description = "会议室照片")
|
||||
@ExcelProperty("会议室照片")
|
||||
private String photo;
|
||||
|
||||
@Schema(description = "备注", example = "随便")
|
||||
@ExcelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package cn.iocoder.yudao.module.home.controller.admin.hysgl.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 HysglSaveReqVO {
|
||||
|
||||
@Schema(description = "会议室管理id", requiredMode = Schema.RequiredMode.REQUIRED, example = "11961")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "标题", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "标题不能为空")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "会议室名", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
|
||||
@NotEmpty(message = "会议室名不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "会议室地址", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "会议室地址不能为空")
|
||||
private String location;
|
||||
|
||||
@Schema(description = "会议室类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@NotNull(message = "会议室类型不能为空")
|
||||
private Integer roomType;
|
||||
|
||||
@Schema(description = "会议室管理员", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "会议室管理员不能为空")
|
||||
private String manager;
|
||||
|
||||
@Schema(description = "会议室大小")
|
||||
private String roomMax;
|
||||
|
||||
@Schema(description = "容纳人数")
|
||||
private Integer capacity;
|
||||
|
||||
@Schema(description = "会议室设备")
|
||||
private String facilities;
|
||||
|
||||
@Schema(description = "使用状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "使用状态不能为空")
|
||||
private Integer roomStatus;
|
||||
|
||||
@Schema(description = "会议室照片")
|
||||
private String photo;
|
||||
|
||||
@Schema(description = "备注", example = "随便")
|
||||
private String remark;
|
||||
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package cn.iocoder.yudao.module.home.dal.dataobject.hysgl;
|
||||
|
||||
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_hysgl")
|
||||
@KeySequence("oa_hysgl_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class HysglDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 会议室管理id
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 会议室名
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 会议室地址
|
||||
*/
|
||||
private String location;
|
||||
/**
|
||||
* 会议室类型
|
||||
*
|
||||
* 枚举 {@link TODO hsgl_type 对应的类}
|
||||
*/
|
||||
private Integer roomType;
|
||||
/**
|
||||
* 会议室管理员
|
||||
*/
|
||||
private String manager;
|
||||
/**
|
||||
* 会议室大小
|
||||
*/
|
||||
private String roomMax;
|
||||
/**
|
||||
* 容纳人数
|
||||
*/
|
||||
private Integer capacity;
|
||||
/**
|
||||
* 会议室设备
|
||||
*/
|
||||
private String facilities;
|
||||
/**
|
||||
* 使用状态
|
||||
*
|
||||
* 枚举 {@link TODO hsgl_status 对应的类}
|
||||
*/
|
||||
private Integer roomStatus;
|
||||
/**
|
||||
* 会议室照片
|
||||
*/
|
||||
private String photo;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package cn.iocoder.yudao.module.home.dal.mysql.hysgl;
|
||||
|
||||
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.hysgl.HysglDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.home.controller.admin.hysgl.vo.*;
|
||||
|
||||
/**
|
||||
* 会议室管理 Mapper
|
||||
*
|
||||
* @author 君风
|
||||
*/
|
||||
@Mapper
|
||||
public interface HysglMapper extends BaseMapperX<HysglDO> {
|
||||
|
||||
default PageResult<HysglDO> selectPage(HysglPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<HysglDO>()
|
||||
.eqIfPresent(HysglDO::getId, reqVO.getId())
|
||||
.eqIfPresent(HysglDO::getTitle, reqVO.getTitle())
|
||||
.likeIfPresent(HysglDO::getName, reqVO.getName())
|
||||
.eqIfPresent(HysglDO::getLocation, reqVO.getLocation())
|
||||
.eqIfPresent(HysglDO::getRoomType, reqVO.getRoomType())
|
||||
.eqIfPresent(HysglDO::getManager, reqVO.getManager())
|
||||
.eqIfPresent(HysglDO::getRoomMax, reqVO.getRoomMax())
|
||||
.eqIfPresent(HysglDO::getCapacity, reqVO.getCapacity())
|
||||
.eqIfPresent(HysglDO::getFacilities, reqVO.getFacilities())
|
||||
.eqIfPresent(HysglDO::getRoomStatus, reqVO.getRoomStatus())
|
||||
.eqIfPresent(HysglDO::getPhoto, reqVO.getPhoto())
|
||||
.eqIfPresent(HysglDO::getRemark, reqVO.getRemark())
|
||||
.betweenIfPresent(HysglDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(HysglDO::getId));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package cn.iocoder.yudao.module.home.service.hysgl;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
import cn.iocoder.yudao.module.home.controller.admin.hysgl.vo.*;
|
||||
import cn.iocoder.yudao.module.home.dal.dataobject.hysgl.HysglDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 会议室管理 Service 接口
|
||||
*
|
||||
* @author 君风
|
||||
*/
|
||||
public interface HysglService {
|
||||
|
||||
/**
|
||||
* 创建会议室管理
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createHysgl(@Valid HysglSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新会议室管理
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateHysgl(@Valid HysglSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除会议室管理
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteHysgl(Long id);
|
||||
|
||||
/**
|
||||
* 获得会议室管理
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 会议室管理
|
||||
*/
|
||||
HysglDO getHysgl(Long id);
|
||||
|
||||
/**
|
||||
* 获得会议室管理分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 会议室管理分页
|
||||
*/
|
||||
PageResult<HysglDO> getHysglPage(HysglPageReqVO pageReqVO);
|
||||
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package cn.iocoder.yudao.module.home.service.hysgl;
|
||||
|
||||
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.hysgl.vo.*;
|
||||
import cn.iocoder.yudao.module.home.dal.dataobject.hysgl.HysglDO;
|
||||
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.hysgl.HysglMapper;
|
||||
|
||||
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 HysglServiceImpl implements HysglService {
|
||||
|
||||
@Resource
|
||||
private HysglMapper hysglMapper;
|
||||
|
||||
@Override
|
||||
public Long createHysgl(HysglSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
HysglDO hysgl = BeanUtils.toBean(createReqVO, HysglDO.class);
|
||||
hysglMapper.insert(hysgl);
|
||||
// 返回
|
||||
return hysgl.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateHysgl(HysglSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateHysglExists(updateReqVO.getId());
|
||||
// 更新
|
||||
HysglDO updateObj = BeanUtils.toBean(updateReqVO, HysglDO.class);
|
||||
hysglMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteHysgl(Long id) {
|
||||
// 校验存在
|
||||
validateHysglExists(id);
|
||||
// 删除
|
||||
hysglMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateHysglExists(Long id) {
|
||||
if (hysglMapper.selectById(id) == null) {
|
||||
throw exception(HYSGL_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HysglDO getHysgl(Long id) {
|
||||
return hysglMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<HysglDO> getHysglPage(HysglPageReqVO pageReqVO) {
|
||||
return hysglMapper.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.hysgl.HysglMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
@ -0,0 +1,178 @@
|
||||
package cn.iocoder.yudao.module.home.service.hysgl;
|
||||
|
||||
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.hysgl.vo.*;
|
||||
import cn.iocoder.yudao.module.home.dal.dataobject.hysgl.HysglDO;
|
||||
import cn.iocoder.yudao.module.home.dal.mysql.hysgl.HysglMapper;
|
||||
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 HysglServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 君风
|
||||
*/
|
||||
@Import(HysglServiceImpl.class)
|
||||
public class HysglServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private HysglServiceImpl hysglService;
|
||||
|
||||
@Resource
|
||||
private HysglMapper hysglMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateHysgl_success() {
|
||||
// 准备参数
|
||||
HysglSaveReqVO createReqVO = randomPojo(HysglSaveReqVO.class).setId(null);
|
||||
|
||||
// 调用
|
||||
Long hysglId = hysglService.createHysgl(createReqVO);
|
||||
// 断言
|
||||
assertNotNull(hysglId);
|
||||
// 校验记录的属性是否正确
|
||||
HysglDO hysgl = hysglMapper.selectById(hysglId);
|
||||
assertPojoEquals(createReqVO, hysgl, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateHysgl_success() {
|
||||
// mock 数据
|
||||
HysglDO dbHysgl = randomPojo(HysglDO.class);
|
||||
hysglMapper.insert(dbHysgl);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
HysglSaveReqVO updateReqVO = randomPojo(HysglSaveReqVO.class, o -> {
|
||||
o.setId(dbHysgl.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
hysglService.updateHysgl(updateReqVO);
|
||||
// 校验是否更新正确
|
||||
HysglDO hysgl = hysglMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(updateReqVO, hysgl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateHysgl_notExists() {
|
||||
// 准备参数
|
||||
HysglSaveReqVO updateReqVO = randomPojo(HysglSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> hysglService.updateHysgl(updateReqVO), HYSGL_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteHysgl_success() {
|
||||
// mock 数据
|
||||
HysglDO dbHysgl = randomPojo(HysglDO.class);
|
||||
hysglMapper.insert(dbHysgl);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbHysgl.getId();
|
||||
|
||||
// 调用
|
||||
hysglService.deleteHysgl(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(hysglMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteHysgl_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> hysglService.deleteHysgl(id), HYSGL_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetHysglPage() {
|
||||
// mock 数据
|
||||
HysglDO dbHysgl = randomPojo(HysglDO.class, o -> { // 等会查询到
|
||||
o.setId(null);
|
||||
o.setTitle(null);
|
||||
o.setName(null);
|
||||
o.setLocation(null);
|
||||
o.setRoomType(null);
|
||||
o.setManager(null);
|
||||
o.setRoomMax(null);
|
||||
o.setCapacity(null);
|
||||
o.setFacilities(null);
|
||||
o.setRoomStatus(null);
|
||||
o.setPhoto(null);
|
||||
o.setRemark(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
hysglMapper.insert(dbHysgl);
|
||||
// 测试 id 不匹配
|
||||
hysglMapper.insert(cloneIgnoreId(dbHysgl, o -> o.setId(null)));
|
||||
// 测试 title 不匹配
|
||||
hysglMapper.insert(cloneIgnoreId(dbHysgl, o -> o.setTitle(null)));
|
||||
// 测试 name 不匹配
|
||||
hysglMapper.insert(cloneIgnoreId(dbHysgl, o -> o.setName(null)));
|
||||
// 测试 location 不匹配
|
||||
hysglMapper.insert(cloneIgnoreId(dbHysgl, o -> o.setLocation(null)));
|
||||
// 测试 roomType 不匹配
|
||||
hysglMapper.insert(cloneIgnoreId(dbHysgl, o -> o.setRoomType(null)));
|
||||
// 测试 manager 不匹配
|
||||
hysglMapper.insert(cloneIgnoreId(dbHysgl, o -> o.setManager(null)));
|
||||
// 测试 roomMax 不匹配
|
||||
hysglMapper.insert(cloneIgnoreId(dbHysgl, o -> o.setRoomMax(null)));
|
||||
// 测试 capacity 不匹配
|
||||
hysglMapper.insert(cloneIgnoreId(dbHysgl, o -> o.setCapacity(null)));
|
||||
// 测试 facilities 不匹配
|
||||
hysglMapper.insert(cloneIgnoreId(dbHysgl, o -> o.setFacilities(null)));
|
||||
// 测试 roomStatus 不匹配
|
||||
hysglMapper.insert(cloneIgnoreId(dbHysgl, o -> o.setRoomStatus(null)));
|
||||
// 测试 photo 不匹配
|
||||
hysglMapper.insert(cloneIgnoreId(dbHysgl, o -> o.setPhoto(null)));
|
||||
// 测试 remark 不匹配
|
||||
hysglMapper.insert(cloneIgnoreId(dbHysgl, o -> o.setRemark(null)));
|
||||
// 测试 createTime 不匹配
|
||||
hysglMapper.insert(cloneIgnoreId(dbHysgl, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
HysglPageReqVO reqVO = new HysglPageReqVO();
|
||||
reqVO.setId(null);
|
||||
reqVO.setTitle(null);
|
||||
reqVO.setName(null);
|
||||
reqVO.setLocation(null);
|
||||
reqVO.setRoomType(null);
|
||||
reqVO.setManager(null);
|
||||
reqVO.setRoomMax(null);
|
||||
reqVO.setCapacity(null);
|
||||
reqVO.setFacilities(null);
|
||||
reqVO.setRoomStatus(null);
|
||||
reqVO.setPhoto(null);
|
||||
reqVO.setRemark(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
PageResult<HysglDO> pageResult = hysglService.getHysglPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbHysgl, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user