TaskOperationServiceImpl.java
4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.topdraw.business.process.service.impl;
import com.topdraw.business.module.task.attribute.domain.TaskAttr;
import com.topdraw.business.module.task.attribute.service.TaskAttrService;
import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO;
import com.topdraw.business.module.task.domain.Task;
import com.topdraw.business.module.task.service.TaskService;
import com.topdraw.business.module.task.service.dto.TaskDTO;
import com.topdraw.business.module.task.template.service.dto.TaskTemplateDTO;
import com.topdraw.business.process.service.TaskOperationService;
import com.topdraw.business.process.service.TaskTemplateOperationService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Objects;
/**
* @author :
* @description:
* @function :
* @date :Created in 2022/4/25 15:48
* @version: :
* @modified By:
* @since : modified in 2022/4/25 15:48
*/
@Service
@Slf4j
public class TaskOperationServiceImpl implements TaskOperationService {
@Autowired
private TaskService taskService;
@Autowired
private TaskAttrService taskAttrService;
@Autowired
private TaskTemplateOperationService taskTemplateOperationService;
public void asyncCreateTask(Task task) {
String taskTemplateCode = task.getTaskTemplateCode();
TaskTemplateDTO taskTemplateDTO = this.taskTemplateOperationService.findByCode(taskTemplateCode);
Long id = taskTemplateDTO.getId();
task.setTaskTemplateId(id);
this.create(task);
}
private void create(Task task) {
String code = task.getCode();
TaskDTO taskDTO = this.findByCode(code);
if (Objects.isNull(taskDTO.getId())) {
TaskDTO taskDTO_ = this.taskService.create(task);
/*if (Objects.nonNull(taskDTO_.getId())) {
task.setId(taskDTO_.getId());
this.createTaskAttr(task);
}*/
}
}
/**
*
* @param task_
*/
private void createTaskAttr(Task task_) {
TaskAttr taskAttr = new TaskAttr();
taskAttr.setAttrStr(task_.getAttr());
taskAttr.setTaskId(task_.getId());
this.taskAttrService.create(taskAttr);
}
public void asyncUpdateTask(Task task) {
String code = task.getCode();
TaskDTO taskDTO = this.findByCode(code);
if (Objects.nonNull(taskDTO.getId())) {
Task task1 = new Task();
BeanUtils.copyProperties(taskDTO, task1);
Long id = taskDTO.getId();
task1.setId(id);
String taskTemplateCode = task.getTaskTemplateCode();
if (StringUtils.isNotBlank(taskTemplateCode)) {
TaskTemplateDTO taskTemplateDTO = this.taskTemplateOperationService.findByCode(taskTemplateCode);
Long templateId = taskTemplateDTO.getId();
task1.setTaskTemplateId(templateId);
}
task1.copy(task);
TaskDTO update = this.update(task1);
/*if (Objects.nonNull(update)) {
this.updateTaskAttr(task);
}*/
}
}
/**
*
* @param task_
*/
private void updateTaskAttr(Task task_) {
TaskAttrDTO taskAttrDTO = this.findTaskAttrByTaskId(task_.getId());
if (Objects.nonNull(taskAttrDTO.getId())) {
TaskAttr taskAttr = new TaskAttr();
BeanUtils.copyProperties(taskAttrDTO, taskAttr);
taskAttr.setAttrStr(task_.getAttr());
this.taskAttrService.update(taskAttr);
}
}
private TaskAttrDTO findTaskAttrByTaskId(Long taskId) {
return this.taskAttrService.findByTaskId(taskId);
}
private TaskDTO update(Task task) {
return this.taskService.update(task);
}
public void asyncDeleteTask(Task task) {
String code = task.getCode();
TaskDTO taskDTO = this.findByCode(code);
if (Objects.nonNull(taskDTO.getId())) {
Long id = taskDTO.getId();
task.setId(id);
this.delete(task);
}
}
private void delete(Task task) {
this.taskService.delete(task);
}
private TaskDTO findByCode(String code){
return this.taskService.findByCode(code);
}
}