|
@@ -1,5 +1,7 @@
|
|
|
package com.persagy.dmp.rwd.edit.service;
|
|
|
|
|
|
+import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
|
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
import com.persagy.common.criteria.CriteriaUtils;
|
|
|
import com.persagy.common.criteria.JacksonCriteria;
|
|
@@ -7,20 +9,24 @@ import com.persagy.common.date.DateUtils;
|
|
|
import com.persagy.common.web.MapResponse;
|
|
|
import com.persagy.common.web.PagedResponse;
|
|
|
import com.persagy.dmp.rwd.edit.config.web.UserUtils;
|
|
|
-import com.persagy.dmp.rwd.edit.entity.ClassDefChangeRecord;
|
|
|
-import com.persagy.dmp.rwd.edit.entity.FuncidDefChangeRecord;
|
|
|
-import com.persagy.dmp.rwd.edit.entity.QRwdeditVersion;
|
|
|
-import com.persagy.dmp.rwd.edit.entity.RwdeditVersion;
|
|
|
+import com.persagy.dmp.rwd.edit.entity.*;
|
|
|
import com.persagy.dmp.rwd.edit.enumeration.EnumVersionState;
|
|
|
+import com.persagy.dmp.rwd.edit.repository.ClassDefRepository;
|
|
|
+import com.persagy.dmp.rwd.edit.repository.FuncidDefRepository;
|
|
|
import com.persagy.dmp.rwd.edit.repository.RwdeditVersionRepository;
|
|
|
+import com.persagy.dmp.rwd.enums.FuncidDataType;
|
|
|
import com.querydsl.core.types.dsl.BooleanExpression;
|
|
|
+import com.querydsl.jpa.impl.JPAQuery;
|
|
|
+import com.querydsl.jpa.impl.JPAQueryFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.transaction.Transactional;
|
|
|
import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
|
+import java.io.PrintWriter;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -28,6 +34,9 @@ import java.util.*;
|
|
|
public class RwdeditVersionService {
|
|
|
|
|
|
@Autowired
|
|
|
+ private JPAQueryFactory queryFactory;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private CriteriaUtils criteriaUtils;
|
|
|
|
|
|
@Autowired
|
|
@@ -172,5 +181,152 @@ public class RwdeditVersionService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private List<ClassDef> loadClassDefList() {
|
|
|
+ QClassDef qt = QClassDef.classDef;
|
|
|
+ List<ClassDef> result = new LinkedList<>();
|
|
|
+ List<String> codes = Arrays.asList("project", "building", "floor", "space", "shaft", "system", "equipment", "component", "virtual", "tool", "material");
|
|
|
+ for (String code : codes) {
|
|
|
+ List<ClassDef> classDefList = queryFactory.selectFrom(qt).where(qt.code.eq(code), qt.isUsed.eq(1), qt.parentCode.isNull()).orderBy(qt.code.asc()).fetch();
|
|
|
+ result.addAll(classDefList);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String code : codes) {
|
|
|
+ List<ClassDef> temp = queryFactory.selectFrom(qt).where(qt.isUsed.eq(1), qt.parentCode.eq(code)).orderBy(qt.code.asc()).fetch();
|
|
|
+ result.addAll(temp);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 下載全量字典
|
|
|
+ public void downloadTotal(PrintWriter out) {
|
|
|
+
|
|
|
+ // 当前使用中的类型
|
|
|
+ List<ClassDef> classDefList = loadClassDefList();
|
|
|
+
|
|
|
+ out.println("truncate table rwd_def_class;\n");
|
|
|
+ int size = classDefList.size();
|
|
|
+ if (size > 0) {
|
|
|
+ out.println("INSERT INTO rwd_def_class ");
|
|
|
+ out.println("(id,obj_type,code,name,alias_code,alias_name,major_code,system_code,equipment_code,type,group_code,project_id,parent_code) ");
|
|
|
+ out.println("values ");
|
|
|
+ for (int i = 0; i < size; i++) {
|
|
|
+ ClassDef classDef = classDefList.get(i);
|
|
|
+ StringBuilder buff = new StringBuilder();
|
|
|
+ buff.append("(");
|
|
|
+ buff.append(addString(classDef.getId())).append(",");
|
|
|
+ buff.append(addString(classDef.getObjType().name())).append(",");
|
|
|
+ buff.append(addString(classDef.getCode())).append(",");
|
|
|
+ buff.append(addString(classDef.getName())).append(",");
|
|
|
+ buff.append(addString(classDef.getAliasCode())).append(",");
|
|
|
+ buff.append(addString(classDef.getAliasName())).append(",");
|
|
|
+ buff.append(addString(classDef.getMajorCode())).append(",");
|
|
|
+ buff.append(addString(classDef.getSystemCode())).append(",");
|
|
|
+ buff.append(addString(classDef.getEquipmentCode())).append(",");
|
|
|
+ buff.append("'common',"); // type
|
|
|
+ buff.append("'0',"); // group_code
|
|
|
+ buff.append("'0',"); // project_id
|
|
|
+ buff.append(addString(classDef.getParentCode()));
|
|
|
+ buff.append(")");
|
|
|
+ buff.append(i < size - 1 ? "," : ";");
|
|
|
+ out.println(buff.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ out.println();
|
|
|
+
|
|
|
+ // 当前使用中的信息点
|
|
|
+ QFuncidDef fqt = QFuncidDef.funcidDef;
|
|
|
+ List<FuncidDef> funcidDefList = queryFactory.selectFrom(fqt).where(fqt.isUsed.eq(1)).orderBy(fqt.classCode.asc(), fqt.code.asc()).fetch();
|
|
|
+ out.println("truncate table rwd_def_funcid;\n");
|
|
|
+ size = funcidDefList.size();
|
|
|
+ if (size > 0) {
|
|
|
+ out.println("INSERT INTO rwd_def_funcid ");
|
|
|
+ out.println("(id,first_tag,second_tag,code,orig_code,name,alias_code,alias_name,class_code,type,group_code,project_id," +
|
|
|
+ "category,priority,unit,data_type,is_multiple,is_region,formater,data_source,note,sub_flag,weak_point) ");
|
|
|
+ out.println("values ");
|
|
|
+ for (int i = 0; i < size; i++) {
|
|
|
+ FuncidDef funcid = funcidDefList.get(i);
|
|
|
+ StringBuilder buff = new StringBuilder();
|
|
|
+ buff.append("(");
|
|
|
+ buff.append(addString(funcid.getId())).append(",");
|
|
|
+ buff.append(addString(funcid.getFirstTag())).append(",");
|
|
|
+ buff.append(addString(funcid.getSecondTag())).append(",");
|
|
|
+ buff.append(addString(funcid.getCode())).append(",");
|
|
|
+ buff.append(addString(funcid.getOrigCode())).append(",");
|
|
|
+ buff.append(addString(funcid.getName())).append(",");
|
|
|
+ buff.append(addString(funcid.getAliasCode())).append(",");
|
|
|
+ buff.append(addString(funcid.getAliasName())).append(",");
|
|
|
+ buff.append(addString(funcid.getClassCode())).append(",");
|
|
|
+ buff.append("'common',");
|
|
|
+ buff.append("'0',");
|
|
|
+ buff.append("'0',");
|
|
|
+ buff.append(addString(funcid.getCategory().name())).append(",");
|
|
|
+ buff.append(addString(funcid.getPriority())).append(",");
|
|
|
+ buff.append(addString(funcid.getUnit())).append(",");
|
|
|
+ buff.append(addString(funcid.getDataType().name())).append(",");
|
|
|
+ buff.append(funcid.getIsMultiple() ? 1 : 0).append(",");
|
|
|
+ buff.append(funcid.getIsRegion() ? 1 : 0).append(",");
|
|
|
+ buff.append(addString(funcid.getFormater())).append(",");
|
|
|
+ // datasource
|
|
|
+ buff.append(getDataSource(funcid)).append(",");
|
|
|
+ buff.append(addString(funcid.getNote())).append(",");
|
|
|
+ buff.append(funcid.getSubFlag() ? 1 : 0).append(",");
|
|
|
+ buff.append(funcid.getWeakPoint() ? 1 : 0);
|
|
|
+ buff.append(")");
|
|
|
+ buff.append(i < size - 1 ? "," : ";");
|
|
|
+ out.println(buff.toString());
|
|
|
+ }
|
|
|
+ out.println();
|
|
|
+ }
|
|
|
+ out.flush();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String addString(String param) {
|
|
|
+ if (param == null) {
|
|
|
+ return "null";
|
|
|
+ } else {
|
|
|
+ return "'" + param + "'";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getDataSource(FuncidDef funcid) {
|
|
|
+ FuncidDataType dataType = funcid.getDataType();
|
|
|
+ ArrayNode dataSource = funcid.getDataSource();
|
|
|
+ if (dataType == FuncidDataType.INTEGER) {
|
|
|
+ return dataSource == null ? "null" : dataSource.toString();
|
|
|
+ } else if (dataType == FuncidDataType.DOUBLE) {
|
|
|
+ return dataSource == null ? "null" : dataSource.toString();
|
|
|
+ } else if (dataType == FuncidDataType.BOOLEAN) {
|
|
|
+ return dataSource == null ? "null" : dataSource.toString();
|
|
|
+ } else if (dataType == FuncidDataType.STRING) {
|
|
|
+ return dataSource == null ? "null" : dataSource.toString();
|
|
|
+ } else if (dataType == FuncidDataType.DATETIME) {
|
|
|
+ return dataSource == null ? "null" : dataSource.toString();
|
|
|
+ } else if (dataType == FuncidDataType.ENUM) {
|
|
|
+ return dataSource == null ? "null" : dataSource.toString();
|
|
|
+ } else if (dataType == FuncidDataType.MENUM) {
|
|
|
+ return dataSource == null ? "null" : dataSource.toString();
|
|
|
+ } else if (dataType == FuncidDataType.ATTACHMENT) {
|
|
|
+ return dataSource == null ? "null" : dataSource.toString();
|
|
|
+ } else if (dataType == FuncidDataType.OBJECT) {
|
|
|
+ return dataSource == null ? "null" : dataSource.toString();
|
|
|
+ } else if (dataType == FuncidDataType.REFENUM) {
|
|
|
+ String refKey = dataSource.get(0).get("refKey").asText();
|
|
|
+ QRwdeditRefTypeInfos qt = QRwdeditRefTypeInfos.rwdeditRefTypeInfos;
|
|
|
+ List<RwdeditRefTypeInfos> infos = queryFactory.selectFrom(qt).where(qt.refKey.eq(refKey)).orderBy(qt.code.asc()).fetch();
|
|
|
+ ArrayNode array = JsonNodeFactory.instance.arrayNode();
|
|
|
+ for (RwdeditRefTypeInfos info : infos) {
|
|
|
+ ObjectNode node = array.addObject();
|
|
|
+ node.put("code", info.getCode());
|
|
|
+ node.put("name", info.getName());
|
|
|
+ if (info.getParentCode() != null) {
|
|
|
+ node.put("parentCode", info.getParentCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return array.toString();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|