Browse Source

添加值班日志的导出相关接口

zhongwei
tyty 2 years ago
parent
commit
0fc8c9d43d
  1. 11
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/controller/ImsDutyRecController.java
  2. 6
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/IImsAnalyseExampleService.java
  3. 89
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsAnalyseExampleServiceImpl.java
  4. 2
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyMainServiceImpl.java
  5. 2
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyRecServiceImpl.java

11
hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/controller/ImsDutyRecController.java

@ -31,6 +31,7 @@ import org.springblade.flow.core.entity.BladeFlow;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
@ -268,6 +269,16 @@ public class ImsDutyRecController extends BladeController {
public R queryAnalyseExampleData( AnalyzeDataCondition analyzeDataCondition) {
return iImsAnalyseExampleService.queryAnalyseExampleData(analyzeDataCondition);
}
/**
* 导出分析实例数据
*/
@PostMapping("/outPutAnalyseExampleData")
@ApiOperationSupport(order = 6)
@ApiOperation(value = "导出分析实例数据", notes = "传入analyseExample")
public void outPutAnalyseExampleData(HttpServletResponse response, @Valid @RequestBody AnalyzeDataCondition analyzeDataCondition) {
iImsAnalyseExampleService.outPutAnalyseExampleData(response, analyzeDataCondition);
}
/**
* 查询分析实例模板

6
hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/IImsAnalyseExampleService.java

@ -6,6 +6,8 @@ import org.springblade.core.mp.base.BaseService;
import org.springblade.core.tool.api.R;
import org.springblade.core.mp.support.Query;
import javax.servlet.http.HttpServletResponse;
/**
* 服务类
*
@ -14,8 +16,6 @@ import org.springblade.core.mp.support.Query;
public interface IImsAnalyseExampleService extends BaseService<AnalyseExample> {
R queryAnalyseExampleData(AnalyzeDataCondition analyzeDataCondition);
R queryAnalyseExample(AnalyseExample analyseExample,Query query);
@ -23,4 +23,6 @@ public interface IImsAnalyseExampleService extends BaseService<AnalyseExample> {
R getAnalyseId(String projectId);
R updateAnalyseExample(AnalyseExample analyseExample);
void outPutAnalyseExampleData(HttpServletResponse response, AnalyzeDataCondition analyzeDataCondition);
}

89
hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsAnalyseExampleServiceImpl.java

@ -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();

2
hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyMainServiceImpl.java

@ -176,7 +176,7 @@ public class ImsDutyMainServiceImpl extends BaseServiceImpl<ImsDutyMainMapper, I
if (null == imsSchedulingVo.getGroupId()) {
imsSchedulingVo.setGroupName("临时班组");
ImsDutyMainPersonEntity imsDutyMainPersonEntity = imsDutyMainPersonMapper.selectOne(new LambdaQueryWrapper<ImsDutyMainPersonEntity>() {{
eq(ImsDutyMainPersonEntity::getDutyMainId, id);
eq(ImsDutyMainPersonEntity::getDutyMainId, imsSchedulingVo.getId());
last("limit 1");
}});
imsSchedulingVo.setManagerId(imsDutyMainPersonEntity.getDutyChargePerson());

2
hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyRecServiceImpl.java

@ -338,6 +338,8 @@ public class ImsDutyRecServiceImpl extends BaseServiceImpl<ImsDutyRecMapper, Ims
ImsDutyMainPersonEntity personEntity = imsDutyMainPersonService.getOne(new LambdaQueryWrapper<ImsDutyMainPersonEntity>() {{
eq(ImsDutyMainPersonEntity::getDutyMainId, entity.getId());
eq(ImsDutyMainPersonEntity::getDutyChargePerson, AuthUtil.getUserId());
last(" limit 1");
}});
if (ObjectUtil.isEmpty(groupEntity)&&ObjectUtil.isEmpty(personEntity)) {
return R.success("您不是该班组负责人,不可交班!");

Loading…
Cancel
Save