暂降事件
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.njcn.csdevice.controller.equipment;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
@@ -9,30 +11,34 @@ import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.csdevice.enums.DeviceOperate;
|
||||
import com.njcn.csdevice.pojo.dto.CsEquipmentDeliveryDTO;
|
||||
import com.njcn.csdevice.pojo.param.CsEquipmentDeliveryAddParm;
|
||||
import com.njcn.csdevice.pojo.param.CsEquipmentDeliveryAuditParm;
|
||||
import com.njcn.csdevice.pojo.param.CsEquipmentDeliveryQueryParm;
|
||||
import com.njcn.csdevice.pojo.param.ProjectEquipmentQueryParm;
|
||||
import com.njcn.csdevice.pojo.param.*;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import com.njcn.csdevice.pojo.vo.DeviceManagerVO;
|
||||
import com.njcn.csdevice.pojo.vo.ProjectEquipmentVO;
|
||||
import com.njcn.csdevice.service.CsEquipmentDeliveryService;
|
||||
import com.njcn.csdevice.service.IMqttUserService;
|
||||
import com.njcn.csdevice.utils.ExcelStyleUtil;
|
||||
import com.njcn.poi.excel.ExcelUtil;
|
||||
import com.njcn.poi.util.PoiUtil;
|
||||
|
||||
import com.njcn.web.advice.DeviceLog;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
@@ -190,4 +196,29 @@ public class EquipmentDeliveryController extends BaseController {
|
||||
}
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@ApiOperation("导出设备模板")
|
||||
@GetMapping(value = "getExcelTemplate")
|
||||
public HttpResult<String> getExcelTemplate(HttpServletResponse response) {
|
||||
String methodDescribe = getMethodDescribe("getExcelTemplate");
|
||||
|
||||
ExportParams exportParams = new ExportParams("批量导入模板(请严格按照模板标准填入数据)", "终端入网检测录入信息");
|
||||
exportParams.setStyle(ExcelStyleUtil.class);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, DeviceExcelTemplete.class, new ArrayList<DeviceExcelTemplete>());
|
||||
ExcelUtil.selectList(workbook, 2, 2, Stream.of("直连设备","网关设备").collect(Collectors.toList()).toArray(new String[]{}));
|
||||
ExcelUtil.selectList(workbook, 4, 4, Stream.of("mqtt","cloud").collect(Collectors.toList()).toArray(new String[]{}));
|
||||
String fileName = "设备模板.xlsx";
|
||||
ExportParams exportExcel = new ExportParams("设备模板", "设备模板");
|
||||
PoiUtil.exportFileByWorkbook(workbook, fileName, response);
|
||||
return null;
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@ApiOperation("excel批量导入设备信息")
|
||||
@PostMapping(value = "importEquipment")
|
||||
public HttpResult<String> importEquipment(@ApiParam(value = "文件", required = true) @RequestPart("file") MultipartFile file, HttpServletResponse response) {
|
||||
String methodDescribe = getMethodDescribe("importEquipment");
|
||||
csEquipmentDeliveryService.importEquipment(file, response);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import com.njcn.csdevice.pojo.vo.DeviceManagerVO;
|
||||
import com.njcn.csdevice.pojo.vo.ProjectEquipmentVO;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -89,4 +92,6 @@ public interface CsEquipmentDeliveryService extends IService<CsEquipmentDelivery
|
||||
* @return
|
||||
*/
|
||||
CsEquipmentDeliveryPO findDevByNDid(String nDid);
|
||||
|
||||
void importEquipment(MultipartFile file, HttpServletResponse response);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package com.njcn.csdevice.service.impl;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
|
||||
import cn.hutool.core.text.StrPool;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
@@ -24,16 +30,22 @@ import com.njcn.csdevice.util.QRCodeUtil;
|
||||
import com.njcn.db.constant.DbConstant;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import com.njcn.poi.util.PoiUtil;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.api.DictTreeFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.pojo.vo.DictTreeVO;
|
||||
import com.njcn.web.factory.PageFactory;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -74,6 +86,7 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
|
||||
private final FileStorageUtil fileStorageUtil;
|
||||
private final DictTreeFeignClient dictTreeFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@@ -86,18 +99,12 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
BeanUtils.copyProperties (csEquipmentDeliveryAddParm,csEquipmentDeliveryPo);
|
||||
csEquipmentDeliveryPo.setStatus ("1");
|
||||
csEquipmentDeliveryPo.setRunStatus(1);
|
||||
csEquipmentDeliveryPo.setProcess(1);
|
||||
|
||||
//生成二维码文件
|
||||
try {
|
||||
QrParam qrParam = new QrParam();
|
||||
qrParam.setData(csEquipmentDeliveryAddParm.getNdid());
|
||||
BufferedImage bufferedImage = QRCodeUtil.getBufferedImage(JSONObject.toJSONString(qrParam));
|
||||
InputStream inputStream = bufferedImageToInputStream(bufferedImage);
|
||||
String fileName = csEquipmentDeliveryAddParm.getNdid() + ".png";
|
||||
String filePath = fileStorageUtil.uploadStream(inputStream,OssPath.APP_DEVICE_QR,fileName);
|
||||
csEquipmentDeliveryPo.setQrPath(filePath);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String qr = this.createQr(csEquipmentDeliveryAddParm.getNdid());
|
||||
csEquipmentDeliveryPo.setQrPath(qr);
|
||||
|
||||
return this.save (csEquipmentDeliveryPo);
|
||||
}
|
||||
|
||||
@@ -311,6 +318,115 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
return this.lambdaQuery().eq(CsEquipmentDeliveryPO::getNdid,nDid).one();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void importEquipment(MultipartFile file, HttpServletResponse response) {
|
||||
ImportParams params = new ImportParams ( );
|
||||
params.setHeadRows(1);
|
||||
params.setTitleRows(1);
|
||||
//第一个sheet为台账信息
|
||||
params.setStartSheetIndex(0);
|
||||
params.setSheetNum(1);
|
||||
try {
|
||||
ExcelImportResult<DeviceExcelTemplete> terminalBaseList = ExcelImportUtil.importExcelMore (file.getInputStream ( ), DeviceExcelTemplete.class, params);
|
||||
//如果存在非法数据,将不合格的数据导出
|
||||
List<DeviceExcelTemplete> trueCollect = new ArrayList<> ( );
|
||||
List<DeviceExcelTemplete.IllegalityDeviceExcelTemplete> falseCollect = new ArrayList<> ( );
|
||||
|
||||
for (int i = 0; i < terminalBaseList.getList ( ).size ( ); i++) {
|
||||
DeviceExcelTemplete deviceExcelTemplete = terminalBaseList.getList ( ).get (i);
|
||||
CsEquipmentDeliveryPO po = this.queryEquipmentPOByndid (deviceExcelTemplete.getNdid ( ));
|
||||
if(!Objects.isNull (po)){
|
||||
DeviceExcelTemplete.IllegalityDeviceExcelTemplete idlegalityDeviceException = new DeviceExcelTemplete.IllegalityDeviceExcelTemplete();
|
||||
BeanUtils.copyProperties(deviceExcelTemplete,idlegalityDeviceException);
|
||||
idlegalityDeviceException.setMsg("NDID重复");
|
||||
falseCollect.add(idlegalityDeviceException);
|
||||
}
|
||||
if(Objects.equals(deviceExcelTemplete.getDevType(),DicDataEnum.GATEWAY_DEV.getName())){
|
||||
DictTreeVO data = dictTreeFeignClient.queryByCode(DicDataEnum.GATEWAY_DEV.getCode()).getData();
|
||||
deviceExcelTemplete.setDevType(data.getId());
|
||||
List<DictTreeVO> data1 = dictTreeFeignClient.query(data.getId()).getData();
|
||||
Map<String, DictTreeVO> collect = data1.stream().collect(Collectors.toMap(DictTreeVO::getCode, dictTreeVO -> dictTreeVO));
|
||||
if(collect.containsKey(deviceExcelTemplete.getDevModel())){
|
||||
deviceExcelTemplete.setDevModel(collect.get(deviceExcelTemplete.getDevModel()).getId());
|
||||
trueCollect.add(deviceExcelTemplete);
|
||||
}else {
|
||||
DeviceExcelTemplete.IllegalityDeviceExcelTemplete idlegalityDeviceException = new DeviceExcelTemplete.IllegalityDeviceExcelTemplete();
|
||||
BeanUtils.copyProperties(deviceExcelTemplete,idlegalityDeviceException);
|
||||
idlegalityDeviceException.setMsg("装置型号不正确");
|
||||
falseCollect.add(idlegalityDeviceException);
|
||||
}
|
||||
} else if (Objects.equals(deviceExcelTemplete.getDevType(),DicDataEnum.CONNECT_DEV.getName())) {
|
||||
DictTreeVO data = dictTreeFeignClient.queryByCode(DicDataEnum.CONNECT_DEV.getCode()).getData();
|
||||
deviceExcelTemplete.setDevType(data.getId());
|
||||
List<DictTreeVO> data1 = dictTreeFeignClient.query(data.getId()).getData();
|
||||
Map<String, DictTreeVO> collect = data1.stream().collect(Collectors.toMap(DictTreeVO::getCode, dictTreeVO -> dictTreeVO));
|
||||
if(collect.containsKey(deviceExcelTemplete.getDevModel())){
|
||||
deviceExcelTemplete.setDevModel(collect.get(deviceExcelTemplete.getDevModel()).getId());
|
||||
trueCollect.add(deviceExcelTemplete);
|
||||
}else {
|
||||
DeviceExcelTemplete.IllegalityDeviceExcelTemplete idlegalityDeviceException = new DeviceExcelTemplete.IllegalityDeviceExcelTemplete();
|
||||
BeanUtils.copyProperties(deviceExcelTemplete,idlegalityDeviceException);
|
||||
idlegalityDeviceException.setMsg("装置型号不正确");
|
||||
falseCollect.add(idlegalityDeviceException);
|
||||
}
|
||||
}else {
|
||||
DeviceExcelTemplete.IllegalityDeviceExcelTemplete idlegalityDeviceException = new DeviceExcelTemplete.IllegalityDeviceExcelTemplete();
|
||||
BeanUtils.copyProperties(deviceExcelTemplete,idlegalityDeviceException);
|
||||
idlegalityDeviceException.setMsg("装置类型不正确");
|
||||
falseCollect.add(idlegalityDeviceException);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if (!CollectionUtils.isEmpty (trueCollect)) {
|
||||
List<CsEquipmentDeliveryPO> collect = trueCollect.stream ( ).map (temp -> {
|
||||
CsEquipmentDeliveryPO csEquipmentDeliveryPO = new CsEquipmentDeliveryPO ( );
|
||||
BeanUtils.copyProperties (temp, csEquipmentDeliveryPO);
|
||||
String qr = this.createQr(temp.getNdid());
|
||||
csEquipmentDeliveryPO.setQrPath(qr);
|
||||
String path = this.createPath(temp.getNdid());
|
||||
csEquipmentDeliveryPO.setMac(path);
|
||||
csEquipmentDeliveryPO.setRunStatus(1);
|
||||
csEquipmentDeliveryPO.setStatus("1");
|
||||
csEquipmentDeliveryPO.setProcess(1);
|
||||
return csEquipmentDeliveryPO;
|
||||
}).collect (Collectors.toList ( ));
|
||||
this.saveOrUpdateBatch (collect, 500);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty (falseCollect)) {
|
||||
ExportParams exportExcel = new ExportParams ("批量导入模板(请严格按照模板标准填入数据)", "非法设备信息");
|
||||
Workbook workbook = ExcelExportUtil.exportExcel (exportExcel, DeviceExcelTemplete.IllegalityDeviceExcelTemplete.class, falseCollect);
|
||||
PoiUtil.exportFileByWorkbook (workbook, "非法设备信息.xlsx", response);
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace ( );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ndid生成二维码
|
||||
* @param ndid
|
||||
* @return
|
||||
*/
|
||||
private String createQr(String ndid){
|
||||
String filePath ="";
|
||||
//生成二维码文件
|
||||
try {
|
||||
QrParam qrParam = new QrParam();
|
||||
qrParam.setData(ndid);
|
||||
BufferedImage bufferedImage = QRCodeUtil.getBufferedImage(JSONObject.toJSONString(qrParam));
|
||||
InputStream inputStream = bufferedImageToInputStream(bufferedImage);
|
||||
String fileName = ndid + ".png";
|
||||
filePath = fileStorageUtil.uploadStream(inputStream,OssPath.APP_DEVICE_QR,fileName);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return filePath;
|
||||
|
||||
}
|
||||
|
||||
public InputStream bufferedImageToInputStream(BufferedImage image) {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
try {
|
||||
@@ -322,4 +438,25 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/*将ndid转成mac地址*/
|
||||
public String createPath(String nDid) {
|
||||
// 使用StringBuilder来构建新的字符串
|
||||
StringBuilder output = new StringBuilder();
|
||||
// 遍历输入字符串,每两个字符分割并添加冒号
|
||||
for (int i = 0; i < nDid.length(); i += 2) {
|
||||
if (i > 0) {
|
||||
//添加冒号分隔符
|
||||
output.append(StrPool.COLON);
|
||||
}
|
||||
if (i + 1 < nDid.length()) {
|
||||
// 检查是否有足够的字符来分割成两组
|
||||
// 每两个字符添加到新字符串
|
||||
output.append(nDid.substring(i, i + 2));
|
||||
} else {
|
||||
// 如果只剩一个字符,可以根据需要添加处理逻辑
|
||||
output.append(nDid.charAt(i));
|
||||
}
|
||||
}
|
||||
return output.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> i
|
||||
public DevDetailDTO queryDevDetail(String devId) {
|
||||
DevDetailDTO device = new DevDetailDTO();
|
||||
CsLedger dev = this.findDataById(devId);
|
||||
device.setEquipmentName(dev.getId());
|
||||
device.setEquipmentName(dev.getName());
|
||||
device.setEquipmentId(devId);
|
||||
CsLedger project = this.findDataById(dev.getPid());
|
||||
device.setProjectId(project.getId());
|
||||
|
||||
Reference in New Issue
Block a user