feat: 物联网卡管理
This commit is contained in:
+128
@@ -0,0 +1,128 @@
|
||||
package com.central.device.controller;
|
||||
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.device.model.IotCard;
|
||||
import com.central.device.service.IIotCardService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 物联网卡管理
|
||||
*
|
||||
* @author system
|
||||
* @date 2026-03-27
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/iot-card")
|
||||
@Tag(name = "物联网卡管理")
|
||||
@RequiredArgsConstructor
|
||||
public class IotCardController {
|
||||
|
||||
private final IIotCardService iotCardService;
|
||||
|
||||
/**
|
||||
* 分页列表
|
||||
*/
|
||||
@Operation(summary = "查询物联网卡列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "page", description = "页码", required = true, in = ParameterIn.QUERY),
|
||||
@Parameter(name = "limit", description = "每页条数", required = true, in = ParameterIn.QUERY),
|
||||
@Parameter(name = "cardNumber", description = "卡号", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "deviceSn", description = "设备SN", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "enabled", description = "启用状态", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "carrier", description = "运营商", in = ParameterIn.QUERY)
|
||||
})
|
||||
@GetMapping
|
||||
public PageResult<IotCard> list(@RequestParam Map<String, Object> params) {
|
||||
return iotCardService.findList(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*/
|
||||
@Operation(summary = "查询物联网卡详情")
|
||||
@GetMapping("/{id}")
|
||||
public Result<IotCard> findById(@PathVariable Long id) {
|
||||
IotCard model = iotCardService.getById(id);
|
||||
return Result.succeed(model, "查询成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增或更新
|
||||
*/
|
||||
@Operation(summary = "新增/更新物联网卡")
|
||||
@PostMapping
|
||||
public Result<String> save(@RequestBody IotCard iotCard) {
|
||||
// 新增时校验卡号唯一
|
||||
if (iotCard.getId() == null && iotCard.getCardNumber() != null) {
|
||||
if (iotCardService.checkCardNumberExists(iotCard.getCardNumber())) {
|
||||
return Result.failed("卡号已存在");
|
||||
}
|
||||
}
|
||||
iotCardService.saveOrUpdate(iotCard);
|
||||
return Result.succeed("保存成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@Operation(summary = "删除物联网卡")
|
||||
@Parameter(name = "id", description = "物联网卡ID", in = ParameterIn.PATH, required = true)
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<String> delete(@PathVariable Long id) {
|
||||
iotCardService.removeById(id);
|
||||
return Result.succeed("删除成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定设备
|
||||
*/
|
||||
@Operation(summary = "绑定设备")
|
||||
@PostMapping("/{id}/bind")
|
||||
public Result<String> bindDevice(@PathVariable Long id, @RequestParam String deviceSn) {
|
||||
try {
|
||||
boolean result = iotCardService.bindDevice(id, deviceSn);
|
||||
return result ? Result.succeed("绑定成功") : Result.failed("绑定失败");
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.failed(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解绑设备
|
||||
*/
|
||||
@Operation(summary = "解绑设备")
|
||||
@PostMapping("/{id}/unbind")
|
||||
public Result<String> unbindDevice(@PathVariable Long id) {
|
||||
try {
|
||||
boolean result = iotCardService.unbindDevice(id);
|
||||
return result ? Result.succeed("解绑成功") : Result.failed("解绑失败");
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.failed(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用/停用
|
||||
*/
|
||||
@Operation(summary = "启用/停用物联网卡")
|
||||
@PutMapping("/{id}/toggle")
|
||||
public Result<String> toggleEnabled(@PathVariable Long id, @RequestParam Integer enabled) {
|
||||
try {
|
||||
boolean result = iotCardService.toggleEnabled(id, enabled);
|
||||
return result ? Result.succeed("操作成功") : Result.failed("操作失败");
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.failed(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -185,6 +185,12 @@ public class BoatRoute implements Serializable {
|
||||
@TableField(value = "create_by", fill = FieldFill.INSERT)
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 航线JSON文件URL(S3)
|
||||
*/
|
||||
@TableField("route_file_url")
|
||||
private String routeFileUrl;
|
||||
|
||||
/**
|
||||
* 删除标记
|
||||
*/
|
||||
|
||||
+9
@@ -73,6 +73,15 @@ public interface FileCenterService {
|
||||
@RequestParam(value = "batchSize", defaultValue = "100") int batchSize,
|
||||
@RequestParam(value = "area", required = false) String area);
|
||||
|
||||
/**
|
||||
* 上传文件到S3存储
|
||||
*
|
||||
* @param file 文件
|
||||
* @return 文件信息(含CDN URL)
|
||||
*/
|
||||
@PostMapping(value = "/files-S3", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
FileInfo uploadForS3(@RequestPart("file") MultipartFile file);
|
||||
|
||||
// ========== 3D模型文件上传相关接口 ==========
|
||||
|
||||
/**
|
||||
|
||||
+6
@@ -74,6 +74,12 @@ public class FileCenterServiceFallbackFactory implements FallbackFactory<FileCen
|
||||
return Result.failed("CDN批量预热文件失败: " + cause.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileInfo uploadForS3(MultipartFile file) {
|
||||
log.error("上传文件到S3失败: fileName={}", file != null ? file.getOriginalFilename() : "null", cause);
|
||||
return null;
|
||||
}
|
||||
|
||||
// ========== 3D模型文件上传相关接口 ==========
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.central.device.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.db.mapper.SuperMapper;
|
||||
import com.central.device.model.IotCard;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 物联网卡数据访问层
|
||||
*
|
||||
* @author system
|
||||
* @date 2026-03-27
|
||||
*/
|
||||
@Mapper
|
||||
public interface IotCardMapper extends SuperMapper<IotCard> {
|
||||
/**
|
||||
* 分页查询物联网卡列表
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @param params 查询条件
|
||||
* @return 物联网卡列表
|
||||
*/
|
||||
List<IotCard> findList(Page<IotCard> page, @Param("p") Map<String, Object> params);
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.central.device.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.central.common.model.SuperEntity;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 物联网卡实体
|
||||
*
|
||||
* @author system
|
||||
* @date 2026-03-27
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("iot_card")
|
||||
public class IotCard extends SuperEntity {
|
||||
|
||||
/**
|
||||
* 卡号(ICCID)
|
||||
*/
|
||||
private String cardNumber;
|
||||
|
||||
/**
|
||||
* MSISDN号码(手机号)
|
||||
*/
|
||||
private String msisdn;
|
||||
|
||||
/**
|
||||
* IMSI号码
|
||||
*/
|
||||
private String imsi;
|
||||
|
||||
/**
|
||||
* 运营商:1-中国移动,2-中国联通,3-中国电信
|
||||
*/
|
||||
private Integer carrier;
|
||||
|
||||
/**
|
||||
* 套餐类型/流量套餐描述
|
||||
*/
|
||||
private String packageType;
|
||||
|
||||
/**
|
||||
* 启用状态:0-停用,1-启用
|
||||
*/
|
||||
private Integer enabled;
|
||||
|
||||
/**
|
||||
* 绑定设备SN
|
||||
*/
|
||||
private String deviceSn;
|
||||
|
||||
/**
|
||||
* 绑定设备名称(冗余字段,方便展示)
|
||||
*/
|
||||
private String deviceName;
|
||||
|
||||
/**
|
||||
* 激活时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date activationTime;
|
||||
|
||||
/**
|
||||
* 到期时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date expirationTime;
|
||||
|
||||
/**
|
||||
* 所属租户ID
|
||||
*/
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 逻辑删除:0-未删除,1-已删除
|
||||
*/
|
||||
@TableLogic
|
||||
private Integer isDel;
|
||||
}
|
||||
+3
@@ -83,6 +83,9 @@ public class BoatRouteDetailVO {
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "航线JSON文件URL")
|
||||
private String routeFileUrl;
|
||||
|
||||
@Schema(description = "航点列表")
|
||||
private List<BoatWaypointVO> waypoints;
|
||||
|
||||
|
||||
+3
@@ -55,6 +55,9 @@ public class BoatRouteListVO {
|
||||
@Schema(description = "规划水域边界ID")
|
||||
private String boundaryId;
|
||||
|
||||
@Schema(description = "航线JSON文件URL")
|
||||
private String routeFileUrl;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package com.central.device.service;
|
||||
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.service.ISuperService;
|
||||
import com.central.device.model.IotCard;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 物联网卡服务接口
|
||||
*
|
||||
* @author system
|
||||
* @date 2026-03-27
|
||||
*/
|
||||
public interface IIotCardService extends ISuperService<IotCard> {
|
||||
|
||||
/**
|
||||
* 分页查询物联网卡列表
|
||||
*
|
||||
* @param params 查询条件(page、limit、cardNumber、deviceSn、enabled 等)
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResult<IotCard> findList(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 根据卡号查询物联网卡
|
||||
*
|
||||
* @param cardNumber 卡号
|
||||
* @return 物联网卡
|
||||
*/
|
||||
IotCard getByCardNumber(String cardNumber);
|
||||
|
||||
/**
|
||||
* 检查卡号是否已存在
|
||||
*
|
||||
* @param cardNumber 卡号
|
||||
* @return 是否存在
|
||||
*/
|
||||
boolean checkCardNumberExists(String cardNumber);
|
||||
|
||||
/**
|
||||
* 绑定设备
|
||||
*
|
||||
* @param id 物联网卡ID
|
||||
* @param deviceSn 设备SN
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean bindDevice(Long id, String deviceSn);
|
||||
|
||||
/**
|
||||
* 解绑设备
|
||||
*
|
||||
* @param id 物联网卡ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean unbindDevice(Long id);
|
||||
|
||||
/**
|
||||
* 启用/停用物联网卡
|
||||
*
|
||||
* @param id 物联网卡ID
|
||||
* @param enabled 启用状态:0-停用,1-启用
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean toggleEnabled(Long id, Integer enabled);
|
||||
}
|
||||
+99
@@ -9,6 +9,7 @@ import com.central.common.context.LoginUserContextHolder;
|
||||
import com.central.common.exception.BusinessException;
|
||||
import com.central.device.entity.BoatRoute;
|
||||
import com.central.device.entity.BoatWaypoint;
|
||||
import com.central.device.feign.FileCenterService;
|
||||
import com.central.device.mapper.BoatRouteMapper;
|
||||
import com.central.device.mapper.BoatWaypointMapper;
|
||||
import com.central.device.model.dto.BoatRouteCreateDTO;
|
||||
@@ -18,11 +19,20 @@ import com.central.device.model.dto.PointDTO;
|
||||
import com.central.device.model.vo.*;
|
||||
import com.central.device.service.IBoatRouteService;
|
||||
import com.central.device.service.IWaterBoundaryService;
|
||||
import com.central.common.model.FileInfo;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
@@ -44,6 +54,7 @@ public class BoatRouteServiceImpl extends ServiceImpl<BoatRouteMapper, BoatRoute
|
||||
|
||||
private final BoatWaypointMapper waypointMapper;
|
||||
private final IWaterBoundaryService waterBoundaryService;
|
||||
private final FileCenterService fileCenterService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@@ -207,6 +218,10 @@ public class BoatRouteServiceImpl extends ServiceImpl<BoatRouteMapper, BoatRoute
|
||||
}
|
||||
|
||||
this.updateById(route);
|
||||
// 已发布航线更新后重新生成并上传JSON文件
|
||||
if (BoatRoute.RouteStatus.PUBLISHED.getCode().equals(route.getStatus())) {
|
||||
generateAndUploadRouteJson(routeId);
|
||||
}
|
||||
log.info("航线更新成功: routeId={}", routeId);
|
||||
}
|
||||
|
||||
@@ -472,6 +487,8 @@ public class BoatRouteServiceImpl extends ServiceImpl<BoatRouteMapper, BoatRoute
|
||||
throw new BusinessException("只有草稿状态的航线才能发布");
|
||||
}
|
||||
updateStatus(routeId, BoatRoute.RouteStatus.PUBLISHED.getCode());
|
||||
// 发布时生成航线JSON文件并上传到S3
|
||||
generateAndUploadRouteJson(routeId);
|
||||
log.info("航线发布成功: routeId={}", routeId);
|
||||
}
|
||||
|
||||
@@ -561,4 +578,86 @@ public class BoatRouteServiceImpl extends ServiceImpl<BoatRouteMapper, BoatRoute
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成航线JSON文件并上传到S3,将返回的URL存入航线表
|
||||
*/
|
||||
private void generateAndUploadRouteJson(String routeId) {
|
||||
try {
|
||||
// 1. 获取航线详情(含航点)
|
||||
BoatRouteDetailVO detail = getRouteDetail(routeId);
|
||||
|
||||
// 2. 序列化为JSON
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.registerModule(new JavaTimeModule());
|
||||
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
byte[] jsonBytes = objectMapper.writerWithDefaultPrettyPrinter()
|
||||
.writeValueAsBytes(detail);
|
||||
|
||||
// 3. 构造MultipartFile
|
||||
String fileName = "route_" + routeId + ".json";
|
||||
MultipartFile multipartFile = new InMemoryMultipartFile(
|
||||
"file", fileName, "application/json", jsonBytes);
|
||||
// 4. 通过Feign上传到S3
|
||||
FileInfo fileInfo = fileCenterService.uploadForS3(multipartFile);
|
||||
if (fileInfo == null || fileInfo.getUrl() == null) {
|
||||
log.warn("航线JSON上传S3返回为空: routeId={}", routeId);
|
||||
return;
|
||||
}
|
||||
|
||||
// 5. 将URL存入航线表
|
||||
BoatRoute route = getByRouteId(routeId);
|
||||
if (route != null) {
|
||||
route.setRouteFileUrl(fileInfo.getUrl());
|
||||
this.updateById(route);
|
||||
log.info("航线JSON文件上传成功: routeId={}, url={}", routeId, fileInfo.getUrl());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 上传失败不影响主流程,仅记录日志
|
||||
log.error("航线JSON文件生成或上传失败: routeId={}", routeId, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 内存MultipartFile实现,用于将字节数组包装为MultipartFile通过Feign上传
|
||||
*/
|
||||
private static class InMemoryMultipartFile implements MultipartFile {
|
||||
private final String name;
|
||||
private final String originalFilename;
|
||||
private final String contentType;
|
||||
private final byte[] content;
|
||||
|
||||
InMemoryMultipartFile(String name, String originalFilename, String contentType, byte[] content) {
|
||||
this.name = name;
|
||||
this.originalFilename = originalFilename;
|
||||
this.contentType = contentType;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() { return name; }
|
||||
|
||||
@Override
|
||||
public String getOriginalFilename() { return originalFilename; }
|
||||
|
||||
@Override
|
||||
public String getContentType() { return contentType; }
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() { return content.length == 0; }
|
||||
|
||||
@Override
|
||||
public long getSize() { return content.length; }
|
||||
|
||||
@Override
|
||||
public byte[] getBytes() { return content; }
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() { return new ByteArrayInputStream(content); }
|
||||
|
||||
@Override
|
||||
public void transferTo(File dest) throws IOException, IllegalStateException {
|
||||
java.nio.file.Files.write(dest.toPath(), content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
package com.central.device.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.feign.UserService;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.service.impl.SuperServiceImpl;
|
||||
import com.central.device.mapper.IotCardMapper;
|
||||
import com.central.device.model.AgeDevice;
|
||||
import com.central.device.model.IotCard;
|
||||
import com.central.device.service.IAgeDeviceService;
|
||||
import com.central.device.service.IIotCardService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 物联网卡服务实现
|
||||
*
|
||||
* @author system
|
||||
* @date 2026-03-27
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class IotCardServiceImpl extends SuperServiceImpl<IotCardMapper, IotCard> implements IIotCardService {
|
||||
|
||||
@Autowired
|
||||
private UserService userCenterService;
|
||||
|
||||
@Autowired
|
||||
private IAgeDeviceService ageDeviceService;
|
||||
|
||||
@Override
|
||||
public PageResult<IotCard> findList(Map<String, Object> params) {
|
||||
Page<IotCard> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
|
||||
String anchor = MapUtils.getString(params, "tenantId");
|
||||
try {
|
||||
if (anchor == null || anchor.isEmpty()) {
|
||||
anchor = com.central.common.context.TenantQueryOverrideContext.getTenantId();
|
||||
if (anchor == null || anchor.isEmpty()) {
|
||||
anchor = com.central.common.context.LoginUserContextHolder.getCurrentTenantId();
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
log.error("获取当前登录用户租户失败");
|
||||
}
|
||||
List<String> tenantIds = userCenterService.getSonTenantIds(anchor);
|
||||
params.put("tenantIds", tenantIds);
|
||||
List<IotCard> list = baseMapper.findList(page, params);
|
||||
return PageResult.<IotCard>builder().data(list).resp_code(0).count(page.getTotal()).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IotCard getByCardNumber(String cardNumber) {
|
||||
return this.getOne(new QueryWrapper<IotCard>().eq("card_number", cardNumber).eq("is_del", 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkCardNumberExists(String cardNumber) {
|
||||
return this.baseMapper.exists(new QueryWrapper<IotCard>().eq("card_number", cardNumber).eq("is_del", 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean bindDevice(Long id, String deviceSn) {
|
||||
IotCard card = this.getById(id);
|
||||
if (card == null) {
|
||||
throw new IllegalArgumentException("物联网卡不存在");
|
||||
}
|
||||
// 查询设备信息,回填设备名称
|
||||
AgeDevice device = ageDeviceService.getByDeviceSn(deviceSn);
|
||||
card.setDeviceSn(deviceSn);
|
||||
card.setDeviceName(device != null ? device.getDeviceName() : null);
|
||||
boolean result = this.updateById(card);
|
||||
if (result) {
|
||||
log.info("物联网卡绑定设备成功: cardNumber={}, deviceSn={}", card.getCardNumber(), deviceSn);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean unbindDevice(Long id) {
|
||||
IotCard card = this.getById(id);
|
||||
if (card == null) {
|
||||
throw new IllegalArgumentException("物联网卡不存在");
|
||||
}
|
||||
String oldDeviceSn = card.getDeviceSn();
|
||||
// 使用 UpdateWrapper 显式将字段置为 null,避免 MyBatis-Plus 默认策略跳过 null 值
|
||||
boolean result = this.update(
|
||||
new com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper<IotCard>()
|
||||
.set("device_sn", null)
|
||||
.set("device_name", null)
|
||||
.eq("id", id)
|
||||
);
|
||||
if (result) {
|
||||
log.info("物联网卡解绑设备成功: cardNumber={}, oldDeviceSn={}", card.getCardNumber(), oldDeviceSn);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean toggleEnabled(Long id, Integer enabled) {
|
||||
IotCard card = this.getById(id);
|
||||
if (card == null) {
|
||||
throw new IllegalArgumentException("物联网卡不存在");
|
||||
}
|
||||
card.setEnabled(enabled);
|
||||
boolean result = this.updateById(card);
|
||||
if (result) {
|
||||
log.info("物联网卡状态变更: cardNumber={}, enabled={}", card.getCardNumber(), enabled);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user