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