文件记录-通过定时任务修改记录状态
This commit is contained in:
@@ -65,7 +65,7 @@ rocketmq:
|
|||||||
xxl:
|
xxl:
|
||||||
job:
|
job:
|
||||||
admin:
|
admin:
|
||||||
addresses: http://172.16.46.63:30082/xxl-job-admin # 调度中心部署跟地址
|
addresses: http://192.168.26.116:888/xxl-job-admin # 调度中心部署跟地址
|
||||||
|
|
||||||
# Lock4j 配置项
|
# Lock4j 配置项
|
||||||
lock4j:
|
lock4j:
|
||||||
|
|||||||
@@ -97,7 +97,8 @@ easy-trans:
|
|||||||
xxl:
|
xxl:
|
||||||
job:
|
job:
|
||||||
executor:
|
executor:
|
||||||
appname: ${spring.application.name} # 执行器 AppName
|
# appname: ${spring.application.name} # 执行器 AppName
|
||||||
|
appname: xxl-job-executor-sample # 执行器 AppName
|
||||||
logpath: ${user.home}/logs/xxl-job/${spring.application.name} # 执行器运行日志文件存储磁盘路径
|
logpath: ${user.home}/logs/xxl-job/${spring.application.name} # 执行器运行日志文件存储磁盘路径
|
||||||
accessToken: default_token # 执行器通讯TOKEN
|
accessToken: default_token # 执行器通讯TOKEN
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.zt.plat.module.qms.resource.record.controller.admin.recordrecord;
|
package com.zt.plat.module.qms.resource.record.controller.admin.recordrecord;
|
||||||
|
|
||||||
import com.zt.plat.framework.datapermission.core.annotation.DeptDataPermissionIgnore;
|
import com.zt.plat.framework.datapermission.core.annotation.DeptDataPermissionIgnore;
|
||||||
|
import com.zt.plat.framework.security.core.LoginUser;
|
||||||
|
import com.zt.plat.framework.security.core.util.SecurityFrameworkUtils;
|
||||||
import com.zt.plat.module.qms.common.service.BusinessFileService;
|
import com.zt.plat.module.qms.common.service.BusinessFileService;
|
||||||
import com.zt.plat.module.qms.resource.clientManage.controller.vo.VersionManagementRespVO;
|
import com.zt.plat.module.qms.resource.clientManage.controller.vo.VersionManagementRespVO;
|
||||||
import com.zt.plat.module.qms.resource.record.constant.RecordConstants;
|
import com.zt.plat.module.qms.resource.record.constant.RecordConstants;
|
||||||
@@ -14,6 +16,9 @@ import com.zt.plat.module.qms.resource.record.controller.admin.recordrecord.vo.R
|
|||||||
import com.zt.plat.module.qms.resource.record.dal.dataobject.recordpermission.RecordPermissionDO;
|
import com.zt.plat.module.qms.resource.record.dal.dataobject.recordpermission.RecordPermissionDO;
|
||||||
import com.zt.plat.module.qms.resource.record.service.recordcategory.RecordCategoryService;
|
import com.zt.plat.module.qms.resource.record.service.recordcategory.RecordCategoryService;
|
||||||
import com.zt.plat.module.qms.resource.record.service.recordpermission.RecordPermissionService;
|
import com.zt.plat.module.qms.resource.record.service.recordpermission.RecordPermissionService;
|
||||||
|
import com.zt.plat.module.system.api.dept.DeptApi;
|
||||||
|
import com.zt.plat.module.system.api.dept.dto.*;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
@@ -42,10 +47,12 @@ import com.zt.plat.framework.excel.core.util.ExcelUtils;
|
|||||||
|
|
||||||
import com.zt.plat.framework.apilog.core.annotation.ApiAccessLog;
|
import com.zt.plat.framework.apilog.core.annotation.ApiAccessLog;
|
||||||
import static com.zt.plat.framework.apilog.core.enums.OperateTypeEnum.*;
|
import static com.zt.plat.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||||
|
import static com.zt.plat.module.qms.enums.ErrorCodeConstants.RECORD_PERMISSION_NOT_ALLOW;
|
||||||
|
|
||||||
import com.zt.plat.module.qms.resource.record.dal.dataobject.recordrecord.RecordRecordDO;
|
import com.zt.plat.module.qms.resource.record.dal.dataobject.recordrecord.RecordRecordDO;
|
||||||
import com.zt.plat.module.qms.resource.record.service.recordrecord.RecordRecordService;
|
import com.zt.plat.module.qms.resource.record.service.recordrecord.RecordRecordService;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Tag(name = "管理后台 - 文件、模板、记录")
|
@Tag(name = "管理后台 - 文件、模板、记录")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/qms/resource/record-record")
|
@RequestMapping("/qms/resource/record-record")
|
||||||
@@ -69,6 +76,43 @@ public class RecordRecordController extends AbstractFileUploadController impleme
|
|||||||
@Resource
|
@Resource
|
||||||
private BusinessFileService businessFileService;
|
private BusinessFileService businessFileService;
|
||||||
|
|
||||||
|
// @Resource
|
||||||
|
// private DeptApi deptApi;
|
||||||
|
|
||||||
|
// @GetMapping("/deptList")
|
||||||
|
// @Operation(summary = "获得文件记录关系")
|
||||||
|
//@PreAuthorize("@ss.hasPermission('qms:record-relation:query')")
|
||||||
|
// public CommonResult<List<DeptRespDTO>> getRecordRelation() {
|
||||||
|
// // 获取当前部门的所有子部门
|
||||||
|
// LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||||
|
// Long visitCompanyId = loginUser.getVisitCompanyId();
|
||||||
|
// log.info("visitCompanyId:{}", visitCompanyId);
|
||||||
|
// Long deptId = loginUser.getVisitDeptId();
|
||||||
|
// DeptListReqDTO dto = new DeptListReqDTO();
|
||||||
|
// List<String> deptIds = new ArrayList<>();
|
||||||
|
// deptIds.add(deptId.toString());
|
||||||
|
// dto.setIds(deptIds);
|
||||||
|
// CommonResult<List<DeptDetailRespDTO>> deptList = deptApi.getDeptList(dto);
|
||||||
|
// log.info("deptList:{}", deptList);
|
||||||
|
// // 获取当前所属公司下面的所有的部门
|
||||||
|
// if (visitCompanyId != null) {
|
||||||
|
//// return deptApi.getChildDeptList(visitCompanyId);
|
||||||
|
// CommonResult<List<DeptSimpleRespDTO>> allCompanyList = deptApi.getAllCompanyList();
|
||||||
|
// log.info("allCompanyList:{}", allCompanyList);
|
||||||
|
// DeptSimpleRespDTO deptSimpleRespDTO = allCompanyList.getData().get(0);
|
||||||
|
// deptSimpleRespDTO.getIsCompany();
|
||||||
|
// log.info("deptSimpleRespDTO:{}", deptSimpleRespDTO);
|
||||||
|
// CommonResult<List<DeptRespDTO>> childDeptList = deptApi.getChildDeptList(deptId);
|
||||||
|
// log.info("childDeptList:{}", childDeptList);
|
||||||
|
// CommonResult<Set<CompanyDeptInfoRespDTO>> companyDeptInfoListByUserId = deptApi.getCompanyDeptInfoListByUserId(loginUser.getId());
|
||||||
|
// log.info("companyDeptInfoListByUserId:{}", companyDeptInfoListByUserId);
|
||||||
|
// return childDeptList;
|
||||||
|
// }
|
||||||
|
// Long visitDeptId = loginUser.getVisitDeptId();
|
||||||
|
// if (visitDeptId == null) return CommonResult.error(RECORD_PERMISSION_NOT_ALLOW.getCode(), "用户部门不存在");
|
||||||
|
// return deptApi.getChildDeptList(visitDeptId);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@Operation(summary = "创建文件、模板、记录->分类明细")
|
@Operation(summary = "创建文件、模板、记录->分类明细")
|
||||||
@@ -151,5 +195,25 @@ public class RecordRecordController extends AbstractFileUploadController impleme
|
|||||||
return success(BeanUtils.toBean(result, RecordRecordRespVO.class));
|
return success(BeanUtils.toBean(result, RecordRecordRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 已由 XXL-Job 定时任务(updateRecordStatusJob)驱动,此接口保留用于手动触发/测试
|
||||||
|
@GetMapping("/timing-updateRecordStatus")
|
||||||
|
@Operation(summary = "定时更新文件、模板、记录状态")
|
||||||
|
//@PreAuthorize("@ss.hasPermission('qms:record-record:update')")
|
||||||
|
public CommonResult<Boolean> timingUpdateRecordStatus() {
|
||||||
|
recordRecordService.updateRecordStatus();
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过定时任务,判断文件是否到期(到期自动作废)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
// 已由 XXL-Job 定时任务(XXX)驱动,此接口保留用于手动触发/测试
|
||||||
|
// @GetMapping("/timing-updateRecordStatus")
|
||||||
|
// @Operation(summary = "定时更新文件、模板、记录状态")
|
||||||
|
// //@PreAuthorize("@ss.hasPermission('qms:record-record:update')")
|
||||||
|
// public CommonResult<Boolean> timingUpdateRecordStatus() {
|
||||||
|
// recordRecordService.updateRecordStatus();
|
||||||
|
// return success(true);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.zt.plat.module.qms.resource.record.job;
|
||||||
|
|
||||||
|
import com.xxl.job.core.context.XxlJobHelper;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
|
import com.zt.plat.module.qms.resource.record.service.recordrecord.RecordRecordService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件记录相关定时任务
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class RecordRecordJob {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RecordRecordService recordRecordService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时更新文件记录生效状态
|
||||||
|
* 检测 effectiveDate <= 当前时间 且 recordStatus != 1 的记录,将其更新为已生效(recordStatus = 1)
|
||||||
|
*
|
||||||
|
* JobHandler 名称: updateRecordStatusJob
|
||||||
|
* 推荐 Cron: 0 0 0 * * ?(每天零点执行)
|
||||||
|
*/
|
||||||
|
@XxlJob("updateRecordStatusJob")
|
||||||
|
public void updateRecordStatusJob() {
|
||||||
|
log.info("[updateRecordStatusJob] 开始执行文件记录生效状态更新任务");
|
||||||
|
try {
|
||||||
|
Integer updateCount = recordRecordService.updateRecordStatus();
|
||||||
|
log.info("[updateRecordStatusJob] 任务执行成功,共更新 {} 条记录", updateCount);
|
||||||
|
XxlJobHelper.handleSuccess(String.format("任务执行成功,共更新 %d 条记录", updateCount));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("[updateRecordStatusJob] 任务执行失败:{}", e.getMessage(), e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -529,7 +529,12 @@ public class RecordApplyServiceImpl implements RecordApplyService, BMPCallbackIn
|
|||||||
throw exception(RECORD_APPLY_NOT_EXISTS);
|
throw exception(RECORD_APPLY_NOT_EXISTS);
|
||||||
RecordCategoryDO category = recordCategoryService.getRecordCategory(Long.valueOf(s));
|
RecordCategoryDO category = recordCategoryService.getRecordCategory(Long.valueOf(s));
|
||||||
String customConfig = category.getCustomConfig();
|
String customConfig = category.getCustomConfig();
|
||||||
if (!ObjectUtils.isEmpty(customConfig)) {
|
if (ObjectUtils.isEmpty(customConfig)) { // 空,直接判断是否到生效日期
|
||||||
|
// 判断是否到生效日期
|
||||||
|
RecordRecordDO effectiveRecordRecordDO = isEffective(recordDO);
|
||||||
|
recordRecordService.updateRecordRecordById(effectiveRecordRecordDO);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
JSONObject jsonObject = JSONObject.parseObject(customConfig);
|
JSONObject jsonObject = JSONObject.parseObject(customConfig);
|
||||||
Integer submitFlag = jsonObject.getInteger("submitFlag");
|
Integer submitFlag = jsonObject.getInteger("submitFlag");
|
||||||
if (submitFlag == 0) {
|
if (submitFlag == 0) {
|
||||||
@@ -542,7 +547,7 @@ public class RecordApplyServiceImpl implements RecordApplyService, BMPCallbackIn
|
|||||||
RecordRecordDO effectiveRecordRecordDO = isEffective(recordDO);
|
RecordRecordDO effectiveRecordRecordDO = isEffective(recordDO);
|
||||||
recordRecordService.updateRecordRecordById(effectiveRecordRecordDO);
|
recordRecordService.updateRecordRecordById(effectiveRecordRecordDO);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -555,9 +560,10 @@ public class RecordApplyServiceImpl implements RecordApplyService, BMPCallbackIn
|
|||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
if (now.isAfter(effectiveDate) || now.isEqual(effectiveDate)) {
|
if (now.isAfter(effectiveDate) || now.isEqual(effectiveDate)) {
|
||||||
recordDO.setRecordStatus(1); // 已生效
|
recordDO.setRecordStatus(1); // 已生效
|
||||||
} else {
|
|
||||||
recordDO.setRecordStatus(3); // 待生效
|
|
||||||
}
|
}
|
||||||
|
// else {
|
||||||
|
// recordDO.setRecordStatus(3); // 待生效
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
return recordDO;
|
return recordDO;
|
||||||
}
|
}
|
||||||
@@ -816,9 +822,10 @@ public class RecordApplyServiceImpl implements RecordApplyService, BMPCallbackIn
|
|||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
if (now.isAfter(effectiveDate) || now.isEqual(effectiveDate)) {
|
if (now.isAfter(effectiveDate) || now.isEqual(effectiveDate)) {
|
||||||
entity.setRecordStatus(1); // 已生效
|
entity.setRecordStatus(1); // 已生效
|
||||||
} else {
|
|
||||||
entity.setRecordStatus(3); // 待生效
|
|
||||||
}
|
}
|
||||||
|
// else {
|
||||||
|
// entity.setRecordStatus(0); // 待生效
|
||||||
|
// }
|
||||||
} else {
|
} else {
|
||||||
entity.setRecordStatus(1); // 默认已生效
|
entity.setRecordStatus(1); // 默认已生效
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,6 +90,13 @@ public interface RecordRecordService {
|
|||||||
|
|
||||||
List<RecordRecordRespVO> getRecordList(RecordRecordPageReqVO pageReqVO);
|
List<RecordRecordRespVO> getRecordList(RecordRecordPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务:将生效日期已到的记录状态更新为已生效(recordStatus = 1)
|
||||||
|
*
|
||||||
|
* @return 更新条数
|
||||||
|
*/
|
||||||
|
Integer updateRecordStatus();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件更改申请流程-- 查询文件记录数据
|
* 文件更改申请流程-- 查询文件记录数据
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
|||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
@@ -33,6 +34,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -452,5 +454,20 @@ public class RecordRecordServiceImpl implements RecordRecordService {
|
|||||||
return recordRecordMapper.selectPage(pageReqVO);
|
return recordRecordMapper.selectPage(pageReqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务:将生效日期已到的记录状态更新为已生效(recordStatus = 1)
|
||||||
|
* 筛选条件:effectiveDate <= 当前时间 且 recordStatus != 1
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Integer updateRecordStatus() {
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
LambdaUpdateWrapper<RecordRecordDO> updateWrapper = Wrappers.lambdaUpdate();
|
||||||
|
updateWrapper.isNotNull(RecordRecordDO::getEffectiveDate)
|
||||||
|
.le(RecordRecordDO::getEffectiveDate, now)
|
||||||
|
.ne(RecordRecordDO::getRecordStatus, 1)
|
||||||
|
.set(RecordRecordDO::getRecordStatus, 1);
|
||||||
|
return recordRecordMapper.update(null, updateWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user