Commit 323e93a9 authored by zengtianlai3's avatar zengtianlai3

修改excel的格式和错误信息提示

parent b101cb1f
...@@ -5,6 +5,7 @@ import iot.sixiang.license.model.vo.ResourceVo; ...@@ -5,6 +5,7 @@ import iot.sixiang.license.model.vo.ResourceVo;
import iot.sixiang.license.service.ResourceService; import iot.sixiang.license.service.ResourceService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.*; import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -39,11 +40,21 @@ public class ResourceManager { ...@@ -39,11 +40,21 @@ public class ResourceManager {
//第二步创建sheet //第二步创建sheet
HSSFSheet sheet = wb.createSheet(); HSSFSheet sheet = wb.createSheet();
wb.setSheetName(0, sheetName); wb.setSheetName(0, sheetName);
sheet.setDefaultColumnWidth(20); // sheet.setDefaultColumnWidth(20);
//设置表格格式 //设置首行格式
HSSFCellStyle styleRow = wb.createCellStyle();
HSSFFont font1 = wb.createFont();
font1.setFontName("宋体");
font1.setBold(true);//粗体显示
styleRow.setFont(font1);//选择须要用到的字体格式
styleRow.setAlignment(HorizontalAlignment.CENTER); //居中
//设置单元格格式
HSSFCellStyle style = wb.createCellStyle(); HSSFCellStyle style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER); //居中 style.setAlignment(HorizontalAlignment.CENTER); //居中
Font font = wb.createFont();
font.setFontName("宋体");
style.setFont(font);
//第三步创建行row:添加表头0行 //第三步创建行row:添加表头0行
HSSFRow row = sheet.createRow((short)0); HSSFRow row = sheet.createRow((short)0);
...@@ -51,23 +62,23 @@ public class ResourceManager { ...@@ -51,23 +62,23 @@ public class ResourceManager {
//第四步创建单元格 //第四步创建单元格
HSSFCell cell = row.createCell((short)0); //第一个单元格 HSSFCell cell = row.createCell((short)0); //第一个单元格
cell.setCellValue("公司名称"); cell.setCellValue("公司名称");
cell.setCellStyle(style); cell.setCellStyle(styleRow);
cell = row.createCell((short)1); //第二个单元格 cell = row.createCell((short)1); //第二个单元格
cell.setCellValue("应用名称"); cell.setCellValue("应用名称");
cell.setCellStyle(style); cell.setCellStyle(styleRow);
cell = row.createCell((short)2); //第三个单元格 cell = row.createCell((short)2); //第三个单元格
cell.setCellValue("app_id"); cell.setCellValue("app_id");
cell.setCellStyle(style); cell.setCellStyle(styleRow);
cell = row.createCell((short)3); //第四个单元格 cell = row.createCell((short)3); //第四个单元格
cell.setCellValue("app_key"); cell.setCellValue("app_key");
cell.setCellStyle(style); cell.setCellStyle(styleRow);
cell = row.createCell((short)4); //第五个单元格 cell = row.createCell((short)4); //第五个单元格
cell.setCellValue("sn"); cell.setCellValue("sn");
cell.setCellStyle(style); cell.setCellStyle(styleRow);
//第五步插入数据 //第五步插入数据
List<ResourceVo> resourceList = resourceService.getResource(userId); List<ResourceVo> resourceList = resourceService.getResource(userId);
for (int i = 0; i < resourceList.size(); i++) { for (int i = 0; i < resourceList.size(); i++) {
...@@ -96,11 +107,10 @@ public class ResourceManager { ...@@ -96,11 +107,10 @@ public class ResourceManager {
cell.setCellValue(resourceVo.getSn()); cell.setCellValue(resourceVo.getSn());
cell.setCellStyle(style); cell.setCellStyle(style);
} }
sheet.autoSizeColumn((short)0); //调整第一列宽度 //在填完所有值以后,对每一列设置自适应宽度
sheet.autoSizeColumn((short)1); //调整第二列宽度 for (int n = 0; n < 5; n++) {
sheet.autoSizeColumn((short)2); //调整第三列宽度 sheet.autoSizeColumn(n);
sheet.autoSizeColumn((short)3); //调整第四列宽度 }
sheet.autoSizeColumn((short)4); //调整第五列宽度
wb.write(os); wb.write(os);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -41,7 +41,7 @@ public class ApplyServiceImpl extends ServiceImpl<ApplyMapper, Apply> implements ...@@ -41,7 +41,7 @@ public class ApplyServiceImpl extends ServiceImpl<ApplyMapper, Apply> implements
} }
Apply res = applyMapper.getApplyByAppName(appName); Apply res = applyMapper.getApplyByAppName(appName);
if (res != null) { if (res != null) {
throw new IotLicenseException(ResultCode.FAILED.getCode(),ResultCode.FAILED.getMsg()); throw new IotLicenseException(403, "应用名已存在");
} }
String appId = CommonUtil.genRandomNum(18).toLowerCase(); String appId = CommonUtil.genRandomNum(18).toLowerCase();
boolean re = applyMapper.addApply(appId, appName, appKey, userId); boolean re = applyMapper.addApply(appId, appName, appKey, userId);
......
...@@ -56,7 +56,7 @@ public class DeviceBlackServiceImpl extends ServiceImpl<DeviceBlackMapper, Devic ...@@ -56,7 +56,7 @@ public class DeviceBlackServiceImpl extends ServiceImpl<DeviceBlackMapper, Devic
} }
} }
if (!flag) { if (!flag) {
throw new IotLicenseException(ResultCode.FAILED.getCode(),ResultCode.FAILED.getMsg()); throw new IotLicenseException(403, "设备不存在");
} }
boolean res = deviceBlackMapper.addDeviceBlack(deviceId); boolean res = deviceBlackMapper.addDeviceBlack(deviceId);
if (res) { if (res) {
......
...@@ -66,7 +66,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us ...@@ -66,7 +66,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
} }
User res = userMapper.getUserByUserName(userName); User res = userMapper.getUserByUserName(userName);
if (res != null) { if (res != null) {
throw new IotLicenseException(ResultCode.FAILED.getCode(),ResultCode.FAILED.getMsg()); throw new IotLicenseException(403, "用户名已存在");
} }
return userMapper.addUser(userName,company,password); return userMapper.addUser(userName,company,password);
} }
......
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