Compare commits

...

5 Commits

Author SHA1 Message Date
XaoLi717
90039f7033 办公用品
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
2024-11-06 10:55:22 +08:00
XaoLi717
de690b7cea 办公用品 2024-11-06 10:50:35 +08:00
XaoLi717
dcad4cd75f 办公用品 2024-11-06 10:50:23 +08:00
XaoLi717
e4b25d7a1a 办公用品 2024-11-06 10:50:13 +08:00
XaoLi717
1907c10686 办公用品 2024-11-06 08:52:01 +08:00
14 changed files with 870 additions and 0 deletions

View File

@ -20,4 +20,6 @@ public interface ErrorCodeConstants {
ErrorCode QJGL_NOT_EXISTS = new ErrorCode(1_009_005_000, "请假管理不存在");
// ========== 车辆管理 1_011_004_000 ==========
ErrorCode CLGL_NOT_EXISTS = new ErrorCode(1_011_004_000, "车辆管理不存在");
// ========== 办公用品管理 1_011_005_000 ==========
ErrorCode BGYP_NOT_EXISTS = new ErrorCode(1_011_005_000, "办公用品管理不存在");
}

View File

@ -0,0 +1,96 @@
package cn.iocoder.yudao.module.home.controller.admin.bgyp;
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 static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import cn.iocoder.yudao.module.home.controller.admin.bgyp.vo.*;
import cn.iocoder.yudao.module.home.dal.dataobject.bgyp.BgypDO;
import cn.iocoder.yudao.module.home.service.bgyp.BgypService;
@Tag(name = "管理后台 - 办公用品管理")
@RestController
@RequestMapping("/home/bgyp")
@Validated
public class BgypController {
@Resource
private BgypService bgypService;
@PostMapping("/create")
@Operation(summary = "创建办公用品管理")
@PreAuthorize("@ss.hasPermission('home:bgyp:create')")
public CommonResult<Long> createBgyp(@Valid @RequestBody BgypSaveReqVO createReqVO) {
return success(bgypService.createBgyp(getLoginUserId(), createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新办公用品管理")
@PreAuthorize("@ss.hasPermission('home:bgyp:update')")
public CommonResult<Boolean> updateBgyp(@Valid @RequestBody BgypSaveReqVO updateReqVO) {
bgypService.updateBgyp(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除办公用品管理")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('home:bgyp:delete')")
public CommonResult<Boolean> deleteBgyp(@RequestParam("id") Long id) {
bgypService.deleteBgyp(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得办公用品管理")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('home:bgyp:query')")
public CommonResult<BgypRespVO> getBgyp(@RequestParam("id") Long id) {
BgypDO bgyp = bgypService.getBgyp(id);
return success(BeanUtils.toBean(bgyp, BgypRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得办公用品管理分页")
@PreAuthorize("@ss.hasPermission('home:bgyp:query')")
public CommonResult<PageResult<BgypRespVO>> getBgypPage(@Valid BgypPageReqVO pageReqVO) {
PageResult<BgypDO> pageResult = bgypService.getBgypPage(getLoginUserId(), pageReqVO);
return success(BeanUtils.toBean(pageResult, BgypRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出办公用品管理 Excel")
@PreAuthorize("@ss.hasPermission('home:bgyp:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportBgypExcel(@Valid BgypPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<BgypDO> list = bgypService.getBgypPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "办公用品管理.xls", "数据", BgypRespVO.class,
BeanUtils.toBean(list, BgypRespVO.class));
}
}

View File

@ -0,0 +1,59 @@
package cn.iocoder.yudao.module.home.controller.admin.bgyp.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 BgypPageReqVO extends PageParam {
@Schema(description = "审批状态", example = "2")
private Integer status;
@Schema(description = "申请人的用户编号", example = "12591")
private Long userId;
@Schema(description = "申请标题")
private String title;
@Schema(description = "申请用户名称", example = "王五")
private String userName;
@Schema(description = "申请部门名称", example = "李四")
private String deptName;
@Schema(description = "申请部门id", example = "31022")
private Long deptId;
@Schema(description = "申请物品名字", example = "张三")
private String usageName;
@Schema(description = "申请物品id", example = "11372")
private Integer usageId;
@Schema(description = "申请物品数量")
private Integer usageQuantity;
@Schema(description = "申请物品分类")
private Integer unit;
@Schema(description = "申请用途")
private String usagePurpose;
@Schema(description = "申请时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] usageDate;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,79 @@
package cn.iocoder.yudao.module.home.controller.admin.bgyp.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 BgypRespVO {
@Schema(description = "审批状态", example = "2")
@ExcelProperty("审批状态")
private Integer status;
@Schema(description = "申请人的用户编号", example = "12591")
@ExcelProperty("申请人的用户编号")
private Long userId;
@Schema(description = "流程实例的编号", example = "13849")
@ExcelProperty("流程实例的编号")
private String processInstanceId;
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "12104")
@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 userName;
@Schema(description = "申请部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
@ExcelProperty("申请部门名称")
private String deptName;
@Schema(description = "申请部门id", requiredMode = Schema.RequiredMode.REQUIRED, example = "31022")
@ExcelProperty("申请部门id")
private Long deptId;
@Schema(description = "申请物品名字", example = "张三")
@ExcelProperty("申请物品名字")
private String usageName;
@Schema(description = "申请物品id", requiredMode = Schema.RequiredMode.REQUIRED, example = "11372")
@ExcelProperty(value = "申请物品id", converter = DictConvert.class)
@DictFormat("bgyp_usage_name") // TODO 代码优化建议设置到对应的 DictTypeConstants 枚举类中
private Integer usageId;
@Schema(description = "申请物品数量", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("申请物品数量")
private Integer usageQuantity;
@Schema(description = "申请物品分类")
@ExcelProperty(value = "申请物品分类", converter = DictConvert.class)
@DictFormat("bgyp_unit") // TODO 代码优化建议设置到对应的 DictTypeConstants 枚举类中
private Integer unit;
@Schema(description = "申请用途")
@ExcelProperty("申请用途")
private String usagePurpose;
@Schema(description = "申请时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("申请时间")
private LocalDateTime usageDate;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -0,0 +1,66 @@
package cn.iocoder.yudao.module.home.controller.admin.bgyp.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 BgypSaveReqVO {
@Schema(description = "发起人自选审批人 Map", example = "{taskKey1: [1, 2]}")
private Map<String, List<Long>> startUserSelectAssignees;
@Schema(description = "审批状态", example = "2")
private Integer status;
@Schema(description = "申请人的用户编号", example = "12591")
private Long userId;
@Schema(description = "流程实例的编号", example = "13849")
private String processInstanceId;
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "12104")
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 userName;
@Schema(description = "申请部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
@NotEmpty(message = "申请部门名称不能为空")
private String deptName;
@Schema(description = "申请部门id", requiredMode = Schema.RequiredMode.REQUIRED, example = "31022")
@NotNull(message = "申请部门id不能为空")
private Long deptId;
@Schema(description = "申请物品名字", example = "张三")
private String usageName;
@Schema(description = "申请物品id", requiredMode = Schema.RequiredMode.REQUIRED, example = "11372")
@NotNull(message = "申请物品id不能为空")
private Integer usageId;
@Schema(description = "申请物品数量", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "申请物品数量不能为空")
private Integer usageQuantity;
@Schema(description = "申请物品分类")
private Integer unit;
@Schema(description = "申请用途")
private String usagePurpose;
@Schema(description = "申请时间", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "申请时间不能为空")
private LocalDateTime usageDate;
}

View File

@ -0,0 +1,89 @@
package cn.iocoder.yudao.module.home.dal.dataobject.bgyp;
import com.sun.xml.bind.v2.TODO;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 办公用品管理 DO
*
* @author 君风
*/
@TableName("oa_bgyp")
@KeySequence("oa_bgyp_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BgypDO extends BaseDO {
/**
* id
*/
@TableId
private Long id;
/**
* 审批状态
*/
private Integer status;
/**
* 申请人的用户编号
*/
private Long userId;
/**
* 流程实例的编号
*/
private String processInstanceId;
/**
* 申请标题
*/
private String title;
/**
* 申请用户名称
*/
private String userName;
/**
* 申请部门名称
*/
private String deptName;
/**
* 申请部门id
*/
private Long deptId;
/**
* 申请物品名字
*/
private String usageName;
/**
* 申请物品id
*
* 枚举 {@link TODO bgyp_usage_name 对应的类}
*/
private Integer usageId;
/**
* 申请物品数量
*/
private Integer usageQuantity;
/**
* 申请物品分类
*
* 枚举 {@link TODO bgyp_unit 对应的类}
*/
private Integer unit;
/**
* 申请用途
*/
private String usagePurpose;
/**
* 申请时间
*/
private LocalDateTime usageDate;
}

View File

@ -0,0 +1,55 @@
package cn.iocoder.yudao.module.home.dal.mysql.bgyp;
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.bgyp.BgypDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.home.controller.admin.bgyp.vo.*;
/**
* 办公用品管理 Mapper
*
* @author 君风
*/
@Mapper
public interface BgypMapper extends BaseMapperX<BgypDO> {
default PageResult<BgypDO> selectPage(Long userId, BgypPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<BgypDO>()
.eqIfPresent(BgypDO::getTitle, reqVO.getTitle())
.likeIfPresent(BgypDO::getUserName, reqVO.getUserName())
.likeIfPresent(BgypDO::getDeptName, reqVO.getDeptName())
.eqIfPresent(BgypDO::getDeptId, reqVO.getDeptId())
.likeIfPresent(BgypDO::getUsageName, reqVO.getUsageName())
.eqIfPresent(BgypDO::getUsageId, reqVO.getUsageId())
.eqIfPresent(BgypDO::getUsageQuantity, reqVO.getUsageQuantity())
.eqIfPresent(BgypDO::getUnit, reqVO.getUnit())
.eqIfPresent(BgypDO::getUsagePurpose, reqVO.getUsagePurpose())
.betweenIfPresent(BgypDO::getUsageDate, reqVO.getUsageDate())
.eqIfPresent(BgypDO::getStatus, reqVO.getStatus())
.eqIfPresent(BgypDO::getUserId, userId)
.betweenIfPresent(BgypDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(BgypDO::getId));
}
default PageResult<BgypDO> selectPage(BgypPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<BgypDO>()
.eqIfPresent(BgypDO::getTitle, reqVO.getTitle())
.likeIfPresent(BgypDO::getUserName, reqVO.getUserName())
.likeIfPresent(BgypDO::getDeptName, reqVO.getDeptName())
.eqIfPresent(BgypDO::getDeptId, reqVO.getDeptId())
.likeIfPresent(BgypDO::getUsageName, reqVO.getUsageName())
.eqIfPresent(BgypDO::getUsageId, reqVO.getUsageId())
.eqIfPresent(BgypDO::getUsageQuantity, reqVO.getUsageQuantity())
.eqIfPresent(BgypDO::getUnit, reqVO.getUnit())
.eqIfPresent(BgypDO::getUsagePurpose, reqVO.getUsagePurpose())
.betweenIfPresent(BgypDO::getUsageDate, reqVO.getUsageDate())
.eqIfPresent(BgypDO::getStatus, reqVO.getStatus())
.eqIfPresent(BgypDO::getUserId, reqVO.getUserId())
.betweenIfPresent(BgypDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(BgypDO::getId));
}
}

View File

@ -0,0 +1,65 @@
package cn.iocoder.yudao.module.home.service.bgyp;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.home.controller.admin.bgyp.vo.*;
import cn.iocoder.yudao.module.home.dal.dataobject.bgyp.BgypDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* 办公用品管理 Service 接口
*
* @author 君风
*/
public interface BgypService {
/**
* 创建办公用品管理
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createBgyp(@Valid BgypSaveReqVO createReqVO);
Long createBgyp(Long userId, @Valid BgypSaveReqVO createReqVO);
/**
* 更新办公用品管理
*
* @param updateReqVO 更新信息
*/
void updateBgyp(@Valid BgypSaveReqVO updateReqVO);
/**
* 删除办公用品管理
*
* @param id 编号
*/
void deleteBgyp(Long id);
/**
* 获得办公用品管理
*
* @param id 编号
* @return 办公用品管理
*/
BgypDO getBgyp(Long id);
/**
* 获得办公用品管理分页
*
* @param pageReqVO 分页查询
* @return 办公用品管理分页
*/
PageResult<BgypDO> getBgypPage(BgypPageReqVO pageReqVO);
PageResult<BgypDO> getBgypPage(Long userid, BgypPageReqVO pageReqVO);
/**
* 更新请假申请的状态
*
* @param id 编号
* @param status 结果
*/
void updateBgypStatus(Long id, Integer status);
}

View File

@ -0,0 +1,116 @@
package cn.iocoder.yudao.module.home.service.bgyp;
import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi;
import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum;
import cn.iocoder.yudao.module.home.dal.dataobject.clgl.ClglDO;
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.bgyp.vo.*;
import cn.iocoder.yudao.module.home.dal.dataobject.bgyp.BgypDO;
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.bgyp.BgypMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.KNOWLEDGE_NOT_EXISTS;
import static cn.iocoder.yudao.module.home.enums.ErrorCodeConstants.*;
/**
* 办公用品管理 Service 实现类
*
* @author 君风
*/
@Service
@Validated
public class BgypServiceImpl implements BgypService {
public static final String PROCESS_KEY = "bgyp-001";
@Resource
private BgypMapper bgypMapper;
@Resource
private BpmProcessInstanceApi processInstanceApi;
@Override
public Long createBgyp(BgypSaveReqVO createReqVO) {
// 插入
BgypDO bgyp = BeanUtils.toBean(createReqVO, BgypDO.class);
bgypMapper.insert(bgyp);
// 返回
return bgyp.getId();
}
@Override
public Long createBgyp(Long userId, BgypSaveReqVO createReqVO) {
// 插入
BgypDO bgyp = BeanUtils.toBean(createReqVO, BgypDO.class)
.setUserId(userId).setStatus(BpmTaskStatusEnum.RUNNING.getStatus());
bgypMapper.insert(bgyp);
// 发起 BPM 流程
Map<String, Object> processInstanceVariables = new HashMap<>();
String processInstanceId = processInstanceApi.createProcessInstance(userId,
new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
.setVariables(processInstanceVariables).setBusinessKey(String.valueOf(bgyp.getId()))
.setStartUserSelectAssignees(createReqVO.getStartUserSelectAssignees()));
bgypMapper.updateById(new BgypDO().setId(bgyp.getId()).setProcessInstanceId(processInstanceId));
// 返回
return bgyp.getId();
}
@Override
public void updateBgyp(BgypSaveReqVO updateReqVO) {
// 校验存在
validateBgypExists(updateReqVO.getId());
// 更新
BgypDO updateObj = BeanUtils.toBean(updateReqVO, BgypDO.class);
bgypMapper.updateById(updateObj);
}
@Override
public void deleteBgyp(Long id) {
// 校验存在
validateBgypExists(id);
// 删除
bgypMapper.deleteById(id);
}
private void validateBgypExists(Long id) {
if (bgypMapper.selectById(id) == null) {
throw exception(BGYP_NOT_EXISTS);
}
}
@Override
public BgypDO getBgyp(Long id) {
return bgypMapper.selectById(id);
}
@Override
public PageResult<BgypDO> getBgypPage(BgypPageReqVO pageReqVO) {
return bgypMapper.selectPage(pageReqVO);
}
@Override
public PageResult<BgypDO> getBgypPage(Long userId, BgypPageReqVO pageReqVO) {
return bgypMapper.selectPage(userId,pageReqVO);
}
@Override
public void updateBgypStatus(Long id, Integer status) {
validateLeaveExists(id);
bgypMapper.updateById(new BgypDO().setId(id).setStatus(status));
}
private void validateLeaveExists(Long id) {
if (bgypMapper.selectById(id) == null) {
throw exception(KNOWLEDGE_NOT_EXISTS);
}
}
}

View File

@ -0,0 +1,26 @@
package cn.iocoder.yudao.module.home.service.bgyp.listener;
import cn.iocoder.yudao.module.bpm.event.BpmProcessInstanceStatusEvent;
import cn.iocoder.yudao.module.bpm.event.BpmProcessInstanceStatusEventListener;
import cn.iocoder.yudao.module.home.service.bgyp.BgypService;
import cn.iocoder.yudao.module.home.service.bgyp.BgypServiceImpl;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component
public class BpmBygpStatusListener extends BpmProcessInstanceStatusEventListener {
@Resource
private BgypService bgypService;
@Override
protected String getProcessDefinitionKey() {
return BgypServiceImpl.PROCESS_KEY;
}
@Override
protected void onEvent(BpmProcessInstanceStatusEvent event) {
bgypService.updateBgypStatus(Long.parseLong(event.getBusinessKey()), event.getStatus());
}
}

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

View File

@ -0,0 +1,181 @@
package cn.iocoder.yudao.module.home.service.bgyp;
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.bgyp.vo.*;
import cn.iocoder.yudao.module.home.dal.dataobject.bgyp.BgypDO;
import cn.iocoder.yudao.module.home.dal.mysql.bgyp.BgypMapper;
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 BgypServiceImpl} 的单元测试类
*
* @author 君风
*/
@Import(BgypServiceImpl.class)
public class BgypServiceImplTest extends BaseDbUnitTest {
@Resource
private BgypServiceImpl bgypService;
@Resource
private BgypMapper bgypMapper;
@Test
public void testCreateBgyp_success() {
// 准备参数
BgypSaveReqVO createReqVO = randomPojo(BgypSaveReqVO.class).setId(null);
// 调用
Long bgypId = bgypService.createBgyp(createReqVO);
// 断言
assertNotNull(bgypId);
// 校验记录的属性是否正确
BgypDO bgyp = bgypMapper.selectById(bgypId);
assertPojoEquals(createReqVO, bgyp, "id");
}
@Test
public void testUpdateBgyp_success() {
// mock 数据
BgypDO dbBgyp = randomPojo(BgypDO.class);
bgypMapper.insert(dbBgyp);// @Sql: 先插入出一条存在的数据
// 准备参数
BgypSaveReqVO updateReqVO = randomPojo(BgypSaveReqVO.class, o -> {
o.setId(dbBgyp.getId()); // 设置更新的 ID
});
// 调用
bgypService.updateBgyp(updateReqVO);
// 校验是否更新正确
BgypDO bgyp = bgypMapper.selectById(updateReqVO.getId()); // 获取最新的
assertPojoEquals(updateReqVO, bgyp);
}
@Test
public void testUpdateBgyp_notExists() {
// 准备参数
BgypSaveReqVO updateReqVO = randomPojo(BgypSaveReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> bgypService.updateBgyp(updateReqVO), BGYP_NOT_EXISTS);
}
@Test
public void testDeleteBgyp_success() {
// mock 数据
BgypDO dbBgyp = randomPojo(BgypDO.class);
bgypMapper.insert(dbBgyp);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbBgyp.getId();
// 调用
bgypService.deleteBgyp(id);
// 校验数据不存在了
assertNull(bgypMapper.selectById(id));
}
@Test
public void testDeleteBgyp_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> bgypService.deleteBgyp(id), BGYP_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetBgypPage() {
// mock 数据
BgypDO dbBgyp = randomPojo(BgypDO.class, o -> { // 等会查询到
o.setTitle(null);
o.setUserName(null);
o.setDeptName(null);
o.setDeptId(null);
o.setUsageName(null);
o.setUsageId(null);
o.setUsageQuantity(null);
o.setUnit(null);
o.setUsagePurpose(null);
o.setUsageDate(null);
o.setStatus(null);
o.setUserId(null);
o.setProcessInstanceId(null);
o.setCreateTime(null);
});
bgypMapper.insert(dbBgyp);
// 测试 title 不匹配
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setTitle(null)));
// 测试 userName 不匹配
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setUserName(null)));
// 测试 deptName 不匹配
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setDeptName(null)));
// 测试 deptId 不匹配
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setDeptId(null)));
// 测试 usageName 不匹配
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setUsageName(null)));
// 测试 usageId 不匹配
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setUsageId(null)));
// 测试 usageQuantity 不匹配
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setUsageQuantity(null)));
// 测试 unit 不匹配
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setUnit(null)));
// 测试 usagePurpose 不匹配
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setUsagePurpose(null)));
// 测试 usageDate 不匹配
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setUsageDate(null)));
// 测试 status 不匹配
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setStatus(null)));
// 测试 userId 不匹配
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setUserId(null)));
// 测试 processInstanceId 不匹配
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setProcessInstanceId(null)));
// 测试 createTime 不匹配
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setCreateTime(null)));
// 准备参数
BgypPageReqVO reqVO = new BgypPageReqVO();
reqVO.setTitle(null);
reqVO.setUserName(null);
reqVO.setDeptName(null);
reqVO.setDeptId(null);
reqVO.setUsageName(null);
reqVO.setUsageId(null);
reqVO.setUsageQuantity(null);
reqVO.setUnit(null);
reqVO.setUsagePurpose(null);
reqVO.setUsageDate(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
reqVO.setStatus(null);
reqVO.setUserId(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
PageResult<BgypDO> pageResult = bgypService.getBgypPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbBgyp, pageResult.getList().get(0));
}
}

View File

@ -2,3 +2,4 @@ DELETE FROM "des_datainfo";
DELETE FROM "des_homePJ";
DELETE FROM "des_homeimg";
DELETE FROM "oa_clgl";
DELETE FROM "oa-bgyp";

View File

@ -85,3 +85,26 @@ CREATE TABLE IF NOT EXISTS "oa_clgl" (
"tenant_id" bigint NOT NULL,
PRIMARY KEY ("id")
) COMMENT '车辆管理表';
CREATE TABLE IF NOT EXISTS "oa-bgyp" (
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"title" varchar NOT NULL,
"user_name" varchar NOT NULL,
"dept_name" varchar NOT NULL,
"dept_id" bigint NOT NULL,
"usage_name" varchar,
"usage_id" int NOT NULL,
"usage_quantity" int NOT NULL,
"unit" int,
"usage_purpose" varchar,
"usage_date" varchar NOT NULL,
"status" int,
"user_id" bigint,
"process_instance_id" varchar,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint NOT NULL,
PRIMARY KEY ("id")
) COMMENT '办公用品管理表';