diff --git a/iot-access/access-api/src/main/java/com/njcn/access/pojo/param/DeviceStatusParam.java b/iot-access/access-api/src/main/java/com/njcn/access/pojo/param/DeviceStatusParam.java new file mode 100644 index 0000000..2778825 --- /dev/null +++ b/iot-access/access-api/src/main/java/com/njcn/access/pojo/param/DeviceStatusParam.java @@ -0,0 +1,32 @@ +package com.njcn.access.pojo.param; + +import lombok.Data; + +/** + * 类的介绍: + * + * @author xuyang + * @version 1.0.0 + * @createTime 2023/10/31 15:00 + */ +@Data +public class DeviceStatusParam { + + private String nDid; + + /** + * 设备接入状态(1:未注册 2:注册 3:接入) + */ + private Integer status; + + /** + * 设备运行状态(0:删除 1:离线 2:在线) + */ + private Integer runStatus; + + /** + * 设备当前流程(1:设备登记,2:功能调试,3:出厂调试 4:设备投运) + */ + private Integer process; + +} diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/controller/CsDeviceController.java b/iot-access/access-boot/src/main/java/com/njcn/access/controller/CsDeviceController.java index 2c9d4bb..9b31820 100644 --- a/iot-access/access-boot/src/main/java/com/njcn/access/controller/CsDeviceController.java +++ b/iot-access/access-boot/src/main/java/com/njcn/access/controller/CsDeviceController.java @@ -68,4 +68,14 @@ public class CsDeviceController extends BaseController { csDeviceService.devAccess(devAccessParam); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/resetFactory") + @ApiOperation("设备恢复出厂设置") + @ApiImplicitParam(name = "nDid", value = "设备id", required = true) + public HttpResult resetFactory(@RequestParam String nDid){ + String methodDescribe = getMethodDescribe("resetFactory"); + csDeviceService.resetFactory(nDid); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } } diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/listener/RedisKeyExpirationListener.java b/iot-access/access-boot/src/main/java/com/njcn/access/listener/RedisKeyExpirationListener.java index 475650b..dd4c817 100644 --- a/iot-access/access-boot/src/main/java/com/njcn/access/listener/RedisKeyExpirationListener.java +++ b/iot-access/access-boot/src/main/java/com/njcn/access/listener/RedisKeyExpirationListener.java @@ -92,13 +92,13 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene csDeviceService.devAccess(nDid,version); //接入再次失败,则定时发起接入请求 Thread.sleep(1000); - Integer status = csEquipmentDeliveryService.queryEquipmentByndid(nDid).getRunStatus(); + Integer status = csEquipmentDeliveryService.queryEquipmentBynDid(nDid).getRunStatus(); if (!Objects.isNull(status) && Objects.equals(status,AccessEnum.OFFLINE.getCode())){ ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(2); ScheduledFuture runnableFuture = executor.scheduleAtFixedRate(() -> { log.info("定时发送接入请求..."); csDeviceService.devAccess(nDid, version); - Integer status2 = csEquipmentDeliveryService.queryEquipmentByndid(nDid).getRunStatus(); + Integer status2 = csEquipmentDeliveryService.queryEquipmentBynDid(nDid).getRunStatus(); if (Objects.equals(status2,AccessEnum.ONLINE.getCode())){ throw new BusinessException(CommonResponseEnum.SUCCESS); } diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsDeviceUserPOMapper.java b/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsDeviceUserPOMapper.java new file mode 100644 index 0000000..d104e1c --- /dev/null +++ b/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsDeviceUserPOMapper.java @@ -0,0 +1,15 @@ +package com.njcn.access.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.njcn.csdevice.pojo.po.CsDeviceUserPO; + +/** + * + * Description: + * Date: 2023/6/27 9:40【需求编号】 + * + * @author clam + * @version V1.0.0 + */ +public interface CsDeviceUserPOMapper extends BaseMapper { +} \ No newline at end of file diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsLinePOMapper.java b/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsLinePOMapper.java new file mode 100644 index 0000000..2f81aea --- /dev/null +++ b/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsLinePOMapper.java @@ -0,0 +1,19 @@ +package com.njcn.access.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.njcn.csdevice.pojo.po.CsLinePO; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * + * Description: + * Date: 2023/5/18 14:01【需求编号】 + * + * @author clam + * @version V1.0.0 + */ +public interface CsLinePOMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/runner/AccessApplicationRunner.java b/iot-access/access-boot/src/main/java/com/njcn/access/runner/AccessApplicationRunner.java index 716417d..fc726b4 100644 --- a/iot-access/access-boot/src/main/java/com/njcn/access/runner/AccessApplicationRunner.java +++ b/iot-access/access-boot/src/main/java/com/njcn/access/runner/AccessApplicationRunner.java @@ -1,47 +1,47 @@ -//package com.njcn.access.runner; -// -//import com.njcn.access.service.ICsEquipmentDeliveryService; -//import com.njcn.access.service.ICsTopicService; -//import com.njcn.access.service.impl.CsDeviceServiceImpl; -//import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO; -//import lombok.extern.slf4j.Slf4j; -//import org.springframework.boot.ApplicationArguments; -//import org.springframework.boot.ApplicationRunner; -//import org.springframework.stereotype.Component; -// -//import javax.annotation.Resource; -//import java.util.List; -//import java.util.Objects; -// -///** -// * 类的介绍:用来重新发起设备的接入,存在程序意外停止了,缓存失效导致无法更新装置的状态,所以需要在程序启动时发起设备的接入 -// * -// * @author xuyang -// * @version 1.0.0 -// * @createTime 2023/8/28 13:57 -// */ -//@Component -//@Slf4j -//public class AccessApplicationRunner implements ApplicationRunner { -// -// @Resource -// private CsDeviceServiceImpl csDeviceService; -// -// @Resource -// private ICsTopicService csTopicService; -// -// @Resource -// private ICsEquipmentDeliveryService csEquipmentDeliveryService; -// -// @Override -// public void run(ApplicationArguments args){ -// List list = csEquipmentDeliveryService.getAll(); -// list.forEach(item->{ -// String version = csTopicService.getVersion(item.getNdid()); -// if (!Objects.isNull(version)){ -// csDeviceService.devAccess(item.getNdid(),version); -// } -// }); -// } -// -//} +package com.njcn.access.runner; + +import com.njcn.access.service.ICsEquipmentDeliveryService; +import com.njcn.access.service.ICsTopicService; +import com.njcn.access.service.impl.CsDeviceServiceImpl; +import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Objects; + +/** + * 类的介绍:用来重新发起设备的接入,存在程序意外停止了,缓存失效导致无法更新装置的状态,所以需要在程序启动时发起设备的接入 + * + * @author xuyang + * @version 1.0.0 + * @createTime 2023/8/28 13:57 + */ +@Component +@Slf4j +public class AccessApplicationRunner implements ApplicationRunner { + + @Resource + private CsDeviceServiceImpl csDeviceService; + + @Resource + private ICsTopicService csTopicService; + + @Resource + private ICsEquipmentDeliveryService csEquipmentDeliveryService; + + @Override + public void run(ApplicationArguments args){ + List list = csEquipmentDeliveryService.getAll(); + list.forEach(item->{ + String version = csTopicService.getVersion(item.getNdid()); + if (!Objects.isNull(version)){ + csDeviceService.devAccess(item.getNdid(),version); + } + }); + } + +} diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/CsDeviceUserPOService.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/CsDeviceUserPOService.java new file mode 100644 index 0000000..a66a508 --- /dev/null +++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/CsDeviceUserPOService.java @@ -0,0 +1,20 @@ +package com.njcn.access.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.njcn.csdevice.pojo.po.CsDeviceUserPO; +import com.njcn.csdevice.pojo.vo.DevCountVO; +import com.njcn.csdevice.pojo.vo.DevUserVO; + +import java.util.List; + +/** + * + * Description: + * Date: 2023/6/27 9:40【需求编号】 + * + * @author clam + * @version V1.0.0 + */ +public interface CsDeviceUserPOService extends IService{ + +} diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/CsLinePOService.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/CsLinePOService.java new file mode 100644 index 0000000..0539a90 --- /dev/null +++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/CsLinePOService.java @@ -0,0 +1,19 @@ +package com.njcn.access.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.njcn.csdevice.pojo.param.CsLineParam; +import com.njcn.csdevice.pojo.po.CsLinePO; + +import java.util.List; + +/** + * + * Description: + * Date: 2023/5/18 14:01【需求编号】 + * + * @author clam + * @version V1.0.0 + */ +public interface CsLinePOService extends IService{ + +} diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsDeviceService.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsDeviceService.java index bc59e3f..d06bf18 100644 --- a/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsDeviceService.java +++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsDeviceService.java @@ -30,4 +30,10 @@ public interface ICsDeviceService { * @param devAccessParam */ void devAccess(DevAccessParam devAccessParam); + + /** + * 设备恢复成出厂设置状态 + * @param nDid + */ + void resetFactory(String nDid); } diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsEquipmentDeliveryService.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsEquipmentDeliveryService.java index 2b58745..28b6ea8 100644 --- a/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsEquipmentDeliveryService.java +++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsEquipmentDeliveryService.java @@ -3,6 +3,7 @@ package com.njcn.access.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; +import com.njcn.access.pojo.param.DeviceStatusParam; import com.njcn.csdevice.pojo.param.CsEquipmentDeliveryAddParm; import com.njcn.csdevice.pojo.param.CsEquipmentDeliveryAuditParm; import com.njcn.csdevice.pojo.param.CsEquipmentDeliveryQueryParm; @@ -45,14 +46,19 @@ public interface ICsEquipmentDeliveryService extends IService getAll(); + + /** + * 恢复出厂设置 + */ + void devResetFactory(DeviceStatusParam param); } diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceServiceImpl.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceServiceImpl.java index edaed8a..41b7d45 100644 --- a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceServiceImpl.java +++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceServiceImpl.java @@ -2,9 +2,10 @@ package com.njcn.access.service.impl; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.IdUtil; -import com.alibaba.excel.util.CollectionUtils; import com.alibaba.fastjson.JSON; +import com.alibaba.nacos.client.naming.utils.CollectionUtils; import com.alibaba.nacos.shaded.com.google.gson.Gson; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.github.tocrhz.mqtt.publisher.MqttPublisher; import com.njcn.access.enums.AccessEnum; import com.njcn.access.enums.AccessResponseEnum; @@ -15,6 +16,7 @@ import com.njcn.access.pojo.dto.AccessDto; import com.njcn.access.pojo.dto.AskDataDto; import com.njcn.access.pojo.dto.CsModelDto; import com.njcn.access.pojo.dto.ReqAndResDto; +import com.njcn.access.pojo.param.DeviceStatusParam; import com.njcn.access.pojo.po.CsSoftInfoPO; import com.njcn.access.service.*; import com.njcn.access.utils.MqttUtil; @@ -26,10 +28,7 @@ import com.njcn.csdevice.api.EquipmentFeignClient; import com.njcn.csdevice.api.ProcessFeignClient; import com.njcn.csdevice.pojo.param.CsDevModelRelationAddParm; 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.CsEquipmentProcessPO; -import com.njcn.csdevice.pojo.po.CsLinePO; +import com.njcn.csdevice.pojo.po.*; import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO; import com.njcn.redis.pojo.enums.AppRedisKey; import com.njcn.redis.utils.RedisUtil; @@ -43,6 +42,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; +import org.springframework.test.annotation.Rollback; import org.springframework.transaction.annotation.Transactional; import java.text.SimpleDateFormat; @@ -93,12 +93,14 @@ public class CsDeviceServiceImpl implements ICsDeviceService { private final DicDataFeignClient dicDataFeignClient; - private final ICsSoftInfoService csSoftInfoService; - private final CsLogsFeignClient csLogsFeignClient; private final ProcessFeignClient processFeignClient; + private final CsLinePOService csLinePOService; + + private final CsDeviceUserPOService csDeviceUserPOService; + @Override @Transactional(rollbackFor = {Exception.class}) public void devRegister(String nDid,Integer type) { @@ -109,7 +111,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService { logDto.setOperate("当前设备"+nDid+"状态判断"); logDto.setResult(1); //1.判断nDid是否存在 - CsEquipmentDeliveryVO csEquipmentDeliveryVO = equipmentFeignClient.queryEquipmentByndid(nDid).getData(); + CsEquipmentDeliveryVO csEquipmentDeliveryVO = csEquipmentDeliveryService.queryEquipmentBynDid(nDid); if (Objects.isNull(csEquipmentDeliveryVO.getNdid())){ logDto.setResult(0); logDto.setFailReason(AccessResponseEnum.NDID_NO_FIND.getMessage()); @@ -309,6 +311,51 @@ public class CsDeviceServiceImpl implements ICsDeviceService { } } + @Override + @Transactional(rollbackFor = {Exception.class}) + public void resetFactory(String nDid) { + CsEquipmentDeliveryVO csEquipmentDeliveryVO = csEquipmentDeliveryService.queryEquipmentBynDid(nDid); + String devId = csEquipmentDeliveryVO.getId(); + //修改装置状态 + DeviceStatusParam param = new DeviceStatusParam(); + param.setNDid(nDid); + param.setStatus(1); + param.setRunStatus(1); + param.setProcess(2); + csEquipmentDeliveryService.devResetFactory(param); + //清除关系表 + QueryWrapper csLedgerQueryWrapper = new QueryWrapper<>(); + /** + * 删除设备 + */ + csLedgerQueryWrapper.clear(); + csLedgerQueryWrapper.eq("id",devId); + csLedgerService.remove(csLedgerQueryWrapper); + csLedgerQueryWrapper.clear(); + csLedgerQueryWrapper.eq("pid",devId); + List list = csLedgerService.list(csLedgerQueryWrapper); + List collect = list.stream().map(CsLedger::getId).collect(Collectors.toList()); + csLedgerService.remove(csLedgerQueryWrapper); + QueryWrapper csDevModelRelationPOQueryWrapper = new QueryWrapper<>(); + csDevModelRelationPOQueryWrapper.clear(); + csDevModelRelationPOQueryWrapper.eq("dev_id",devId); + csDevModelRelationService.remove(csDevModelRelationPOQueryWrapper); + QueryWrapper csDeviceUserPOQueryWrapper = new QueryWrapper<>(); + csDeviceUserPOQueryWrapper.clear(); + csDeviceUserPOQueryWrapper.eq("device_id",devId); + csDeviceUserPOService.remove(csDeviceUserPOQueryWrapper); + if (!CollectionUtils.isEmpty(collect)) { + QueryWrapper csLinePOQueryWrapper = new QueryWrapper<>(); + csLinePOQueryWrapper.clear(); + csLinePOQueryWrapper.in("line_id",collect); + csLinePOService.remove(csLinePOQueryWrapper); + QueryWrapper appLineTopologyDiagramPOQueryWrapper = new QueryWrapper<>(); + appLineTopologyDiagramPOQueryWrapper.clear(); + appLineTopologyDiagramPOQueryWrapper.in("line_id",collect); + appLineTopologyDiagramService.remove(appLineTopologyDiagramPOQueryWrapper); + } + } + public void devAccess(String nDid,String version) { ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req(); reqAndResParam.setMid(1); diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceUserPOServiceImpl.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceUserPOServiceImpl.java new file mode 100644 index 0000000..b4b4dcb --- /dev/null +++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceUserPOServiceImpl.java @@ -0,0 +1,22 @@ +package com.njcn.access.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.njcn.access.mapper.CsDeviceUserPOMapper; +import com.njcn.access.service.CsDeviceUserPOService; +import com.njcn.csdevice.pojo.po.CsDeviceUserPO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +/** + * + * Description: + * Date: 2023/6/27 9:40【需求编号】 + * + * @author clam + * @version V1.0.0 + */ +@Service +@RequiredArgsConstructor +public class CsDeviceUserPOServiceImpl extends ServiceImpl implements CsDeviceUserPOService { + +} diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsEquipmentDeliveryServiceImpl.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsEquipmentDeliveryServiceImpl.java index c5f8dc1..ad318be 100644 --- a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsEquipmentDeliveryServiceImpl.java +++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsEquipmentDeliveryServiceImpl.java @@ -1,9 +1,9 @@ package com.njcn.access.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.njcn.access.mapper.CsEquipmentDeliveryMapper; +import com.njcn.access.pojo.param.DeviceStatusParam; import com.njcn.access.service.ICsEquipmentDeliveryService; import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO; import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO; @@ -49,9 +49,9 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl lambdaUpdateWrapper = new LambdaUpdateWrapper<>(); + lambdaUpdateWrapper.eq(CsEquipmentDeliveryPO::getNdid,param.getNDid()) + .set(CsEquipmentDeliveryPO::getRunStatus,param.getRunStatus()) + .set(CsEquipmentDeliveryPO::getStatus,param.getStatus()) + .set(CsEquipmentDeliveryPO::getProcess,param.getProcess()); + this.update(lambdaUpdateWrapper); + } + } diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsLinePOServiceImpl.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsLinePOServiceImpl.java new file mode 100644 index 0000000..936245f --- /dev/null +++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsLinePOServiceImpl.java @@ -0,0 +1,22 @@ +package com.njcn.access.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.njcn.access.mapper.CsLinePOMapper; +import com.njcn.access.service.CsLinePOService; +import com.njcn.csdevice.pojo.po.CsLinePO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +/** + * + * Description: + * Date: 2023/5/18 14:01【需求编号】 + * + * @author clam + * @version V1.0.0 + */ +@Service +@RequiredArgsConstructor +public class CsLinePOServiceImpl extends ServiceImpl implements CsLinePOService { + +}