新增物接入流程
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
package com.njcn.access.config;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.OAuthBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.*;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spi.service.contexts.SecurityContext;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/4/3 9:03
|
||||
*/
|
||||
@Configuration
|
||||
public class SwaggerConfig {
|
||||
|
||||
@Value("${microservice.gateway.url}")
|
||||
private String gatewayUrl;
|
||||
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
|
||||
List<GrantType> grantTypes = new ArrayList<>();
|
||||
String passwordTokenUrl = "http://" + gatewayUrl + "/pqs-auth/oauth/token";
|
||||
ResourceOwnerPasswordCredentialsGrant resourceOwnerPasswordCredentialsGrant = new ResourceOwnerPasswordCredentialsGrant(passwordTokenUrl);
|
||||
grantTypes.add(resourceOwnerPasswordCredentialsGrant);
|
||||
OAuth oAuth = new OAuthBuilder().name("oauth2").grantTypes(grantTypes).build();
|
||||
//schemas
|
||||
List<SecurityScheme> securitySchemes = Lists.newArrayList(oAuth);
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.groupName("物联网注册服务")
|
||||
.apiInfo(apiInfo())
|
||||
.enable(true)
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.njcn.access.controller"))
|
||||
.paths(PathSelectors.any())
|
||||
.build()
|
||||
.securityContexts(securityContexts())
|
||||
.securitySchemes(securitySchemes);
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("物接入")
|
||||
.description("物接入接口文档")
|
||||
.version("1.0")
|
||||
.contact(contact())
|
||||
.build();
|
||||
}
|
||||
|
||||
private List<SecurityContext> securityContexts() {
|
||||
List<SecurityContext> securityContexts = new ArrayList<>();
|
||||
securityContexts.add(
|
||||
SecurityContext.builder()
|
||||
.securityReferences(defaultAuth())
|
||||
.forPaths(PathSelectors.ant("/**"))
|
||||
.build());
|
||||
return securityContexts;
|
||||
}
|
||||
|
||||
List<SecurityReference> defaultAuth() {
|
||||
//scope方位
|
||||
List<AuthorizationScope> scopes = new ArrayList<>();
|
||||
scopes.add(new AuthorizationScope("read", "read resources"));
|
||||
scopes.add(new AuthorizationScope("write", "write resources"));
|
||||
scopes.add(new AuthorizationScope("reads", "read all resources"));
|
||||
scopes.add(new AuthorizationScope("writes", "write all resources"));
|
||||
SecurityReference securityReference = new SecurityReference("oauth2", scopes.toArray(new AuthorizationScope[]{}));
|
||||
List<SecurityReference> securityReferences = new ArrayList<>();
|
||||
securityReferences.add(securityReference);
|
||||
return securityReferences;
|
||||
}
|
||||
|
||||
private Contact contact() {
|
||||
return new Contact("灿能系统组", "", "13914774158@163.com");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.njcn.access.controller;
|
||||
|
||||
import com.njcn.access.service.IAccessService;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/3/31 9:12
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/devAccess")
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "装置接入")
|
||||
public class AccessController extends BaseController {
|
||||
|
||||
private final IAccessService accessService;
|
||||
|
||||
@PostMapping("/add")
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@ApiOperation("平台发起注册")
|
||||
@ApiImplicitParam(name = "nDid", value = "网关识别码", required = true)
|
||||
public HttpResult<Object> add(@RequestParam String nDid){
|
||||
log.info("设备向装置侧发起注册请求,请求的nDid为:" + nDid);
|
||||
String methodDescribe = getMethodDescribe("add");
|
||||
LogUtil.njcnDebug(log, "{},设备向装置侧发起注册请求,请求的nDid为:{}", methodDescribe, nDid);
|
||||
accessService.add(nDid);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.njcn.access.controller;
|
||||
|
||||
import com.njcn.access.pojo.param.DevModelParam;
|
||||
import com.njcn.access.service.IDevModelService;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
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.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/4/10 10:26
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/devModel")
|
||||
@AllArgsConstructor
|
||||
@Validated
|
||||
@Api(tags = "装置模板录入")
|
||||
public class DevModelController extends BaseController {
|
||||
|
||||
private final IDevModelService devModelService;
|
||||
|
||||
@PostMapping("/add")
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@ApiOperation("装置录入模板")
|
||||
public HttpResult<String> add(DevModelParam devModelParam){
|
||||
log.info("装置录入模板文件");
|
||||
String methodDescribe = getMethodDescribe("add");
|
||||
LogUtil.njcnDebug(log, "{},装置录入模板文件", methodDescribe);
|
||||
return devModelService.add(devModelParam);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.njcn.access.handler;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.github.tocrhz.mqtt.annotation.MqttSubscribe;
|
||||
import com.github.tocrhz.mqtt.annotation.NamedValue;
|
||||
import com.github.tocrhz.mqtt.annotation.Payload;
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.access.pojo.dto.*;
|
||||
import com.njcn.algorithm.api.DevModelFeignClient;
|
||||
import com.njcn.algorithm.api.EquipmentFeignClient;
|
||||
import com.njcn.algorithm.pojo.param.CsDevModelQueryListParm;
|
||||
import com.njcn.algorithm.pojo.vo.CsDevModelPageVO;
|
||||
import com.njcn.algorithm.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2022年03月23日 09:41
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class MqttMessageHandler {
|
||||
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
|
||||
private final DevModelFeignClient devModelFeignClient;
|
||||
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
|
||||
private final MqttPublisher publisher;
|
||||
|
||||
private final RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 接收装置接入响应
|
||||
* 1.收到注册信息,修改装置出厂表,装置的状态,调整为注册;然后开始接入流程
|
||||
* 2.询问当前装置类型的模板。有则完成接入;没有则告警出来,需要人工手动上传模板信息
|
||||
* @param topic
|
||||
* @param message
|
||||
* @param payload
|
||||
*/
|
||||
@MqttSubscribe(value = "/device/register/{nDid}",qos = 1)
|
||||
public void devOperation(String topic, MqttMessage message, @NamedValue("nDid") String nDid, @Payload String payload){
|
||||
Gson gson = new Gson();
|
||||
RegisterDTO.RegisterResponse registerDTO = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), RegisterDTO.RegisterResponse.class);
|
||||
if (registerDTO.getCode() == 200){
|
||||
//todo 调整装置出厂表状态
|
||||
|
||||
|
||||
PublicDto publicDto = new PublicDto();
|
||||
publicDto.setMid(Long.toString(Instant.now().toEpochMilli()));
|
||||
publicDto.setNDid(nDid);
|
||||
publicDto.setTimestamp(Instant.now().toEpochMilli());
|
||||
publicDto.setType("CMD_DEV_DATA");
|
||||
AccessDto accessDto = new AccessDto();
|
||||
accessDto.setNDid(nDid);
|
||||
accessDto.setDevType(registerDTO.getParam().getDev_type());
|
||||
publicDto.setParam(accessDto);
|
||||
publisher.send("/platform/devcmd/"+nDid,new Gson().toJson(publicDto),1,false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 装置类型模板相应
|
||||
* 1.判断网关的类型
|
||||
* 2.直联设备的DevCfg和DevMod是以直联设备为准,上送平台端,平台端保存。通过校验DevMod模板信息来从平台端模板池中选取对应的模板,如果找不到匹配模板需告警提示人工干预处理。
|
||||
* 3.平台端需读取装置的DevMod来判断网关支持的设备模板(包含设备型号和模板版本),根据app提交的接入子设备DID匹配数据模板(型号及版本),生成DevCfg下发给网关,网关根据下发信息生成就地设备点表。
|
||||
* @param topic
|
||||
* @param message
|
||||
* @param nDid
|
||||
* @param payload
|
||||
*/
|
||||
@MqttSubscribe(value = "/device/devack/{nDid}",qos = 1)
|
||||
public void devModelOperation(String topic, MqttMessage message, @NamedValue("nDid") String nDid, @Payload String payload){
|
||||
Gson gson = new Gson();
|
||||
ModelDto modelDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ModelDto.class);
|
||||
HttpResult<CsEquipmentDeliveryVO> pojo = equipmentFeignClient.queryEquipmentByndid(nDid);
|
||||
if (!Objects.isNull(pojo)){
|
||||
String devType = pojo.getData().getDevType();
|
||||
if (Objects.equals(devType,"直连设备")){
|
||||
List<DevModelDto> list = modelDto.getDevMod();
|
||||
list.forEach(item->{
|
||||
//todo 根据条件查询库中是否有符合条件的数据
|
||||
DictData dicData = dicDataFeignClient.getDicDataByCode(item.getDevType()).getData();
|
||||
CsDevModelQueryListParm csDevModelQueryListParm = new CsDevModelQueryListParm();
|
||||
if (Objects.isNull(dicData)) {
|
||||
log.info("新增模板失败,获取装置类型字典数据为空,请先录入装置类型!");
|
||||
return;
|
||||
} else {
|
||||
csDevModelQueryListParm.setDevType( dicData.getId());
|
||||
}
|
||||
csDevModelQueryListParm.setVersionNo(item.getVersionNo());
|
||||
csDevModelQueryListParm.setVersionDate(item.getVersionDate());
|
||||
CsDevModelPageVO csDevModelPageVO = devModelFeignClient.queryDevModelOne(csDevModelQueryListParm).getData();
|
||||
if (Objects.isNull(csDevModelPageVO)){
|
||||
log.info("模板不存在,请先录入模板数据!");
|
||||
return;
|
||||
} else {
|
||||
//todo 录入装置和模板的关系表
|
||||
System.out.println("录入装置和模板的关系表");
|
||||
}
|
||||
});
|
||||
} else if (Objects.equals(devType,"网关")){
|
||||
//todo 处理待定
|
||||
System.out.println("网关设备判断");
|
||||
}
|
||||
} else {
|
||||
log.info("通过nDid未找到相关装置信息");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.quality.mapper.DataGroupMapper">
|
||||
|
||||
|
||||
<select id="getGroupDataList" resultType="DataGroupTemplateVO">
|
||||
select id,pid,name,sort,1 as level from ele_data_group
|
||||
where pid = #{id}
|
||||
order by sort
|
||||
</select>
|
||||
|
||||
<select id="getGroupList" resultType="DataGroupTemplateVO">
|
||||
select id,pid,name,sort from ele_data_group
|
||||
where pid = #{id}
|
||||
order by sort
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.access.service;
|
||||
|
||||
/**
|
||||
* @author 徐扬
|
||||
*/
|
||||
public interface IAccessService {
|
||||
|
||||
/**
|
||||
* 设备注册(1.判断此装置是否完成出厂设置 2.判断此装置是否能正常通讯)
|
||||
* 1.根据nDid获取装置的信息(设备型号、网关识别码)
|
||||
* 2.发送MQTT信息给装置
|
||||
* 3.装置响应则修改装置状态;3分钟未响应则生成告警信息
|
||||
* @param nDid 网关识别码
|
||||
*/
|
||||
void add(String nDid);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.njcn.access.service;
|
||||
|
||||
import com.njcn.access.pojo.param.DevModelParam;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
public interface IDevModelService {
|
||||
|
||||
/**
|
||||
* 直连装置录入模板信息
|
||||
* 1.解析模板文件,将数据录入库中
|
||||
* 2.将文件上传至文件服务器保存起来,先以装置型号-版本号-时间作为名称名称
|
||||
* @param devModelParam 模板文件参数
|
||||
*/
|
||||
HttpResult<String> add(DevModelParam devModelParam);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.njcn.access.service.serviceImpl;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.access.pojo.dto.AccessDto;
|
||||
import com.njcn.access.pojo.dto.PublicDto;
|
||||
import com.njcn.access.service.IAccessService;
|
||||
import com.njcn.algorithm.api.EquipmentFeignClient;
|
||||
import com.njcn.algorithm.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/3/31 9:21
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class AccessServiceImpl implements IAccessService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AccessServiceImpl.class);
|
||||
|
||||
private final MqttPublisher publisher;
|
||||
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
|
||||
@Override
|
||||
public void add(String nDid) {
|
||||
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
|
||||
if (Objects.isNull(vo)){
|
||||
logger.error("平台侧无此网关信息,请先录入!");
|
||||
return;
|
||||
}
|
||||
PublicDto publicDto = new PublicDto();
|
||||
publicDto.setMid(Long.toString(Instant.now().toEpochMilli()));
|
||||
publicDto.setNDid(nDid);
|
||||
publicDto.setTimestamp(Instant.now().toEpochMilli());
|
||||
publicDto.setType("CMD_DEV_REGISTER");
|
||||
AccessDto accessDto = new AccessDto();
|
||||
accessDto.setNDid(nDid);
|
||||
accessDto.setDevType(vo.getDevModel());
|
||||
publicDto.setParam(accessDto);
|
||||
publisher.send("/platform/register/"+nDid,new Gson().toJson(publicDto),1,false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.njcn.access.service.serviceImpl;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.njcn.access.enums.AccessResponseEnum;
|
||||
import com.njcn.access.pojo.dto.devModel.*;
|
||||
import com.njcn.access.pojo.param.DevModelParam;
|
||||
import com.njcn.access.service.IDevModelService;
|
||||
import com.njcn.access.utils.JsonUtil;
|
||||
import com.njcn.algorithm.api.DevModelFeignClient;
|
||||
import com.njcn.algorithm.pojo.param.CsDevModelAddParm;
|
||||
import com.njcn.algorithm.pojo.param.CsDevModelQueryListParm;
|
||||
import com.njcn.algorithm.pojo.vo.CsDevModelPageVO;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/4/10 10:37
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class DevModelServiceImpl implements IDevModelService {
|
||||
|
||||
private final FileStorageUtil fileStorageUtil;
|
||||
|
||||
private final DevModelFeignClient devModelFeignClient;
|
||||
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public HttpResult<String> add(DevModelParam devModelParam) {
|
||||
String json = null;
|
||||
try {
|
||||
json = JsonUtil.convertStreamToString(devModelParam.getFile().getInputStream());
|
||||
|
||||
Gson gson = new Gson();
|
||||
TemplateDto templateDto = gson.fromJson(json, TemplateDto.class);
|
||||
ParamDto pojo = templateDto.getParam();
|
||||
//网关模板
|
||||
NetDevModDto po1 = pojo.getDataArray().get(0).getTemplate().getNetDevModDto();
|
||||
//装置信息模板
|
||||
DevCfgDetailDto po2 = pojo.getDataArray().get(0).getTemplate().getDevCfgDetailDto();
|
||||
//装置数据模板
|
||||
List<DevModDetailDto> po3 = pojo.getDataArray().get(0).getTemplate().getDevModDetailDto();
|
||||
|
||||
String name = po3.get(0).getName();
|
||||
String version = po3.get(0).getVersion();
|
||||
String time = po3.get(0).getTime();
|
||||
String devType = po3.get(0).getDevType();
|
||||
String devTypeId = "";
|
||||
|
||||
DictData dicData = dicDataFeignClient.getDicDataByCode(devType).getData();
|
||||
if (Objects.isNull(dicData)) {
|
||||
log.info("新增模板失败,获取装置类型字典数据为空,请先录入装置类型!");
|
||||
return HttpResultUtil.assembleResult(CommonResponseEnum.NO_DATA.getCode(), null, "获取装置类型字典数据为空!");
|
||||
} else {
|
||||
devTypeId = dicData.getId();
|
||||
}
|
||||
CsDevModelQueryListParm csDevModelQueryListParm = new CsDevModelQueryListParm();
|
||||
csDevModelQueryListParm.setDevType(devTypeId);
|
||||
csDevModelQueryListParm.setVersionNo(version);
|
||||
csDevModelQueryListParm.setVersionDate(time);
|
||||
csDevModelQueryListParm.setName(name);
|
||||
CsDevModelPageVO vo = devModelFeignClient.queryDevModelOne(csDevModelQueryListParm).getData();
|
||||
if (!Objects.isNull(vo)){
|
||||
log.info("新增模板失败,新增的模板在库中存在!");
|
||||
return HttpResultUtil.assembleResult(AccessResponseEnum.MODEL_REPEAT.getCode(), null, AccessResponseEnum.MODEL_REPEAT.getMessage());
|
||||
} else {
|
||||
CsDevModelAddParm csDevModelAddParm = new CsDevModelAddParm();
|
||||
csDevModelAddParm.setName(name);
|
||||
csDevModelAddParm.setDevType(devTypeId);
|
||||
csDevModelAddParm.setVersionNo(version);
|
||||
csDevModelAddParm.setVersionDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(time));
|
||||
String filePath = fileStorageUtil.uploadMultipart(devModelParam.getFile(), OssPath.DEV_MODEL + devModelParam.getDevType() + "_");
|
||||
log.info("文件路径为:" + filePath);
|
||||
csDevModelAddParm.setFilePath(filePath);
|
||||
//新增cs_dev_model表数据
|
||||
devModelFeignClient.addDevModel(csDevModelAddParm);
|
||||
//新增cs_data_set
|
||||
|
||||
//新增cs_data_array
|
||||
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("文件转成json出现异常");
|
||||
e.getMessage();
|
||||
} catch (ParseException e) {
|
||||
log.error("时间转换出现异常");
|
||||
e.getMessage();
|
||||
}
|
||||
return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), null, CommonResponseEnum.SUCCESS.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.njcn.access.utils;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/4/10 16:03
|
||||
*/
|
||||
public class JsonUtil {
|
||||
|
||||
/**
|
||||
* @param jsonString 要保存的JSON串
|
||||
* @param filePath 保存到的文件路径
|
||||
* @param fileName 文件名称
|
||||
* @return
|
||||
*/
|
||||
//保存json 文件
|
||||
public static boolean createJsonFile(String jsonString, String filePath, String fileName) {
|
||||
// 标记文件生成是否成功
|
||||
boolean flag = true;
|
||||
// 拼接文件完整路径
|
||||
String fullPath = filePath + File.separator + fileName + ".json";
|
||||
// 生成json格式文件
|
||||
try {
|
||||
// 保证创建一个新文件
|
||||
File file = new File(fullPath);
|
||||
// 如果父目录不存在,创建父目录
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
// 如果已存在,删除旧文件
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
file.createNewFile();
|
||||
// 格式化json字符串
|
||||
//jsonString = JsonFormatTool.formatJson2(jsonString);
|
||||
// 将格式化后的字符串写入文件
|
||||
Writer write = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8);
|
||||
write.write(jsonString);
|
||||
write.flush();
|
||||
write.close();
|
||||
} catch (Exception e) {
|
||||
flag = false;
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 返回是否成功的标记
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成随机文件名:当前年月日时分秒+五位随机数
|
||||
* @return
|
||||
*/
|
||||
public static String getRandomFileName() {
|
||||
SimpleDateFormat simpleDateFormat;
|
||||
simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||
Date date = new Date();
|
||||
String str = simpleDateFormat.format(date);
|
||||
Random random = new Random();
|
||||
// 获取5位随机数
|
||||
int ranNum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 10000;
|
||||
// 当前时间
|
||||
return ranNum + str;
|
||||
}
|
||||
|
||||
public static String convertStreamToString(InputStream inputStream){
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line = null;
|
||||
try {
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,7 +36,6 @@ spring:
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
|
||||
|
||||
#项目日志的配置
|
||||
logging:
|
||||
config: http://@nacos.url@/nacos/v1/cs/configs?tenant=@nacos.namespace@&group=DEFAULT_GROUP&dataId=logback.xml
|
||||
|
||||
Reference in New Issue
Block a user