1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package com.ruoyi.iot.controller;
 
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.iot.domain.DeviceOrder;
import com.ruoyi.iot.domain.DeviceOrderTime;
import com.ruoyi.iot.service.IDeviceOrderService;
import com.ruoyi.iot.service.IDeviceOrderTimeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.springframework.web.multipart.MultipartFile;
 
import javax.annotation.Resource;
import java.util.List;
 
/**
 * @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 {
 
    private static final Logger log = LoggerFactory.getLogger(DeviceOrderController.class);
 
    @Resource
    private IDeviceOrderService iDeviceOrderService;
 
    @Autowired
    private IDeviceOrderTimeService deviceOrderTimeService;
 
    /**
     * 查询全部设备安装单订单信息
     *
     * @param deviceOrder
     * @return
     * @throws Exception
     */
    @PreAuthorize("@ss.hasAnyPermi('iot:deviceOrder:list')")
    @GetMapping("/list")
    @ApiOperation(value = "获取设备订单分页列表")
    public TableDataInfo list(DeviceOrder deviceOrder) throws Exception {
        startPage();
        List<DeviceOrder> list = iDeviceOrderService.selectDeviceOrderList(deviceOrder);
        return getDataTable(list);
    }
 
    /**
     * 根据登录的联营商查询设备订单超时的时间间隔
     *
     * @param deviceOrderTime
     * @return
     * @throws Exception
     */
    @PreAuthorize("@ss.hasAnyPermi('iot:deviceOrder:list')")
    @GetMapping("/selecttimeout")
    @ApiOperation(value = "根据登录的联营商查询设备订单超时的时间间隔")
    public AjaxResult selectTimeout(DeviceOrderTime deviceOrderTime) throws Exception {
        return deviceOrderTimeService.selectDeviceOrderTimeoutById(deviceOrderTime);
    }
 
    /**
     * 根据登录的联营商修改设备订单超时的时间间隔
     *
     * @param deviceOrderTime
     * @return
     * @throws Exception
     */
    @PreAuthorize("@ss.hasAnyPermi('iot:deviceOrder:list')")
    @Log(title = "联营商登录后修改设备订单超时的时间间隔", businessType = BusinessType.UPDATE)
    @PutMapping("/updatetimeout")
    @ApiOperation(value = "根据登录的联营商修改设备订单超时的时间间隔")
    public AjaxResult assignDeviceOrderTimeout(DeviceOrderTime deviceOrderTime) throws Exception {
        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);
    }
 
    /**
     * 查询未派单/已派单/已接单/已完成的安装单/维修单数维修单数量
     *
     * @param deviceOrder
     * @return
     * @throws Exception
     */
    @PreAuthorize("@ss.hasAnyPermi('iot:deviceOrder:list')")
    @GetMapping("/get")
    @ApiOperation(value = "获取未派单/已派单/已接单/已完成的安装单/维修单数量")
    public AjaxResult selectDeviceOrderCount(DeviceOrder deviceOrder) throws Exception {
        if (deviceOrder != null) {
            return iDeviceOrderService.selectDeviceOrderCountByUndeliveredOrders(deviceOrder);
        } else {
            return AjaxResult.error("未查询到有关信息");
        }
    }
 
    /**
     * 添加安装设备订单信息
     *
     * @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 {
        return iDeviceOrderService.insertDeviceOrder(deviceOrder);
    }
 
    /**
     * 修改设备订单信息
     *
     * @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 iDeviceOrderService.updateDeviceOrder(deviceOrder);
    }
 
    /**
     * 删除设备订单信息
     *
     * @param deviceId
     * @return
     * @throws Exception
     */
    @PreAuthorize("@ss.hasPermi('iot:device:remove')")
    @Log(title = "删除设备订单信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}/{deviceId}")
    @ApiOperation("删除设备订单信息")
    public AjaxResult remove(@PathVariable("id") Long id, @PathVariable("deviceId") Long deviceId) throws Exception {
        return iDeviceOrderService.deleteDeviceOrderById(id, deviceId);
    }
 
    /**
     * 安装单图片上传
     *
     * @param file
     * @return
     * @throws Exception
     */
 
    @Log(title = "安装单图片上传", businessType = BusinessType.INSERT)
    @PostMapping("/Install/profile/avatar")
    @ApiOperation("安装单图片上传")
    public AjaxResult deviceOrderinstallImgUrl(@RequestParam("avatarfile") MultipartFile file) throws Exception {
        // 判断头像文件不为空
        if (!file.isEmpty()) {
            // 通过Security获取到登录的用户信息
            LoginUser loginUser = getLoginUser();
            String avatar = FileUploadUtils.upload(RuoYiConfig.getDeviceOrderInstallPath(), file);
            AjaxResult ajax = AjaxResult.success();
            ajax.put("imgUrl", avatar);
            return ajax;
        }
        return AjaxResult.error("图片上传失败");
    }
 
    /**
     * 维修单图片上传
     *
     * @param file
     * @return
     * @throws Exception
     */
    @Log(title = "维修单图片上传", businessType = BusinessType.INSERT)
    @PostMapping("/Repair/profile/avatar")
    @ApiOperation("维修单图片上传")
    public AjaxResult deviceOrderRepairImgUrl(@RequestParam("avatarfile") MultipartFile file) throws Exception {
        // 判断头像文件不为空
        if (!file.isEmpty()) {
            // 通过Security获取到登录的用户信息
            LoginUser loginUser = getLoginUser();
            String avatar = FileUploadUtils.upload(RuoYiConfig.getDeviceOrderRepairPath(), file);
            AjaxResult ajax = AjaxResult.success();
            ajax.put("imgUrl", avatar);
            return ajax;
        }
        return AjaxResult.error("图片上传失败");
    }
}