Bladeren bron

添加报表配置信息编辑接口

fengyanjie@sagacloud.cn 4 jaren geleden
bovenliggende
commit
f1cd54e6f4

+ 15 - 0
dmp-report/src/main/java/com/persagy/dmp/report/controller/ReportConfigController.java

@@ -1,5 +1,6 @@
 package com.persagy.dmp.report.controller;
 
+import com.persagy.common.web.MapResponse;
 import com.persagy.common.web.PagedResponse;
 import com.persagy.dmp.report.common.criteria.JacksonCriteria;
 import com.persagy.dmp.report.entity.ReportConfig;
@@ -22,4 +23,18 @@ public class ReportConfigController {
         return service.query(criteria);
     }
 
+    @PostMapping("/create")
+    public MapResponse create(@RequestBody ReportConfig param) {
+        return service.create(param);
+    }
+
+    @PostMapping("/update")
+    public MapResponse update(@RequestBody ReportConfig param) {
+        return service.update(param);
+    }
+
+    @PostMapping("/delete")
+    public MapResponse delete(@RequestBody ReportConfig param) {
+        return service.delete(param);
+    }
 }

+ 40 - 0
dmp-report/src/main/java/com/persagy/dmp/report/controller/ReportConfigGroupController.java

@@ -0,0 +1,40 @@
+package com.persagy.dmp.report.controller;
+
+import com.persagy.common.web.MapResponse;
+import com.persagy.common.web.PagedResponse;
+import com.persagy.dmp.report.common.criteria.JacksonCriteria;
+import com.persagy.dmp.report.entity.ReportConfigGroup;
+import com.persagy.dmp.report.service.ReportConfigGroupService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/report/config/group")
+public class ReportConfigGroupController {
+
+    @Autowired
+    private ReportConfigGroupService service;
+
+    @PostMapping("/query")
+    public PagedResponse<ReportConfigGroup> query(@RequestBody JacksonCriteria criteria) {
+        return service.query(criteria);
+    }
+
+    @PostMapping("/create")
+    public MapResponse create(@RequestBody ReportConfigGroup param) {
+        return service.create(param);
+    }
+
+    @PostMapping("/update")
+    public MapResponse update(@RequestBody ReportConfigGroup param) {
+        return service.update(param);
+    }
+
+    @PostMapping("/delete")
+    public MapResponse delete(@RequestBody ReportConfigGroup param) {
+        return service.delete(param);
+    }
+}

+ 0 - 1
dmp-report/src/main/java/com/persagy/dmp/report/entity/ReportConfig.java

@@ -17,7 +17,6 @@ import javax.persistence.*;
 public class ReportConfig extends BaseEntity {
 
     @Id
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
     private String calculated;
     private String tableName;
     private String mappingName;

+ 0 - 1
dmp-report/src/main/java/com/persagy/dmp/report/entity/ReportConfigGroup.java

@@ -13,7 +13,6 @@ import java.util.List;
 public class ReportConfigGroup extends BaseEntity {
 
     @Id
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
     private String conlumnName;
     private String conlumnDesc;
     private String method;

+ 1 - 1
dmp-report/src/main/java/com/persagy/dmp/report/repository/ReportConfigGroupRepository.java

@@ -4,6 +4,6 @@ import com.persagy.dmp.report.entity.ReportConfigGroup;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.querydsl.QuerydslPredicateExecutor;
 
-public interface ReportConfigGroupRepository extends JpaRepository<ReportConfigGroup, Integer>, QuerydslPredicateExecutor<ReportConfigGroup> {
+public interface ReportConfigGroupRepository extends JpaRepository<ReportConfigGroup, String>, QuerydslPredicateExecutor<ReportConfigGroup> {
 }
 

+ 1 - 1
dmp-report/src/main/java/com/persagy/dmp/report/repository/ReportConfigRepository.java

@@ -4,6 +4,6 @@ import com.persagy.dmp.report.entity.ReportConfig;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.querydsl.QuerydslPredicateExecutor;
 
-public interface ReportConfigRepository extends JpaRepository<ReportConfig, Integer>, QuerydslPredicateExecutor<ReportConfig> {
+public interface ReportConfigRepository extends JpaRepository<ReportConfig, String>, QuerydslPredicateExecutor<ReportConfig> {
 }
 

+ 114 - 0
dmp-report/src/main/java/com/persagy/dmp/report/service/ReportConfigGroupService.java

@@ -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;
+    }
+}

+ 57 - 0
dmp-report/src/main/java/com/persagy/dmp/report/service/ReportConfigService.java

@@ -1,12 +1,14 @@
 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.BaseEntity;
 import com.persagy.dmp.report.entity.QReportConfig;
 import com.persagy.dmp.report.entity.ReportConfig;
+import com.persagy.dmp.report.repository.ReportConfigRepository;
 import com.querydsl.core.Tuple;
 import com.querydsl.core.types.dsl.BooleanExpression;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -15,6 +17,7 @@ import org.springframework.stereotype.Service;
 import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Optional;
 
 /**
  * @author fengyanjie
@@ -23,6 +26,9 @@ import java.util.List;
 public class ReportConfigService implements BaseService {
 
     @Autowired
+    protected ReportConfigRepository reportConfigRepository;
+
+    @Autowired
     private CriteriaUtils criteriaUtils;
 
     @Override
@@ -55,4 +61,55 @@ public class ReportConfigService implements BaseService {
         });
         return list;
     }
+
+    public MapResponse create(ReportConfig param) {
+        MapResponse response = new MapResponse();
+
+        String calculated = param.getCalculated();
+        if (calculated == null) {
+            response.setFail("calculated is required");
+            return response;
+        }
+
+        long count = reportConfigRepository.count(QReportConfig.reportConfig.calculated.eq(calculated));
+        if (count > 0) {
+            response.setFail("calculated is exists");
+            return response;
+        }
+        reportConfigRepository.save(param);
+        response.add("calculated", param.getCalculated());
+        return response;
+    }
+
+    public MapResponse update(ReportConfig param) {
+        MapResponse response = new MapResponse();
+
+        String calculated = param.getCalculated();
+        if (calculated == null) {
+            response.setFail("calculated is required");
+            return response;
+        }
+
+        Optional<ReportConfig> one = reportConfigRepository.findOne(QReportConfig.reportConfig.calculated.eq(calculated));
+        if(!one.isPresent()){
+            response.setFail("calculated is not exists");
+            return response;
+        }
+        reportConfigRepository.save(param);
+        response.add("calculated", param.getCalculated());
+        return response;
+    }
+
+    public MapResponse delete(ReportConfig param) {
+        MapResponse response = new MapResponse();
+
+        String calculated = param.getCalculated();
+        if (calculated == null) {
+            response.setFail("calculated is required");
+            return response;
+        }
+
+        reportConfigRepository.deleteById(calculated);
+        return response;
+    }
 }