|
@@ -0,0 +1,114 @@
|
|
|
|
+package com.persagy.dmp.report.service;
|
|
|
|
+
|
|
|
|
+import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
|
+import com.persagy.common.web.MapResponse;
|
|
|
|
+import com.persagy.common.web.PagedResponse;
|
|
|
|
+import com.persagy.dmp.report.common.criteria.CriteriaUtils;
|
|
|
|
+import com.persagy.dmp.report.common.criteria.JacksonCriteria;
|
|
|
|
+import com.persagy.dmp.report.entity.*;
|
|
|
|
+import com.persagy.dmp.report.repository.ReportConfigGroupRepository;
|
|
|
|
+import com.querydsl.core.Tuple;
|
|
|
|
+import com.querydsl.core.types.dsl.BooleanExpression;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.LinkedList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Optional;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author fengyanjie
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class ReportConfigGroupService implements BaseService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ protected ReportConfigGroupRepository reportConfigGroupRepository;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private CriteriaUtils criteriaUtils;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<BooleanExpression> parse(ObjectNode criteria) {
|
|
|
|
+ List<BooleanExpression> exps = new LinkedList<>();
|
|
|
|
+ QReportConfigGroup qt = QReportConfigGroup.reportConfigGroup;
|
|
|
|
+ exps.addAll(CriteriaUtils.parse(qt.conlumnName, criteria.get("conlumnName")));
|
|
|
|
+ exps.addAll(CriteriaUtils.parse(qt.conlumnDesc, criteria.get("conlumnDesc")));
|
|
|
|
+ exps.addAll(CriteriaUtils.parse(qt.method, criteria.get("method")));
|
|
|
|
+ exps.addAll(CriteriaUtils.parse(qt.value, criteria.get("value")));
|
|
|
|
+ exps.addAll(CriteriaUtils.parse(qt.valueType, criteria.get("valueType")));
|
|
|
|
+ return exps;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public PagedResponse<ReportConfigGroup> query(JacksonCriteria criteria) {
|
|
|
|
+ return criteriaUtils.query(QReportConfigGroup.reportConfigGroup, this::parse, criteria);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<BaseEntity> getData(PagedResponse<Tuple> tuplePagedResponse, List<JacksonCriteria.Calculated> calculatedColumns) {
|
|
|
|
+ List<BaseEntity> list = new ArrayList<>();
|
|
|
|
+ QReportConfig qt = QReportConfig.reportConfig;
|
|
|
|
+ tuplePagedResponse.getData().forEach(item -> {
|
|
|
|
+ ReportConfig entity = new ReportConfig();
|
|
|
|
+ entity.setCalculated(item.get(qt.calculated));
|
|
|
|
+ entity.setTableName(item.get(qt.tableName));
|
|
|
|
+ entity.setMappingName(item.get(qt.mappingName));
|
|
|
|
+ entity.setGroupColumn(item.get(qt.groupColumn));
|
|
|
|
+ entity.setTableGroup(item.get(qt.tableGroup));
|
|
|
|
+ list.add(entity);
|
|
|
|
+ });
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public MapResponse create(ReportConfigGroup param) {
|
|
|
|
+ MapResponse response = new MapResponse();
|
|
|
|
+
|
|
|
|
+ String conlumnName = param.getConlumnName();
|
|
|
|
+ if (conlumnName == null) {
|
|
|
|
+ response.setFail("conlumnName is required");
|
|
|
|
+ return response;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ long count = reportConfigGroupRepository.count(QReportConfigGroup.reportConfigGroup.conlumnName.eq(conlumnName));
|
|
|
|
+ if (count > 0) {
|
|
|
|
+ response.setFail("conlumnName is exists");
|
|
|
|
+ return response;
|
|
|
|
+ }
|
|
|
|
+ reportConfigGroupRepository.save(param);
|
|
|
|
+ response.add("conlumnName", param.getConlumnName());
|
|
|
|
+ return response;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public MapResponse update(ReportConfigGroup param) {
|
|
|
|
+ MapResponse response = new MapResponse();
|
|
|
|
+
|
|
|
|
+ String conlumnName = param.getConlumnName();
|
|
|
|
+ if (conlumnName == null) {
|
|
|
|
+ response.setFail("conlumnName is required");
|
|
|
|
+ return response;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Optional<ReportConfigGroup> one = reportConfigGroupRepository.findOne(QReportConfigGroup.reportConfigGroup.conlumnName.eq(conlumnName));
|
|
|
|
+ if (!one.isPresent()) {
|
|
|
|
+ response.setFail("conlumnName is not exists");
|
|
|
|
+ return response;
|
|
|
|
+ }
|
|
|
|
+ reportConfigGroupRepository.save(param);
|
|
|
|
+ response.add("conlumnName", param.getConlumnName());
|
|
|
|
+ return response;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public MapResponse delete(ReportConfigGroup param) {
|
|
|
|
+ MapResponse response = new MapResponse();
|
|
|
|
+
|
|
|
|
+ String conlumnName = param.getConlumnName();
|
|
|
|
+ if (conlumnName == null) {
|
|
|
|
+ response.setFail("conlumnName is required");
|
|
|
|
+ return response;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ reportConfigGroupRepository.deleteById(conlumnName);
|
|
|
|
+ return response;
|
|
|
|
+ }
|
|
|
|
+}
|