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> { ...@@ -176,9 +176,12 @@ public class BusDeviceController extends PaginationController<BusDevice> {
} }
@ApiOperation(value="参数库导出", notes="参数库导出功能,需要将页面上的名称、编号以json对象数组的形式传到后台") @ApiOperation(value="参数库导出", notes="参数库导出功能,需要将页面上的名称、编号以json对象数组的形式传到后台")
@ApiImplicitParams({
@ApiImplicitParam(name = "devNums", value = "devNums", required = true, dataType = "逗号分隔的devNum字符串,如:111,222,333")
})
@RequestMapping("/downloadExcel") @RequestMapping("/downloadExcel")
public void downloadExcel(HttpServletResponse response, @RequestBody List<DeviceParamsVo> list) { public void downloadExcel(HttpServletResponse response, @RequestParam String devNums) {
busDeviceServiceImpl.downloadExcel(response, list); busDeviceServiceImpl.downloadExcel(response, devNums);
} }
@ApiOperation(value="生成设备二维码", notes="生成设备二维码") @ApiOperation(value="生成设备二维码", notes="生成设备二维码")
......
...@@ -89,7 +89,7 @@ public interface BusDeviceService { ...@@ -89,7 +89,7 @@ public interface BusDeviceService {
* 参数库导出 * 参数库导出
* @param response * @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; ...@@ -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.service.BusDeviceService;
import org.rcisoft.business.device.assets.vo.DeviceAssetStatisticVo; import org.rcisoft.business.device.assets.vo.DeviceAssetStatisticVo;
import org.rcisoft.business.device.assets.vo.DeviceParamsVo; 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.dao.BusLibraryParamRepository;
import org.rcisoft.business.manage.entity.BusDevicetpParam; import org.rcisoft.business.manage.entity.BusDevicetpParam;
import org.rcisoft.business.manage.entity.BusLibraryParam; import org.rcisoft.business.manage.entity.BusLibraryParam;
...@@ -59,6 +61,8 @@ public class BusDeviceServiceImpl implements BusDeviceService { ...@@ -59,6 +61,8 @@ public class BusDeviceServiceImpl implements BusDeviceService {
private BusLibraryParamRepository busLibraryParamRepository; private BusLibraryParamRepository busLibraryParamRepository;
@Autowired @Autowired
private BusDevicetpParamService busDevicetpParamService; private BusDevicetpParamService busDevicetpParamService;
@Autowired
private ParamLibraryRepository paramLibraryRepository;
/** /**
* 二维码存放路径 * 二维码存放路径
...@@ -249,10 +253,10 @@ public class BusDeviceServiceImpl implements BusDeviceService { ...@@ -249,10 +253,10 @@ public class BusDeviceServiceImpl implements BusDeviceService {
} }
@Override @Override
public void downloadExcel(HttpServletResponse response, List<DeviceParamsVo> list) { public void downloadExcel(HttpServletResponse response, String devNums) {
try (OutputStream outputStream = response.getOutputStream()) { try (OutputStream outputStream = response.getOutputStream()) {
response.setHeader("Content-disposition", "attachment;filename=download.xls"); response.setHeader("Content-disposition", "attachment;filename=download.xls");
outputStream.write(this.createExcel(list)); outputStream.write(this.createExcel(devNums));
outputStream.flush(); outputStream.flush();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -289,23 +293,67 @@ public class BusDeviceServiceImpl implements BusDeviceService { ...@@ -289,23 +293,67 @@ public class BusDeviceServiceImpl implements BusDeviceService {
return new PersistModel(line,message); 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; HSSFWorkbook workbook = null;
try(ByteArrayOutputStream os = new ByteArrayOutputStream()) { try(ByteArrayOutputStream os = new ByteArrayOutputStream()) {
workbook = new HSSFWorkbook(); workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("sheet1"); // 拆分devNums
//表头 String[] numArray = devNums.split(",");
String[] title = new String[]{"名称", "编号"}; for (String devNum : numArray) {
HSSFRow title_row = sheet.createRow(0); int rowNum = 0;
for (int i = 0; i < title.length; i++) { //定义sheet
title_row.createCell(i, CellType.STRING).setCellValue(title[i]); HSSFSheet sheet = workbook.createSheet(devNum);
} //第一行:设备编号 + 年份
//内容 HSSFRow row_1 = sheet.createRow(rowNum++);
for (int i = 0; i < list.size(); i++) { row_1.createCell(0, CellType.STRING).setCellValue("设备编号");
HSSFRow row = sheet.createRow(i + 1); row_1.createCell(1, CellType.STRING).setCellValue(devNum);
DeviceParamsVo deviceParamsVo = list.get(i); row_1.createCell(3, CellType.STRING).setCellValue("年份");
row.createCell(0, CellType.STRING).setCellValue(deviceParamsVo.getName()); row_1.createCell(4, CellType.STRING).setCellValue(Calendar.getInstance().get(Calendar.YEAR));
row.createCell(1, CellType.STRING).setCellValue(deviceParamsVo.getNum()); //空一行
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); workbook.write(os);
return os.toByteArray(); 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