diff --git a/fys-admin/src/main/java/com/fuyuanshen/app/service/AppLoginService.java b/fys-admin/src/main/java/com/fuyuanshen/app/service/AppLoginService.java index 6d038219..9893dec5 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/app/service/AppLoginService.java +++ b/fys-admin/src/main/java/com/fuyuanshen/app/service/AppLoginService.java @@ -4,6 +4,7 @@ import cn.dev33.satoken.exception.NotLoginException; import cn.dev33.satoken.stp.StpUtil; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.ObjectUtil; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.fuyuanshen.app.domain.bo.AppDeviceBindRecordBo; import com.fuyuanshen.app.domain.bo.AppDeviceShareBo; import com.fuyuanshen.app.domain.vo.AppDeviceBindRecordVo; @@ -27,6 +28,8 @@ import com.fuyuanshen.common.satoken.utils.AppLoginHelper; import com.fuyuanshen.common.satoken.utils.LoginHelper; import com.fuyuanshen.common.tenant.exception.TenantException; import com.fuyuanshen.common.tenant.helper.TenantHelper; +import com.fuyuanshen.equipment.domain.Device; +import com.fuyuanshen.equipment.service.DeviceService; import com.fuyuanshen.system.domain.vo.SysTenantVo; import com.fuyuanshen.system.service.ISysTenantService; import lombok.RequiredArgsConstructor; @@ -59,6 +62,7 @@ public class AppLoginService { private final IAppUserService appUserService; private final IAppDeviceShareService appDeviceShareService; private final IAppDeviceBindRecordService appDeviceBindRecordService; + private final DeviceService deviceService; /** @@ -209,8 +213,7 @@ public class AppLoginService { if(ObjectUtil.length(appDeviceBindRecordVos)>0){ - // 根据设备id批量删除 - List deviceIds = appDeviceBindRecordVos.stream().map(AppDeviceBindRecordVo::getDeviceId).toList(); + Set deviceIds = appDeviceBindRecordVos.stream().map(AppDeviceBindRecordVo::getDeviceId).collect(Collectors.toSet()); appDeviceShareService.deleteByDeviceIds(deviceIds); @@ -219,6 +222,21 @@ public class AppLoginService { .collect(Collectors.toList()); appDeviceBindRecordService.deleteWithValidByIds(ids, true); log.info("删除绑定关系表数据:ids={}",ids); + + + // 检查设备id是否存在绑定关系 + for (Long deviceId : deviceIds){ + // 根据设备id查询是否存在绑定关系 + Long count = appDeviceBindRecordService.checkDeviceExistBindRecord(deviceId); + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.eq("id",deviceId); + if(count>0){ + updateWrapper.set("binding_status",1); + }else{ + updateWrapper.set("binding_status",0); + } + deviceService.update(updateWrapper); + } } if (TenantHelper.isEnable() && LoginHelper.isSuperAdmin()) { diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/controller/AuthController.java b/fys-admin/src/main/java/com/fuyuanshen/web/controller/AuthController.java index dee5b537..2e1a0b4f 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/web/controller/AuthController.java +++ b/fys-admin/src/main/java/com/fuyuanshen/web/controller/AuthController.java @@ -101,13 +101,13 @@ public class AuthController { // 登录 LoginVo loginVo = IAuthStrategy.login(body, client, grantType); - Long userId = LoginHelper.getUserId(); - scheduledExecutorService.schedule(() -> { - SseMessageDto dto = new SseMessageDto(); - dto.setMessage("欢迎登录fys-Vue-Plus后台管理系统"); - dto.setUserIds(List.of(userId)); - SseMessageUtils.publishMessage(dto); - }, 5, TimeUnit.SECONDS); +// Long userId = LoginHelper.getUserId(); +// scheduledExecutorService.schedule(() -> { +// SseMessageDto dto = new SseMessageDto(); +// dto.setMessage("欢迎登录fys-Vue-Plus后台管理系统"); +// dto.setUserIds(List.of(userId)); +// SseMessageUtils.publishMessage(dto); +// }, 5, TimeUnit.SECONDS); return R.ok(loginVo); } diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/mapper/AppDeviceBindRecordMapper.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/mapper/AppDeviceBindRecordMapper.java index 2fa66a8f..d261bc89 100644 --- a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/mapper/AppDeviceBindRecordMapper.java +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/mapper/AppDeviceBindRecordMapper.java @@ -3,6 +3,7 @@ package com.fuyuanshen.app.mapper; import com.fuyuanshen.app.domain.AppDeviceBindRecord; import com.fuyuanshen.app.domain.vo.AppDeviceBindRecordVo; import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus; +import org.apache.ibatis.annotations.Param; /** * 设备绑定关系Mapper接口 @@ -12,4 +13,5 @@ import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus; */ public interface AppDeviceBindRecordMapper extends BaseMapperPlus { + Long checkDeviceExistBindRecord(@Param("deviceId") Long deviceId); } diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/mapper/AppDeviceShareMapper.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/mapper/AppDeviceShareMapper.java index 19819c11..8647cf12 100644 --- a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/mapper/AppDeviceShareMapper.java +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/mapper/AppDeviceShareMapper.java @@ -10,6 +10,7 @@ import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus; import org.apache.ibatis.annotations.Param; import java.util.List; +import java.util.Set; /** * 设备分享Mapper接口 @@ -30,5 +31,5 @@ public interface AppDeviceShareMapper extends BaseMapperPlus selectWebDeviceShareList(@Param("bo") AppDeviceShareBo bo, Page page); - void deleteByDeviceIds(@Param("deviceIds") List deviceIds); + void deleteByDeviceIds(@Param("deviceIds") Set deviceIds); } diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/IAppDeviceBindRecordService.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/IAppDeviceBindRecordService.java index 2d3a2391..9bb68354 100644 --- a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/IAppDeviceBindRecordService.java +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/IAppDeviceBindRecordService.java @@ -4,6 +4,7 @@ import com.fuyuanshen.app.domain.vo.AppDeviceBindRecordVo; import com.fuyuanshen.app.domain.bo.AppDeviceBindRecordBo; import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; import com.fuyuanshen.common.mybatis.core.page.PageQuery; +import org.apache.ibatis.annotations.Param; import java.util.Collection; import java.util.List; @@ -65,4 +66,6 @@ public interface IAppDeviceBindRecordService { * @return 是否删除成功 */ Boolean deleteWithValidByIds(Collection ids, Boolean isValid); + + Long checkDeviceExistBindRecord(Long deviceId); } diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/IAppDeviceShareService.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/IAppDeviceShareService.java index cff36c5c..0f893ed1 100644 --- a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/IAppDeviceShareService.java +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/IAppDeviceShareService.java @@ -7,6 +7,7 @@ import com.fuyuanshen.common.mybatis.core.page.PageQuery; import java.util.Collection; import java.util.List; +import java.util.Set; /** * 设备分享Service接口 @@ -68,5 +69,5 @@ public interface IAppDeviceShareService { TableDataInfo otherDeviceShareList(AppDeviceShareBo bo, PageQuery pageQuery); - void deleteByDeviceIds(List deviceIds); + void deleteByDeviceIds(Set deviceIds); } diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/impl/AppDeviceBindRecordServiceImpl.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/impl/AppDeviceBindRecordServiceImpl.java index 59c9fd9a..bcfa1485 100644 --- a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/impl/AppDeviceBindRecordServiceImpl.java +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/impl/AppDeviceBindRecordServiceImpl.java @@ -130,4 +130,9 @@ public class AppDeviceBindRecordServiceImpl implements IAppDeviceBindRecordServi } return baseMapper.deleteByIds(ids) > 0; } + + @Override + public Long checkDeviceExistBindRecord(Long deviceId) { + return baseMapper.checkDeviceExistBindRecord(deviceId); + } } diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/impl/AppDeviceShareServiceImpl.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/impl/AppDeviceShareServiceImpl.java index 726ef15c..5ac764c5 100644 --- a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/impl/AppDeviceShareServiceImpl.java +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/impl/AppDeviceShareServiceImpl.java @@ -23,6 +23,7 @@ import com.fuyuanshen.app.service.IAppDeviceShareService; import java.util.List; import java.util.Map; import java.util.Collection; +import java.util.Set; /** * 设备分享Service业务层处理 @@ -168,7 +169,7 @@ public class AppDeviceShareServiceImpl implements IAppDeviceShareService { } @Override - public void deleteByDeviceIds(List deviceIds) { + public void deleteByDeviceIds(Set deviceIds) { baseMapper.deleteByDeviceIds(deviceIds); } } diff --git a/fys-modules/fys-app/src/main/resources/mapper/app/AppDeviceBindRecordMapper.xml b/fys-modules/fys-app/src/main/resources/mapper/app/AppDeviceBindRecordMapper.xml index a523cece..6cb545f1 100644 --- a/fys-modules/fys-app/src/main/resources/mapper/app/AppDeviceBindRecordMapper.xml +++ b/fys-modules/fys-app/src/main/resources/mapper/app/AppDeviceBindRecordMapper.xml @@ -4,4 +4,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + diff --git a/fys-modules/fys-app/src/main/resources/mapper/app/AppDeviceShareMapper.xml b/fys-modules/fys-app/src/main/resources/mapper/app/AppDeviceShareMapper.xml index 56de3ddb..060490bb 100644 --- a/fys-modules/fys-app/src/main/resources/mapper/app/AppDeviceShareMapper.xml +++ b/fys-modules/fys-app/src/main/resources/mapper/app/AppDeviceShareMapper.xml @@ -4,7 +4,7 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - delete from app_device_share where device_id in + delete from app_device_share where device_id in #{item} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/query/DeviceQueryCriteria.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/query/DeviceQueryCriteria.java index fa053673..5258b1e5 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/query/DeviceQueryCriteria.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/query/DeviceQueryCriteria.java @@ -123,4 +123,12 @@ public class DeviceQueryCriteria extends BaseEntity { */ private Integer onlineStatus; + /** + * 绑定状态 + * 0 未绑定 + * 1 已绑定 + */ + @Schema(title = "绑定状态") + private Integer bindingStatus; + } diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/DeviceService.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/DeviceService.java index f0ab8143..d283534e 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/DeviceService.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/DeviceService.java @@ -1,13 +1,10 @@ package com.fuyuanshen.equipment.service; -import cn.hutool.core.lang.Dict; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; -import com.fuyuanshen.common.core.domain.PageResult; import com.fuyuanshen.common.mybatis.core.page.PageQuery; import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; import com.fuyuanshen.equipment.domain.Device; -import com.fuyuanshen.equipment.domain.DeviceType; import com.fuyuanshen.equipment.domain.dto.AppDeviceBo; import com.fuyuanshen.equipment.domain.form.DeviceForm; import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria; @@ -146,7 +143,7 @@ public interface DeviceService extends IService { * @return */ List> getEquipmentUsageData(Long deviceTypeId, Integer range); - + /** * 根据设备IMEI查询设备 * @@ -191,7 +188,7 @@ public interface DeviceService extends IService { /** * 根据条件查询设备位置信息 * - * @param groupId 设备分组ID + * @param groupId 设备分组ID * @param deviceType 设备类型 * @param deviceImei 设备IMEI * @return 设备位置信息列表 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 44059604..0e7ff3c7 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 @@ -74,6 +74,9 @@ and d.online_status = #{criteria.onlineStatus} + + and d.binding_status = #{criteria.bindingStatus} + and d.group_id = #{criteria.groupId} @@ -305,7 +308,7 @@