APP用户设备绑定
This commit is contained in:
@ -50,6 +50,9 @@ public class APPDevice extends BaseEntity implements Serializable {
|
|||||||
@ApiModelProperty(value = "设备MAC")
|
@ApiModelProperty(value = "设备MAC")
|
||||||
private String deviceMac;
|
private String deviceMac;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "设备IMEI")
|
||||||
|
private String deviceImei;
|
||||||
|
|
||||||
@ApiModelProperty(value = "设备SN")
|
@ApiModelProperty(value = "设备SN")
|
||||||
private String deviceSn;
|
private String deviceSn;
|
||||||
|
|
||||||
|
@ -58,4 +58,7 @@ public class DeviceQueryCriteria {
|
|||||||
@ApiModelProperty(value = "租户ID")
|
@ApiModelProperty(value = "租户ID")
|
||||||
private Long tenantId;
|
private Long tenantId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "通讯方式", example = "0:4G;1:蓝牙")
|
||||||
|
private Integer communicationMode;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
package com.fuyuanshen.modules.system.enums;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通讯方式枚举
|
||||||
|
*
|
||||||
|
* @author: 默苍璃
|
||||||
|
* @date: 2025-06-2414:11
|
||||||
|
*/
|
||||||
|
public enum CommunicationModeEnum {
|
||||||
|
|
||||||
|
FOUR_G(0, "4G"),
|
||||||
|
BLUETOOTH(1, "蓝牙");
|
||||||
|
|
||||||
|
private final int value;
|
||||||
|
private final String label;
|
||||||
|
|
||||||
|
CommunicationModeEnum(int value, String label) {
|
||||||
|
this.value = value;
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
public int getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据值获取标签
|
||||||
|
*/
|
||||||
|
public static String getLabelByValue(int value) {
|
||||||
|
for (CommunicationModeEnum mode : values()) {
|
||||||
|
if (mode.getValue() == value) {
|
||||||
|
return mode.getLabel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -67,10 +67,10 @@ public class APPDeviceController {
|
|||||||
private final APPDeviceService appDeviceService;
|
private final APPDeviceService appDeviceService;
|
||||||
|
|
||||||
|
|
||||||
@GetMapping(value = "/bind")
|
@PostMapping(value = "/bind")
|
||||||
@ApiOperation("APP用户设备绑定")
|
@ApiOperation("APP用户设备绑定")
|
||||||
public ResponseVO<String> appBindDevice(@ApiParam("设备MAC地址") @RequestParam String mac) {
|
public ResponseVO<String> appBindDevice( @RequestBody DeviceQueryCriteria criteria) {
|
||||||
appDeviceService.appBindDevice(mac);
|
appDeviceService.appBindDevice(criteria);
|
||||||
return ResponseVO.success("绑定成功!");
|
return ResponseVO.success("绑定成功!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,9 +25,9 @@ public interface APPDeviceService extends IService<APPDevice> {
|
|||||||
/**
|
/**
|
||||||
* APP/小程序用户设备绑定
|
* APP/小程序用户设备绑定
|
||||||
*
|
*
|
||||||
* @param mac
|
* @param criteria
|
||||||
*/
|
*/
|
||||||
void appBindDevice(String mac);
|
void appBindDevice(DeviceQueryCriteria criteria);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,6 +14,7 @@ import com.fuyuanshen.modules.system.domain.app.APPDeviceType;
|
|||||||
import com.fuyuanshen.modules.system.domain.dto.DeviceQueryCriteria;
|
import com.fuyuanshen.modules.system.domain.dto.DeviceQueryCriteria;
|
||||||
import com.fuyuanshen.modules.system.domain.dto.app.APPUnbindDTO;
|
import com.fuyuanshen.modules.system.domain.dto.app.APPUnbindDTO;
|
||||||
import com.fuyuanshen.modules.system.enums.BindingStatusEnum;
|
import com.fuyuanshen.modules.system.enums.BindingStatusEnum;
|
||||||
|
import com.fuyuanshen.modules.system.enums.CommunicationModeEnum;
|
||||||
import com.fuyuanshen.modules.system.enums.UserType;
|
import com.fuyuanshen.modules.system.enums.UserType;
|
||||||
import com.fuyuanshen.modules.system.mapper.DeviceMapper;
|
import com.fuyuanshen.modules.system.mapper.DeviceMapper;
|
||||||
import com.fuyuanshen.modules.system.mapper.DeviceTypeMapper;
|
import com.fuyuanshen.modules.system.mapper.DeviceTypeMapper;
|
||||||
@ -26,6 +27,9 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -48,19 +52,36 @@ public class APPDeviceServiceImpl extends ServiceImpl<APPDeviceMapper, APPDevice
|
|||||||
/**
|
/**
|
||||||
* APP/小程序用户设备绑定
|
* APP/小程序用户设备绑定
|
||||||
*
|
*
|
||||||
* @param mac
|
* @param criteria
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void appBindDevice(String mac) {
|
public void appBindDevice(DeviceQueryCriteria criteria) {
|
||||||
List<Device> devices = deviceMapper.selectList(new QueryWrapper<Device>().eq("device_mac", mac));
|
|
||||||
if (CollectionUtil.isEmpty(devices)) {
|
List<Device> devices = new ArrayList<>();
|
||||||
throw new BadRequestException("请先将设备入库!!!");
|
|
||||||
|
if (criteria.getCommunicationMode().equals(CommunicationModeEnum.BLUETOOTH.getValue())) {
|
||||||
|
devices = deviceMapper.selectList(new QueryWrapper<Device>().eq("device_mac", criteria.getDeviceMac()));
|
||||||
|
if (CollectionUtil.isEmpty(devices)) {
|
||||||
|
throw new BadRequestException("请先将设备入库!!!");
|
||||||
|
}
|
||||||
|
List<APPDevice> appDevices = appDeviceMapper.selectList(new QueryWrapper<APPDevice>()
|
||||||
|
.eq("device_mac", criteria.getDeviceMac()).eq("binding_type", UserType.APP.getValue()));
|
||||||
|
if (CollectionUtil.isNotEmpty(appDevices)) {
|
||||||
|
throw new BadRequestException("该设备已绑定!!!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
List<APPDevice> appDevices = appDeviceMapper.selectList(new QueryWrapper<APPDevice>()
|
|
||||||
.eq("device_mac", mac).eq("binding_type", UserType.APP.getValue()));
|
if (criteria.getCommunicationMode().equals(CommunicationModeEnum.FOUR_G.getValue())) {
|
||||||
if (CollectionUtil.isNotEmpty(appDevices)) {
|
devices = deviceMapper.selectList(new QueryWrapper<Device>().eq("device_imei", criteria.getDeviceImei()));
|
||||||
throw new BadRequestException("该设备已绑定!!!");
|
if (CollectionUtil.isEmpty(devices)) {
|
||||||
|
throw new BadRequestException("请先将设备入库!!!");
|
||||||
|
}
|
||||||
|
List<APPDevice> appDevices = appDeviceMapper.selectList(new QueryWrapper<APPDevice>()
|
||||||
|
.eq("device_imei", criteria.getDeviceImei()).eq("binding_type", UserType.APP.getValue()));
|
||||||
|
if (CollectionUtil.isNotEmpty(appDevices)) {
|
||||||
|
throw new BadRequestException("该设备已绑定!!!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Device device = devices.get(0);
|
Device device = devices.get(0);
|
||||||
@ -70,12 +91,18 @@ public class APPDeviceServiceImpl extends ServiceImpl<APPDeviceMapper, APPDevice
|
|||||||
appDevice.setBindingStatus(BindingStatusEnum.BOUND.getCode());
|
appDevice.setBindingStatus(BindingStatusEnum.BOUND.getCode());
|
||||||
Long currentUserId = SecurityUtils.getCurrentUserId();
|
Long currentUserId = SecurityUtils.getCurrentUserId();
|
||||||
appDevice.setCustomerId(currentUserId);
|
appDevice.setCustomerId(currentUserId);
|
||||||
|
appDevice.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
||||||
|
// 设备类型名称
|
||||||
|
appDevice.setDeviceTypeName(device.getTypeName());
|
||||||
appDeviceMapper.insert(appDevice);
|
appDeviceMapper.insert(appDevice);
|
||||||
|
|
||||||
DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType());
|
APPDeviceType appDeviceType = appDeviceTypeMapper.selectById(device.getDeviceType());
|
||||||
APPDeviceType appDeviceType = new APPDeviceType();
|
if (appDeviceType == null) {
|
||||||
BeanUtil.copyProperties(deviceType, appDeviceType);
|
DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType());
|
||||||
appDeviceTypeMapper.insert(appDeviceType);
|
APPDeviceType type = new APPDeviceType();
|
||||||
|
BeanUtil.copyProperties(deviceType, type);
|
||||||
|
appDeviceTypeMapper.insert(type);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,10 +12,7 @@ import com.fuyuanshen.constants.ExceptionMessages;
|
|||||||
import com.fuyuanshen.exception.BadRequestException;
|
import com.fuyuanshen.exception.BadRequestException;
|
||||||
import com.fuyuanshen.modules.security.service.UserCacheManager;
|
import com.fuyuanshen.modules.security.service.UserCacheManager;
|
||||||
import com.fuyuanshen.modules.system.constant.UserConstants;
|
import com.fuyuanshen.modules.system.constant.UserConstants;
|
||||||
import com.fuyuanshen.modules.system.domain.Device;
|
import com.fuyuanshen.modules.system.domain.*;
|
||||||
import com.fuyuanshen.modules.system.domain.DeviceAssignments;
|
|
||||||
import com.fuyuanshen.modules.system.domain.DeviceTypeGrants;
|
|
||||||
import com.fuyuanshen.modules.system.domain.User;
|
|
||||||
import com.fuyuanshen.modules.system.domain.app.APPDevice;
|
import com.fuyuanshen.modules.system.domain.app.APPDevice;
|
||||||
import com.fuyuanshen.modules.system.domain.dto.CustomerVo;
|
import com.fuyuanshen.modules.system.domain.dto.CustomerVo;
|
||||||
import com.fuyuanshen.modules.system.domain.dto.DeviceForm;
|
import com.fuyuanshen.modules.system.domain.dto.DeviceForm;
|
||||||
@ -195,6 +192,8 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|||||||
// device.setId(snowflakeGenerator.next());
|
// device.setId(snowflakeGenerator.next());
|
||||||
device.setCurrentOwnerId(currentUser.getId());
|
device.setCurrentOwnerId(currentUser.getId());
|
||||||
device.setOriginalOwnerId(currentUser.getId());
|
device.setOriginalOwnerId(currentUser.getId());
|
||||||
|
DeviceType deviceType = deviceTypeMapper.selectById(deviceForm.getDeviceType());
|
||||||
|
device.setTypeName(deviceType.getTypeName());
|
||||||
|
|
||||||
deviceMapper.insert(device);
|
deviceMapper.insert(device);
|
||||||
|
|
||||||
|
@ -27,9 +27,12 @@
|
|||||||
<if test="criteria.deviceName != null and criteria.deviceName.trim() != ''">
|
<if test="criteria.deviceName != null and criteria.deviceName.trim() != ''">
|
||||||
and d.device_name like concat('%', TRIM(#{criteria.deviceName}), '%')
|
and d.device_name like concat('%', TRIM(#{criteria.deviceName}), '%')
|
||||||
</if>
|
</if>
|
||||||
<if test="criteria.deviceMac != null and criteria.deviceName.trim() != ''">
|
<if test="criteria.deviceMac != null and criteria.deviceMac.trim() != ''">
|
||||||
and d.device_mac = #{criteria.deviceMac}
|
and d.device_mac = #{criteria.deviceMac}
|
||||||
</if>
|
</if>
|
||||||
|
<if test="criteria.deviceImei != null and criteria.deviceImei.trim() != ''">
|
||||||
|
and d.device_imei = #{criteria.deviceImei}
|
||||||
|
</if>
|
||||||
<if test="criteria.deviceSn != null">
|
<if test="criteria.deviceSn != null">
|
||||||
and d.device_sn = #{criteria.deviceSn}
|
and d.device_sn = #{criteria.deviceSn}
|
||||||
</if>
|
</if>
|
||||||
@ -48,7 +51,7 @@
|
|||||||
</if>
|
</if>
|
||||||
and d.customer_id = #{criteria.customerId}
|
and d.customer_id = #{criteria.customerId}
|
||||||
</where>
|
</where>
|
||||||
order by d.app_device_id desc
|
order by d.create_time desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
Reference in New Issue
Block a user