Commit 372a228a authored by 王夏晖's avatar 王夏晖

Merge remote-tracking branch 'origin/develop' into develop

parents f398625d d2be8d64
......@@ -176,9 +176,12 @@ public class BusDeviceController extends PaginationController<BusDevice> {
}
@ApiOperation(value="参数库导出", notes="参数库导出功能,需要将页面上的名称、编号以json对象数组的形式传到后台")
@ApiImplicitParams({
@ApiImplicitParam(name = "devNums", value = "devNums", required = true, dataType = "逗号分隔的devNum字符串,如:111,222,333")
})
@RequestMapping("/downloadExcel")
public void downloadExcel(HttpServletResponse response, @RequestBody List<DeviceParamsVo> list) {
busDeviceServiceImpl.downloadExcel(response, list);
public void downloadExcel(HttpServletResponse response, @RequestParam String devNums) {
busDeviceServiceImpl.downloadExcel(response, devNums);
}
@ApiOperation(value="生成设备二维码", notes="生成设备二维码")
......
......@@ -89,7 +89,7 @@ public interface BusDeviceService {
* 参数库导出
* @param response
*/
void downloadExcel(HttpServletResponse response, List<DeviceParamsVo> list);
void downloadExcel(HttpServletResponse response, String devNums);
/**
* 生成设备二维码
......
......@@ -9,6 +9,8 @@ import org.rcisoft.business.device.assets.dao.BusDeviceRepository;
import org.rcisoft.business.device.assets.service.BusDeviceService;
import org.rcisoft.business.device.assets.vo.DeviceAssetStatisticVo;
import org.rcisoft.business.device.assets.vo.DeviceParamsVo;
import org.rcisoft.business.mainte.paramlibrary.dao.ParamLibraryRepository;
import org.rcisoft.business.mainte.paramlibrary.entity.BusParamLibrary;
import org.rcisoft.business.manage.dao.BusLibraryParamRepository;
import org.rcisoft.business.manage.entity.BusDevicetpParam;
import org.rcisoft.business.manage.entity.BusLibraryParam;
......@@ -59,6 +61,8 @@ public class BusDeviceServiceImpl implements BusDeviceService {
private BusLibraryParamRepository busLibraryParamRepository;
@Autowired
private BusDevicetpParamService busDevicetpParamService;
@Autowired
private ParamLibraryRepository paramLibraryRepository;
/**
* 二维码存放路径
......@@ -249,10 +253,10 @@ public class BusDeviceServiceImpl implements BusDeviceService {
}
@Override
public void downloadExcel(HttpServletResponse response, List<DeviceParamsVo> list) {
public void downloadExcel(HttpServletResponse response, String devNums) {
try (OutputStream outputStream = response.getOutputStream()) {
response.setHeader("Content-disposition", "attachment;filename=download.xls");
outputStream.write(this.createExcel(list));
outputStream.write(this.createExcel(devNums));
outputStream.flush();
} catch (IOException e) {
e.printStackTrace();
......@@ -289,23 +293,67 @@ public class BusDeviceServiceImpl implements BusDeviceService {
return new PersistModel(line,message);
}
private byte[] createExcel(List<DeviceParamsVo> list) throws IOException {
private byte[] createExcel(String devNums) throws IOException {
int year = Calendar.getInstance().get(Calendar.YEAR);
HSSFWorkbook workbook = null;
try(ByteArrayOutputStream os = new ByteArrayOutputStream()) {
workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("sheet1");
//表头
String[] title = new String[]{"名称", "编号"};
HSSFRow title_row = sheet.createRow(0);
for (int i = 0; i < title.length; i++) {
title_row.createCell(i, CellType.STRING).setCellValue(title[i]);
}
//内容
for (int i = 0; i < list.size(); i++) {
HSSFRow row = sheet.createRow(i + 1);
DeviceParamsVo deviceParamsVo = list.get(i);
row.createCell(0, CellType.STRING).setCellValue(deviceParamsVo.getName());
row.createCell(1, CellType.STRING).setCellValue(deviceParamsVo.getNum());
// 拆分devNums
String[] numArray = devNums.split(",");
for (String devNum : numArray) {
int rowNum = 0;
//定义sheet
HSSFSheet sheet = workbook.createSheet(devNum);
//第一行:设备编号 + 年份
HSSFRow row_1 = sheet.createRow(rowNum++);
row_1.createCell(0, CellType.STRING).setCellValue("设备编号");
row_1.createCell(1, CellType.STRING).setCellValue(devNum);
row_1.createCell(3, CellType.STRING).setCellValue("年份");
row_1.createCell(4, CellType.STRING).setCellValue(Calendar.getInstance().get(Calendar.YEAR));
//空一行
rowNum++;
// 第三行:参数、参数名称、参数编码
String[] title_3 = new String[]{"参数", "名称", "编码"};
HSSFRow row_3 = sheet.createRow(rowNum++);
for (int i = 0; i < title_3.length; i++) {
row_3.createCell(i, CellType.STRING).setCellValue(title_3[i]);
}
//循环参数列表
List<Map<String, String>> paramsList = busLibraryParamRepository.selectParamsByDevNum(devNum);
int size = paramsList.size();
for (int i = 0; i < size; i++) {
Map<String, String> param = paramsList.get(i);
HSSFRow row = sheet.createRow(rowNum++);
row.createCell(0, CellType.STRING).setCellValue(i + 1);//编号
row.createCell(1, CellType.STRING).setCellValue(param.get("paramNm"));//参数名称
row.createCell(2, CellType.STRING).setCellValue(param.get("param"));//参数编码
}
//空一行
rowNum = rowNum + 1 + 3 - size;
//添加参数值表头列
HSSFRow row_next = sheet.createRow(rowNum);
row_next.createCell(0, CellType.STRING).setCellValue("参数值列表");
row_next.createCell(1, CellType.STRING).setCellValue("功率(kw)");
row_next.createCell(2, CellType.STRING).setCellValue("用气速率(m3/h)");
for (int i = 0; i < size; i++) {
row_next.createCell(3 + i, CellType.STRING).setCellValue("参数" + (i + 1) + "值");
}
//查询参数库列表
Example example = new Example(BusParamLibrary.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("devNum", devNum);
criteria.andEqualTo("year", year);
List<BusParamLibrary> list = paramLibraryRepository.selectByExample(example);
//循环放入当前sheet
rowNum++;
for (BusParamLibrary busParamLibrary : list) {
HSSFRow row = sheet.createRow(rowNum++);
row.createCell(1, CellType.STRING).setCellValue(busParamLibrary.getPower() == null ? "" : busParamLibrary.getPower().toString());
row.createCell(2, CellType.STRING).setCellValue(busParamLibrary.getGasSpeed() == null ? "" : busParamLibrary.getGasSpeed().toString());
row.createCell(3, CellType.STRING).setCellValue(busParamLibrary.getP1V() == null ? "" : busParamLibrary.getP1V().toString());
row.createCell(4, CellType.STRING).setCellValue(busParamLibrary.getP2V() == null ? "" : busParamLibrary.getP2V().toString());
row.createCell(5, CellType.STRING).setCellValue(busParamLibrary.getP3V() == null ? "" : busParamLibrary.getP3V().toString());
}
}
workbook.write(os);
return os.toByteArray();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment