admin
2023-11-01 50fe2303fef148de18d39f90a8653feda1b21c05
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
package com.ruoyi.iot.controller;
 
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
 
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.framework.config.ServerConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.iot.domain.JointOperator;
import com.ruoyi.iot.service.IJointOperatorService;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;
 
/**
 * 联营商Controller
 *
 * @author kerwincui
 * @date 2023-10-07
 */
@Api(tags = "联营商")
@RestController
@RequestMapping("/iot/operator")
public class JointOperatorController extends BaseController {
    @Autowired
    private IJointOperatorService jointOperatorService;
 
    @Autowired
    private ServerConfig serverConfig;
 
    /**
     * 查询联营商列表
     */
//    @ApiOperation("查询联营商列表")
    @PreAuthorize("@ss.hasPermi('iot:operator:list')")
    @GetMapping("/list")
    public TableDataInfo list(JointOperator jointOperator) {
        startPage();
        List<JointOperator> list = jointOperatorService.selectJointOperatorList(jointOperator);
        return getDataTable(list);
    }
 
    /**
     * 获取联营商详细信息
     */
//    @ApiOperation("获取联营商详细信息")
    @PreAuthorize("@ss.hasPermi('iot:operator:query')")
    @GetMapping(value = "/{no}")
    public AjaxResult getInfo(@PathVariable("no") String no) {
        return AjaxResult.success(jointOperatorService.selectJointOperatorByNo(no));
    }
 
//    /**
//     * 新增联营商
//     */
//    @PreAuthorize("@ss.hasPermi('iot:operator:add')")
//    @Log(title = "联营商", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody JointOperator jointOperator)
//    {
//        return toAjax(jointOperatorService.insertJointOperator(jointOperator));
//    }
 
    /**
     * 修改联营商
     */
//    @ApiOperation("修改联营商")
    @PreAuthorize("@ss.hasPermi('iot:operator:edit')")
    @Log(title = "联营商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JointOperator jointOperator) {
        return toAjax(jointOperatorService.updateJointOperator(jointOperator));
    }
 
//    /**
//     * 删除联营商
//     */
//    @PreAuthorize("@ss.hasPermi('iot:operator:remove')")
//    @Log(title = "联营商", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{nos}")
//    public AjaxResult remove(@PathVariable String[] nos)
//    {
//        return toAjax(jointOperatorService.deleteJointOperatorByNos(nos));
//    }
 
    @ApiOperation(value = "通过roleKey获取用户列表")
    @PreAuthorize("@ss.hasPermi('*:*:*')")
    @GetMapping("/user/list")
    public TableDataInfo list(String roleKey) {
        startPage();
        List<SysUser> list = jointOperatorService.selectListByRole(roleKey);
        return getDataTable(list);
    }
 
    @ApiOperation(value = "上传设备SN.txt更新设备租户为当前用户")
    @PreAuthorize("@ss.hasPermi('*:*:*')")
    @Log(title = "联营商", businessType = BusinessType.UPDATE)
    @PostMapping("/device/batchEdit")
    public AjaxResult batchEdit(@RequestParam("file") MultipartFile file,
                                @RequestParam("tenantId") Long tenantId) throws Exception {
        // 获取文件输入流
        BufferedReader reader = new BufferedReader(new InputStreamReader(file.getInputStream()));
 
        // 读取文本内容
        String line;
        List<String> lines = new ArrayList<>();
        while ((line = reader.readLine()) != null) {
            lines.add(line.trim());
        }
        // 关闭文件输入流
        reader.close();
        return toAjax(jointOperatorService.updateDeviceBySN(lines, tenantId));
    }
 
    @ApiOperation(value = "绑定设备SN为终端用户")
    @PreAuthorize("@ss.hasPermi('*:*:*')")
    @Log(title = "终端用户", businessType = BusinessType.UPDATE)
    @PostMapping("/device/bindUser")
    public AjaxResult bindUser(@RequestParam("serialNumber") String serialNumber,
                                @RequestParam("userId") Long userId) throws Exception {
 
        List<String> lines = new ArrayList<>();
        lines.add(serialNumber);
        return toAjax(jointOperatorService.updateDeviceUserBySN(lines, userId));
    }
 
}