forked from dyf/fys-Multi-tenant
设备绑定优化
This commit is contained in:
@ -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<APPDeviceTypeVo> 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<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
|
||||
bindRecordQueryWrapper.eq("device_id", device.getId());
|
||||
AppDeviceBindRecord appDeviceBindRecord = appDeviceBindRecordMapper.selectOne(bindRecordQueryWrapper);
|
||||
if (appDeviceBindRecord != null) {
|
||||
UpdateWrapper<AppDeviceBindRecord> 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<Device> 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<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
|
||||
bindRecordQueryWrapper.eq("device_id", device.getId());
|
||||
bindRecordQueryWrapper.eq("binding_user_id", userId);
|
||||
AppDeviceBindRecord appDeviceBindRecord = appDeviceBindRecordMapper.selectOne(bindRecordQueryWrapper);
|
||||
if (appDeviceBindRecord != null) {
|
||||
UpdateWrapper<AppDeviceBindRecord> 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<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
deviceUpdateWrapper.eq("id", device.getId())
|
||||
.set("binding_status", BindingStatusEnum.BOUND.getCode())
|
||||
@ -159,10 +198,21 @@ public class AppDeviceBizService {
|
||||
}
|
||||
UpdateWrapper<Device> 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<AppDeviceBindRecord> 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) {
|
||||
|
@ -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<AppUser> 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");
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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<AppDeviceBindRecordVo> 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<AppDeviceBindRecordVo> list = appDeviceBindRecordService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "设备绑定关系", AppDeviceBindRecordVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备绑定关系详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@SaCheckPermission("app:deviceBindRecord:query")
|
||||
@GetMapping("/{id}")
|
||||
public R<AppDeviceBindRecordVo> 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<Void> 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<Void> 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<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable Long[] ids) {
|
||||
return toAjax(appDeviceBindRecordService.deleteWithValidByIds(List.of(ids), true));
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
|
||||
}
|
@ -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<AppDeviceBindRecord, AppDeviceBindRecordVo> {
|
||||
|
||||
}
|
@ -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<AppDeviceBindRecordVo> queryPageList(AppDeviceBindRecordBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询符合条件的设备绑定关系列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @return 设备绑定关系列表
|
||||
*/
|
||||
List<AppDeviceBindRecordVo> 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<Long> ids, Boolean isValid);
|
||||
}
|
@ -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<AppDeviceBindRecordVo> queryPageList(AppDeviceBindRecordBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<AppDeviceBindRecord> lqw = buildQueryWrapper(bo);
|
||||
Page<AppDeviceBindRecordVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询符合条件的设备绑定关系列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @return 设备绑定关系列表
|
||||
*/
|
||||
@Override
|
||||
public List<AppDeviceBindRecordVo> queryList(AppDeviceBindRecordBo bo) {
|
||||
LambdaQueryWrapper<AppDeviceBindRecord> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<AppDeviceBindRecord> buildQueryWrapper(AppDeviceBindRecordBo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
LambdaQueryWrapper<AppDeviceBindRecord> 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<Long> ids, Boolean isValid) {
|
||||
if(isValid){
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper">
|
||||
|
||||
</mapper>
|
@ -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}
|
||||
<if test="criteria.deviceType != null">
|
||||
and d.device_type = #{criteria.deviceType}
|
||||
</if>
|
||||
|
Reference in New Issue
Block a user