mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-02-01 19:24:57 +08:00
[feat] 增加项目与用户的关联表
This commit is contained in:
parent
f32dd75760
commit
9e7575e9cb
@ -4,9 +4,13 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
||||
|
||||
/**
|
||||
* @author hhyykk
|
||||
* @description 错误码枚举类 1_021_000_000 段
|
||||
* @description 错误码枚举类
|
||||
* @date 2024/7/3
|
||||
*/
|
||||
public interface ErrorCodeConstants {
|
||||
// ============ 项目信息 =========
|
||||
ErrorCode PROJECT_NOT_EXISTS = new ErrorCode(1_021_000_000, "项目信息不存在");
|
||||
|
||||
// ============ 项目与人员关联关系 =========
|
||||
ErrorCode PROJECT_USER_NOT_EXISTS = new ErrorCode(1_022_000_000, "项目与人员关联关系不存在");
|
||||
}
|
||||
|
@ -0,0 +1,95 @@
|
||||
package cn.iocoder.yudao.module.pms.controller.admin.projectuser;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.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 jakarta.validation.constraints.*;
|
||||
import jakarta.validation.*;
|
||||
import jakarta.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.pms.controller.admin.projectuser.vo.*;
|
||||
import cn.iocoder.yudao.module.pms.dal.dataobject.projectuser.ProjectUserDO;
|
||||
import cn.iocoder.yudao.module.pms.service.projectuser.ProjectUserService;
|
||||
|
||||
@Tag(name = "管理后台 - 项目与人员关联关系")
|
||||
@RestController
|
||||
@RequestMapping("/pms/project-user")
|
||||
@Validated
|
||||
public class ProjectUserController {
|
||||
|
||||
@Resource
|
||||
private ProjectUserService projectUserService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建项目与人员关联关系")
|
||||
@PreAuthorize("@ss.hasPermission('pms:project-user:create')")
|
||||
public CommonResult<Long> createProjectUser(@Valid @RequestBody ProjectUserSaveReqVO createReqVO) {
|
||||
return success(projectUserService.createProjectUser(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新项目与人员关联关系")
|
||||
@PreAuthorize("@ss.hasPermission('pms:project-user:update')")
|
||||
public CommonResult<Boolean> updateProjectUser(@Valid @RequestBody ProjectUserSaveReqVO updateReqVO) {
|
||||
projectUserService.updateProjectUser(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除项目与人员关联关系")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('pms:project-user:delete')")
|
||||
public CommonResult<Boolean> deleteProjectUser(@RequestParam("id") Long id) {
|
||||
projectUserService.deleteProjectUser(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得项目与人员关联关系")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('pms:project-user:query')")
|
||||
public CommonResult<ProjectUserRespVO> getProjectUser(@RequestParam("id") Long id) {
|
||||
ProjectUserDO projectUser = projectUserService.getProjectUser(id);
|
||||
return success(BeanUtils.toBean(projectUser, ProjectUserRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得项目与人员关联关系分页")
|
||||
@PreAuthorize("@ss.hasPermission('pms:project-user:query')")
|
||||
public CommonResult<PageResult<ProjectUserRespVO>> getProjectUserPage(@Valid ProjectUserPageReqVO pageReqVO) {
|
||||
PageResult<ProjectUserDO> pageResult = projectUserService.getProjectUserPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, ProjectUserRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出项目与人员关联关系 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('pms:project-user:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportProjectUserExcel(@Valid ProjectUserPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<ProjectUserDO> list = projectUserService.getProjectUserPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "项目与人员关联关系.xls", "数据", ProjectUserRespVO.class,
|
||||
BeanUtils.toBean(list, ProjectUserRespVO.class));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package cn.iocoder.yudao.module.pms.controller.admin.projectuser.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 ProjectUserPageReqVO extends PageParam {
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package cn.iocoder.yudao.module.pms.controller.admin.projectuser.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - 项目与人员关联关系 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class ProjectUserRespVO {
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package cn.iocoder.yudao.module.pms.controller.admin.projectuser.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 项目与人员关联关系新增/修改 Request VO")
|
||||
@Data
|
||||
public class ProjectUserSaveReqVO {
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package cn.iocoder.yudao.module.pms.dal.dataobject.projectuser;
|
||||
|
||||
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 hhyykk
|
||||
*/
|
||||
@TableName("pms_project_user")
|
||||
@KeySequence("pms_project_user_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ProjectUserDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 项目id
|
||||
*/
|
||||
private Long projectId;
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
private String updator;
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
private Boolean delete;
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package cn.iocoder.yudao.module.pms.dal.mysql.projectuser;
|
||||
|
||||
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.pms.dal.dataobject.projectuser.ProjectUserDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.pms.controller.admin.projectuser.vo.*;
|
||||
|
||||
/**
|
||||
* 项目与人员关联关系 Mapper
|
||||
*
|
||||
* @author hhyykk
|
||||
*/
|
||||
@Mapper
|
||||
public interface ProjectUserMapper extends BaseMapperX<ProjectUserDO> {
|
||||
|
||||
default PageResult<ProjectUserDO> selectPage(ProjectUserPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<ProjectUserDO>()
|
||||
.orderByDesc(ProjectUserDO::getId));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package cn.iocoder.yudao.module.pms.service.projectuser;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.validation.*;
|
||||
import cn.iocoder.yudao.module.pms.controller.admin.projectuser.vo.*;
|
||||
import cn.iocoder.yudao.module.pms.dal.dataobject.projectuser.ProjectUserDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 项目与人员关联关系 Service 接口
|
||||
*
|
||||
* @author hhyykk
|
||||
*/
|
||||
public interface ProjectUserService {
|
||||
|
||||
/**
|
||||
* 创建项目与人员关联关系
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createProjectUser(@Valid ProjectUserSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新项目与人员关联关系
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateProjectUser(@Valid ProjectUserSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除项目与人员关联关系
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteProjectUser(Long id);
|
||||
|
||||
/**
|
||||
* 获得项目与人员关联关系
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 项目与人员关联关系
|
||||
*/
|
||||
ProjectUserDO getProjectUser(Long id);
|
||||
|
||||
/**
|
||||
* 获得项目与人员关联关系分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 项目与人员关联关系分页
|
||||
*/
|
||||
PageResult<ProjectUserDO> getProjectUserPage(ProjectUserPageReqVO pageReqVO);
|
||||
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package cn.iocoder.yudao.module.pms.service.projectuser;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import cn.iocoder.yudao.module.pms.controller.admin.projectuser.vo.*;
|
||||
import cn.iocoder.yudao.module.pms.dal.dataobject.projectuser.ProjectUserDO;
|
||||
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.pms.dal.mysql.projectuser.ProjectUserMapper;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 项目与人员关联关系 Service 实现类
|
||||
*
|
||||
* @author hhyykk
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ProjectUserServiceImpl implements ProjectUserService {
|
||||
|
||||
@Resource
|
||||
private ProjectUserMapper projectUserMapper;
|
||||
|
||||
@Override
|
||||
public Long createProjectUser(ProjectUserSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
ProjectUserDO projectUser = BeanUtils.toBean(createReqVO, ProjectUserDO.class);
|
||||
projectUserMapper.insert(projectUser);
|
||||
// 返回
|
||||
return projectUser.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProjectUser(ProjectUserSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateProjectUserExists(updateReqVO.getId());
|
||||
// 更新
|
||||
ProjectUserDO updateObj = BeanUtils.toBean(updateReqVO, ProjectUserDO.class);
|
||||
projectUserMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteProjectUser(Long id) {
|
||||
// 校验存在
|
||||
validateProjectUserExists(id);
|
||||
// 删除
|
||||
projectUserMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateProjectUserExists(Long id) {
|
||||
if (projectUserMapper.selectById(id) == null) {
|
||||
throw exception(PROJECT_USER_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectUserDO getProjectUser(Long id) {
|
||||
return projectUserMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ProjectUserDO> getProjectUserPage(ProjectUserPageReqVO pageReqVO) {
|
||||
return projectUserMapper.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.pms.dal.mysql.projectuser.ProjectUserMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
@ -0,0 +1,126 @@
|
||||
package cn.iocoder.yudao.module.pms.service.projectuser;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import cn.iocoder.yudao.module.pms.controller.admin.projectuser.vo.*;
|
||||
import cn.iocoder.yudao.module.pms.dal.dataobject.projectuser.ProjectUserDO;
|
||||
import cn.iocoder.yudao.module.pms.dal.mysql.projectuser.ProjectUserMapper;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import jakarta.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.pms.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 ProjectUserServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author hhyykk
|
||||
*/
|
||||
@Import(ProjectUserServiceImpl.class)
|
||||
public class ProjectUserServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private ProjectUserServiceImpl projectUserService;
|
||||
|
||||
@Resource
|
||||
private ProjectUserMapper projectUserMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateProjectUser_success() {
|
||||
// 准备参数
|
||||
ProjectUserSaveReqVO createReqVO = randomPojo(ProjectUserSaveReqVO.class).setId(null);
|
||||
|
||||
// 调用
|
||||
Long projectUserId = projectUserService.createProjectUser(createReqVO);
|
||||
// 断言
|
||||
assertNotNull(projectUserId);
|
||||
// 校验记录的属性是否正确
|
||||
ProjectUserDO projectUser = projectUserMapper.selectById(projectUserId);
|
||||
assertPojoEquals(createReqVO, projectUser, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateProjectUser_success() {
|
||||
// mock 数据
|
||||
ProjectUserDO dbProjectUser = randomPojo(ProjectUserDO.class);
|
||||
projectUserMapper.insert(dbProjectUser);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
ProjectUserSaveReqVO updateReqVO = randomPojo(ProjectUserSaveReqVO.class, o -> {
|
||||
o.setId(dbProjectUser.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
projectUserService.updateProjectUser(updateReqVO);
|
||||
// 校验是否更新正确
|
||||
ProjectUserDO projectUser = projectUserMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(updateReqVO, projectUser);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateProjectUser_notExists() {
|
||||
// 准备参数
|
||||
ProjectUserSaveReqVO updateReqVO = randomPojo(ProjectUserSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> projectUserService.updateProjectUser(updateReqVO), PROJECT_USER_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteProjectUser_success() {
|
||||
// mock 数据
|
||||
ProjectUserDO dbProjectUser = randomPojo(ProjectUserDO.class);
|
||||
projectUserMapper.insert(dbProjectUser);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbProjectUser.getId();
|
||||
|
||||
// 调用
|
||||
projectUserService.deleteProjectUser(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(projectUserMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteProjectUser_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> projectUserService.deleteProjectUser(id), PROJECT_USER_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetProjectUserPage() {
|
||||
// mock 数据
|
||||
ProjectUserDO dbProjectUser = randomPojo(ProjectUserDO.class, o -> { // 等会查询到
|
||||
});
|
||||
projectUserMapper.insert(dbProjectUser);
|
||||
// 准备参数
|
||||
ProjectUserPageReqVO reqVO = new ProjectUserPageReqVO();
|
||||
|
||||
// 调用
|
||||
PageResult<ProjectUserDO> pageResult = projectUserService.getProjectUserPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbProjectUser, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user