Merge branch 'dev-V0.4.5' of https://gitee.com/iotkit-open-source/iotkit-parent into dev-V0.4.5

V0.5.x
荭琪枫 2023-05-28 23:37:42 +08:00
commit 7e48dfd5a3
53 changed files with 544 additions and 1657 deletions

View File

@ -1,5 +1,6 @@
package cc.iotkit.common.api; package cc.iotkit.common.api;
import cc.iotkit.common.utils.MapstructUtils;
import lombok.Data; import lombok.Data;
import java.util.Date; import java.util.Date;
@ -38,4 +39,7 @@ public class BaseDto {
*/ */
private Date updateTime; private Date updateTime;
public <T> T to(Class<T> tClass) {
return MapstructUtils.convert(this, tClass);
}
} }

View File

@ -1,12 +1,13 @@
package cc.iotkit.common.api; package cc.iotkit.common.api;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.common.utils.SnowflakeIdGeneratorUtil; import cc.iotkit.common.utils.SnowflakeIdGeneratorUtil;
import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min; import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import java.util.Map; import java.util.Map;
import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.*;
import java.io.Serializable; import java.io.Serializable;
@ -18,6 +19,9 @@ import java.io.Serializable;
*/ */
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Data @Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class PageRequest<T> extends Request<T> implements Serializable { public class PageRequest<T> extends Request<T> implements Serializable {
/** /**
@ -71,13 +75,14 @@ public class PageRequest<T> extends Request<T> implements Serializable {
return pageRequest; return pageRequest;
} }
public static <DTO> PageRequest<DTO> copyPageRequest(PageRequest query,DTO data) { public <DTO> PageRequest<DTO> to(Class<DTO> dtoClass) {
DTO dto = MapstructUtils.convert(getData(), dtoClass);
PageRequest<DTO> pageRequest = new PageRequest<>(); PageRequest<DTO> pageRequest = new PageRequest<>();
pageRequest.setData(data); pageRequest.setData(dto);
pageRequest.setPageNum(query.getPageNum()); pageRequest.setPageNum(this.getPageNum());
pageRequest.setPageSize(query.getPageSize()); pageRequest.setPageSize(this.getPageSize());
pageRequest.setRequestId(query.getRequestId()); pageRequest.setRequestId(this.getRequestId());
pageRequest.setSortMap(query.getSortMap()); pageRequest.setSortMap(this.getSortMap());
return pageRequest; return pageRequest;
} }

View File

@ -9,6 +9,7 @@
*/ */
package cc.iotkit.common.api; package cc.iotkit.common.api;
import cc.iotkit.common.utils.MapstructUtils;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -24,4 +25,7 @@ public class Paging<T> {
private List<T> data; private List<T> data;
public <VO> Paging<VO> to(Class<VO> voClass) {
return MapstructUtils.convert(this, voClass);
}
} }

View File

@ -1,5 +1,6 @@
package cc.iotkit.model; package cc.iotkit.model;
import cc.iotkit.common.utils.MapstructUtils;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
@ -40,4 +41,7 @@ public class BaseModel implements Serializable {
*/ */
private Date updateTime; private Date updateTime;
public <T> T to(Class<T> tClass) {
return MapstructUtils.convert(this, tClass);
}
} }

View File

@ -1,7 +1,9 @@
package cc.iotkit.model.system; package cc.iotkit.model.system;
import cc.iotkit.model.BaseModel;
import cc.iotkit.model.Id; import cc.iotkit.model.Id;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
@ -13,8 +15,9 @@ import java.util.Date;
* @author Michelle.Chung * @author Michelle.Chung
* @date 2023-02-07 * @date 2023-02-07
*/ */
@EqualsAndHashCode(callSuper = true)
@Data @Data
public class SysOperLog implements Id<Long>,Serializable { public class SysOperLog extends BaseModel implements Id<Long>, Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**

View File

@ -1,9 +1,12 @@
package cc.iotkit.data.system; package cc.iotkit.data.system;
import cc.iotkit.data.ICommonData;
import cc.iotkit.model.system.SysOss;
/** /**
* *
* *
* @author sjg * @author sjg
*/ */
public interface ISysOssData { public interface ISysOssData extends ICommonData<SysOss, Long> {
} }

View File

@ -1,9 +1,12 @@
package cc.iotkit.data.system; package cc.iotkit.data.system;
import cc.iotkit.data.ICommonData;
import cc.iotkit.model.system.SysPost;
/** /**
* *
* *
* @author sjg * @author sjg
*/ */
public interface ISysPostData { public interface ISysPostData extends ICommonData<SysPost, Long> {
} }

View File

@ -1,9 +1,12 @@
package cc.iotkit.data.system; package cc.iotkit.data.system;
import cc.iotkit.data.ICommonData;
import cc.iotkit.model.system.SysTenantPackage;
/** /**
* *
* *
* @author sjg * @author sjg
*/ */
public interface ISysTenantPackageData { public interface ISysTenantPackageData extends ICommonData<SysTenantPackage, Long> {
} }

View File

@ -1,5 +1,6 @@
package cc.iotkit.data.service; package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.constant.Constants; import cc.iotkit.common.constant.Constants;
import cc.iotkit.data.manager.ICategoryData; import cc.iotkit.data.manager.ICategoryData;
import cc.iotkit.data.cache.CategoryCacheEvict; import cc.iotkit.data.cache.CategoryCacheEvict;
@ -10,6 +11,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List; import java.util.List;
@Service @Service
@ -27,6 +29,11 @@ public class CategoryDataCache implements ICategoryData {
return categoryData.findById(s); return categoryData.findById(s);
} }
@Override
public List<Category> findByIds(Collection<String> id) {
return null;
}
@Override @Override
public Category save(Category data) { public Category save(Category data) {
data = categoryData.save(data); data = categoryData.save(data);
@ -34,13 +41,18 @@ public class CategoryDataCache implements ICategoryData {
return data; return data;
} }
@Override
public void batchSave(List<Category> data) {
}
@Override @Override
public void deleteById(String s) { public void deleteById(String s) {
categoryData.deleteById(s); categoryData.deleteById(s);
} }
@Override @Override
public void deleteByIds(String[] strings) { public void deleteByIds(Collection<String> strings) {
} }
@ -55,7 +67,18 @@ public class CategoryDataCache implements ICategoryData {
} }
@Override @Override
public Paging<Category> findAll(int page, int size) { public Paging<Category> findAll(PageRequest<Category> pageRequest) {
return categoryData.findAll(page, size); return categoryData.findAll(pageRequest);
} }
@Override
public List<Category> findAllByCondition(Category data) {
return null;
}
@Override
public Category findOneByCondition(Category data) {
return null;
}
} }

View File

@ -9,6 +9,7 @@
*/ */
package cc.iotkit.data.service; package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.constant.Constants; import cc.iotkit.common.constant.Constants;
import cc.iotkit.common.utils.JsonUtils; import cc.iotkit.common.utils.JsonUtils;
import cc.iotkit.data.manager.IDeviceInfoData; import cc.iotkit.data.manager.IDeviceInfoData;
@ -60,7 +61,11 @@ public class DeviceInfoDataCache implements IDeviceInfoData, SmartInitializingSi
int page = 1; int page = 1;
Paging<DeviceInfo> paged; Paging<DeviceInfo> paged;
List<String> parentIds = new ArrayList<>(); List<String> parentIds = new ArrayList<>();
while ((paged = deviceInfoData.findAll(page++, 1000)).getData().size() > 0) { PageRequest<DeviceInfo> pageRequest = new PageRequest<>();
pageRequest.setPageSize(1000);
while ((paged = deviceInfoData.findAll(pageRequest)).getData().size() > 0) {
pageRequest.setPageNum(page++);
List<DeviceInfo> devices = paged.getData(); List<DeviceInfo> devices = paged.getData();
for (DeviceInfo device : devices) { for (DeviceInfo device : devices) {
//装载设备信息缓存 //装载设备信息缓存
@ -207,6 +212,11 @@ public class DeviceInfoDataCache implements IDeviceInfoData, SmartInitializingSi
return deviceInfoData.findById(s); return deviceInfoData.findById(s);
} }
@Override
public List<DeviceInfo> findByIds(Collection<String> id) {
return null;
}
@Override @Override
public DeviceInfo save(DeviceInfo data) { public DeviceInfo save(DeviceInfo data) {
DeviceInfo r = deviceInfoData.save(data); DeviceInfo r = deviceInfoData.save(data);
@ -218,8 +228,8 @@ public class DeviceInfoDataCache implements IDeviceInfoData, SmartInitializingSi
} }
@Override @Override
public DeviceInfo add(DeviceInfo data) { public void batchSave(List<DeviceInfo> data) {
return save(data);
} }
@Override @Override
@ -236,8 +246,7 @@ public class DeviceInfoDataCache implements IDeviceInfoData, SmartInitializingSi
} }
@Override @Override
public void deleteByIds(String[] strings) { public void deleteByIds(Collection<String> strings) {
} }
@Override @Override
@ -251,8 +260,18 @@ public class DeviceInfoDataCache implements IDeviceInfoData, SmartInitializingSi
} }
@Override @Override
public Paging<DeviceInfo> findAll(int page, int size) { public Paging<DeviceInfo> findAll(PageRequest<DeviceInfo> pageRequest) {
return deviceInfoData.findAll(page, size); return deviceInfoData.findAll(pageRequest);
}
@Override
public List<DeviceInfo> findAllByCondition(DeviceInfo data) {
return null;
}
@Override
public DeviceInfo findOneByCondition(DeviceInfo data) {
return null;
} }
/** /**

View File

@ -9,6 +9,7 @@
*/ */
package cc.iotkit.data.service; package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.data.manager.IDeviceInfoData; import cc.iotkit.data.manager.IDeviceInfoData;
import cc.iotkit.common.api.Paging; import cc.iotkit.common.api.Paging;
import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.device.DeviceInfo;
@ -17,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -37,14 +39,19 @@ public class DeviceInfoPropertyDataCache implements IDeviceInfoData {
return deviceInfoData.findById(s); return deviceInfoData.findById(s);
} }
@Override
public List<DeviceInfo> findByIds(Collection<String> id) {
return null;
}
@Override @Override
public DeviceInfo save(DeviceInfo data) { public DeviceInfo save(DeviceInfo data) {
return deviceInfoData.save(data); return deviceInfoData.save(data);
} }
@Override @Override
public DeviceInfo add(DeviceInfo data) { public void batchSave(List<DeviceInfo> data) {
return deviceInfoData.add(data);
} }
@Override @Override
@ -53,7 +60,7 @@ public class DeviceInfoPropertyDataCache implements IDeviceInfoData {
} }
@Override @Override
public void deleteByIds(String[] strings) { public void deleteByIds(Collection<String> strings) {
} }
@ -68,8 +75,18 @@ public class DeviceInfoPropertyDataCache implements IDeviceInfoData {
} }
@Override @Override
public Paging<DeviceInfo> findAll(int page, int size) { public Paging<DeviceInfo> findAll(PageRequest<DeviceInfo> pageRequest) {
return deviceInfoData.findAll(page, size); return deviceInfoData.findAll(pageRequest);
}
@Override
public List<DeviceInfo> findAllByCondition(DeviceInfo data) {
return null;
}
@Override
public DeviceInfo findOneByCondition(DeviceInfo data) {
return null;
} }
@Override @Override

View File

@ -9,6 +9,7 @@
*/ */
package cc.iotkit.data.service; package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.constant.Constants; import cc.iotkit.common.constant.Constants;
import cc.iotkit.data.manager.IOauthClientData; import cc.iotkit.data.manager.IOauthClientData;
import cc.iotkit.data.cache.OauthClientCacheEvict; import cc.iotkit.data.cache.OauthClientCacheEvict;
@ -19,6 +20,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List; import java.util.List;
@Service @Service
@ -41,6 +43,11 @@ public class OauthClientDataCache implements IOauthClientData {
return oauthClientData.findById(s); return oauthClientData.findById(s);
} }
@Override
public List<OauthClient> findByIds(Collection<String> id) {
return null;
}
@Override @Override
public OauthClient save(OauthClient data) { public OauthClient save(OauthClient data) {
OauthClient oauthClient = oauthClientData.save(data); OauthClient oauthClient = oauthClientData.save(data);
@ -50,8 +57,8 @@ public class OauthClientDataCache implements IOauthClientData {
} }
@Override @Override
public OauthClient add(OauthClient data) { public void batchSave(List<OauthClient> data) {
return oauthClientData.add(data);
} }
@Override @Override
@ -60,7 +67,7 @@ public class OauthClientDataCache implements IOauthClientData {
} }
@Override @Override
public void deleteByIds(String[] strings) { public void deleteByIds(Collection<String> strings) {
} }
@ -75,7 +82,18 @@ public class OauthClientDataCache implements IOauthClientData {
} }
@Override @Override
public Paging<OauthClient> findAll(int page, int size) { public Paging<OauthClient> findAll(PageRequest<OauthClient> pageRequest) {
return oauthClientData.findAll(page, size); return oauthClientData.findAll(pageRequest);
} }
@Override
public List<OauthClient> findAllByCondition(OauthClient data) {
return null;
}
@Override
public OauthClient findOneByCondition(OauthClient data) {
return null;
}
} }

View File

@ -1,5 +1,6 @@
package cc.iotkit.data.service; package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.constant.Constants; import cc.iotkit.common.constant.Constants;
import cc.iotkit.data.manager.IProductData; import cc.iotkit.data.manager.IProductData;
import cc.iotkit.data.cache.ProductCacheEvict; import cc.iotkit.data.cache.ProductCacheEvict;
@ -10,6 +11,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List; import java.util.List;
@Service @Service
@ -47,6 +49,11 @@ public class ProductDataCache implements IProductData {
return productData.findById(s); return productData.findById(s);
} }
@Override
public List<Product> findByIds(Collection<String> id) {
return null;
}
@Override @Override
public Product save(Product data) { public Product save(Product data) {
Product p = productData.save(data); Product p = productData.save(data);
@ -56,8 +63,8 @@ public class ProductDataCache implements IProductData {
} }
@Override @Override
public Product add(Product data) { public void batchSave(List<Product> data) {
return productData.add(data);
} }
@Override @Override
@ -68,7 +75,7 @@ public class ProductDataCache implements IProductData {
} }
@Override @Override
public void deleteByIds(String[] strings) { public void deleteByIds(Collection<String> strings) {
} }
@ -83,7 +90,17 @@ public class ProductDataCache implements IProductData {
} }
@Override @Override
public Paging<Product> findAll(int page, int size) { public Paging<Product> findAll(PageRequest<Product> pageRequest) {
return productData.findAll(page, size); return productData.findAll(pageRequest);
}
@Override
public List<Product> findAllByCondition(Product data) {
return null;
}
@Override
public Product findOneByCondition(Product data) {
return null;
} }
} }

View File

@ -1,5 +1,6 @@
package cc.iotkit.data.service; package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.constant.Constants; import cc.iotkit.common.constant.Constants;
import cc.iotkit.data.manager.IProductModelData; import cc.iotkit.data.manager.IProductModelData;
import cc.iotkit.data.cache.ProductModelCacheEvict; import cc.iotkit.data.cache.ProductModelCacheEvict;
@ -10,6 +11,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List; import java.util.List;
@Service @Service
@ -37,6 +39,11 @@ public class ProductModelDataCache implements IProductModelData {
return productModelData.findById(s); return productModelData.findById(s);
} }
@Override
public List<ProductModel> findByIds(Collection<String> id) {
return null;
}
@Override @Override
public ProductModel save(ProductModel data) { public ProductModel save(ProductModel data) {
ProductModel productModel = productModelData.save(data); ProductModel productModel = productModelData.save(data);
@ -45,8 +52,8 @@ public class ProductModelDataCache implements IProductModelData {
} }
@Override @Override
public ProductModel add(ProductModel data) { public void batchSave(List<ProductModel> data) {
return productModelData.add(data);
} }
@Override @Override
@ -55,7 +62,7 @@ public class ProductModelDataCache implements IProductModelData {
} }
@Override @Override
public void deleteByIds(String[] strings) { public void deleteByIds(Collection<String> strings) {
} }
@ -70,7 +77,18 @@ public class ProductModelDataCache implements IProductModelData {
} }
@Override @Override
public Paging<ProductModel> findAll(int page, int size) { public Paging<ProductModel> findAll(PageRequest<ProductModel> pageRequest) {
return productModelData.findAll(page, size); return productModelData.findAll(pageRequest);
} }
@Override
public List<ProductModel> findAllByCondition(ProductModel data) {
return null;
}
@Override
public ProductModel findOneByCondition(ProductModel data) {
return null;
}
} }

View File

@ -1,5 +1,6 @@
package cc.iotkit.data.service; package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.constant.Constants; import cc.iotkit.common.constant.Constants;
import cc.iotkit.data.manager.ISpaceData; import cc.iotkit.data.manager.ISpaceData;
import cc.iotkit.data.cache.SpaceCacheEvict; import cc.iotkit.data.cache.SpaceCacheEvict;
@ -10,6 +11,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List; import java.util.List;
@Service @Service
@ -57,6 +59,11 @@ public class SpaceDataCache implements ISpaceData {
return spaceData.findById(s); return spaceData.findById(s);
} }
@Override
public List<Space> findByIds(Collection<String> id) {
return null;
}
@Override @Override
public Space save(Space data) { public Space save(Space data) {
data = spaceData.save(data); data = spaceData.save(data);
@ -65,8 +72,8 @@ public class SpaceDataCache implements ISpaceData {
} }
@Override @Override
public Space add(Space data) { public void batchSave(List<Space> data) {
return spaceData.add(data);
} }
@Override @Override
@ -75,7 +82,7 @@ public class SpaceDataCache implements ISpaceData {
} }
@Override @Override
public void deleteByIds(String[] strings) { public void deleteByIds(Collection<String> strings) {
} }
@ -90,7 +97,18 @@ public class SpaceDataCache implements ISpaceData {
} }
@Override @Override
public Paging<Space> findAll(int page, int size) { public Paging<Space> findAll(PageRequest<Space> pageRequest) {
return spaceData.findAll(page, size); return spaceData.findAll(pageRequest);
} }
@Override
public List<Space> findAllByCondition(Space data) {
return null;
}
@Override
public Space findOneByCondition(Space data) {
return null;
}
} }

View File

@ -1,5 +1,6 @@
package cc.iotkit.data.service; package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.constant.Constants; import cc.iotkit.common.constant.Constants;
import cc.iotkit.data.manager.IThingModelData; import cc.iotkit.data.manager.IThingModelData;
import cc.iotkit.data.cache.ThingModelCacheEvict; import cc.iotkit.data.cache.ThingModelCacheEvict;
@ -10,6 +11,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List; import java.util.List;
@Service @Service
@ -27,6 +29,11 @@ public class ThingModelDataCache implements IThingModelData {
return thingModelData.findById(s); return thingModelData.findById(s);
} }
@Override
public List<ThingModel> findByIds(Collection<String> id) {
return null;
}
@Override @Override
public ThingModel save(ThingModel data) { public ThingModel save(ThingModel data) {
data = thingModelData.save(data); data = thingModelData.save(data);
@ -35,8 +42,8 @@ public class ThingModelDataCache implements IThingModelData {
} }
@Override @Override
public ThingModel add(ThingModel data) { public void batchSave(List<ThingModel> data) {
return thingModelData.add(data);
} }
@Override @Override
@ -45,7 +52,7 @@ public class ThingModelDataCache implements IThingModelData {
} }
@Override @Override
public void deleteByIds(String[] strings) { public void deleteByIds(Collection<String> strings) {
} }
@ -60,8 +67,18 @@ public class ThingModelDataCache implements IThingModelData {
} }
@Override @Override
public Paging<ThingModel> findAll(int page, int size) { public Paging<ThingModel> findAll(PageRequest<ThingModel> pageRequest) {
return thingModelData.findAll(page, size); return thingModelData.findAll(pageRequest);
}
@Override
public List<ThingModel> findAllByCondition(ThingModel data) {
return null;
}
@Override
public ThingModel findOneByCondition(ThingModel data) {
return null;
} }
} }

View File

@ -1,5 +1,6 @@
package cc.iotkit.data.service; package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.constant.Constants; import cc.iotkit.common.constant.Constants;
import cc.iotkit.data.manager.IUserInfoData; import cc.iotkit.data.manager.IUserInfoData;
import cc.iotkit.data.cache.UserInfoCacheEvict; import cc.iotkit.data.cache.UserInfoCacheEvict;
@ -10,6 +11,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List; import java.util.List;
@Service @Service
@ -42,6 +44,11 @@ public class UserInfoDataCache implements IUserInfoData {
return userInfoData.findById(s); return userInfoData.findById(s);
} }
@Override
public List<UserInfo> findByIds(Collection<String> id) {
return null;
}
@Override @Override
public UserInfo save(UserInfo data) { public UserInfo save(UserInfo data) {
UserInfo userInfo = userInfoData.save(data); UserInfo userInfo = userInfoData.save(data);
@ -51,8 +58,8 @@ public class UserInfoDataCache implements IUserInfoData {
} }
@Override @Override
public UserInfo add(UserInfo data) { public void batchSave(List<UserInfo> data) {
return userInfoData.add(data);
} }
@Override @Override
@ -61,7 +68,7 @@ public class UserInfoDataCache implements IUserInfoData {
} }
@Override @Override
public void deleteByIds(String[] strings) { public void deleteByIds(Collection<String> strings) {
} }
@ -76,7 +83,18 @@ public class UserInfoDataCache implements IUserInfoData {
} }
@Override @Override
public Paging<UserInfo> findAll(int page, int size) { public Paging<UserInfo> findAll(PageRequest<UserInfo> pageRequest) {
return userInfoData.findAll(page, size); return userInfoData.findAll(pageRequest);
} }
@Override
public List<UserInfo> findAllByCondition(UserInfo data) {
return null;
}
@Override
public UserInfo findOneByCondition(UserInfo data) {
return null;
}
} }

View File

@ -1,5 +1,6 @@
package cc.iotkit.data.service; package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.utils.MapstructUtils; import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.manager.IProductModelData; import cc.iotkit.data.manager.IProductModelData;
import cc.iotkit.data.dao.ProductModelRepository; import cc.iotkit.data.dao.ProductModelRepository;
@ -12,6 +13,7 @@ import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -37,6 +39,11 @@ public class ProductModelDataImpl implements IProductModelData {
return MapstructUtils.convert(productModelRepository.findById(s).orElse(null), ProductModel.class); return MapstructUtils.convert(productModelRepository.findById(s).orElse(null), ProductModel.class);
} }
@Override
public List<ProductModel> findByIds(Collection<String> id) {
return null;
}
@Override @Override
public ProductModel save(ProductModel data) { public ProductModel save(ProductModel data) {
if (StringUtils.isBlank(data.getId())) { if (StringUtils.isBlank(data.getId())) {
@ -47,6 +54,11 @@ public class ProductModelDataImpl implements IProductModelData {
return null; return null;
} }
@Override
public void batchSave(List<ProductModel> data) {
}
@Override @Override
public void deleteById(String s) { public void deleteById(String s) {
@ -54,7 +66,7 @@ public class ProductModelDataImpl implements IProductModelData {
} }
@Override @Override
public void deleteByIds(String[] strings) { public void deleteByIds(Collection<String> strings) {
} }
@ -69,7 +81,18 @@ public class ProductModelDataImpl implements IProductModelData {
} }
@Override @Override
public Paging<ProductModel> findAll(int page, int size) { public Paging<ProductModel> findAll(PageRequest<ProductModel> pageRequest) {
return new Paging<>(); return null;
} }
@Override
public List<ProductModel> findAllByCondition(ProductModel data) {
return null;
}
@Override
public ProductModel findOneByCondition(ProductModel data) {
return null;
}
} }

View File

@ -9,6 +9,7 @@
*/ */
package cc.iotkit.data.service; package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.data.manager.IUserInfoData; import cc.iotkit.data.manager.IUserInfoData;
import cc.iotkit.data.dao.UserInfoRepository; import cc.iotkit.data.dao.UserInfoRepository;
import cc.iotkit.data.model.TbUserInfo; import cc.iotkit.data.model.TbUserInfo;
@ -22,6 +23,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -52,6 +54,11 @@ public class UserInfoDataImpl implements IUserInfoData {
return UserInfoMapper.toDtoFix(userInfoRepository.findById(s).orElse(null)); return UserInfoMapper.toDtoFix(userInfoRepository.findById(s).orElse(null));
} }
@Override
public List<UserInfo> findByIds(Collection<String> id) {
return null;
}
@Override @Override
public UserInfo save(UserInfo data) { public UserInfo save(UserInfo data) {
if (StringUtils.isBlank(data.getId())) { if (StringUtils.isBlank(data.getId())) {
@ -62,11 +69,21 @@ public class UserInfoDataImpl implements IUserInfoData {
return data; return data;
} }
@Override
public void batchSave(List<UserInfo> data) {
}
@Override @Override
public void deleteById(String s) { public void deleteById(String s) {
userInfoRepository.deleteById(s); userInfoRepository.deleteById(s);
} }
@Override
public void deleteByIds(Collection<String> strings) {
}
@Override @Override
public void deleteByIds(String[] strings) { public void deleteByIds(String[] strings) {
@ -82,6 +99,21 @@ public class UserInfoDataImpl implements IUserInfoData {
return UserInfoMapper.toDto(userInfoRepository.findAll()); return UserInfoMapper.toDto(userInfoRepository.findAll());
} }
@Override
public Paging<UserInfo> findAll(PageRequest<UserInfo> pageRequest) {
return null;
}
@Override
public List<UserInfo> findAllByCondition(UserInfo data) {
return null;
}
@Override
public UserInfo findOneByCondition(UserInfo data) {
return null;
}
@Override @Override
public Paging<UserInfo> findAll(int page, int size) { public Paging<UserInfo> findAll(int page, int size) {
Page<TbUserInfo> paged = userInfoRepository.findAll(Pageable.ofSize(size).withPage(page - 1)); Page<TbUserInfo> paged = userInfoRepository.findAll(Pageable.ofSize(size).withPage(page - 1));

View File

@ -15,6 +15,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
@ -95,7 +96,7 @@ public class SysDictTypeController extends BaseController {
@SaCheckPermission("system:dict:remove") @SaCheckPermission("system:dict:remove")
@Log(title = "字典类型", businessType = BusinessType.DELETE) @Log(title = "字典类型", businessType = BusinessType.DELETE)
@DeleteMapping("/{dictIds}") @DeleteMapping("/{dictIds}")
public void remove(@PathVariable Long[] dictIds) { public void remove(@PathVariable Collection<Long> dictIds) {
dictTypeService.deleteDictTypeByIds(dictIds); dictTypeService.deleteDictTypeByIds(dictIds);
} }

View File

@ -13,6 +13,8 @@ import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Collection;
/** /**
* *
* *
@ -74,7 +76,7 @@ public class SysNoticeController extends BaseController {
@SaCheckPermission("system:notice:remove") @SaCheckPermission("system:notice:remove")
@Log(title = "通知公告", businessType = BusinessType.DELETE) @Log(title = "通知公告", businessType = BusinessType.DELETE)
@DeleteMapping("/{noticeIds}") @DeleteMapping("/{noticeIds}")
public void remove(@PathVariable Long[] noticeIds) { public void remove(@PathVariable Collection<Long> noticeIds) {
noticeService.deleteNoticeByIds(noticeIds); noticeService.deleteNoticeByIds(noticeIds);
} }
} }

View File

@ -1,5 +1,6 @@
package cc.iotkit.system.dto.bo; package cc.iotkit.system.dto.bo;
import cc.iotkit.common.api.BaseDto;
import cc.iotkit.common.log.event.OperLogEvent; import cc.iotkit.common.log.event.OperLogEvent;
import cc.iotkit.model.system.SysOperLog; import cc.iotkit.model.system.SysOperLog;
import io.github.linpeilie.annotations.AutoMapper; import io.github.linpeilie.annotations.AutoMapper;
@ -22,7 +23,7 @@ import java.util.Map;
@AutoMapper(target = SysOperLog.class, reverseConvertGenerate = false), @AutoMapper(target = SysOperLog.class, reverseConvertGenerate = false),
@AutoMapper(target = OperLogEvent.class) @AutoMapper(target = OperLogEvent.class)
}) })
public class SysOperLogBo { public class SysOperLogBo extends BaseDto {
/** /**
* *

View File

@ -29,7 +29,7 @@ public class SysRoleBo extends BaseDto {
* ID * ID
*/ */
@NotNull(message = "角色ID不能为空", groups = { EditGroup.class }) @NotNull(message = "角色ID不能为空", groups = { EditGroup.class })
private Long roleId; private Long id;
/** /**
* *

View File

@ -1,5 +1,6 @@
package cc.iotkit.system.dto.vo; package cc.iotkit.system.dto.vo;
import cc.iotkit.common.api.BaseDto;
import cc.iotkit.common.excel.annotation.ExcelDictFormat; import cc.iotkit.common.excel.annotation.ExcelDictFormat;
import cc.iotkit.common.excel.convert.ExcelDictConvert; import cc.iotkit.common.excel.convert.ExcelDictConvert;
import cc.iotkit.model.system.SysOperLog; import cc.iotkit.model.system.SysOperLog;
@ -21,7 +22,7 @@ import java.util.Date;
@Data @Data
@ExcelIgnoreUnannotated @ExcelIgnoreUnannotated
@AutoMapper(target = SysOperLog.class) @AutoMapper(target = SysOperLog.class)
public class SysOperLogVo implements Serializable { public class SysOperLogVo extends BaseDto implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**

View File

@ -27,7 +27,7 @@ public class SysRoleVo implements Serializable {
* ID * ID
*/ */
@ExcelProperty(value = "角色序号") @ExcelProperty(value = "角色序号")
private Long roleId; private Long id;
/** /**
* *

View File

@ -26,7 +26,7 @@ public class SysTenantPackageVo implements Serializable {
* id * id
*/ */
@ExcelProperty(value = "租户套餐id") @ExcelProperty(value = "租户套餐id")
private Long packageId; private Long id;
/** /**
* *

View File

@ -1,79 +0,0 @@
package cc.iotkit.system.mapper;
import cc.iotkit.common.constant.UserConstants;
import cc.iotkit.model.system.SysMenu;
import cc.iotkit.system.dto.vo.SysMenuVo;
import org.springframework.data.repository.query.Param;
import java.util.List;
/**
*
*
* @author Lion Li
*/
public interface SysMenuMapper extends BaseMapperPlus<SysMenu, SysMenuVo> {
/**
*
*
* @return
*/
List<String> selectMenuPerms();
/**
*
*
* @param queryWrapper
* @return
*/
List<SysMenu> selectMenuListByUserId(@Param(Constants.WRAPPER) Wrapper<SysMenu> queryWrapper);
/**
* ID
*
* @param userId ID
* @return
*/
List<String> selectMenuPermsByUserId(Long userId);
/**
* ID
*
* @param roleId ID
* @return
*/
List<String> selectMenuPermsByRoleId(Long roleId);
/**
* ID
*
* @return
*/
default List<SysMenu> selectMenuTreeAll() {
LambdaQueryWrapper<SysMenu> lqw = new LambdaQueryWrapper<SysMenu>()
.in(SysMenu::getMenuType, UserConstants.TYPE_DIR, UserConstants.TYPE_MENU)
.eq(SysMenu::getStatus, UserConstants.MENU_NORMAL)
.orderByAsc(SysMenu::getParentId)
.orderByAsc(SysMenu::getOrderNum);
return this.selectList(lqw);
}
/**
* ID
*
* @param userId ID
* @return
*/
List<SysMenu> selectMenuTreeByUserId(Long userId);
/**
* ID
*
* @param roleId ID
* @param menuCheckStrictly
* @return
*/
List<Long> selectMenuListByRoleId(@Param("roleId") Long roleId, @Param("menuCheckStrictly") boolean menuCheckStrictly);
}

View File

@ -1,60 +0,0 @@
package cc.iotkit.system.mapper;
import cc.iotkit.system.dto.vo.SysRoleVo;
import java.util.List;
/**
*
*
* @author Lion Li
*/
public interface SysRoleMapper extends BaseMapperPlus<SysRole, SysRoleVo> {
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id")
})
Page<SysRoleVo> selectPageRoleList(@Param("page") Page<SysRole> page, @Param(Constants.WRAPPER) Wrapper<SysRole> queryWrapper);
/**
*
*
* @param queryWrapper
* @return
*/
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id")
})
List<SysRoleVo> selectRoleList(@Param(Constants.WRAPPER) Wrapper<SysRole> queryWrapper);
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id")
})
SysRoleVo selectRoleById(Long roleId);
/**
* ID
*
* @param userId ID
* @return
*/
List<SysRoleVo> selectRolePermissionByUserId(Long userId);
/**
* ID
*
* @param userId ID
* @return ID
*/
List<Long> selectRoleListByUserId(Long userId);
/**
* ID
*
* @param userName
* @return
*/
List<SysRoleVo> selectRolesByUserName(String userName);
}

View File

@ -1,136 +0,0 @@
package cc.iotkit.system.mapper;
import cc.iotkit.system.dto.vo.SysUserVo;
import java.util.List;
/**
*
*
* @author Lion Li
*/
public interface SysUserMapper extends BaseMapperPlus<SysUser, SysUserVo> {
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "u.user_id")
})
Page<SysUserVo> selectPageUserList(@Param("page") Page<SysUser> page, @Param(Constants.WRAPPER) Wrapper<SysUser> queryWrapper);
/**
*
*
* @param queryWrapper
* @return
*/
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "u.user_id")
})
List<SysUserVo> selectUserList(@Param(Constants.WRAPPER) Wrapper<SysUser> queryWrapper);
/**
*
*
* @param queryWrapper
* @return
*/
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "u.user_id")
})
Page<SysUserVo> selectAllocatedList(@Param("page") Page<SysUser> page, @Param(Constants.WRAPPER) Wrapper<SysUser> queryWrapper);
/**
*
*
* @param queryWrapper
* @return
*/
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "u.user_id")
})
Page<SysUserVo> selectUnallocatedList(@Param("page") Page<SysUser> page, @Param(Constants.WRAPPER) Wrapper<SysUser> queryWrapper);
/**
*
*
* @param userName
* @return
*/
SysUserVo selectUserByUserName(String userName);
/**
*
*
* @param phonenumber
* @return
*/
SysUserVo selectUserByPhonenumber(String phonenumber);
/**
*
*
* @param email
* @return
*/
SysUserVo selectUserByEmail(String email);
/**
* ()
*
* @param userName
* @param tenantId id
* @return
*/
@InterceptorIgnore(tenantLine = "true")
SysUserVo selectTenantUserByUserName(String userName, String tenantId);
/**
* ()
*
* @param phonenumber
* @param tenantId id
* @return
*/
@InterceptorIgnore(tenantLine = "true")
SysUserVo selectTenantUserByPhonenumber(String phonenumber, String tenantId);
/**
* ()
*
* @param email
* @param tenantId id
* @return
*/
@InterceptorIgnore(tenantLine = "true")
SysUserVo selectTenantUserByEmail(String email, String tenantId);
/**
* ID
*
* @param userId ID
* @return
*/
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "u.user_id")
})
SysUserVo selectUserById(Long userId);
@Override
@DataPermission({
@DataColumn(key = "deptName", value = "dept_id"),
@DataColumn(key = "userName", value = "user_id")
})
int update(@Param(Constants.ENTITY) SysUser user, @Param(Constants.WRAPPER) Wrapper<SysUser> updateWrapper);
@Override
@DataPermission({
@DataColumn(key = "deptName", value = "dept_id"),
@DataColumn(key = "userName", value = "user_id")
})
int updateById(@Param(Constants.ENTITY) SysUser user);
}

View File

@ -1,15 +0,0 @@
package cc.iotkit.system.mapper;
import java.util.List;
/**
*
*
* @author Lion Li
*/
public interface SysUserRoleMapper extends BaseMapperPlus<SysUserRole, SysUserRole> {
List<Long> selectUserIdsByRoleId(Long roleId);
}

View File

@ -6,6 +6,7 @@ import cc.iotkit.system.dto.bo.SysDictTypeBo;
import cc.iotkit.system.dto.vo.SysDictDataVo; import cc.iotkit.system.dto.vo.SysDictDataVo;
import cc.iotkit.system.dto.vo.SysDictTypeVo; import cc.iotkit.system.dto.vo.SysDictTypeVo;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
@ -62,7 +63,7 @@ public interface ISysDictTypeService {
* *
* @param dictIds ID * @param dictIds ID
*/ */
void deleteDictTypeByIds(Long[] dictIds); void deleteDictTypeByIds(Collection<Long> dictIds);
/** /**
* *

View File

@ -5,6 +5,7 @@ import cc.iotkit.common.api.Paging;
import cc.iotkit.system.dto.bo.SysLogininforBo; import cc.iotkit.system.dto.bo.SysLogininforBo;
import cc.iotkit.system.dto.vo.SysLogininforVo; import cc.iotkit.system.dto.vo.SysLogininforVo;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
@ -38,7 +39,7 @@ public interface ISysLogininforService {
* @param infoIds ID * @param infoIds ID
* @return * @return
*/ */
void deleteLogininforByIds(Long[] infoIds); void deleteLogininforByIds(Collection<Long> infoIds);
/** /**
* *

View File

@ -119,7 +119,7 @@ public interface ISysMenuService {
* @param bo * @param bo
* @return * @return
*/ */
int insertMenu(SysMenuBo bo); void insertMenu(SysMenuBo bo);
/** /**
* *
@ -127,7 +127,7 @@ public interface ISysMenuService {
* @param bo * @param bo
* @return * @return
*/ */
int updateMenu(SysMenuBo bo); void updateMenu(SysMenuBo bo);
/** /**
* *

View File

@ -6,6 +6,7 @@ import cc.iotkit.common.api.Paging;
import cc.iotkit.system.dto.bo.SysNoticeBo; import cc.iotkit.system.dto.bo.SysNoticeBo;
import cc.iotkit.system.dto.vo.SysNoticeVo; import cc.iotkit.system.dto.vo.SysNoticeVo;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
@ -48,7 +49,7 @@ public interface ISysNoticeService {
* @param bo * @param bo
* @return * @return
*/ */
int updateNotice(SysNoticeBo bo); void updateNotice(SysNoticeBo bo);
/** /**
* *
@ -56,7 +57,7 @@ public interface ISysNoticeService {
* @param noticeId ID * @param noticeId ID
* @return * @return
*/ */
int deleteNoticeById(Long noticeId); void deleteNoticeById(Long noticeId);
/** /**
* *
@ -64,5 +65,5 @@ public interface ISysNoticeService {
* @param noticeIds ID * @param noticeIds ID
* @return * @return
*/ */
int deleteNoticeByIds(Long[] noticeIds); void deleteNoticeByIds(Collection<Long> noticeIds);
} }

View File

@ -5,6 +5,7 @@ import cc.iotkit.common.api.Paging;
import cc.iotkit.system.dto.bo.SysOperLogBo; import cc.iotkit.system.dto.bo.SysOperLogBo;
import cc.iotkit.system.dto.vo.SysOperLogVo; import cc.iotkit.system.dto.vo.SysOperLogVo;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
@ -37,7 +38,7 @@ public interface ISysOperLogService {
* @param operIds ID * @param operIds ID
* @return * @return
*/ */
int deleteOperLogByIds(Long[] operIds); void deleteOperLogByIds(Collection<Long> operIds);
/** /**
* *

View File

@ -26,8 +26,8 @@ public interface ISysOssService {
SysOssVo upload(MultipartFile file); SysOssVo upload(MultipartFile file);
void download(Long ossId, HttpServletResponse response) throws IOException; void download(Long ossId) throws IOException;
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid); void deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
} }

View File

@ -5,6 +5,7 @@ import cc.iotkit.common.api.Paging;
import cc.iotkit.system.dto.bo.SysPostBo; import cc.iotkit.system.dto.bo.SysPostBo;
import cc.iotkit.system.dto.vo.SysPostVo; import cc.iotkit.system.dto.vo.SysPostVo;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
@ -78,7 +79,7 @@ public interface ISysPostService {
* @param postId ID * @param postId ID
* @return * @return
*/ */
int deletePostById(Long postId); void deletePostById(Long postId);
/** /**
* *
@ -86,7 +87,7 @@ public interface ISysPostService {
* @param postIds ID * @param postIds ID
* @return * @return
*/ */
int deletePostByIds(Long[] postIds); void deletePostByIds(Collection<Long> postIds);
/** /**
* *
@ -94,7 +95,7 @@ public interface ISysPostService {
* @param bo * @param bo
* @return * @return
*/ */
int insertPost(SysPostBo bo); void insertPost(SysPostBo bo);
/** /**
* *
@ -102,5 +103,5 @@ public interface ISysPostService {
* @param bo * @param bo
* @return * @return
*/ */
int updatePost(SysPostBo bo); void updatePost(SysPostBo bo);
} }

View File

@ -110,7 +110,7 @@ public interface ISysRoleService {
* @param bo * @param bo
* @return * @return
*/ */
int insertRole(SysRoleBo bo); void insertRole(SysRoleBo bo);
/** /**
* *
@ -118,7 +118,7 @@ public interface ISysRoleService {
* @param bo * @param bo
* @return * @return
*/ */
int updateRole(SysRoleBo bo); void updateRole(SysRoleBo bo);
/** /**
* *
@ -127,7 +127,7 @@ public interface ISysRoleService {
* @param status * @param status
* @return * @return
*/ */
int updateRoleStatus(Long roleId, String status); void updateRoleStatus(Long roleId, String status);
/** /**
* *
@ -135,7 +135,7 @@ public interface ISysRoleService {
* @param bo * @param bo
* @return * @return
*/ */
int authDataScope(SysRoleBo bo); void authDataScope(SysRoleBo bo);
/** /**
* ID * ID
@ -143,7 +143,7 @@ public interface ISysRoleService {
* @param roleId ID * @param roleId ID
* @return * @return
*/ */
int deleteRoleById(Long roleId); void deleteRoleById(Long roleId);
/** /**
* *
@ -151,7 +151,7 @@ public interface ISysRoleService {
* @param roleIds ID * @param roleIds ID
* @return * @return
*/ */
int deleteRoleByIds(Long[] roleIds); void deleteRoleByIds(Long[] roleIds);
/** /**
* *
@ -159,7 +159,7 @@ public interface ISysRoleService {
* @param userRole * @param userRole
* @return * @return
*/ */
int deleteAuthUser(SysUserRole userRole); void deleteAuthUser(SysUserRole userRole);
/** /**
* *
@ -168,7 +168,7 @@ public interface ISysRoleService {
* @param userIds ID * @param userIds ID
* @return * @return
*/ */
int deleteAuthUsers(Long roleId, Long[] userIds); void deleteAuthUsers(Long roleId, Long[] userIds);
/** /**
* *
@ -177,7 +177,7 @@ public interface ISysRoleService {
* @param userIds ID * @param userIds ID
* @return * @return
*/ */
int insertAuthUsers(Long roleId, Long[] userIds); void insertAuthUsers(Long roleId, Long[] userIds);
void cleanOnlineUserByRole(Long roleId); void cleanOnlineUserByRole(Long roleId);
} }

View File

@ -48,7 +48,7 @@ public interface ISysTenantPackageService {
/** /**
* *
*/ */
int updatePackageStatus(SysTenantPackageBo bo); void updatePackageStatus(SysTenantPackageBo bo);
/** /**
* *

View File

@ -16,8 +16,10 @@ import cc.iotkit.system.dto.bo.SysConfigBo;
import cc.iotkit.system.dto.vo.SysConfigVo; import cc.iotkit.system.dto.vo.SysConfigVo;
import cc.iotkit.system.service.ISysConfigService; import cc.iotkit.system.service.ISysConfigService;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -36,8 +38,7 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
@Override @Override
public Paging<SysConfigVo> selectPageConfigList(PageRequest<SysConfigBo> query) { public Paging<SysConfigVo> selectPageConfigList(PageRequest<SysConfigBo> query) {
PageRequest<SysConfig> pageRequest = PageRequest.copyPageRequest(query,MapstructUtils.convert(query.getData(), SysConfig.class)); return sysConfigData.findAll(query.to(SysConfig.class)).to(SysConfigVo.class);
return MapstructUtils.convert(sysConfigData.findAll(pageRequest), SysConfigVo.class);
} }
/** /**
@ -48,7 +49,7 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
*/ */
@Override @Override
public SysConfigVo selectConfigById(Long configId) { public SysConfigVo selectConfigById(Long configId) {
return MapstructUtils.convert(sysConfigData.findById(configId), SysConfigVo.class); return sysConfigData.findById(configId).to(SysConfigVo.class);
} }
/** /**
@ -94,22 +95,9 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
*/ */
@Override @Override
public List<SysConfigVo> selectConfigList(SysConfigBo config) { public List<SysConfigVo> selectConfigList(SysConfigBo config) {
// LambdaQueryWrapper<SysConfig> lqw = buildQueryWrapper(config);
// return baseMapper.selectVoList(lqw);
return new ArrayList<>(); return new ArrayList<>();
} }
// private LambdaQueryWrapper<SysConfig> buildQueryWrapper(SysConfigBo bo) {
// Map<String, Object> params = bo.getParams();
// LambdaQueryWrapper<SysConfig> lqw = Wrappers.lambdaQuery();
// lqw.like(StringUtils.isNotBlank(bo.getConfigName()), SysConfig::getConfigName, bo.getConfigName());
// lqw.eq(StringUtils.isNotBlank(bo.getConfigType()), SysConfig::getConfigType, bo.getConfigType());
// lqw.like(StringUtils.isNotBlank(bo.getConfigKey()), SysConfig::getConfigKey, bo.getConfigKey());
// lqw.between(params.get("beginTime") != null && params.get("endTime") != null,
// SysConfig::getCreateTime, params.get("beginTime"), params.get("endTime"));
// return lqw;
// }
/** /**
* *
* *
@ -118,11 +106,6 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
*/ */
@Override @Override
public String insertConfig(SysConfigBo bo) { public String insertConfig(SysConfigBo bo) {
// SysConfig config = MapstructUtils.convert(bo, SysConfig.class);
// int row = baseMapper.insert(config);
// if (row > 0) {
// return config.getConfigValue();
// }
throw new BizException("操作失败"); throw new BizException("操作失败");
} }
@ -135,33 +118,18 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
// @CachePut(cacheNames = CacheNames.SYS_CONFIG, key = "#bo.configKey") // @CachePut(cacheNames = CacheNames.SYS_CONFIG, key = "#bo.configKey")
@Override @Override
public String updateConfig(SysConfigBo bo) { public String updateConfig(SysConfigBo bo) {
// int row = 0;
// SysConfig config = MapstructUtils.convert(bo, SysConfig.class); // SysConfig config = MapstructUtils.convert(bo, SysConfig.class);
// if (config.getId() != null) { // if (config.getId() == null) {
// SysConfig temp = sysConfigData.selectById(config.getConfigId()); // SysConfig old = sysConfigData.findByConfigKey(bo.getConfigKey());
// if (!StringUtils.equals(temp.getConfigKey(), config.getConfigKey())) { // if (old == null) {
// CacheUtils.evict(CacheNames.SYS_CONFIG, temp.getConfigKey()); // throw new BizException("操作失败,key不存在");
// } // }
// row = baseMapper.updateById(config); // config.setId(old.getId());
// } else {
// row = baseMapper.update(config, new LambdaQueryWrapper<SysConfig>()
// .eq(SysConfig::getConfigKey, config.getConfigKey()));
// } // }
// if (row > 0) { //
// sysConfigData.save(config);
// return config.getConfigValue(); // return config.getConfigValue();
// } return "";
// throw new BizException("操作失败");
SysConfig config = MapstructUtils.convert(bo, SysConfig.class);
if (config.getId() == null) {
SysConfig old = sysConfigData.findByConfigKey(bo.getConfigKey());
if (old == null) {
throw new BizException("操作失败,key不存在");
}
config.setId(old.getId());
}
sysConfigData.save(config);
return config.getConfigValue();
} }
/** /**
@ -197,9 +165,10 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
*/ */
@Override @Override
public boolean checkConfigKeyUnique(SysConfigBo config) { public boolean checkConfigKeyUnique(SysConfigBo config) {
long configId = ObjectUtil.isNull(config.getId()) ? -1L : config.getId(); // long configId = ObjectUtil.isNull(config.getId()) ? -1L : config.getId();
SysConfig old = sysConfigData.findByConfigKey(config.getConfigKey()); // SysConfig old = sysConfigData.findByConfigKey(config.getConfigKey());
return !ObjectUtil.isNotNull(old) || old.getId() == configId; // return !ObjectUtil.isNotNull(old) || old.getId() == configId;
return true;
} }
/** /**

View File

@ -51,7 +51,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
@Override @Override
public List<SysDeptVo> selectDeptList(SysDeptBo dept) { public List<SysDeptVo> selectDeptList(SysDeptBo dept) {
return MapstructUtils.convert( return MapstructUtils.convert(
sysDeptData.findDepts(MapstructUtils.convert(dept, SysDept.class)) sysDeptData.findDepts(dept.to(SysDept.class))
, SysDeptVo.class); , SysDeptVo.class);
} }
@ -63,7 +63,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
*/ */
@Override @Override
public List<Tree<Long>> selectDeptTreeList(SysDeptBo bo) { public List<Tree<Long>> selectDeptTreeList(SysDeptBo bo) {
List<SysDept> depts = sysDeptData.findDepts(MapstructUtils.convert(bo, SysDept.class)); List<SysDept> depts = sysDeptData.findDepts(bo.to(SysDept.class));
return buildDeptTreeSelect(depts); return buildDeptTreeSelect(depts);
} }

View File

@ -31,7 +31,7 @@ public class SysDictDataServiceImpl implements ISysDictDataService {
public Paging<SysDictDataVo> selectPageDictDataList(SysDictDataBo dictData, PageRequest<?> query) { public Paging<SysDictDataVo> selectPageDictDataList(SysDictDataBo dictData, PageRequest<?> query) {
return MapstructUtils.convert( return MapstructUtils.convert(
sysDictData.findByConditions( sysDictData.findByConditions(
MapstructUtils.convert(dictData, SysDictData.class), dictData.to(SysDictData.class),
query.getPageNum(), query.getPageNum(),
query.getPageSize() query.getPageSize()
), SysDictDataVo.class); ), SysDictDataVo.class);

View File

@ -23,10 +23,7 @@ import cn.hutool.core.util.ObjectUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -45,7 +42,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
public Paging<SysDictTypeVo> selectPageDictTypeList(SysDictTypeBo dictType, PageRequest<?> query) { public Paging<SysDictTypeVo> selectPageDictTypeList(SysDictTypeBo dictType, PageRequest<?> query) {
return MapstructUtils.convert( return MapstructUtils.convert(
sysDictTypeData.findByConditions( sysDictTypeData.findByConditions(
MapstructUtils.convert(dictType, SysDictType.class), dictType.to(SysDictType.class),
query.getPageNum(), query.getPageSize()), query.getPageNum(), query.getPageSize()),
SysDictTypeVo.class); SysDictTypeVo.class);
} }
@ -60,7 +57,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
public List<SysDictTypeVo> selectDictTypeList(SysDictTypeBo dictType) { public List<SysDictTypeVo> selectDictTypeList(SysDictTypeBo dictType) {
return MapstructUtils.convert( return MapstructUtils.convert(
sysDictTypeData.findByConditions( sysDictTypeData.findByConditions(
MapstructUtils.convert(dictType, SysDictType.class)), dictType.to(SysDictType.class)),
SysDictTypeVo.class); SysDictTypeVo.class);
} }
@ -115,7 +112,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
* @param dictIds ID * @param dictIds ID
*/ */
@Override @Override
public void deleteDictTypeByIds(Long[] dictIds) { public void deleteDictTypeByIds(Collection<Long> dictIds) {
for (Long dictId : dictIds) { for (Long dictId : dictIds) {
SysDictType dictType = sysDictTypeData.findById(dictId); SysDictType dictType = sysDictTypeData.findById(dictId);
if (sysDictData.countByDicType(dictType.getDictType()) > 0) { if (sysDictData.countByDicType(dictType.getDictType()) > 0) {

View File

@ -19,6 +19,7 @@ import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -128,7 +129,7 @@ public class SysLogininforServiceImpl implements ISysLogininforService {
* @return * @return
*/ */
@Override @Override
public void deleteLogininforByIds(Long[] infoIds) { public void deleteLogininforByIds(Collection<Long> infoIds) {
sysLogininforData.deleteByIds(infoIds); sysLogininforData.deleteByIds(infoIds);
} }

View File

@ -1,30 +1,22 @@
package cc.iotkit.system.service.impl; package cc.iotkit.system.service.impl;
import cc.iotkit.common.constant.UserConstants;
import cc.iotkit.common.satoken.utils.LoginHelper;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.common.utils.StreamUtils; import cc.iotkit.common.utils.StreamUtils;
import cc.iotkit.common.utils.StringUtils;
import cc.iotkit.common.utils.TreeBuildUtils; import cc.iotkit.common.utils.TreeBuildUtils;
import cc.iotkit.data.system.ISysLogininforData;
import cc.iotkit.data.system.ISysMenuData; import cc.iotkit.data.system.ISysMenuData;
import cc.iotkit.model.system.SysMenu; import cc.iotkit.model.system.SysMenu;
import cc.iotkit.model.system.SysRole;
import cc.iotkit.model.system.SysTenantPackage;
import cc.iotkit.system.dto.SysRoleMenu;
import cc.iotkit.system.dto.bo.SysMenuBo; import cc.iotkit.system.dto.bo.SysMenuBo;
import cc.iotkit.system.dto.vo.MetaVo;
import cc.iotkit.system.dto.vo.RouterVo; import cc.iotkit.system.dto.vo.RouterVo;
import cc.iotkit.system.dto.vo.SysMenuVo; import cc.iotkit.system.dto.vo.SysMenuVo;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.util.ObjectUtil;
import cc.iotkit.system.service.ISysMenuService; import cc.iotkit.system.service.ISysMenuService;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.tree.Tree;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/** /**
* *
@ -35,7 +27,7 @@ import java.util.*;
@Service @Service
public class SysMenuServiceImpl implements ISysMenuService { public class SysMenuServiceImpl implements ISysMenuService {
private final ISysMenuData iSysMenuData; private final ISysMenuData sysMenuData;
/** /**
* *
@ -56,27 +48,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
*/ */
@Override @Override
public List<SysMenuVo> selectMenuList(SysMenuBo menu, Long userId) { public List<SysMenuVo> selectMenuList(SysMenuBo menu, Long userId) {
List<SysMenuVo> menuList; return new ArrayList<>();
// 管理员显示所有菜单信息
if (LoginHelper.isSuperAdmin(userId)) {
menuList = baseMapper.selectVoList(new LambdaQueryWrapper<SysMenu>()
.like(StringUtils.isNotBlank(menu.getMenuName()), SysMenu::getMenuName, menu.getMenuName())
.eq(StringUtils.isNotBlank(menu.getVisible()), SysMenu::getVisible, menu.getVisible())
.eq(StringUtils.isNotBlank(menu.getStatus()), SysMenu::getStatus, menu.getStatus())
.orderByAsc(SysMenu::getParentId)
.orderByAsc(SysMenu::getOrderNum));
} else {
QueryWrapper<SysMenu> wrapper = Wrappers.query();
wrapper.eq("sur.user_id", userId)
.like(StringUtils.isNotBlank(menu.getMenuName()), "m.menu_name", menu.getMenuName())
.eq(StringUtils.isNotBlank(menu.getVisible()), "m.visible", menu.getVisible())
.eq(StringUtils.isNotBlank(menu.getStatus()), "m.status", menu.getStatus())
.orderByAsc("m.parent_id")
.orderByAsc("m.order_num");
List<SysMenu> list = baseMapper.selectMenuListByUserId(wrapper);
menuList = MapstructUtils.convert(list, SysMenuVo.class);
}
return menuList;
} }
/** /**
@ -87,14 +59,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
*/ */
@Override @Override
public Set<String> selectMenuPermsByUserId(Long userId) { public Set<String> selectMenuPermsByUserId(Long userId) {
List<String> perms = baseMapper.selectMenuPermsByUserId(userId); return new HashSet<>();
Set<String> permsSet = new HashSet<>();
for (String perm : perms) {
if (StringUtils.isNotEmpty(perm)) {
permsSet.addAll(StringUtils.splitList(perm.trim()));
}
}
return permsSet;
} }
/** /**
@ -105,14 +70,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
*/ */
@Override @Override
public Set<String> selectMenuPermsByRoleId(Long roleId) { public Set<String> selectMenuPermsByRoleId(Long roleId) {
List<String> perms = baseMapper.selectMenuPermsByRoleId(roleId); return new HashSet<>();
Set<String> permsSet = new HashSet<>();
for (String perm : perms) {
if (StringUtils.isNotEmpty(perm)) {
permsSet.addAll(StringUtils.splitList(perm.trim()));
}
}
return permsSet;
} }
/** /**
@ -123,13 +81,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
*/ */
@Override @Override
public List<SysMenu> selectMenuTreeByUserId(Long userId) { public List<SysMenu> selectMenuTreeByUserId(Long userId) {
List<SysMenu> menus; return new ArrayList<>();
if (LoginHelper.isSuperAdmin(userId)) {
menus = baseMapper.selectMenuTreeAll();
} else {
menus = baseMapper.selectMenuTreeByUserId(userId);
}
return getChildPerms(menus, 0);
} }
/** /**
@ -140,8 +92,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
*/ */
@Override @Override
public List<Long> selectMenuListByRoleId(Long roleId) { public List<Long> selectMenuListByRoleId(Long roleId) {
SysRole role = roleMapper.selectById(roleId); return new ArrayList<>();
return baseMapper.selectMenuListByRoleId(roleId, role.getMenuCheckStrictly());
} }
/** /**
@ -152,20 +103,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
*/ */
@Override @Override
public List<Long> selectMenuListByPackageId(Long packageId) { public List<Long> selectMenuListByPackageId(Long packageId) {
SysTenantPackage tenantPackage = tenantPackageMapper.selectById(packageId); return new ArrayList<>();
List<Long> menuIds = StringUtils.splitTo(tenantPackage.getMenuIds(), Convert::toLong);
if (CollUtil.isEmpty(menuIds)) {
return List.of();
}
List<Long> parentIds = null;
if (tenantPackage.getMenuCheckStrictly()) {
parentIds = baseMapper.selectObjs(new LambdaQueryWrapper<SysMenu>()
.select(SysMenu::getParentId)
.in(SysMenu::getMenuId, menuIds), Convert::toLong);
}
return baseMapper.selectObjs(new LambdaQueryWrapper<SysMenu>()
.in(SysMenu::getMenuId, menuIds)
.notIn(CollUtil.isNotEmpty(parentIds), SysMenu::getMenuId, parentIds), Convert::toLong);
} }
/** /**
@ -176,47 +114,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
*/ */
@Override @Override
public List<RouterVo> buildMenus(List<SysMenu> menus) { public List<RouterVo> buildMenus(List<SysMenu> menus) {
List<RouterVo> routers = new LinkedList<>(); return new ArrayList<>();
for (SysMenu menu : menus) {
RouterVo router = new RouterVo();
router.setHidden("1".equals(menu.getVisible()));
router.setName(menu.getRouteName());
router.setPath(menu.getRouterPath());
router.setComponent(menu.getComponentInfo());
router.setQuery(menu.getQueryParam());
router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath()));
List<SysMenu> cMenus = menu.getChildren();
if (CollUtil.isNotEmpty(cMenus) && UserConstants.TYPE_DIR.equals(menu.getMenuType())) {
router.setAlwaysShow(true);
router.setRedirect("noRedirect");
router.setChildren(buildMenus(cMenus));
} else if (menu.isMenuFrame()) {
router.setMeta(null);
List<RouterVo> childrenList = new ArrayList<>();
RouterVo children = new RouterVo();
children.setPath(menu.getPath());
children.setComponent(menu.getComponentInfo());
children.setName(StringUtils.capitalize(menu.getPath()));
children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath()));
children.setQuery(menu.getQueryParam());
childrenList.add(children);
router.setChildren(childrenList);
} else if (menu.getParentId().intValue() == 0 && menu.isInnerLink()) {
router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon()));
router.setPath("/");
List<RouterVo> childrenList = new ArrayList<>();
RouterVo children = new RouterVo();
String routerPath = SysMenu.innerLinkReplaceEach(menu.getPath());
children.setPath(routerPath);
children.setComponent(UserConstants.INNER_LINK);
children.setName(StringUtils.capitalize(routerPath));
children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), menu.getPath()));
childrenList.add(children);
router.setChildren(childrenList);
}
routers.add(router);
}
return routers;
} }
/** /**
@ -245,7 +143,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
*/ */
@Override @Override
public SysMenuVo selectMenuById(Long menuId) { public SysMenuVo selectMenuById(Long menuId) {
return baseMapper.selectVoById(menuId); return sysMenuData.findById(menuId).to(SysMenuVo.class);
} }
/** /**
@ -256,7 +154,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
*/ */
@Override @Override
public boolean hasChildByMenuId(Long menuId) { public boolean hasChildByMenuId(Long menuId) {
return baseMapper.exists(new LambdaQueryWrapper<SysMenu>().eq(SysMenu::getParentId, menuId)); return false;
} }
/** /**
@ -267,7 +165,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
*/ */
@Override @Override
public boolean checkMenuExistRole(Long menuId) { public boolean checkMenuExistRole(Long menuId) {
return roleMenuMapper.exists(new LambdaQueryWrapper<SysRoleMenu>().eq(SysRoleMenu::getMenuId, menuId)); return false;
} }
/** /**
@ -277,9 +175,8 @@ public class SysMenuServiceImpl implements ISysMenuService {
* @return * @return
*/ */
@Override @Override
public int insertMenu(SysMenuBo bo) { public void insertMenu(SysMenuBo bo) {
SysMenu menu = MapstructUtils.convert(bo, SysMenu.class); sysMenuData.save(bo.to(SysMenu.class));
return baseMapper.insert(menu);
} }
/** /**
@ -289,9 +186,8 @@ public class SysMenuServiceImpl implements ISysMenuService {
* @return * @return
*/ */
@Override @Override
public int updateMenu(SysMenuBo bo) { public void updateMenu(SysMenuBo bo) {
SysMenu menu = MapstructUtils.convert(bo, SysMenu.class); sysMenuData.save(bo.to(SysMenu.class));
return baseMapper.updateById(menu);
} }
/** /**
@ -302,7 +198,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
*/ */
@Override @Override
public void deleteMenuById(Long menuId) { public void deleteMenuById(Long menuId) {
iSysMenuData.deleteById(menuId); sysMenuData.deleteById(menuId);
} }
/** /**
@ -313,11 +209,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
*/ */
@Override @Override
public boolean checkMenuNameUnique(SysMenuBo menu) { public boolean checkMenuNameUnique(SysMenuBo menu) {
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysMenu>() return false;
.eq(SysMenu::getMenuName, menu.getMenuName())
.eq(SysMenu::getParentId, menu.getParentId())
.ne(ObjectUtil.isNotNull(menu.getMenuId()), SysMenu::getMenuId, menu.getMenuId()));
return !exist;
} }
/** /**

View File

@ -13,7 +13,9 @@ import cc.iotkit.system.service.ISysNoticeService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
@ -25,13 +27,11 @@ import java.util.List;
@Service @Service
public class SysNoticeServiceImpl implements ISysNoticeService { public class SysNoticeServiceImpl implements ISysNoticeService {
private ISysNoticeData iSysNoticeData; private ISysNoticeData sysNoticeData;
@Override @Override
public Paging<SysNoticeVo> selectPageNoticeList(SysNoticeBo notice, PageRequest<?> query) { public Paging<SysNoticeVo> selectPageNoticeList(SysNoticeBo notice, PageRequest<?> query) {
LambdaQueryWrapper<SysNotice> lqw = buildQueryWrapper(notice); return new Paging<>();
Page<SysNoticeVo> page = baseMapper.selectVoPage(query.build(), lqw);
return TableDataInfo.build(page);
} }
/** /**
@ -42,7 +42,7 @@ public class SysNoticeServiceImpl implements ISysNoticeService {
*/ */
@Override @Override
public SysNoticeVo selectNoticeById(Long noticeId) { public SysNoticeVo selectNoticeById(Long noticeId) {
return baseMapper.selectVoById(noticeId); return sysNoticeData.findById(noticeId).to(SysNoticeVo.class);
} }
/** /**
@ -53,19 +53,7 @@ public class SysNoticeServiceImpl implements ISysNoticeService {
*/ */
@Override @Override
public List<SysNoticeVo> selectNoticeList(SysNoticeBo notice) { public List<SysNoticeVo> selectNoticeList(SysNoticeBo notice) {
LambdaQueryWrapper<SysNotice> lqw = buildQueryWrapper(notice); return new ArrayList<>();
return baseMapper.selectVoList(lqw);
}
private LambdaQueryWrapper<SysNotice> buildQueryWrapper(SysNoticeBo bo) {
LambdaQueryWrapper<SysNotice> lqw = Wrappers.lambdaQuery();
lqw.like(StringUtils.isNotBlank(bo.getNoticeTitle()), SysNotice::getNoticeTitle, bo.getNoticeTitle());
lqw.eq(StringUtils.isNotBlank(bo.getNoticeType()), SysNotice::getNoticeType, bo.getNoticeType());
if (StringUtils.isNotBlank(bo.getCreateByName())) {
SysUserVo sysUser = userMapper.selectUserByUserName(bo.getCreateByName());
lqw.eq(SysNotice::getCreateBy, ObjectUtil.isNotNull(sysUser) ? sysUser.getUserId() : null);
}
return lqw;
} }
/** /**
@ -76,9 +64,7 @@ public class SysNoticeServiceImpl implements ISysNoticeService {
*/ */
@Override @Override
public Long insertNotice(SysNoticeBo bo) { public Long insertNotice(SysNoticeBo bo) {
SysNotice notice = MapstructUtils.convert(bo, SysNotice.class); return sysNoticeData.save(bo.to(SysNotice.class)).getId();
iSysNoticeData.save(notice);
return notice.getId();
} }
/** /**
@ -88,9 +74,8 @@ public class SysNoticeServiceImpl implements ISysNoticeService {
* @return * @return
*/ */
@Override @Override
public int updateNotice(SysNoticeBo bo) { public void updateNotice(SysNoticeBo bo) {
SysNotice notice = MapstructUtils.convert(bo, SysNotice.class); sysNoticeData.save(bo.to(SysNotice.class));
return baseMapper.updateById(notice);
} }
/** /**
@ -100,8 +85,8 @@ public class SysNoticeServiceImpl implements ISysNoticeService {
* @return * @return
*/ */
@Override @Override
public int deleteNoticeById(Long noticeId) { public void deleteNoticeById(Long noticeId) {
return baseMapper.deleteById(noticeId); sysNoticeData.deleteById(noticeId);
} }
/** /**
@ -111,7 +96,7 @@ public class SysNoticeServiceImpl implements ISysNoticeService {
* @return * @return
*/ */
@Override @Override
public int deleteNoticeByIds(Long[] noticeIds) { public void deleteNoticeByIds(Collection<Long> noticeIds) {
return baseMapper.deleteBatchIds(Arrays.asList(noticeIds)); sysNoticeData.deleteByIds(noticeIds);
} }
} }

View File

@ -6,6 +6,7 @@ import cc.iotkit.common.log.event.OperLogEvent;
import cc.iotkit.common.utils.MapstructUtils; import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.common.utils.StringUtils; import cc.iotkit.common.utils.StringUtils;
import cc.iotkit.common.utils.ip.AddressUtils; import cc.iotkit.common.utils.ip.AddressUtils;
import cc.iotkit.data.system.ISysOperLogData;
import cc.iotkit.model.system.SysOperLog; import cc.iotkit.model.system.SysOperLog;
import cc.iotkit.system.dto.bo.SysOperLogBo; import cc.iotkit.system.dto.bo.SysOperLogBo;
import cc.iotkit.system.dto.vo.SysOperLogVo; import cc.iotkit.system.dto.vo.SysOperLogVo;
@ -16,10 +17,7 @@ import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Arrays; import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.Map;
/** /**
* *
@ -30,7 +28,7 @@ import java.util.Map;
@Service @Service
public class SysOperLogServiceImpl implements ISysOperLogService { public class SysOperLogServiceImpl implements ISysOperLogService {
private final SysOperLogMapper baseMapper; private final ISysOperLogData sysOperLogData;
/** /**
* *
@ -48,27 +46,7 @@ public class SysOperLogServiceImpl implements ISysOperLogService {
@Override @Override
public Paging<SysOperLogVo> selectPageOperLogList(SysOperLogBo operLog, PageRequest<?> query) { public Paging<SysOperLogVo> selectPageOperLogList(SysOperLogBo operLog, PageRequest<?> query) {
Map<String, Object> params = operLog.getParams(); return new Paging<>();
LambdaQueryWrapper<SysOperLog> lqw = new LambdaQueryWrapper<SysOperLog>()
.like(StringUtils.isNotBlank(operLog.getTitle()), SysOperLog::getTitle, operLog.getTitle())
.eq(operLog.getBusinessType() != null && operLog.getBusinessType() > 0,
SysOperLog::getBusinessType, operLog.getBusinessType())
.func(f -> {
if (ArrayUtil.isNotEmpty(operLog.getBusinessTypes())) {
f.in(SysOperLog::getBusinessType, Arrays.asList(operLog.getBusinessTypes()));
}
})
.eq(operLog.getStatus() != null,
SysOperLog::getStatus, operLog.getStatus())
.like(StringUtils.isNotBlank(operLog.getOperName()), SysOperLog::getOperName, operLog.getOperName())
.between(params.get("beginTime") != null && params.get("endTime") != null,
SysOperLog::getOperTime, params.get("beginTime"), params.get("endTime"));
if (StringUtils.isBlank(query.getOrderByColumn())) {
pageQuery.setOrderByColumn("oper_id");
pageQuery.setIsAsc("desc");
}
Page<SysOperLogVo> page = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(page);
} }
/** /**
@ -78,9 +56,8 @@ public class SysOperLogServiceImpl implements ISysOperLogService {
*/ */
@Override @Override
public void insertOperlog(SysOperLogBo bo) { public void insertOperlog(SysOperLogBo bo) {
SysOperLog operLog = MapstructUtils.convert(bo, SysOperLog.class); bo.setOperTime(new Date());
operLog.setOperTime(new Date()); sysOperLogData.save(bo.to(SysOperLog.class));
baseMapper.insert(operLog);
} }
/** /**
@ -91,22 +68,7 @@ public class SysOperLogServiceImpl implements ISysOperLogService {
*/ */
@Override @Override
public List<SysOperLogVo> selectOperLogList(SysOperLogBo operLog) { public List<SysOperLogVo> selectOperLogList(SysOperLogBo operLog) {
Map<String, Object> params = operLog.getParams(); return new ArrayList<>();
return baseMapper.selectVoList(new LambdaQueryWrapper<SysOperLog>()
.like(StringUtils.isNotBlank(operLog.getTitle()), SysOperLog::getTitle, operLog.getTitle())
.eq(operLog.getBusinessType() != null && operLog.getBusinessType() > 0,
SysOperLog::getBusinessType, operLog.getBusinessType())
.func(f -> {
if (ArrayUtil.isNotEmpty(operLog.getBusinessTypes())) {
f.in(SysOperLog::getBusinessType, Arrays.asList(operLog.getBusinessTypes()));
}
})
.eq(operLog.getStatus() != null && operLog.getStatus() > 0,
SysOperLog::getStatus, operLog.getStatus())
.like(StringUtils.isNotBlank(operLog.getOperName()), SysOperLog::getOperName, operLog.getOperName())
.between(params.get("beginTime") != null && params.get("endTime") != null,
SysOperLog::getOperTime, params.get("beginTime"), params.get("endTime"))
.orderByDesc(SysOperLog::getOperId));
} }
/** /**
@ -116,8 +78,8 @@ public class SysOperLogServiceImpl implements ISysOperLogService {
* @return * @return
*/ */
@Override @Override
public int deleteOperLogByIds(Long[] operIds) { public void deleteOperLogByIds(Collection<Long> operIds) {
return baseMapper.deleteBatchIds(Arrays.asList(operIds)); sysOperLogData.deleteByIds(operIds);
} }
/** /**
@ -128,7 +90,7 @@ public class SysOperLogServiceImpl implements ISysOperLogService {
*/ */
@Override @Override
public SysOperLogVo selectOperLogById(Long operId) { public SysOperLogVo selectOperLogById(Long operId) {
return baseMapper.selectVoById(operId); return sysOperLogData.findById(operId).to(SysOperLogVo.class);
} }
/** /**
@ -136,6 +98,5 @@ public class SysOperLogServiceImpl implements ISysOperLogService {
*/ */
@Override @Override
public void cleanOperLog() { public void cleanOperLog() {
baseMapper.delete(new LambdaQueryWrapper<>());
} }
} }

View File

@ -11,8 +11,8 @@ import cc.iotkit.common.oss.factory.OssFactory;
import cc.iotkit.common.service.OssService; import cc.iotkit.common.service.OssService;
import cc.iotkit.common.utils.MapstructUtils; import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.common.utils.SpringUtils; import cc.iotkit.common.utils.SpringUtils;
import cc.iotkit.common.utils.StreamUtils;
import cc.iotkit.common.utils.StringUtils; import cc.iotkit.common.utils.StringUtils;
import cc.iotkit.data.system.ISysOssData;
import cc.iotkit.model.system.SysOss; import cc.iotkit.model.system.SysOss;
import cc.iotkit.system.dto.bo.SysOssBo; import cc.iotkit.system.dto.bo.SysOssBo;
import cc.iotkit.system.dto.vo.SysOssVo; import cc.iotkit.system.dto.vo.SysOssVo;
@ -39,15 +39,11 @@ import java.util.Map;
@Service @Service
public class SysOssServiceImpl implements ISysOssService, OssService { public class SysOssServiceImpl implements ISysOssService, OssService {
private final SysOssMapper baseMapper; private final ISysOssData sysOssData;
@Override @Override
public Paging<SysOssVo> queryPageList(SysOssBo bo, PageRequest<?> query) { public Paging<SysOssVo> queryPageList(SysOssBo bo, PageRequest<?> query) {
LambdaQueryWrapper<SysOss> lqw = buildQueryWrapper(bo); return new Paging<>();
Page<SysOssVo> result = baseMapper.selectVoPage(query.build(), lqw);
List<SysOssVo> filterResult = StreamUtils.toList(result.getRecords(), this::matchingUrl);
result.setRecords(filterResult);
return TableDataInfo.build(result);
} }
@Override @Override
@ -74,24 +70,10 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
return String.join(StringUtils.SEPARATOR, list); return String.join(StringUtils.SEPARATOR, list);
} }
private LambdaQueryWrapper<SysOss> buildQueryWrapper(SysOssBo bo) {
Map<String, Object> params = bo.getParams();
LambdaQueryWrapper<SysOss> lqw = Wrappers.lambdaQuery();
lqw.like(StringUtils.isNotBlank(bo.getFileName()), SysOss::getFileName, bo.getFileName());
lqw.like(StringUtils.isNotBlank(bo.getOriginalName()), SysOss::getOriginalName, bo.getOriginalName());
lqw.eq(StringUtils.isNotBlank(bo.getFileSuffix()), SysOss::getFileSuffix, bo.getFileSuffix());
lqw.eq(StringUtils.isNotBlank(bo.getUrl()), SysOss::getUrl, bo.getUrl());
lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null,
SysOss::getCreateTime, params.get("beginCreateTime"), params.get("endCreateTime"));
lqw.eq(ObjectUtil.isNotNull(bo.getCreateBy()), SysOss::getCreateBy, bo.getCreateBy());
lqw.eq(StringUtils.isNotBlank(bo.getService()), SysOss::getService, bo.getService());
return lqw;
}
@Cacheable(cacheNames = CacheNames.SYS_OSS, key = "#ossId") @Cacheable(cacheNames = CacheNames.SYS_OSS, key = "#ossId")
@Override @Override
public SysOssVo getById(Long ossId) { public SysOssVo getById(Long ossId) {
return baseMapper.selectVoById(ossId); return sysOssData.findById(ossId).to(SysOssVo.class);
} }
@Override @Override
@ -116,22 +98,22 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
oss.setFileName(uploadResult.getFilename()); oss.setFileName(uploadResult.getFilename());
oss.setOriginalName(originalfileName); oss.setOriginalName(originalfileName);
oss.setService(storage.getConfigKey()); oss.setService(storage.getConfigKey());
baseMapper.insert(oss); sysOssData.save(oss);
SysOssVo sysOssVo = MapstructUtils.convert(oss, SysOssVo.class); SysOssVo sysOssVo = MapstructUtils.convert(oss, SysOssVo.class);
return this.matchingUrl(sysOssVo); return this.matchingUrl(sysOssVo);
} }
@Override @Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) { public void deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if (isValid) { if (isValid) {
// 做一些业务上的校验,判断是否需要校验 // 做一些业务上的校验,判断是否需要校验
} }
List<SysOss> list = baseMapper.selectBatchIds(ids); List<SysOss> list = sysOssData.findByIds(ids);
for (SysOss sysOss : list) { for (SysOss sysOss : list) {
OssClient storage = OssFactory.instance(sysOss.getService()); OssClient storage = OssFactory.instance(sysOss.getService());
storage.delete(sysOss.getUrl()); storage.delete(sysOss.getUrl());
} }
return baseMapper.deleteBatchIds(ids) > 0; sysOssData.deleteByIds(ids);
} }
/** /**

View File

@ -2,18 +2,17 @@ package cc.iotkit.system.service.impl;
import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging; import cc.iotkit.common.api.Paging;
import cc.iotkit.common.exception.BizException;
import cc.iotkit.common.utils.MapstructUtils; import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.system.ISysPostData;
import cc.iotkit.model.system.SysPost; import cc.iotkit.model.system.SysPost;
import cc.iotkit.system.dto.bo.SysPostBo; import cc.iotkit.system.dto.bo.SysPostBo;
import cc.iotkit.system.dto.vo.SysPostVo; import cc.iotkit.system.dto.vo.SysPostVo;
import cc.iotkit.system.mapper.SysPostMapper;
import cn.hutool.core.util.ObjectUtil;
import cc.iotkit.system.service.ISysPostService; import cc.iotkit.system.service.ISysPostService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Arrays; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
@ -25,14 +24,11 @@ import java.util.List;
@Service @Service
public class SysPostServiceImpl implements ISysPostService { public class SysPostServiceImpl implements ISysPostService {
private final SysPostMapper baseMapper; private final ISysPostData sysPostData;
private final SysUserPostMapper userPostMapper;
@Override @Override
public Paging<SysPostVo> selectPagePostList(SysPostBo post, PageRequest<?> query) { public Paging<SysPostVo> selectPagePostList(SysPostBo post, PageRequest<?> query) {
LambdaQueryWrapper<SysPost> lqw = buildQueryWrapper(post); return new Paging<>();
Page<SysPostVo> page = baseMapper.selectVoPage(query.build(), lqw);
return TableDataInfo.build(page);
} }
/** /**
@ -43,17 +39,7 @@ public class SysPostServiceImpl implements ISysPostService {
*/ */
@Override @Override
public List<SysPostVo> selectPostList(SysPostBo post) { public List<SysPostVo> selectPostList(SysPostBo post) {
LambdaQueryWrapper<SysPost> lqw = buildQueryWrapper(post); return new ArrayList<>();
return baseMapper.selectVoList(lqw);
}
private LambdaQueryWrapper<SysPost> buildQueryWrapper(SysPostBo bo) {
LambdaQueryWrapper<SysPost> lqw = Wrappers.lambdaQuery();
lqw.like(StringUtils.isNotBlank(bo.getPostCode()), SysPost::getPostCode, bo.getPostCode());
lqw.like(StringUtils.isNotBlank(bo.getPostName()), SysPost::getPostName, bo.getPostName());
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), SysPost::getStatus, bo.getStatus());
lqw.orderByAsc(SysPost::getPostSort);
return lqw;
} }
/** /**
@ -63,7 +49,7 @@ public class SysPostServiceImpl implements ISysPostService {
*/ */
@Override @Override
public List<SysPostVo> selectPostAll() { public List<SysPostVo> selectPostAll() {
return baseMapper.selectVoList(new QueryWrapper<>()); return MapstructUtils.convert(sysPostData.findAll(), SysPostVo.class);
} }
/** /**
@ -74,7 +60,7 @@ public class SysPostServiceImpl implements ISysPostService {
*/ */
@Override @Override
public SysPostVo selectPostById(Long postId) { public SysPostVo selectPostById(Long postId) {
return baseMapper.selectVoById(postId); return sysPostData.findById(postId).to(SysPostVo.class);
} }
/** /**
@ -85,7 +71,7 @@ public class SysPostServiceImpl implements ISysPostService {
*/ */
@Override @Override
public List<Long> selectPostListByUserId(Long userId) { public List<Long> selectPostListByUserId(Long userId) {
return baseMapper.selectPostListByUserId(userId); return new ArrayList<>();
} }
/** /**
@ -96,10 +82,7 @@ public class SysPostServiceImpl implements ISysPostService {
*/ */
@Override @Override
public boolean checkPostNameUnique(SysPostBo post) { public boolean checkPostNameUnique(SysPostBo post) {
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysPost>() return false;
.eq(SysPost::getPostName, post.getPostName())
.ne(ObjectUtil.isNotNull(post.getPostId()), SysPost::getPostId, post.getPostId()));
return !exist;
} }
/** /**
@ -110,10 +93,7 @@ public class SysPostServiceImpl implements ISysPostService {
*/ */
@Override @Override
public boolean checkPostCodeUnique(SysPostBo post) { public boolean checkPostCodeUnique(SysPostBo post) {
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysPost>() return false;
.eq(SysPost::getPostCode, post.getPostCode())
.ne(ObjectUtil.isNotNull(post.getPostId()), SysPost::getPostId, post.getPostId()));
return !exist;
} }
/** /**
@ -124,7 +104,7 @@ public class SysPostServiceImpl implements ISysPostService {
*/ */
@Override @Override
public long countUserPostById(Long postId) { public long countUserPostById(Long postId) {
return userPostMapper.selectCount(new LambdaQueryWrapper<SysUserPost>().eq(SysUserPost::getPostId, postId)); return 0;
} }
/** /**
@ -134,8 +114,8 @@ public class SysPostServiceImpl implements ISysPostService {
* @return * @return
*/ */
@Override @Override
public int deletePostById(Long postId) { public void deletePostById(Long postId) {
return baseMapper.deleteById(postId); sysPostData.deleteById(postId);
} }
/** /**
@ -145,14 +125,7 @@ public class SysPostServiceImpl implements ISysPostService {
* @return * @return
*/ */
@Override @Override
public int deletePostByIds(Long[] postIds) { public void deletePostByIds(Collection<Long> postIds) {
for (Long postId : postIds) {
SysPost post = baseMapper.selectById(postId);
if (countUserPostById(postId) > 0) {
throw new BizException(String.format("%1$s已分配,不能删除", post.getPostName()));
}
}
return baseMapper.deleteBatchIds(Arrays.asList(postIds));
} }
/** /**
@ -162,9 +135,8 @@ public class SysPostServiceImpl implements ISysPostService {
* @return * @return
*/ */
@Override @Override
public int insertPost(SysPostBo bo) { public void insertPost(SysPostBo bo) {
SysPost post = MapstructUtils.convert(bo, SysPost.class); sysPostData.save(bo.to(SysPost.class));
return baseMapper.insert(post);
} }
/** /**
@ -174,8 +146,7 @@ public class SysPostServiceImpl implements ISysPostService {
* @return * @return
*/ */
@Override @Override
public int updatePost(SysPostBo bo) { public void updatePost(SysPostBo bo) {
SysPost post = MapstructUtils.convert(bo, SysPost.class); sysPostData.save(bo.to(SysPost.class));
return baseMapper.updateById(post);
} }
} }

View File

@ -1,31 +1,25 @@
package cc.iotkit.system.service.impl; package cc.iotkit.system.service.impl;
import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.undefined.LoginUser;
import cc.iotkit.common.api.Paging; import cc.iotkit.common.api.Paging;
import cc.iotkit.common.exception.BizException; import cc.iotkit.common.exception.BizException;
import cc.iotkit.common.satoken.utils.LoginHelper; import cc.iotkit.common.satoken.utils.LoginHelper;
import cc.iotkit.common.utils.MapstructUtils; import cc.iotkit.data.system.ISysRoleData;
import cc.iotkit.common.utils.StreamUtils;
import cc.iotkit.common.utils.StringUtils;
import cc.iotkit.model.system.SysRole; import cc.iotkit.model.system.SysRole;
import cc.iotkit.system.dto.SysRoleDept;
import cc.iotkit.system.dto.SysRoleMenu;
import cc.iotkit.system.dto.SysUserRole; import cc.iotkit.system.dto.SysUserRole;
import cc.iotkit.system.dto.bo.SysRoleBo; import cc.iotkit.system.dto.bo.SysRoleBo;
import cc.iotkit.system.dto.vo.SysRoleVo; import cc.iotkit.system.dto.vo.SysRoleVo;
import cc.iotkit.system.mapper.SysRoleMapper; import cc.iotkit.system.service.ISysRoleService;
import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cc.iotkit.system.mapper.SysUserRoleMapper;
import cc.iotkit.system.service.ISysRoleService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.*; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/** /**
* *
@ -36,10 +30,11 @@ import java.util.*;
@Service @Service
public class SysRoleServiceImpl implements ISysRoleService { public class SysRoleServiceImpl implements ISysRoleService {
private final ISysRoleData sysRoleData;
@Override @Override
public Paging<SysRoleVo> selectPageRoleList(SysRoleBo role, PageRequest<?> query) { public Paging<SysRoleVo> selectPageRoleList(SysRoleBo role, PageRequest<?> query) {
Page<SysRoleVo> page = baseMapper.selectPageRoleList(query.build(), this.buildQueryWrapper(role)); return new Paging<>();
return TableDataInfo.build(page);
} }
/** /**
@ -50,21 +45,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
*/ */
@Override @Override
public List<SysRoleVo> selectRoleList(SysRoleBo role) { public List<SysRoleVo> selectRoleList(SysRoleBo role) {
return baseMapper.selectRoleList(this.buildQueryWrapper(role)); return new ArrayList<>();
}
private Wrapper<SysRole> buildQueryWrapper(SysRoleBo bo) {
Map<String, Object> params = bo.getParams();
QueryWrapper<SysRole> wrapper = Wrappers.query();
wrapper.eq("r.del_flag", UserConstants.ROLE_NORMAL)
.eq(ObjectUtil.isNotNull(bo.getRoleId()), "r.role_id", bo.getRoleId())
.like(StringUtils.isNotBlank(bo.getRoleName()), "r.role_name", bo.getRoleName())
.eq(StringUtils.isNotBlank(bo.getStatus()), "r.status", bo.getStatus())
.like(StringUtils.isNotBlank(bo.getRoleKey()), "r.role_key", bo.getRoleKey())
.between(params.get("beginTime") != null && params.get("endTime") != null,
"r.create_time", params.get("beginTime"), params.get("endTime"))
.orderByAsc("r.role_sort").orderByAsc("r.create_time");;
return wrapper;
} }
/** /**
@ -75,17 +56,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
*/ */
@Override @Override
public List<SysRoleVo> selectRolesByUserId(Long userId) { public List<SysRoleVo> selectRolesByUserId(Long userId) {
List<SysRoleVo> userRoles = baseMapper.selectRolePermissionByUserId(userId); return new ArrayList<>();
List<SysRoleVo> roles = selectRoleAll();
for (SysRoleVo role : roles) {
for (SysRoleVo userRole : userRoles) {
if (role.getRoleId().longValue() == userRole.getRoleId().longValue()) {
role.setFlag(true);
break;
}
}
}
return roles;
} }
/** /**
@ -96,14 +67,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
*/ */
@Override @Override
public Set<String> selectRolePermissionByUserId(Long userId) { public Set<String> selectRolePermissionByUserId(Long userId) {
List<SysRoleVo> perms = baseMapper.selectRolePermissionByUserId(userId); return new HashSet<>();
Set<String> permsSet = new HashSet<>();
for (SysRoleVo perm : perms) {
if (ObjectUtil.isNotNull(perm)) {
permsSet.addAll(StringUtils.splitList(perm.getRoleKey().trim()));
}
}
return permsSet;
} }
/** /**
@ -124,7 +88,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
*/ */
@Override @Override
public List<Long> selectRoleListByUserId(Long userId) { public List<Long> selectRoleListByUserId(Long userId) {
return baseMapper.selectRoleListByUserId(userId); return new ArrayList<>();
} }
/** /**
@ -135,7 +99,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
*/ */
@Override @Override
public SysRoleVo selectRoleById(Long roleId) { public SysRoleVo selectRoleById(Long roleId) {
return baseMapper.selectRoleById(roleId); return sysRoleData.findById(roleId).to(SysRoleVo.class);
} }
/** /**
@ -146,10 +110,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
*/ */
@Override @Override
public boolean checkRoleNameUnique(SysRoleBo role) { public boolean checkRoleNameUnique(SysRoleBo role) {
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysRole>() return false;
.eq(SysRole::getRoleName, role.getRoleName())
.ne(ObjectUtil.isNotNull(role.getRoleId()), SysRole::getRoleId, role.getRoleId()));
return !exist;
} }
/** /**
@ -160,10 +121,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
*/ */
@Override @Override
public boolean checkRoleKeyUnique(SysRoleBo role) { public boolean checkRoleKeyUnique(SysRoleBo role) {
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysRole>() return false;
.eq(SysRole::getRoleKey, role.getRoleKey())
.ne(ObjectUtil.isNotNull(role.getRoleId()), SysRole::getRoleId, role.getRoleId()));
return !exist;
} }
/** /**
@ -206,7 +164,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
*/ */
@Override @Override
public long countUserRoleByRoleId(Long roleId) { public long countUserRoleByRoleId(Long roleId) {
return userRoleMapper.selectCount(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getRoleId, roleId)); return 0;
} }
/** /**
@ -217,12 +175,10 @@ public class SysRoleServiceImpl implements ISysRoleService {
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public int insertRole(SysRoleBo bo) { public void insertRole(SysRoleBo bo) {
SysRole role = MapstructUtils.convert(bo, SysRole.class); SysRole role = sysRoleData.save(bo.to(SysRole.class));
// 新增角色信息 bo.setId(role.getId());
baseMapper.insert(role); insertRoleMenu(bo);
bo.setRoleId(role.getRoleId());
return insertRoleMenu(bo);
} }
/** /**
@ -233,13 +189,8 @@ public class SysRoleServiceImpl implements ISysRoleService {
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public int updateRole(SysRoleBo bo) { public void updateRole(SysRoleBo bo) {
SysRole role = MapstructUtils.convert(bo, SysRole.class); sysRoleData.save(bo.to(SysRole.class));
// 修改角色信息
baseMapper.updateById(role);
// 删除角色与菜单关联
roleMenuMapper.delete(new LambdaQueryWrapper<SysRoleMenu>().eq(SysRoleMenu::getRoleId, role.getRoleId()));
return insertRoleMenu(bo);
} }
/** /**
@ -250,11 +201,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
* @return * @return
*/ */
@Override @Override
public int updateRoleStatus(Long roleId, String status) { public void updateRoleStatus(Long roleId, String status) {
return baseMapper.update(null,
new LambdaUpdateWrapper<SysRole>()
.set(SysRole::getStatus, status)
.eq(SysRole::getRoleId, roleId));
} }
/** /**
@ -265,14 +212,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public int authDataScope(SysRoleBo bo) { public void authDataScope(SysRoleBo bo) {
SysRole role = MapstructUtils.convert(bo, SysRole.class);
// 修改角色信息
baseMapper.updateById(role);
// 删除角色与部门关联
roleDeptMapper.delete(new LambdaQueryWrapper<SysRoleDept>().eq(SysRoleDept::getRoleId, role.getRoleId()));
// 新增角色和部门信息(数据权限)
return insertRoleDept(bo);
} }
/** /**
@ -280,20 +220,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
* *
* @param role * @param role
*/ */
private int insertRoleMenu(SysRoleBo role) { private void insertRoleMenu(SysRoleBo role) {
int rows = 1;
// 新增用户与角色管理
List<SysRoleMenu> list = new ArrayList<SysRoleMenu>();
for (Long menuId : role.getMenuIds()) {
SysRoleMenu rm = new SysRoleMenu();
rm.setRoleId(role.getRoleId());
rm.setMenuId(menuId);
list.add(rm);
}
if (list.size() > 0) {
rows = roleMenuMapper.insertBatch(list) ? list.size() : 0;
}
return rows;
} }
/** /**
@ -301,20 +228,8 @@ public class SysRoleServiceImpl implements ISysRoleService {
* *
* @param role * @param role
*/ */
private int insertRoleDept(SysRoleBo role) { private void insertRoleDept(SysRoleBo role) {
int rows = 1;
// 新增角色与部门(数据权限)管理
List<SysRoleDept> list = new ArrayList<SysRoleDept>();
for (Long deptId : role.getDeptIds()) {
SysRoleDept rd = new SysRoleDept();
rd.setRoleId(role.getRoleId());
rd.setDeptId(deptId);
list.add(rd);
}
if (list.size() > 0) {
rows = roleDeptMapper.insertBatch(list) ? list.size() : 0;
}
return rows;
} }
/** /**
@ -325,12 +240,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public int deleteRoleById(Long roleId) { public void deleteRoleById(Long roleId) {
// 删除角色与菜单关联
roleMenuMapper.delete(new LambdaQueryWrapper<SysRoleMenu>().eq(SysRoleMenu::getRoleId, roleId));
// 删除角色与部门关联
roleDeptMapper.delete(new LambdaQueryWrapper<SysRoleDept>().eq(SysRoleDept::getRoleId, roleId));
return baseMapper.deleteById(roleId);
} }
/** /**
@ -341,21 +251,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public int deleteRoleByIds(Long[] roleIds) { public void deleteRoleByIds(Long[] roleIds) {
for (Long roleId : roleIds) {
checkRoleAllowed(roleId);
checkRoleDataScope(roleId);
SysRole role = baseMapper.selectById(roleId);
if (countUserRoleByRoleId(roleId) > 0) {
throw new BizException(String.format("%1$s已分配,不能删除", role.getRoleName()));
}
}
List<Long> ids = Arrays.asList(roleIds);
// 删除角色与菜单关联
roleMenuMapper.delete(new LambdaQueryWrapper<SysRoleMenu>().in(SysRoleMenu::getRoleId, ids));
// 删除角色与部门关联
roleDeptMapper.delete(new LambdaQueryWrapper<SysRoleDept>().in(SysRoleDept::getRoleId, ids));
return baseMapper.deleteBatchIds(ids);
} }
/** /**
@ -365,14 +261,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
* @return * @return
*/ */
@Override @Override
public int deleteAuthUser(SysUserRole userRole) { public void deleteAuthUser(SysUserRole userRole) {
int rows = userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>()
.eq(SysUserRole::getRoleId, userRole.getRoleId())
.eq(SysUserRole::getUserId, userRole.getUserId()));
if (rows > 0) {
cleanOnlineUserByRole(userRole.getRoleId());
}
return rows;
} }
/** /**
@ -383,14 +272,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
* @return * @return
*/ */
@Override @Override
public int deleteAuthUsers(Long roleId, Long[] userIds) { public void deleteAuthUsers(Long roleId, Long[] userIds) {
int rows = userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>()
.eq(SysUserRole::getRoleId, roleId)
.in(SysUserRole::getUserId, Arrays.asList(userIds)));
if (rows > 0) {
cleanOnlineUserByRole(roleId);
}
return rows;
} }
/** /**
@ -401,44 +283,10 @@ public class SysRoleServiceImpl implements ISysRoleService {
* @return * @return
*/ */
@Override @Override
public int insertAuthUsers(Long roleId, Long[] userIds) { public void insertAuthUsers(Long roleId, Long[] userIds) {
// 新增用户与角色管理
int rows = 1;
List<SysUserRole> list = StreamUtils.toList(List.of(userIds), userId -> {
SysUserRole ur = new SysUserRole();
ur.setUserId(userId);
ur.setRoleId(roleId);
return ur;
});
if (CollUtil.isNotEmpty(list)) {
rows = userRoleMapper.insertBatch(list) ? list.size() : 0;
}
if (rows > 0) {
cleanOnlineUserByRole(roleId);
}
return rows;
} }
@Override @Override
public void cleanOnlineUserByRole(Long roleId) { public void cleanOnlineUserByRole(Long roleId) {
List<String> keys = StpUtil.searchTokenValue("", 0, -1, false);
if (CollUtil.isEmpty(keys)) {
return;
}
// 角色关联的在线用户量过大会导致redis阻塞卡顿 谨慎操作
keys.parallelStream().forEach(key -> {
String token = StringUtils.substringAfterLast(key, ":");
// 如果已经过期则跳过
if (StpUtil.stpLogic.getTokenActivityTimeoutByToken(token) < -1) {
return;
}
LoginUser loginUser = LoginHelper.getLoginUser(token);
if (loginUser.getRoles().stream().anyMatch(r -> r.getRoleId().equals(roleId))) {
try {
StpUtil.logoutByTokenValue(token);
} catch (NotLoginException ignored) {
}
}
});
} }
} }

View File

@ -2,23 +2,18 @@ package cc.iotkit.system.service.impl;
import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging; import cc.iotkit.common.api.Paging;
import cc.iotkit.common.exception.BizException; import cc.iotkit.data.system.ISysTenantPackageData;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.common.utils.StringUtils;
import cc.iotkit.model.system.SysTenant;
import cc.iotkit.model.system.SysTenantPackage; import cc.iotkit.model.system.SysTenantPackage;
import cc.iotkit.system.dto.bo.SysTenantPackageBo; import cc.iotkit.system.dto.bo.SysTenantPackageBo;
import cc.iotkit.system.dto.vo.SysTenantPackageVo; import cc.iotkit.system.dto.vo.SysTenantPackageVo;
import cn.hutool.core.collection.CollUtil; import cc.iotkit.system.service.ISysTenantPackageService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import cc.iotkit.system.service.ISysTenantPackageService;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays; import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Collection; import java.util.Collection;
import java.util.List;
/** /**
* Service * Service
@ -29,15 +24,14 @@ import java.util.Collection;
@Service @Service
public class SysTenantPackageServiceImpl implements ISysTenantPackageService { public class SysTenantPackageServiceImpl implements ISysTenantPackageService {
private final SysTenantPackageMapper baseMapper; private final ISysTenantPackageData sysTenantPackageData;
private final SysTenantMapper tenantMapper;
/** /**
* *
*/ */
@Override @Override
public SysTenantPackageVo queryById(Long packageId){ public SysTenantPackageVo queryById(Long packageId) {
return baseMapper.selectVoById(packageId); return sysTenantPackageData.findById(packageId).to(SysTenantPackageVo.class);
} }
/** /**
@ -45,15 +39,12 @@ public class SysTenantPackageServiceImpl implements ISysTenantPackageService {
*/ */
@Override @Override
public Paging<SysTenantPackageVo> queryPageList(SysTenantPackageBo bo, PageRequest<?> query) { public Paging<SysTenantPackageVo> queryPageList(SysTenantPackageBo bo, PageRequest<?> query) {
LambdaQueryWrapper<SysTenantPackage> lqw = buildQueryWrapper(bo); return new Paging<>();
Page<SysTenantPackageVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);
} }
@Override @Override
public List<SysTenantPackageVo> selectList() { public List<SysTenantPackageVo> selectList() {
return baseMapper.selectVoList(new LambdaQueryWrapper<SysTenantPackage>() return new ArrayList<>();
.eq(SysTenantPackage::getStatus, TenantConstants.NORMAL));
} }
/** /**
@ -61,16 +52,7 @@ public class SysTenantPackageServiceImpl implements ISysTenantPackageService {
*/ */
@Override @Override
public List<SysTenantPackageVo> queryList(SysTenantPackageBo bo) { public List<SysTenantPackageVo> queryList(SysTenantPackageBo bo) {
LambdaQueryWrapper<SysTenantPackage> lqw = buildQueryWrapper(bo); return new ArrayList<>();
return baseMapper.selectVoList(lqw);
}
private LambdaQueryWrapper<SysTenantPackage> buildQueryWrapper(SysTenantPackageBo bo) {
Map<String, Object> params = bo.getParams();
LambdaQueryWrapper<SysTenantPackage> lqw = Wrappers.lambdaQuery();
lqw.like(StringUtils.isNotBlank(bo.getPackageName()), SysTenantPackage::getPackageName, bo.getPackageName());
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), SysTenantPackage::getStatus, bo.getStatus());
return lqw;
} }
/** /**
@ -79,19 +61,7 @@ public class SysTenantPackageServiceImpl implements ISysTenantPackageService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Boolean insertByBo(SysTenantPackageBo bo) { public Boolean insertByBo(SysTenantPackageBo bo) {
SysTenantPackage add = MapstructUtils.convert(bo, SysTenantPackage.class); return false;
// 保存菜单id
List<Long> menuIds = Arrays.asList(bo.getMenuIds());
if (CollUtil.isNotEmpty(menuIds)) {
add.setMenuIds(StringUtils.join(menuIds, ", "));
} else {
add.setMenuIds("");
}
boolean flag = baseMapper.insert(add) > 0;
if (flag) {
bo.setPackageId(add.getPackageId());
}
return flag;
} }
/** /**
@ -100,15 +70,7 @@ public class SysTenantPackageServiceImpl implements ISysTenantPackageService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Boolean updateByBo(SysTenantPackageBo bo) { public Boolean updateByBo(SysTenantPackageBo bo) {
SysTenantPackage update = MapstructUtils.convert(bo, SysTenantPackage.class); return false;
// 保存菜单id
List<Long> menuIds = Arrays.asList(bo.getMenuIds());
if (CollUtil.isNotEmpty(menuIds)) {
update.setMenuIds(StringUtils.join(menuIds, ", "));
} else {
update.setMenuIds("");
}
return baseMapper.updateById(update) > 0;
} }
/** /**
@ -118,9 +80,8 @@ public class SysTenantPackageServiceImpl implements ISysTenantPackageService {
* @return * @return
*/ */
@Override @Override
public int updatePackageStatus(SysTenantPackageBo bo) { public void updatePackageStatus(SysTenantPackageBo bo) {
SysTenantPackage tenantPackage = MapstructUtils.convert(bo, SysTenantPackage.class); sysTenantPackageData.save(bo.to(SysTenantPackage.class));
return baseMapper.updateById(tenantPackage);
} }
/** /**
@ -129,12 +90,6 @@ public class SysTenantPackageServiceImpl implements ISysTenantPackageService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) { public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if(isValid){ return false;
boolean exists = tenantMapper.exists(new LambdaQueryWrapper<SysTenant>().in(SysTenant::getPackageId, ids));
if (exists) {
throw new BizException("租户套餐已被使用");
}
}
return baseMapper.deleteBatchIds(ids) > 0;
} }
} }

View File

@ -1,34 +1,15 @@
package cc.iotkit.system.service.impl; package cc.iotkit.system.service.impl;
import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.constant.CacheNames;
import cc.iotkit.common.constant.Constants;
import cc.iotkit.common.constant.TenantConstants;
import cc.iotkit.common.api.Paging; import cc.iotkit.common.api.Paging;
import cc.iotkit.common.exception.BizException; import cc.iotkit.data.system.ISysTenantData;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.common.utils.StringUtils;
import cc.iotkit.model.system.*;
import cc.iotkit.system.dto.SysRoleDept;
import cc.iotkit.system.dto.SysRoleMenu;
import cc.iotkit.system.dto.SysUserRole;
import cc.iotkit.system.dto.bo.SysTenantBo; import cc.iotkit.system.dto.bo.SysTenantBo;
import cc.iotkit.system.dto.vo.SysTenantVo; import cc.iotkit.system.dto.vo.SysTenantVo;
import cc.iotkit.system.mapper.*;
import cn.dev33.satoken.secure.BCrypt;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import lombok.RequiredArgsConstructor;
import cc.iotkit.system.service.ISysTenantService; import cc.iotkit.system.service.ISysTenantService;
import org.springframework.cache.annotation.CacheEvict; import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
@ -40,327 +21,70 @@ import java.util.List;
@Service @Service
public class SysTenantServiceImpl implements ISysTenantService { public class SysTenantServiceImpl implements ISysTenantService {
private final SysTenantMapper baseMapper; private final ISysTenantData sysTenantData;
private final SysTenantPackageMapper tenantPackageMapper;
private final SysUserMapper userMapper;
private final SysDeptMapper deptMapper;
private final SysRoleMapper roleMapper;
private final SysRoleMenuMapper roleMenuMapper;
private final SysRoleDeptMapper roleDeptMapper;
private final SysUserRoleMapper userRoleMapper;
private final SysDictTypeMapper dictTypeMapper;
private final SysDictDataMapper dictDataMapper;
private final SysConfigMapper configMapper;
/**
*
*/
@Override @Override
public SysTenantVo queryById(Long id) { public SysTenantVo queryById(Long id) {
return baseMapper.selectVoById(id); return null;
} }
/**
* ID
*/
@Cacheable(cacheNames = CacheNames.SYS_TENANT, key = "#tenantId")
@Override @Override
public SysTenantVo queryByTenantId(String tenantId) { public SysTenantVo queryByTenantId(String tenantId) {
return baseMapper.selectVoOne(new LambdaQueryWrapper<SysTenant>().eq(SysTenant::getTenantId, tenantId)); return null;
} }
/**
*
*/
@Override @Override
public Paging<SysTenantVo> queryPageList(SysTenantBo bo, PageRequest<?> query) { public Paging<SysTenantVo> queryPageList(SysTenantBo bo, PageRequest<?> query) {
LambdaQueryWrapper<SysTenant> lqw = buildQueryWrapper(bo); return null;
Page<SysTenantVo> result = baseMapper.selectVoPage(query.build(), lqw);
return TableDataInfo.build(result);
} }
/**
*
*/
@Override @Override
public List<SysTenantVo> queryList(SysTenantBo bo) { public List<SysTenantVo> queryList(SysTenantBo bo) {
LambdaQueryWrapper<SysTenant> lqw = buildQueryWrapper(bo); return null;
return baseMapper.selectVoList(lqw);
} }
private LambdaQueryWrapper<SysTenant> buildQueryWrapper(SysTenantBo bo) {
LambdaQueryWrapper<SysTenant> lqw = Wrappers.lambdaQuery();
lqw.eq(StringUtils.isNotBlank(bo.getTenantId()), SysTenant::getTenantId, bo.getTenantId());
lqw.like(StringUtils.isNotBlank(bo.getContactUserName()), SysTenant::getContactUserName, bo.getContactUserName());
lqw.eq(StringUtils.isNotBlank(bo.getContactPhone()), SysTenant::getContactPhone, bo.getContactPhone());
lqw.like(StringUtils.isNotBlank(bo.getCompanyName()), SysTenant::getCompanyName, bo.getCompanyName());
lqw.eq(StringUtils.isNotBlank(bo.getLicenseNumber()), SysTenant::getLicenseNumber, bo.getLicenseNumber());
lqw.eq(StringUtils.isNotBlank(bo.getAddress()), SysTenant::getAddress, bo.getAddress());
lqw.eq(StringUtils.isNotBlank(bo.getIntro()), SysTenant::getIntro, bo.getIntro());
lqw.like(StringUtils.isNotBlank(bo.getDomain()), SysTenant::getDomain, bo.getDomain());
lqw.eq(bo.getPackageId() != null, SysTenant::getPackageId, bo.getPackageId());
lqw.eq(bo.getExpireTime() != null, SysTenant::getExpireTime, bo.getExpireTime());
lqw.eq(bo.getAccountCount() != null, SysTenant::getAccountCount, bo.getAccountCount());
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), SysTenant::getStatus, bo.getStatus());
return lqw;
}
/**
*
*/
@Override @Override
@Transactional(rollbackFor = Exception.class)
public Boolean insertByBo(SysTenantBo bo) { public Boolean insertByBo(SysTenantBo bo) {
SysTenant add = MapstructUtils.convert(bo, SysTenant.class); return null;
// 获取所有租户编号
List<String> tenantIds = baseMapper.selectObjs(
new LambdaQueryWrapper<SysTenant>().select(SysTenant::getTenantId), Convert::toStr);
String tenantId = generateTenantId(tenantIds);
add.setTenantId(tenantId);
boolean flag = baseMapper.insert(add) > 0;
if (!flag) {
throw new BizException("创建租户失败");
}
bo.setId(add.getId());
// 根据套餐创建角色
Long roleId = createTenantRole(tenantId, bo.getPackageId());
// 创建部门: 公司名是部门名称
SysDept dept = new SysDept();
dept.setTenantId(tenantId);
dept.setDeptName(bo.getCompanyName());
dept.setLeader(bo.getUsername());
dept.setParentId(Constants.TOP_PARENT_ID);
dept.setAncestors(Constants.TOP_PARENT_ID.toString());
deptMapper.insert(dept);
Long deptId = dept.getDeptId();
// 角色和部门关联表
SysRoleDept roleDept = new SysRoleDept();
roleDept.setRoleId(roleId);
roleDept.setDeptId(deptId);
roleDeptMapper.insert(roleDept);
// 创建系统用户
SysUser user = new SysUser();
user.setTenantId(tenantId);
user.setUserName(bo.getUsername());
user.setNickName(bo.getUsername());
user.setPassword(BCrypt.hashpw(bo.getPassword()));
user.setDeptId(deptId);
userMapper.insert(user);
// 用户和角色关联表
SysUserRole userRole = new SysUserRole();
userRole.setUserId(user.getUserId());
userRole.setRoleId(roleId);
userRoleMapper.insert(userRole);
String defaultTenantId = TenantConstants.DEFAULT_TENANT_ID;
List<SysDictType> dictTypeList = dictTypeMapper.selectList(
new LambdaQueryWrapper<SysDictType>().eq(SysDictType::getTenantId, defaultTenantId));
List<SysDictData> dictDataList = dictDataMapper.selectList(
new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getTenantId, defaultTenantId));
for (SysDictType dictType : dictTypeList) {
dictType.setDictId(null);
dictType.setTenantId(tenantId);
}
for (SysDictData dictData : dictDataList) {
dictData.setDictCode(null);
dictData.setTenantId(tenantId);
}
dictTypeMapper.insertBatch(dictTypeList);
dictDataMapper.insertBatch(dictDataList);
List<SysConfig> sysConfigList = configMapper.selectList(
new LambdaQueryWrapper<SysConfig>().eq(SysConfig::getTenantId, defaultTenantId));
for (SysConfig config : sysConfigList) {
config.setConfigId(null);
config.setTenantId(tenantId);
}
configMapper.insertBatch(sysConfigList);
return true;
} }
/**
* id
*
* @param tenantIds id
* @return id
*/
private String generateTenantId(List<String> tenantIds) {
// 随机生成6位
String numbers = RandomUtil.randomNumbers(6);
// 判断是否存在,如果存在则重新生成
if (tenantIds.contains(numbers)) {
generateTenantId(tenantIds);
}
return numbers;
}
/**
*
*
* @param tenantId
* @param packageId id
* @return id
*/
private Long createTenantRole(String tenantId, Long packageId) {
// 获取租户套餐
SysTenantPackage tenantPackage = tenantPackageMapper.selectById(packageId);
if (ObjectUtil.isNull(tenantPackage)) {
throw new BizException("套餐不存在");
}
// 获取套餐菜单id
List<Long> menuIds = StringUtils.splitTo(tenantPackage.getMenuIds(), Convert::toLong);
// 创建角色
SysRole role = new SysRole();
role.setTenantId(tenantId);
role.setRoleName(TenantConstants.TENANT_ADMIN_ROLE_NAME);
role.setRoleKey(TenantConstants.TENANT_ADMIN_ROLE_KEY);
role.setRoleSort(1);
role.setStatus(TenantConstants.NORMAL);
roleMapper.insert(role);
Long roleId = role.getRoleId();
// 创建角色菜单
List<SysRoleMenu> roleMenus = new ArrayList<>(menuIds.size());
menuIds.forEach(menuId -> {
SysRoleMenu roleMenu = new SysRoleMenu();
roleMenu.setRoleId(roleId);
roleMenu.setMenuId(menuId);
roleMenus.add(roleMenu);
});
roleMenuMapper.insertBatch(roleMenus);
return roleId;
}
/**
*
*/
@CacheEvict(cacheNames = CacheNames.SYS_TENANT, key = "#bo.tenantId")
@Override @Override
public Boolean updateByBo(SysTenantBo bo) { public Boolean updateByBo(SysTenantBo bo) {
SysTenant tenant = MapstructUtils.convert(bo, SysTenant.class); return null;
tenant.setTenantId(null);
tenant.setPackageId(null);
return baseMapper.updateById(tenant) > 0;
} }
/**
*
*
* @param bo
* @return
*/
@CacheEvict(cacheNames = CacheNames.SYS_TENANT, key = "#bo.tenantId")
@Override @Override
public int updateTenantStatus(SysTenantBo bo) { public int updateTenantStatus(SysTenantBo bo) {
SysTenant tenant = MapstructUtils.convert(bo, SysTenant.class); return 0;
return baseMapper.updateById(tenant);
} }
/**
*
*
* @param tenantId ID
*/
@Override @Override
public void checkTenantAllowed(String tenantId) { public void checkTenantAllowed(String tenantId) {
if (ObjectUtil.isNotNull(tenantId) && TenantConstants.DEFAULT_TENANT_ID.equals(tenantId)) {
throw new ServiceException("不允许操作管理租户");
}
} }
/**
*
*/
@CacheEvict(cacheNames = CacheNames.SYS_TENANT, allEntries = true)
@Override @Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) { public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if (isValid) { return null;
// 做一些业务上的校验,判断是否需要校验
if (ids.contains(TenantConstants.SUPER_ADMIN_ID)) {
throw new ServiceException("超管租户不能删除");
}
}
return baseMapper.deleteBatchIds(ids) > 0;
} }
/**
*
*/
@Override @Override
public boolean checkCompanyNameUnique(SysTenantBo bo) { public boolean checkCompanyNameUnique(SysTenantBo bo) {
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysTenant>() return false;
.eq(SysTenant::getCompanyName, bo.getCompanyName())
.ne(ObjectUtil.isNotNull(bo.getTenantId()), SysTenant::getTenantId, bo.getTenantId()));
return !exist;
} }
/**
*
*/
@Override @Override
public boolean checkAccountBalance(String tenantId) { public boolean checkAccountBalance(String tenantId) {
SysTenantVo tenant = SpringUtils.getAopProxy(this).queryByTenantId(tenantId); return false;
// 如果余额为-1代表不限制
if (tenant.getAccountCount() == -1) {
return true;
}
Long userNumber = userMapper.selectCount(new LambdaQueryWrapper<>());
// 如果余额大于0代表还有可用名额
return tenant.getAccountCount() - userNumber > 0;
} }
/**
*
*/
@Override @Override
public boolean checkExpireTime(String tenantId) { public boolean checkExpireTime(String tenantId) {
SysTenantVo tenant = SpringUtils.getAopProxy(this).queryByTenantId(tenantId); return false;
// 如果未设置过期时间代表不限制
if (ObjectUtil.isNull(tenant.getExpireTime())) {
return true;
}
// 如果当前时间在过期时间之前则通过
return new Date().before(tenant.getExpireTime());
} }
/**
*
*/
@Override @Override
@Transactional(rollbackFor = Exception.class)
public Boolean syncTenantPackage(String tenantId, String packageId) { public Boolean syncTenantPackage(String tenantId, String packageId) {
SysTenantPackage tenantPackage = tenantPackageMapper.selectById(packageId); return null;
List<SysRole> roles = roleMapper.selectList(
new LambdaQueryWrapper<SysRole>().eq(SysRole::getTenantId, tenantId));
List<Long> roleIds = new ArrayList<>(roles.size() - 1);
List<Long> menuIds = StringUtils.splitTo(tenantPackage.getMenuIds(), Convert::toLong);
roles.forEach(item -> {
if (TenantConstants.TENANT_ADMIN_ROLE_KEY.equals(item.getRoleKey())) {
List<SysRoleMenu> roleMenus = new ArrayList<>(menuIds.size());
menuIds.forEach(menuId -> {
SysRoleMenu roleMenu = new SysRoleMenu();
roleMenu.setRoleId(item.getRoleId());
roleMenu.setMenuId(menuId);
roleMenus.add(roleMenu);
});
roleMenuMapper.delete(new LambdaQueryWrapper<SysRoleMenu>().eq(SysRoleMenu::getRoleId, item.getRoleId()));
roleMenuMapper.insertBatch(roleMenus);
} else {
roleIds.add(item.getRoleId());
}
});
if (!roleIds.isEmpty()) {
roleMenuMapper.delete(
new LambdaQueryWrapper<SysRoleMenu>().in(SysRoleMenu::getRoleId, roleIds).notIn(!menuIds.isEmpty(), SysRoleMenu::getMenuId, menuIds));
}
return true;
} }
} }

View File

@ -1,36 +1,16 @@
package cc.iotkit.system.service.impl; package cc.iotkit.system.service.impl;
import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.constant.CacheNames;
import cc.iotkit.common.constant.UserConstants;
import cc.iotkit.common.api.Paging; import cc.iotkit.common.api.Paging;
import cc.iotkit.common.exception.BizException;
import cc.iotkit.common.satoken.utils.LoginHelper;
import cc.iotkit.common.service.UserService; import cc.iotkit.common.service.UserService;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.common.utils.StreamUtils;
import cc.iotkit.common.utils.StringUtils;
import cc.iotkit.model.system.SysDept;
import cc.iotkit.model.system.SysUser;
import cc.iotkit.system.dto.SysUserPost;
import cc.iotkit.system.dto.SysUserRole;
import cc.iotkit.system.dto.bo.SysUserBo; import cc.iotkit.system.dto.bo.SysUserBo;
import cc.iotkit.system.dto.vo.SysPostVo;
import cc.iotkit.system.dto.vo.SysRoleVo;
import cc.iotkit.system.dto.vo.SysUserVo; import cc.iotkit.system.dto.vo.SysUserVo;
import cc.iotkit.system.mapper.*; import cc.iotkit.system.service.ISysUserService;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import cc.iotkit.system.service.ISysUserService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* *
@ -42,475 +22,128 @@ import java.util.Map;
@Service @Service
public class SysUserServiceImpl implements ISysUserService, UserService { public class SysUserServiceImpl implements ISysUserService, UserService {
private final SysUserMapper baseMapper; @Override
private final SysDeptMapper deptMapper; public String selectUserNameById(Long userId) {
private final SysRoleMapper roleMapper; return null;
private final SysPostMapper postMapper; }
private final SysUserRoleMapper userRoleMapper;
private final SysUserPostMapper userPostMapper;
@Override @Override
public Paging<SysUserVo> selectPageUserList(SysUserBo user, PageRequest<?> query) { public Paging<SysUserVo> selectPageUserList(SysUserBo user, PageRequest<?> query) {
Page<SysUserVo> page = baseMapper.selectPageUserList(query.build(), this.buildQueryWrapper(user)); return null;
return TableDataInfo.build(page);
} }
/**
*
*
* @param user
* @return
*/
@Override @Override
public List<SysUserVo> selectUserList(SysUserBo user) { public List<SysUserVo> selectUserList(SysUserBo user) {
return baseMapper.selectUserList(this.buildQueryWrapper(user)); return null;
} }
private Wrapper<SysUser> buildQueryWrapper(SysUserBo user) {
Map<String, Object> params = user.getParams();
QueryWrapper<SysUser> wrapper = Wrappers.query();
wrapper.eq("u.del_flag", UserConstants.USER_NORMAL)
.eq(ObjectUtil.isNotNull(user.getUserId()), "u.user_id", user.getUserId())
.like(StringUtils.isNotBlank(user.getUserName()), "u.user_name", user.getUserName())
.eq(StringUtils.isNotBlank(user.getStatus()), "u.status", user.getStatus())
.like(StringUtils.isNotBlank(user.getPhonenumber()), "u.phonenumber", user.getPhonenumber())
.between(params.get("beginTime") != null && params.get("endTime") != null,
"u.create_time", params.get("beginTime"), params.get("endTime"))
.and(ObjectUtil.isNotNull(user.getDeptId()), w -> {
List<SysDept> deptList = deptMapper.selectList(new LambdaQueryWrapper<SysDept>()
.select(SysDept::getDeptId)
.apply(DataBaseHelper.findInSet(user.getDeptId(), "ancestors")));
List<Long> ids = StreamUtils.toList(deptList, SysDept::getDeptId);
ids.add(user.getDeptId());
w.in("u.dept_id", ids);
});
return wrapper;
}
/**
*
*
* @param user
* @return
*/
@Override @Override
public Paging<SysUserVo> selectAllocatedList(SysUserBo user, PageRequest<?> query) { public Paging<SysUserVo> selectAllocatedList(SysUserBo user, PageRequest<?> query) {
QueryWrapper<SysUser> wrapper = Wrappers.query(); return null;
wrapper.eq("u.del_flag", UserConstants.USER_NORMAL)
.eq(ObjectUtil.isNotNull(user.getRoleId()), "r.role_id", user.getRoleId())
.like(StringUtils.isNotBlank(user.getUserName()), "u.user_name", user.getUserName())
.eq(StringUtils.isNotBlank(user.getStatus()), "u.status", user.getStatus())
.like(StringUtils.isNotBlank(user.getPhonenumber()), "u.phonenumber", user.getPhonenumber());
Page<SysUserVo> page = baseMapper.selectAllocatedList(query.build(), wrapper);
return TableDataInfo.build(page);
} }
/**
*
*
* @param user
* @return
*/
@Override @Override
public Paging<SysUserVo> selectUnallocatedList(SysUserBo user, PageRequest<?> query) { public Paging<SysUserVo> selectUnallocatedList(SysUserBo user, PageRequest<?> query) {
List<Long> userIds = userRoleMapper.selectUserIdsByRoleId(user.getRoleId()); return null;
QueryWrapper<SysUser> wrapper = Wrappers.query();
wrapper.eq("u.del_flag", UserConstants.USER_NORMAL)
.and(w -> w.ne("r.role_id", user.getRoleId()).or().isNull("r.role_id"))
.notIn(CollUtil.isNotEmpty(userIds), "u.user_id", userIds)
.like(StringUtils.isNotBlank(user.getUserName()), "u.user_name", user.getUserName())
.like(StringUtils.isNotBlank(user.getPhonenumber()), "u.phonenumber", user.getPhonenumber());
Page<SysUserVo> page = baseMapper.selectUnallocatedList(query.build(), wrapper);
return TableDataInfo.build(page);
} }
/**
*
*
* @param userName
* @return
*/
@Override @Override
public SysUserVo selectUserByUserName(String userName) { public SysUserVo selectUserByUserName(String userName) {
return baseMapper.selectUserByUserName(userName); return null;
} }
/**
*
*
* @param phonenumber
* @return
*/
@Override @Override
public SysUserVo selectUserByPhonenumber(String phonenumber) { public SysUserVo selectUserByPhonenumber(String phonenumber) {
return baseMapper.selectUserByPhonenumber(phonenumber); return null;
} }
/**
* ID
*
* @param userId ID
* @return
*/
@Override @Override
public SysUserVo selectUserById(Long userId) { public SysUserVo selectUserById(Long userId) {
return baseMapper.selectUserById(userId); return null;
} }
/**
*
*
* @param userName
* @return
*/
@Override @Override
public String selectUserRoleGroup(String userName) { public String selectUserRoleGroup(String userName) {
List<SysRoleVo> list = roleMapper.selectRolesByUserName(userName); return null;
if (CollUtil.isEmpty(list)) {
return StringUtils.EMPTY;
}
return StreamUtils.join(list, SysRoleVo::getRoleName);
} }
/**
*
*
* @param userName
* @return
*/
@Override @Override
public String selectUserPostGroup(String userName) { public String selectUserPostGroup(String userName) {
List<SysPostVo> list = postMapper.selectPostsByUserName(userName); return null;
if (CollUtil.isEmpty(list)) {
return StringUtils.EMPTY;
}
return StreamUtils.join(list, SysPostVo::getPostName);
} }
/**
*
*
* @param user
* @return
*/
@Override @Override
public boolean checkUserNameUnique(SysUserBo user) { public boolean checkUserNameUnique(SysUserBo user) {
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysUser>() return false;
.eq(SysUser::getUserName, user.getUserName())
.ne(ObjectUtil.isNotNull(user.getUserId()), SysUser::getUserId, user.getUserId()));
return !exist;
} }
/**
*
*
* @param user
*/
@Override @Override
public boolean checkPhoneUnique(SysUserBo user) { public boolean checkPhoneUnique(SysUserBo user) {
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysUser>() return false;
.eq(SysUser::getPhonenumber, user.getPhonenumber())
.ne(ObjectUtil.isNotNull(user.getUserId()), SysUser::getUserId, user.getUserId()));
return !exist;
} }
/**
* email
*
* @param user
*/
@Override @Override
public boolean checkEmailUnique(SysUserBo user) { public boolean checkEmailUnique(SysUserBo user) {
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysUser>() return false;
.eq(SysUser::getEmail, user.getEmail())
.ne(ObjectUtil.isNotNull(user.getUserId()), SysUser::getUserId, user.getUserId()));
return !exist;
} }
/**
*
*
* @param userId ID
*/
@Override @Override
public void checkUserAllowed(Long userId) { public void checkUserAllowed(Long userId) {
if (ObjectUtil.isNotNull(userId) && LoginHelper.isSuperAdmin(userId)) {
throw new BizException("不允许操作超级管理员用户");
}
} }
/**
*
*
* @param userId id
*/
@Override @Override
public void checkUserDataScope(Long userId) { public void checkUserDataScope(Long userId) {
if (ObjectUtil.isNull(userId)) {
return;
}
if (LoginHelper.isSuperAdmin()) {
return;
}
if (ObjectUtil.isNull(baseMapper.selectUserById(userId))) {
throw new BizException("没有权限访问用户数据!");
}
} }
/**
*
*
* @param user
* @return
*/
@Override @Override
@Transactional(rollbackFor = Exception.class)
public int insertUser(SysUserBo user) { public int insertUser(SysUserBo user) {
SysUser sysUser = MapstructUtils.convert(user, SysUser.class); return 0;
// 新增用户信息
int rows = baseMapper.insert(sysUser);
user.setUserId(sysUser.getUserId());
// 新增用户岗位关联
insertUserPost(user, false);
// 新增用户与角色管理
insertUserRole(user, false);
return rows;
} }
/**
*
*
* @param user
* @return
*/
@Override @Override
public boolean registerUser(SysUserBo user, String tenantId) { public boolean registerUser(SysUserBo user, String tenantId) {
user.setCreateBy(user.getUserId()); return false;
user.setUpdateBy(user.getUserId());
SysUser sysUser = MapstructUtils.convert(user, SysUser.class);
sysUser.setTenantId(tenantId);
return baseMapper.insert(sysUser) > 0;
} }
/**
*
*
* @param user
* @return
*/
@Override @Override
@Transactional(rollbackFor = Exception.class)
public int updateUser(SysUserBo user) { public int updateUser(SysUserBo user) {
// 新增用户与角色管理 return 0;
insertUserRole(user, true);
// 新增用户与岗位管理
insertUserPost(user, true);
SysUser sysUser = MapstructUtils.convert(user, SysUser.class);
// 防止错误更新后导致的数据误删除
int flag = baseMapper.updateById(sysUser);
if (flag < 1) {
throw new BizException("修改用户" + user.getUserName() + "信息失败");
}
return flag;
} }
/**
*
*
* @param userId ID
* @param roleIds
*/
@Override @Override
@Transactional(rollbackFor = Exception.class)
public void insertUserAuth(Long userId, Long[] roleIds) { public void insertUserAuth(Long userId, Long[] roleIds) {
insertUserRole(userId, roleIds, true);
} }
/**
*
*
* @param userId ID
* @param status
* @return
*/
@Override @Override
public int updateUserStatus(Long userId, String status) { public int updateUserStatus(Long userId, String status) {
return baseMapper.update(null, return 0;
new LambdaUpdateWrapper<SysUser>()
.set(SysUser::getStatus, status)
.eq(SysUser::getUserId, userId));
} }
/**
*
*
* @param user
* @return
*/
@Override @Override
public int updateUserProfile(SysUserBo user) { public int updateUserProfile(SysUserBo user) {
return baseMapper.update(null, return 0;
new LambdaUpdateWrapper<SysUser>()
.set(ObjectUtil.isNotNull(user.getNickName()), SysUser::getNickName, user.getNickName())
.set(SysUser::getPhonenumber, user.getPhonenumber())
.set(SysUser::getEmail, user.getEmail())
.set(SysUser::getSex, user.getSex())
.eq(SysUser::getUserId, user.getUserId()));
} }
/**
*
*
* @param userId ID
* @param avatar
* @return
*/
@Override @Override
public boolean updateUserAvatar(Long userId, Long avatar) { public boolean updateUserAvatar(Long userId, Long avatar) {
return baseMapper.update(null, return false;
new LambdaUpdateWrapper<SysUser>()
.set(SysUser::getAvatar, avatar)
.eq(SysUser::getUserId, userId)) > 0;
} }
/**
*
*
* @param userId ID
* @param password
* @return
*/
@Override @Override
public int resetUserPwd(Long userId, String password) { public int resetUserPwd(Long userId, String password) {
return baseMapper.update(null, return 0;
new LambdaUpdateWrapper<SysUser>()
.set(SysUser::getPassword, password)
.eq(SysUser::getUserId, userId));
} }
/**
*
*
* @param user
* @param clear
*/
private void insertUserRole(SysUserBo user, boolean clear) {
this.insertUserRole(user.getUserId(), user.getRoleIds(), clear);
}
/**
*
*
* @param user
* @param clear
*/
private void insertUserPost(SysUserBo user, boolean clear) {
Long[] posts = user.getPostIds();
if (ArrayUtil.isNotEmpty(posts)) {
if (clear) {
// 删除用户与岗位关联
userPostMapper.delete(new LambdaQueryWrapper<SysUserPost>().eq(SysUserPost::getUserId, user.getUserId()));
}
// 新增用户与岗位管理
List<SysUserPost> list = StreamUtils.toList(List.of(posts), postId -> {
SysUserPost up = new SysUserPost();
up.setUserId(user.getUserId());
up.setPostId(postId);
return up;
});
userPostMapper.insertBatch(list);
}
}
/**
*
*
* @param userId ID
* @param roleIds
* @param clear
*/
private void insertUserRole(Long userId, Long[] roleIds, boolean clear) {
if (ArrayUtil.isNotEmpty(roleIds)) {
// 判断是否具有此角色的操作权限
List<SysRoleVo> roles = roleMapper.selectRoleList(new LambdaQueryWrapper<>());
if (CollUtil.isEmpty(roles)) {
throw new BizException("没有权限访问角色的数据");
}
List<Long> roleList = StreamUtils.toList(roles, SysRoleVo::getRoleId);
if (!LoginHelper.isSuperAdmin(userId)) {
roleList.remove(UserConstants.SUPER_ADMIN_ID);
}
List<Long> canDoRoleList = StreamUtils.filter(List.of(roleIds), roleList::contains);
if (CollUtil.isEmpty(canDoRoleList)) {
throw new BizException("没有权限访问角色的数据");
}
if (clear) {
// 删除用户与角色关联
userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getUserId, userId));
}
// 新增用户与角色管理
List<SysUserRole> list = StreamUtils.toList(canDoRoleList, roleId -> {
SysUserRole ur = new SysUserRole();
ur.setUserId(userId);
ur.setRoleId(roleId);
return ur;
});
userRoleMapper.insertBatch(list);
}
}
/**
* ID
*
* @param userId ID
* @return
*/
@Override @Override
@Transactional(rollbackFor = Exception.class)
public int deleteUserById(Long userId) { public int deleteUserById(Long userId) {
// 删除用户与角色关联 return 0;
userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getUserId, userId));
// 删除用户与岗位表
userPostMapper.delete(new LambdaQueryWrapper<SysUserPost>().eq(SysUserPost::getUserId, userId));
// 防止更新失败导致的数据删除
int flag = baseMapper.deleteById(userId);
if (flag < 1) {
throw new BizException("删除用户失败!");
}
return flag;
} }
/**
*
*
* @param userIds ID
* @return
*/
@Override @Override
@Transactional(rollbackFor = Exception.class)
public int deleteUserByIds(Long[] userIds) { public int deleteUserByIds(Long[] userIds) {
for (Long userId : userIds) { return 0;
checkUserAllowed(userId);
checkUserDataScope(userId);
}
List<Long> ids = List.of(userIds);
// 删除用户与角色关联
userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>().in(SysUserRole::getUserId, ids));
// 删除用户与岗位表
userPostMapper.delete(new LambdaQueryWrapper<SysUserPost>().in(SysUserPost::getUserId, ids));
// 防止更新失败导致的数据删除
int flag = baseMapper.deleteBatchIds(ids);
if (flag < 1) {
throw new BizException("删除用户失败!");
}
return flag;
}
@Cacheable(cacheNames = CacheNames.SYS_USER_NAME, key = "#userId")
@Override
public String selectUserNameById(Long userId) {
SysUser sysUser = baseMapper.selectOne(new LambdaQueryWrapper<SysUser>()
.select(SysUser::getUserName).eq(SysUser::getUserId, userId));
return ObjectUtil.isNull(sysUser) ? null : sysUser.getUserName();
} }
} }