From 5f4b12a3209c0c5ee540a7cb6a1d27ca3a248947 Mon Sep 17 00:00:00 2001 From: chenyouting <514333061@qq.com> Date: Fri, 1 Aug 2025 09:00:32 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/service/AppDeviceBizService.java | 64 ++++++++- .../web/service/AppRegisterService.java | 4 +- .../src/main/resources/application-prod.yml | 19 +-- .../AppDeviceBindRecordController.java | 105 ++++++++++++++ .../app/domain/AppDeviceBindRecord.java | 53 +++++++ .../app/domain/bo/AppDeviceBindRecordBo.java | 51 +++++++ .../app/domain/vo/AppDeviceBindRecordVo.java | 64 +++++++++ .../app/mapper/AppDeviceBindRecordMapper.java | 15 ++ .../service/IAppDeviceBindRecordService.java | 68 +++++++++ .../impl/AppDeviceBindRecordServiceImpl.java | 133 ++++++++++++++++++ .../mapper/app/AppDeviceBindRecordMapper.xml | 7 + .../mapper/equipment/DeviceMapper.xml | 3 +- 12 files changed, 569 insertions(+), 17 deletions(-) create mode 100644 fys-modules/fys-app/src/main/java/com/fuyuanshen/app/controller/AppDeviceBindRecordController.java create mode 100644 fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/AppDeviceBindRecord.java create mode 100644 fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/bo/AppDeviceBindRecordBo.java create mode 100644 fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/vo/AppDeviceBindRecordVo.java create mode 100644 fys-modules/fys-app/src/main/java/com/fuyuanshen/app/mapper/AppDeviceBindRecordMapper.java create mode 100644 fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/IAppDeviceBindRecordService.java create mode 100644 fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/impl/AppDeviceBindRecordServiceImpl.java create mode 100644 fys-modules/fys-app/src/main/resources/mapper/app/AppDeviceBindRecordMapper.xml diff --git a/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java b/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java index 0f1a83d..b5bc9e1 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java +++ b/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java @@ -4,12 +4,14 @@ import com.alibaba.fastjson2.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.fuyuanshen.app.domain.AppDeviceBindRecord; import com.fuyuanshen.app.domain.AppPersonnelInfo; import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo; import com.fuyuanshen.app.domain.dto.APPReNameDTO; import com.fuyuanshen.app.domain.vo.APPDeviceTypeVo; import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo; import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo; +import com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper; import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper; import com.fuyuanshen.app.mapper.equipment.APPDeviceMapper; import com.fuyuanshen.common.core.exception.ServiceException; @@ -51,7 +53,7 @@ public class AppDeviceBizService { private final AppPersonnelInfoMapper appPersonnelInfoMapper; private final DeviceTypeMapper deviceTypeMapper; private final MqttGateway mqttGateway; - + private final AppDeviceBindRecordMapper appDeviceBindRecordMapper; public List getTypeList() { Long userId = AppLoginHelper.getUserId(); @@ -120,13 +122,32 @@ public class AppDeviceBizService { if (device.getBindingStatus() != null && device.getBindingStatus() == BindingStatusEnum.BOUND.getCode()) { throw new RuntimeException("设备已绑定"); } + + QueryWrapper bindRecordQueryWrapper = new QueryWrapper<>(); + bindRecordQueryWrapper.eq("device_id", device.getId()); + AppDeviceBindRecord appDeviceBindRecord = appDeviceBindRecordMapper.selectOne(bindRecordQueryWrapper); + if (appDeviceBindRecord != null) { + UpdateWrapper deviceUpdateWrapper = new UpdateWrapper<>(); + deviceUpdateWrapper.eq("device_id", device.getId()) + .set("binding_status", BindingStatusEnum.BOUND.getCode()) + .set("binding_user_id", userId) + .set("update_time", new Date()) + .set("binding_time", new Date()); + return appDeviceBindRecordMapper.update(null, deviceUpdateWrapper); + }else{ + AppDeviceBindRecord bindRecord = new AppDeviceBindRecord(); + bindRecord.setDeviceId(device.getId()); + bindRecord.setBindingUserId(userId); + bindRecord.setBindingTime(new Date()); + bindRecord.setCreateBy(userId); + appDeviceBindRecordMapper.insert(bindRecord); + } + UpdateWrapper deviceUpdateWrapper = new UpdateWrapper<>(); deviceUpdateWrapper.eq("id", device.getId()) .set("binding_status", BindingStatusEnum.BOUND.getCode()) .set("binding_user_id", userId) .set("binding_time", new Date()); - - return deviceMapper.update(null, deviceUpdateWrapper); } else if (mode == CommunicationModeEnum.BLUETOOTH.getValue()) { String deviceMac = bo.getDeviceMac(); @@ -137,9 +158,27 @@ public class AppDeviceBizService { throw new RuntimeException("请先将设备入库!!!"); } Device device = devices.get(0); - if (device.getBindingStatus() != null && device.getBindingStatus() == BindingStatusEnum.BOUND.getCode()) { - throw new RuntimeException("设备已绑定"); + + QueryWrapper bindRecordQueryWrapper = new QueryWrapper<>(); + bindRecordQueryWrapper.eq("device_id", device.getId()); + bindRecordQueryWrapper.eq("binding_user_id", userId); + AppDeviceBindRecord appDeviceBindRecord = appDeviceBindRecordMapper.selectOne(bindRecordQueryWrapper); + if (appDeviceBindRecord != null) { + UpdateWrapper deviceUpdateWrapper = new UpdateWrapper<>(); + deviceUpdateWrapper.eq("device_id", device.getId()) + .eq("binding_user_id", userId) + .set("binding_user_id", userId) + .set("binding_time", new Date()); + return appDeviceBindRecordMapper.update(null, deviceUpdateWrapper); + }else{ + AppDeviceBindRecord bindRecord = new AppDeviceBindRecord(); + bindRecord.setDeviceId(device.getId()); + bindRecord.setBindingUserId(userId); + bindRecord.setBindingTime(new Date()); + bindRecord.setCreateBy(userId); + appDeviceBindRecordMapper.insert(bindRecord); } + UpdateWrapper deviceUpdateWrapper = new UpdateWrapper<>(); deviceUpdateWrapper.eq("id", device.getId()) .set("binding_status", BindingStatusEnum.BOUND.getCode()) @@ -159,10 +198,21 @@ public class AppDeviceBizService { } UpdateWrapper deviceUpdateWrapper = new UpdateWrapper<>(); deviceUpdateWrapper.eq("id", device.getId()) - .set("binding_status", BindingStatusEnum.UNBOUND.getCode()) .set("binding_user_id", null) + .set("binding_status", BindingStatusEnum.UNBOUND.getCode()) .set("binding_time", null); - return deviceMapper.update(null, deviceUpdateWrapper); + deviceMapper.update(null, deviceUpdateWrapper); + + Long userId = AppLoginHelper.getUserId(); + QueryWrapper bindRecordQueryWrapper = new QueryWrapper<>(); + bindRecordQueryWrapper.eq("device_id", device.getId()); + bindRecordQueryWrapper.eq("binding_user_id", userId); + AppDeviceBindRecord appDeviceBindRecord = appDeviceBindRecordMapper.selectOne(bindRecordQueryWrapper); + if (appDeviceBindRecord != null) { + return appDeviceBindRecordMapper.deleteById(appDeviceBindRecord.getId()); + } + + return 1; } public AppDeviceDetailVo getInfo(Long id) { diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/service/AppRegisterService.java b/fys-admin/src/main/java/com/fuyuanshen/web/service/AppRegisterService.java index 0270844..9b61425 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/web/service/AppRegisterService.java +++ b/fys-admin/src/main/java/com/fuyuanshen/web/service/AppRegisterService.java @@ -7,6 +7,7 @@ import com.fuyuanshen.app.mapper.AppUserMapper; import com.fuyuanshen.common.core.constant.Constants; import com.fuyuanshen.common.core.constant.GlobalConstants; import com.fuyuanshen.common.core.domain.model.AppSmsRegisterBody; +import com.fuyuanshen.common.core.enums.UserType; import com.fuyuanshen.common.core.exception.BadRequestException; import com.fuyuanshen.common.core.exception.user.CaptchaException; import com.fuyuanshen.common.core.exception.user.CaptchaExpireException; @@ -47,6 +48,7 @@ public class AppRegisterService { String phoneNumber = registerBody.getPhoneNumber(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(AppUser::getPhonenumber, phoneNumber); + wrapper.eq(AppUser::getUserType, UserType.APP_USER.getUserType()); AppUserVo appUserVo = appUserMapper.selectVoOne(wrapper); if (appUserVo != null) { throw new BadRequestException("该手机号已被注册"); @@ -67,7 +69,7 @@ public class AppRegisterService { appUser.setNickName(username); appUser.setPhonenumber(phoneNumber); appUser.setPassword(password); - appUser.setUserType("app_user"); + appUser.setUserType(UserType.APP_USER.getUserType()); appUser.setTenantId(tenantId); appUser.setLoginIp(ServletUtils.getClientIP()); appUser.setStatus("0"); diff --git a/fys-admin/src/main/resources/application-prod.yml b/fys-admin/src/main/resources/application-prod.yml index 1533e58..03a3b83 100644 --- a/fys-admin/src/main/resources/application-prod.yml +++ b/fys-admin/src/main/resources/application-prod.yml @@ -177,11 +177,14 @@ sms: # 框架定义的厂商名称标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分 supplier: alibaba # 有些称为accessKey有些称之为apiKey,也有称为sdkKey或者appId。 - access-key-id: 您的accessKey + access-key-id: LTAI5tJdDNpZootsPQ5hdELx # 称为accessSecret有些称之为apiSecret - access-key-secret: 您的accessKeySecret - signature: 您的短信签名 - sdk-app-id: 您的sdkAppId + access-key-secret: mU4WtffcCXpHPz5tLwQpaGtLsJXONt + #模板ID 非必须配置,如果使用sendMessage的快速发送需此配置 + template-id: SMS_322180518 + #模板变量 上述模板的变量 + templateName: code + signature: 湖北星汉研创科技 config2: # 厂商标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分 supplier: tencent @@ -277,11 +280,11 @@ justauth: # MQTT配置 mqtt: username: admin - password: #YtvpSfCNG - url: tcp://47.120.79.150:2883 + password: fys123456 + url: tcp://47.107.152.87:1883 subClientId: fys_subClient - subTopic: worker/alert/#,worker/location/# - pubTopic: worker/location + subTopic: A/#,worker/location/# + pubTopic: B/# pubClientId: fys_pubClient diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/controller/AppDeviceBindRecordController.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/controller/AppDeviceBindRecordController.java new file mode 100644 index 0000000..fc5c9cd --- /dev/null +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/controller/AppDeviceBindRecordController.java @@ -0,0 +1,105 @@ +package com.fuyuanshen.app.controller; + +import java.util.List; + +import lombok.RequiredArgsConstructor; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.constraints.*; +import cn.dev33.satoken.annotation.SaCheckPermission; +import org.springframework.web.bind.annotation.*; +import org.springframework.validation.annotation.Validated; +import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit; +import com.fuyuanshen.common.log.annotation.Log; +import com.fuyuanshen.common.web.core.BaseController; +import com.fuyuanshen.common.mybatis.core.page.PageQuery; +import com.fuyuanshen.common.core.domain.R; +import com.fuyuanshen.common.core.validate.AddGroup; +import com.fuyuanshen.common.core.validate.EditGroup; +import com.fuyuanshen.common.log.enums.BusinessType; +import com.fuyuanshen.common.excel.utils.ExcelUtil; +import com.fuyuanshen.app.domain.vo.AppDeviceBindRecordVo; +import com.fuyuanshen.app.domain.bo.AppDeviceBindRecordBo; +import com.fuyuanshen.app.service.IAppDeviceBindRecordService; +import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; + +/** + * 设备绑定关系 + * + * @author Lion Li + * @date 2025-07-28 + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/app/deviceBindRecord") +public class AppDeviceBindRecordController extends BaseController { + + private final IAppDeviceBindRecordService appDeviceBindRecordService; + + /** + * 查询设备绑定关系列表 + */ + @SaCheckPermission("app:deviceBindRecord:list") + @GetMapping("/list") + public TableDataInfo list(AppDeviceBindRecordBo bo, PageQuery pageQuery) { + return appDeviceBindRecordService.queryPageList(bo, pageQuery); + } + + /** + * 导出设备绑定关系列表 + */ + @SaCheckPermission("app:deviceBindRecord:export") + @Log(title = "设备绑定关系", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(AppDeviceBindRecordBo bo, HttpServletResponse response) { + List list = appDeviceBindRecordService.queryList(bo); + ExcelUtil.exportExcel(list, "设备绑定关系", AppDeviceBindRecordVo.class, response); + } + + /** + * 获取设备绑定关系详细信息 + * + * @param id 主键 + */ + @SaCheckPermission("app:deviceBindRecord:query") + @GetMapping("/{id}") + public R getInfo(@NotNull(message = "主键不能为空") + @PathVariable Long id) { + return R.ok(appDeviceBindRecordService.queryById(id)); + } + + /** + * 新增设备绑定关系 + */ + @SaCheckPermission("app:deviceBindRecord:add") + @Log(title = "设备绑定关系", businessType = BusinessType.INSERT) + @RepeatSubmit() + @PostMapping() + public R add(@Validated(AddGroup.class) @RequestBody AppDeviceBindRecordBo bo) { + return toAjax(appDeviceBindRecordService.insertByBo(bo)); + } + + /** + * 修改设备绑定关系 + */ + @SaCheckPermission("app:deviceBindRecord:edit") + @Log(title = "设备绑定关系", businessType = BusinessType.UPDATE) + @RepeatSubmit() + @PutMapping() + public R edit(@Validated(EditGroup.class) @RequestBody AppDeviceBindRecordBo bo) { + return toAjax(appDeviceBindRecordService.updateByBo(bo)); + } + + /** + * 删除设备绑定关系 + * + * @param ids 主键串 + */ + @SaCheckPermission("app:deviceBindRecord:remove") + @Log(title = "设备绑定关系", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public R remove(@NotEmpty(message = "主键不能为空") + @PathVariable Long[] ids) { + return toAjax(appDeviceBindRecordService.deleteWithValidByIds(List.of(ids), true)); + } +} diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/AppDeviceBindRecord.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/AppDeviceBindRecord.java new file mode 100644 index 0000000..40698ce --- /dev/null +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/AppDeviceBindRecord.java @@ -0,0 +1,53 @@ +package com.fuyuanshen.app.domain; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fuyuanshen.common.tenant.core.TenantEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serial; +import java.util.Date; + +/** + * 设备绑定关系对象 app_device_bind_record + * + * @author Lion Li + * @date 2025-07-28 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("app_device_bind_record") +public class AppDeviceBindRecord extends TenantEntity { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * 主键ID + */ + @TableId(value = "id") + private Long id; + + /** + * 设备id + */ + private Long deviceId; + + /** + * 绑定用户id + */ + private Long bindingUserId; + + /** + * 备注 + */ + private String remark; + + /** + * 绑定时间 + */ + private Date bindingTime; + + +} diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/bo/AppDeviceBindRecordBo.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/bo/AppDeviceBindRecordBo.java new file mode 100644 index 0000000..4742933 --- /dev/null +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/bo/AppDeviceBindRecordBo.java @@ -0,0 +1,51 @@ +package com.fuyuanshen.app.domain.bo; + +import com.fuyuanshen.app.domain.AppDeviceBindRecord; +import com.fuyuanshen.common.core.validate.EditGroup; +import com.fuyuanshen.common.mybatis.core.domain.BaseEntity; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; +import lombok.EqualsAndHashCode; +import jakarta.validation.constraints.*; +import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; + +/** + * 设备绑定关系业务对象 app_device_bind_record + * + * @author Lion Li + * @date 2025-07-28 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = AppDeviceBindRecord.class, reverseConvertGenerate = false) +public class AppDeviceBindRecordBo extends BaseEntity { + + /** + * 主键ID + */ + @NotNull(message = "主键ID不能为空", groups = { EditGroup.class }) + private Long id; + + /** + * 设备id + */ + private Long deviceId; + + /** + * 绑定用户id + */ + private Long bindingUserId; + + /** + * 备注 + */ + private String remark; + + /** + * 绑定时间 + */ + private Date bindingTime; + + +} diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/vo/AppDeviceBindRecordVo.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/vo/AppDeviceBindRecordVo.java new file mode 100644 index 0000000..206b3f9 --- /dev/null +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/vo/AppDeviceBindRecordVo.java @@ -0,0 +1,64 @@ +package com.fuyuanshen.app.domain.vo; + +import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fuyuanshen.app.domain.AppDeviceBindRecord; +import cn.idev.excel.annotation.ExcelIgnoreUnannotated; +import cn.idev.excel.annotation.ExcelProperty; +import com.fuyuanshen.common.excel.annotation.ExcelDictFormat; +import com.fuyuanshen.common.excel.convert.ExcelDictConvert; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; +import java.util.Date; + + + +/** + * 设备绑定关系视图对象 app_device_bind_record + * + * @author Lion Li + * @date 2025-07-28 + */ +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = AppDeviceBindRecord.class) +public class AppDeviceBindRecordVo implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * 主键ID + */ + @ExcelProperty(value = "主键ID") + private Long id; + + /** + * 设备id + */ + @ExcelProperty(value = "设备id") + private Long deviceId; + + /** + * 绑定用户id + */ + @ExcelProperty(value = "绑定用户id") + private Long bindingUserId; + + /** + * 备注 + */ + @ExcelProperty(value = "备注") + private String remark; + + /** + * 绑定时间 + */ + @ExcelProperty(value = "绑定时间") + private Date bindingTime; + + +} 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 new file mode 100644 index 0000000..2fa66a8 --- /dev/null +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/mapper/AppDeviceBindRecordMapper.java @@ -0,0 +1,15 @@ +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; + +/** + * 设备绑定关系Mapper接口 + * + * @author Lion Li + * @date 2025-07-28 + */ +public interface AppDeviceBindRecordMapper extends BaseMapperPlus { + +} 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 new file mode 100644 index 0000000..2d3a239 --- /dev/null +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/IAppDeviceBindRecordService.java @@ -0,0 +1,68 @@ +package com.fuyuanshen.app.service; + +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 java.util.Collection; +import java.util.List; + +/** + * 设备绑定关系Service接口 + * + * @author Lion Li + * @date 2025-07-28 + */ +public interface IAppDeviceBindRecordService { + + /** + * 查询设备绑定关系 + * + * @param id 主键 + * @return 设备绑定关系 + */ + AppDeviceBindRecordVo queryById(Long id); + + /** + * 分页查询设备绑定关系列表 + * + * @param bo 查询条件 + * @param pageQuery 分页参数 + * @return 设备绑定关系分页列表 + */ + TableDataInfo queryPageList(AppDeviceBindRecordBo bo, PageQuery pageQuery); + + /** + * 查询符合条件的设备绑定关系列表 + * + * @param bo 查询条件 + * @return 设备绑定关系列表 + */ + List queryList(AppDeviceBindRecordBo bo); + + /** + * 新增设备绑定关系 + * + * @param bo 设备绑定关系 + * @return 是否新增成功 + */ + Boolean insertByBo(AppDeviceBindRecordBo bo); + + /** + * 修改设备绑定关系 + * + * @param bo 设备绑定关系 + * @return 是否修改成功 + */ + Boolean updateByBo(AppDeviceBindRecordBo bo); + + /** + * 校验并批量删除设备绑定关系信息 + * + * @param ids 待删除的主键集合 + * @param isValid 是否进行有效性校验 + * @return 是否删除成功 + */ + Boolean deleteWithValidByIds(Collection ids, Boolean isValid); +} 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 new file mode 100644 index 0000000..59c9fd9 --- /dev/null +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/impl/AppDeviceBindRecordServiceImpl.java @@ -0,0 +1,133 @@ +package com.fuyuanshen.app.service.impl; + +import com.fuyuanshen.common.core.utils.MapstructUtils; +import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; +import com.fuyuanshen.common.mybatis.core.page.PageQuery; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import com.fuyuanshen.app.domain.bo.AppDeviceBindRecordBo; +import com.fuyuanshen.app.domain.vo.AppDeviceBindRecordVo; +import com.fuyuanshen.app.domain.AppDeviceBindRecord; +import com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper; +import com.fuyuanshen.app.service.IAppDeviceBindRecordService; + +import java.util.List; +import java.util.Map; +import java.util.Collection; + +/** + * 设备绑定关系Service业务层处理 + * + * @author Lion Li + * @date 2025-07-28 + */ +@Slf4j +@RequiredArgsConstructor +@Service +public class AppDeviceBindRecordServiceImpl implements IAppDeviceBindRecordService { + + private final AppDeviceBindRecordMapper baseMapper; + + /** + * 查询设备绑定关系 + * + * @param id 主键 + * @return 设备绑定关系 + */ + @Override + public AppDeviceBindRecordVo queryById(Long id){ + return baseMapper.selectVoById(id); + } + + /** + * 分页查询设备绑定关系列表 + * + * @param bo 查询条件 + * @param pageQuery 分页参数 + * @return 设备绑定关系分页列表 + */ + @Override + public TableDataInfo queryPageList(AppDeviceBindRecordBo bo, PageQuery pageQuery) { + LambdaQueryWrapper lqw = buildQueryWrapper(bo); + Page result = baseMapper.selectVoPage(pageQuery.build(), lqw); + return TableDataInfo.build(result); + } + + /** + * 查询符合条件的设备绑定关系列表 + * + * @param bo 查询条件 + * @return 设备绑定关系列表 + */ + @Override + public List queryList(AppDeviceBindRecordBo bo) { + LambdaQueryWrapper lqw = buildQueryWrapper(bo); + return baseMapper.selectVoList(lqw); + } + + private LambdaQueryWrapper buildQueryWrapper(AppDeviceBindRecordBo bo) { + Map params = bo.getParams(); + LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); + lqw.orderByAsc(AppDeviceBindRecord::getId); + lqw.eq(bo.getDeviceId() != null, AppDeviceBindRecord::getDeviceId, bo.getDeviceId()); + lqw.eq(bo.getBindingUserId() != null, AppDeviceBindRecord::getBindingUserId, bo.getBindingUserId()); + lqw.eq(bo.getBindingTime() != null, AppDeviceBindRecord::getBindingTime, bo.getBindingTime()); + return lqw; + } + + /** + * 新增设备绑定关系 + * + * @param bo 设备绑定关系 + * @return 是否新增成功 + */ + @Override + public Boolean insertByBo(AppDeviceBindRecordBo bo) { + AppDeviceBindRecord add = MapstructUtils.convert(bo, AppDeviceBindRecord.class); + validEntityBeforeSave(add); + boolean flag = baseMapper.insert(add) > 0; + if (flag) { + bo.setId(add.getId()); + } + return flag; + } + + /** + * 修改设备绑定关系 + * + * @param bo 设备绑定关系 + * @return 是否修改成功 + */ + @Override + public Boolean updateByBo(AppDeviceBindRecordBo bo) { + AppDeviceBindRecord update = MapstructUtils.convert(bo, AppDeviceBindRecord.class); + validEntityBeforeSave(update); + return baseMapper.updateById(update) > 0; + } + + /** + * 保存前的数据校验 + */ + private void validEntityBeforeSave(AppDeviceBindRecord entity){ + //TODO 做一些数据校验,如唯一约束 + } + + /** + * 校验并批量删除设备绑定关系信息 + * + * @param ids 待删除的主键集合 + * @param isValid 是否进行有效性校验 + * @return 是否删除成功 + */ + @Override + public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { + if(isValid){ + //TODO 做一些业务上的校验,判断是否需要校验 + } + return baseMapper.deleteByIds(ids) > 0; + } +} 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 new file mode 100644 index 0000000..a523cec --- /dev/null +++ b/fys-modules/fys-app/src/main/resources/mapper/app/AppDeviceBindRecordMapper.xml @@ -0,0 +1,7 @@ + + + + + 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 9a683ad..e54ae78 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 @@ -151,7 +151,8 @@ d.binding_time from device d inner join device_type dt on d.device_type = dt.id - where d.binding_user_id = #{criteria.bindingUserId} + inner join app_device_bind_record c on d.id = c.device_id + where c.binding_user_id = #{criteria.bindingUserId} and d.device_type = #{criteria.deviceType} From 2cb4f5b83ea720e6e8054fccc19b624c253a4e0e Mon Sep 17 00:00:00 2001 From: chenyouting <514333061@qq.com> Date: Fri, 1 Aug 2025 09:07:27 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E4=BC=98=E5=8C=962?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fuyuanshen/app/domain/AppDeviceBindRecord.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/AppDeviceBindRecord.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/AppDeviceBindRecord.java index 5abebed..40698ce 100644 --- a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/AppDeviceBindRecord.java +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/AppDeviceBindRecord.java @@ -1,5 +1,7 @@ package com.fuyuanshen.app.domain; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; import com.fuyuanshen.common.tenant.core.TenantEntity; import lombok.Data; import lombok.EqualsAndHashCode; From 4271085e7833adfc1e711a9f8a92835c816d5663 Mon Sep 17 00:00:00 2001 From: chenyouting <514333061@qq.com> Date: Fri, 1 Aug 2025 09:58:33 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=B3=A8=E9=94=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/controller/AppAuthController.java | 9 +- .../app/domain/dto/DeviceInstructDto.java | 2 +- .../app/service/AppDeviceBizService.java | 153 +++++++++++++++++- .../app/service/AppLoginService.java | 28 +++- 4 files changed, 178 insertions(+), 14 deletions(-) diff --git a/fys-admin/src/main/java/com/fuyuanshen/app/controller/AppAuthController.java b/fys-admin/src/main/java/com/fuyuanshen/app/controller/AppAuthController.java index 521b3ae..884690a 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/app/controller/AppAuthController.java +++ b/fys-admin/src/main/java/com/fuyuanshen/app/controller/AppAuthController.java @@ -92,7 +92,14 @@ public class AppAuthController { } - + /** + * 用户注销 + */ + @DeleteMapping("/cancelAccount") + public R cancelAccount() { + loginService.cancelAccount(); + return R.ok("用户注销成功"); + } /** * 退出登录 diff --git a/fys-admin/src/main/java/com/fuyuanshen/app/domain/dto/DeviceInstructDto.java b/fys-admin/src/main/java/com/fuyuanshen/app/domain/dto/DeviceInstructDto.java index f176699..074bed3 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/app/domain/dto/DeviceInstructDto.java +++ b/fys-admin/src/main/java/com/fuyuanshen/app/domain/dto/DeviceInstructDto.java @@ -11,6 +11,6 @@ public class DeviceInstructDto { /** * 下发指令 */ - private Object instructValue; + private String instructValue; } diff --git a/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java b/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java index 00fa94a..024f63b 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java +++ b/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java @@ -9,6 +9,8 @@ import com.fuyuanshen.app.domain.AppDeviceBindRecord; import com.fuyuanshen.app.domain.AppPersonnelInfo; import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo; import com.fuyuanshen.app.domain.dto.APPReNameDTO; +import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto; +import com.fuyuanshen.app.domain.dto.DeviceInstructDto; import com.fuyuanshen.app.domain.vo.APPDeviceTypeVo; import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo; import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo; @@ -16,10 +18,13 @@ import com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper; import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper; import com.fuyuanshen.app.mapper.equipment.APPDeviceMapper; import com.fuyuanshen.common.core.exception.ServiceException; +import com.fuyuanshen.common.core.utils.ImageToCArrayConverter; import com.fuyuanshen.common.core.utils.MapstructUtils; import com.fuyuanshen.common.core.utils.ObjectUtils; +import com.fuyuanshen.common.core.utils.StringUtils; import com.fuyuanshen.common.mybatis.core.page.PageQuery; import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; +import com.fuyuanshen.common.redis.utils.RedisUtils; import com.fuyuanshen.common.satoken.utils.AppLoginHelper; import com.fuyuanshen.equipment.domain.Device; import com.fuyuanshen.equipment.domain.DeviceType; @@ -32,16 +37,18 @@ import com.fuyuanshen.equipment.enums.CommunicationModeEnum; import com.fuyuanshen.equipment.mapper.DeviceMapper; import com.fuyuanshen.equipment.mapper.DeviceTypeMapper; import com.fuyuanshen.equipment.utils.c.ReliableTextToBitmap; -import com.fuyuanshen.system.mqtt.config.MqttGateway; -import com.fuyuanshen.system.mqtt.constants.MqttConstants; +import com.fuyuanshen.global.mqtt.config.MqttGateway; +import com.fuyuanshen.global.mqtt.constants.MqttConstants; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.time.Duration; +import java.util.*; + +import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY; +import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal; @Slf4j @@ -283,5 +290,139 @@ public class AppDeviceBizService { } + public void uploadDeviceLogo(AppDeviceLogoUploadDto bo) { + try { + Device device = deviceMapper.selectById(bo.getDeviceId()); + if (device == null) { + throw new ServiceException("设备不存在"); + } + MultipartFile file = bo.getFile(); + + byte[] largeData = ImageToCArrayConverter.convertImageToCArray(file.getInputStream(), 160, 80, 25600); + System.out.println("长度:" + largeData.length); + + System.out.println("原始数据大小: " + largeData.length + " 字节"); + + int[] ints = convertHexToDecimal(largeData); + RedisUtils.setCacheObject(GLOBAL_REDIS_KEY+"app_logo_data:" + device.getDeviceImei(), Arrays.toString(ints), Duration.ofSeconds(30 * 60L)); + + String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+"app_logo_data:" + device.getDeviceImei()); + + byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data); + byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512); + System.out.println("第0块数据大小: " + specificChunk.length + " 字节"); + System.out.println("第0块数据: " + Arrays.toString(specificChunk)); + + ArrayList intData = new ArrayList<>(); + intData.add(3); + intData.add(1); + ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk),intData); + intData.add(0); + intData.add(0); + intData.add(0); + intData.add(0); + Map map = new HashMap<>(); + map.put("instruct", intData); + mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , JSON.toJSONString(map)); + log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),JSON.toJSONString(map)); + } catch (Exception e){ + e.printStackTrace(); + } + } + + /** + * 灯光模式 + * 0(关灯),1(强光模式),2(弱光模式), 3(爆闪模式), 4(泛光模式) + */ + public void lightModeSettings(DeviceInstructDto params) { + try { + Long deviceId = params.getDeviceId(); + Device device = deviceMapper.selectById(deviceId); + if(device == null){ + throw new ServiceException("设备不存在"); + } + Integer instructValue = Integer.parseInt(params.getInstructValue()); + ArrayList intData = new ArrayList<>(); + intData.add(1); + intData.add(instructValue); + intData.add(0); + intData.add(0); + intData.add(0); + Map map = new HashMap<>(); + map.put("instruct", intData); + mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , JSON.toJSONString(map)); + log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),JSON.toJSONString(map)); + } catch (Exception e){ + e.printStackTrace(); + } + } + + //灯光亮度设置 + public void lightBrightnessSettings(DeviceInstructDto params) { + try { + Long deviceId = params.getDeviceId(); + Device device = deviceMapper.selectById(deviceId); + if(device == null){ + throw new ServiceException("设备不存在"); + } + String instructValue = params.getInstructValue(); + ArrayList intData = new ArrayList<>(); + intData.add(5); + String[] values = instructValue.split("\\."); + String value1 = values[0]; + String value2 = values[1]; + if(StringUtils.isNoneBlank(value1)){ + intData.add(Integer.parseInt(value1)); + } + if(StringUtils.isNoneBlank(value2)){ + intData.add(Integer.parseInt(value2)); + } + intData.add(0); + intData.add(0); + intData.add(0); + Map map = new HashMap<>(); + map.put("instruct", intData); + mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , JSON.toJSONString(map)); + log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),JSON.toJSONString(map)); + } catch (Exception e){ + e.printStackTrace(); + } + } + + //激光模式设置 + public void laserModeSettings(DeviceInstructDto params) { + try { + Long deviceId = params.getDeviceId(); + Device device = deviceMapper.selectById(deviceId); + if(device == null){ + throw new ServiceException("设备不存在"); + } + Integer instructValue = Integer.parseInt(params.getInstructValue()); + ArrayList intData = new ArrayList<>(); + intData.add(4); + intData.add(instructValue); + intData.add(0); + intData.add(0); + intData.add(0); + Map map = new HashMap<>(); + map.put("instruct", intData); + mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , JSON.toJSONString(map)); + log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),JSON.toJSONString(map)); + } catch (Exception e){ + e.printStackTrace(); + } + } + + public String mapReverseGeocoding(DeviceInstructDto params) { +// Long deviceId = params.getDeviceId(); +// Device device = deviceMapper.selectById(deviceId); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("device_imei", params.getDeviceImei()); + List devices = deviceMapper.selectList(queryWrapper); + if(ObjectUtils.length( devices) ==0){ + throw new ServiceException("设备不存在"); + } + return RedisUtils.getCacheObject("device:location:" + devices.get(0).getDeviceImei()); + } } 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 a9aa566..23b8d5b 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 @@ -28,10 +28,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.time.Duration; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashSet; -import java.util.Set; +import java.util.*; import java.util.function.Supplier; /** @@ -51,7 +48,7 @@ public class AppLoginService { private Integer lockTime; private final ISysTenantService tenantService; - private final IAppRoleService roleService; + private final IAppUserService appUserService; /** @@ -184,5 +181,24 @@ public class AppLoginService { throw new TenantException("tenant.expired"); } } - + public void cancelAccount() { + try { + AppLoginUser loginUser = AppLoginHelper.getLoginUser(); + if (ObjectUtil.isNull(loginUser)) { + return; + } + appUserService.deleteWithValidByIds(Collections.singletonList(loginUser.getUserId()),true); + if (TenantHelper.isEnable() && LoginHelper.isSuperAdmin()) { + // 超级管理员 登出清除动态租户 + TenantHelper.clearDynamic(); + } + recordLogininfor(loginUser.getTenantId(), loginUser.getUsername(), Constants.LOGOUT, "用户注销成功"); + } catch (NotLoginException ignored) { + } finally { + try { + StpUtil.logout(); + } catch (NotLoginException ignored) { + } + } + } }