From 6a6397da2389a3b4d88036ace6d5d6db061cd785 Mon Sep 17 00:00:00 2001 From: chenyouting <514333061@qq.com> Date: Wed, 8 Oct 2025 11:48:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A7=E5=88=B6=E6=9F=A5=E8=AF=A2=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E5=8A=A0=E6=A8=A1=E7=B3=8A=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/controller/AppDeviceController.java | 4 +- .../web/service/device/DeviceBizService.java | 70 ++++++++++++------- .../mapper/equipment/DeviceMapper.xml | 10 +-- 3 files changed, 53 insertions(+), 31 deletions(-) diff --git a/fys-admin/src/main/java/com/fuyuanshen/app/controller/AppDeviceController.java b/fys-admin/src/main/java/com/fuyuanshen/app/controller/AppDeviceController.java index d4b1695e..402244e4 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/app/controller/AppDeviceController.java +++ b/fys-admin/src/main/java/com/fuyuanshen/app/controller/AppDeviceController.java @@ -6,6 +6,7 @@ import com.fuyuanshen.app.domain.vo.APPDeviceTypeVo; import com.fuyuanshen.common.core.domain.R; import com.fuyuanshen.common.mybatis.core.page.PageQuery; import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; +import com.fuyuanshen.common.satoken.utils.AppLoginHelper; import com.fuyuanshen.common.web.core.BaseController; import com.fuyuanshen.equipment.domain.Device; import com.fuyuanshen.equipment.domain.dto.AppDeviceBo; @@ -53,7 +54,8 @@ public class AppDeviceController extends BaseController { */ @DeleteMapping("/unBind") public R unBind(Long id) { - return toAjax(appDeviceService.unBindDevice(id)); + Long userId = AppLoginHelper.getUserId(); + return toAjax(appDeviceService.unBindDevice(id,userId,0)); } /** diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/service/device/DeviceBizService.java b/fys-admin/src/main/java/com/fuyuanshen/web/service/device/DeviceBizService.java index 71cb591b..21437650 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/web/service/device/DeviceBizService.java +++ b/fys-admin/src/main/java/com/fuyuanshen/web/service/device/DeviceBizService.java @@ -265,43 +265,63 @@ public class DeviceBizService { if (device == null) { throw new RuntimeException("请先将设备入库!!!"); } - UpdateWrapper deviceUpdateWrapper = new UpdateWrapper<>(); - deviceUpdateWrapper.eq("id", device.getId()) - .set("binding_user_id", null) - .set("binding_status", BindingStatusEnum.UNBOUND.getCode()) - .set("binding_time", null); - deviceMapper.update(null, deviceUpdateWrapper); - if (userId == null) { - userId = AppLoginHelper.getUserId(); - } - QueryWrapper bindRecordQueryWrapper = new QueryWrapper<>(); - bindRecordQueryWrapper.eq("device_id", device.getId()); - // 设备端解绑 0:设备端解绑 1:web端解绑 - if (type == 1) { + // type: 0 app,1 web + if (type == 0) { + QueryWrapper bindRecordQueryWrapper = new QueryWrapper<>(); + bindRecordQueryWrapper.eq("device_id", device.getId()); bindRecordQueryWrapper.eq("binding_user_id", userId); + Long count = appDeviceBindRecordMapper.selectCount(bindRecordQueryWrapper); + if (count == 0) { + throw new RuntimeException("请先绑定设备!!!"); + } + if(count<2){ + UpdateWrapper deviceUpdateWrapper = new UpdateWrapper<>(); + deviceUpdateWrapper.eq("id", device.getId()) + .set("binding_user_id", null) + .set("binding_status", BindingStatusEnum.UNBOUND.getCode()) + .set("binding_time", null); + deviceMapper.update(null, deviceUpdateWrapper); + } + }else{ + QueryWrapper bindRecordQueryWrapper = new QueryWrapper<>(); + bindRecordQueryWrapper.eq("device_id", device.getId()); + Long count = appDeviceBindRecordMapper.selectCount(bindRecordQueryWrapper); + if (count == 0) { + throw new RuntimeException("请先绑定设备!!!"); + } + UpdateWrapper deviceUpdateWrapper = new UpdateWrapper<>(); + deviceUpdateWrapper.eq("id", device.getId()) + .set("binding_user_id", null) + .set("binding_status", BindingStatusEnum.UNBOUND.getCode()) + .set("binding_time", null); + deviceMapper.update(null, deviceUpdateWrapper); } - // AppDeviceBindRecord appDeviceBindRecord = appDeviceBindRecordMapper.selectOne(bindRecordQueryWrapper); - // if (appDeviceBindRecord != null) { - // return appDeviceBindRecordMapper.deleteById(appDeviceBindRecord.getId()); - // } + QueryWrapper brqWrapper = new QueryWrapper<>(); + brqWrapper.eq("device_id", device.getId()); + if(userId != null){ + brqWrapper.eq("binding_user_id", userId); + } - List appDeviceBindRecordList = appDeviceBindRecordMapper.selectList(bindRecordQueryWrapper); + List appDeviceBindRecordList = appDeviceBindRecordMapper.selectList(brqWrapper); if (CollectionUtil.isNotEmpty(appDeviceBindRecordList)) { appDeviceBindRecordList.forEach(appDeviceBindRecord -> appDeviceBindRecordMapper.deleteById(appDeviceBindRecord.getId())); } AppUserVo appUserVo = appUserMapper.selectVoById(userId); - QueryWrapper appDeviceShareQueryWrapper = new QueryWrapper<>(); - appDeviceShareQueryWrapper.eq("device_id", device.getId()); - appDeviceShareQueryWrapper.eq("phonenumber", appUserVo.getPhonenumber()); - List appDeviceShareList = appDeviceShareMapper.selectList(appDeviceShareQueryWrapper); - if (CollectionUtil.isNotEmpty(appDeviceShareList)) { - appDeviceShareList.forEach(appDeviceShare -> - appDeviceShareMapper.deleteById(appDeviceShare.getId())); + if(appUserVo != null){ + QueryWrapper appDeviceShareQueryWrapper = new QueryWrapper<>(); + appDeviceShareQueryWrapper.eq("device_id", device.getId()); + appDeviceShareQueryWrapper.eq("phonenumber", appUserVo.getPhonenumber()); + List appDeviceShareList = appDeviceShareMapper.selectList(appDeviceShareQueryWrapper); + if (CollectionUtil.isNotEmpty(appDeviceShareList)) { + appDeviceShareList.forEach(appDeviceShare -> + appDeviceShareMapper.deleteById(appDeviceShare.getId())); + } } + return 1; } diff --git a/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceMapper.xml b/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceMapper.xml index 92fa6447..c9ac28a6 100644 --- a/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceMapper.xml +++ b/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceMapper.xml @@ -268,10 +268,10 @@ and a.device_name like concat('%', #{criteria.deviceName}, '%') - and a.device_imei = #{criteria.deviceImei} + and a.device_imei like concat('%',#{criteria.deviceImei}, '%') - AND (a.device_imei = #{criteria.content} or a.device_mac = #{criteria.content}) + AND (a.device_imei like concat('%',#{criteria.content}, '%') or a.device_mac like concat('%',#{criteria.content}, '%') ) and a.device_status = #{criteria.deviceStatus} @@ -288,7 +288,7 @@ and a.online_status = #{criteria.onlineStatus} - ORDER BY a.binding_time DESC + ORDER BY a.online_status,a.binding_time DESC