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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?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.central.device.mapper.IotCardMapper">
|
||||
<select id="findList" resultType="com.central.device.model.IotCard">
|
||||
select * from iot_card t where t.is_del = 0
|
||||
<if test="p.cardNumber != null and p.cardNumber != ''">
|
||||
and t.card_number like concat('%', #{p.cardNumber}, '%')
|
||||
</if>
|
||||
<if test="p.msisdn != null and p.msisdn != ''">
|
||||
and t.msisdn like concat('%', #{p.msisdn}, '%')
|
||||
</if>
|
||||
<if test="p.deviceSn != null and p.deviceSn != ''">
|
||||
and t.device_sn = #{p.deviceSn}
|
||||
</if>
|
||||
<if test="p.enabled != null and p.enabled != ''">
|
||||
and t.enabled = #{p.enabled}
|
||||
</if>
|
||||
<if test="p.carrier != null and p.carrier != ''">
|
||||
and t.carrier = #{p.carrier}
|
||||
</if>
|
||||
<if test="p.tenantIds != null and p.tenantIds.size > 0">
|
||||
AND t.tenant_id IN
|
||||
<foreach collection="p.tenantIds" item="tid" open="(" separator="," close=")">
|
||||
#{tid}
|
||||
</foreach>
|
||||
</if>
|
||||
order by t.id desc
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,25 @@
|
||||
-- 物联网卡管理表
|
||||
-- 使用前请确认目标数据库
|
||||
CREATE TABLE IF NOT EXISTS `iot_card` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`card_number` VARCHAR(32) NOT NULL COMMENT '卡号(ICCID)',
|
||||
`msisdn` VARCHAR(20) DEFAULT NULL COMMENT 'MSISDN号码(手机号)',
|
||||
`imsi` VARCHAR(20) DEFAULT NULL COMMENT 'IMSI号码',
|
||||
`carrier` TINYINT DEFAULT NULL COMMENT '运营商:1-中国移动,2-中国联通,3-中国电信',
|
||||
`package_type` VARCHAR(100) DEFAULT NULL COMMENT '套餐类型/流量套餐描述',
|
||||
`enabled` TINYINT NOT NULL DEFAULT 1 COMMENT '启用状态:0-停用,1-启用',
|
||||
`device_sn` VARCHAR(64) DEFAULT NULL COMMENT '绑定设备SN',
|
||||
`device_name` VARCHAR(128) DEFAULT NULL COMMENT '绑定设备名称',
|
||||
`activation_time` DATETIME DEFAULT NULL COMMENT '激活时间',
|
||||
`expiration_time` DATETIME DEFAULT NULL COMMENT '到期时间',
|
||||
`tenant_id` VARCHAR(32) DEFAULT NULL COMMENT '所属租户ID',
|
||||
`remark` VARCHAR(500) DEFAULT NULL COMMENT '备注',
|
||||
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`is_del` TINYINT NOT NULL DEFAULT 0 COMMENT '逻辑删除:0-未删除,1-已删除',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_card_number` (`card_number`),
|
||||
KEY `idx_device_sn` (`device_sn`),
|
||||
KEY `idx_tenant_id` (`tenant_id`),
|
||||
KEY `idx_enabled` (`enabled`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='物联网卡管理表';
|
||||
@@ -16,7 +16,8 @@ ALTER TABLE `3d_model_file`
|
||||
ADD COLUMN `device_name` VARCHAR(100) DEFAULT NULL COMMENT '关联设备名称'
|
||||
AFTER `device_sn`;
|
||||
|
||||
ALTER TABLE `3d_model_file`
|
||||
ADD INDEX `idx_device_sn` (`device_sn`);
|
||||
ALTER TABLE `3d_model_file` ADD INDEX `idx_device_sn` (`device_sn`);
|
||||
|
||||
ALTER TABLE boat_route ADD COLUMN route_file_url VARCHAR(512) DEFAULT NULL COMMENT '航线JSON文件URL(S3)' AFTER remark;
|
||||
|
||||
--
|
||||
@@ -61,4 +61,10 @@ public class OrderFavorite extends SuperEntity {
|
||||
|
||||
@TableField(exist = false)
|
||||
private Date orderCreateTime;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Long orderUserId;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String phone;
|
||||
}
|
||||
|
||||
+31
@@ -1,24 +1,33 @@
|
||||
package com.central.order.service.impl;
|
||||
|
||||
import com.alibaba.csp.sentinel.util.StringUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.context.LoginUserContextHolder;
|
||||
import com.central.common.feign.UserService;
|
||||
import com.central.common.model.LoginAppUser;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.model.SysUser;
|
||||
import com.central.common.service.impl.SuperServiceImpl;
|
||||
import com.central.order.mapper.OrderFavoriteMapper;
|
||||
import com.central.order.model.Order;
|
||||
import com.central.order.model.OrderFavorite;
|
||||
import com.central.order.service.IOrderFavoriteService;
|
||||
import com.central.order.service.IOrderService;
|
||||
import com.central.order.util.StringUtils;
|
||||
import com.central.wechat.entity.WechatConfig;
|
||||
import com.central.wechat.feign.WechatConfigService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 订单收藏
|
||||
@@ -33,12 +42,34 @@ public class OrderFavoriteServiceImpl extends SuperServiceImpl<OrderFavoriteMapp
|
||||
@Autowired
|
||||
private IOrderService orderService;
|
||||
|
||||
@Resource
|
||||
private UserService userCenterService;
|
||||
|
||||
@Autowired
|
||||
private WechatConfigService wechatConfigService;
|
||||
|
||||
@Override
|
||||
public PageResult<OrderFavorite> findList(Map<String, Object> params) {
|
||||
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||
Page<OrderFavorite> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
|
||||
params.put("userId", user.getId());
|
||||
List<OrderFavorite> list = baseMapper.findList(page, params);
|
||||
for(OrderFavorite orderFavorite:list){
|
||||
if(Objects.nonNull(orderFavorite.getOrderUserId())){
|
||||
//获取手机号
|
||||
SysUser orderUser = userCenterService.findUserById(orderFavorite.getOrderUserId());
|
||||
if(Objects.nonNull(orderUser)){
|
||||
orderFavorite.setPhone(orderUser.getMobile());
|
||||
}
|
||||
}
|
||||
//获取资金去向
|
||||
if(StringUtil.isNotBlank(orderFavorite.getTenantId())){
|
||||
WechatConfig wechatConfig = wechatConfigService.getConfig("PAY",orderFavorite.getTenantId());
|
||||
if(wechatConfig!=null){
|
||||
orderFavorite.setCompany(wechatConfig.getSubMchName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return PageResult.<OrderFavorite>builder().data(list).resp_code(0).count(page.getTotal()).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
<mapper namespace="com.central.order.mapper.OrderFavoriteMapper">
|
||||
|
||||
<select id="findList" resultType="com.central.order.model.OrderFavorite">
|
||||
select t.id, t.user_id, t.order_id, t.order_no, t.create_time, t.tenant_id, t.company,
|
||||
select t.id, t.user_id, t.order_id, t.order_no, t.create_time, qr.tenant_id as tenant_id, t.company,
|
||||
o.device_sn, o.tourism_id, o.order_amount, o.order_status, o.pay_type, o.pay_time,
|
||||
o.create_time as order_create_time,
|
||||
o.create_time as order_create_time, o.user_id as order_user_id,
|
||||
tr.tourism_name as tourism_name
|
||||
from order_favorite t
|
||||
left join orders o on t.order_id = o.id
|
||||
left join tourisms tr on o.tourism_id = tr.id
|
||||
left join qrcodes qr on o.code_id= qr.code_id
|
||||
<where>
|
||||
<if test="p.userId != null">
|
||||
and t.user_id = #{p.userId}
|
||||
|
||||
Reference in New Issue
Block a user