forked from dyf/fys-Multi-tenant
Merge branch 'dyf-device'
This commit is contained in:
@ -92,7 +92,7 @@ public class Customer extends TenantEntity {
|
||||
/**
|
||||
* 帐号状态(0正常 1停用)
|
||||
*/
|
||||
private String status;
|
||||
private String status = "0";
|
||||
|
||||
/**
|
||||
* 删除标志(0代表存在 1代表删除)
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.fuyuanshen.customer.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fuyuanshen.common.core.domain.model.LoginUser;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.customer.constant.ArrayConstants;
|
||||
@ -92,6 +94,7 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
||||
}
|
||||
customer.setUserLevel((byte) (loginUser.getUserLevel() + 1));
|
||||
customer.setPid(loginUser.getUserId());
|
||||
customer.setStatus("0");
|
||||
|
||||
save(customer);
|
||||
|
||||
@ -106,18 +109,40 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
||||
|
||||
/**
|
||||
* 修改客户
|
||||
* 不是因为寂寞才想你,只是因为想你才寂寞。
|
||||
*
|
||||
* @param resources /
|
||||
* @param customer /
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateCustomer(Customer resources) throws Exception {
|
||||
if (resources.getEnabled()) {
|
||||
resources.setStatus("0");
|
||||
} else {
|
||||
resources.setStatus("1");
|
||||
public void updateCustomer(Customer customer) throws Exception {
|
||||
|
||||
UserQueryCriteria userQueryCriteria = new UserQueryCriteria();
|
||||
if (StringUtils.isNotEmpty(customer.getUserName())) {
|
||||
userQueryCriteria.setCustomerName(customer.getUserName());
|
||||
List<Customer> customers = customerMapper.queryCustomers(userQueryCriteria);
|
||||
if (!customers.isEmpty()) {
|
||||
throw new BadRequestException("用户名已存在!!!");
|
||||
}
|
||||
saveOrUpdate(resources);
|
||||
}
|
||||
|
||||
if (customer.getEnabled()) {
|
||||
customer.setStatus("0");
|
||||
} else {
|
||||
// 强制下线
|
||||
// StpUtil.logout(customer.getCustomerId());
|
||||
// StpUtil.kickout(customer.getCustomerId());
|
||||
customer.setStatus("1");
|
||||
// 检查目标用户是否有有效的登录状态
|
||||
if (StpUtil.isLogin(customer.getCustomerId())) {
|
||||
// 用户已登录,可以执行踢出操作
|
||||
StpUtil.kickout(customer.getCustomerId());
|
||||
} else {
|
||||
// 用户未登录,无法踢出
|
||||
System.out.println("目标用户未登录,无法执行踢出操作");
|
||||
}
|
||||
}
|
||||
saveOrUpdate(customer);
|
||||
}
|
||||
|
||||
|
||||
|
@ -105,7 +105,6 @@ public class Device extends TenantEntity {
|
||||
@Schema(name = "设备状态")
|
||||
private Integer deviceStatus;
|
||||
|
||||
|
||||
/**
|
||||
* 绑定状态
|
||||
* 0 未绑定
|
||||
@ -127,4 +126,17 @@ public class Device extends TenantEntity {
|
||||
private Date bindingTime;
|
||||
|
||||
private String sendMsg;
|
||||
|
||||
/**
|
||||
* 发布主题(格式:A/{device_id})
|
||||
* pub_topic
|
||||
*/
|
||||
private String pubTopic;
|
||||
|
||||
/**
|
||||
* 订阅主题(格式:B/{device_id})
|
||||
* sub_topic
|
||||
*/
|
||||
private String subTopic;
|
||||
|
||||
}
|
||||
|
@ -186,6 +186,10 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
device.setCreateByName(loginUser.getNickname());
|
||||
device.setTypeName(deviceTypes.getTypeName());
|
||||
device.setDeviceType(deviceTypes.getId());
|
||||
if (device.getDeviceImei() != null) {
|
||||
device.setPubTopic("A/" + device.getDeviceImei());
|
||||
device.setSubTopic("B/" + device.getDeviceImei());
|
||||
}
|
||||
|
||||
deviceMapper.insert(device);
|
||||
|
||||
@ -293,14 +297,18 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
|
||||
for (Long id : ids) {
|
||||
DeviceAssignments deviceAssignment = deviceAssignmentsMapper.selectById(id);
|
||||
Device deviceType = deviceMapper.selectById(deviceAssignment.getDeviceId());
|
||||
Device device = deviceMapper.selectById(deviceAssignment.getDeviceId());
|
||||
|
||||
if (StringUtils.isNotEmpty(deviceAssignment.getAssigneeName())) {
|
||||
throw new BadRequestException(deviceType.getDeviceName() + ":设备已分配,请先解绑设备!!!");
|
||||
throw new BadRequestException(device.getDeviceName() + ":设备已分配,请先解绑设备!!!");
|
||||
}
|
||||
|
||||
if (device.getBindingStatus().equals(1)){
|
||||
throw new BadRequestException(device.getDeviceName() + ":设备已绑定,请先解绑设备!!!");
|
||||
}
|
||||
|
||||
// 接收者
|
||||
if (Objects.equals(deviceAssignment.getAssigneeId(), deviceType.getOriginalOwnerId())) {
|
||||
if (Objects.equals(deviceAssignment.getAssigneeId(), device.getOriginalOwnerId())) {
|
||||
invalidIds.add(deviceAssignment.getDeviceId());
|
||||
}
|
||||
|
||||
|
@ -38,13 +38,19 @@
|
||||
|
||||
<!-- 分页查询设备 -->
|
||||
<select id="findAll" resultType="com.fuyuanshen.equipment.domain.Device">
|
||||
select
|
||||
SELECT *
|
||||
FROM (
|
||||
SELECT
|
||||
da.id AS id, d.device_name, d.bluetooth_name,
|
||||
d.device_pic, d.device_mac, d.device_sn, d.update_by,d.device_imei,
|
||||
d.update_time, dg.id AS device_type, d.remark, d.binding_status,t.type_name AS typeName,
|
||||
da.assignee_id AS customerId, da.assignee_name AS customerName, da.active AS deviceStatus,
|
||||
da.create_time AS create_time , da.assigner_name AS createByName , da.id AS assignId
|
||||
from device d
|
||||
d.pub_topic, d.sub_topic, d.device_pic,
|
||||
d.device_mac, d.device_sn, d.update_by,
|
||||
d.device_imei, d.update_time, dg.id AS device_type,
|
||||
d.remark, d.binding_status, t.type_name AS typeName,
|
||||
da.assignee_id AS customerId, da.assignee_name AS customerName,
|
||||
da.active AS deviceStatus, da.create_time AS create_time,
|
||||
da.assigner_name AS createByName, da.id AS assignId,
|
||||
ROW_NUMBER() OVER (PARTITION BY d.id ORDER BY da.create_time DESC) AS rn
|
||||
FROM device d
|
||||
LEFT JOIN device_type t ON d.device_type = t.id
|
||||
LEFT JOIN device_type_grants dg ON dg.device_type_id = t.id
|
||||
LEFT JOIN device_assignments da ON da.device_id = d.id
|
||||
@ -71,9 +77,12 @@
|
||||
AND da.assignee_id = #{criteria.currentOwnerId}
|
||||
AND dg.customer_id = #{criteria.currentOwnerId}
|
||||
</where>
|
||||
ORDER BY da.create_time DESC
|
||||
) AS ranked
|
||||
WHERE rn = 1
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
|
||||
<select id="findAllDevices" resultType="com.fuyuanshen.equipment.domain.Device">
|
||||
select
|
||||
d.id, d.customer_id, d.device_name,d.bluetooth_name,
|
||||
|
Reference in New Issue
Block a user