Merge remote-tracking branch 'origin/main'
This commit is contained in:
@ -39,4 +39,5 @@ public class AuthorityConfig {
|
|||||||
// 判断当前用户的所有权限是否包含接口上定义的权限
|
// 判断当前用户的所有权限是否包含接口上定义的权限
|
||||||
return elPermissions.contains("admin") || Arrays.stream(permissions).anyMatch(elPermissions::contains);
|
return elPermissions.contains("admin") || Arrays.stream(permissions).anyMatch(elPermissions::contains);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ public class DeviceAssignments {
|
|||||||
* id
|
* id
|
||||||
*/
|
*/
|
||||||
@TableId(type = IdType.AUTO)
|
@TableId(type = IdType.AUTO)
|
||||||
private Integer id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备id
|
* 设备id
|
||||||
|
@ -108,7 +108,7 @@ public class APPUser extends BaseEntity implements Serializable {
|
|||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "是否为admin账号", hidden = true)
|
@ApiModelProperty(value = "是否为admin账号", hidden = true)
|
||||||
@TableField(value = "is_admin")
|
@TableField(value = "is_admin")
|
||||||
private Byte admin;
|
private Byte admin = 0;
|
||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private Boolean isAdmin = false;
|
private Boolean isAdmin = false;
|
||||||
|
@ -49,6 +49,9 @@ public class DeviceQueryCriteria {
|
|||||||
private Long customerId;
|
private Long customerId;
|
||||||
private Set<Long> customerIds;
|
private Set<Long> customerIds;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "当前所有者")
|
||||||
|
private Long currentOwnerId;
|
||||||
|
|
||||||
@ApiModelProperty(value = "租户ID")
|
@ApiModelProperty(value = "租户ID")
|
||||||
private Long tenantId;
|
private Long tenantId;
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ import com.fuyuanshen.modules.system.mapper.UserMapper;
|
|||||||
import com.fuyuanshen.modules.system.mapper.app.APPDeviceMapper;
|
import com.fuyuanshen.modules.system.mapper.app.APPDeviceMapper;
|
||||||
import com.fuyuanshen.modules.system.service.DeviceAssignmentsService;
|
import com.fuyuanshen.modules.system.service.DeviceAssignmentsService;
|
||||||
import com.fuyuanshen.modules.system.service.DeviceService;
|
import com.fuyuanshen.modules.system.service.DeviceService;
|
||||||
|
import com.fuyuanshen.modules.system.service.DeviceTypeGrantsService;
|
||||||
import com.fuyuanshen.modules.system.service.UserService;
|
import com.fuyuanshen.modules.system.service.UserService;
|
||||||
import com.fuyuanshen.modules.utils.NanoId;
|
import com.fuyuanshen.modules.utils.NanoId;
|
||||||
import com.fuyuanshen.utils.*;
|
import com.fuyuanshen.utils.*;
|
||||||
@ -34,8 +35,6 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.security.core.Authentication;
|
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@ -71,7 +70,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|||||||
private final APPDeviceMapper appDeviceMapper;
|
private final APPDeviceMapper appDeviceMapper;
|
||||||
private final DeviceTypeGrantsMapper deviceTypeGrantsMapper;
|
private final DeviceTypeGrantsMapper deviceTypeGrantsMapper;
|
||||||
private final DeviceAssignmentsService deviceAssignmentsService;
|
private final DeviceAssignmentsService deviceAssignmentsService;
|
||||||
|
private final DeviceTypeGrantsService deviceTypeGrantsService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
@ -98,7 +97,8 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|||||||
|
|
||||||
// 只能看到自己的创建的设备,以及被分配的设备。
|
// 只能看到自己的创建的设备,以及被分配的设备。
|
||||||
if (onlineuser.getTenantId() != null && !onlineuser.getTenantId().equals(UserConstants.SUPER_ADMIN_ID)) {
|
if (onlineuser.getTenantId() != null && !onlineuser.getTenantId().equals(UserConstants.SUPER_ADMIN_ID)) {
|
||||||
criteria.setTenantId(onlineuser.getTenantId());
|
// criteria.setTenantId(onlineuser.getTenantId());
|
||||||
|
criteria.setCurrentOwnerId(onlineuser.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
IPage<Device> devices = deviceMapper.findAll(criteria, page);
|
IPage<Device> devices = deviceMapper.findAll(criteria, page);
|
||||||
@ -257,6 +257,8 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<DeviceAssignments> assignments = new ArrayList<>();
|
List<DeviceAssignments> assignments = new ArrayList<>();
|
||||||
|
List<DeviceTypeGrants> deviceTypeGrants = new ArrayList<>();
|
||||||
|
List<Device> devices = new ArrayList<>();
|
||||||
customerVo.getDeviceIds().forEach(deviceId -> {
|
customerVo.getDeviceIds().forEach(deviceId -> {
|
||||||
|
|
||||||
// 阻止重复分配
|
// 阻止重复分配
|
||||||
@ -265,79 +267,42 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|||||||
throw new BadRequestException("设备 " + device.getDeviceName() + " 已被分配给客户 " + device.getCustomerName());
|
throw new BadRequestException("设备 " + device.getDeviceName() + " 已被分配给客户 " + device.getCustomerName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 自定义16位id
|
||||||
|
Long generatedId = NanoId.generate(16);
|
||||||
|
|
||||||
// -- 记录分配历史
|
// -- 记录分配历史
|
||||||
DeviceAssignments deviceAssignments = new DeviceAssignments();
|
DeviceAssignments deviceAssignments = new DeviceAssignments();
|
||||||
|
deviceAssignments.setId(generatedId);
|
||||||
deviceAssignments.setDeviceId(deviceId);
|
deviceAssignments.setDeviceId(deviceId);
|
||||||
deviceAssignments.setFromCustomerId(currentUser.getId());
|
deviceAssignments.setFromCustomerId(currentUser.getId());
|
||||||
deviceAssignments.setToCustomerId(customerVo.getCustomerId());
|
deviceAssignments.setToCustomerId(customerVo.getCustomerId());
|
||||||
deviceAssignments.setAssignedAt(new Date());
|
deviceAssignments.setAssignedAt(new Date());
|
||||||
deviceAssignments.setDeviceTypeGranted(DeviceAuthorizationStatus.AUTHORIZED.getValue());
|
deviceAssignments.setDeviceTypeGranted(DeviceAuthorizationStatus.AUTHORIZED.getValue());
|
||||||
assignments.add(deviceAssignments);
|
assignments.add(deviceAssignments);
|
||||||
});
|
|
||||||
deviceAssignmentsService.saveBatch(assignments);
|
|
||||||
|
|
||||||
// -- 授权设备类型给客户
|
// -- 授权设备类型给客户
|
||||||
QueryWrapper<DeviceTypeGrants> deviceTypeGrantsQueryWrapper = new QueryWrapper<>();
|
// QueryWrapper<DeviceTypeGrants> deviceTypeGrantsQueryWrapper = new QueryWrapper<>();
|
||||||
deviceTypeGrantsMapper.selectCount(deviceTypeGrantsQueryWrapper);
|
// Long count = deviceTypeGrantsMapper.selectCount(deviceTypeGrantsQueryWrapper);
|
||||||
|
DeviceTypeGrants deviceTypeGrant = new DeviceTypeGrants();
|
||||||
|
deviceTypeGrant.setGrantedAt(new Date());
|
||||||
|
// 设备类型
|
||||||
|
deviceTypeGrant.setDeviceTypeId(device.getDeviceType());
|
||||||
|
deviceTypeGrant.setAssignmentId(generatedId);
|
||||||
|
// 被授权的客户
|
||||||
|
deviceTypeGrant.setCustomerId(customerVo.getCustomerId());
|
||||||
|
// 授权方客户
|
||||||
|
deviceTypeGrant.setGrantorCustomerId(currentUser.getId());
|
||||||
|
deviceTypeGrants.add(deviceTypeGrant);
|
||||||
|
|
||||||
User user = userService.findById(customerVo.getCustomerId());
|
// -- 更新设备所有者
|
||||||
List<Device> devices = deviceMapper.selectBatchIds(customerVo.getDeviceIds());
|
device.setCurrentOwnerId(customerVo.getCustomerId());
|
||||||
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
|
devices.add( device);
|
||||||
for (Device device : devices) {
|
});
|
||||||
device.setCustomerId(user.getId());
|
|
||||||
device.setCustomerName(user.getNickName());
|
deviceAssignmentsService.saveBatch(assignments);
|
||||||
device.setUpdateTime(timestamp);
|
deviceTypeGrantsService.saveBatch(deviceTypeGrants);
|
||||||
}
|
|
||||||
this.updateBatchById(devices);
|
this.updateBatchById(devices);
|
||||||
|
|
||||||
// 批量更新设备状态
|
|
||||||
for (Device device : devices) {
|
|
||||||
// 获取当前用户的所有祖先用户
|
|
||||||
List<User> ancestorsById = userMapper.findAncestorsById(currentUser.getId());
|
|
||||||
Set<Long> excludedTenantIds = new HashSet<>();
|
|
||||||
if (CollectionUtil.isNotEmpty(ancestorsById)) {
|
|
||||||
// 提取所有需要排除的 tenant_id
|
|
||||||
excludedTenantIds = ancestorsById.stream().map(User::getTenantId).distinct().collect(Collectors.toSet());
|
|
||||||
}
|
|
||||||
excludedTenantIds.add(currentUser.getTenantId());
|
|
||||||
// 构建查询条件:device_mac 相同,并且 tenant_id 不在 excludedTenantIds 列表中
|
|
||||||
Wrapper<Device> wrapper = new QueryWrapper<Device>().eq("device_mac", device.getDeviceMac()).notIn("tenant_id", excludedTenantIds);
|
|
||||||
|
|
||||||
// 构建要更新的数据
|
|
||||||
Device updateDevice = new Device();
|
|
||||||
updateDevice.setDeviceStatus(0);
|
|
||||||
updateDevice.setUpdateTime(new Timestamp(System.currentTimeMillis()));
|
|
||||||
|
|
||||||
// 根据条件批量更新
|
|
||||||
deviceMapper.update(updateDevice, wrapper);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 批量分配
|
|
||||||
Set<DeviceType> deviceTypes = new HashSet<>();
|
|
||||||
for (Device device : devices) {
|
|
||||||
device.setId(null);
|
|
||||||
device.setCustomerName(null);
|
|
||||||
device.setCustomerId(null);
|
|
||||||
device.setTenantId(user.getTenantId());
|
|
||||||
device.setCreateTime(timestamp);
|
|
||||||
device.setCreateBy(currentUser.getUsername());
|
|
||||||
device.setUpdateTime(timestamp);
|
|
||||||
|
|
||||||
// 查询设备类型
|
|
||||||
DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType());
|
|
||||||
// SnowflakeGenerator snowflakeGenerator = new SnowflakeGenerator();
|
|
||||||
Long id = NanoId.generate(16);
|
|
||||||
deviceType.setId(id);
|
|
||||||
deviceType.setCreateTime(timestamp);
|
|
||||||
deviceType.setCreateBy(currentUser.getUsername());
|
|
||||||
deviceType.setCustomerId(customerVo.getCustomerId());
|
|
||||||
deviceTypes.add(deviceType);
|
|
||||||
|
|
||||||
device.setDeviceType(deviceType.getId());
|
|
||||||
}
|
|
||||||
this.saveBatch(devices);
|
|
||||||
deviceTypeService.saveBatch(deviceTypes);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,14 +21,18 @@
|
|||||||
|
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
id
|
id
|
||||||
, device_type, customer_id, device_name, device_pic, device_mac, device_sn, remark, create_by, update_by, create_time, update_time
|
, device_type, customer_id, device_name, device_pic, device_mac, device_sn,
|
||||||
|
remark, create_by, update_by, create_time, update_time
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<sql id="device_Column_List">
|
<sql id="device_Column_List">
|
||||||
d.id,
|
d
|
||||||
d.device_type, d.customer_id, d.device_name, d.device_pic, d.device_mac,
|
.
|
||||||
|
id
|
||||||
|
,d.device_type,
|
||||||
|
d.customer_id, d.device_name, d.device_pic, d.device_mac,
|
||||||
d.device_sn, d.remark, d.create_by, d.update_by, d.create_time, d.update_time,
|
d.device_sn, d.remark, d.create_by, d.update_by, d.create_time, d.update_time,
|
||||||
d.binding_status, d.current_owner_id, d.original_owner_id, d.customer_name,
|
d.binding_status, d.device_status, d.current_owner_id, d.original_owner_id, d.customer_name,
|
||||||
d.device_imei, d.longitude, d.latitude, d.tenant_id
|
d.device_imei, d.longitude, d.latitude, d.tenant_id
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
@ -38,8 +42,8 @@
|
|||||||
<include refid="device_Column_List"/>,
|
<include refid="device_Column_List"/>,
|
||||||
t.type_name as typeName
|
t.type_name as typeName
|
||||||
from device d
|
from device d
|
||||||
left join device_type t
|
left join device_type t on d.device_type = t.id
|
||||||
on d.device_type = t.id
|
left join device_assignments da on d.current_owner_id = da.from_customer_id
|
||||||
<where>
|
<where>
|
||||||
<!-- 时间范围等其他条件保持原样 -->
|
<!-- 时间范围等其他条件保持原样 -->
|
||||||
<if test="criteria.deviceName != null and criteria.deviceName.trim() != ''">
|
<if test="criteria.deviceName != null and criteria.deviceName.trim() != ''">
|
||||||
@ -61,8 +65,8 @@
|
|||||||
and d.create_time between #{criteria.createTime[0]} and #{criteria.createTime[1]}
|
and d.create_time between #{criteria.createTime[0]} and #{criteria.createTime[1]}
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
<if test="criteria.tenantId != null">
|
<if test="criteria.currentOwnerId != null">
|
||||||
AND tenant_id = #{criteria.tenantId}
|
AND (current_owner_id = #{criteria.currentOwnerId} OR da.from_customer_id = #{criteria.currentOwnerId})
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
|
|
||||||
@ -76,6 +80,8 @@
|
|||||||
<!-- <if test="criteria.customerId == null"> -->
|
<!-- <if test="criteria.customerId == null"> -->
|
||||||
<!-- AND tenant_id = #{criteria.tenantId} -->
|
<!-- AND tenant_id = #{criteria.tenantId} -->
|
||||||
<!-- </if> -->
|
<!-- </if> -->
|
||||||
|
|
||||||
|
|
||||||
</where>
|
</where>
|
||||||
|
|
||||||
order by d.id desc
|
order by d.id desc
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
and dt.type_name like concat('%', TRIM(#{criteria.typeName}), '%')
|
and dt.type_name like concat('%', TRIM(#{criteria.typeName}), '%')
|
||||||
</if>
|
</if>
|
||||||
<if test="criteria.customerId != null">
|
<if test="criteria.customerId != null">
|
||||||
and dt.customer_id = #{criteria.customerId}
|
and dg.customer_id = #{criteria.customerId}
|
||||||
</if>
|
</if>
|
||||||
<if test="criteria.tenantId != null">
|
<if test="criteria.tenantId != null">
|
||||||
and dt.tenant_id = #{criteria.tenantId}
|
and dt.tenant_id = #{criteria.tenantId}
|
||||||
|
@ -60,9 +60,7 @@
|
|||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
u1
|
u1.user_id
|
||||||
.
|
|
||||||
user_id
|
|
||||||
as user_user_id, u1.dept_id as user_dept_id, u1.username as user_username,
|
as user_user_id, u1.dept_id as user_dept_id, u1.username as user_username,
|
||||||
u1.nick_name as user_nick_name, u1.email as user_email, u1.phone as user_phone,
|
u1.nick_name as user_nick_name, u1.email as user_email, u1.phone as user_phone,
|
||||||
u1.gender as user_gender, u1.avatar_name as user_avatar_name, u1.avatar_path as user_avatar_path,
|
u1.gender as user_gender, u1.avatar_name as user_avatar_name, u1.avatar_path as user_avatar_path,
|
||||||
@ -73,16 +71,12 @@
|
|||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<sql id="Job_Column_List">
|
<sql id="Job_Column_List">
|
||||||
j
|
j . job_id
|
||||||
.
|
|
||||||
job_id
|
|
||||||
as job_id, j.name as job_name
|
as job_id, j.name as job_name
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<sql id="Role_Column_List">
|
<sql id="Role_Column_List">
|
||||||
r
|
r . role_id
|
||||||
.
|
|
||||||
role_id
|
|
||||||
as role_id, r.name as role_name, r.level as role_level, r.data_scope as role_data_scope
|
as role_id, r.name as role_name, r.level as role_level, r.data_scope as role_data_scope
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user