146 lines
4.7 KiB
Java
146 lines
4.7 KiB
Java
package com.ruoyi.web.bst;
|
|
|
|
import com.ruoyi.bst.device.domain.Device;
|
|
import com.ruoyi.bst.device.domain.DeviceQuery;
|
|
import com.ruoyi.bst.device.domain.DeviceVO;
|
|
import com.ruoyi.bst.device.service.DeviceConverter;
|
|
import com.ruoyi.bst.device.service.DeviceIotService;
|
|
import com.ruoyi.bst.device.service.DeviceService;
|
|
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.page.TableDataInfo;
|
|
import com.ruoyi.common.core.validate.ValidGroup;
|
|
import com.ruoyi.common.enums.BusinessType;
|
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
import com.ruoyi.iot.constants.IotConstants;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiParam;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 设备Controller
|
|
*
|
|
* @author ruoyi
|
|
* @date 2025-04-23
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/bst/device")
|
|
public class DeviceController extends BaseController
|
|
{
|
|
@Autowired
|
|
private DeviceService deviceService;
|
|
@Autowired
|
|
private DeviceConverter deviceConverter;
|
|
@Autowired
|
|
private DeviceIotService deviceIotService;
|
|
|
|
/**
|
|
* 查询设备列表
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('bst:device:list')")
|
|
@GetMapping("/list")
|
|
public TableDataInfo list(DeviceQuery query)
|
|
{
|
|
startPage();
|
|
startOrderBy();
|
|
query.setDeleted(false);
|
|
query.setScope(true);
|
|
List<DeviceVO> list = deviceService.selectDeviceList(query);
|
|
deviceIotService.pullDeviceInfoList(list, IotConstants.ONLINE_TYPE_COMMAND);
|
|
return getDataTable(list);
|
|
}
|
|
|
|
/**
|
|
* 导出设备列表
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('bst:device:export')")
|
|
@Log(title = "设备", businessType = BusinessType.EXPORT)
|
|
@PostMapping("/export")
|
|
public void export(HttpServletResponse response, DeviceQuery query)
|
|
{
|
|
List<DeviceVO> list = deviceService.selectDeviceList(query);
|
|
ExcelUtil<DeviceVO> util = new ExcelUtil<DeviceVO>(DeviceVO.class);
|
|
util.exportExcel(response, list, "设备数据");
|
|
}
|
|
|
|
/**
|
|
* 获取设备详细信息
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('bst:device:query')")
|
|
@GetMapping(value = "/{deviceId}")
|
|
public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId)
|
|
{
|
|
return success(deviceService.selectDeviceByDeviceId(deviceId));
|
|
}
|
|
|
|
/**
|
|
* 新增设备
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('bst:device:add')")
|
|
@Log(title = "设备", businessType = BusinessType.INSERT)
|
|
@PostMapping
|
|
public AjaxResult add(@RequestBody @Validated(ValidGroup.Create.class) Device device)
|
|
{
|
|
deviceConverter.toPoByCreate(device);
|
|
return toAjax(deviceService.insertDevice(device));
|
|
}
|
|
|
|
/**
|
|
* 修改设备
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('bst:device:edit')")
|
|
@Log(title = "设备", businessType = BusinessType.UPDATE)
|
|
@PutMapping
|
|
public AjaxResult edit(@RequestBody @Validated(ValidGroup.Update.class)Device device)
|
|
{
|
|
deviceConverter.toPoByUpdate(device);
|
|
return toAjax(deviceService.updateDevice(device));
|
|
}
|
|
|
|
/**
|
|
* 删除设备
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('bst:device:remove')")
|
|
@Log(title = "设备", businessType = BusinessType.DELETE)
|
|
@DeleteMapping("/{ids}")
|
|
public AjaxResult remove(@PathVariable Long[] ids)
|
|
{
|
|
return toAjax(deviceService.deleteDeviceByDeviceIds(ids));
|
|
}
|
|
|
|
/**
|
|
* 逻辑删除设备
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('bst:device:remove')")
|
|
@Log(title = "设备", businessType = BusinessType.DELETE)
|
|
@DeleteMapping("/logic/{ids}")
|
|
public AjaxResult remove(@PathVariable List<Long> ids)
|
|
{
|
|
return toAjax(deviceService.logicDel(ids));
|
|
}
|
|
|
|
@PreAuthorize("@ss.hasPermi('system:device:bindStore')")
|
|
@Log(title = "设备绑定商户", businessType = BusinessType.OTHER)
|
|
@PutMapping("/{deviceId}/bindMch")
|
|
public AjaxResult bindMch(@PathVariable @ApiParam("设备id") Long deviceId, @RequestParam Long mchId) {
|
|
return AjaxResult.success("操作成功", deviceService.bindMch(deviceId, mchId));
|
|
}
|
|
|
|
@ApiOperation("解除设备绑定商户")
|
|
@PreAuthorize("@ss.hasPermi('system:device:unbind')")
|
|
@Log(title = "设备", businessType = BusinessType.OTHER)
|
|
@DeleteMapping("/{deviceId}/unbind")
|
|
public AjaxResult unbind(@PathVariable @ApiParam("设备id") Long deviceId) {
|
|
return toAjax(deviceService.unbind(deviceId));
|
|
}
|
|
|
|
|
|
}
|