|
@ -1,9 +1,12 @@
|
|
|
package com.yihu.wlyy.controller.manager.device;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JavaType;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.wlyy.controller.BaseController;
|
|
|
import com.yihu.wlyy.device.entity.WlyyDevice;
|
|
|
import com.yihu.wlyy.service.manager.device.WlyyDeviceService;
|
|
|
import jxl.Workbook;
|
|
|
import jxl.write.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Controller;
|
|
@ -12,6 +15,12 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* Created by yww on 2016/12/2.
|
|
|
* 设备管理
|
|
@ -131,4 +140,81 @@ public class WlyyDeviceController extends BaseController {
|
|
|
public String isCodeExist(String deviceCode) {
|
|
|
return deviceService.existDeviceCode(deviceCode);
|
|
|
}
|
|
|
|
|
|
|
|
|
//导出设备报表
|
|
|
@RequestMapping(value="toExcel",method = RequestMethod.POST,produces = "application/json;charset=UTF-8" )
|
|
|
public void exportList(
|
|
|
@RequestParam(value = "deviceName",required = false)String deviceName,
|
|
|
@RequestParam(value = "deviceCode",required = false) String deviceCode,
|
|
|
@RequestParam(value = "orgName",required = false)String orgName,
|
|
|
@RequestParam(value = "linkman",required = false) String linkman,
|
|
|
HttpServletResponse response){
|
|
|
try {
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
JavaType javaType = objectMapper.getTypeFactory().constructParametricType(ArrayList.class, WlyyDevice.class);
|
|
|
List<WlyyDevice> wlyyDevices = deviceService.exporthDeviceList(deviceName,deviceCode,orgName,linkman);
|
|
|
response.setContentType("octets/stream");
|
|
|
response.setHeader("Content-Disposition", "attachment; filename="+ new String( "deviceDataList.xls"));
|
|
|
OutputStream os = response.getOutputStream();
|
|
|
this.write(os,wlyyDevices);
|
|
|
}catch (Exception ex){
|
|
|
error(ex);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void addHeader(WritableSheet ws) throws WriteException {
|
|
|
|
|
|
String[] header = {"ID","设备名称","型号","SN码", "SIM卡号","机构名称", "联系人", "联系电话", "厂家名称"};
|
|
|
int i = 0;
|
|
|
for (String h : header) {
|
|
|
addCell(ws, 0, i, h);//表名,行,列,header
|
|
|
i++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void write(WritableWorkbook wwb, List ls) throws Exception {
|
|
|
try {
|
|
|
WritableSheet ws;
|
|
|
ws = wwb.createSheet("sheet",1);
|
|
|
addHeader(ws);
|
|
|
int i = 1;
|
|
|
for (WlyyDevice m : (List<WlyyDevice>) ls) {
|
|
|
addCell(ws, i, 0, m.getId()+"","");
|
|
|
addCell(ws, i, 1, m.getDeviceName(),"");
|
|
|
addCell(ws, i, 2, m.getDeviceModel(),"");
|
|
|
addCell(ws, i, 3, m.getDeviceCode(),"");
|
|
|
addCell(ws, i, 4, m.getSim()+"","");
|
|
|
addCell(ws, i, 5, m.getOrgName(),"");
|
|
|
addCell(ws, i, 6, m.getLinkman(),"");
|
|
|
addCell(ws, i, 7, m.getTel(),"");
|
|
|
addCell(ws, i, 8, m.getManufacturer(),"");
|
|
|
i++;
|
|
|
}
|
|
|
wwb.write();
|
|
|
wwb.close();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
if (wwb != null) wwb.close();
|
|
|
throw e;
|
|
|
}
|
|
|
}
|
|
|
public void write(OutputStream os, List ls) throws Exception{
|
|
|
write(Workbook.createWorkbook(os), ls);
|
|
|
};
|
|
|
//添加单元格内容
|
|
|
public void addCell(WritableSheet ws, int row, int column, String data) throws WriteException {
|
|
|
Label label = new Label(column ,row, data);
|
|
|
ws.addCell(label);
|
|
|
}
|
|
|
//添加单元格内容
|
|
|
public void addCell(WritableSheet ws, int row, int column, String data, String memo) throws WriteException {
|
|
|
Label label = new Label(column ,row, data);
|
|
|
if(!org.springframework.util.StringUtils.isEmpty(memo)){
|
|
|
WritableCellFeatures cellFeatures = new WritableCellFeatures();
|
|
|
cellFeatures.setComment(memo);
|
|
|
label.setCellFeatures(cellFeatures);
|
|
|
}
|
|
|
ws.addCell(label);
|
|
|
}
|
|
|
}
|