|
@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
-import com.sky.ioc.entity.domain.device.DeviceMessage;
|
|
|
import com.sky.ioc.entity.domain.device.DeviceType;
|
|
|
import com.sky.ioc.entity.domain.device.SecurityDevice;
|
|
|
import com.sky.ioc.mapper.device.DeviceTypeMapper;
|
|
@@ -14,10 +13,21 @@ import com.sky.ioc.mapper.device.SecurityDeviceMapper;
|
|
|
import com.sky.ioc.service.device.DeviceTypeService;
|
|
|
import com.sky.ioc.tool.ReturnMsg;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -110,8 +120,65 @@ public class DeviceTypeServiceImpl implements DeviceTypeService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ReturnMsg importDeviceType(String group) {
|
|
|
- return null;
|
|
|
+ public ReturnMsg importDeviceType(MultipartFile file,String group_id) throws IOException {
|
|
|
+ String fileName = file.getOriginalFilename();//文件名称
|
|
|
+ String suffixName = fileName.substring(fileName.lastIndexOf("."));//文件后缀名
|
|
|
+ //创建上传的工作表
|
|
|
+ InputStream inputStream = file.getInputStream();
|
|
|
+ Workbook workbook = null;
|
|
|
+ if(suffixName.equals(".xls")){
|
|
|
+ workbook = new HSSFWorkbook(inputStream);
|
|
|
+ }else if(suffixName.equals(".xlsx")){
|
|
|
+ workbook = new XSSFWorkbook(inputStream);
|
|
|
+ }else{
|
|
|
+ return ReturnMsg.fail("文件格式不正确");
|
|
|
+ }
|
|
|
+ if(workbook!=null){
|
|
|
+ //读取数据
|
|
|
+ Sheet sheet = null; //表
|
|
|
+ Row row = null;//行
|
|
|
+ Cell cell = null;//单元格
|
|
|
+ List<Map<String,Object>> data = new ArrayList<>();//存放读取的内容
|
|
|
+ int number = workbook.getNumberOfSheets();
|
|
|
+ for (int i = 0; i < number ; i++) { //遍历sheets
|
|
|
+ sheet = workbook.getSheetAt(i);
|
|
|
+ int rownum = sheet.getLastRowNum()+1;
|
|
|
+ for (int j = 1; j < rownum; j++) {//遍历sheet的row 忽略第一行表头
|
|
|
+ //表格内容
|
|
|
+ row = sheet.getRow(j);
|
|
|
+ if (row==null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String id = row.getCell(0).toString();
|
|
|
+ String device_name = row.getCell(1).toString();
|
|
|
+ String device_id = row.getCell(2).toString();
|
|
|
+ double device_type = row.getCell(3).getNumericCellValue();
|
|
|
+ String device_location = row.getCell(4).toString();
|
|
|
+ String loop_detail = row.getCell(5).toString();
|
|
|
+ String gateway_code = row.getCell(6).toString();
|
|
|
+ String gateway_ip = row.getCell(7).toString();
|
|
|
+ String usage = row.getCell(8).toString();
|
|
|
+ double status = row.getCell(9).getNumericCellValue();
|
|
|
+ SecurityDevice securityDevice = new SecurityDevice();
|
|
|
+ securityDevice.setDevice_id(device_id);
|
|
|
+ securityDevice.setDevice_name(device_name);
|
|
|
+ securityDevice.setDevice_type((int) device_type);
|
|
|
+ securityDevice.setDevice_location(device_location);
|
|
|
+ securityDevice.setLoop_detail(loop_detail);
|
|
|
+ securityDevice.setGateway_code(gateway_code);
|
|
|
+ securityDevice.setGateway_ip(gateway_ip);
|
|
|
+ securityDevice.setUsage(usage);
|
|
|
+ securityDevice.setStatus((int) status);
|
|
|
+ securityDeviceMapper.insert(securityDevice);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return ReturnMsg.ok(data);
|
|
|
+ }else{
|
|
|
+ return ReturnMsg.fail("Excel工作簿为空");
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|