|
|
|
package com.zhonglai.luhui.api.controller.user;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.*;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
...
|
...
|
@@ -17,6 +14,7 @@ import com.zhonglai.luhui.sys.utils.ExcelUtil; |
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
...
|
...
|
@@ -113,6 +111,7 @@ public class UserTerminalGroupRelationController extends BaseController |
|
|
|
*/
|
|
|
|
@ApiOperation("新增终端分组关系")
|
|
|
|
@Log(title = "终端分组关系", businessType = BusinessType.INSERT)
|
|
|
|
@Transactional
|
|
|
|
@PostMapping
|
|
|
|
public AjaxResult add(@RequestBody UserTerminalGroupRelation userTerminalGroupRelation)
|
|
|
|
{
|
|
...
|
...
|
@@ -132,6 +131,19 @@ public class UserTerminalGroupRelationController extends BaseController |
|
|
|
newuserTerminalGroupRelation.setUser_info_id(userid);
|
|
|
|
list.add(newuserTerminalGroupRelation);
|
|
|
|
}
|
|
|
|
String ids = "'"+iotTerminalIds.replace(",","','")+"'";
|
|
|
|
List<Map<String,Object>> userIdlist = publicService.getObjectListBySQL("SELECT user_info_id,device_id FROM `iot_terminal` WHERE device_id IN(SELECT device_id FROM `iot_terminal` WHERE id IN("+ids+"))");
|
|
|
|
if(null != userIdlist && userIdlist.size() >0)
|
|
|
|
{
|
|
|
|
for (Map<String,Object> map:userIdlist)
|
|
|
|
{
|
|
|
|
if(null != map.get("user_info_id") && !String.valueOf(map.get("user_info_id")).equals(String.valueOf(userid)))
|
|
|
|
{
|
|
|
|
return AjaxResult.error("设备"+map.get("device_id")+"已被其他人绑定");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
publicService.updateBySql("UPDATE `iot_terminal` SET user_info_id="+userid+" WHERE id IN("+ids+")");
|
|
|
|
return toAjax( publicService.insertAll(list));
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -148,7 +160,8 @@ public class UserTerminalGroupRelationController extends BaseController |
|
|
|
{
|
|
|
|
return AjaxResult.error("终端id必填");
|
|
|
|
}
|
|
|
|
int i = publicService.updateBySql("UPDATE `user_terminal_group_relation` SET iot_terminal_group_id="+userTerminalGroupRelation.getIot_terminal_group_id()+",iot_terminal_group_name='"+userTerminalGroupRelation.getIot_terminal_group_name()+"' WHERE iot_terminal_id IN('"+iotTerminalIds.replace(",","','")+"') and user_info_id="+SecurityUtils.getUserId().intValue());
|
|
|
|
String ids = "'"+iotTerminalIds.replace(",","','")+"'";
|
|
|
|
int i = publicService.updateBySql("UPDATE `user_terminal_group_relation` SET iot_terminal_group_id="+userTerminalGroupRelation.getIot_terminal_group_id()+",iot_terminal_group_name='"+userTerminalGroupRelation.getIot_terminal_group_name()+"' WHERE iot_terminal_id IN("+ids+") and user_info_id="+SecurityUtils.getUserId().intValue());
|
|
|
|
return toAjax(i);
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -156,10 +169,13 @@ public class UserTerminalGroupRelationController extends BaseController |
|
|
|
* 删除终端分组关系
|
|
|
|
*/
|
|
|
|
@ApiOperation("删除终端分组关系")
|
|
|
|
@Transactional
|
|
|
|
@Log(title = "终端分组关系", businessType = BusinessType.DELETE)
|
|
|
|
@DeleteMapping("/{ids}")
|
|
|
|
public AjaxResult remove(@PathVariable Integer[] ids)
|
|
|
|
{
|
|
|
|
String idss = "'"+Arrays.toString(ids).replace(",","','")+"'";
|
|
|
|
publicService.updateBySql("UPDATE `iot_terminal` SET user_info_id=null WHERE id IN("+idss+")");
|
|
|
|
return toAjax(userTerminalGroupRelationService.deleteUserTerminalGroupRelationByIds(ids));
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -191,4 +207,12 @@ public class UserTerminalGroupRelationController extends BaseController |
|
|
|
map.put("offline",offline);
|
|
|
|
return AjaxResult.success(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation("查询用户下的所有网关")
|
|
|
|
@GetMapping(value = "/getIotDeviceList")
|
|
|
|
public AjaxResult getIotDeviceList()
|
|
|
|
{
|
|
|
|
Integer userid = SecurityUtils.getUserId().intValue();
|
|
|
|
return AjaxResult.success(publicService.getObjectListBySQL("SELECT `client_id`,`name`,`mqtt_username` FROM `iot_device` WHERE client_id IN(SELECT DISTINCT device_id FROM iot_terminal WHERE user_info_id = "+userid+")"));
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|