|
|
|
@ -1,16 +1,22 @@
|
|
|
|
|
package com.hnac.hzims.operational.duty.service.impl; |
|
|
|
|
|
|
|
|
|
import com.alibaba.druid.support.json.JSONUtils; |
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
|
import com.alibaba.excel.ExcelWriter; |
|
|
|
|
import com.alibaba.excel.converters.longconverter.LongStringConverter; |
|
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet; |
|
|
|
|
import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.hnac.hzims.operational.duty.entity.AnalyseExample; |
|
|
|
|
import com.hnac.hzims.operational.duty.mapper.ImsAnalyseExampleMapper; |
|
|
|
|
import com.hnac.hzims.operational.duty.mapper.ImsDutyMainMapper; |
|
|
|
|
import com.hnac.hzims.operational.duty.service.IImsAnalyseExampleService; |
|
|
|
|
import com.hnac.hzims.operational.station.entity.StationEntity; |
|
|
|
|
import com.hnac.hzims.operational.station.feign.StationClient; |
|
|
|
|
import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; |
|
|
|
|
import com.hnac.hzinfo.datasearch.analyse.domain.AnalyzeDataCondition; |
|
|
|
|
import com.hnac.hzinfo.datasearch.analyse.domain.AnalyzeDataList; |
|
|
|
|
import com.hnac.hzinfo.datasearch.analyse.domain.FieldsData; |
|
|
|
|
import com.hnac.hzinfo.sdk.core.response.HzPage; |
|
|
|
|
import com.hnac.hzinfo.sdk.core.response.Result; |
|
|
|
|
import com.hnac.hzinfo.sdk.v5.analyse.AnalyseDataHandlerClient; |
|
|
|
@ -18,16 +24,20 @@ import com.hnac.hzinfo.sdk.v5.analyse.vo.AnalseInstanceVO;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import net.logstash.logback.encoder.org.apache.commons.lang3.ObjectUtils; |
|
|
|
|
import net.logstash.logback.encoder.org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
import org.springblade.core.mp.support.Condition; |
|
|
|
|
import org.springblade.core.mp.support.Query; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.utils.DateUtil; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.net.URLEncoder; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -38,8 +48,6 @@ import java.util.List;
|
|
|
|
|
@Slf4j |
|
|
|
|
@Service |
|
|
|
|
public class ImsAnalyseExampleServiceImpl extends BaseServiceImpl<ImsAnalyseExampleMapper, AnalyseExample> implements IImsAnalyseExampleService { |
|
|
|
|
@Resource |
|
|
|
|
private ImsDutyMainMapper imsDutyMainMapper; |
|
|
|
|
@Autowired |
|
|
|
|
private IAnalyseDataSearchClient searchClient; |
|
|
|
|
@Autowired |
|
|
|
@ -119,6 +127,75 @@ public class ImsAnalyseExampleServiceImpl extends BaseServiceImpl<ImsAnalyseExam
|
|
|
|
|
return R.success("保存成功"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void outPutAnalyseExampleData(HttpServletResponse response, AnalyzeDataCondition analyzeDataCondition) { |
|
|
|
|
try { |
|
|
|
|
R analyseExampleData =queryAnalyseExampleData(analyzeDataCondition); |
|
|
|
|
String name="值班日志"; |
|
|
|
|
if(ObjectUtils.isEmpty(analyzeDataCondition.getBeginTime())){ |
|
|
|
|
String format = DateUtil.format(analyzeDataCondition.getBeginTime(), DateUtil.PATTERN_DATE); |
|
|
|
|
name=format+name; |
|
|
|
|
} |
|
|
|
|
HzPage<AnalyzeDataList> page = (HzPage<AnalyzeDataList>) analyseExampleData.getData(); |
|
|
|
|
response.setContentType("application/vnd.ms-excel"); |
|
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
|
// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
|
|
|
|
|
String fileName = URLEncoder.encode( name, "UTF-8"); |
|
|
|
|
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); |
|
|
|
|
if(page.getRecords()!=null){ |
|
|
|
|
List<List<String>> head=new ArrayList<>(); |
|
|
|
|
List<String> title = new ArrayList<>(Arrays.asList("时间")); |
|
|
|
|
head.add(title); |
|
|
|
|
List<AnalyzeDataList> records = page.getRecords(); |
|
|
|
|
AnalyzeDataList analyzeDataList = records.get(0); |
|
|
|
|
//把时间加属性名称作为表头
|
|
|
|
|
List<String> stringList=analyzeDataList.getFields().stream().map(FieldsData::getFieldName).collect(Collectors.toList()); |
|
|
|
|
for (String s : stringList) { |
|
|
|
|
head.add(Arrays.asList(s)); |
|
|
|
|
} |
|
|
|
|
//把数据填充
|
|
|
|
|
List<List<String>> data=new ArrayList<>(); |
|
|
|
|
for (int i = 0; i < records.size(); i++) { |
|
|
|
|
List<String> arrayData=new ArrayList<>(); |
|
|
|
|
String date = DateUtil.format(records.get(i).getTs(), DateUtil.PATTERN_DATETIME); |
|
|
|
|
arrayData.add(date); |
|
|
|
|
List<String> dataBefore = records.get(i).getFields().stream().map(FieldsData::getValue).collect(Collectors.toList()); |
|
|
|
|
arrayData.addAll(dataBefore); |
|
|
|
|
data.add(arrayData); |
|
|
|
|
} |
|
|
|
|
System.out.println("---------------- 数据详情 = " + records.toString()); |
|
|
|
|
//ExcelWriter初始化
|
|
|
|
|
ExcelWriter excelWriter = EasyExcel |
|
|
|
|
.write(response.getOutputStream()) |
|
|
|
|
.autoCloseStream(Boolean.TRUE) |
|
|
|
|
.registerConverter(new LongStringConverter()) |
|
|
|
|
.registerWriteHandler(new SimpleColumnWidthStyleStrategy(45)) |
|
|
|
|
.build(); |
|
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet(1, "值班日志").head(head).build(); |
|
|
|
|
excelWriter.write(data, writeSheet); |
|
|
|
|
// 这里需要设置关闭流
|
|
|
|
|
excelWriter.finish(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
System.out.println("exportExcel = " + e.toString()); |
|
|
|
|
// 重置response
|
|
|
|
|
response.reset(); |
|
|
|
|
response.setContentType("application/json"); |
|
|
|
|
response.setCharacterEncoding("utf-8"); |
|
|
|
|
Map<String, String> map = new HashMap<>(); |
|
|
|
|
map.put("success", "false"); |
|
|
|
|
map.put("msg", "值班日志信息导出失败" + e.getMessage()); |
|
|
|
|
try { |
|
|
|
|
response.getWriter().println(JSONUtils.toJSONString(map)); |
|
|
|
|
} catch (IOException e3) { |
|
|
|
|
throw new ServiceException( "发生异常 :" + e.toString()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private QueryWrapper<AnalyseExample> getQueryWrapper(AnalyseExample analyseExample) { |
|
|
|
|
QueryWrapper<AnalyseExample> queryWrapper = new QueryWrapper(); |
|
|
|
|