From 72af3aa203ea5069d2ec81c0202d790bd8a595c8 Mon Sep 17 00:00:00 2001 From: wangna0328 <3402195679@qq.com> Date: Wed, 30 Jul 2025 16:17:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=B6=E5=BA=A6=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E7=AE=A1=E7=90=86=E9=A1=B5=E9=9D=A2=EF=BC=8C=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=96=B9=E6=B3=95=E5=B7=B2=E9=80=9A=E8=BF=87=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../znpt/domain/dto/RegulationConfirmDTO.java | 6 +- .../entity/RegulationConfirmationEntity.java | 34 +-- .../znpt/domain/entity/RegulationEntity.java | 10 - .../RegulationConfirmationService.java | 56 +---- .../dite/znpt/service/RegulationService.java | 11 +- .../RegulationConfirmationServiceImpl.java | 170 +-------------- .../service/impl/RegulationServiceImpl.java | 87 ++++---- doc/regulation_api_test.md | 202 +----------------- doc/regulation_tables.sql | 67 +++--- doc/regulation_test_data.sql | 18 +- .../web/controller/RegulationController.java | 11 +- 11 files changed, 88 insertions(+), 584 deletions(-) diff --git a/core/src/main/java/com/dite/znpt/domain/dto/RegulationConfirmDTO.java b/core/src/main/java/com/dite/znpt/domain/dto/RegulationConfirmDTO.java index 3cd0cd2..63b99e1 100644 --- a/core/src/main/java/com/dite/znpt/domain/dto/RegulationConfirmDTO.java +++ b/core/src/main/java/com/dite/znpt/domain/dto/RegulationConfirmDTO.java @@ -1,6 +1,8 @@ package com.dite.znpt.domain.dto; import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.AllArgsConstructor; /** * 制度确认DTO @@ -8,7 +10,9 @@ import lombok.Data; * @date 2025/07/29 */ @Data +@NoArgsConstructor +@AllArgsConstructor public class RegulationConfirmDTO { - private Boolean agreeTerms; // 是否同意条款 + private Boolean agreeTerms = true; // 是否同意条款,默认为true } \ No newline at end of file diff --git a/core/src/main/java/com/dite/znpt/domain/entity/RegulationConfirmationEntity.java b/core/src/main/java/com/dite/znpt/domain/entity/RegulationConfirmationEntity.java index 1787517..aad8e25 100644 --- a/core/src/main/java/com/dite/znpt/domain/entity/RegulationConfirmationEntity.java +++ b/core/src/main/java/com/dite/znpt/domain/entity/RegulationConfirmationEntity.java @@ -20,7 +20,7 @@ import java.time.LocalDateTime; @EqualsAndHashCode(callSuper = false) @TableName("regulation_confirmation") @ApiModel(value="RegulationConfirmationEntity对象", description="制度确认") -public class RegulationConfirmationEntity extends AuditableEntity implements Serializable { +public class RegulationConfirmationEntity implements Serializable { private static final long serialVersionUID = 1L; @@ -34,11 +34,6 @@ public class RegulationConfirmationEntity extends AuditableEntity implements Ser @TableField("regulation_id") private String regulationId; - @ExcelProperty("制度标题") - @ApiModelProperty("制度标题") - @TableField("regulation_title") - private String regulationTitle; - @ExcelProperty("确认人ID") @ApiModelProperty("确认人ID") @TableField("confirmer_id") @@ -55,7 +50,7 @@ public class RegulationConfirmationEntity extends AuditableEntity implements Ser private String confirmerDept; @ExcelProperty("确认状态") - @ApiModelProperty("确认状态:PENDING-待确认,CONFIRMED-已确认,DECLINED-已拒绝") + @ApiModelProperty("确认状态:CONFIRMED-已确认") @TableField("status") private String status; @@ -64,31 +59,6 @@ public class RegulationConfirmationEntity extends AuditableEntity implements Ser @TableField("confirm_time") private LocalDateTime confirmTime; - @ExcelProperty("确认意见") - @ApiModelProperty("确认意见") - @TableField("confirm_comment") - private String confirmComment; - - @ExcelProperty("阅读时长(秒)") - @ApiModelProperty("阅读时长(秒)") - @TableField("read_duration") - private Integer readDuration; - - @ExcelProperty("IP地址") - @ApiModelProperty("IP地址") - @TableField("ip_address") - private String ipAddress; - - @ExcelProperty("用户代理") - @ApiModelProperty("用户代理") - @TableField("user_agent") - private String userAgent; - - @ExcelProperty("备注") - @ApiModelProperty("备注") - @TableField("remark") - private String remark; - @ExcelProperty("删除标志(0代表存在,1代表删除)") @ApiModelProperty("删除标志(0代表存在,1代表删除)") @TableField("del_flag") diff --git a/core/src/main/java/com/dite/znpt/domain/entity/RegulationEntity.java b/core/src/main/java/com/dite/znpt/domain/entity/RegulationEntity.java index 8d305b4..00f93ac 100644 --- a/core/src/main/java/com/dite/znpt/domain/entity/RegulationEntity.java +++ b/core/src/main/java/com/dite/znpt/domain/entity/RegulationEntity.java @@ -49,16 +49,6 @@ public class RegulationEntity extends AuditableEntity implements Serializable { @TableField("status") private String status; - @ExcelProperty("发布人ID") - @ApiModelProperty("发布人ID") - @TableField("publisher_id") - private String publisherId; - - @ExcelProperty("发布人姓名") - @ApiModelProperty("发布人姓名") - @TableField("publisher_name") - private String publisherName; - @ExcelProperty("发布时间") @ApiModelProperty("发布时间") @TableField("publish_time") diff --git a/core/src/main/java/com/dite/znpt/service/RegulationConfirmationService.java b/core/src/main/java/com/dite/znpt/service/RegulationConfirmationService.java index 1654993..f92847b 100644 --- a/core/src/main/java/com/dite/znpt/service/RegulationConfirmationService.java +++ b/core/src/main/java/com/dite/znpt/service/RegulationConfirmationService.java @@ -2,7 +2,6 @@ package com.dite.znpt.service; import com.baomidou.mybatisplus.extension.service.IService; import com.dite.znpt.domain.entity.RegulationConfirmationEntity; -import com.dite.znpt.domain.Result; /** * @author wangna @@ -10,57 +9,6 @@ import com.dite.znpt.domain.Result; * @Description: 制度确认Service接口 */ public interface RegulationConfirmationService extends IService { - - /** - * 确认制度 - * @param confirmation 确认信息 - * @return 结果 - */ - Result confirmRegulation(RegulationConfirmationEntity confirmation); - - /** - * 获取确认记录 - * @param regulationId 制度ID - * @return 结果 - */ - Result getConfirmationRecords(String regulationId); - - /** - * 获取用户确认记录 - * @param confirmerId 确认人ID - * @param regulationId 制度ID - * @return 结果 - */ - Result getUserConfirmationRecord(String confirmerId, String regulationId); - - /** - * 取消确认 - * @param confirmationId 确认ID - * @return 结果 - */ - Result cancelConfirmation(String confirmationId); - - /** - * 获取确认统计 - * @param regulationId 制度ID - * @return 结果 - */ - Result getConfirmationStatistics(String regulationId); - - /** - * 批量创建确认任务 - * @param regulationId 制度ID - * @param userIds 用户ID列表 - * @return 结果 - */ - Result createConfirmationTasks(String regulationId, String[] userIds); - - /** - * 获取待确认列表 - * @param confirmerId 确认人ID - * @param page 页码 - * @param pageSize 页大小 - * @return 结果 - */ - Result getPendingConfirmations(String confirmerId, Integer page, Integer pageSize); + // 继承自IService的方法已经足够使用 + // 包括:save, update, remove, list, page, lambdaQuery等 } \ No newline at end of file diff --git a/core/src/main/java/com/dite/znpt/service/RegulationService.java b/core/src/main/java/com/dite/znpt/service/RegulationService.java index 5ad0ae0..27a9f90 100644 --- a/core/src/main/java/com/dite/znpt/service/RegulationService.java +++ b/core/src/main/java/com/dite/znpt/service/RegulationService.java @@ -29,13 +29,6 @@ public interface RegulationService extends IService { */ Result createRegulationProposal(RegulationEntity regulation); - /** - * 更新制度提案 - * @param regulation 制度信息 - * @return 结果 - */ - Result updateRegulationProposal(RegulationEntity regulation); - /** * 获取制度详情 * @param regulationId 制度ID @@ -46,9 +39,7 @@ public interface RegulationService extends IService { /** * 确认制度知晓 * @param regulationId 制度ID - * @param confirm 确认信息 * @return 结果 */ - Result confirmRegulation(String regulationId, RegulationConfirmDTO confirm); - + Result confirmRegulation(String regulationId); } \ No newline at end of file diff --git a/core/src/main/java/com/dite/znpt/service/impl/RegulationConfirmationServiceImpl.java b/core/src/main/java/com/dite/znpt/service/impl/RegulationConfirmationServiceImpl.java index bf5385a..c153e8f 100644 --- a/core/src/main/java/com/dite/znpt/service/impl/RegulationConfirmationServiceImpl.java +++ b/core/src/main/java/com/dite/znpt/service/impl/RegulationConfirmationServiceImpl.java @@ -1,19 +1,10 @@ package com.dite.znpt.service.impl; -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.RegulationConfirmationEntity; import com.dite.znpt.mapper.RegulationConfirmationMapper; import com.dite.znpt.service.RegulationConfirmationService; -import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.time.LocalDateTime; -import java.util.List; -import java.util.Map; /** * @author wangna @@ -21,164 +12,7 @@ import java.util.Map; * @Description: 制度确认服务实现类 */ @Service -@RequiredArgsConstructor public class RegulationConfirmationServiceImpl extends ServiceImpl implements RegulationConfirmationService { - - @Override - @Transactional(rollbackFor = Exception.class) - public Result confirmRegulation(RegulationConfirmationEntity confirmation) { - try { - // 检查是否已经确认 - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(RegulationConfirmationEntity::getConfirmerId, confirmation.getConfirmerId()) - .eq(RegulationConfirmationEntity::getRegulationId, confirmation.getRegulationId()) - .eq(RegulationConfirmationEntity::getDelFlag, "0"); - - RegulationConfirmationEntity existingConfirmation = this.getOne(wrapper); - if (existingConfirmation != null) { - return Result.error("您已经确认过该制度"); - } - - confirmation.setConfirmTime(LocalDateTime.now()); - confirmation.setDelFlag("0"); - this.save(confirmation); - return Result.ok("制度确认成功"); - } catch (Exception e) { - return Result.error("制度确认失败:" + e.getMessage()); - } - } - - @Override - public Result getConfirmationRecords(String regulationId) { - try { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(RegulationConfirmationEntity::getRegulationId, regulationId) - .eq(RegulationConfirmationEntity::getDelFlag, "0") - .orderByDesc(RegulationConfirmationEntity::getConfirmTime); - - List confirmations = this.list(wrapper); - return Result.ok(confirmations); - } catch (Exception e) { - return Result.error("获取确认记录失败:" + e.getMessage()); - } - } - - @Override - public Result getUserConfirmationRecord(String confirmerId, String regulationId) { - try { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(RegulationConfirmationEntity::getConfirmerId, confirmerId) - .eq(RegulationConfirmationEntity::getRegulationId, regulationId) - .eq(RegulationConfirmationEntity::getDelFlag, "0"); - - RegulationConfirmationEntity confirmation = this.getOne(wrapper); - return Result.ok(confirmation); - } catch (Exception e) { - return Result.error("获取用户确认记录失败:" + e.getMessage()); - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public Result cancelConfirmation(String confirmationId) { - try { - RegulationConfirmationEntity confirmation = this.getById(confirmationId); - if (confirmation == null) { - return Result.error("确认记录不存在"); - } - - confirmation.setDelFlag("1"); - this.updateById(confirmation); - return Result.ok("确认取消成功"); - } catch (Exception e) { - return Result.error("确认取消失败:" + e.getMessage()); - } - } - - @Override - public Result getConfirmationStatistics(String regulationId) { - try { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(RegulationConfirmationEntity::getRegulationId, regulationId) - .eq(RegulationConfirmationEntity::getDelFlag, "0"); - - List confirmations = this.list(wrapper); - - int confirmedCount = 0; - int declinedCount = 0; - int pendingCount = 0; - - for (RegulationConfirmationEntity confirmation : confirmations) { - switch (confirmation.getStatus()) { - case "CONFIRMED": - confirmedCount++; - break; - case "DECLINED": - declinedCount++; - break; - case "PENDING": - pendingCount++; - break; - } - } - - int totalConfirmations = confirmedCount + declinedCount + pendingCount; - double confirmRate = totalConfirmations > 0 ? (double) confirmedCount / totalConfirmations * 100 : 0; - - return Result.okM(Map.of( - "regulationId", regulationId, - "totalConfirmations", totalConfirmations, - "confirmedCount", confirmedCount, - "declinedCount", declinedCount, - "pendingCount", pendingCount, - "confirmRate", confirmRate - ), "确认统计"); - } catch (Exception e) { - return Result.error("获取确认统计失败:" + e.getMessage()); - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public Result createConfirmationTasks(String regulationId, String[] userIds) { - try { - for (String userId : userIds) { - // 检查是否已经存在确认任务 - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(RegulationConfirmationEntity::getConfirmerId, userId) - .eq(RegulationConfirmationEntity::getRegulationId, regulationId) - .eq(RegulationConfirmationEntity::getDelFlag, "0"); - - RegulationConfirmationEntity existingTask = this.getOne(wrapper); - if (existingTask == null) { - RegulationConfirmationEntity task = new RegulationConfirmationEntity(); - task.setRegulationId(regulationId); - task.setConfirmerId(userId); - task.setStatus("PENDING"); - task.setDelFlag("0"); - this.save(task); - } - } - return Result.okM("确认任务创建成功"); - } catch (Exception e) { - return Result.error("确认任务创建失败:" + e.getMessage()); - } - } - - @Override - public Result getPendingConfirmations(String confirmerId, Integer page, Integer pageSize) { - try { - Page pageParam = new Page<>(page, pageSize); - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(RegulationConfirmationEntity::getConfirmerId, confirmerId) - .eq(RegulationConfirmationEntity::getStatus, "PENDING") - .eq(RegulationConfirmationEntity::getDelFlag, "0") - .orderByDesc(RegulationConfirmationEntity::getCreateTime); - - Page result = this.page(pageParam, wrapper); - return Result.ok(result); - } catch (Exception e) { - return Result.error("获取待确认列表失败:" + e.getMessage()); - } - } + // 继承自ServiceImpl的方法已经足够使用 + // 包括:save, update, remove, list, page, lambdaQuery等 } \ No newline at end of file diff --git a/core/src/main/java/com/dite/znpt/service/impl/RegulationServiceImpl.java b/core/src/main/java/com/dite/znpt/service/impl/RegulationServiceImpl.java index 868576a..82d1442 100644 --- a/core/src/main/java/com/dite/znpt/service/impl/RegulationServiceImpl.java +++ b/core/src/main/java/com/dite/znpt/service/impl/RegulationServiceImpl.java @@ -1,5 +1,6 @@ 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; @@ -12,15 +13,10 @@ import com.dite.znpt.mapper.RegulationMapper; import com.dite.znpt.service.RegulationService; import com.dite.znpt.service.RegulationConfirmationService; import com.dite.znpt.service.UserService; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.dite.znpt.mapper.RegulationDraftMapper; -import com.dite.znpt.domain.entity.RegulationDraftEntity; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.beans.factory.annotation.Autowired; -import java.util.List; import java.time.LocalDateTime; /** @@ -34,8 +30,10 @@ public class RegulationServiceImpl extends ServiceImpl drafts = regulationDraftMapper.selectList( - new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper() - .eq(RegulationDraftEntity::getStatus, "DRAFT") - .le(RegulationDraftEntity::getCreateTime, tenDaysAgo) - ); - for (RegulationDraftEntity draft : drafts) { + + // 查询需要自动发布的制度(状态为DRAFT且创建时间超过10天) + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(RegulationEntity::getStatus, "DRAFT"); + wrapper.le(RegulationEntity::getCreateTime, tenDaysAgo); + wrapper.eq(RegulationEntity::getDelFlag, "0"); + + java.util.List drafts = this.list(wrapper); + + for (RegulationEntity draft : drafts) { + // 更新制度状态和发布信息 draft.setStatus("PUBLISHED"); - regulationDraftMapper.updateById(draft); + draft.setPublishTime(LocalDateTime.now()); + draft.setEffectiveTime(LocalDateTime.now()); // 设置生效时间为当前时间 + draft.setUpdateTime(LocalDateTime.now()); + draft.setUpdateBy("系统自动发布"); + + this.updateById(draft); + } + + if (!drafts.isEmpty()) { + System.out.println("自动发布完成,共发布 " + drafts.size() + " 个制度"); } - } - - public RegulationServiceImpl(RegulationConfirmationService regulationConfirmationService, UserService userService) { - this.regulationConfirmationService = regulationConfirmationService; - this.userService = userService; } @Override @@ -78,7 +85,7 @@ public class RegulationServiceImpl extends ServiceImpl confirmedIds = regulationConfirmationService.lambdaQuery() .eq(RegulationConfirmationEntity::getConfirmerId, userId) .eq(RegulationConfirmationEntity::getStatus, "CONFIRMED") @@ -105,9 +112,12 @@ public class RegulationServiceImpl extends ServiceImpl