mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
完善设备管理
This commit is contained in:
@@ -3,6 +3,7 @@ package cn.lihongjie.coal.device.service;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.common.Ctx;
|
||||
import cn.lihongjie.coal.device.dto.CreateDeviceDto;
|
||||
import cn.lihongjie.coal.device.dto.DeviceDto;
|
||||
import cn.lihongjie.coal.device.dto.UpdateDeviceDto;
|
||||
@@ -11,13 +12,18 @@ import cn.lihongjie.coal.device.mapper.DeviceMapper;
|
||||
import cn.lihongjie.coal.device.repository.DeviceRepository;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
|
||||
import jakarta.persistence.criteria.Join;
|
||||
import jakarta.persistence.criteria.JoinType;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -69,9 +75,31 @@ public class DeviceService extends BaseService<DeviceEntity, DeviceRepository> {
|
||||
}
|
||||
|
||||
public Page<DeviceDto> list(CommonQuery query) {
|
||||
|
||||
Specification specification = query.specification(conversionService);
|
||||
|
||||
if (!BooleanUtils.isTrue(Ctx.currentUser().getOrgAdmin())) {
|
||||
|
||||
//
|
||||
specification =
|
||||
specification.and(
|
||||
(root, query1, cb) -> {
|
||||
query1.distinct(true);
|
||||
Join category = root.join("category", JoinType.LEFT);
|
||||
Join caUsers = category.join("users", JoinType.LEFT);
|
||||
return cb.or(
|
||||
// 没有绑定类目的设备
|
||||
cb.isNull(category.get("id")),
|
||||
// 类目没有配置管理员的设备
|
||||
cb.isNull(caUsers.get("id")),
|
||||
// 当前用户是类目管理员的设备
|
||||
cb.equal(caUsers.get("id"), Ctx.currentUser().getId()));
|
||||
});
|
||||
}
|
||||
|
||||
Page<DeviceEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
specification,
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
|
||||
@@ -4,7 +4,10 @@ import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class CreateDeviceCategoryDto extends OrgCommonDto {
|
||||
private String parent;
|
||||
private List<String> users;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.lihongjie.coal.deviceCategory.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.base.dto.SimpleDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -9,6 +10,7 @@ import java.util.List;
|
||||
@Data
|
||||
public class DeviceCategoryDto extends OrgCommonDto {
|
||||
private String parent;
|
||||
private List<SimpleDto> user;
|
||||
private List<String> allDeviceIds;
|
||||
|
||||
private List<String> childrenDeviceIds;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.lihongjie.coal.deviceCategory.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.base.dto.SimpleDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -9,6 +10,7 @@ import java.util.List;
|
||||
@Data
|
||||
public class DeviceCategoryTreeDto extends OrgCommonDto {
|
||||
|
||||
private List<SimpleDto> user;
|
||||
private List<String> allDeviceIds;
|
||||
|
||||
private List<String> childrenDeviceIds;
|
||||
|
||||
@@ -4,7 +4,10 @@ import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class UpdateDeviceCategoryDto extends OrgCommonDto {
|
||||
private String parent;
|
||||
private List<String> users;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.lihongjie.coal.deviceCategory.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
import cn.lihongjie.coal.user.entity.UserEntity;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Entity;
|
||||
@@ -16,6 +17,8 @@ import java.util.List;
|
||||
public class DeviceCategoryEntity extends OrgCommonEntity {
|
||||
|
||||
|
||||
@OneToMany
|
||||
private List<UserEntity> users;
|
||||
|
||||
|
||||
@ManyToOne private DeviceCategoryEntity parent;
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -77,9 +78,24 @@ public class DeviceCategoryService
|
||||
}
|
||||
|
||||
public Page<DeviceCategoryDto> list(CommonQuery query) {
|
||||
Specification specification = query.specification(conversionService);
|
||||
|
||||
// if (!BooleanUtils.isTrue(Ctx.currentUser().getOrgAdmin())) {
|
||||
//
|
||||
// //
|
||||
// specification =
|
||||
// specification.and(
|
||||
// (root, query1, cb) -> {
|
||||
// Join users = root.join("users", JoinType.LEFT);
|
||||
// return cb.or(
|
||||
// cb.isNull(users.get("id")),
|
||||
// cb.equal(users.get("id"), Ctx.currentUser().getId()));
|
||||
// });
|
||||
// }
|
||||
|
||||
Page<DeviceCategoryEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
specification,
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
@@ -95,13 +111,12 @@ public class DeviceCategoryService
|
||||
this.repository.findAll(
|
||||
(root, query, criteriaBuilder) ->
|
||||
criteriaBuilder.isNull(root.get("parent")));
|
||||
List<DeviceCategoryTreeDto> collect = roots.stream()
|
||||
.map(de -> this.mapper.toTreeDto(de))
|
||||
.collect(Collectors.toList());
|
||||
List<DeviceCategoryTreeDto> collect =
|
||||
roots.stream()
|
||||
.map(de -> this.mapper.toTreeDto(de))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
return addDeviceIds(
|
||||
collect);
|
||||
return addDeviceIds(collect);
|
||||
} else {
|
||||
Page<DeviceCategoryEntity> page =
|
||||
repository.findAll(
|
||||
@@ -118,9 +133,10 @@ public class DeviceCategoryService
|
||||
true);
|
||||
|
||||
List<DeviceCategoryTreeDto> selfAndParent =
|
||||
addDeviceIds(this.findAllByIds(selfAndParentIds).stream()
|
||||
.map(x -> (this.mapper.toTreeDtoExcludeChildren(x)))
|
||||
.collect(Collectors.toList()));
|
||||
addDeviceIds(
|
||||
this.findAllByIds(selfAndParentIds).stream()
|
||||
.map(x -> (this.mapper.toTreeDtoExcludeChildren(x)))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
return (StreamSupport.stream(
|
||||
TreeUtils.buildTreeFromList(
|
||||
@@ -142,12 +158,11 @@ public class DeviceCategoryService
|
||||
|
||||
private List<DeviceCategoryTreeDto> addDeviceIds(List<DeviceCategoryTreeDto> collect) {
|
||||
|
||||
|
||||
var dtos = TreeUtils.treeToList(collect);
|
||||
var dtos = TreeUtils.treeToList(collect);
|
||||
|
||||
var maps = repository.deviceIds(ReflectUtils.idList(dtos));
|
||||
|
||||
JpaUtils.mergeMapToPojo (dtos, maps, conversionService);
|
||||
JpaUtils.mergeMapToPojo(dtos, maps, conversionService);
|
||||
return collect;
|
||||
}
|
||||
|
||||
|
||||
@@ -195,6 +195,7 @@ public class WeightDeviceDataService
|
||||
+ groupSql
|
||||
+ ",\n"
|
||||
+ fieldSql
|
||||
+ ", array_agg(d.id) as ids\n"
|
||||
+ "\n from t_weight_device_data d\n"
|
||||
+ " "
|
||||
+ where
|
||||
|
||||
Reference in New Issue
Block a user