| | |
| | | package com.ruoyi.iot.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.iot.domain.Device; |
| | | import com.ruoyi.iot.dto.DeviceFilterDto; |
| | | import com.ruoyi.iot.model.DeviceAllShortOutput; |
| | | import com.ruoyi.iot.model.DeviceRelateUserInput; |
| | | import com.ruoyi.iot.model.DeviceShortOutput; |
| | | import com.ruoyi.iot.model.ThingsModels.ThingsModelValueItem; |
| | | import com.ruoyi.iot.mqtt.EmqxService; |
| | | import com.ruoyi.iot.service.IDeviceService; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.checkerframework.checker.units.qual.A; |
| | | import org.quartz.SchedulerException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | |
| | | /** |
| | | * 查询首页的总用户数(人),总设备数(台) |
| | | * |
| | | * @param tenantName |
| | | * @param id |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('iot:device:list')") |
| | | @GetMapping(value = {"/", "/{tenantName}"}) |
| | | @GetMapping("/select/{id}") |
| | | @ApiOperation(value = "获取总用户数和总设备数") |
| | | public AjaxResult selectCount(@PathVariable("tenantName") String tenantName) throws Exception { |
| | | //根据用户登录的角色身份查询总设备数(台) |
| | | int count = deviceService.selectDeviceCount(tenantName); |
| | | //根据登录用户的角色身份查询设备的使用人数 |
| | | int total = deviceService.selectUserDeviceByCount(tenantName); |
| | | AjaxResult ajax = new AjaxResult(); |
| | | ajax.put("deviceCount", count); |
| | | ajax.put("userTotal", total); |
| | | return AjaxResult.success("查询成功", ajax); |
| | | public AjaxResult selectCount(@PathVariable("id") int id) throws Exception { |
| | | if (id > 0) { |
| | | return deviceService.selectDeviceCount(id); |
| | | } else { |
| | | return AjaxResult.error("未查询到有关信息,id的值不能小于1"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询滤芯寿命清单列表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('iot:device:list')") |
| | | @GetMapping("/cartridgeList") |
| | | @ApiOperation("滤芯寿命清单列表") |
| | | public TableDataInfo selectCartridgeLifeList(Device device) throws Exception { |
| | | //把device表中每一条数据的things_model_value物模型值json解析为ThingsModelValueItem对象 |
| | | List<DeviceFilterDto> list = new ArrayList<>(); |
| | | Long deviceId = 0L; |
| | | ThingsModelValueItem thingsModelValueItem = null; |
| | | //查询所有的设备 |
| | | List<Device> deviceList = deviceService.selectDeviceAll(); |
| | | for (Device devices : deviceList) { |
| | | //拿到物模型值 |
| | | String thingsModelValue = devices.getThingsModelValue(); |
| | | deviceId = devices.getDeviceId(); |
| | | if (thingsModelValue != null) { |
| | | //JSONObject.parseObject方法用于将一个JSON字符串解析为一个JSONObject对象 |
| | | JSONObject jsonObject = JSONObject.parseObject(thingsModelValue); |
| | | //toJavaObject方法是用于将JSON字符串转换为Java对象的静态方法。这个方法可以将JSON格式的字符串转换为对应的Java对象。 |
| | | thingsModelValueItem = jsonObject.toJavaObject(ThingsModelValueItem.class); |
| | | //拿到物模型的id——FilterA |
| | | String thingsModelId = thingsModelValueItem.getId(); |
| | | //拿到物模型id是FilterA的值 |
| | | int thingsModelValues = Integer.parseInt(thingsModelValueItem.getValue()); |
| | | if ("FilterA".equals(thingsModelId) && thingsModelValues <= 5 || "FilterB".equals(thingsModelId) && thingsModelValues <= 5 || "FilterC".equals(thingsModelId) && thingsModelValues <= 5 || "FilterD".equals(thingsModelId) && thingsModelValues <= 5) { |
| | | //根据滤芯寿命A小于等于5的设备id去查询设备信息 |
| | | Device deviceA = deviceService.selectDeviceByDeviceId(deviceId); |
| | | DeviceFilterDto deviceFilterDto = new DeviceFilterDto(deviceA.getDeviceId(), deviceA.getDeviceName(), deviceA.getDeviceOrder().getUserName(), deviceA.getDeviceOrder().getUserPhone(), thingsModelValues, null, null, null); |
| | | list.add(deviceFilterDto); |
| | | break; |
| | | } |
| | | } else { |
| | | return null; |
| | | } |
| | | } |
| | | startPage(); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | /** |
| | | * 查询未分配授权码设备列表 |
| | |
| | | @ApiOperation("设备分页简短列表") |
| | | public TableDataInfo shortList(Device device) { |
| | | startPage(); |
| | | return getDataTable(deviceService.selectDeviceShortList(device)); |
| | | return getDataTable(deviceService.selectDeviceShortList(device, false)); |
| | | } |
| | | |
| | | /** |
| | | * 查询设备简短列表,主页列表数据 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('iot:device:list')") |
| | | @GetMapping("/shortListRepair") |
| | | @ApiOperation("设备分页简短列表") |
| | | public TableDataInfo shortListRepair(Device device) { |
| | | startPage(); |
| | | return getDataTable(deviceService.selectDeviceShortList(device, true)); |
| | | } |
| | | |
| | | /** |
| | |
| | | /** |
| | | * 获取设备详细信息 |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('iot:device:query')") |
| | | // @GetMapping(value = "/{deviceId}") |
| | | // @ApiOperation("获取设备详情") |
| | | // public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId) { |
| | | // return AjaxResult.success(deviceService.selectDeviceByDeviceId(deviceId)); |
| | | // } |
| | | @PreAuthorize("@ss.hasPermi('iot:device:query')") |
| | | @GetMapping(value = "/{deviceId}") |
| | | @ApiOperation("获取设备详情") |
| | | public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId) { |
| | | return AjaxResult.success(deviceService.selectDeviceByDeviceId(deviceId)); |
| | | } |
| | | |
| | | /** |
| | | * 设备数据同步 |