| | |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.object.BaseConditionVO; |
| | | import com.sandu.common.service.impl.BaseServiceImpl; |
| | | import com.sandu.common.util.SpringContextHolder; |
| | | import com.sandu.ximon.admin.manager.iot.frame.A5Frame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5AtmosphereOperationReportInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.request.AtmosphereSetHeartBeatTimeReqInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.dto.CommonFrame; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.enums.A5OrderEnum; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.enums.AtmoFunctionCode; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.mainboard.MainBoardInvokeSyncService; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.utils.RedisUtils; |
| | | import com.sandu.ximon.dao.bo.AirEquipmentBo; |
| | | import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils; |
| | | import com.sandu.ximon.admin.utils.StringUtil; |
| | | import com.sandu.ximon.dao.bo.AirEquipmentNongGengBo; |
| | | import com.sandu.ximon.dao.domain.AirEquipment; |
| | | import com.sandu.ximon.dao.domain.AirEquipmentNongGeng; |
| | | import com.sandu.ximon.dao.mapper.AirEquipmentMapper; |
| | | import com.sandu.ximon.dao.mapper.AirEquipmentNongGengMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | AirEquipmentNongGeng one = getOne(Wrappers.lambdaQuery(AirEquipmentNongGeng.class).eq(AirEquipmentNongGeng::getMac, airEquipmentNongGeng.getMac())); |
| | | if (one == null) { |
| | | save(airEquipmentNongGeng); |
| | | /** |
| | | * 添加农耕大气设备 日志记录开始 |
| | | */ |
| | | List<String> listCode = new ArrayList<>(1); |
| | | listCode.add(airEquipmentNongGeng.getMac()); |
| | | String content = "{ 设备id:" + airEquipmentNongGeng.getId() + "设备code:" + airEquipmentNongGeng.getMac() + |
| | | "}"; |
| | | |
| | | StoreOperationRecordsUtils.storeOperationData(listCode, null, "添加农耕大气设备", content); |
| | | /** |
| | | * 添加农耕大气设备 日志记录结束 |
| | | */ |
| | | } |
| | | } |
| | | |
| | |
| | | airEquipmentBos = airEquipmentNongGengMapper.listAirEquipmentByIds(keyword, SecurityUtils.getUserId()); |
| | | } |
| | | |
| | | |
| | | return airEquipmentBos; |
| | | } |
| | | |
| | | /** |
| | | * 大气设备列表(农耕,用于首页数据统计) |
| | | */ |
| | | public List<AirEquipmentNongGengBo> listAirEquipmentOnHome() { |
| | | List<AirEquipmentNongGengBo> airEquipmentBos; |
| | | if (SecurityUtils.getClientId() == null) { |
| | | airEquipmentBos = airEquipmentNongGengMapper.listAirEquipmentByIds(null, null); |
| | | } else { |
| | | airEquipmentBos = airEquipmentNongGengMapper.listAirEquipmentByIds(null, SecurityUtils.getUserId()); |
| | | } |
| | | |
| | | return airEquipmentBos; |
| | | } |
| | | |
| | |
| | | if (airEquipmentNongGeng == null) { |
| | | throw new BusinessException("找不到大气设备数据"); |
| | | } |
| | | |
| | | /** |
| | | * 删除农耕大气设备 日志记录开始 |
| | | */ |
| | | List<String> listCode = new ArrayList<>(1); |
| | | listCode.add(airEquipmentNongGeng.getMac()); |
| | | String content = "{ 设备id:" + airEquipmentNongGeng.getId() + "设备code:" + airEquipmentNongGeng.getMac() + |
| | | "}"; |
| | | |
| | | StoreOperationRecordsUtils.storeOperationData(listCode, null, "删除农耕大气设备", content); |
| | | /** |
| | | * 删除农耕大气设备 日志记录结束 |
| | | */ |
| | | return removeById(Id); |
| | | } |
| | | |
| | |
| | | */ |
| | | public AirEquipmentNongGeng getAirEquipment(String mac) { |
| | | AirEquipmentNongGeng one = getOne(Wrappers.lambdaQuery(AirEquipmentNongGeng.class).eq(AirEquipmentNongGeng::getMac, mac)); |
| | | if (RedisUtils.getBean().get(AtmoFunctionCode.AIR_HEARTBEAT_NONG_GENG.getCode() + mac) != null) { |
| | | if (one == null) { |
| | | throw new BusinessException("大气设备不存在!"); |
| | | } |
| | | if (RedisUtils.getBean().get(AtmoFunctionCode.AIR_HEARTBEAT_NONG_GENG_STATE.getCode() + mac) != null) { |
| | | one.setState(1); |
| | | } else { |
| | | one.setState(0); |
| | | } |
| | | return one; |
| | | } |
| | | |
| | | /** |
| | | * 设置大气设备心跳包间隔时间 |
| | | * |
| | | * @param mac |
| | | * @param time |
| | | */ |
| | | public String setHeartBeatTime(String mac, Integer time) { |
| | | if (StringUtil.strIsNullOrEmpty(mac)) { |
| | | throw new BusinessException("灯杆mac参数错误!"); |
| | | } |
| | | if (time == null) { |
| | | throw new BusinessException("心跳包间隔时间不能为空!"); |
| | | } |
| | | |
| | | if (time < 30) { |
| | | throw new BusinessException("心跳包间隔时间不能少于30s!"); |
| | | } |
| | | AirEquipmentNongGeng airEquipmentNongGeng = SpringContextHolder.getBean(AirEquipmentNongGengService.class). |
| | | getOne(Wrappers.lambdaQuery(AirEquipmentNongGeng.class).eq(AirEquipmentNongGeng::getMac, mac).last("limit 1")); |
| | | if (airEquipmentNongGeng == null) { |
| | | throw new BusinessException("大气设备不存在!"); |
| | | } |
| | | |
| | | AtmosphereSetHeartBeatTimeReqInnerFrame atmosphereSetHeartBeatTimeReqInnerFrame = new AtmosphereSetHeartBeatTimeReqInnerFrame(time); |
| | | A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_ATMOSPHERE_DATA.getCode(), atmosphereSetHeartBeatTimeReqInnerFrame); |
| | | System.out.println(a5Frame + " --------a5Frame"); |
| | | CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(mac, a5Frame); |
| | | System.out.println(commonFrame + " -----------commonFrame"); |
| | | |
| | | A5AtmosphereOperationReportInnerFrame a5AtmosphereOperationReportInnerFrame |
| | | = new A5AtmosphereOperationReportInnerFrame().transformFrame(commonFrame.getPayload()); |
| | | if (a5AtmosphereOperationReportInnerFrame != null && a5AtmosphereOperationReportInnerFrame.isValidate()) { |
| | | return a5AtmosphereOperationReportInnerFrame.getState(); |
| | | } else { |
| | | throw new BusinessException("数据校验异常!"); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 设置类型 |
| | | * |
| | | * @param param |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean setAirEquipmentType(AirEquipmentNongGeng param) { |
| | | if (param.getType() == null || param.getId() == null || param.getType().isEmpty()) { |
| | | throw new BusinessException("设备id或类型不能为空"); |
| | | } |
| | | if (!"0".equals(param.getType()) && !"1".equals(param.getType()) && !"2".equals(param.getType())) { |
| | | throw new BusinessException("设备类型不正确"); |
| | | } |
| | | AirEquipmentNongGeng byId = getById(param.getId()); |
| | | if (byId == null) { |
| | | throw new BusinessException("设备id错误或设备不存在!"); |
| | | } |
| | | byId.setType(param.getType()); |
| | | |
| | | return updateById(byId); |
| | | } |
| | | } |