2023-12-05 15:49:48 +08:00
|
|
|
package com.ruoyi.device.app;
|
|
|
|
|
2023-12-15 15:39:32 +08:00
|
|
|
import com.ruoyi.common.annotation.Log;
|
2023-12-05 15:49:48 +08:00
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
2023-12-15 15:39:32 +08:00
|
|
|
import com.ruoyi.common.enums.BusinessType;
|
2023-12-15 21:33:18 +08:00
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
2023-12-05 15:49:48 +08:00
|
|
|
import com.ruoyi.device.domain.AsDevice;
|
2023-12-15 15:39:32 +08:00
|
|
|
import com.ruoyi.device.domain.AsDeviceVersion;
|
2023-12-05 15:49:48 +08:00
|
|
|
import com.ruoyi.device.domain.AsWateringRecord;
|
|
|
|
import com.ruoyi.device.service.IAsDeviceService;
|
2023-12-15 15:39:32 +08:00
|
|
|
import com.ruoyi.device.service.IAsDeviceVersionService;
|
2023-12-05 15:49:48 +08:00
|
|
|
import com.ruoyi.device.service.IAsUserService;
|
|
|
|
import com.ruoyi.device.service.IAsWateringRecordService;
|
2023-12-15 15:39:32 +08:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
2023-12-05 15:49:48 +08:00
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户信息
|
|
|
|
*
|
|
|
|
* @author ruoyi
|
|
|
|
*/
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/app")
|
|
|
|
public class AppController extends BaseController
|
|
|
|
{
|
|
|
|
@Resource
|
|
|
|
private IAsUserService asUserService;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
private IAsWateringRecordService asWateringRecordService;
|
|
|
|
|
2023-12-15 15:39:32 +08:00
|
|
|
@Resource
|
2023-12-05 15:49:48 +08:00
|
|
|
private IAsDeviceService asDeviceService;
|
|
|
|
|
2023-12-15 15:39:32 +08:00
|
|
|
@Resource
|
|
|
|
private IAsDeviceVersionService asDeviceVersionService;
|
|
|
|
|
|
|
|
|
2023-12-05 15:49:48 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 根据登录用户获取绑定设备
|
|
|
|
*/
|
|
|
|
@GetMapping("/getDeviceInfoByUser")
|
2023-12-15 21:33:18 +08:00
|
|
|
public AjaxResult list(Long userId,String deviceId)
|
2023-12-05 15:49:48 +08:00
|
|
|
{
|
2023-12-15 21:33:18 +08:00
|
|
|
List<AsDevice> device;
|
|
|
|
if(StringUtils.isEmpty(deviceId) || "null".equals(deviceId)){
|
|
|
|
device = asUserService.selectDeviceInfoByUser(userId,null);
|
|
|
|
}else{
|
|
|
|
device = asUserService.selectDeviceInfoByUser(userId,Long.parseLong(deviceId));
|
|
|
|
}
|
2023-12-05 15:49:48 +08:00
|
|
|
return AjaxResult.success(device);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 滑动浇水
|
|
|
|
*/
|
|
|
|
@GetMapping(value = "/watering/{deviceId}/{wateringSwitch}")
|
|
|
|
public AjaxResult watering(@PathVariable("deviceId") Long deviceId,@PathVariable("wateringSwitch") Integer wateringSwitch)
|
|
|
|
{
|
|
|
|
AsDevice device = asDeviceService.selectAsDeviceByDeviceId(deviceId);
|
|
|
|
return asDeviceService.watering(device,wateringSwitch);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 根据设备id获取更多浇水记录
|
|
|
|
*/
|
|
|
|
@GetMapping("/getWateringRecord")
|
|
|
|
public TableDataInfo wateringRecord(String deviceId)
|
|
|
|
{
|
|
|
|
startPage();
|
|
|
|
List<AsWateringRecord> asWateringRecords = asWateringRecordService.selectAsWateringRecordList(AsWateringRecord.builder().deviceId(Long.parseLong(deviceId)).build());
|
|
|
|
return getDataTable(asWateringRecords);
|
|
|
|
}
|
|
|
|
|
2023-12-15 15:39:32 +08:00
|
|
|
/**
|
|
|
|
* 查询固件版本列表
|
|
|
|
*/
|
|
|
|
@GetMapping("/version/list")
|
|
|
|
public TableDataInfo list(AsDeviceVersion asDeviceVersion)
|
|
|
|
{
|
|
|
|
startPage();
|
|
|
|
List<AsDeviceVersion> list = asDeviceVersionService.selectAsDeviceVersionList(asDeviceVersion);
|
|
|
|
return getDataTable(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 修改设备列表
|
|
|
|
*/
|
|
|
|
@Log(title = "设备列表", businessType = BusinessType.UPDATE)
|
|
|
|
@PutMapping("/device")
|
|
|
|
public AjaxResult edit(@RequestBody AsDevice asDevice)
|
|
|
|
{
|
|
|
|
return toAjax(asDeviceService.updateAsDevice(asDevice));
|
|
|
|
}
|
2023-12-15 21:33:18 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取设备列表详细信息
|
|
|
|
*/
|
|
|
|
@GetMapping(value = "/getDeviceInfo/{deviceId}")
|
|
|
|
public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId)
|
|
|
|
{
|
|
|
|
return success(asDeviceService.selectAsDeviceByDeviceId(deviceId));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 删除设备列表
|
|
|
|
*/
|
|
|
|
@Log(title = "设备列表", businessType = BusinessType.DELETE)
|
|
|
|
@DeleteMapping("/device/{deviceIds}")
|
|
|
|
public AjaxResult remove(@PathVariable Long[] deviceIds)
|
|
|
|
{
|
|
|
|
return toAjax(asDeviceService.deleteAsDeviceByDeviceIds(deviceIds));
|
|
|
|
}
|
2024-01-24 12:02:48 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 植物识别
|
|
|
|
*/
|
|
|
|
@Log(title = "植物识别", businessType = BusinessType.OTHER)
|
|
|
|
@PostMapping("/plant/identify")
|
|
|
|
public AjaxResult plant(String url)
|
|
|
|
{
|
|
|
|
/** 请求百度获取token*/
|
|
|
|
// HttpUtils.
|
|
|
|
// try
|
|
|
|
// {
|
|
|
|
// // 上传文件路径
|
|
|
|
// String filePath = RuoYiConfig.getUploadPath();
|
|
|
|
// // 上传并返回新文件名称
|
|
|
|
// String fileName = FileUploadUtils.upload(filePath, file);
|
|
|
|
// String url = serverConfig.getUrl() + fileName;
|
|
|
|
// AjaxResult ajax = AjaxResult.success();
|
|
|
|
// ajax.put("url", url);
|
|
|
|
// ajax.put("fileName", fileName);
|
|
|
|
// ajax.put("newFileName", FileUtils.getName(fileName));
|
|
|
|
// ajax.put("originalFilename", file.getOriginalFilename());
|
|
|
|
// return ajax;
|
|
|
|
// }
|
|
|
|
// catch (Exception e)
|
|
|
|
// {
|
|
|
|
// return AjaxResult.error(e.getMessage());
|
|
|
|
// }
|
|
|
|
return AjaxResult.success();
|
|
|
|
}
|
2023-12-05 15:49:48 +08:00
|
|
|
}
|