wumei-smart-master/springboot/wumei-iot/src/main/java/com/ruoyi/iot/controller/DeviceOrderController.java
@@ -25,6 +25,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.parameters.P;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -39,7 +40,7 @@
 * @author wmz
 * @version v1.0
 * @ClassName DeviceOrderController
 * @description 设备安装controller
 * @description 设备安装单/维修单controller
 * @createTime 2023/11/13 0:27
 */
@Api(tags = "设备安装信息")
@@ -51,9 +52,6 @@
    @Resource
    private IDeviceOrderService iDeviceOrderService;
    @Autowired
    private IDeviceService deviceService;
    @Autowired
    private IDeviceOrderTimeService deviceOrderTimeService;
@@ -85,29 +83,7 @@
    @GetMapping("/selecttimeout")
    @ApiOperation(value = "根据登录的联营商查询设备订单超时的时间间隔")
    public AjaxResult selectTimeout(DeviceOrderTime deviceOrderTime) throws Exception {
        DeviceOrderTime userDeviceOrder = deviceOrderTimeService.selectDeviceOrderTimeByUserId(deviceOrderTime.getUserId(), deviceOrderTime.getOrderType());
        if (userDeviceOrder != null) {
            List<DeviceOrderTime> rowsA = deviceOrderTimeService.selectReceiveTimeoutById(deviceOrderTime);
            List<DeviceOrderTime> rowsB = deviceOrderTimeService.selectFinishTimeoutById(deviceOrderTime);
            AjaxResult ajax = new AjaxResult();
            ajax.put("receiveTimeout", rowsA);
            ajax.put("finishTimeout", rowsB);
            return AjaxResult.success("查询成功", ajax);
        } else {
            deviceOrderTime.setReceiveTimeout(0);
            deviceOrderTime.setFinishTimeout(0);
            int row = deviceOrderTimeService.insertDeviceOrderTimeout(deviceOrderTime);
            if (row > 0) {
                List<DeviceOrderTime> rowsA = deviceOrderTimeService.selectReceiveTimeoutById(deviceOrderTime);
                List<DeviceOrderTime> rowsB = deviceOrderTimeService.selectFinishTimeoutById(deviceOrderTime);
                AjaxResult ajax = new AjaxResult();
                ajax.put("receiveTimeout", rowsA);
                ajax.put("finishTimeout", rowsB);
                return AjaxResult.success("查询成功", ajax);
            } else {
                return AjaxResult.error("添加数据失败");
            }
        }
        return deviceOrderTimeService.selectDeviceOrderTimeoutById(deviceOrderTime);
    }
    /**
@@ -118,21 +94,27 @@
     * @throws Exception
     */
    @PreAuthorize("@ss.hasAnyPermi('iot:deviceOrder:list')")
    @Log(title = "修改设备订单信息", businessType = BusinessType.UPDATE)
    @PostMapping("/updatetimeout")
    @Log(title = "联营商登录后修改设备订单超时的时间间隔", businessType = BusinessType.UPDATE)
    @PutMapping("/updatetimeout")
    @ApiOperation(value = "根据登录的联营商修改设备订单超时的时间间隔")
    public AjaxResult assignDeviceOrderTimeout(DeviceOrderTime deviceOrderTime) throws Exception {
        DeviceOrderTime userDeviceOrder = deviceOrderTimeService.selectDeviceOrderTimeByUserId(deviceOrderTime.getUserId(), deviceOrderTime.getOrderType());
        if (userDeviceOrder != null) {
            return toAjax(deviceOrderTimeService.updateDeviceOrderTimeoutById(deviceOrderTime));
        } else {
            int rowsB = deviceOrderTimeService.insertDeviceOrderTimeout(deviceOrderTime);
            if (rowsB > 0) {
                return toAjax(deviceOrderTimeService.updateDeviceOrderTimeoutById(deviceOrderTime));
            } else {
                return AjaxResult.error("添加数据失败");
            }
        }
        return deviceOrderTimeService.updateDeviceOrderTimeoutById(deviceOrderTime);
    }
    /**
     * 安装单/维修单完成后用户的评价
     *
     * @param deviceOrder
     * @return
     * @throws Exception 参数是安装单的id,用户的id,ordertype类型
     */
    @PreAuthorize("@ss.hasAnyPermi('iot:deviceOrder:list')")
    @PostMapping("/editDeviceOrderScore")
    @Log(title = "安装单/维修单完成后用户添加评价", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "安装单/维修单完成后用户的评价")
    public AjaxResult updateDeviceOrderScoreAndComment(DeviceOrder deviceOrder) throws Exception {
        return iDeviceOrderService.updateDeviceOrderScoreAndComment(deviceOrder);
    }
    /**
@@ -147,24 +129,7 @@
    @ApiOperation(value = "获取未派单/已派单/已接单/已完成的安装单/维修单数量")
    public AjaxResult selectDeviceOrderCount(DeviceOrder deviceOrder) throws Exception {
        if (deviceOrder != null) {
            //根据登录的用户来查询自己未派单的安装单/维修单数量
            int count = iDeviceOrderService.selectDeviceOrderCountByUndeliveredorders(deviceOrder);
            //根据登录的用户来查询自己已派单的安装单/维修单数量
            int total = iDeviceOrderService.selectDeviceOrderCountByDispatchedorders(deviceOrder);
            //根据登录的用户来查询自己已接单的安装单/维修单数量
            int number = iDeviceOrderService.selectDeviceOrderCountByReceivedorders(deviceOrder);
            //根据登录的用户来查询自己已完成的安装单/维修单数量
            int amount = iDeviceOrderService.selectDeviceOrderCountByCompleted(deviceOrder);
            AjaxResult ajax = new AjaxResult();
            //未派单的安装单/维修单的数量
            ajax.put("deviceOrderUndeliveredorders", count);
            //已派单的安装单/维修单的数量
            ajax.put("deviceOrderDispatchedorders", total);
            //已接单的安装单/维修单的数量
            ajax.put("deviceOrderReceivedorders", number);
            //已完成的安装单/维修单的数量
            ajax.put("deviceOrderCompleted", amount);
            return AjaxResult.success("查询成功", ajax);
            return iDeviceOrderService.selectDeviceOrderCountByUndeliveredorders(deviceOrder);
        } else {
            return AjaxResult.error("未查询到有关信息");
        }
@@ -182,45 +147,7 @@
    @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);
        }
        //判断传过来的orderType的值是否为2-维修
        if ("2".equals(deviceOrder.getOrderType())) {
            log.info("orderType{}", deviceOrder.getOrderType());
            System.out.println(deviceOrder.getOrderType());
            //更新订单的用户信息
            SysUser sysUser = getLoginUser().getUser();
            deviceOrder.setCreateUserId(sysUser.getUserId());
            //插入维修单
            int rows = iDeviceOrderService.insertDeviceOrder(deviceOrder);
            if (rows > 0) {
                Device device1 = deviceService.selectDeviceByDeviceId(deviceOrder.getDeviceId());
                //更新当前设备的是否维修信息-未维修
                Device device = new Device();
                device.setDeviceId(deviceOrder.getDeviceId());
                device.setRepairFlag(1);
                device.setStatus(device1.getStatus());
                deviceService.updateDevice(device);
            }
            return toAjax(rows);
        }
        //更新订单的用户信息
        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);
        return iDeviceOrderService.insertDeviceOrder(deviceOrder);
    }
    /**
@@ -235,54 +162,7 @@
    @Log(title = "修改设备订单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceOrder deviceOrder) throws Exception {
        //判断传过来的orderType的值是否为1-安装,并且安装单的状态为已完成,修改设备的状态为离线状态
        if ("1".equals(deviceOrder.getOrderType()) && deviceOrder.getState() == 3) {
            log.info("OrderType{}", deviceOrder.getOrderType());
            log.info("State{}", deviceOrder.getState());
            System.out.println(deviceOrder.getOrderType());
            System.out.println(deviceOrder.getState());
            //获取修改订单的用户信息
            SysUser sysUser = getLoginUser().getUser();
            //拿到修改安装单的用户id
            deviceOrder.setUpdateUserId(sysUser.getUserId());
            deviceOrder.setFinishTime(new Date());
            int rows = iDeviceOrderService.updateDeviceOrder(deviceOrder);
            if (rows > 0) {
                Device device = new Device();
                device.setDeviceId(deviceOrder.getDeviceId());
                //修改设备的状态为离线
                device.setStatus(4);
                deviceService.updateDevice(device);
            }
            return toAjax(rows);
        }
        //判断传过来的orderType的值是否为2-维修,并且维修单的状态为为已完成,修改设备的是否维修为0-已维修
        if ("2".equals(deviceOrder.getOrderType()) && deviceOrder.getState() == 3) {
            log.info("OrderType{}", deviceOrder.getOrderType());
            log.info("State{}", deviceOrder.getState());
            System.out.println(deviceOrder.getOrderType());
            System.out.println(deviceOrder.getState());
            //获取修改订单的用户信息
            SysUser sysUser = getLoginUser().getUser();
            //拿到修维修单的用户id
            deviceOrder.setUpdateUserId(sysUser.getUserId());
            deviceOrder.setFinishTime(new Date());
            int rows = iDeviceOrderService.updateDeviceOrder(deviceOrder);
            if (rows > 0) {
                Device device1 = deviceService.selectDeviceByDeviceId(deviceOrder.getDeviceId());
                Device device = new Device();
                device.setDeviceId(deviceOrder.getDeviceId());
                device.setRepairFlag(0);
                device.setStatus(device1.getStatus());
                deviceService.updateDevice(device);
            }
            return toAjax(rows);
        }
        //获取修改订单的用户信息
        SysUser sysUser = getLoginUser().getUser();
        //拿到修改安装单的用户id
        deviceOrder.setUpdateUserId(sysUser.getUserId());
        return toAjax(iDeviceOrderService.updateDeviceOrder(deviceOrder));
        return iDeviceOrderService.updateDeviceOrder(deviceOrder);
    }
    /**
@@ -297,21 +177,7 @@
    @DeleteMapping("/{deviceId}")
    @ApiOperation("删除订单信息")
    public AjaxResult remove(@PathVariable("deviceId") Integer deviceId) throws Exception {
        //根据要删除安装单的id查询出安装单信息
        DeviceOrder deviceOrder = iDeviceOrderService.selectDeviceOrderById(deviceId);
        SysUser user = getLoginUser().getUser();
        //如果根据查询出来的安装单对象不为空的话,并且状态等于未派单才可以删除
        if (deviceOrder != null && deviceOrder.getState() == 0 && user.getUserId() != 1) {
            //未派单的安装单删除后设备的状态更新为-未激活
            Device device = new Device();
            device.setDeviceId(deviceOrder.getDeviceId());
            device.setStatus(1);
            deviceService.updateDevice(device);
            int i = iDeviceOrderService.deleteDeviceOrderById(deviceOrder.getId());
            return toAjax(i);
        } else {
            return AjaxResult.error();
        }
        return iDeviceOrderService.deleteDeviceOrderById(deviceId);
    }
    /**