feat(oa): 添加日记账批量更新接口并优化流程实例启动逻辑

- 在 IOaJournalAccountService 中添加 batchUpdate 方法
- 在 OaJournalAccountBo 中添加 journalIds 字段用于批量更新
- 实现 OaJournalAccountController 中的 batchUpdate 接口
- 在 OaJournalAccountServiceImpl 中实现 batchUpdate 方法,用于批量更新日记账的 batchId
- 优化 WfProcessServiceImpl 中的 startProcess
This commit is contained in:
2025-09-15 15:29:51 +08:00
parent 7b74ae82a7
commit 743c3133a6
5 changed files with 117 additions and 1 deletions

View File

@@ -37,7 +37,12 @@ import com.ruoyi.common.core.page.TableDataInfo;
public class OaJournalAccountController extends BaseController {
private final IOaJournalAccountService iOaJournalAccountService;
//需要一个接口用来批量修改batch_id字段传入一个batch_id和多个journal_ids
@Log(title = "日记账绑定封账批次未封账数据batch_id为NULL", businessType = BusinessType.UPDATE)
@PutMapping("/batchUpdate")
public R<Void> batchUpdate(@RequestBody OaJournalAccountBo bo) {
return toAjax(iOaJournalAccountService.batchUpdate(bo));
}
/**
* 查询日记账绑定封账批次未封账数据batch_id为NULL列表
*/

View File

@@ -10,6 +10,8 @@ import java.util.Date;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.domain.BaseEntity;
@@ -73,6 +75,8 @@ public class OaJournalAccountBo extends BaseEntity {
* 备注
*/
private String remark;
//需要批量修改batchId的日记账记录ID
private List<Long> journalIds;
}

View File

@@ -46,4 +46,6 @@ public interface IOaJournalAccountService {
* 校验并批量删除日记账绑定封账批次未封账数据batch_id为NULL信息
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
int batchUpdate(OaJournalAccountBo bo);
}

View File

@@ -15,6 +15,7 @@ import com.ruoyi.oa.domain.vo.OaJournalAccountVo;
import com.ruoyi.oa.domain.OaJournalAccount;
import com.ruoyi.oa.mapper.OaJournalAccountMapper;
import com.ruoyi.oa.service.IOaJournalAccountService;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
@@ -131,4 +132,38 @@ public class OaJournalAccountServiceImpl implements IOaJournalAccountService {
}
return baseMapper.deleteBatchIds(ids) > 0;
}
@Override
@Transactional
public int batchUpdate(OaJournalAccountBo bo) {
// 参数校验
if (bo.getJournalIds() == null || bo.getJournalIds().isEmpty()) {
return 0;
}
if (bo.getBatchId() == null) {
throw new ServiceException("批次ID不能为空");
}
int count = 0;
// 循环遍历list数组然后修改batchId
for (Long journalId : bo.getJournalIds()) {
// 检查记录是否存在且未封账
OaJournalAccount existing = baseMapper.selectById(journalId);
if (existing == null) {
throw new ServiceException("记录不存在ID: " + journalId);
}
if (existing.getBatchId() != null) {
throw new ServiceException("记录已封账不能重复封账ID: " + journalId);
}
OaJournalAccount oaJournalAccount = new OaJournalAccount();
oaJournalAccount.setJournalId(journalId);
oaJournalAccount.setBatchId(bo.getBatchId());
count += baseMapper.updateById(oaJournalAccount);
}
return count;
}
}

View File

@@ -853,12 +853,82 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
variables.put(ProcessConstants.PROCESS_STATUS_KEY, ProcessStatus.RUNNING.getStatus());
// 发起流程实例
ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDef.getId(), variables);
// 如果包含审批人信息,则设置下一个任务的审批人
try {
if (variables.containsKey("flowable") && variables.get("flowable") != null) {
Object flowableObj = variables.get("flowable");
if (flowableObj instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, Object> flowable = (Map<String, Object>) flowableObj;
if (flowable.containsKey("candidateUsers")) {
Object candidateUsersObj = flowable.get("candidateUsers");
if (candidateUsersObj != null) {
String candidateUsers = candidateUsersObj.toString();
if (StringUtils.isNotBlank(candidateUsers)) {
// 获取流程模型
BpmnModel bpmnModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId());
// 设置下一个任务的审批人
this.assignNextUsers(bpmnModel, processInstance.getProcessInstanceId(), candidateUsers);
}
}
}
}
}
} catch (Exception e) {
// 记录异常但不影响流程启动
e.printStackTrace();
}
// 第一个用户任务为发起人,则自动完成任务
wfTaskService.startFirstTask(processInstance, variables);
return processInstance.getProcessInstanceId();
}
/**
* 设置下一个任务的审批人
*
* @param bpmnModel 流程模型
* @param processInstanceId 流程实例ID
* @param candidateUsers 审批人字符串
*/
private void assignNextUsers(BpmnModel bpmnModel, String processInstanceId, String candidateUsers) {
if (StringUtils.isBlank(candidateUsers)) {
return;
}
try {
// 获取当前流程实例的所有任务
List<Task> tasks = taskService.createTaskQuery()
.processInstanceId(processInstanceId)
.list();
if (CollUtil.isEmpty(tasks)) {
return;
}
// 解析审批人字符串格式可能是userId1,userId2,userId3
String[] userIds = candidateUsers.split(",");
// 为每个任务直接指定实际办理人
for (Task task : tasks) {
// 如果只有一个审批人,直接设置为实际办理人
if (userIds.length == 1 && StringUtils.isNotBlank(userIds[0])) {
taskService.setAssignee(task.getId(), userIds[0].trim());
} else if (userIds.length > 1) {
// 如果有多个审批人,设置第一个为实际办理人,其他为候选人
// 或者根据业务需求,可以只设置候选人让用户自己认领
taskService.setAssignee(task.getId(), userIds[0].trim());
// 如果需要其他人也能看到任务,可以添加候选人
for (int i = 1; i < userIds.length; i++) {
if (StringUtils.isNotBlank(userIds[i])) {
taskService.addCandidateUser(task.getId(), userIds[i].trim());
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 获取流程变量
*