代码调整

This commit is contained in:
2023-07-11 10:22:06 +08:00
parent feb30c71dd
commit 147aef0bfd
20 changed files with 711 additions and 14 deletions

View File

@@ -1,6 +1,8 @@
package com.njcn.access.service;
import com.njcn.access.param.DevAccessParam;
import com.njcn.access.param.WgDeviceRegisterParam;
import com.njcn.access.param.WgRegisterParam;
/**
* 类的介绍:
@@ -29,5 +31,4 @@ public interface ICsDeviceService {
* @param devAccessParam
*/
void devAccess(DevAccessParam devAccessParam);
}

View File

@@ -0,0 +1,27 @@
package com.njcn.access.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.access.pojo.po.CsGatewayDevice;
import com.njcn.csdevice.pojo.po.CsEquipmentAlarmPO;
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
import java.util.List;
/**
* <p>
* 网关装置关系表 服务类
* </p>
*
* @author xuyang
* @since 2023-07-07
*/
public interface ICsGatewayDeviceService extends IService<CsGatewayDevice> {
/**
* 根据网关id获取网关下装置的信息
* @param id
* @return
*/
List<CsEquipmentDeliveryPO> getList(String id);
}

View File

@@ -0,0 +1,51 @@
package com.njcn.access.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.access.param.WgDeviceRegisterParam;
import com.njcn.access.param.WgRegisterParam;
import com.njcn.access.pojo.po.CsGateway;
import com.njcn.access.pojo.vo.CsGatewayVo;
import java.util.List;
/**
* <p>
* 网关表 服务类
* </p>
*
* @author xuyang
* @since 2023-07-06
*/
public interface ICsGatewayService extends IService<CsGateway> {
/**
* 网关注册
* @param nDid 设备识别码
*/
void wgRegister(String nDid);
/**
* 网关ndid校验成功后添加网关信息
* @param wgRegisterParam
*/
void wgRegister2(WgRegisterParam wgRegisterParam);
/**
* 查询用户下的网关
* @return
*/
List<CsGatewayVo> getWgList();
/**
* 查询具体网关信息
* @return
*/
CsGatewayVo findById(String id);
/**
* 网关下设备注册
* @param list
*/
void registerByWg(List<WgDeviceRegisterParam> list);
}

View File

@@ -1,14 +1,19 @@
package com.njcn.access.service.impl;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
import com.njcn.access.enums.AccessEnum;
import com.njcn.access.enums.AccessResponseEnum;
import com.njcn.access.enums.TypeEnum;
import com.njcn.access.param.DevAccessParam;
import com.njcn.access.param.WgDeviceRegisterParam;
import com.njcn.access.param.WgRegisterParam;
import com.njcn.access.pojo.dto.AccessDto;
import com.njcn.access.pojo.dto.ReqAndResDto;
import com.njcn.access.pojo.po.CsGateway;
import com.njcn.access.service.ICsDeviceService;
import com.njcn.access.service.ICsGatewayService;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.utils.PubUtils;
@@ -66,6 +71,8 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
private final CsDeviceUserFeignClient csDeviceUserFeignClient;
private final ICsGatewayService csGatewayService;
private final MqttPublisher publisher;
private final RedisUtil redisUtil;
@@ -177,7 +184,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
devModelRelationFeignClient.addDevModelRelation(csDevModelRelationAddParm);
redisUtil.delete("MODEL" + devAccessParam.getNDid());
//5.修改装置状态
equipmentFeignClient.updateStatusBynDid(devAccessParam.getNDid(), AccessEnum.ACCESS.getCode());
equipmentFeignClient.updateStatusBynDid(devAccessParam.getNDid(), AccessEnum.REGISTERED.getCode());
//6.设置心跳时间,超时改为掉线
redisUtil.saveByKeyWithExpire("MQTT:" + devAccessParam.getNDid(), Instant.now().toEpochMilli(),180L);
//7.绑定装置和人的关系
@@ -194,7 +201,6 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
}
}
public void zhiLianRegister(String nDid,String devType) {
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
reqAndResParam.setMid(1);

View File

@@ -0,0 +1,28 @@
package com.njcn.access.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.access.mapper.CsGatewayDeviceMapper;
import com.njcn.access.pojo.po.CsGatewayDevice;
import com.njcn.access.service.ICsGatewayDeviceService;
import com.njcn.csdevice.pojo.po.CsEquipmentAlarmPO;
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 网关装置关系表 服务实现类
* </p>
*
* @author xuyang
* @since 2023-07-07
*/
@Service
public class CsGatewayDeviceServiceImpl extends ServiceImpl<CsGatewayDeviceMapper, CsGatewayDevice> implements ICsGatewayDeviceService {
@Override
public List<CsEquipmentDeliveryPO> getList(String id) {
return this.baseMapper.getList(id);
}
}

View File

@@ -0,0 +1,116 @@
package com.njcn.access.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.access.enums.AccessEnum;
import com.njcn.access.enums.AccessResponseEnum;
import com.njcn.access.mapper.CsGatewayMapper;
import com.njcn.access.param.WgDeviceRegisterParam;
import com.njcn.access.param.WgRegisterParam;
import com.njcn.access.pojo.po.CsGateway;
import com.njcn.access.pojo.vo.CsGatewayVo;
import com.njcn.access.service.ICsGatewayDeviceService;
import com.njcn.access.service.ICsGatewayService;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.api.EquipmentFeignClient;
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
import com.njcn.oss.utils.FileStorageUtil;
import com.njcn.system.api.DictTreeFeignClient;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.pojo.po.SysDicTreePO;
import com.njcn.web.utils.RequestUtil;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* <p>
* 网关表 服务实现类
* </p>
*
* @author xuyang
* @since 2023-07-06
*/
@Service
@AllArgsConstructor
public class CsGatewayServiceImpl extends ServiceImpl<CsGatewayMapper, CsGateway> implements ICsGatewayService {
private final FileStorageUtil fileStorageUtil;
private final EquipmentFeignClient equipmentFeignClient;
private final DictTreeFeignClient dictTreeFeignClient;
private final ICsGatewayDeviceService csGatewayDeviceService;
@Override
public void wgRegister(String nDid) {
//1.判断nDid是否存在
CsEquipmentDeliveryVO csEquipmentDeliveryVO = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
if (Objects.isNull(csEquipmentDeliveryVO.getNdid())){
throw new BusinessException(AccessResponseEnum.NDID_NO_FIND);
}
//2.判断设备是否是网关
SysDicTreePO sysDicTreePo = dictTreeFeignClient.queryById(csEquipmentDeliveryVO.getDevType()).getData();
if (Objects.isNull(sysDicTreePo)){
throw new BusinessException(AccessResponseEnum.DEV_NOT_FIND);
}
String code = sysDicTreePo.getCode();
if (!Objects.equals(code, DicDataEnum.GATEWAY_DEV.getCode())){
throw new BusinessException(AccessResponseEnum.DEV_IS_NOT_WG);
}
}
@Override
@Transactional(rollbackFor = {Exception.class})
public void wgRegister2(WgRegisterParam wgRegisterParam) {
CsEquipmentDeliveryVO csEquipmentDeliveryVO = equipmentFeignClient.queryEquipmentByndid(wgRegisterParam.getNDid()).getData();
CsGateway csGateway = new CsGateway();
csGateway.setId(csEquipmentDeliveryVO.getId());
csGateway.setPid(wgRegisterParam.getProjectId());
csGateway.setArea(wgRegisterParam.getArea());
csGateway.setTid(wgRegisterParam.getTopologyDiagram());
csGateway.setStatus(1);
this.save(csGateway);
equipmentFeignClient.updateStatusBynDid(wgRegisterParam.getNDid(), AccessEnum.REGISTERED.getCode());
}
@Override
public List<CsGatewayVo> getWgList() {
return this.baseMapper.getWgList(RequestUtil.getUserIndex());
}
@Override
public CsGatewayVo findById(String id) {
CsGatewayVo vo = this.baseMapper.findById(id);
vo.setFilePath (fileStorageUtil.getFileUrl (vo.getFilePath()));
List<CsEquipmentDeliveryPO> list = csGatewayDeviceService.getList(id);
List<CsGatewayVo.Device> devList = new ArrayList<>();
if (CollectionUtil.isNotEmpty(list)){
list.forEach(item->{
CsGatewayVo.Device pojo = new CsGatewayVo.Device();
pojo.setDevName(item.getName());
pojo.setProName(vo.getProName());
devList.add(pojo);
});
}
vo.setList(devList);
return vo;
}
@Override
public void registerByWg(List<WgDeviceRegisterParam> list) {
list.forEach(item->{
});
}
}