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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ public class DeviceAssignments {
|
||||
* id
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 设备id
|
||||
|
@ -108,7 +108,7 @@ public class APPUser extends BaseEntity implements Serializable {
|
||||
*/
|
||||
@ApiModelProperty(value = "是否为admin账号", hidden = true)
|
||||
@TableField(value = "is_admin")
|
||||
private Byte admin;
|
||||
private Byte admin = 0;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Boolean isAdmin = false;
|
||||
|
@ -49,6 +49,9 @@ public class DeviceQueryCriteria {
|
||||
private Long customerId;
|
||||
private Set<Long> customerIds;
|
||||
|
||||
@ApiModelProperty(value = "当前所有者")
|
||||
private Long currentOwnerId;
|
||||
|
||||
@ApiModelProperty(value = "租户ID")
|
||||
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.service.DeviceAssignmentsService;
|
||||
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.utils.NanoId;
|
||||
import com.fuyuanshen.utils.*;
|
||||
@ -34,8 +35,6 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@ -71,7 +70,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
private final APPDeviceMapper appDeviceMapper;
|
||||
private final DeviceTypeGrantsMapper deviceTypeGrantsMapper;
|
||||
private final DeviceAssignmentsService deviceAssignmentsService;
|
||||
|
||||
private final DeviceTypeGrantsService deviceTypeGrantsService;
|
||||
|
||||
@Autowired
|
||||
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)) {
|
||||
criteria.setTenantId(onlineuser.getTenantId());
|
||||
// criteria.setTenantId(onlineuser.getTenantId());
|
||||
criteria.setCurrentOwnerId(onlineuser.getId());
|
||||
}
|
||||
|
||||
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<DeviceTypeGrants> deviceTypeGrants = new ArrayList<>();
|
||||
List<Device> devices = new ArrayList<>();
|
||||
customerVo.getDeviceIds().forEach(deviceId -> {
|
||||
|
||||
// 阻止重复分配
|
||||
@ -265,79 +267,42 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
throw new BadRequestException("设备 " + device.getDeviceName() + " 已被分配给客户 " + device.getCustomerName());
|
||||
}
|
||||
|
||||
// 自定义16位id
|
||||
Long generatedId = NanoId.generate(16);
|
||||
|
||||
// -- 记录分配历史
|
||||
DeviceAssignments deviceAssignments = new DeviceAssignments();
|
||||
deviceAssignments.setId(generatedId);
|
||||
deviceAssignments.setDeviceId(deviceId);
|
||||
deviceAssignments.setFromCustomerId(currentUser.getId());
|
||||
deviceAssignments.setToCustomerId(customerVo.getCustomerId());
|
||||
deviceAssignments.setAssignedAt(new Date());
|
||||
deviceAssignments.setDeviceTypeGranted(DeviceAuthorizationStatus.AUTHORIZED.getValue());
|
||||
assignments.add(deviceAssignments);
|
||||
|
||||
// -- 授权设备类型给客户
|
||||
// QueryWrapper<DeviceTypeGrants> deviceTypeGrantsQueryWrapper = new QueryWrapper<>();
|
||||
// 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);
|
||||
|
||||
// -- 更新设备所有者
|
||||
device.setCurrentOwnerId(customerVo.getCustomerId());
|
||||
devices.add( device);
|
||||
});
|
||||
|
||||
deviceAssignmentsService.saveBatch(assignments);
|
||||
|
||||
// -- 授权设备类型给客户
|
||||
QueryWrapper<DeviceTypeGrants> deviceTypeGrantsQueryWrapper = new QueryWrapper<>();
|
||||
deviceTypeGrantsMapper.selectCount(deviceTypeGrantsQueryWrapper);
|
||||
|
||||
User user = userService.findById(customerVo.getCustomerId());
|
||||
List<Device> devices = deviceMapper.selectBatchIds(customerVo.getDeviceIds());
|
||||
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
|
||||
for (Device device : devices) {
|
||||
device.setCustomerId(user.getId());
|
||||
device.setCustomerName(user.getNickName());
|
||||
device.setUpdateTime(timestamp);
|
||||
}
|
||||
deviceTypeGrantsService.saveBatch(deviceTypeGrants);
|
||||
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,25 +21,29 @@
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
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 id="device_Column_List">
|
||||
d.id,
|
||||
d.device_type, d.customer_id, d.device_name, d.device_pic, d.device_mac,
|
||||
d
|
||||
.
|
||||
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.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
|
||||
</sql>
|
||||
|
||||
<!-- 分页查询设备 -->
|
||||
<select id="findAll" resultType="com.fuyuanshen.modules.system.domain.Device">
|
||||
select
|
||||
<include refid="device_Column_List" />,
|
||||
<include refid="device_Column_List"/>,
|
||||
t.type_name as typeName
|
||||
from device d
|
||||
left join device_type t
|
||||
on d.device_type = t.id
|
||||
left join device_type t on d.device_type = t.id
|
||||
left join device_assignments da on d.current_owner_id = da.from_customer_id
|
||||
<where>
|
||||
<!-- 时间范围等其他条件保持原样 -->
|
||||
<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]}
|
||||
</if>
|
||||
|
||||
<if test="criteria.tenantId != null">
|
||||
AND tenant_id = #{criteria.tenantId}
|
||||
<if test="criteria.currentOwnerId != null">
|
||||
AND (current_owner_id = #{criteria.currentOwnerId} OR da.from_customer_id = #{criteria.currentOwnerId})
|
||||
</if>
|
||||
|
||||
|
||||
@ -76,6 +80,8 @@
|
||||
<!-- <if test="criteria.customerId == null"> -->
|
||||
<!-- AND tenant_id = #{criteria.tenantId} -->
|
||||
<!-- </if> -->
|
||||
|
||||
|
||||
</where>
|
||||
|
||||
order by d.id desc
|
||||
|
@ -52,7 +52,7 @@
|
||||
and dt.type_name like concat('%', TRIM(#{criteria.typeName}), '%')
|
||||
</if>
|
||||
<if test="criteria.customerId != null">
|
||||
and dt.customer_id = #{criteria.customerId}
|
||||
and dg.customer_id = #{criteria.customerId}
|
||||
</if>
|
||||
<if test="criteria.tenantId != null">
|
||||
and dt.tenant_id = #{criteria.tenantId}
|
||||
|
@ -60,9 +60,7 @@
|
||||
</sql>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
u1
|
||||
.
|
||||
user_id
|
||||
u1.user_id
|
||||
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.gender as user_gender, u1.avatar_name as user_avatar_name, u1.avatar_path as user_avatar_path,
|
||||
@ -73,16 +71,12 @@
|
||||
</sql>
|
||||
|
||||
<sql id="Job_Column_List">
|
||||
j
|
||||
.
|
||||
job_id
|
||||
j . job_id
|
||||
as job_id, j.name as job_name
|
||||
</sql>
|
||||
|
||||
<sql id="Role_Column_List">
|
||||
r
|
||||
.
|
||||
role_id
|
||||
r . role_id
|
||||
as role_id, r.name as role_name, r.level as role_level, r.data_scope as role_data_scope
|
||||
</sql>
|
||||
|
||||
|
Reference in New Issue
Block a user