From d64216ee5f10c09a095b92ea939c82611bb22d07 Mon Sep 17 00:00:00 2001 From: daiyongfei <974332738@qq.com> Date: Tue, 24 Jun 2025 14:34:44 +0800 Subject: [PATCH] =?UTF-8?q?APP=E7=94=A8=E6=88=B7=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/system/domain/app/APPDevice.java | 3 ++ .../domain/dto/DeviceQueryCriteria.java | 3 ++ .../system/enums/CommunicationModeEnum.java | 45 ++++++++++++++++ .../system/rest/app/APPDeviceController.java | 6 +-- .../system/service/app/APPDeviceService.java | 4 +- .../service/app/APPDeviceServiceImpl.java | 53 ++++++++++++++----- .../service/impl/DeviceServiceImpl.java | 7 ++- .../mapper/system/APPDeviceMapper.xml | 7 ++- 8 files changed, 104 insertions(+), 24 deletions(-) create mode 100644 fys-system/src/main/java/com/fuyuanshen/modules/system/enums/CommunicationModeEnum.java diff --git a/fys-system/src/main/java/com/fuyuanshen/modules/system/domain/app/APPDevice.java b/fys-system/src/main/java/com/fuyuanshen/modules/system/domain/app/APPDevice.java index 4d1c174..78a9c59 100644 --- a/fys-system/src/main/java/com/fuyuanshen/modules/system/domain/app/APPDevice.java +++ b/fys-system/src/main/java/com/fuyuanshen/modules/system/domain/app/APPDevice.java @@ -50,6 +50,9 @@ public class APPDevice extends BaseEntity implements Serializable { @ApiModelProperty(value = "设备MAC") private String deviceMac; + @ApiModelProperty(value = "设备IMEI") + private String deviceImei; + @ApiModelProperty(value = "设备SN") private String deviceSn; diff --git a/fys-system/src/main/java/com/fuyuanshen/modules/system/domain/dto/DeviceQueryCriteria.java b/fys-system/src/main/java/com/fuyuanshen/modules/system/domain/dto/DeviceQueryCriteria.java index ff6dbfd..e0e0fa5 100644 --- a/fys-system/src/main/java/com/fuyuanshen/modules/system/domain/dto/DeviceQueryCriteria.java +++ b/fys-system/src/main/java/com/fuyuanshen/modules/system/domain/dto/DeviceQueryCriteria.java @@ -58,4 +58,7 @@ public class DeviceQueryCriteria { @ApiModelProperty(value = "租户ID") private Long tenantId; + @ApiModelProperty(value = "通讯方式", example = "0:4G;1:蓝牙") + private Integer communicationMode; + } diff --git a/fys-system/src/main/java/com/fuyuanshen/modules/system/enums/CommunicationModeEnum.java b/fys-system/src/main/java/com/fuyuanshen/modules/system/enums/CommunicationModeEnum.java new file mode 100644 index 0000000..26b6046 --- /dev/null +++ b/fys-system/src/main/java/com/fuyuanshen/modules/system/enums/CommunicationModeEnum.java @@ -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; + } + +} \ No newline at end of file diff --git a/fys-system/src/main/java/com/fuyuanshen/modules/system/rest/app/APPDeviceController.java b/fys-system/src/main/java/com/fuyuanshen/modules/system/rest/app/APPDeviceController.java index 549c36c..66daf9d 100644 --- a/fys-system/src/main/java/com/fuyuanshen/modules/system/rest/app/APPDeviceController.java +++ b/fys-system/src/main/java/com/fuyuanshen/modules/system/rest/app/APPDeviceController.java @@ -67,10 +67,10 @@ public class APPDeviceController { private final APPDeviceService appDeviceService; - @GetMapping(value = "/bind") + @PostMapping(value = "/bind") @ApiOperation("APP用户设备绑定") - public ResponseVO appBindDevice(@ApiParam("设备MAC地址") @RequestParam String mac) { - appDeviceService.appBindDevice(mac); + public ResponseVO appBindDevice( @RequestBody DeviceQueryCriteria criteria) { + appDeviceService.appBindDevice(criteria); return ResponseVO.success("绑定成功!"); } diff --git a/fys-system/src/main/java/com/fuyuanshen/modules/system/service/app/APPDeviceService.java b/fys-system/src/main/java/com/fuyuanshen/modules/system/service/app/APPDeviceService.java index c0fe8c0..adcd92a 100644 --- a/fys-system/src/main/java/com/fuyuanshen/modules/system/service/app/APPDeviceService.java +++ b/fys-system/src/main/java/com/fuyuanshen/modules/system/service/app/APPDeviceService.java @@ -25,9 +25,9 @@ public interface APPDeviceService extends IService { /** * APP/小程序用户设备绑定 * - * @param mac + * @param criteria */ - void appBindDevice(String mac); + void appBindDevice(DeviceQueryCriteria criteria); /** diff --git a/fys-system/src/main/java/com/fuyuanshen/modules/system/service/app/APPDeviceServiceImpl.java b/fys-system/src/main/java/com/fuyuanshen/modules/system/service/app/APPDeviceServiceImpl.java index 6b6cbd0..e72f02c 100644 --- a/fys-system/src/main/java/com/fuyuanshen/modules/system/service/app/APPDeviceServiceImpl.java +++ b/fys-system/src/main/java/com/fuyuanshen/modules/system/service/app/APPDeviceServiceImpl.java @@ -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.app.APPUnbindDTO; 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.mapper.DeviceMapper; import com.fuyuanshen.modules.system.mapper.DeviceTypeMapper; @@ -26,6 +27,9 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; 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.stream.Collectors; @@ -48,19 +52,36 @@ public class APPDeviceServiceImpl extends ServiceImpl devices = deviceMapper.selectList(new QueryWrapper().eq("device_mac", mac)); - if (CollectionUtil.isEmpty(devices)) { - throw new BadRequestException("请先将设备入库!!!"); + public void appBindDevice(DeviceQueryCriteria criteria) { + + List devices = new ArrayList<>(); + + if (criteria.getCommunicationMode().equals(CommunicationModeEnum.BLUETOOTH.getValue())) { + devices = deviceMapper.selectList(new QueryWrapper().eq("device_mac", criteria.getDeviceMac())); + if (CollectionUtil.isEmpty(devices)) { + throw new BadRequestException("请先将设备入库!!!"); + } + List appDevices = appDeviceMapper.selectList(new QueryWrapper() + .eq("device_mac", criteria.getDeviceMac()).eq("binding_type", UserType.APP.getValue())); + if (CollectionUtil.isNotEmpty(appDevices)) { + throw new BadRequestException("该设备已绑定!!!"); + } } - List appDevices = appDeviceMapper.selectList(new QueryWrapper() - .eq("device_mac", mac).eq("binding_type", UserType.APP.getValue())); - if (CollectionUtil.isNotEmpty(appDevices)) { - throw new BadRequestException("该设备已绑定!!!"); + + if (criteria.getCommunicationMode().equals(CommunicationModeEnum.FOUR_G.getValue())) { + devices = deviceMapper.selectList(new QueryWrapper().eq("device_imei", criteria.getDeviceImei())); + if (CollectionUtil.isEmpty(devices)) { + throw new BadRequestException("请先将设备入库!!!"); + } + List appDevices = appDeviceMapper.selectList(new QueryWrapper() + .eq("device_imei", criteria.getDeviceImei()).eq("binding_type", UserType.APP.getValue())); + if (CollectionUtil.isNotEmpty(appDevices)) { + throw new BadRequestException("该设备已绑定!!!"); + } } Device device = devices.get(0); @@ -70,12 +91,18 @@ public class APPDeviceServiceImpl extends ServiceImpl impleme // device.setId(snowflakeGenerator.next()); device.setCurrentOwnerId(currentUser.getId()); device.setOriginalOwnerId(currentUser.getId()); + DeviceType deviceType = deviceTypeMapper.selectById(deviceForm.getDeviceType()); + device.setTypeName(deviceType.getTypeName()); deviceMapper.insert(device); diff --git a/fys-system/src/main/resources/mapper/system/APPDeviceMapper.xml b/fys-system/src/main/resources/mapper/system/APPDeviceMapper.xml index 664580c..18f13f4 100644 --- a/fys-system/src/main/resources/mapper/system/APPDeviceMapper.xml +++ b/fys-system/src/main/resources/mapper/system/APPDeviceMapper.xml @@ -27,9 +27,12 @@ and d.device_name like concat('%', TRIM(#{criteria.deviceName}), '%') - + and d.device_mac = #{criteria.deviceMac} + + and d.device_imei = #{criteria.deviceImei} + and d.device_sn = #{criteria.deviceSn} @@ -48,7 +51,7 @@ and d.customer_id = #{criteria.customerId} - order by d.app_device_id desc + order by d.create_time desc \ No newline at end of file