Browse Source

Merge remote-tracking branch 'origin/prod-5.1.3' into prod-5.1.3

zhongwei
luyie 2 months ago
parent
commit
4502ac747d
  1. 8
      hzims-service/equipment/src/main/java/com/hnac/hzims/electric/controller/ElectricReportController.java
  2. 2
      hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/IElectricReportService.java
  3. 91
      hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/impl/ElectricReportServiceImpl.java
  4. 2
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/database/service/WeaviateService.java

8
hzims-service/equipment/src/main/java/com/hnac/hzims/electric/controller/ElectricReportController.java

@ -68,4 +68,12 @@ public class ElectricReportController extends BladeController {
public R<Map<String,Object>> run(@RequestBody RunParamVo param) { public R<Map<String,Object>> run(@RequestBody RunParamVo param) {
return R.data(service.run(param)); return R.data(service.run(param));
} }
@PostMapping("/run/export")
@ApiOperationSupport(order = 6)
@ApiOperation(value = "综合报表导出", notes = "传入 deptId、year")
public void runExport(HttpServletResponse response,
@RequestBody RunParamVo param) {
service.runExport(response,param);
}
} }

2
hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/IElectricReportService.java

@ -22,4 +22,6 @@ public interface IElectricReportService {
void comprehensiveExport(HttpServletResponse response, Long deptId, String year); void comprehensiveExport(HttpServletResponse response, Long deptId, String year);
Map<String,Object> run(RunParamVo param); Map<String,Object> run(RunParamVo param);
void runExport(HttpServletResponse response, RunParamVo param);
} }

91
hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/impl/ElectricReportServiceImpl.java

@ -1660,4 +1660,95 @@ public class ElectricReportServiceImpl implements IElectricReportService {
table.put("tableDate",tableDates); table.put("tableDate",tableDates);
return table; return table;
} }
/**
* 运行报表导出
* @param response
* @param param
*/
@Override
public void runExport(HttpServletResponse response, RunParamVo param) {
Map<String, Object> runs = this.run(param);
if(MapUtils.isEmpty(runs)){
throw new ServiceException("暂无可进行导出报表!");
}
// 创建Excel文件
HSSFWorkbook hssWB = new HSSFWorkbook();
// 添加sheet页
HSSFSheet sheet = hssWB.createSheet("运行报表");
// 行高
sheet.setDefaultRowHeight((short) (20 * 25));
// 列宽
sheet.setDefaultColumnWidth(15);
// 填充数据
List<Object> tableHeads = JSONObject.parseArray(JSONObject.toJSONString(runs.get("tableHead")),Object.class);
List<List<Object>> tableBodys = JSON.parseObject(JSONObject.toJSONString(runs.get("tableDate")), new TypeReference<List<List<Object>>>() {});
// 表头
this.setRunHeader(hssWB, sheet,tableHeads);
if (!CollectionUtil.isEmpty(tableBodys)) {
// 数据填充
this.setRunWork(hssWB, sheet, tableBodys);
}
// 下载导出
String filename = param.getTime() + "日_运行报表";
// 设置头信息
response.setCharacterEncoding("UTF-8");
response.setContentType("application/vnd.ms-excel");
ServletOutputStream outputStream;
try {
//设置xlsx格式
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename + ".xls", "UTF-8"));
//创建一个输出流
outputStream = response.getOutputStream();
//写入数据
hssWB.write(outputStream);
// 关闭
outputStream.close();
hssWB.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 运行报表表头
* @param hssWB
* @param sheet
* @param tableHeads
*/
private void setRunHeader(HSSFWorkbook hssWB, HSSFSheet sheet, List<Object> tableHeads) {
// 第一行
int size = tableHeads.size();
HSSFRow row = sheet.createRow(0);
// 下标从0开始,所以要减1
this.setTitileStyle(hssWB, row, size - 1 , true);
for (int i = 0; i < size; i++) {
HSSFCell heade_cell = row.getCell(i);
heade_cell.setCellValue(tableHeads.get(i).toString());
}
}
/**
* 运行报表内容
* @param hssWB
* @param sheet
* @param tableBodys
*/
private void setRunWork(HSSFWorkbook hssWB, HSSFSheet sheet, List<List<Object>> tableBodys) {
// 第一行
int rowIndex = 1;
// 下标从0开始,所以要减1
for(List<Object> bodys : tableBodys){
HSSFRow bodyRow = sheet.createRow(rowIndex);
// 下标从0开始,所以要减1
this.setTitileStyle(hssWB, bodyRow, bodys.size() - 1, false);
// 内容填充
for(int i = 0; i < bodys.size() ; i++){
HSSFCell body_cell = bodyRow.getCell(i);
body_cell.setCellValue(bodys.get(i).toString());
}
rowIndex++;
}
}
} }

2
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/database/service/WeaviateService.java

@ -167,8 +167,8 @@ public class WeaviateService {
// 将entity转换为Map<String,String> // 将entity转换为Map<String,String>
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(entity, SerializerFeature.WriteMapNullValue)); JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(entity, SerializerFeature.WriteMapNullValue));
Map<String,Object> map = new HashMap<>(); Map<String,Object> map = new HashMap<>();
data.add(this.getVectorData(map,attrsMap));
jsonObject.forEach((k,v) -> map.put(k,jsonObject.get(k))); jsonObject.forEach((k,v) -> map.put(k,jsonObject.get(k)));
data.add(this.getVectorData(map,attrsMap));
}); });
params.put("data",data); params.put("data",data);
String url = gglmUrl + invokeApi.getInsertVectors(); String url = gglmUrl + invokeApi.getInsertVectors();

Loading…
Cancel
Save