|
@@ -0,0 +1,410 @@
|
|
|
+package com.persagy.dmp.rwd.edit.service;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
|
+import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
+import com.persagy.common.criteria.CriteriaUtils;
|
|
|
+import com.persagy.common.criteria.JacksonCriteria;
|
|
|
+import com.persagy.common.json.JacksonMapper;
|
|
|
+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.FuncidDefChangeRecord;
|
|
|
+import com.persagy.dmp.rwd.edit.entity.QFuncidDefChangeRecord;
|
|
|
+import com.persagy.dmp.rwd.edit.entity.RwdeditRefTypeInfos;
|
|
|
+import com.persagy.dmp.rwd.edit.enumeration.EnumOperationType;
|
|
|
+import com.persagy.dmp.rwd.edit.repository.FuncidDefChangeRecordRepository;
|
|
|
+import com.persagy.dmp.rwd.enums.FuncidDataType;
|
|
|
+import com.persagy.dmp.rwd.model.FuncidDefModel;
|
|
|
+import com.querydsl.core.types.dsl.BooleanExpression;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.transaction.Transactional;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class FuncidDefChangeRecordService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ FuncidDefChangeRecordRepository repository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ FuncidDefService funcidDefService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RwdeditRefTypeInfosService rwdeditRefTypeInfosService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CriteriaUtils criteriaUtils;
|
|
|
+
|
|
|
+ private List<BooleanExpression> parse(ObjectNode object) {
|
|
|
+ List<BooleanExpression> list = new LinkedList<>();
|
|
|
+ QFuncidDefChangeRecord qt = QFuncidDefChangeRecord.funcidDefChangeRecord;
|
|
|
+ list.addAll(CriteriaUtils.parse(qt.id, object.get("id")));
|
|
|
+ list.addAll(CriteriaUtils.parse(qt.code, object.get("code")));
|
|
|
+ list.addAll(CriteriaUtils.parse(qt.operationType, object.get("operationType"), EnumOperationType.class));
|
|
|
+ list.addAll(CriteriaUtils.parse(qt.operationUser, object.get("operationUser")));
|
|
|
+ list.addAll(CriteriaUtils.parse(qt.operationTime, object.get("operationTime")));
|
|
|
+ list.addAll(CriteriaUtils.parse(qt.confirmUser, object.get("confirmUser")));
|
|
|
+ list.addAll(CriteriaUtils.parse(qt.confirmTime, object.get("confirmTime")));
|
|
|
+ list.addAll(CriteriaUtils.parse(qt.publishUser, object.get("publishUser")));
|
|
|
+ list.addAll(CriteriaUtils.parse(qt.publishTime, object.get("publishTime")));
|
|
|
+ list.addAll(CriteriaUtils.parse(qt.finishTime, object.get("finishTime")));
|
|
|
+ list.addAll(CriteriaUtils.parse(qt.state, object.get("state")));
|
|
|
+ list.addAll(CriteriaUtils.parse(qt.version, object.get("version")));
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public PagedResponse<FuncidDefChangeRecord> query(JacksonCriteria criteria) {
|
|
|
+ PagedResponse<FuncidDefChangeRecord> result = criteriaUtils.query(QFuncidDefChangeRecord.funcidDefChangeRecord, this::parse, criteria);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public MapResponse create(FuncidDefChangeRecord param) {
|
|
|
+ MapResponse response = new MapResponse();
|
|
|
+ String code = param.getCode();
|
|
|
+ String classCode = param.getClassCode();
|
|
|
+ if (code == null) {
|
|
|
+ response.setFail("code is required");
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ if (classCode == null) {
|
|
|
+ response.setFail("classCode is required");
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ List<FuncidDefModel> funcidDefList = queryFuncidDef(code, classCode);
|
|
|
+ if (EnumOperationType.create.equals(param.getOperationType())) {
|
|
|
+ if (funcidDefList.size() > 0) {
|
|
|
+ response.setFail("code is exists");
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (funcidDefList.size() == 0) {
|
|
|
+ response.setFail("code not exists");
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ FuncidDefModel funcidDef = funcidDefList.get(0);
|
|
|
+ param.setOrigCode(funcidDef.getOrigCode());
|
|
|
+ param.setName(funcidDef.getName());
|
|
|
+ if (param.getAliasCode() == null) {
|
|
|
+ param.setAliasCode(funcidDef.getAliasCode());
|
|
|
+ }
|
|
|
+ if (param.getAliasName() == null) {
|
|
|
+ param.setAliasName(funcidDef.getAliasName());
|
|
|
+ }
|
|
|
+ param.setClassCode(funcidDef.getClassCode());
|
|
|
+ param.setCategory(funcidDef.getCategory());
|
|
|
+ param.setType(funcidDef.getType());
|
|
|
+ param.setGroupCode(funcidDef.getGroupCode());
|
|
|
+ param.setProjectId(funcidDef.getProjectId());
|
|
|
+ if (param.getFirstTag() == null) {
|
|
|
+ param.setFirstTag(funcidDef.getFirstTag());
|
|
|
+ }
|
|
|
+ if (param.getSecondTag() == null) {
|
|
|
+ param.setSecondTag(funcidDef.getSecondTag());
|
|
|
+ }
|
|
|
+ param.setPriority(funcidDef.getPriority());
|
|
|
+ param.setInputMode(funcidDef.getInputMode());
|
|
|
+ param.setUnit(funcidDef.getUnit());
|
|
|
+ param.setDataType(funcidDef.getDataType());
|
|
|
+ param.setOrigDataType(funcidDef.getOrigDataType());
|
|
|
+ param.setIsMultiple(funcidDef.getIsMultiple());
|
|
|
+ param.setIsRegion(funcidDef.getIsRegion());
|
|
|
+ param.setFormater(funcidDef.getFormater());
|
|
|
+ param.setDataSource(funcidDef.getDataSource());
|
|
|
+ if (param.getNote() == null) {
|
|
|
+ param.setNote(funcidDef.getNote());
|
|
|
+ }
|
|
|
+ param.setSubFlag(funcidDef.getSubFlag());
|
|
|
+ param.setWeakPoint(funcidDef.getWeakPoint());
|
|
|
+ }
|
|
|
+ QFuncidDefChangeRecord qt = QFuncidDefChangeRecord.funcidDefChangeRecord;
|
|
|
+ BooleanExpression ex = qt.code.eq(code).and(qt.state.eq(1)).and(qt.version.isNull());
|
|
|
+ Iterable<FuncidDefChangeRecord> all = repository.findAll(ex);
|
|
|
+ List<FuncidDefChangeRecord> list = new ArrayList<>();
|
|
|
+ all.forEach(list::add);
|
|
|
+ if (list.size() > 0) {
|
|
|
+ repository.deleteAll(list);
|
|
|
+ }
|
|
|
+ param.setOperationUser(UserUtils.currentUserId() + "");
|
|
|
+ param.setOperationTime(new Date());
|
|
|
+ param.setValid(true);
|
|
|
+ param.setState(1);
|
|
|
+ repository.save(param);
|
|
|
+ response.add("id", param.getId());
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<FuncidDefModel> queryFuncidDef(String code, String classCode) {
|
|
|
+ JacksonCriteria criteria = JacksonCriteria.newInstance();
|
|
|
+ criteria.add("type", "common");
|
|
|
+ criteria.add("code", code);
|
|
|
+ criteria.add("classCode", classCode);
|
|
|
+ PagedResponse<FuncidDefModel> query = funcidDefService.query(criteria);
|
|
|
+ List<FuncidDefModel> data = query.getData();
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public MapResponse update(FuncidDefChangeRecord param) {
|
|
|
+ MapResponse response = new MapResponse();
|
|
|
+ Optional<FuncidDefChangeRecord> optional = repository.findById(param.getId());
|
|
|
+ if (!optional.isPresent()) {
|
|
|
+ response.setFail("code not exists");
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ FuncidDefChangeRecord changeRecord = optional.get();
|
|
|
+ if (changeRecord.getState() == 1 && changeRecord.getVersion() == null) {
|
|
|
+ if (param.getAliasCode() != null) {
|
|
|
+ changeRecord.setAliasCode(param.getAliasCode());
|
|
|
+ }
|
|
|
+ if (param.getAliasName() != null) {
|
|
|
+ changeRecord.setAliasName(param.getAliasName());
|
|
|
+ }
|
|
|
+ if (param.getFirstTag() != null) {
|
|
|
+ changeRecord.setFirstTag(param.getFirstTag());
|
|
|
+ }
|
|
|
+ if (param.getSecondTag() != null) {
|
|
|
+ changeRecord.setSecondTag(param.getSecondTag());
|
|
|
+ }
|
|
|
+ if (param.getNote() != null) {
|
|
|
+ changeRecord.setNote(param.getNote());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (param.getState() != null) {
|
|
|
+ switch (param.getState()) {
|
|
|
+ case 2: {
|
|
|
+ changeRecord.setConfirmUser(UserUtils.currentUserId() + "");
|
|
|
+ changeRecord.setConfirmTime(new Date());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 3: {
|
|
|
+ changeRecord.setPublishUser(UserUtils.currentUserId() + "");
|
|
|
+ changeRecord.setPublishTime(new Date());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 4: {
|
|
|
+ changeRecord.setFinishTime(new Date());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default: {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ repository.save(changeRecord);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void updateStateByVersion(Integer state, String version) {
|
|
|
+ JacksonCriteria criteria = JacksonCriteria.newInstance();
|
|
|
+ criteria.add("version", version);
|
|
|
+ PagedResponse<FuncidDefChangeRecord> query = query(criteria);
|
|
|
+ if (query.getCount() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<FuncidDefChangeRecord> data = query.getData();
|
|
|
+ switch (state) {
|
|
|
+ case 2: {
|
|
|
+ for (FuncidDefChangeRecord changeRecord : data) {
|
|
|
+ changeRecord.setConfirmUser(UserUtils.currentUserId() + "");
|
|
|
+ changeRecord.setConfirmTime(new Date());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 3: {
|
|
|
+ for (FuncidDefChangeRecord changeRecord : data) {
|
|
|
+ changeRecord.setPublishUser(UserUtils.currentUserId() + "");
|
|
|
+ changeRecord.setPublishTime(new Date());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 4: {
|
|
|
+ for (FuncidDefChangeRecord changeRecord : data) {
|
|
|
+ changeRecord.setFinishTime(new Date());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default: {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ repository.saveAll(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public MapResponse addVersion(String version, List<Integer> idList) {
|
|
|
+ MapResponse response = new MapResponse();
|
|
|
+// JacksonCriteria criteria = JacksonCriteria.newInstance();
|
|
|
+// criteria.add("version", version);
|
|
|
+// Long count = rwdeditVersionService.query(criteria).getCount();
|
|
|
+// if (count == 0) {
|
|
|
+// response.setFail("version not exists");
|
|
|
+// return response;
|
|
|
+// }
|
|
|
+ Integer num = repository.addVersion(version, idList);
|
|
|
+ response.setMessage("update num: " + num);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public MapResponse delete(FuncidDefChangeRecord param) {
|
|
|
+ MapResponse response = new MapResponse();
|
|
|
+ Optional<FuncidDefChangeRecord> optional = repository.findById(param.getId());
|
|
|
+ if (optional.isPresent()) {
|
|
|
+ FuncidDefChangeRecord changeRecord = optional.get();
|
|
|
+ if (changeRecord.getState() != 1 || changeRecord.getVersion() != null) {
|
|
|
+ response.setFail(changeRecord.getId() + " 不可删除!");
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ repository.delete(param);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<String> getSqlList(String version) {
|
|
|
+ List<String> sqlList = new ArrayList<>();
|
|
|
+ JacksonCriteria criteria = JacksonCriteria.newInstance();
|
|
|
+ criteria.add("version", version);
|
|
|
+ PagedResponse<FuncidDefChangeRecord> response = query(criteria);
|
|
|
+ List<FuncidDefChangeRecord> data = response.getData();
|
|
|
+ for (FuncidDefChangeRecord changeRecord : data) {
|
|
|
+ StringBuilder sql = new StringBuilder();
|
|
|
+ switch (changeRecord.getOperationType()) {
|
|
|
+ case create: {
|
|
|
+ String uuid = UUID.randomUUID().toString().replace("-", "");
|
|
|
+ sql.append("INSERT INTO `rwd_def_funcid`(`id`,`code`,`orig_code`,`name`,`alias_code`,`alias_name`,`class_code`,`type`," +
|
|
|
+ "`group_code`,`project_id`,`category`,`first_tag`,`second_tag`,`priority`,`input_mode`,`unit`,`data_type`,`orig_data_type`," +
|
|
|
+ "`is_multiple`,`is_region`,`formater`,`data_source`,`note`,`sub_flag`,`weak_point`) VALUES (");
|
|
|
+ sql.append("'" + uuid + "',");
|
|
|
+ sql.append("'" + changeRecord.getCode() + "',");
|
|
|
+ if (changeRecord.getOrigCode() == null) {
|
|
|
+ sql.append("null,");
|
|
|
+ } else {
|
|
|
+ sql.append("'" + changeRecord.getOrigCode() + "',");
|
|
|
+ }
|
|
|
+ sql.append("'" + changeRecord.getName() + "',");
|
|
|
+ sql.append("'" + changeRecord.getAliasCode() + "',");
|
|
|
+ sql.append("'" + changeRecord.getAliasName() + "',");
|
|
|
+ sql.append("'" + changeRecord.getClassCode() + "',");
|
|
|
+ if (changeRecord.getType() == null) {
|
|
|
+ sql.append("null,");
|
|
|
+ } else {
|
|
|
+ sql.append("'" + changeRecord.getType() + "',");
|
|
|
+ }
|
|
|
+ sql.append("'" + changeRecord.getGroupCode() + "',");
|
|
|
+ sql.append("'" + changeRecord.getProjectId() + "',");
|
|
|
+ if (changeRecord.getCategory() == null) {
|
|
|
+ sql.append("null,");
|
|
|
+ } else {
|
|
|
+ sql.append("'" + changeRecord.getCategory().name() + "',");
|
|
|
+ }
|
|
|
+ if (changeRecord.getFirstTag() == null) {
|
|
|
+ sql.append("null,");
|
|
|
+ } else {
|
|
|
+ sql.append("'" + changeRecord.getFirstTag() + "',");
|
|
|
+ }
|
|
|
+ if (changeRecord.getSecondTag() == null) {
|
|
|
+ sql.append("null,");
|
|
|
+ } else {
|
|
|
+ sql.append("'" + changeRecord.getSecondTag() + "',");
|
|
|
+ }
|
|
|
+ if (changeRecord.getPriority() == null) {
|
|
|
+ sql.append("null,");
|
|
|
+ } else {
|
|
|
+ sql.append("'" + changeRecord.getPriority() + "',");
|
|
|
+ }
|
|
|
+ if (changeRecord.getInputMode() == null) {
|
|
|
+ sql.append("null,");
|
|
|
+ } else {
|
|
|
+ sql.append("'" + changeRecord.getInputMode() + "',");
|
|
|
+ }
|
|
|
+ if (changeRecord.getUnit() == null) {
|
|
|
+ sql.append("null,");
|
|
|
+ } else {
|
|
|
+ sql.append("'" + changeRecord.getUnit() + "',");
|
|
|
+ }
|
|
|
+ boolean refenumBool = FuncidDataType.REFENUM.equals(changeRecord.getDataType());
|
|
|
+ if (refenumBool) {
|
|
|
+ sql.append("'ENUM',");
|
|
|
+ } else {
|
|
|
+ sql.append("'" + changeRecord.getDataType().name() + "',");
|
|
|
+ }
|
|
|
+ if (changeRecord.getOrigDataType() == null) {
|
|
|
+ sql.append("null,");
|
|
|
+ } else {
|
|
|
+ sql.append("'" + changeRecord.getOrigDataType() + "',");
|
|
|
+ }
|
|
|
+ if (changeRecord.getIsMultiple() == null) {
|
|
|
+ sql.append("null,");
|
|
|
+ } else {
|
|
|
+ sql.append("'" + changeRecord.getIsMultiple() + "',");
|
|
|
+ }
|
|
|
+ if (changeRecord.getFormater() == null) {
|
|
|
+ sql.append("null,");
|
|
|
+ } else {
|
|
|
+ sql.append("'" + changeRecord.getFormater() + "')");
|
|
|
+ }
|
|
|
+ if (refenumBool) {
|
|
|
+ ArrayNode dataSource = changeRecord.getDataSource();
|
|
|
+ String refKey = dataSource.get(0).get("refKey").asText();
|
|
|
+ JacksonCriteria queryRef = JacksonCriteria.newInstance();
|
|
|
+ queryRef.add("refKey", refKey);
|
|
|
+ List<RwdeditRefTypeInfos> refInfos = rwdeditRefTypeInfosService.query(queryRef).getData();
|
|
|
+ sql.append("'" + JacksonMapper.toSimpleJson(refInfos) + "')");
|
|
|
+ } else {
|
|
|
+ if (changeRecord.getDataSource() == null) {
|
|
|
+ sql.append("null,");
|
|
|
+ } else {
|
|
|
+ sql.append("'" + JacksonMapper.toSimpleJson(changeRecord.getDataSource()) + "')");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (changeRecord.getNote() == null) {
|
|
|
+ sql.append("null,");
|
|
|
+ } else {
|
|
|
+ sql.append("'" + changeRecord.getNote() + "')");
|
|
|
+ }
|
|
|
+ if (changeRecord.getSubFlag() == null) {
|
|
|
+ sql.append("null,");
|
|
|
+ } else {
|
|
|
+ sql.append("'" + changeRecord.getSubFlag() + "')");
|
|
|
+ }
|
|
|
+ if (changeRecord.getWeakPoint() == null) {
|
|
|
+ sql.append("null);");
|
|
|
+ } else {
|
|
|
+ sql.append("'" + changeRecord.getWeakPoint() + "');");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case update: {
|
|
|
+ sql.append("UPDATE `rwd_def_funcid` SET");
|
|
|
+ sql.append(" `alias_code` = '" + changeRecord.getAliasCode() + "',");
|
|
|
+ sql.append(" `alias_name` = '" + changeRecord.getAliasName() + "'");
|
|
|
+ sql.append(" WHERE `code` = '" + changeRecord.getCode() + "'");
|
|
|
+ sql.append(" WHERE `class_code` = '" + changeRecord.getClassCode() + "'");
|
|
|
+ sql.append(" and `group_code` = '" + changeRecord.getGroupCode() + "'");
|
|
|
+ sql.append(" and `project_id` = '" + changeRecord.getProjectId() + "';");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case delete: {
|
|
|
+ sql.append("DELETE FROM `rwd_def_funcid`");
|
|
|
+ sql.append(" WHERE `code` = '" + changeRecord.getCode() + "'");
|
|
|
+ sql.append(" WHERE `class_code` = '" + changeRecord.getClassCode() + "'");
|
|
|
+ sql.append(" and `group_code` = '" + changeRecord.getGroupCode() + "'");
|
|
|
+ sql.append(" and `project_id` = '" + changeRecord.getProjectId() + "';");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default: {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sqlList.add(sql.toString());
|
|
|
+ }
|
|
|
+ return sqlList;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|