|
@@ -1,6 +1,8 @@
|
|
|
package com.flow.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.flow.common.core.exception.BaseException;
|
|
|
import com.flow.common.core.model.OauthUserDetails;
|
|
|
import com.flow.common.core.util.SecurityContextUtil;
|
|
@@ -9,6 +11,9 @@ import com.flow.common.mybatis.service.impl.BaseServiceImpl;
|
|
|
import com.flow.common.redis.service.RedisService;
|
|
|
import com.flow.dao.FlowDefineDao;
|
|
|
import com.flow.entity.FlowDefine;
|
|
|
+import com.flow.entity.FormModel;
|
|
|
+import com.flow.entity.form.Field;
|
|
|
+import com.flow.entity.form.serial.SerialRule;
|
|
|
import com.flow.entity.node.*;
|
|
|
import com.flow.entity.settings.Settings;
|
|
|
import com.flow.entity.settings.TitleConfig;
|
|
@@ -33,10 +38,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.Calendar;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class FlowDefineServiceImpl extends BaseServiceImpl<FlowDefineDao, FlowDefine> implements FlowDefineService {
|
|
@@ -50,6 +55,8 @@ public class FlowDefineServiceImpl extends BaseServiceImpl<FlowDefineDao, FlowDe
|
|
|
private FlowDefineService _this;
|
|
|
@Autowired
|
|
|
private RedisService<Long> redisService;
|
|
|
+ @Autowired
|
|
|
+ private ObjectMapper objectMapper;
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
@@ -95,15 +102,24 @@ public class FlowDefineServiceImpl extends BaseServiceImpl<FlowDefineDao, FlowDe
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
+ // 生成流水号
|
|
|
+ FormModel formModel = flowDefine.getForm();
|
|
|
+ List<Field> fields = formModel.findByName("SerialNumber");
|
|
|
+ for (Field field : fields) {
|
|
|
+ String value = this.generateSerialNumber(field, flowDefine.getModelId());
|
|
|
+ if (StringUtils.isNotBlank(value)) {
|
|
|
+ values.put(field.getId(), value);
|
|
|
+ }
|
|
|
+ }
|
|
|
// 生成流程实例ID
|
|
|
- String currentDate = DateTimeFormatter.ISO_DATE.format(LocalDate.now());
|
|
|
+ String currentDate = DateTimeFormatter.ofPattern("yyyyMMdd").format(LocalDate.now());
|
|
|
String serialKey = String.format("flow:serial:%s", currentDate);
|
|
|
Long increment = redisService.incr(serialKey, 1L);
|
|
|
if (increment == 1L) {
|
|
|
redisService.expire(serialKey, 60 * 60 * 24L);
|
|
|
}
|
|
|
String serial = String.format("%3s", increment).replace(" ", "0");
|
|
|
- String instanceId = String.format("LF%s%s", currentDate, serial);
|
|
|
+ String instanceId = String.format("fw%s%s", currentDate, serial);
|
|
|
String instanceName = startProcess.getInstanceName();
|
|
|
Settings settings = flowDefine.getSettings();
|
|
|
TitleConfig titleConfig = settings.getTitle();
|
|
@@ -132,6 +148,15 @@ public class FlowDefineServiceImpl extends BaseServiceImpl<FlowDefineDao, FlowDe
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private String generateSerialNumber(Field field, Long modelId) {
|
|
|
+ Map<String, Object> props = field.getProps();
|
|
|
+ Object rules = props.get("rules");
|
|
|
+ List<SerialRule> serialRules = objectMapper.convertValue(rules, new TypeReference<List<SerialRule>>() {
|
|
|
+ });
|
|
|
+ String key = String.format("%s:%s", modelId, field.getId());
|
|
|
+ return serialRules.stream().map(e->e.generate(key)).collect(Collectors.joining());
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<FlowDefine> list(FlowDefine flowDefine) {
|
|
|
return flowDefineDao.getList(flowDefine);
|