模板导入功能

This commit is contained in:
2023-07-28 16:32:01 +08:00
parent 623df5b9b4
commit acf4ebb33d
19 changed files with 70 additions and 39 deletions

View File

@@ -14,10 +14,8 @@ import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
/**
* 类的介绍:
@@ -38,10 +36,9 @@ public class CsDevModelController extends BaseController {
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/addModel")
@ApiOperation("新增设备模板")
@ApiImplicitParam(name = "devModelParam", value = "设备模板参数", required = true)
public HttpResult<String> addModel(@RequestBody @Validated DevModelParam devModelParam){
public HttpResult<String> addModel(@RequestPart("file") @Validated MultipartFile file){
String methodDescribe = getMethodDescribe("addModel");
csDevModelService.addModel(devModelParam);
csDevModelService.addModel(file);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}

View File

@@ -1,6 +1,6 @@
package com.njcn.access.service;
import com.njcn.access.pojo.param.DevModelParam;
import org.springframework.web.multipart.MultipartFile;
/**
* 类的介绍:
@@ -14,8 +14,8 @@ public interface ICsDevModelService {
/**
* 解析模板文件->入库
* @param devModelParam
* @param file
*/
void addModel(DevModelParam devModelParam);
void addModel(MultipartFile file);
}

View File

@@ -2,15 +2,22 @@ package com.njcn.access.service.impl;
import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.njcn.access.pojo.dto.devModel.TemplateDto;
import com.njcn.access.pojo.param.DevModelParam;
import com.njcn.access.service.ICsDevModelService;
import com.njcn.access.utils.JsonUtil;
import com.njcn.oss.constant.OssPath;
import com.njcn.csdevice.api.DevModelFeignClient;
import com.njcn.csdevice.pojo.param.CsDevModelAddParm;
import com.njcn.csdevice.pojo.po.CsDevModelPO;
import com.njcn.oss.utils.FileStorageUtil;
import com.njcn.system.api.DictTreeFeignClient;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.sql.Date;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* 类的介绍:
@@ -25,20 +32,44 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
private final FileStorageUtil fileStorageUtil;
private final DevModelFeignClient devModelFeignClient;
private final DictTreeFeignClient dictTreeFeignClient;
@Override
public void addModel(DevModelParam devModelParam) {
@Transactional(rollbackFor = Exception.class)
public void addModel(MultipartFile file) {
String json = null;
try {
json = JsonUtil.convertStreamToString(devModelParam.getFile().getInputStream());
json = JsonUtil.convertStreamToString(file.getInputStream());
Gson gson = new Gson();
TemplateDto templateDto = gson.fromJson(json, TemplateDto.class);
//模板文件存入文件服务器
//String filePath = fileStorageUtil.uploadMultipart(devModelParam.getFile(), OssPath.DEV_MODEL + devModelParam.getDevType() + "_");
String filePath = "";
System.out.println("templateDto==:" + templateDto);
//1.录入cs_dev_model表记录装置型号和模板记录
addCsDevModel(templateDto,filePath);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 新增cs_dev_model数据
*/
private CsDevModelPO addCsDevModel(TemplateDto templateDto, String filePath){
CsDevModelAddParm csDevModelAddParm = new CsDevModelAddParm();
csDevModelAddParm.setDevTypeName(templateDto.getDevType());
csDevModelAddParm.setName(templateDto.getDevType());
csDevModelAddParm.setVersionNo(templateDto.getVersion());
csDevModelAddParm.setTime(templateDto.getTime());
csDevModelAddParm.setFilePath(filePath);
CsDevModelPO csDevModel = devModelFeignClient.addDevModel(csDevModelAddParm).getData();
return csDevModel;
}
}

View File

@@ -88,7 +88,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
}
//3.判断客户端是否在线
//mqttUtil.judgeClientOnline(nDid);
boolean mqttClient = mqttUtil.judgeClientOnline("access-boot123456");
boolean mqttClient = mqttUtil.judgeClientOnline("access-boot1234567");
if (!mqttClient){
throw new BusinessException(AccessResponseEnum.MISSING_CLIENT);
}

View File

@@ -33,8 +33,6 @@ spring:
refresh: true
- data-Id: algorithm-config.yaml
refresh: true
- data-Id: kafka-config.yaml
refresh: true
main:
allow-bean-definition-overriding: true
@@ -52,4 +50,4 @@ mybatis-plus:
mqtt:
client-id: access-boot123456
client-id: access-boot1234567