这里写自定义目录标题
欢迎使用Markdown编辑器
你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。
新的改变
import com.ruoyi.common.utils.poi.ExcelUtil;
//导入用POI 用POI 用POI 提醒自己三遍用POI 不要用jxl了
@RequestMapping(value = "/picUpload")
public Map<String, Object> upload(HttpServletRequest request, HttpServletResponse response) throws IOException {
String saveUrl = "/upload/website";//文件保存路径前缀 必须包含upload
saveUrl += "/mainPic/" + new SimpleDateFormat("yyyyMMdd").format(new Date()) + "/";
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
/** 页面控件的文件流* */
MultipartFile multipartFile = null;
Map map =multipartRequest.getFileMap();
for (Iterator i = map.keySet().iterator(); i.hasNext();) {
Object obj = i.next();
multipartFile=(MultipartFile) map.get(obj);
}
JSONObject json = new JSONObject();
try {
String fileName = multipartFile.getOriginalFilename();
String oldName = fileName;
String fileType = fileName.substring(fileName.indexOf(".") + 1);
// 生成随机字符串名,防止出现中文乱码的情况
int max=100,min=1;
int ran2 = (int) (Math.random()*(max-min)+min);
fileName = ran2 + "." + fileType;
File dest = new File(baseUrl + saveUrl + "/" + fileName);
if (!dest.getParentFile().exists()) { // 判断文件父目录是否存在
dest.getParentFile().mkdirs();
}
multipartFile.transferTo(dest); // 保存文件
//按照相应的json数据格式返回结果
json.put("newVersionName", fileName);
json.put("fileMd5", Files.hash(dest, Hashing.md5()).toString());
json.put("message", "应用上传成功");
json.put("status", true);
json.put("filePath", saveUrl + fileName);
InputStream is = new FileInputStream(dest);
Workbook hssfWorkbook = null;
if (fileName.endsWith("xlsx")){
hssfWorkbook = new XSSFWorkbook(is);//Excel 2007
}else if (fileName.endsWith("xls")){
hssfWorkbook = new HSSFWorkbook(is);//Excel 2003
}
// HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
// XSSFWorkbook hssfWorkbook = new XSSFWorkbook(is);
// 循环工作表Sheet
for (int numSheet = 0; numSheet <hssfWorkbook.getNumberOfSheets(); numSheet++) {
//HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
Sheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
if (hssfSheet == null) {
continue;
}
// 循环行Row
for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
//HSSFRow hssfRow = hssfSheet.getRow(rowNum);
Row hssfRow = hssfSheet.getRow(rowNum);
if (hssfRow != null) {
boolean b=true;
for (int i = 0; i < hssfRow.getRowNum(); i++) {
if (hssfRow.getCell(i)!=null) {
if (!hssfRow.getCell(i).toString().equals("")) {
b=false;
}
}
}
if (!b) {
Cell equipmentName = hssfRow.getCell(7);
Cell equipmentcode = hssfRow.getCell(12);
Cell circulationState = hssfRow.getCell(13);
Cell equipmentIP = hssfRow.getCell(6);
Cell name = hssfRow.getCell(1);
Cell office = hssfRow.getCell(0);
Cell companyClass = hssfRow.getCell(5);
Cell idcard = hssfRow.getCell(4);
Cell cellphone = hssfRow.getCell(2);
Cell phone = hssfRow.getCell(3);
Cell remark = hssfRow.getCell(14);
Cell kvmIf = hssfRow.getCell(8);
Cell keyboardIf = hssfRow.getCell(9);
Cell mouseIf = hssfRow.getCell(10);
Cell monitorIf = hssfRow.getCell(11);
ArrayList<String> array=new ArrayList<String>();
if (kvmIf.toString().equals("是")) {
array.add("kvmIf");
}
if (keyboardIf!=null&&keyboardIf.toString().equals("是")) {
array.add("keyboardIf");
}
if (mouseIf!=null&&mouseIf.toString().equals("是")) {
array.add("mouseIf");
}
if (monitorIf!=null&&monitorIf.toString().equals("是")) {
array.add("monitorIf");
}
String pphone="0";
if (phone!=null) {
pphone=phone.toString();
}
String[] strs1=array.toArray(new String[array.size()]);
//这里是自己的逻辑
String sremark="";
if (remark!=null) {
sremark = remark.toString();
}
addzzk(equipmentName==null? "":equipmentName.toString(), equipmentcode==null? "":equipmentcode.toString(), circulationState==null? "":circulationState.toString(), strs1, equipmentIP==null? "":equipmentIP.toString(), name==null? "":name.toString(), office==null? "":office.toString(), companyClass==null? "":companyClass.toString(), idcard==null? "":idcard.toString(),
cellphone==null? "":cellphone.toString(), Convert.toLong(pphone), sremark);
}
}
}
}
} catch (Exception e) {
json.put("status", false);
e.printStackTrace();
}
response.getWriter().print(json.toString());
return null;
}