后端多租户调整

This commit is contained in:
kerwincui
2022-06-03 17:21:51 +08:00
parent 168d987779
commit 4999c2abcb
28 changed files with 80 additions and 175 deletions

View File

@@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.iot.model.IdAndName;
import io.swagger.annotations.Api;
@@ -49,15 +51,7 @@ public class CategoryController extends BaseController
public TableDataInfo list(Category category)
{
startPage();
List<Category> list = new ArrayList<>();
if(category.getTenantName()== null || category.getTenantName()=="")
{
list = categoryService.selectCategoryList(category);
}else {
list = categoryService.selectCategoryListAccurate(category);
}
return getDataTable(list);
return getDataTable(categoryService.selectCategoryList(category));
}
/**

View File

@@ -44,15 +44,7 @@ public class DeviceController extends BaseController
public TableDataInfo list(Device device)
{
startPage();
List<Device> list = new ArrayList<>();
if(device.getUserId() == null)
{
list = deviceService.selectDeviceList(device);
}else {
// 精确查询
list = deviceService.selectDeviceListAccurate(device);
}
return getDataTable(list);
return getDataTable(deviceService.selectDeviceList(device));
}
/**
@@ -64,15 +56,7 @@ public class DeviceController extends BaseController
public TableDataInfo shortList(Device device)
{
startPage();
List<DeviceShortOutput> list = new ArrayList<>();
if(device.getUserId() == null)
{
list = deviceService.selectDeviceShortList(device);
}else {
// 精确查询
list = deviceService.selectDeviceShortListAccurate(device);
}
return getDataTable(list);
return getDataTable(deviceService.selectDeviceShortList(device));
}
/**

View File

@@ -59,9 +59,7 @@ public class FirmwareController extends BaseController
public TableDataInfo list(Firmware firmware)
{
startPage();
System.out.print("租户名称"+firmware.getTenantName()+"hs");
List<Firmware> list = firmwareService.selectFirmwareList(firmware);
return getDataTable(list);
return getDataTable(firmwareService.selectFirmwareList(firmware));
}
/**

View File

@@ -50,17 +50,7 @@ public class GroupController extends BaseController
public TableDataInfo list(Group group)
{
startPage();
List<Group> list = new ArrayList<>();
if(group.getUserName() == null || group.getUserName().equals(""))
{
// 搜索查询 ,mapper使用的是模糊查询
list = groupService.selectGroupList(group);
}else {
// 精准查询
list = groupService.selectGroupListAccurate(group);
}
return getDataTable(list);
return getDataTable(groupService.selectGroupList(group));
}
/**

View File

@@ -43,14 +43,7 @@ public class ProductController extends BaseController
public TableDataInfo list(Product product)
{
startPage();
List<Product> list = new ArrayList<>();
if(product.getTenantName()=="" ||product.getTenantName()==null)
{
list = productService.selectProductList(product);
}else {
list = productService.selectProductListAccurate(product);
}
return getDataTable(list);
return getDataTable(productService.selectProductList(product));
}
/**

View File

@@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -25,6 +27,8 @@ import com.ruoyi.iot.service.IThingsModelTemplateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;
/**
* 通用物模型Controller
*
@@ -48,14 +52,7 @@ public class ThingsModelTemplateController extends BaseController
public TableDataInfo list(ThingsModelTemplate thingsModelTemplate)
{
startPage();
List<ThingsModelTemplate> list = new ArrayList<>();
if (thingsModelTemplate.getTenantName().equals("")|| thingsModelTemplate.getTenantName() == null){
list = thingsModelTemplateService.selectThingsModelTemplateList(thingsModelTemplate);
}else{
// 精准查询
list = thingsModelTemplateService.selectThingsModelTemplateListAccurate(thingsModelTemplate);
}
return getDataTable(list);
return getDataTable(thingsModelTemplateService.selectThingsModelTemplateList(thingsModelTemplate));
}
/**

View File

@@ -77,8 +77,6 @@ public interface CategoryMapper
* @return 结果
*/
public int productCountInCategorys(Long[] categoryIds);
// 精准查询
List<Category> selectCategoryListAccurate(Category category);
List<IdAndName> selectCategoryShortListAccurate(Category category);
}

View File

@@ -180,5 +180,4 @@ public interface DeviceMapper
*/
List<Device> selectDeviceListAccurate(Device device);
List<DeviceShortOutput> selectDeviceShortListAccurate(Device device);
}

View File

@@ -84,6 +84,4 @@ public interface GroupMapper
*/
public int deleteDeviceGroupByGroupIds(Long[] groupIds);
// 精准查询所有
List<Group> selectGroupListAccurate(Group group);
}

View File

@@ -116,6 +116,4 @@ public interface ProductMapper
* @return 结果
*/
public int thingsCountInProduct(Long productId);
// 精准查询
List<Product> selectProductListAccurate(Product product);
}

View File

@@ -68,6 +68,5 @@ public interface ThingsModelTemplateMapper
* @return 结果
*/
public int deleteThingsModelTemplateByTemplateIds(Long[] templateIds);
// 精准查询
List<ThingsModelTemplate> selectThingsModelTemplateListAccurate(ThingsModelTemplate thingsModelTemplate);
}

View File

@@ -69,8 +69,5 @@ public interface ICategoryService
*/
public int deleteCategoryByCategoryId(Long categoryId);
// 精准查询
List<Category> selectCategoryListAccurate(Category category);
List<IdAndName> selectCategoryShortListAccurate(Category category);
}

View File

@@ -172,10 +172,4 @@ public interface IDeviceService
*/
List<Device> selectDeviceListAccurate(Device device);
/**
* 精准查询所有条件设备的简短信息
* @param device
* @return
*/
List<DeviceShortOutput> selectDeviceShortListAccurate(Device device);
}

View File

@@ -73,7 +73,4 @@ public interface IGroupService
* @return 结果
*/
public int deleteGroupByGroupId(Long groupId);
// 精准查询
List<Group> selectGroupListAccurate(Group group);
}

View File

@@ -78,6 +78,4 @@ public interface IProductService
*/
public int deleteProductByProductId(Long productId);
// 精准查询
List<Product> selectProductListAccurate(Product product);
}

View File

@@ -59,6 +59,4 @@ public interface IThingsModelTemplateService
*/
public int deleteThingsModelTemplateByTemplateId(Long templateId);
// 精准查询
List<ThingsModelTemplate> selectThingsModelTemplateListAccurate(ThingsModelTemplate thingsModelTemplate);
}

View File

@@ -48,6 +48,12 @@ public class CategoryServiceImpl implements ICategoryService
@Override
public List<Category> selectCategoryList(Category category)
{
SysUser user = getLoginUser().getUser();
List<SysRole> roles=user.getRoles();
// 租户
if(roles.stream().anyMatch(a->a.getRoleKey().equals("tenant"))){
category.setTenantId(user.getUserId());
}
return categoryMapper.selectCategoryList(category);
}
@@ -132,9 +138,4 @@ public class CategoryServiceImpl implements ICategoryService
{
return categoryMapper.deleteCategoryByCategoryId(categoryId);
}
@Override
public List<Category> selectCategoryListAccurate(Category category) {
return categoryMapper.selectCategoryListAccurate(category);
}
}

View File

@@ -3,6 +3,7 @@ package com.ruoyi.iot.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
@@ -218,6 +219,17 @@ public class DeviceServiceImpl implements IDeviceService {
*/
@Override
public List<Device> selectDeviceList(Device device) {
SysUser user = getLoginUser().getUser();
List<SysRole> roles=user.getRoles();
for(int i=0;i<roles.size();i++){
if(roles.get(i).getRoleKey().equals("tenant")){
// 租户查看产品下所有设备
device.setTenantId(user.getUserId());
}else if (roles.get(i).getRoleKey().equals("general")){
// 用户查看自己设备
device.setUserId(user.getUserId());
}
}
return deviceMapper.selectDeviceList(device);
}
@@ -241,6 +253,20 @@ public class DeviceServiceImpl implements IDeviceService {
@Override
public List<DeviceShortOutput> selectDeviceShortList(Device device) {
// TODO 关联设备用户表
SysUser user = getLoginUser().getUser();
List<SysRole> roles=user.getRoles();
for(int i=0;i<roles.size();i++){
if(roles.get(i).getRoleKey().equals("tenant")){
// 租户查看产品下所有设备
device.setTenantId(user.getUserId());
break;
}else if (roles.get(i).getRoleKey().equals("general")){
// 用户查看自己设备
device.setUserId(user.getUserId());
break;
}
}
List<DeviceShortOutput> deviceList = deviceMapper.selectDeviceShortList(device);
for (int i = 0; i < deviceList.size(); i++) {
JSONObject thingsModelObject = JSONObject.parseObject(thingsModelService.getCacheThingsModelByProductId(deviceList.get(i).getProductId()));
@@ -254,11 +280,6 @@ public class DeviceServiceImpl implements IDeviceService {
return deviceList;
}
// 精准查询所有条件的设备
@Override
public List<DeviceShortOutput> selectDeviceShortListAccurate(Device device) {
return deviceMapper.selectDeviceShortListAccurate(device);
}
/**
* Json物模型集合转换为对象中的分类集合

View File

@@ -46,6 +46,12 @@ public class FirmwareServiceImpl implements IFirmwareService
@Override
public List<Firmware> selectFirmwareList(Firmware firmware)
{
SysUser user = getLoginUser().getUser();
List<SysRole> roles=user.getRoles();
// 租户
if(roles.stream().anyMatch(a->a.getRoleKey().equals("tenant"))){
firmware.setTenantId(user.getUserId());
}
return firmwareMapper.selectFirmwareList(firmware);
}

View File

@@ -1,5 +1,6 @@
package com.ruoyi.iot.service.impl;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.iot.domain.Group;
@@ -63,6 +64,15 @@ public class GroupServiceImpl implements IGroupService
@Override
public List<Group> selectGroupList(Group group)
{
SysUser user = getLoginUser().getUser();
List<SysRole> roles=user.getRoles();
for(int i=0;i<roles.size();i++){
if (roles.get(i).getRoleKey().equals("general")){
// 用户查看自己设备
group.setUserId(user.getUserId());
break;
}
}
return groupMapper.selectGroupList(group);
}
@@ -140,9 +150,4 @@ public class GroupServiceImpl implements IGroupService
return groupMapper.deleteGroupByGroupId(groupId);
}
// 精准查询所有
@Override
public List<Group> selectGroupListAccurate(Group group) {
return groupMapper.selectGroupListAccurate(group);
}
}

View File

@@ -59,6 +59,12 @@ public class ProductServiceImpl implements IProductService
@Override
public List<Product> selectProductList(Product product)
{
SysUser user = getLoginUser().getUser();
List<SysRole> roles=user.getRoles();
// 租户
if(roles.stream().anyMatch(a->a.getRoleKey().equals("tenant"))){
product.setTenantId(user.getUserId());
}
return productMapper.selectProductList(product);
}
@@ -194,9 +200,4 @@ public class ProductServiceImpl implements IProductService
redisCache.deleteObject(tslPreKey+productId);
return productMapper.deleteProductByProductId(productId);
}
// 精准查询
@Override
public List<Product> selectProductListAccurate(Product product) {
return productMapper.selectProductListAccurate(product);
}
}

View File

@@ -47,6 +47,12 @@ public class ThingsModelTemplateServiceImpl implements IThingsModelTemplateServi
@Override
public List<ThingsModelTemplate> selectThingsModelTemplateList(ThingsModelTemplate thingsModelTemplate)
{
SysUser user = getLoginUser().getUser();
List<SysRole> roles=user.getRoles();
// 租户
if(roles.stream().anyMatch(a->a.getRoleKey().equals("tenant"))){
thingsModelTemplate.setTenantId(user.getUserId());
}
return thingsModelTemplateMapper.selectThingsModelTemplateList(thingsModelTemplate);
}
@@ -108,9 +114,4 @@ public class ThingsModelTemplateServiceImpl implements IThingsModelTemplateServi
{
return thingsModelTemplateMapper.deleteThingsModelTemplateByTemplateId(templateId);
}
// 精准查询
@Override
public List<ThingsModelTemplate> selectThingsModelTemplateListAccurate(ThingsModelTemplate thingsModelTemplate) {
return thingsModelTemplateMapper.selectThingsModelTemplateListAccurate(thingsModelTemplate);
}
}