制度模块按需求修改完成,且通过测试

This commit is contained in:
wangna0328 2025-07-31 15:04:46 +08:00
parent 72af3aa203
commit 78c23c019c
11 changed files with 436 additions and 48 deletions

View File

@ -45,7 +45,7 @@ public class RegulationEntity extends AuditableEntity implements Serializable {
private String regulationType;
@ExcelProperty("制度状态")
@ApiModelProperty("制度状态DRAFT-草案,PUBLISHED-已发布ARCHIVED-已归档")
@ApiModelProperty("制度状态DRAFT-草案,APPROVED-已公示,PUBLISHED-已发布ARCHIVED-已归档")
@TableField("status")
private String status;
@ -92,4 +92,8 @@ public class RegulationEntity extends AuditableEntity implements Serializable {
@TableField(exist = false)
@ApiModelProperty("当前用户确认状态pending-待确认confirmed-已确认")
private String confirmStatus;
@TableField(exist = false)
@ApiModelProperty("创建人姓名")
private String createByName;
}

View File

@ -1,12 +0,0 @@
package com.dite.znpt.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dite.znpt.domain.entity.RegulationDraftEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* 制度草案Mapper接口
*/
@Mapper
public interface RegulationDraftMapper extends BaseMapper<RegulationDraftEntity> {
}

View File

@ -1,8 +1,10 @@
package com.dite.znpt.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dite.znpt.domain.entity.RegulationEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* @author wangna
@ -11,4 +13,15 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface RegulationMapper extends BaseMapper<RegulationEntity> {
/**
* 分页查询制度列表包含创建人姓名
* @param page 分页参数
* @param status 状态
* @param type 类型
* @return 分页结果
*/
Page<RegulationEntity> selectRegulationListWithCreator(Page<RegulationEntity> page,
@Param("status") String status,
@Param("type") String type);
}

View File

@ -0,0 +1,24 @@
package com.dite.znpt.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dite.znpt.domain.entity.RegulationTypeEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 制度类型Mapper接口
* @author wangna
* @date 2025/07/29
*/
@Mapper
public interface RegulationTypeMapper extends BaseMapper<RegulationTypeEntity> {
/**
* 分页查询制度类型列表包含创建人姓名
* @param page 分页参数
* @param typeName 类型名称
* @return 分页结果
*/
Page<RegulationTypeEntity> selectRegulationTypeListWithCreator(Page<RegulationTypeEntity> page, @Param("typeName") String typeName);
}

View File

@ -3,7 +3,6 @@ package com.dite.znpt.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.dite.znpt.domain.entity.RegulationEntity;
import com.dite.znpt.domain.Result;
import com.dite.znpt.domain.dto.RegulationConfirmDTO;
/**
* @author wangna
@ -29,6 +28,20 @@ public interface RegulationService extends IService<RegulationEntity> {
*/
Result createRegulationProposal(RegulationEntity regulation);
/**
* 更新制度提案
* @param regulation 制度信息
* @return 结果
*/
Result updateRegulationProposal(RegulationEntity regulation);
/**
* 删除制度提案
* @param regulationId 制度ID
* @return 结果
*/
Result deleteRegulationProposal(String regulationId);
/**
* 获取制度详情
* @param regulationId 制度ID
@ -42,4 +55,11 @@ public interface RegulationService extends IService<RegulationEntity> {
* @return 结果
*/
Result confirmRegulation(String regulationId);
/**
* 公示制度
* @param regulationId 制度ID
* @return 结果
*/
Result approveRegulation(String regulationId);
}

View File

@ -0,0 +1,43 @@
package com.dite.znpt.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.dite.znpt.domain.entity.RegulationTypeEntity;
import com.dite.znpt.domain.Result;
/**
* 制度类型Service接口
* @author wangna
* @date 2025/07/29
*/
public interface RegulationTypeService extends IService<RegulationTypeEntity> {
/**
* 获取制度类型列表
* @param page 页码
* @param size 页大小
* @param typeName 类型名称
* @return 结果
*/
Result getRegulationTypes(Integer page, Integer size, String typeName);
/**
* 创建制度类型
* @param regulationType 制度类型信息
* @return 结果
*/
Result createRegulationType(RegulationTypeEntity regulationType);
/**
* 更新制度类型
* @param regulationType 制度类型信息
* @return 结果
*/
Result updateRegulationType(RegulationTypeEntity regulationType);
/**
* 删除制度类型
* @param typeId 类型ID
* @return 结果
*/
Result deleteRegulationType(String typeId);
}

View File

@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.dite.znpt.domain.entity.RoleMenuEntity;
import com.dite.znpt.domain.vo.RoleMenuReq;
import java.util.List;
/**
* @author Bear.G
@ -12,6 +11,5 @@ import java.util.List;
* @description
*/
public interface RoleMenuService extends IService<RoleMenuEntity> {
void bindRoleMenu(RoleMenuReq req);
}

View File

@ -7,7 +7,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dite.znpt.domain.Result;
import com.dite.znpt.domain.entity.RegulationEntity;
import com.dite.znpt.domain.entity.RegulationConfirmationEntity;
import com.dite.znpt.domain.dto.RegulationConfirmDTO;
import com.dite.znpt.domain.vo.UserResp;
import com.dite.znpt.mapper.RegulationMapper;
import com.dite.znpt.service.RegulationService;
@ -36,52 +35,45 @@ public class RegulationServiceImpl extends ServiceImpl<RegulationMapper, Regulat
}
/**
* 每天凌晨1点自动将公示期10天已到的草案变为已发布
* 每天凌晨1点自动将公示期10天已到的已公示制度变为已发布
*/
@Scheduled(cron = "0 0 1 * * ?")
public void autoPublishDrafts() {
@Transactional(rollbackFor = Exception.class)
public void autoPublishApprovedRegulations() {
LocalDateTime tenDaysAgo = LocalDateTime.now().minusDays(10);
// 查询需要自动发布的制度状态为DRAFT且创建时间超过10天
// 查询需要自动发布的制度状态为APPROVED且更新时间超过10天
LambdaQueryWrapper<RegulationEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(RegulationEntity::getStatus, "DRAFT");
wrapper.le(RegulationEntity::getCreateTime, tenDaysAgo);
wrapper.eq(RegulationEntity::getStatus, "APPROVED");
wrapper.le(RegulationEntity::getUpdateTime, tenDaysAgo);
wrapper.eq(RegulationEntity::getDelFlag, "0");
java.util.List<RegulationEntity> drafts = this.list(wrapper);
java.util.List<RegulationEntity> approvedRegulations = this.list(wrapper);
for (RegulationEntity draft : drafts) {
for (RegulationEntity regulation : approvedRegulations) {
// 更新制度状态和发布信息
draft.setStatus("PUBLISHED");
draft.setPublishTime(LocalDateTime.now());
draft.setEffectiveTime(LocalDateTime.now()); // 设置生效时间为当前时间
draft.setUpdateTime(LocalDateTime.now());
draft.setUpdateBy("系统自动发布");
regulation.setStatus("PUBLISHED");
regulation.setPublishTime(LocalDateTime.now());
regulation.setEffectiveTime(LocalDateTime.now()); // 设置生效时间为当前时间
regulation.setUpdateTime(LocalDateTime.now());
regulation.setUpdateBy("系统自动发布");
this.updateById(draft);
this.updateById(regulation);
}
if (!drafts.isEmpty()) {
System.out.println("自动发布完成,共发布 " + drafts.size() + " 个制度");
if (!approvedRegulations.isEmpty()) {
System.out.println("自动发布完成,共发布 " + approvedRegulations.size() + " 个制度");
}
}
@Override
@Transactional(readOnly = true)
public Result getRegulationList(Integer page, Integer pageSize, String status, String type) {
try {
Page<RegulationEntity> pageParam = new Page<>(page, pageSize);
LambdaQueryWrapper<RegulationEntity> wrapper = new LambdaQueryWrapper<>();
if (status != null && !status.isEmpty()) {
wrapper.eq(RegulationEntity::getStatus, status);
}
if (type != null && !type.isEmpty()) {
wrapper.eq(RegulationEntity::getRegulationType, type);
}
wrapper.eq(RegulationEntity::getDelFlag, "0");
wrapper.orderByDesc(RegulationEntity::getCreateTime);
Page<RegulationEntity> result = this.page(pageParam, wrapper);
// 使用关联查询获取创建人姓名
Page<RegulationEntity> result = this.baseMapper.selectRegulationListWithCreator(pageParam, status, type);
// 如果是获取已发布的制度需要添加确认状态
if (status != null && "PUBLISHED".equals(status)) {
@ -113,11 +105,10 @@ public class RegulationServiceImpl extends ServiceImpl<RegulationMapper, Regulat
regulation.setStatus("DRAFT");
regulation.setCreateTime(LocalDateTime.now());
UserResp user = userService.detail(StpUtil.getLoginIdAsString());
String userName = user != null ? user.getName() : StpUtil.getLoginIdAsString();
regulation.setCreateBy(userName);
String userId = StpUtil.getLoginIdAsString();
regulation.setCreateBy(userId);
regulation.setUpdateTime(LocalDateTime.now());
regulation.setUpdateBy(userName);
regulation.setUpdateBy(userId);
regulation.setDelFlag("0");
this.save(regulation);
@ -128,12 +119,90 @@ public class RegulationServiceImpl extends ServiceImpl<RegulationMapper, Regulat
}
@Override
@Transactional(rollbackFor = Exception.class)
public Result updateRegulationProposal(RegulationEntity regulation) {
try {
RegulationEntity existing = this.getById(regulation.getRegulationId());
if (existing == null) {
return Result.error("制度提案不存在");
}
// 只能更新DRAFT状态的提案
if (!"DRAFT".equals(existing.getStatus())) {
return Result.error("只能更新草稿状态的制度提案");
}
// 只能由创建人更新
if (!existing.getCreateBy().equals(StpUtil.getLoginIdAsString())) {
return Result.error("只能更新自己创建的制度提案");
}
String userId = StpUtil.getLoginIdAsString();
regulation.setUpdateTime(LocalDateTime.now());
regulation.setUpdateBy(userId);
regulation.setStatus("DRAFT"); // 确保状态保持为DRAFT
this.updateById(regulation);
return Result.okM("制度提案更新成功");
} catch (Exception e) {
return Result.error("制度提案更新失败:" + e.getMessage());
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public Result deleteRegulationProposal(String regulationId) {
try {
RegulationEntity regulation = this.getById(regulationId);
if (regulation == null) {
return Result.error("制度提案不存在");
}
// 只能删除DRAFT状态的提案
if (!"DRAFT".equals(regulation.getStatus())) {
return Result.error("只能删除草稿状态的制度提案");
}
// 只能由创建人删除
if (!regulation.getCreateBy().equals(StpUtil.getLoginIdAsString())) {
return Result.error("只能删除自己创建的制度提案");
}
// 软删除
regulation.setDelFlag("1");
regulation.setUpdateTime(LocalDateTime.now());
regulation.setUpdateBy(StpUtil.getLoginIdAsString());
this.updateById(regulation);
return Result.okM("制度提案删除成功");
} catch (Exception e) {
return Result.error("制度提案删除失败:" + e.getMessage());
}
}
@Override
@Transactional(readOnly = true)
public Result getRegulationDetail(String regulationId) {
try {
RegulationEntity regulation = this.getById(regulationId);
if (regulation == null) {
return Result.error("制度不存在");
}
// 获取创建人姓名
if (regulation.getCreateBy() != null && !regulation.getCreateBy().isEmpty()) {
try {
UserResp user = userService.detail(regulation.getCreateBy());
if (user != null) {
regulation.setCreateByName(user.getName());
}
} catch (Exception e) {
// 如果查询失败使用用户ID作为备选
regulation.setCreateByName(regulation.getCreateBy());
}
}
return Result.ok(regulation);
} catch (Exception e) {
return Result.error("获取制度详情失败:" + e.getMessage());
@ -182,4 +251,35 @@ public class RegulationServiceImpl extends ServiceImpl<RegulationMapper, Regulat
return Result.error("制度确认失败:" + e.getMessage());
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public Result approveRegulation(String regulationId) {
try {
RegulationEntity regulation = this.getById(regulationId);
if (regulation == null) {
return Result.error("制度不存在");
}
// 检查制度状态只有DRAFT状态的制度才能公示
if (!"DRAFT".equals(regulation.getStatus())) {
return Result.error("只能公示草稿状态的制度");
}
// 检查权限只有创建人才能公示
if (!regulation.getCreateBy().equals(StpUtil.getLoginIdAsString())) {
return Result.error("只能公示自己创建的制度");
}
// 更新制度状态为已公示
regulation.setStatus("APPROVED");
regulation.setUpdateTime(LocalDateTime.now());
regulation.setUpdateBy(StpUtil.getLoginIdAsString());
this.updateById(regulation);
return Result.okM("制度公示成功");
} catch (Exception e) {
return Result.error("制度公示失败:" + e.getMessage());
}
}
}

View File

@ -0,0 +1,125 @@
package com.dite.znpt.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dite.znpt.domain.Result;
import com.dite.znpt.domain.entity.RegulationTypeEntity;
import com.dite.znpt.domain.entity.RegulationEntity;
import com.dite.znpt.mapper.RegulationTypeMapper;
import com.dite.znpt.mapper.RegulationMapper;
import com.dite.znpt.service.RegulationTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
/**
* 制度类型Service实现类
* @author wangna
* @date 2025/07/29
*/
@Service
public class RegulationTypeServiceImpl extends ServiceImpl<RegulationTypeMapper, RegulationTypeEntity> implements RegulationTypeService {
@Autowired
private RegulationMapper regulationMapper;
@Override
@Transactional(readOnly = true)
public Result getRegulationTypes(Integer page, Integer size, String typeName) {
try {
Page<RegulationTypeEntity> pageParam = new Page<>(page, size);
// 使用连表查询获取创建人姓名
Page<RegulationTypeEntity> result = this.baseMapper.selectRegulationTypeListWithCreator(pageParam, typeName);
return Result.ok(result);
} catch (Exception e) {
return Result.error("获取制度类型列表失败:" + e.getMessage());
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public Result createRegulationType(RegulationTypeEntity regulationType) {
try {
regulationType.setTypeId(java.util.UUID.randomUUID().toString());
regulationType.setCreateTime(LocalDateTime.now());
String userId = StpUtil.getLoginIdAsString();
regulationType.setCreateBy(userId);
regulationType.setUpdateTime(LocalDateTime.now());
regulationType.setUpdateBy(userId);
regulationType.setDelFlag("0");
// 如果没有设置排序顺序设置为当前最大值+1
if (regulationType.getSortOrder() == null) {
Integer maxSortOrder = this.lambdaQuery()
.eq(RegulationTypeEntity::getDelFlag, "0")
.orderByDesc(RegulationTypeEntity::getSortOrder)
.last("LIMIT 1")
.oneOpt()
.map(RegulationTypeEntity::getSortOrder)
.orElse(0);
regulationType.setSortOrder(maxSortOrder + 1);
}
this.save(regulationType);
return Result.okM("制度类型创建成功");
} catch (Exception e) {
return Result.error("制度类型创建失败:" + e.getMessage());
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public Result updateRegulationType(RegulationTypeEntity regulationType) {
try {
RegulationTypeEntity existing = this.getById(regulationType.getTypeId());
if (existing == null) {
return Result.error("制度类型不存在");
}
regulationType.setUpdateTime(LocalDateTime.now());
regulationType.setUpdateBy(cn.dev33.satoken.stp.StpUtil.getLoginIdAsString());
this.updateById(regulationType);
return Result.okM("制度类型更新成功");
} catch (Exception e) {
return Result.error("制度类型更新失败:" + e.getMessage());
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public Result deleteRegulationType(String typeId) {
try {
RegulationTypeEntity regulationType = this.getById(typeId);
if (regulationType == null) {
return Result.error("制度类型不存在");
}
// 检查是否有制度使用此类型
String typeName = regulationType.getTypeName();
// 检查制度表中是否有使用此类型的记录包括所有状态
long regulationCount = regulationMapper.selectCount(
new LambdaQueryWrapper<RegulationEntity>()
.eq(RegulationEntity::getRegulationType, typeName)
.eq(RegulationEntity::getDelFlag, "0")
);
// 如果有制度使用此类型则不允许删除
if (regulationCount > 0) {
return Result.error("该制度类型正在被使用,无法删除。请先删除或修改使用该类型的制度。");
}
regulationType.setDelFlag("1");
this.updateById(regulationType);
return Result.okM("制度类型删除成功");
} catch (Exception e) {
return Result.error("制度类型删除失败:" + e.getMessage());
}
}
}

View File

@ -2,7 +2,6 @@ package com.dite.znpt.web.controller;
import com.dite.znpt.domain.Result;
import com.dite.znpt.domain.entity.RegulationEntity;
import com.dite.znpt.domain.dto.RegulationConfirmDTO;
import com.dite.znpt.service.RegulationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -37,6 +36,19 @@ public class RegulationController {
return regulationService.createRegulationProposal(regulation);
}
@ApiOperation(value = "更新制度提案", httpMethod = "PUT")
@PutMapping("/proposal/{regulationId}")
public Result updateRegulationProposal(@PathVariable String regulationId, @RequestBody RegulationEntity regulation) {
regulation.setRegulationId(regulationId);
return regulationService.updateRegulationProposal(regulation);
}
@ApiOperation(value = "删除制度提案", httpMethod = "DELETE")
@DeleteMapping("/proposal/{regulationId}")
public Result deleteRegulationProposal(@PathVariable String regulationId) {
return regulationService.deleteRegulationProposal(regulationId);
}
@ApiOperation(value = "获取制度详情", httpMethod = "GET")
@GetMapping("/{regulationId}")
public Result getRegulationDetail(@PathVariable String regulationId) {
@ -49,4 +61,15 @@ public class RegulationController {
return regulationService.confirmRegulation(regulationId);
}
/**
* 点击确认公示后原本的制度草案就会进入十天公示期
* @param regulationId
* @return
*/
@ApiOperation(value = "公示制度", httpMethod = "POST")
@PostMapping("/{regulationId}/approve")
public Result approveRegulation(@PathVariable String regulationId) {
return regulationService.approveRegulation(regulationId);
}
}

View File

@ -0,0 +1,50 @@
package com.dite.znpt.web.controller;
import com.dite.znpt.domain.Result;
import com.dite.znpt.domain.entity.RegulationTypeEntity;
import com.dite.znpt.service.RegulationTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* 制度类型Controller
* @author wangna
* @date 2025/07/29
*/
@Api(tags = "制度类型管理")
@RestController
@RequestMapping("/regulation/types")
public class RegulationTypeController {
@Autowired
private RegulationTypeService regulationTypeService;
@ApiOperation(value = "获取制度类型列表", httpMethod = "GET")
@GetMapping
public Result getRegulationTypes(@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "10") int size,
@RequestParam(required = false) String typeName) {
return regulationTypeService.getRegulationTypes(page, size, typeName);
}
@ApiOperation(value = "创建制度类型", httpMethod = "POST")
@PostMapping
public Result createRegulationType(@RequestBody RegulationTypeEntity regulationType) {
return regulationTypeService.createRegulationType(regulationType);
}
@ApiOperation(value = "更新制度类型", httpMethod = "PUT")
@PutMapping("/{typeId}")
public Result updateRegulationType(@PathVariable String typeId, @RequestBody RegulationTypeEntity regulationType) {
regulationType.setTypeId(typeId);
return regulationTypeService.updateRegulationType(regulationType);
}
@ApiOperation(value = "删除制度类型", httpMethod = "DELETE")
@DeleteMapping("/{typeId}")
public Result deleteRegulationType(@PathVariable String typeId) {
return regulationTypeService.deleteRegulationType(typeId);
}
}