日志记录调整
This commit is contained in:
@@ -12,6 +12,8 @@ import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import com.njcn.csdevice.pojo.vo.DeviceManagerVO;
|
||||
import com.njcn.csdevice.pojo.vo.ProjectEquipmentVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* Description:
|
||||
@@ -47,4 +49,10 @@ public interface ICsEquipmentDeliveryService extends IService<CsEquipmentDeliver
|
||||
* @return
|
||||
*/
|
||||
CsEquipmentDeliveryVO queryEquipmentByndid(String ndid);
|
||||
|
||||
/**
|
||||
* 获取所有装置信息
|
||||
* @return
|
||||
*/
|
||||
List<CsEquipmentDeliveryPO> getAll();
|
||||
}
|
||||
|
||||
@@ -11,7 +11,9 @@ import com.njcn.access.pojo.dto.devModel.*;
|
||||
import com.njcn.access.pojo.po.CsLineModel;
|
||||
import com.njcn.access.service.*;
|
||||
import com.njcn.access.utils.JsonUtil;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.CsLogsFeignClient;
|
||||
import com.njcn.csdevice.api.DevModelFeignClient;
|
||||
import com.njcn.csdevice.pojo.po.*;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
@@ -23,6 +25,7 @@ import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.pojo.param.EleEpdPqdParam;
|
||||
import com.njcn.system.pojo.param.EleEvtParam;
|
||||
import com.njcn.system.pojo.po.EleEpdPqd;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -69,14 +72,23 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
|
||||
private final ICsGroArrService csGroArrService;
|
||||
|
||||
private final CsLogsFeignClient csLogsFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public void addModel(MultipartFile file) {
|
||||
//日志实体
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserIndex(RequestUtil.getUserIndex());
|
||||
logDto.setUserName(RequestUtil.getUsername());
|
||||
logDto.setLoginName(RequestUtil.getLoginName());
|
||||
logDto.setResult(1);
|
||||
String json = null;
|
||||
try {
|
||||
json = JsonUtil.convertStreamToString(file.getInputStream());
|
||||
Gson gson = new Gson();
|
||||
TemplateDto templateDto = gson.fromJson(json, TemplateDto.class);
|
||||
logDto.setOperate("新增设备模板,模板名称:" + templateDto.getDevType());
|
||||
//模板文件存入文件服务器
|
||||
String filePath = fileStorageUtil.uploadMultipart(file, OssPath.DEV_MODEL + templateDto.getDevType() + "_");
|
||||
//1.录入cs_dev_model表,记录装置型号和模板记录
|
||||
@@ -85,7 +97,11 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
analysisDataSet(templateDto,csDevModelPo.getId());
|
||||
//3.录入监测点模板表(记录当前模板有几个监测点,治理类型的模板目前规定1个监测点,电能质量模板根据逻辑子设备来)
|
||||
addCsLineModel(templateDto,csDevModelPo.getId());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
} catch (Exception e) {
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.MODEL_ANALYSIS_ERROR.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.MODEL_ANALYSIS_ERROR);
|
||||
}
|
||||
}
|
||||
@@ -93,13 +109,24 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public void addDict(MultipartFile file) {
|
||||
//日志实体
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserIndex(RequestUtil.getUserIndex());
|
||||
logDto.setUserName(RequestUtil.getUsername());
|
||||
logDto.setLoginName(RequestUtil.getLoginName());
|
||||
logDto.setOperate("录入通用字典");
|
||||
logDto.setResult(1);
|
||||
String json = null;
|
||||
try {
|
||||
json = JsonUtil.convertStreamToString(file.getInputStream());
|
||||
Gson gson = new Gson();
|
||||
TemplateDto templateDto = gson.fromJson(json, TemplateDto.class);
|
||||
analysisDict(templateDto);
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
} catch (Exception e) {
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.DICT_ANALYSIS_ERROR.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.DICT_ANALYSIS_ERROR);
|
||||
}
|
||||
}
|
||||
@@ -108,8 +135,18 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
* 新增cs_dev_model数据
|
||||
*/
|
||||
private CsDevModelPO addCsDevModel(TemplateDto templateDto, String filePath){
|
||||
//日志实体
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserIndex(RequestUtil.getUserIndex());
|
||||
logDto.setUserName(RequestUtil.getUsername());
|
||||
logDto.setLoginName(RequestUtil.getLoginName());
|
||||
logDto.setOperate("新增cs_dev_model数据");
|
||||
logDto.setResult(1);
|
||||
CsDevModelPO po = devModelFeignClient.findModel(templateDto.getDevType(),templateDto.getVersion(),templateDto.getTime()).getData();
|
||||
if (!Objects.isNull(po)){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.MODEL_REPEAT.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.MODEL_REPEAT);
|
||||
}
|
||||
CsDevModelPO model = new CsDevModelPO();
|
||||
@@ -126,6 +163,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
model.setType(1);
|
||||
}
|
||||
csDevModelMapper.insert(model);
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -197,6 +235,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
EleEpdPqd po = epdFeignClient.add(eleEpdPqdParam).getData();
|
||||
if (CollectionUtil.isNotEmpty(evt.getParam())){
|
||||
evt.getParam().forEach(param->{
|
||||
//录入关系表
|
||||
EleEvtParam eleEvtParam = new EleEvtParam();
|
||||
eleEvtParam.setPid(po.getId());
|
||||
eleEvtParam.setData(param.getData());
|
||||
@@ -205,6 +244,8 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
eleEvtParam.setType(param.getType());
|
||||
eleEvtParam.setUnit(param.getUnit());
|
||||
eleEvtFeignClient.add(eleEvtParam);
|
||||
//录入字典表
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.njcn.access.pojo.dto.ReqAndResDto;
|
||||
import com.njcn.access.pojo.po.CsSoftInfoPO;
|
||||
import com.njcn.access.service.*;
|
||||
import com.njcn.access.utils.MqttUtil;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.utils.PubUtils;
|
||||
@@ -27,6 +28,7 @@ import com.njcn.csdevice.pojo.param.CsLedgerParam;
|
||||
import com.njcn.csdevice.pojo.po.AppLineTopologyDiagramPO;
|
||||
import com.njcn.csdevice.pojo.po.CsDeviceUserPO;
|
||||
import com.njcn.csdevice.pojo.po.CsLinePO;
|
||||
import com.njcn.csdevice.pojo.po.CsLogsPO;
|
||||
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
@@ -90,27 +92,48 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
|
||||
private final ICsSoftInfoService csSoftInfoService;
|
||||
|
||||
private final CsLogsFeignClient csLogsFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public void devRegister(String nDid) {
|
||||
//日志实体
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserIndex(RequestUtil.getUserIndex());
|
||||
logDto.setUserName(RequestUtil.getUsername());
|
||||
logDto.setLoginName(RequestUtil.getLoginName());
|
||||
logDto.setOperate("直连设备状态判断");
|
||||
logDto.setResult(1);
|
||||
//1.判断nDid是否存在
|
||||
CsEquipmentDeliveryVO csEquipmentDeliveryVO = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
|
||||
if (Objects.isNull(csEquipmentDeliveryVO.getNdid())){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.NDID_NO_FIND.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.NDID_NO_FIND);
|
||||
}
|
||||
//2.判断设备是否是直连设备
|
||||
SysDicTreePO sysDicTreePo = dictTreeFeignClient.queryById(csEquipmentDeliveryVO.getDevType()).getData();
|
||||
if (Objects.isNull(sysDicTreePo)){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.DEV_NOT_FIND.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.DEV_NOT_FIND);
|
||||
}
|
||||
String code = sysDicTreePo.getCode();
|
||||
if (!Objects.equals(code, DicDataEnum.CONNECT_DEV.getCode())){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.DEV_IS_NOT_ZL.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.DEV_IS_NOT_ZL);
|
||||
}
|
||||
//3.判断客户端是否在线
|
||||
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
if (!mqttClient){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.MISSING_CLIENT.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.MISSING_CLIENT);
|
||||
}
|
||||
//4.询问设备支持的主题信息
|
||||
@@ -120,32 +143,55 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
//存在则建立关系;不存在则告警出来
|
||||
SysDicTreePO dictData = dictTreeFeignClient.queryById(csEquipmentDeliveryVO.getDevModel()).getData();
|
||||
if (Objects.isNull(dictData)){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.DEV_MODEL_NOT_FIND.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.DEV_MODEL_NOT_FIND);
|
||||
}
|
||||
String devModel = dictData.getCode();
|
||||
zhiLianRegister(nDid,devModel);
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getModel(String nDid) {
|
||||
//日志实体
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserIndex(RequestUtil.getUserIndex());
|
||||
logDto.setUserName(RequestUtil.getUsername());
|
||||
logDto.setLoginName(RequestUtil.getLoginName());
|
||||
logDto.setOperate("获取直连设备模板信息");
|
||||
logDto.setResult(1);
|
||||
Object model = null;
|
||||
try {
|
||||
Thread.sleep(1500);
|
||||
String key = AppRedisKey.LINE + nDid;
|
||||
model = redisUtil.getObjectByKey(key);
|
||||
if (Objects.isNull(model)){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.MODEL_MISS.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.MODEL_MISS);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
return model;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public void devAccess(DevAccessParam devAccessParam) {
|
||||
//日志实体
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserIndex(RequestUtil.getUserIndex());
|
||||
logDto.setUserName(RequestUtil.getUsername());
|
||||
logDto.setLoginName(RequestUtil.getLoginName());
|
||||
logDto.setOperate("直连设备注册");
|
||||
logDto.setResult(1);
|
||||
try {
|
||||
//获取版本
|
||||
String version = csTopicService.getVersion(devAccessParam.getNDid());
|
||||
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(devAccessParam.getNDid()).getData();
|
||||
List<CsLinePO> csLinePoList = new ArrayList<>();
|
||||
@@ -175,9 +221,15 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
}
|
||||
}
|
||||
if (Objects.isNull(clDid)){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.CLDID_IS_NULL.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.CLDID_IS_NULL);
|
||||
}
|
||||
if (Objects.isNull(moduleNumber)){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.MODULE_NUMBER_IS_NULL.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.MODULE_NUMBER_IS_NULL);
|
||||
}
|
||||
askDevData(devAccessParam.getNDid(),AccessEnum.L_DEV_INFO.getCode(),version,clDid);
|
||||
@@ -187,6 +239,9 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
String key = AppRedisKey.LINE_DATA + devAccessParam.getNDid();
|
||||
list = objectToList2(redisUtil.getObjectByKey(key));
|
||||
if (CollectionUtils.isEmpty(list)){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.LDEVINFO_IS_NULL.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.LDEVINFO_IS_NULL);
|
||||
}
|
||||
//3.监测点表录入关系
|
||||
@@ -233,6 +288,9 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
List<String> position = csLinePoList.stream().map(CsLinePO::getPosition).collect(Collectors.toList());
|
||||
List<String> lineList = position.stream().filter(e-> Collections.frequency(position,e) > 1).distinct().collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(lineList)){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.LINE_POSITION_REPEAT.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.LINE_POSITION_REPEAT);
|
||||
}
|
||||
csLineService.saveBatch(csLinePoList);
|
||||
@@ -252,6 +310,9 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
String key2 = AppRedisKey.SOFTINFO + devAccessParam.getNDid();
|
||||
RspDataDto.SoftInfo softInfo = JSON.parseObject(JSON.toJSONString(redisUtil.getObjectByKey(key2)), RspDataDto.SoftInfo.class);
|
||||
if (Objects.isNull(softInfo)){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.SOFTINFO_IS_NULL.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.SOFTINFO_IS_NULL);
|
||||
}
|
||||
//记录设备软件信息
|
||||
@@ -270,12 +331,16 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
redisUtil.delete(AppRedisKey.LINE + devAccessParam.getNDid());
|
||||
redisUtil.delete(AppRedisKey.LINE_DATA + devAccessParam.getNDid());
|
||||
redisUtil.delete(AppRedisKey.SOFTINFO + devAccessParam.getNDid());
|
||||
//存储日志
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
} catch (Exception e) {
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(CommonResponseEnum.FAIL.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(CommonResponseEnum.FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void devAccess(String nDid,String version) {
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(1);
|
||||
|
||||
@@ -11,6 +11,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -58,4 +59,9 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CsEquipmentDeliveryPO> getAll() {
|
||||
return this.lambdaQuery().ne(CsEquipmentDeliveryPO::getRunStatus,0).list();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.njcn.access.mapper.CsTopicMapper;
|
||||
import com.njcn.access.pojo.po.CsTopic;
|
||||
import com.njcn.access.service.ICsTopicService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -34,6 +35,11 @@ public class CsTopicServiceImpl extends ServiceImpl<CsTopicMapper, CsTopic> impl
|
||||
|
||||
@Override
|
||||
public String getVersion(String nDid) {
|
||||
return this.lambdaQuery().eq(CsTopic::getNDid,nDid).isNotNull(CsTopic::getVersion).list().get(0).getVersion();
|
||||
String version = null;
|
||||
List<CsTopic> list = this.lambdaQuery().eq(CsTopic::getNDid,nDid).isNotNull(CsTopic::getVersion).list();
|
||||
if (CollectionUtil.isNotEmpty(list)){
|
||||
version = list.get(0).getVersion();
|
||||
}
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user