package com.ruoyi.iot.controller;
|
|
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.constant.UserConstants;
|
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.iot.domain.Device;
|
import com.ruoyi.iot.domain.DeviceOrder;
|
import com.ruoyi.iot.service.IDeviceOrderService;
|
import com.ruoyi.iot.service.IDeviceService;
|
import com.ruoyi.system.service.ISysUserService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
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 org.thymeleaf.util.ArrayUtils;
|
|
import javax.annotation.Resource;
|
import java.util.List;
|
|
import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;
|
|
/**
|
* @author wmz
|
* @version v1.0
|
* @ClassName DeviceOrderController
|
* @description 设备安装controller
|
* @createTime 2023/11/13 0:27
|
*/
|
@Api(tags = "设备安装信息")
|
@RestController
|
@RequestMapping("/iot/deviceOrder")
|
public class DeviceOrderController extends BaseController {
|
|
@Resource
|
private IDeviceOrderService iDeviceOrderService;
|
|
@Autowired
|
private IDeviceService deviceService;
|
|
/**
|
* 查询全部设备订单信息
|
*
|
* @return
|
* @throws Exception
|
*/
|
@PreAuthorize("@ss.hasAnyPermi('iot:deviceOrder:list')")
|
@GetMapping("/list")
|
@ApiOperation(value = "获取设备订单分页列表")
|
public TableDataInfo list(DeviceOrder deviceOrder) throws Exception {
|
startPage();
|
SysUser sysUser = getLoginUser().getUser();
|
deviceOrder.setCreateUserId(sysUser.getUserId());
|
List<DeviceOrder> list = iDeviceOrderService.selectDeviceOrderList(deviceOrder);
|
return getDataTable(list);
|
}
|
|
/**
|
* 添加安装设备订单信息
|
*
|
* @param deviceOrder
|
* @return
|
* @throws Exception
|
*/
|
@ApiOperation("添加安装单")
|
@PreAuthorize("@ss.hasPermi('iot:device:add')")
|
@Log(title = "添加安装单信息", businessType = BusinessType.INSERT)
|
@PostMapping
|
public AjaxResult add(@Validated @RequestBody DeviceOrder deviceOrder) throws Exception {
|
//更新订单的初始化状态
|
if ("未指派".equals(deviceOrder.getErectoName())) {
|
deviceOrder.setState(0);
|
} else {
|
deviceOrder.setState(1);
|
}
|
//更新订单的用户信息
|
SysUser sysUser = getLoginUser().getUser();
|
deviceOrder.setCreateUserId(sysUser.getUserId());
|
//插入安装订单
|
int rows = iDeviceOrderService.insertDeviceOrder(deviceOrder);
|
if (rows > 0) {
|
//更新当前设备状态信息--安装中
|
Device device = new Device();
|
device.setDeviceId(deviceOrder.getDeviceId());
|
device.setStatus(5);
|
deviceService.updateDevice(device);
|
}
|
return toAjax(rows);
|
}
|
|
/**
|
* 修改设备订单信息
|
*
|
* @param deviceOrder
|
* @return
|
* @throws Exception
|
*/
|
@ApiOperation(value = "修改设备订单信息")
|
@PreAuthorize("@ss.hasPermi('iot:device:edit')")
|
@Log(title = "修改设备订单信息", businessType = BusinessType.UPDATE)
|
@PutMapping
|
public AjaxResult edit(@RequestBody DeviceOrder deviceOrder) throws Exception {
|
return AjaxResult.success(iDeviceOrderService.updateDeviceOrder(deviceOrder));
|
}
|
|
/**
|
* 删除设备订单信息
|
*
|
* @param deviceId
|
* @return
|
* @throws Exception
|
*/
|
@PreAuthorize("@ss.hasPermi('iot:device:list')")
|
@Log(title = "修改设备订单信息", businessType = BusinessType.DELETE)
|
@DeleteMapping("/{deviceId}")
|
@ApiOperation("删除订单信息")
|
public AjaxResult remove(@PathVariable("deviceId") Integer deviceId) throws Exception {
|
//根据要删除安装单的id查询出安装单信息
|
DeviceOrder deviceOrder = iDeviceOrderService.selectDeviceOrderById(deviceId);
|
//如果根据查询出来的安装单对象不为空的话,并且状态等于未派单才可以删除
|
if (deviceOrder != null && deviceOrder.getState() == 0) {
|
int i = iDeviceOrderService.deleteDeviceOrderById(deviceOrder.getId());
|
return toAjax(i);
|
} else {
|
return AjaxResult.error();
|
}
|
}
|
}
|