| | |
| | | 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; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import static sun.audio.AudioDevice.device; |
| | | |
| | | /** |
| | | * 设备Controller |
| | | * |
| | | * |
| | | * @author kerwincui |
| | | * @date 2021-12-16 |
| | | */ |
| | | @Api(tags = "设备管理") |
| | | @RestController |
| | | @RequestMapping("/iot/device") |
| | | public class DeviceController extends BaseController |
| | | { |
| | | public class DeviceController extends BaseController { |
| | | |
| | | @Autowired |
| | | private IDeviceService deviceService; |
| | | |
| | |
| | | @PreAuthorize("@ss.hasPermi('iot:device:list')") |
| | | @GetMapping("/list") |
| | | @ApiOperation("设备分页列表") |
| | | public TableDataInfo list(Device device) |
| | | { |
| | | public TableDataInfo list(Device device) { |
| | | startPage(); |
| | | return getDataTable(deviceService.selectDeviceList(device)); |
| | | } |
| | | |
| | | /** |
| | | * 查询首页的总用户数(人),总设备数(台) |
| | | * |
| | | * @param id |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('iot:device:list')") |
| | | @GetMapping("/select/{id}") |
| | | @ApiOperation(value = "获取总用户数和总设备数") |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | |
| | | @PreAuthorize("@ss.hasPermi('iot:device:list')") |
| | | @GetMapping("/unAuthlist") |
| | | @ApiOperation("设备分页列表") |
| | | public TableDataInfo unAuthlist(Device device) |
| | | { |
| | | public TableDataInfo unAuthlist(Device device) { |
| | | startPage(); |
| | | return getDataTable(deviceService.selectUnAuthDeviceList(device)); |
| | | } |
| | |
| | | @PreAuthorize("@ss.hasPermi('iot:device:list')") |
| | | @GetMapping("/listByGroup") |
| | | @ApiOperation("查询分组可添加设备分页列表") |
| | | public TableDataInfo listByGroup(Device device) |
| | | { |
| | | public TableDataInfo listByGroup(Device device) { |
| | | startPage(); |
| | | return getDataTable(deviceService.selectDeviceListByGroup(device)); |
| | | } |
| | |
| | | @PreAuthorize("@ss.hasPermi('iot:device:list')") |
| | | @GetMapping("/shortList") |
| | | @ApiOperation("设备分页简短列表") |
| | | public TableDataInfo shortList(Device device) |
| | | { |
| | | 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:list')") |
| | | @GetMapping("/all") |
| | | @ApiOperation("查询所有设备简短列表") |
| | | public TableDataInfo allShortList() |
| | | { |
| | | public TableDataInfo allShortList() { |
| | | return getDataTable(deviceService.selectAllDeviceShortList()); |
| | | } |
| | | |
| | |
| | | @Log(title = "设备", businessType = BusinessType.EXPORT) |
| | | @PostMapping("/export") |
| | | @ApiOperation("导出设备") |
| | | public void export(HttpServletResponse response, Device device) |
| | | { |
| | | public void export(HttpServletResponse response, Device device) { |
| | | List<Device> list = deviceService.selectDeviceList(device); |
| | | ExcelUtil<Device> util = new ExcelUtil<Device>(Device.class); |
| | | util.exportExcel(response, list, "设备数据"); |
| | |
| | | @PreAuthorize("@ss.hasPermi('iot:device:query')") |
| | | @GetMapping(value = "/{deviceId}") |
| | | @ApiOperation("获取设备详情") |
| | | public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId) |
| | | { |
| | | public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId) { |
| | | return AjaxResult.success(deviceService.selectDeviceByDeviceId(deviceId)); |
| | | } |
| | | |
| | |
| | | @PreAuthorize("@ss.hasPermi('iot:device:query')") |
| | | @GetMapping(value = "/synchronization/{serialNumber}") |
| | | @ApiOperation("设备数据同步") |
| | | public AjaxResult deviceSynchronization(@PathVariable("serialNumber") String serialNumber) |
| | | { |
| | | public AjaxResult deviceSynchronization(@PathVariable("serialNumber") String serialNumber) { |
| | | return AjaxResult.success(emqxService.deviceSynchronization(serialNumber)); |
| | | } |
| | | |
| | |
| | | @PreAuthorize("@ss.hasPermi('iot:device:query')") |
| | | @GetMapping(value = "/getDeviceBySerialNumber/{serialNumber}") |
| | | @ApiOperation("根据设备编号获取设备详情") |
| | | public AjaxResult getInfoBySerialNumber(@PathVariable("serialNumber") String serialNumber) |
| | | { |
| | | public AjaxResult getInfoBySerialNumber(@PathVariable("serialNumber") String serialNumber) { |
| | | return AjaxResult.success(deviceService.selectDeviceBySerialNumber(serialNumber)); |
| | | } |
| | | |
| | |
| | | @PreAuthorize("@ss.hasPermi('iot:device:query')") |
| | | @GetMapping(value = "/statistic") |
| | | @ApiOperation("获取设备统计信息") |
| | | public AjaxResult getDeviceStatistic() |
| | | { |
| | | public AjaxResult getDeviceStatistic() { |
| | | return AjaxResult.success(deviceService.selectDeviceStatistic()); |
| | | } |
| | | |
| | |
| | | @PreAuthorize("@ss.hasPermi('iot:device:query')") |
| | | @GetMapping(value = "/runningStatus/{deviceId}") |
| | | @ApiOperation("获取设备详情和运行状态") |
| | | public AjaxResult getRunningStatusInfo(@PathVariable("deviceId") Long deviceId) |
| | | { |
| | | public AjaxResult getRunningStatusInfo(@PathVariable("deviceId") Long deviceId) { |
| | | return AjaxResult.success(deviceService.selectDeviceRunningStatusByDeviceId(deviceId)); |
| | | } |
| | | |
| | |
| | | @Log(title = "添加设备", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | @ApiOperation("添加设备") |
| | | public AjaxResult add(@RequestBody Device device) |
| | | { |
| | | public AjaxResult add(@RequestBody Device device) { |
| | | return AjaxResult.success(deviceService.insertDevice(device)); |
| | | } |
| | | |
| | |
| | | @Log(title = "设备关联用户", businessType = BusinessType.UPDATE) |
| | | @PostMapping("/relateUser") |
| | | @ApiOperation("设备关联用户") |
| | | public AjaxResult relateUser(@RequestBody DeviceRelateUserInput deviceRelateUserInput) |
| | | { |
| | | if(deviceRelateUserInput.getUserId()==0 || deviceRelateUserInput.getUserId()==null){ |
| | | public AjaxResult relateUser(@RequestBody DeviceRelateUserInput deviceRelateUserInput) { |
| | | if (deviceRelateUserInput.getUserId() == 0 || deviceRelateUserInput.getUserId() == null) { |
| | | return AjaxResult.error("用户ID不能为空"); |
| | | } |
| | | if(deviceRelateUserInput.getDeviceNumberAndProductIds()==null || deviceRelateUserInput.getDeviceNumberAndProductIds().size()==0){ |
| | | if (deviceRelateUserInput.getDeviceNumberAndProductIds() == null || deviceRelateUserInput.getDeviceNumberAndProductIds().size() == 0) { |
| | | return AjaxResult.error("设备编号和产品ID不能为空"); |
| | | } |
| | | return deviceService.deviceRelateUser(deviceRelateUserInput); |
| | |
| | | @Log(title = "修改设备", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | @ApiOperation("修改设备") |
| | | public AjaxResult edit(@RequestBody Device device) |
| | | { |
| | | public AjaxResult edit(@RequestBody Device device) { |
| | | return deviceService.updateDevice(device); |
| | | } |
| | | |
| | | /** |
| | | * 重新指派设备 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('iot:device:edit')") |
| | | @Log(title = "重新指派设备", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/assignDevice") |
| | | @ApiOperation("重新指派设备") |
| | | public AjaxResult assignDevice(@RequestBody Device device) { |
| | | device.setAssignTime(DateUtils.getNowDate()); |
| | | return deviceService.updateDevice(device); |
| | | } |
| | | |
| | |
| | | @Log(title = "重置设备状态", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/reset/{serialNumber}") |
| | | @ApiOperation("重置设备状态") |
| | | public AjaxResult resetDeviceStatus(@PathVariable String serialNumber) |
| | | { |
| | | Device device=new Device(); |
| | | public AjaxResult resetDeviceStatus(@PathVariable String serialNumber) { |
| | | Device device = new Device(); |
| | | device.setSerialNumber(serialNumber); |
| | | return toAjax(deviceService.resetDeviceStatus(device.getSerialNumber())); |
| | | } |
| | |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('iot:device:remove')") |
| | | @Log(title = "删除设备", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{deviceIds}") |
| | | @DeleteMapping("/{deviceIds}") |
| | | @ApiOperation("批量删除设备") |
| | | public AjaxResult remove(@PathVariable Long[] deviceIds) throws SchedulerException { |
| | | return toAjax(deviceService.deleteDeviceByDeviceId(deviceIds[0])); |
| | |
| | | @PreAuthorize("@ss.hasPermi('iot:device:edit')") |
| | | @GetMapping("/generator") |
| | | @ApiOperation("生成设备编号") |
| | | public AjaxResult generatorDeviceNum(){ |
| | | return AjaxResult.success("操作成功",deviceService.generationDeviceNum()); |
| | | public AjaxResult generatorDeviceNum() { |
| | | return AjaxResult.success("操作成功", deviceService.generationDeviceNum()); |
| | | } |
| | | } |