|
@@ -1,6 +1,8 @@
|
|
|
package com.platform.service.custom.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.platform.common.bean.AbstractPageResultBean;
|
|
|
import com.platform.common.exception.DeniedException;
|
|
@@ -12,8 +14,12 @@ import com.platform.dao.bean.MyPage;
|
|
|
import com.platform.dao.dto.custom.CustomFieldDTO;
|
|
|
import com.platform.dao.dto.custom.CustomFormDTO;
|
|
|
import com.platform.dao.entity.custom.CustomForm;
|
|
|
+import com.platform.dao.entity.custom.CustomFormBom;
|
|
|
import com.platform.dao.entity.custom.CustomFormBomField;
|
|
|
+import com.platform.dao.entity.custom.CustomFormData;
|
|
|
import com.platform.dao.mapper.custom.CustomFormBomFieldMapper;
|
|
|
+import com.platform.dao.mapper.custom.CustomFormBomMapper;
|
|
|
+import com.platform.dao.mapper.custom.CustomFormDataMapper;
|
|
|
import com.platform.dao.mapper.custom.CustomFormMapper;
|
|
|
import com.platform.dao.vo.query.custom.CustomFormVO;
|
|
|
import com.platform.service.base.impl.BaseServiceImpl;
|
|
@@ -23,9 +29,12 @@ import org.springframework.stereotype.Service;
|
|
|
import tk.mybatis.mapper.weekend.Weekend;
|
|
|
import tk.mybatis.mapper.weekend.WeekendCriteria;
|
|
|
|
|
|
+import java.lang.reflect.Method;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @Description 自定义表单表 service 实现类
|
|
@@ -38,6 +47,8 @@ import java.util.List;
|
|
|
public class CustomFormServiceImpl extends BaseServiceImpl<CustomFormMapper, CustomForm, CustomFormDTO> implements CustomFormService {
|
|
|
|
|
|
private final CustomFormBomFieldMapper customFormBomFieldMapper;
|
|
|
+ private final CustomFormDataMapper customFormDataMapper;
|
|
|
+ private final CustomFormBomMapper customFormBomMapper;
|
|
|
|
|
|
@Override
|
|
|
public int batchDelete(List<String> ids) {
|
|
@@ -108,6 +119,11 @@ public class CustomFormServiceImpl extends BaseServiceImpl<CustomFormMapper, Cus
|
|
|
if(CollectionUtil.isNotEmpty(record.getQueryFields())){
|
|
|
List<CustomFormBomField> saveFields = packageField(record.getId(),record.getQueryFields());
|
|
|
customFormBomFieldMapper.insertListforComplex(saveFields);
|
|
|
+ // 检索是否已有,formData配置了查询参数
|
|
|
+ CustomFormData dataQuery = new CustomFormData();
|
|
|
+ dataQuery.setFormId(record.getId());
|
|
|
+ List<CustomFormData> dataList = customFormDataMapper.select(dataQuery);
|
|
|
+ handleHistoryDataBom(dataList,saveFields);
|
|
|
}
|
|
|
CustomForm form = BeanConverterUtil.copyObjectProperties(record, CustomForm.class);
|
|
|
form.setUpdateTime(LocalDateTime.now());
|
|
@@ -116,6 +132,47 @@ public class CustomFormServiceImpl extends BaseServiceImpl<CustomFormMapper, Cus
|
|
|
mapper.updateByPrimaryKeySelective(form);
|
|
|
}
|
|
|
|
|
|
+ private void handleHistoryDataBom(List<CustomFormData> dataList,List<CustomFormBomField> fieldList) {
|
|
|
+ if(CollectionUtil.isNotEmpty(dataList)){
|
|
|
+ dataList.forEach(item->{
|
|
|
+ CustomFormBom bom = new CustomFormBom();
|
|
|
+ bom.setDataId(item.getId());
|
|
|
+ bom = customFormBomMapper.selectOne(bom);
|
|
|
+ if(bom != null){
|
|
|
+ Map<String,JSONObject> maps = new HashMap<>();
|
|
|
+ // json data 解析
|
|
|
+ JSONArray arrays = JSONArray.parseArray(item.getJsonString());
|
|
|
+ for(int i=0; i< arrays.size(); i++){
|
|
|
+ JSONObject object = arrays.getJSONObject(i);
|
|
|
+ String key = object.getString("value");
|
|
|
+ maps.put(key,object);
|
|
|
+ }
|
|
|
+ Class<?> cla = bom.getClass();
|
|
|
+ for(CustomFormBomField itemField:fieldList){
|
|
|
+ // 检索出查询字段名称,并给bom赋值
|
|
|
+ String key = itemField.getFiledName();
|
|
|
+ JSONObject object = maps.get(key);
|
|
|
+ if(object != null){
|
|
|
+ JSONObject attrs = object.getJSONObject("attrs");
|
|
|
+ String value = attrs.getString("value");
|
|
|
+ try{
|
|
|
+ String methodName = transferMethodName(itemField.getBomFieldName());
|
|
|
+ Method method = cla.getMethod(methodName,String.class);
|
|
|
+ method.invoke(bom,value);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String transferMethodName(String bomFieldName){
|
|
|
+ return "set" + bomFieldName.substring(0, 1).toUpperCase() + bomFieldName.substring(1);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public CustomFormVO getVOById(String id) {
|
|
|
CustomFormVO vo = BeanConverterUtil.copyObjectProperties(mapper.selectByPrimaryKey(id),CustomFormVO.class);
|