Browse Source

8/9 exportExcel

xiexiang 2 years ago
parent
commit
fc9286df15

+ 28 - 0
RMS/src/main/java/cn/cslg/report/common/model/vo/ReportTenantVO.java

@@ -0,0 +1,28 @@
+package cn.cslg.report.common.model.vo;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 租户报告表
+ * @Author xiexiang
+ * @Date 2023/8/2
+ */
+@Data
+public class ReportTenantVO {
+    /**
+     * 租户id
+     */
+    private Integer tenantId;
+
+    /**
+     * 租户名
+     */
+    private String tenantName;
+
+    /**
+     * 人员ids
+     */
+    private List<Integer> personnelIds;
+}

+ 26 - 0
RMS/src/main/java/cn/cslg/report/common/model/vo/ReportUsedByTenantVO.java

@@ -0,0 +1,26 @@
+package cn.cslg.report.common.model.vo;
+
+import lombok.Data;
+
+/**
+ * 租户报告使用情况
+ * @Author xiexiang
+ * @Date 2023/8/2
+ */
+@Data
+public class ReportUsedByTenantVO {
+    /**
+     * 租户名
+     */
+    private String tenantName;
+
+    /**
+     * 报告数量
+     */
+    private Integer reportNum;
+
+    /**
+     * 报告名称
+     */
+    private String reportName;
+}

+ 13 - 0
RMS/src/main/java/cn/cslg/report/controller/ReportController.java

@@ -4,6 +4,7 @@ import cn.cslg.report.common.core.base.Constants;
 import cn.cslg.report.common.model.dto.ConclusionDTO;
 import cn.cslg.report.common.model.dto.ReportDTO;
 import cn.cslg.report.common.model.vo.ReportDeVO;
+import cn.cslg.report.common.model.vo.ReportUsedByTenantVO;
 import cn.cslg.report.common.model.vo.ReportVO;
 import cn.cslg.report.common.utils.Response;
 import cn.cslg.report.common.utils.StringUtils;
@@ -158,4 +159,16 @@ public class ReportController {
         }
         return Response.success(reportDeDTO);
     }
+
+    @Operation(summary = "查询租户报告使用情况")
+    @PostMapping("/queryReportNameUsedByTenant")
+    public List<ReportUsedByTenantVO> queryReportNameUsedByTenant(@RequestBody List<Integer> tenantIds) throws IOException {
+        return reportService.getReportUsedByTenant(tenantIds);
+    }
+
+    @Operation(summary = "查询汇总报表的报告数量")
+    @GetMapping("/queryReportNumOfTotal")
+    public Integer queryReportNumOfTotal(Integer tenantId) throws IOException {
+        return reportService.getReportNumOfTotal(tenantId);
+    }
 }

+ 109 - 0
RMS/src/main/java/cn/cslg/report/service/business/ReportService.java

@@ -24,9 +24,15 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 
+import okhttp3.MediaType;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
 import org.springframework.beans.BeanUtils;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
@@ -34,7 +40,9 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
+import java.lang.reflect.Type;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -754,4 +762,105 @@ public class ReportService extends ServiceImpl<ReportMapper, Report> {
         }
         return reportDeVO;
     }
+
+    /**
+     * 查询租户报告使用报表
+     * @return
+     * @throws IOException
+     */
+    public List<ReportUsedByTenantVO> getReportUsedByTenant(List<Integer> tenantIds) throws IOException {
+        List<ReportUsedByTenantVO> reportUsedByTenantVOS = new ArrayList<>();
+        //调用权限系统接口获取租户下人员ids
+        String reData = this.getReportTenantVOFromPCS(tenantIds);
+        //字符串转对象集合
+        Gson gson = new Gson();
+        Type listType = new TypeToken<List<ReportTenantVO>>(){}.getType();
+        List<ReportTenantVO> reportTenantVOS = gson.fromJson(reData, listType);
+        //遍历
+        for(ReportTenantVO rT : reportTenantVOS){
+            //人员ids
+            List<Integer> personnelIds = rT.getPersonnelIds();
+            if(personnelIds.size() > 0) {
+                //查出所有人员ids名下的报告以及数量
+                LambdaQueryWrapper<Report> queryWrapper = new LambdaQueryWrapper<>();
+                queryWrapper.in(Report::getCreatePersonId, personnelIds);
+                //所有人员ids名下报告的数量
+                Long count = this.count(queryWrapper);
+                //查询出所有人员ids名下的报告集合
+                List<Report> reports = this.list(queryWrapper);
+                if (reports.size() > 0) {
+                    for (Report report : reports) {
+                        ReportUsedByTenantVO reportUsedByTenantVO = new ReportUsedByTenantVO();
+                        //租户名
+                        reportUsedByTenantVO.setTenantName(rT.getTenantName());
+                        //报告名
+                        reportUsedByTenantVO.setReportName(report.getName());
+                        Integer reportNum = Long.valueOf(count).intValue();
+                        //报告数量
+                        reportUsedByTenantVO.setReportNum(reportNum);
+                        reportUsedByTenantVOS.add(reportUsedByTenantVO);
+                    }
+                } else {
+                    ReportUsedByTenantVO reportUsedByTenantVO = new ReportUsedByTenantVO();
+                    //租户名
+                    reportUsedByTenantVO.setTenantName(rT.getTenantName());
+                    //报告数量
+                    reportUsedByTenantVO.setReportNum(0);
+                    reportUsedByTenantVOS.add(reportUsedByTenantVO);
+                }
+            }
+        }
+        return reportUsedByTenantVOS;
+    }
+
+    /**
+     * 调用权限系统查询租户人员ids接口
+     * @return
+     * @throws IOException
+     */
+    public String getReportTenantVOFromPCS(List<Integer> tenantIds) throws IOException {
+        String param = new Gson().toJson(tenantIds);
+        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
+        OkHttpClient okHttpClient = new OkHttpClient.Builder()
+                .connectTimeout(60, TimeUnit.SECONDS)
+                .writeTimeout(60, TimeUnit.SECONDS)
+                .readTimeout(60, TimeUnit.SECONDS)
+                .build();
+        Request request = new Request.Builder()
+                .url("http://localhost:8871" + "/permission/api/exportExcel/getTenantPerson")
+                .post(requestBody)
+                .build();
+        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
+    }
+
+    /**
+     * 传入租户id,返回报告数量
+     * @param tenantId
+     * @return
+     * @throws IOException
+     */
+    public Integer getReportNumOfTotal(Integer tenantId) throws IOException {
+        //字符串转对象!
+        List<Integer> tenantIds = new ArrayList<>();
+        tenantIds.add(tenantId);
+        String reData = this.getReportTenantVOFromPCS(tenantIds);
+        //字符串转对象集合
+        Gson gson = new Gson();
+        Type listType = new TypeToken<List<ReportTenantVO>>(){}.getType();
+        List<ReportTenantVO> reportTenantVOS = gson.fromJson(reData, listType);
+        ReportTenantVO reportTenantVO = reportTenantVOS.get(0);
+        //人员ids
+        List<Integer> personnelIds = reportTenantVO.getPersonnelIds();
+        if(personnelIds.size() > 0) {
+            //查出所有人员ids名下的报告以及数量
+            LambdaQueryWrapper<Report> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.in(Report::getCreatePersonId, personnelIds);
+            //所有人员ids名下报告的数量
+            Long count = this.count(queryWrapper);
+            Integer reportNum = Long.valueOf(count).intValue();
+            return reportNum;
+        } else {
+            return 0;
+        }
+    }
 }