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));
|
}
|
|
}
|