|
@@ -7,7 +7,9 @@ import com.qmth.sop.business.entity.TBSopInfo;
|
|
|
import com.qmth.sop.business.entity.TFCustomFlow;
|
|
|
import com.qmth.sop.business.mapper.TBSopInfoMapper;
|
|
|
import com.qmth.sop.business.service.TBSopInfoService;
|
|
|
+import com.qmth.sop.common.contant.SystemConstant;
|
|
|
import com.qmth.sop.common.enums.WidgetCodeEnum;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
@@ -45,36 +47,82 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
|
|
|
* 保存动态sop信息
|
|
|
*
|
|
|
* @param tfCustomFlow
|
|
|
+ * @param code
|
|
|
* @param flowId
|
|
|
* @param flowTaskResult
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public Boolean saveDynamicSop(TFCustomFlow tfCustomFlow, Long flowId, FlowTaskResult flowTaskResult) {
|
|
|
+ public Boolean saveDynamicSop(TFCustomFlow tfCustomFlow, String code, Long flowId, FlowTaskResult flowTaskResult) {
|
|
|
String tableName = tfCustomFlow.getType().getTableName() + "_" + tfCustomFlow.getVersion();
|
|
|
List<FlowFormWidgetResult> flowFormWidgetResultList = flowTaskResult.getFormProperty();
|
|
|
- List<Map<String, String>> fieldValue = new ArrayList<>(flowFormWidgetResultList.size());
|
|
|
- StringJoiner stringJoiner = new StringJoiner(",");
|
|
|
+ Map<String, String> formFieldMap = new HashMap<>(flowFormWidgetResultList.size());
|
|
|
for (FlowFormWidgetResult f : flowFormWidgetResultList) {
|
|
|
if (f.getCode() != WidgetCodeEnum.FORM_GROUP_TITLE && f.getCode() != WidgetCodeEnum.ONLE_TITLE
|
|
|
&& f.getCode() != WidgetCodeEnum.BUTTON && f.getCode() != WidgetCodeEnum.IMG
|
|
|
&& f.getCode() != WidgetCodeEnum.LABEL && f.getCode() != WidgetCodeEnum.SIGN
|
|
|
&& f.getCode() != WidgetCodeEnum.OTHER) {
|
|
|
- Map<String, String> map = new LinkedHashMap<>();
|
|
|
- map.put(f.getFormId(), f.getValue());
|
|
|
- fieldValue.add(map);
|
|
|
- stringJoiner.add(f.getFormId());
|
|
|
+ if (Objects.nonNull(f.getValue()) && f.getValue().startsWith("[") && f.getValue().endsWith("]")) {
|
|
|
+ f.setValue(f.getValue().replaceAll("\\[", "").replaceAll("\\]", ""));
|
|
|
+ formFieldMap.put(f.getFormId(), StringUtils.join(Arrays.asList(f.getValue()), SystemConstant.LIST_JOIN_SPLIT));
|
|
|
+ } else {
|
|
|
+ formFieldMap.put(f.getFormId(), f.getValue());
|
|
|
+ }
|
|
|
+ formFieldMap.put(f.getFormId(), f.getValue());
|
|
|
}
|
|
|
}
|
|
|
//首先查询动态表里是否有当前表单的数据,没有插入,有则更新
|
|
|
- List<Map> list = this.selectDynamicSop(tableName, tfCustomFlow.getFlowDeploymentId(), flowId, stringJoiner.toString());
|
|
|
- if (CollectionUtils.isEmpty(list)) {//插入操作
|
|
|
-// tbSopInfoMapper.saveDynamicSop();
|
|
|
+ int count = this.selectDynamicSop(tableName, tfCustomFlow.getFlowDeploymentId(), flowId);
|
|
|
+ if (count == 0) {//插入操作
|
|
|
+ //查询所有列
|
|
|
+ List<Map<String, String>> dynamicFieldList = this.baseMapper.selectDynamicSopAll(tableName);
|
|
|
+ Map<String, Object> map = new LinkedHashMap<>();
|
|
|
+ if (!CollectionUtils.isEmpty(dynamicFieldList)) {
|
|
|
+ StringJoiner stringJoinerFieldName = new StringJoiner(",");
|
|
|
+ StringJoiner stringJoinerFieldValue = new StringJoiner(",");
|
|
|
+ for (Map<String, String> m : dynamicFieldList) {
|
|
|
+ for (Map.Entry<String, String> entry : m.entrySet()) {
|
|
|
+ switch (entry.getValue()) {
|
|
|
+ case SystemConstant.TYPE:
|
|
|
+ map.put(entry.getValue(), tfCustomFlow.getType());
|
|
|
+ break;
|
|
|
+ case SystemConstant.FLOW_DEPLOYMENT_ID_FIELD:
|
|
|
+ map.put(entry.getValue(), tfCustomFlow.getFlowDeploymentId());
|
|
|
+ break;
|
|
|
+ case SystemConstant.VERSION:
|
|
|
+ map.put(entry.getValue(), tfCustomFlow.getVersion());
|
|
|
+ break;
|
|
|
+ case SystemConstant.CODE:
|
|
|
+ map.put(entry.getValue(), code);
|
|
|
+ break;
|
|
|
+ case SystemConstant.FLOW_ID:
|
|
|
+ map.put(entry.getValue(), flowId);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ if (formFieldMap.containsKey(entry.getValue())) {
|
|
|
+ map.put(entry.getValue(), formFieldMap.get(entry.getValue()));
|
|
|
+ } else {
|
|
|
+ map.put(entry.getValue(), null);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (Map.Entry<String, Object> entry : map.entrySet()) {
|
|
|
+ stringJoinerFieldName.add(entry.getKey());
|
|
|
+ stringJoinerFieldValue.add(Objects.nonNull(entry.getValue()) ? "'" + entry.getValue().toString() + "'" : null);
|
|
|
+ }
|
|
|
+ tbSopInfoMapper.saveDynamicSop(tableName, stringJoinerFieldName.toString(), stringJoinerFieldValue.toString());
|
|
|
+ }
|
|
|
} else {//否则更新
|
|
|
-// tbSopInfoMapper.updateDynamicSop();
|
|
|
+ StringJoiner stringJoinerFieldValue = new StringJoiner(",");
|
|
|
+ for (Map.Entry<String, String> entry : formFieldMap.entrySet()) {
|
|
|
+ stringJoinerFieldValue.add(entry.getKey() + "='" + entry.getValue() + "'");
|
|
|
+ }
|
|
|
+ tbSopInfoMapper.updateDynamicSop(tableName, tfCustomFlow.getFlowDeploymentId(), flowId, stringJoinerFieldValue.toString());
|
|
|
}
|
|
|
- return null;
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -83,11 +131,10 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
|
|
|
* @param tableName
|
|
|
* @param flowDeploymentId
|
|
|
* @param flowId
|
|
|
- * @param fieldName
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<Map> selectDynamicSop(String tableName, String flowDeploymentId, Long flowId, String fieldName) {
|
|
|
- return this.baseMapper.selectDynamicSop(tableName, flowDeploymentId, flowId, fieldName);
|
|
|
+ public int selectDynamicSop(String tableName, String flowDeploymentId, Long flowId) {
|
|
|
+ return this.baseMapper.selectDynamicSop(tableName, flowDeploymentId, flowId);
|
|
|
}
|
|
|
}
|