|
|
@ -1,11 +1,13 @@
|
|
|
|
package com.ruoyi.jjh.ent.controller;
|
|
|
|
package com.ruoyi.jjh.ent.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
|
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
|
import com.ruoyi.jjh.declaration.entity.BmsDeclarationRecords;
|
|
|
|
import com.ruoyi.jjh.declaration.entity.BmsDeclarationRecords;
|
|
|
|
import com.ruoyi.jjh.ent.entity.JPolicyFile;
|
|
|
|
import com.ruoyi.jjh.ent.entity.JPolicyFile;
|
|
|
|
import com.ruoyi.jjh.ent.entity.request.JPolicyFileRequest;
|
|
|
|
import com.ruoyi.jjh.ent.entity.request.JPolicyFileRequest;
|
|
|
@ -24,8 +26,9 @@ import java.io.Serializable;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 政策文件(j_policy_file)表控制层
|
|
|
|
* 政策文件(j_policy_file)表控制层
|
|
|
@ -62,71 +65,97 @@ public class JPolicyFileController extends BaseController {
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "获取某个模板的已填报数据并且导出")
|
|
|
|
@ApiOperation(value = "获取某个模板的已填报数据并且导出")
|
|
|
|
@GetMapping("/getYtb")
|
|
|
|
@GetMapping("/getYtb")
|
|
|
|
public void getYtb(HttpServletResponse response, Long templateRecordId) {
|
|
|
|
@PreAuthorize("@ss.hasAnyRoles('admin,other-gov,gov')")
|
|
|
|
List<BmsDeclarationRecords> ytb = jMemorandumService.getYtb(templateRecordId);
|
|
|
|
public void getYtb(HttpServletResponse response, @RequestParam(name = "list") List<Long> list1) {
|
|
|
|
|
|
|
|
List<BmsDeclarationRecords> ytb = jMemorandumService.getYtb(list1);
|
|
|
|
|
|
|
|
int size1 = 0;
|
|
|
|
|
|
|
|
if(ytb!=null&& !ytb.isEmpty()){
|
|
|
|
|
|
|
|
Long trId = ytb.get(0).getTemplateRecordId();
|
|
|
|
|
|
|
|
for (BmsDeclarationRecords item : ytb) {
|
|
|
|
|
|
|
|
if (item.getTemplateRecordId().equals(trId)) {
|
|
|
|
|
|
|
|
size1++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(size1!=ytb.size()){
|
|
|
|
|
|
|
|
throw new ServiceException("请选择同一在线模板数据!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
throw new ServiceException("请选择企业填报数据!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<List<String>> data = new ArrayList<>();
|
|
|
|
List<List<String>> data = new ArrayList<>();
|
|
|
|
//单选的value
|
|
|
|
|
|
|
|
List<String> value1 = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<List<String>> list = new ArrayList<>();
|
|
|
|
List<List<String>> final1 = new ArrayList<>();
|
|
|
|
|
|
|
|
// 创建一个 Map 用于存储不同的列表,键为字符串表示“变量名”,值为列表
|
|
|
|
|
|
|
|
Map<String, List<String>> list = new LinkedHashMap<>();
|
|
|
|
List<String> head0 = new ArrayList<>();
|
|
|
|
List<String> head0 = new ArrayList<>();
|
|
|
|
head0.add("企业名称");
|
|
|
|
head0.add("企业名称");
|
|
|
|
List<String> head1 = new ArrayList<>();
|
|
|
|
List<String> head1 = new ArrayList<>();
|
|
|
|
head1.add("统一社会信用代码");
|
|
|
|
head1.add("统一社会信用代码");
|
|
|
|
list.add(head0);
|
|
|
|
list.put("head0", head0);
|
|
|
|
list.add(head1);
|
|
|
|
list.put("head1", head1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//根据数据添加近excel
|
|
|
|
for (int i = 0; i < ytb.size(); i++) {
|
|
|
|
for (int i = 0; i < ytb.size(); i++) {
|
|
|
|
JSONArray js1 = JSONObject.parse(ytb.get(i).getTemplateJson()).getJSONArray("fields");
|
|
|
|
JSONArray js1 = JSONObject.parse(ytb.get(i).getTemplateJson()).getJSONArray("fields");
|
|
|
|
JSONArray op1 = JSONObject.parse(js1.get(0).toString()).getJSONArray("options");
|
|
|
|
//要添加的数据
|
|
|
|
if (i == 0) {
|
|
|
|
List<String> addData = new ArrayList<>();
|
|
|
|
for (Object s1 : op1) {
|
|
|
|
addData.add(ytb.get(i).getMatter());
|
|
|
|
List<String> head2 = new ArrayList<>();
|
|
|
|
addData.add(ytb.get(i).getCreditCode());
|
|
|
|
JSONObject parse = JSONObject.parse(s1.toString());
|
|
|
|
for (int i1 = 0; i1 < js1.size(); i1++) {
|
|
|
|
head2.add(parse.get("label").toString());
|
|
|
|
//获取每个组件
|
|
|
|
value1.add(parse.get("value").toString());
|
|
|
|
JSONObject lb = JSON.parseObject(js1.get(i1).toString());
|
|
|
|
list.add(head2);
|
|
|
|
if ("el-select".equals(lb.get("tag").toString()) || "el-radio-group".equals(lb.get("tag").toString())) {
|
|
|
|
}
|
|
|
|
List<String> head6 = new ArrayList<>();
|
|
|
|
}
|
|
|
|
head6.add(lb.get("label").toString());
|
|
|
|
JSONArray jsonArray = JSONObject.parse(js1.get(0).toString()).getJSONArray("defaultValue");
|
|
|
|
list.put("headi" + i1, head6);
|
|
|
|
for (Object o : jsonArray) {
|
|
|
|
JSONArray op1 = JSONObject.parse(js1.get(i1).toString()).getJSONArray("options");
|
|
|
|
int i1 = value1.indexOf(o.toString());
|
|
|
|
for (Object s1 : op1) {
|
|
|
|
if (i1 != -1) {
|
|
|
|
JSONObject parse = JSONObject.parse(s1.toString());
|
|
|
|
if (i1==0) {
|
|
|
|
if (parse.get("value").toString().equals(lb.get("defaultValue").toString())) {
|
|
|
|
data.add(Arrays.asList(ytb.get(i).getMatter(), ytb.get(i).getCreditCode(), "是", "", "", "", ""));
|
|
|
|
addData.add(parse.get("label").toString());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
if (i1==1) {
|
|
|
|
}
|
|
|
|
data.add(Arrays.asList(ytb.get(i).getMatter(), ytb.get(i).getCreditCode(), "", "是", "", "", ""));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ("el-checkbox-group".equals(lb.get("tag").toString())) {
|
|
|
|
if (i1==2) {
|
|
|
|
List<String> head7 = new ArrayList<>();
|
|
|
|
data.add(Arrays.asList(ytb.get(i).getMatter(), ytb.get(i).getCreditCode(), "", "", "是", "", ""));
|
|
|
|
head7.add(lb.get("label").toString());
|
|
|
|
}
|
|
|
|
list.put("headi" + i1, head7);
|
|
|
|
if (i1==3) {
|
|
|
|
JSONArray op1 = JSONObject.parse(js1.get(i1).toString()).getJSONArray("options");
|
|
|
|
data.add(Arrays.asList(ytb.get(i).getMatter(), ytb.get(i).getCreditCode(), "", "", "", "是", ""));
|
|
|
|
StringBuilder as = new StringBuilder();
|
|
|
|
}
|
|
|
|
JSONArray jsonArray = JSONObject.parse(js1.get(i1).toString()).getJSONArray("defaultValue");
|
|
|
|
if (i1==4) {
|
|
|
|
for (Object o : jsonArray) {
|
|
|
|
data.add(Arrays.asList(ytb.get(i).getMatter(), ytb.get(i).getCreditCode(), "", "", "", "", "是"));
|
|
|
|
for (Object s1 : op1) {
|
|
|
|
|
|
|
|
JSONObject parse = JSONObject.parse(s1.toString());
|
|
|
|
|
|
|
|
if(parse.get("value").toString().equals(o.toString())){
|
|
|
|
|
|
|
|
as.append(parse.get("label")).append(",");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addData.add(as.toString());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
List<String> head2 = new ArrayList<>();
|
|
|
|
|
|
|
|
head2.add(lb.get("label").toString());
|
|
|
|
|
|
|
|
list.put("head2" + i1, head2);
|
|
|
|
|
|
|
|
addData.add(lb.get("defaultValue").toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data.add(addData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Map.Entry<String, List<String>> st : list.entrySet()) {
|
|
|
|
|
|
|
|
final1.add(st.getValue());
|
|
|
|
String fileName = "数据导出" + ".xlsx";
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
fileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
|
|
|
|
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
|
|
|
throw new RuntimeException("文件名编码失败", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 创建 Excel 写入流
|
|
|
|
|
|
|
|
// 设置响应头,告诉浏览器下载文件
|
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
|
// 设置响应头,告诉浏览器下载文件
|
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
|
response.setContentType("application/vnd.ms-excel");
|
|
|
|
response.setHeader("Content-Disposition", "attachment; filename=data.xlsx");
|
|
|
|
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
|
|
|
|
try {
|
|
|
|
try (ServletOutputStream outputStream = response.getOutputStream()) {
|
|
|
|
ServletOutputStream outputStream = response.getOutputStream();
|
|
|
|
// 使用 EasyExcel 写数据到响应流
|
|
|
|
// 使用 EasyExcel 写数据到响应流
|
|
|
|
EasyExcel.write(outputStream)
|
|
|
|
EasyExcel.write(outputStream)
|
|
|
|
// 这里放入动态头
|
|
|
|
// 这里放入动态头
|
|
|
|
.head(list).sheet("模板")
|
|
|
|
.head(final1).sheet("模板")
|
|
|
|
// 当然这里数据也可以用 List<List<String>> 去传入
|
|
|
|
// 当然这里数据也可以用 List<List<String>> 去传入
|
|
|
|
.doWrite(data);
|
|
|
|
.doWrite(data);
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|