首页
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
20670def3c
commit
8c15c22455
@ -0,0 +1,95 @@
|
||||
package cn.iocoder.yudao.module.home.controller.admin.homepj;
|
||||
|
||||
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.homepj.vo.*;
|
||||
import cn.iocoder.yudao.module.home.dal.dataobject.homepj.HomepjDO;
|
||||
import cn.iocoder.yudao.module.home.service.homepj.HomepjService;
|
||||
|
||||
@Tag(name = "管理后台 - 主要用于首页的项目数据")
|
||||
@RestController
|
||||
@RequestMapping("/home/pj")
|
||||
@Validated
|
||||
public class HomepjController {
|
||||
|
||||
@Resource
|
||||
private HomepjService pjService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建主要用于首页的项目数据")
|
||||
@PreAuthorize("@ss.hasPermission('home:pj:create')")
|
||||
public CommonResult<Long> createpj(@Valid @RequestBody HomepjSaveReqVO createReqVO) {
|
||||
return success(pjService.createpj(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新主要用于首页的项目数据")
|
||||
@PreAuthorize("@ss.hasPermission('home:pj:update')")
|
||||
public CommonResult<Boolean> updatepj(@Valid @RequestBody HomepjSaveReqVO updateReqVO) {
|
||||
pjService.updatepj(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除主要用于首页的项目数据")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('home:pj:delete')")
|
||||
public CommonResult<Boolean> deletepj(@RequestParam("id") Long id) {
|
||||
pjService.deletepj(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得主要用于首页的项目数据")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('home:pj:query')")
|
||||
public CommonResult<HomepjRespVO> getpj(@RequestParam("id") Long id) {
|
||||
HomepjDO pj = pjService.getpj(id);
|
||||
return success(BeanUtils.toBean(pj, HomepjRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得主要用于首页的项目数据分页")
|
||||
@PreAuthorize("@ss.hasPermission('home:pj:query')")
|
||||
public CommonResult<PageResult<HomepjRespVO>> getpjPage(@Valid HomepjPageReqVO pageReqVO) {
|
||||
PageResult<HomepjDO> pageResult = pjService.getpjPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, HomepjRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出主要用于首页的项目数据 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('home:pj:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportpjExcel(@Valid HomepjPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<HomepjDO> list = pjService.getpjPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "主要用于首页的项目数据.xls", "数据", HomepjRespVO.class,
|
||||
BeanUtils.toBean(list, HomepjRespVO.class));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package cn.iocoder.yudao.module.home.controller.admin.homepj.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 HomepjPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "id", example = "21859")
|
||||
private Long pjId;
|
||||
|
||||
@Schema(description = "项目名称", example = "张三")
|
||||
private String pjName;
|
||||
|
||||
@Schema(description = "是否完成0未完成1完成")
|
||||
private Integer pjDone;
|
||||
|
||||
@Schema(description = "项目描述")
|
||||
private String pjDescribe;
|
||||
|
||||
@Schema(description = "项目内容")
|
||||
private String pjContent;
|
||||
|
||||
@Schema(description = "项目类别", example = "2")
|
||||
private Integer pjType;
|
||||
|
||||
@Schema(description = "项目预计完成时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] pjEtime;
|
||||
|
||||
@Schema(description = "项目实际完成时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] pjVtime;
|
||||
|
||||
@Schema(description = "参与部门")
|
||||
private Integer pjDept;
|
||||
|
||||
@Schema(description = "参与人数")
|
||||
private Long pjNumber;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package cn.iocoder.yudao.module.home.controller.admin.homepj.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 HomepjRespVO {
|
||||
|
||||
@Schema(description = "id", example = "21859")
|
||||
@ExcelProperty("id")
|
||||
private Long pjId;
|
||||
|
||||
@Schema(description = "项目名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
|
||||
@ExcelProperty("项目名称")
|
||||
private String pjName;
|
||||
|
||||
@Schema(description = "是否完成0未完成1完成", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty(value = "是否完成0未完成1完成", converter = DictConvert.class)
|
||||
@DictFormat("home_pj") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
private Integer pjDone;
|
||||
|
||||
@Schema(description = "项目描述", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("项目描述")
|
||||
private String pjDescribe;
|
||||
|
||||
@Schema(description = "项目内容")
|
||||
@ExcelProperty("项目内容")
|
||||
private String pjContent;
|
||||
|
||||
@Schema(description = "项目类别", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@ExcelProperty(value = "项目类别", converter = DictConvert.class)
|
||||
@DictFormat("home_pj_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
private Integer pjType;
|
||||
|
||||
@Schema(description = "项目预计完成时间")
|
||||
@ExcelProperty("项目预计完成时间")
|
||||
private LocalDateTime pjEtime;
|
||||
|
||||
@Schema(description = "项目实际完成时间")
|
||||
@ExcelProperty("项目实际完成时间")
|
||||
private LocalDateTime pjVtime;
|
||||
|
||||
@Schema(description = "参与部门", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty(value = "参与部门", converter = DictConvert.class)
|
||||
@DictFormat("home_pj_dept") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
private Integer pjDept;
|
||||
|
||||
@Schema(description = "参与人数", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("参与人数")
|
||||
private Long pjNumber;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package cn.iocoder.yudao.module.home.controller.admin.homepj.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 HomepjSaveReqVO {
|
||||
|
||||
@Schema(description = "id", example = "21859")
|
||||
private Long pjId;
|
||||
|
||||
@Schema(description = "项目名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
|
||||
@NotEmpty(message = "项目名称不能为空")
|
||||
private String pjName;
|
||||
|
||||
@Schema(description = "是否完成0未完成1完成", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "是否完成0未完成1完成不能为空")
|
||||
private Integer pjDone;
|
||||
|
||||
@Schema(description = "项目描述", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "项目描述不能为空")
|
||||
private String pjDescribe;
|
||||
|
||||
@Schema(description = "项目内容")
|
||||
@NotEmpty(message = "项目内容不能为空")
|
||||
private String pjContent;
|
||||
|
||||
@Schema(description = "项目类别", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@NotNull(message = "项目类别不能为空")
|
||||
private Integer pjType;
|
||||
|
||||
@Schema(description = "项目预计完成时间")
|
||||
private LocalDateTime pjEtime;
|
||||
|
||||
@Schema(description = "项目实际完成时间")
|
||||
private LocalDateTime pjVtime;
|
||||
|
||||
@Schema(description = "参与部门", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "参与部门不能为空")
|
||||
private Integer pjDept;
|
||||
|
||||
@Schema(description = "参与人数", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "参与人数不能为空")
|
||||
private Long pjNumber;
|
||||
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package cn.iocoder.yudao.module.home.dal.dataobject.homepj;
|
||||
|
||||
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("des_homePJ")
|
||||
@KeySequence("des_homepj_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class HomepjDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId
|
||||
private Long pjId;
|
||||
/**
|
||||
* 项目名称
|
||||
*/
|
||||
private String pjName;
|
||||
/**
|
||||
* 是否完成0未完成1完成
|
||||
*
|
||||
* 枚举 {@link TODO home_pj 对应的类}
|
||||
*/
|
||||
private Integer pjDone;
|
||||
/**
|
||||
* 项目描述
|
||||
*/
|
||||
private String pjDescribe;
|
||||
/**
|
||||
* 项目内容
|
||||
*/
|
||||
private String pjContent;
|
||||
/**
|
||||
* 项目类别
|
||||
*
|
||||
* 枚举 {@link TODO home_pj_type 对应的类}
|
||||
*/
|
||||
private Integer pjType;
|
||||
/**
|
||||
* 项目预计完成时间
|
||||
*/
|
||||
private LocalDateTime pjEtime;
|
||||
/**
|
||||
* 项目实际完成时间
|
||||
*/
|
||||
private LocalDateTime pjVtime;
|
||||
/**
|
||||
* 参与部门
|
||||
*
|
||||
* 枚举 {@link TODO home_pj_dept 对应的类}
|
||||
*/
|
||||
private Integer pjDept;
|
||||
/**
|
||||
* 参与人数
|
||||
*/
|
||||
private Long pjNumber;
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package cn.iocoder.yudao.module.home.dal.mysql.homepj;
|
||||
|
||||
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.homepj.HomepjDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.home.controller.admin.homepj.vo.*;
|
||||
|
||||
/**
|
||||
* 主要用于首页的项目数据 Mapper
|
||||
*
|
||||
* @author 君风
|
||||
*/
|
||||
@Mapper
|
||||
public interface HomepjMapper extends BaseMapperX<HomepjDO> {
|
||||
|
||||
default PageResult<HomepjDO> selectPage(HomepjPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<HomepjDO>()
|
||||
.eqIfPresent(HomepjDO::getPjId, reqVO.getPjId())
|
||||
.likeIfPresent(HomepjDO::getPjName, reqVO.getPjName())
|
||||
.eqIfPresent(HomepjDO::getPjDone, reqVO.getPjDone())
|
||||
.eqIfPresent(HomepjDO::getPjDescribe, reqVO.getPjDescribe())
|
||||
.eqIfPresent(HomepjDO::getPjContent, reqVO.getPjContent())
|
||||
.eqIfPresent(HomepjDO::getPjType, reqVO.getPjType())
|
||||
.betweenIfPresent(HomepjDO::getPjEtime, reqVO.getPjEtime())
|
||||
.betweenIfPresent(HomepjDO::getPjVtime, reqVO.getPjVtime())
|
||||
.eqIfPresent(HomepjDO::getPjDept, reqVO.getPjDept())
|
||||
.eqIfPresent(HomepjDO::getPjNumber, reqVO.getPjNumber())
|
||||
.betweenIfPresent(HomepjDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(HomepjDO::getPjId));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package cn.iocoder.yudao.module.home.service.homepj;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
import cn.iocoder.yudao.module.home.controller.admin.homepj.vo.*;
|
||||
import cn.iocoder.yudao.module.home.dal.dataobject.homepj.HomepjDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 主要用于首页的项目数据 Service 接口
|
||||
*
|
||||
* @author 君风
|
||||
*/
|
||||
public interface HomepjService {
|
||||
|
||||
/**
|
||||
* 创建主要用于首页的项目数据
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createpj(@Valid HomepjSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新主要用于首页的项目数据
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updatepj(@Valid HomepjSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除主要用于首页的项目数据
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deletepj(Long id);
|
||||
|
||||
/**
|
||||
* 获得主要用于首页的项目数据
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 主要用于首页的项目数据
|
||||
*/
|
||||
HomepjDO getpj(Long id);
|
||||
|
||||
/**
|
||||
* 获得主要用于首页的项目数据分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 主要用于首页的项目数据分页
|
||||
*/
|
||||
PageResult<HomepjDO> getpjPage(HomepjPageReqVO pageReqVO);
|
||||
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package cn.iocoder.yudao.module.home.service.homepj;
|
||||
|
||||
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.homepj.vo.*;
|
||||
import cn.iocoder.yudao.module.home.dal.dataobject.homepj.HomepjDO;
|
||||
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.homepj.HomepjMapper;
|
||||
|
||||
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 HomepjServiceImpl implements HomepjService {
|
||||
|
||||
@Resource
|
||||
private HomepjMapper pjMapper;
|
||||
|
||||
@Override
|
||||
public Long createpj(HomepjSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
HomepjDO pj = BeanUtils.toBean(createReqVO, HomepjDO.class);
|
||||
pjMapper.insert(pj);
|
||||
// 返回
|
||||
return pj.getPjId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatepj(HomepjSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validatepjExists(updateReqVO.getPjId());
|
||||
// 更新
|
||||
HomepjDO updateObj = BeanUtils.toBean(updateReqVO, HomepjDO.class);
|
||||
pjMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletepj(Long id) {
|
||||
// 校验存在
|
||||
validatepjExists(id);
|
||||
// 删除
|
||||
pjMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validatepjExists(Long id) {
|
||||
if (pjMapper.selectById(id) == null) {
|
||||
throw exception(PJ_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HomepjDO getpj(Long id) {
|
||||
return pjMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<HomepjDO> getpjPage(HomepjPageReqVO pageReqVO) {
|
||||
return pjMapper.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.homepj.HomepjMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
@ -0,0 +1,170 @@
|
||||
package cn.iocoder.yudao.module.home.service.homepj;
|
||||
|
||||
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.homepj.vo.*;
|
||||
import cn.iocoder.yudao.module.home.dal.dataobject.homepj.HomepjDO;
|
||||
import cn.iocoder.yudao.module.home.dal.mysql.homepj.HomepjMapper;
|
||||
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 HomepjServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 君风
|
||||
*/
|
||||
@Import(HomepjServiceImpl.class)
|
||||
public class HomepjServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private HomepjServiceImpl pjService;
|
||||
|
||||
@Resource
|
||||
private HomepjMapper pjMapper;
|
||||
|
||||
@Test
|
||||
public void testCreatepj_success() {
|
||||
// 准备参数
|
||||
HomepjSaveReqVO createReqVO = randomPojo(HomepjSaveReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long pjId = pjService.createpj(createReqVO);
|
||||
// 断言
|
||||
assertNotNull(pjId);
|
||||
// 校验记录的属性是否正确
|
||||
HomepjDO pj = pjMapper.selectById(pjId);
|
||||
assertPojoEquals(createReqVO, pj, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatepj_success() {
|
||||
// mock 数据
|
||||
HomepjDO dbpj = randomPojo(HomepjDO.class);
|
||||
pjMapper.insert(dbpj);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
HomepjSaveReqVO updateReqVO = randomPojo(HomepjSaveReqVO.class, o -> {
|
||||
o.setPjId(dbpj.getPjId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
pjService.updatepj(updateReqVO);
|
||||
// 校验是否更新正确
|
||||
HomepjDO pj = pjMapper.selectById(updateReqVO.getPjId()); // 获取最新的
|
||||
assertPojoEquals(updateReqVO, pj);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatepj_notExists() {
|
||||
// 准备参数
|
||||
HomepjSaveReqVO updateReqVO = randomPojo(HomepjSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> pjService.updatepj(updateReqVO), PJ_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeletepj_success() {
|
||||
// mock 数据
|
||||
HomepjDO dbpj = randomPojo(HomepjDO.class);
|
||||
pjMapper.insert(dbpj);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbpj.getPjId();
|
||||
|
||||
// 调用
|
||||
pjService.deletepj(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(pjMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeletepj_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> pjService.deletepj(id), PJ_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetpjPage() {
|
||||
// mock 数据
|
||||
HomepjDO dbpj = randomPojo(HomepjDO.class, o -> { // 等会查询到
|
||||
o.setPjId(null);
|
||||
o.setPjName(null);
|
||||
o.setPjDone(null);
|
||||
o.setPjDescribe(null);
|
||||
o.setPjContent(null);
|
||||
o.setPjType(null);
|
||||
o.setPjEtime(null);
|
||||
o.setPjVtime(null);
|
||||
o.setPjDept(null);
|
||||
o.setPjNumber(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
pjMapper.insert(dbpj);
|
||||
// 测试 pjId 不匹配
|
||||
pjMapper.insert(cloneIgnoreId(dbpj, o -> o.setPjId(null)));
|
||||
// 测试 pjName 不匹配
|
||||
pjMapper.insert(cloneIgnoreId(dbpj, o -> o.setPjName(null)));
|
||||
// 测试 pjDone 不匹配
|
||||
pjMapper.insert(cloneIgnoreId(dbpj, o -> o.setPjDone(null)));
|
||||
// 测试 pjDescribe 不匹配
|
||||
pjMapper.insert(cloneIgnoreId(dbpj, o -> o.setPjDescribe(null)));
|
||||
// 测试 pjContent 不匹配
|
||||
pjMapper.insert(cloneIgnoreId(dbpj, o -> o.setPjContent(null)));
|
||||
// 测试 pjType 不匹配
|
||||
pjMapper.insert(cloneIgnoreId(dbpj, o -> o.setPjType(null)));
|
||||
// 测试 pjEtime 不匹配
|
||||
pjMapper.insert(cloneIgnoreId(dbpj, o -> o.setPjEtime(null)));
|
||||
// 测试 pjVtime 不匹配
|
||||
pjMapper.insert(cloneIgnoreId(dbpj, o -> o.setPjVtime(null)));
|
||||
// 测试 pjDept 不匹配
|
||||
pjMapper.insert(cloneIgnoreId(dbpj, o -> o.setPjDept(null)));
|
||||
// 测试 pjNumber 不匹配
|
||||
pjMapper.insert(cloneIgnoreId(dbpj, o -> o.setPjNumber(null)));
|
||||
// 测试 createTime 不匹配
|
||||
pjMapper.insert(cloneIgnoreId(dbpj, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
HomepjPageReqVO reqVO = new HomepjPageReqVO();
|
||||
reqVO.setPjId(null);
|
||||
reqVO.setPjName(null);
|
||||
reqVO.setPjDone(null);
|
||||
reqVO.setPjDescribe(null);
|
||||
reqVO.setPjContent(null);
|
||||
reqVO.setPjType(null);
|
||||
reqVO.setPjEtime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setPjVtime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setPjDept(null);
|
||||
reqVO.setPjNumber(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
PageResult<HomepjDO> pageResult = pjService.getpjPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbpj, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user