check flowStatus

This commit is contained in:
devezhao 2021-06-01 18:02:44 +08:00
parent 78b260e727
commit 85ea6a75e6

View file

@ -16,6 +16,7 @@ import com.rebuild.core.UserContextHolder;
import com.rebuild.core.configuration.ConfigBean;
import com.rebuild.core.metadata.EntityHelper;
import com.rebuild.core.privileges.OperationDeniedException;
import com.rebuild.core.service.DataSpecificationException;
import com.rebuild.core.service.notification.Message;
import com.rebuild.core.service.notification.MessageBuilder;
import com.rebuild.core.support.i18n.Language;
@ -50,9 +51,16 @@ public class ProjectTaskService extends BaseTaskService {
final ID user = UserContextHolder.getUser();
checkInMembers(user, record.getID("projectId"));
record.setLong("taskNumber", getNextTaskNumber(record.getID("projectId")));
applyFlowStatue(record);
record.setInt("seq", getNextSeqViaMidValue(record.getID("projectPlanId")));
ID projectId = record.getID("projectId");
ID projectPlanId = record.getID("projectPlanId");
ConfigBean p = ProjectManager.instance.getPlanOfProject(projectPlanId, projectId);
if (p.getInteger("flowStatus") == ProjectPlanConfigService.FLOW_STATUS_PROCESSING) {
throw new DataSpecificationException(Language.L("该任务面板不可新建任务"));
}
record.setLong("taskNumber", getNextTaskNumber(projectId));
applyFlowStatus(record);
record.setInt("seq", getNextSeqViaMidValue(projectPlanId));
record = super.create(record);
@ -68,17 +76,26 @@ public class ProjectTaskService extends BaseTaskService {
checkInMembers(user, record.getPrimary());
// 自动完成
int flowStatus = applyFlowStatue(record);
int newFlowStatus = applyFlowStatus(record);
if (flowStatus == ProjectPlanConfigService.FLOW_STATUS_END) {
if (newFlowStatus == ProjectPlanConfigService.FLOW_STATUS_END) {
record.setDate("endTime", CalendarUtils.now());
} else if (record.hasValue("status")) {
int status = record.getInt("status");
// 处理完成时间
if (status == 0) {
record.setNull("endTime");
record.setInt("seq", getSeqInStatus(record.getPrimary(), false));
} else {
// 检查工作流
Object[] flowStatus = Application.getQueryFactory()
.uniqueNoFilter(record.getPrimary(), "projectPlanId.flowStatus");
if ((int) flowStatus[0] == ProjectPlanConfigService.FLOW_STATUS_PROCESSING) {
throw new DataSpecificationException(Language.L("该任务面板不可完成任务"));
}
record.setDate("endTime", CalendarUtils.now());
record.setInt("seq", getSeqInStatus(record.getPrimary(), true));
}
@ -162,7 +179,7 @@ public class ProjectTaskService extends BaseTaskService {
*
* @param newOrUpdate
*/
private int applyFlowStatue(Record newOrUpdate) {
private int applyFlowStatus(Record newOrUpdate) {
if (newOrUpdate.hasValue("projectPlanId")) {
ConfigBean c = ProjectManager.instance.getPlanOfProject(
newOrUpdate.getID("projectPlanId"), newOrUpdate.getID("projectId"));
@ -178,11 +195,10 @@ public class ProjectTaskService extends BaseTaskService {
return -1;
}
/**
* @param taskId
*/
private void sendNotification(ID taskId) {
Object[] task = Application.getQueryFactory().uniqueNoFilter(taskId, "executor", "taskName");
if (task[0] == null) return;
String msg = Language.L("有一个新任务分派给你") + " \n> " + task[1];
Application.getNotifications().send(
MessageBuilder.createMessage((ID) task[0], msg, Message.TYPE_PROJECT, taskId));