| | |
| | | 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.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.mapper.DeviceMapper; |
| | | 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 javax.servlet.http.HttpServletResponse; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import static sun.audio.AudioDevice.device; |
| | | import static com.ruoyi.framework.datasource.DynamicDataSourceContextHolder.log; |
| | | |
| | | /** |
| | | * 设备Controller |
| | |
| | | |
| | | @Autowired |
| | | private IDeviceService deviceService; |
| | | |
| | | @Autowired |
| | | private DeviceMapper deviceMapper; |
| | | |
| | | @Lazy |
| | | @Autowired |
| | |
| | | * 查询滤芯寿命清单列表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('iot:device:list')") |
| | | @GetMapping("/cartridgeList") |
| | | @GetMapping("/FilterElement") |
| | | @ApiOperation("滤芯寿命清单列表") |
| | | public TableDataInfo selectCartridgeLifeList(Device device) throws Exception { |
| | | public TableDataInfo selectCartridgeLifeList() 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; |
| | | SysUser sysUser = getLoginUser().getUser(); //拿到当前登录的用户信息 |
| | | if ("admin".equals(sysUser.getRoleKey())) { |
| | | List<DeviceFilterDto> list = new ArrayList<>(); |
| | | String FilterAValue = null; |
| | | String FilterBValue = null; |
| | | String FilterCValue = null; |
| | | String FilterDValue = null; |
| | | List<Device> deviceList = deviceService.selectDeviceAll(); |
| | | for (Device devices : deviceList) { |
| | | //拿到物模型值 |
| | | String thingsModelValue = devices.getThingsModelValue(); |
| | | Long deviceId = devices.getDeviceId(); |
| | | if (!"[]".equals(thingsModelValue)) { |
| | | List<ThingsModelValueItem> thingsModelValueItems = JSONObject.parseArray(thingsModelValue, ThingsModelValueItem.class); |
| | | //循环遍历 |
| | | for (ThingsModelValueItem modelValueItem : thingsModelValueItems) { |
| | | // 拿到物模型的id |
| | | //判断物模型的id等不等于FilterA,FilterB,FilterC,FilterD如果等于的话拿到物模型的value值 |
| | | if (!"".equals(modelValueItem.getValue())) { |
| | | if ("FilterA".equals(modelValueItem.getId()) && !"".equals(modelValueItem.getValue())) { |
| | | FilterAValue = modelValueItem.getValue(); |
| | | } else if ("FilterB".equals(modelValueItem.getId()) && !"".equals(modelValueItem.getValue())) { |
| | | FilterBValue = modelValueItem.getValue(); |
| | | } else if ("FilterC".equals(modelValueItem.getId()) && !"".equals(modelValueItem.getValue())) { |
| | | FilterCValue = modelValueItem.getValue(); |
| | | } else if ("FilterD".equals(modelValueItem.getId()) && !"".equals(modelValueItem.getValue())) { |
| | | FilterDValue = modelValueItem.getValue(); |
| | | } |
| | | //滤芯寿命的值小于等于5的话数据库的值是几就返回给前端显示是几,滤芯寿命的值大于等于5的话赋值为null返回给前端 |
| | | int value = (int) Integer.parseInt(modelValueItem.getValue()); |
| | | if ("FilterA".equals(modelValueItem.getId()) && value <= 5 || "FilterB".equals(modelValueItem.getId()) && value <= 5 |
| | | || "FilterC".equals(modelValueItem.getId()) && value <= 5 || "FilterD".equals(modelValueItem.getId()) && value <= 5) { |
| | | //根据滤芯寿命A小于等于5的设备id去查询设备信息 |
| | | Device deviceA = deviceService.selectDeviceById(deviceId); |
| | | DeviceFilterDto deviceFilterDto = new DeviceFilterDto(deviceA.getDeviceId(), deviceA.getDeviceName(), deviceA.getDeviceOrder().getUserName(), deviceA.getDeviceOrder().getUserPhone(), FilterAValue, FilterBValue, FilterCValue, FilterDValue); |
| | | list.add(deviceFilterDto); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | return null; |
| | | } |
| | | startPage(); |
| | | return getDataTable(list); |
| | | } |
| | | startPage(); |
| | | return getDataTable(list); |
| | | if ("tenant".equals(sysUser.getRoleKey())) { |
| | | List<DeviceFilterDto> list = new ArrayList<>(); |
| | | String FilterAValue = null; |
| | | String FilterBValue = null; |
| | | String FilterCValue = null; |
| | | String FilterDValue = null; |
| | | //根据登录的联营商查询出自己的设备 |
| | | List<Device> devices = deviceService.selectDeviceByTenantId(sysUser.getUserId()); |
| | | for (Device device : devices) { |
| | | String thingsModelValue = device.getThingsModelValue(); //拿到设备的物模型值 |
| | | Long deviceId = device.getDeviceId(); //拿到设备的id |
| | | if (!"[]".equals(thingsModelValue)) { |
| | | //解析物模型数据 |
| | | List<ThingsModelValueItem> thingsModelValueItems = JSONObject.parseArray(thingsModelValue, ThingsModelValueItem.class); |
| | | //循环遍历 |
| | | for (ThingsModelValueItem modelValueItem : thingsModelValueItems) { |
| | | if (!"".equals(modelValueItem.getValue())) { //判断物模型的值不等于空的字符串 |
| | | if ("FilterA".equals(modelValueItem.getId()) && !"".equals(modelValueItem.getValue())) { |
| | | FilterAValue = modelValueItem.getValue(); |
| | | } else if ("FilterB".equals(modelValueItem.getId()) && !"".equals(modelValueItem.getValue())) { |
| | | FilterBValue = modelValueItem.getValue(); |
| | | } else if ("FilterC".equals(modelValueItem.getId()) && !"".equals(modelValueItem.getValue())) { |
| | | FilterCValue = modelValueItem.getValue(); |
| | | } else if ("FilterD".equals(modelValueItem.getId()) && !"".equals(modelValueItem.getValue())) { |
| | | FilterDValue = modelValueItem.getValue(); |
| | | } |
| | | int value = Integer.parseInt(modelValueItem.getValue()); |
| | | if ("FilterA".equals(modelValueItem.getId()) && value <= 5 || "FilterB".equals(modelValueItem.getId()) && value <= 5 |
| | | || "FilterC".equals(modelValueItem.getId()) && value <= 5 || "FilterD".equals(modelValueItem.getId()) && value <= 5) { |
| | | //根据滤芯寿命A小于等于5的设备id去查询设备信息 |
| | | Device deviceA = deviceService.selectDeviceById(deviceId); |
| | | DeviceFilterDto deviceFilterDto = new DeviceFilterDto(deviceA.getDeviceId(), deviceA.getDeviceName(), deviceA.getDeviceOrder().getUserName(), deviceA.getDeviceOrder().getUserPhone(), FilterAValue, FilterBValue, FilterCValue, FilterDValue); |
| | | list.add(deviceFilterDto); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | startPage(); |
| | | return getDataTable(list); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | |
| | | util.exportExcel(response, list, "设备数据"); |
| | | } |
| | | |
| | | |
| | | //http://localhost/dev-api/iot/device/60 |
| | | |
| | | /** |
| | | * 获取设备详细信息 |
| | | */ |