refactor(iot): 重构 IoT 模块代码
- 优化了多个控制器、服务和 mapper 类的实现 - 删除了不必要的代码和注释 - 改进了查询逻辑,使用 LambdaQueryWrapper替代复杂的 XML 配置- 统一了分页查询的实现方式 - 删除了未使用的 AttachmentVo 类 -调整了 Event 和 Product 相关的 mapper 配置
This commit is contained in:
parent
1c1c9586e6
commit
f6a12e2b35
@ -1,5 +1,8 @@
|
||||
//package com.zsc.edu.gateway.framework.response;
|
||||
//
|
||||
//import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
//import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
//import jakarta.annotation.Resource;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.core.MethodParameter;
|
||||
//import org.springframework.http.HttpHeaders;
|
||||
@ -23,6 +26,9 @@
|
||||
//@RestControllerAdvice(basePackages = "com.zsc.edu.gateway")
|
||||
//public class GlobalResponseHandler implements ResponseBodyAdvice<Object> {
|
||||
//
|
||||
// @Resource
|
||||
// private ObjectMapper objectMapper;
|
||||
//
|
||||
// /**
|
||||
// * 此组件是否支持给定的控制器方法返回类型和选定的 {@code HttpMessageConverter} 类型。
|
||||
// *
|
||||
@ -56,6 +62,10 @@
|
||||
// headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
// // 2. 将 ResponseResult 转为 Json字符串 再返回
|
||||
// // (否则会报错 java.lang.ClassCastException: com.example.core.model.ResponseResult cannot be cast to java.lang.String)
|
||||
// return JsonUtil.toJson(responseResult);
|
||||
// try {
|
||||
// return objectMapper.writeValueAsString(responseResult);
|
||||
// } catch (JsonProcessingException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
@ -1,93 +1,93 @@
|
||||
package com.zsc.edu.gateway.framework.response;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Http状态返回枚举
|
||||
*
|
||||
* @author javadog
|
||||
**/
|
||||
@Getter
|
||||
public enum HttpStatusEnum {
|
||||
|
||||
|
||||
/**
|
||||
* 操作成功
|
||||
*/
|
||||
SUCCESS(200, "操作成功"),
|
||||
/**
|
||||
* 对象创建成功
|
||||
*/
|
||||
CREATED(201, "对象创建成功"),
|
||||
/**
|
||||
* 请求已经被接受
|
||||
*/
|
||||
ACCEPTED(202, "请求已经被接受"),
|
||||
/**
|
||||
* 操作已经执行成功,但是没有返回数据
|
||||
*/
|
||||
NO_CONTENT(204, "操作已经执行成功,但是没有返回数据"),
|
||||
/**
|
||||
* 资源已被移除
|
||||
*/
|
||||
MOVED_PERM(301, "资源已被移除"),
|
||||
/**
|
||||
* 重定向
|
||||
*/
|
||||
SEE_OTHER(303, "重定向"),
|
||||
/**
|
||||
* 资源没有被修改
|
||||
*/
|
||||
NOT_MODIFIED(304, "资源没有被修改"),
|
||||
/**
|
||||
* 参数列表错误(缺少,格式不匹配)
|
||||
*/
|
||||
BAD_REQUEST(400, "参数列表错误(缺少,格式不匹配)"),
|
||||
/**
|
||||
* 未授权
|
||||
*/
|
||||
UNAUTHORIZED(401, "未授权"),
|
||||
/**
|
||||
* 访问受限,授权过期
|
||||
*/
|
||||
FORBIDDEN(403, "访问受限,授权过期"),
|
||||
/**
|
||||
* 资源,服务未找到
|
||||
*/
|
||||
NOT_FOUND(404, "资源,服务未找!"),
|
||||
/**
|
||||
* 不允许的http方法
|
||||
*/
|
||||
BAD_METHOD(405, "不允许的http方法"),
|
||||
/**
|
||||
* 资源冲突,或者资源被锁
|
||||
*/
|
||||
CONFLICT(409, "资源冲突,或者资源被锁"),
|
||||
/**
|
||||
* 不支持的数据,媒体类型
|
||||
*/
|
||||
UNSUPPORTED_TYPE(415, "不支持的数据,媒体类型"),
|
||||
/**
|
||||
* 系统内部错误
|
||||
*/
|
||||
ERROR(500, "系统内部错误"),
|
||||
/**
|
||||
* 接口未实现
|
||||
*/
|
||||
NOT_IMPLEMENTED(501, "接口未实现"),
|
||||
/**
|
||||
* 系统警告消息
|
||||
*/
|
||||
WARN(601, "系统警告消息");
|
||||
|
||||
private final Integer code;
|
||||
private final String message;
|
||||
|
||||
HttpStatusEnum(Integer code, String message) {
|
||||
|
||||
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
//package com.zsc.edu.gateway.framework.response;
|
||||
//
|
||||
//import lombok.Getter;
|
||||
//
|
||||
///**
|
||||
// * Http状态返回枚举
|
||||
// *
|
||||
// * @author javadog
|
||||
// **/
|
||||
//@Getter
|
||||
//public enum HttpStatusEnum {
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 操作成功
|
||||
// */
|
||||
// SUCCESS(200, "操作成功"),
|
||||
// /**
|
||||
// * 对象创建成功
|
||||
// */
|
||||
// CREATED(201, "对象创建成功"),
|
||||
// /**
|
||||
// * 请求已经被接受
|
||||
// */
|
||||
// ACCEPTED(202, "请求已经被接受"),
|
||||
// /**
|
||||
// * 操作已经执行成功,但是没有返回数据
|
||||
// */
|
||||
// NO_CONTENT(204, "操作已经执行成功,但是没有返回数据"),
|
||||
// /**
|
||||
// * 资源已被移除
|
||||
// */
|
||||
// MOVED_PERM(301, "资源已被移除"),
|
||||
// /**
|
||||
// * 重定向
|
||||
// */
|
||||
// SEE_OTHER(303, "重定向"),
|
||||
// /**
|
||||
// * 资源没有被修改
|
||||
// */
|
||||
// NOT_MODIFIED(304, "资源没有被修改"),
|
||||
// /**
|
||||
// * 参数列表错误(缺少,格式不匹配)
|
||||
// */
|
||||
// BAD_REQUEST(400, "参数列表错误(缺少,格式不匹配)"),
|
||||
// /**
|
||||
// * 未授权
|
||||
// */
|
||||
// UNAUTHORIZED(401, "未授权"),
|
||||
// /**
|
||||
// * 访问受限,授权过期
|
||||
// */
|
||||
// FORBIDDEN(403, "访问受限,授权过期"),
|
||||
// /**
|
||||
// * 资源,服务未找到
|
||||
// */
|
||||
// NOT_FOUND(404, "资源,服务未找!"),
|
||||
// /**
|
||||
// * 不允许的http方法
|
||||
// */
|
||||
// BAD_METHOD(405, "不允许的http方法"),
|
||||
// /**
|
||||
// * 资源冲突,或者资源被锁
|
||||
// */
|
||||
// CONFLICT(409, "资源冲突,或者资源被锁"),
|
||||
// /**
|
||||
// * 不支持的数据,媒体类型
|
||||
// */
|
||||
// UNSUPPORTED_TYPE(415, "不支持的数据,媒体类型"),
|
||||
// /**
|
||||
// * 系统内部错误
|
||||
// */
|
||||
// ERROR(500, "系统内部错误"),
|
||||
// /**
|
||||
// * 接口未实现
|
||||
// */
|
||||
// NOT_IMPLEMENTED(501, "接口未实现"),
|
||||
// /**
|
||||
// * 系统警告消息
|
||||
// */
|
||||
// WARN(601, "系统警告消息");
|
||||
//
|
||||
// private final Integer code;
|
||||
// private final String message;
|
||||
//
|
||||
// HttpStatusEnum(Integer code, String message) {
|
||||
//
|
||||
//
|
||||
// this.code = code;
|
||||
// this.message = message;
|
||||
// }
|
||||
//}
|
||||
//
|
||||
|
@ -1,24 +0,0 @@
|
||||
package com.zsc.edu.gateway.framework.response;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class JsonUtil {
|
||||
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* 将对象转换为 JSON 字符串
|
||||
*
|
||||
* @param obj 需要转换的对象
|
||||
* @return JSON 字符串
|
||||
* @throws RuntimeException 如果转换过程中发生异常
|
||||
*/
|
||||
public static String toJson(Object obj) {
|
||||
try {
|
||||
return objectMapper.writeValueAsString(obj);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException("Failed to convert object to JSON", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -14,7 +14,6 @@
|
||||
//@NoArgsConstructor
|
||||
//public class ResponseResult<T> {
|
||||
//
|
||||
////TODO 返回封装处理
|
||||
// /**
|
||||
// * 状态码
|
||||
// */
|
||||
|
@ -1,51 +1,51 @@
|
||||
package com.zsc.edu.gateway.framework.response;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* 返回响应,统一封装实体
|
||||
*
|
||||
* @param <T> 数据实体泛型
|
||||
* @author zhuang
|
||||
*/
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class Result<T> {
|
||||
|
||||
private String userMessage;
|
||||
|
||||
/**
|
||||
* 错误码<br>
|
||||
* 调用成功时,为 null。<br>
|
||||
* 示例:A0211
|
||||
*/
|
||||
private String errorCode;
|
||||
|
||||
/**
|
||||
* 错误信息<br>
|
||||
* 调用成功时,为 null。<br>
|
||||
* 示例:"用户输入密码错误次数超限"
|
||||
*/
|
||||
private String errorMessage;
|
||||
|
||||
/**
|
||||
* 数据实体(泛型)<br>
|
||||
* 当接口没有返回数据时,为 null。
|
||||
*/
|
||||
private T data;
|
||||
|
||||
|
||||
public static <T> Result<T> success(T data) {
|
||||
return new Result<>("操作成功!", null, null, data);
|
||||
}
|
||||
|
||||
|
||||
public static <T> Result<T> fail(String userMessage, String errorCode, String errorMessage) {
|
||||
return new Result<>(userMessage, errorCode, errorMessage, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//package com.zsc.edu.gateway.framework.response;
|
||||
//
|
||||
//import lombok.*;
|
||||
//
|
||||
///**
|
||||
// * 返回响应,统一封装实体
|
||||
// *
|
||||
// * @param <T> 数据实体泛型
|
||||
// * @author zhuang
|
||||
// */
|
||||
//@Getter
|
||||
//@ToString
|
||||
//@EqualsAndHashCode
|
||||
//@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
//public class Result<T> {
|
||||
//
|
||||
// private String userMessage;
|
||||
//
|
||||
// /**
|
||||
// * 错误码<br>
|
||||
// * 调用成功时,为 null。<br>
|
||||
// * 示例:A0211
|
||||
// */
|
||||
// private String errorCode;
|
||||
//
|
||||
// /**
|
||||
// * 错误信息<br>
|
||||
// * 调用成功时,为 null。<br>
|
||||
// * 示例:"用户输入密码错误次数超限"
|
||||
// */
|
||||
// private String errorMessage;
|
||||
//
|
||||
// /**
|
||||
// * 数据实体(泛型)<br>
|
||||
// * 当接口没有返回数据时,为 null。
|
||||
// */
|
||||
// private T data;
|
||||
//
|
||||
//
|
||||
// public static <T> Result<T> success(T data) {
|
||||
// return new Result<>("操作成功!", null, null, data);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public static <T> Result<T> fail(String userMessage, String errorCode, String errorMessage) {
|
||||
// return new Result<>(userMessage, errorCode, errorMessage, null);
|
||||
// }
|
||||
//
|
||||
//}
|
||||
//
|
||||
//
|
||||
|
@ -8,6 +8,7 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.ContentDisposition;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.parameters.P;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@ -81,7 +82,6 @@ public class AttachmentController {
|
||||
|
||||
/**
|
||||
* 批量上传附件
|
||||
* TODO multipartFile
|
||||
*/
|
||||
@PostMapping("multipartFile")
|
||||
public List<Attachment> uploadMultipleFiles(
|
||||
@ -100,9 +100,9 @@ public class AttachmentController {
|
||||
/**
|
||||
* 根据附件ID删除附件信息
|
||||
*/
|
||||
//TODO 上传时没有url
|
||||
@DeleteMapping("delete/{id}")
|
||||
public Boolean delete(@PathVariable("id") String id) {
|
||||
return service.removeById(id);
|
||||
return service.delete(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,4 +23,6 @@ public interface AttachmentService extends IService<Attachment> {
|
||||
Attachment.Wrapper loadAsWrapper(String id);
|
||||
|
||||
List<Attachment> selectList(List<String> dis);
|
||||
|
||||
Boolean delete(String id);
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import org.apache.tika.Tika;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@ -208,4 +209,17 @@ public class AttachmentServiceImpl extends ServiceImpl<AttachmentRepository, Att
|
||||
return repo.selectList(new LambdaQueryWrapper<Attachment>().in(Attachment::getId, dis));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean delete(String id) {
|
||||
if (Files.exists(attachmentPath.resolve(id))) {
|
||||
try {
|
||||
repo.deleteById(id);
|
||||
Files.delete(attachmentPath.resolve(id));
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
log.error("删除文件失败", e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
package com.zsc.edu.gateway.modules.attachment.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Data
|
||||
public class AttachmentVo {
|
||||
/**
|
||||
* 附件ID
|
||||
*/
|
||||
public String attachmentId;
|
||||
/**
|
||||
* 附件地址
|
||||
*/
|
||||
public String url;
|
||||
/**
|
||||
* 附件名称
|
||||
*/
|
||||
public String fileName;
|
||||
}
|
@ -9,8 +9,8 @@ import com.zsc.edu.gateway.modules.iot.device.entity.Device;
|
||||
import com.zsc.edu.gateway.modules.iot.device.query.DeviceQuery;
|
||||
import com.zsc.edu.gateway.modules.iot.device.service.DeviceService;
|
||||
import com.zsc.edu.gateway.modules.iot.device.vo.DeviceVo;
|
||||
import com.zsc.edu.gateway.modules.iot.record.entity.Record;
|
||||
import com.zsc.edu.gateway.modules.iot.record.service.RecordService;
|
||||
import com.zsc.edu.gateway.modules.iot.record.entity.RecordData;
|
||||
import com.zsc.edu.gateway.modules.iot.record.service.RecordDataService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -28,7 +28,7 @@ public class DeviceController {
|
||||
|
||||
DeviceService service;
|
||||
|
||||
RecordService recordService;
|
||||
RecordDataService recordService;
|
||||
|
||||
/**
|
||||
* 创建设备
|
||||
@ -60,10 +60,9 @@ public class DeviceController {
|
||||
/**
|
||||
* 查询设备
|
||||
*/
|
||||
//TODO IPage的分页条数问题
|
||||
@GetMapping
|
||||
public IPage<DeviceVo> query(Page<DeviceVo> page, DeviceQuery query) {
|
||||
return service.query(page, query);
|
||||
public Page<Device> query(Page<Device> page, DeviceQuery query) {
|
||||
return service.page(page, query.wrapper());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,23 +95,11 @@ public class DeviceController {
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 查询设备上报记录
|
||||
// *
|
||||
// * @param clientId 设备的查询表单
|
||||
// * @param page 分页参数
|
||||
// * @return Page<Device> 设备分页数据
|
||||
// */
|
||||
// @GetMapping("record")
|
||||
// public Page<Record> pageRecord(String clientId,Page<Record> page) Pageable pageable) {
|
||||
// return recordService.page(clientId, pageable);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 查询设备上报记录
|
||||
*/
|
||||
@GetMapping("record/photo")
|
||||
public List<Record> recordPhoto(String clientId) {
|
||||
public List<RecordData> recordPhoto(String clientId) {
|
||||
return recordService.recordPhoto(clientId);
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,13 @@
|
||||
package com.zsc.edu.gateway.modules.iot.device.query;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.zsc.edu.gateway.modules.iot.device.entity.Device;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
@ -29,11 +33,20 @@ public class DeviceQuery {
|
||||
/**
|
||||
* 设备状态
|
||||
*/
|
||||
public Device.Status status;
|
||||
public Device.Status state;
|
||||
/**
|
||||
* 设态是否在线
|
||||
*/
|
||||
public Boolean isOnline;
|
||||
|
||||
|
||||
public LambdaQueryWrapper<Device> wrapper() {
|
||||
LambdaQueryWrapper<Device> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.like(StringUtils.hasText(this.name), Device::getName, this.name);
|
||||
queryWrapper.eq(StringUtils.hasText(this.clientId), Device::getClientId, this.clientId);
|
||||
queryWrapper.eq(Objects.nonNull(this.productId), Device::getProductId, this.productId);
|
||||
queryWrapper.eq(Objects.nonNull(this.isOnline), Device::getOnline, this.isOnline);
|
||||
queryWrapper.eq(Objects.nonNull(this.state), Device::getState, this.state);
|
||||
return queryWrapper;
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceRepository, Device> imp
|
||||
deviceDto.setProperties(dto.getProperties());
|
||||
deviceDto.setFirmwareVersion(dto.getFirmwareVersion());
|
||||
Device device = mapper.toEntity(deviceDto);
|
||||
Integer typeCode = Integer.valueOf(product.getTypeString());
|
||||
Integer typeCode = Integer.valueOf(product.getProductType());
|
||||
device.setClientId(String.format("%s%02d%02d%05d", "001", typeCode, 3, i + 1));
|
||||
devices.add(device);
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ public class DeviceVo {
|
||||
/**
|
||||
* 产品类型
|
||||
*/
|
||||
private String typeString;
|
||||
private String productType;
|
||||
|
||||
/**
|
||||
* 产品型号
|
||||
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.modules.iot.product.dto.ProductDto;
|
||||
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
|
||||
import com.zsc.edu.gateway.modules.iot.product.query.ProductQuery;
|
||||
import com.zsc.edu.gateway.modules.iot.product.service.ProductService;
|
||||
import com.zsc.edu.gateway.modules.iot.product.service.impl.ProductServiceImpl;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@ -23,7 +24,8 @@ import java.util.Collection;
|
||||
@RequestMapping("api/rest/product")
|
||||
public class ProductController {
|
||||
|
||||
private final ProductServiceImpl service;
|
||||
private final ProductService service;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@ -57,22 +59,21 @@ public class ProductController {
|
||||
* @return Page<Device> 产品分页数据
|
||||
*/
|
||||
@GetMapping
|
||||
public IPage<Product> page(Page<Product> page, ProductQuery query) {
|
||||
return service.page(page, query);
|
||||
public Page<Product> page(Page<Product> page, ProductQuery query) {
|
||||
return service.page(page, query.wrapper());
|
||||
}
|
||||
|
||||
//TODO 怎么写查询
|
||||
// /**
|
||||
// * 模糊查询部门,最多返回5条数据
|
||||
// *
|
||||
// * @param query 查询参数
|
||||
// * @return 部门列表
|
||||
// */
|
||||
// @GetMapping("fuzzy")
|
||||
// @PreAuthorize("hasAnyAuthority('DEVICE_CREATE', 'DEVICE_UPDATE')")
|
||||
// public Collection<Product> fuzzyQuery(ProductQuery query) {
|
||||
// return service.list(query.name);
|
||||
// }
|
||||
/**
|
||||
* 模糊查询名字,最多返回5条数据
|
||||
*
|
||||
* @param query 查询参数
|
||||
* @return 部门列表
|
||||
*/
|
||||
@GetMapping("fuzzy")
|
||||
@PreAuthorize("hasAnyAuthority('DEVICE_CREATE', 'DEVICE_UPDATE')")
|
||||
public Page<Product> fuzzyQuery(Page<Product> page, ProductQuery query) {
|
||||
return service.page(page, query.wrapper());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除产品
|
||||
|
@ -34,7 +34,7 @@ public class Product extends BaseEntity {
|
||||
/**
|
||||
* 产品类型
|
||||
*/
|
||||
private String typeString;
|
||||
private String productType;
|
||||
|
||||
/**
|
||||
* 产品型号
|
||||
|
@ -3,12 +3,13 @@ package com.zsc.edu.gateway.modules.iot.product.mapper;
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.iot.product.dto.ProductDto;
|
||||
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.mapper.ParamMapper;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author lenovo
|
||||
*/
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
@Mapper(componentModel = "spring", uses = {ParamMapper.class}, unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface ProductMapper extends BaseMapper<ProductDto, Product> {
|
||||
}
|
||||
|
@ -1,6 +1,12 @@
|
||||
package com.zsc.edu.gateway.modules.iot.product.query;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
|
||||
import lombok.Data;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
@ -20,7 +26,17 @@ public class ProductQuery {
|
||||
/**
|
||||
* 接入方式
|
||||
*/
|
||||
public String links;
|
||||
public List<String> links;
|
||||
|
||||
public LambdaQueryWrapper<Product> wrapper() {
|
||||
LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(StringUtils.hasText(this.name), Product::getName, this.name);
|
||||
queryWrapper.eq(StringUtils.hasText(this.type), Product::getProductType, this.type);
|
||||
if (Objects.nonNull(this.links) && !this.links.isEmpty()) {
|
||||
queryWrapper.in(Product::getLink, this.links);
|
||||
}
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
package com.zsc.edu.gateway.modules.iot.product.repo;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
|
||||
import com.zsc.edu.gateway.modules.iot.product.query.ProductQuery;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
@ -17,7 +18,7 @@ public interface ProductRepository extends BaseMapper<Product> {
|
||||
@Select("select * from iot_product where name=#{name}")
|
||||
Product findByName(@Param("name") String name);
|
||||
|
||||
IPage<Product> page(Page<Product> page, @Param("query") ProductQuery query);
|
||||
Page<Product> page(Page<Product> page, @Param(Constants.WRAPPER) LambdaQueryWrapper<Product> wrapper);
|
||||
|
||||
Product selectById(@Param("id") Long id);
|
||||
}
|
||||
|
@ -15,7 +15,9 @@ public interface ProductService extends IService<Product> {
|
||||
|
||||
Product update(ProductDto dto, Long id);
|
||||
|
||||
IPage<Product> page(Page<Product> page, ProductQuery query);
|
||||
// Page<Product> page(Page<Product> page, ProductQuery query);
|
||||
|
||||
Product detail(Long id);
|
||||
|
||||
boolean delete(Long id);
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package com.zsc.edu.gateway.modules.iot.product.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zsc.edu.gateway.exception.ConstraintException;
|
||||
import com.zsc.edu.gateway.modules.iot.product.dto.ProductDto;
|
||||
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
|
||||
import com.zsc.edu.gateway.modules.iot.product.entity.ProductParam;
|
||||
import com.zsc.edu.gateway.modules.iot.product.mapper.ProductMapper;
|
||||
import com.zsc.edu.gateway.modules.iot.product.query.ProductQuery;
|
||||
import com.zsc.edu.gateway.modules.iot.product.repo.ProductParamRepository;
|
||||
import com.zsc.edu.gateway.modules.iot.product.repo.ProductRepository;
|
||||
@ -16,10 +16,10 @@ import com.zsc.edu.gateway.modules.iot.tsl.dto.ParamDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Param;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.mapper.ParamMapper;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.repo.ParamRepository;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.service.ParamService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@ -29,9 +29,11 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
public class ProductServiceImpl extends ServiceImpl<ProductRepository, Product> implements ProductService {
|
||||
private final ProductMapper mapper;
|
||||
private final ParamMapper paramMapper;
|
||||
private final ParamRepository paramRepo;
|
||||
private final ProductParamRepository productParamRepo;
|
||||
private final ParamService paramService;
|
||||
|
||||
/**
|
||||
* 新建产品
|
||||
@ -41,24 +43,9 @@ public class ProductServiceImpl extends ServiceImpl<ProductRepository, Product>
|
||||
if (baseMapper.findByName(dto.getName()) != null) {
|
||||
throw new ConstraintException("该设备已存在!");
|
||||
}
|
||||
Product product = new Product();
|
||||
product.setName(dto.getName());
|
||||
product.setTypeString(dto.getType());
|
||||
product.setModel(dto.getModel());
|
||||
product.setLink(dto.getLink());
|
||||
Product product = mapper.toEntity(dto);
|
||||
save(product);
|
||||
List<Long> paramIds = new ArrayList<>();
|
||||
if (dto.getParams() != null) {
|
||||
dto.getParams().forEach(paramDto -> {
|
||||
Param param = paramMapper.toEntity(paramDto);
|
||||
paramRepo.insert(param);
|
||||
paramIds.add(param.getId());
|
||||
});
|
||||
}
|
||||
List<ProductParam> productParams = paramIds.stream()
|
||||
.map(paramId -> new ProductParam(product.getId(), paramId))
|
||||
.toList();
|
||||
productParamRepo.insert(productParams);
|
||||
productParamRepo.insert(paramService.productParamCreate(dto, product.getId()));
|
||||
return product;
|
||||
}
|
||||
/**
|
||||
@ -66,45 +53,24 @@ public class ProductServiceImpl extends ServiceImpl<ProductRepository, Product>
|
||||
*/
|
||||
@Override
|
||||
public Product update(ProductDto dto, Long id) {
|
||||
// 更新产品信息
|
||||
this.lambdaUpdate().eq(Product::getId, id)
|
||||
.set(Product::getName, dto.getName())
|
||||
.set(Product::getTypeString, dto.getType())
|
||||
.set(Product::getModel, dto.getModel())
|
||||
.set(Product::getLink, dto.getLink())
|
||||
.update();
|
||||
// 通过联表获取paramIds
|
||||
LambdaQueryWrapper<ProductParam> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ProductParam::getProductId, id);
|
||||
List<ProductParam> productParams = productParamRepo.selectList(wrapper);
|
||||
List<Long> paramIds = productParams.stream()
|
||||
.map(ProductParam::getParamId)
|
||||
.toList();
|
||||
//通过paramIds查询出所有param
|
||||
List<Param> params = paramRepo.selectByIds(paramIds);
|
||||
//更新param参数
|
||||
if (dto.getParams() != null && !dto.getParams().isEmpty()) {
|
||||
for (int i = 0; i < dto.getParams().size(); i++) {
|
||||
ParamDto paramDto = dto.getParams().get(i);
|
||||
Param param = params.get(i);
|
||||
paramMapper.convert(paramDto, param);
|
||||
paramRepo.updateById(param);
|
||||
}
|
||||
}
|
||||
return this.getById(id);
|
||||
Product product = baseMapper.selectById(id);
|
||||
mapper.convert(dto, product);
|
||||
updateById(product);
|
||||
paramService.productParamUpdate(dto.getParams(), id);
|
||||
return product;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询产品
|
||||
*
|
||||
* @param query 查询表单
|
||||
* @param page 分页参数
|
||||
*/
|
||||
// /**
|
||||
// * 分页查询产品
|
||||
// *
|
||||
// * @param query 查询表单
|
||||
// * @param page 分页参数
|
||||
// */
|
||||
// @Override
|
||||
// public Page<Product> page(Page<Product> page, ProductQuery query) {
|
||||
// return baseMapper.page(page, query.wrapper());
|
||||
// }
|
||||
@Override
|
||||
public IPage<Product> page(Page<Product> page, ProductQuery query) {
|
||||
return baseMapper.page(page, query);
|
||||
}
|
||||
|
||||
public Product detail(Long id) {
|
||||
return baseMapper.selectById(id);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.zsc.edu.gateway.modules.iot.record.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Date;
|
||||
@ -14,9 +13,7 @@ import java.util.Map;
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("iot_record")
|
||||
public class Record {
|
||||
//TODO 这个类的建表方式
|
||||
public class RecordData {
|
||||
@TableId
|
||||
private String id;
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.zsc.edu.gateway.modules.iot.record.repo;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.iot.record.entity.RecordData;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
public interface RecordDataRepository extends BaseMapper<RecordData> {
|
||||
List<RecordData> findAllByClientIdAndRecordTimeAfter(String clientId, LocalDateTime recordTime);
|
||||
|
||||
List<RecordData> findByRecordTimeStr(String recordTimeStr);
|
||||
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.zsc.edu.gateway.modules.iot.record.repo;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.iot.record.entity.Record;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
public interface RecordRepository extends BaseMapper<Record> {
|
||||
List<Record> findAllByClientIdAndRecordTimeAfter(String clientId, LocalDateTime recordTime);
|
||||
|
||||
List<Record> findByRecordTimeStr(String recordTimeStr);
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.zsc.edu.gateway.modules.iot.record.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zsc.edu.gateway.modules.iot.record.entity.RecordData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
public interface RecordDataService extends IService<RecordData> {
|
||||
RecordData create(RecordData record);
|
||||
|
||||
List<RecordData> page(IPage<RecordData> page, String clientId);
|
||||
|
||||
List<RecordData> recordPhoto(String clientId);
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.zsc.edu.gateway.modules.iot.record.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zsc.edu.gateway.modules.iot.record.entity.Record;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
public interface RecordService extends IService<Record> {
|
||||
Record create(Record record);
|
||||
|
||||
List<Record> page(IPage<Record> page, String clientId);
|
||||
|
||||
List<Record> recordPhoto(String clientId);
|
||||
}
|
@ -4,10 +4,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zsc.edu.gateway.framework.redis.RedisUtils;
|
||||
import com.zsc.edu.gateway.modules.iot.record.entity.Record;
|
||||
import com.zsc.edu.gateway.modules.iot.record.repo.RecordRepository;
|
||||
import com.zsc.edu.gateway.modules.iot.record.service.RecordService;
|
||||
import jakarta.annotation.Resource;
|
||||
import com.zsc.edu.gateway.modules.iot.record.entity.RecordData;
|
||||
import com.zsc.edu.gateway.modules.iot.record.repo.RecordDataRepository;
|
||||
import com.zsc.edu.gateway.modules.iot.record.service.RecordDataService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -21,28 +20,28 @@ import java.util.Optional;
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
public class RecordServiceImpl extends ServiceImpl<RecordRepository, Record> implements RecordService {
|
||||
public class RecordDataDataServiceImpl extends ServiceImpl<RecordDataRepository, RecordData> implements RecordDataService {
|
||||
RedisUtils redisUtils;
|
||||
@Override
|
||||
public Record create(Record record) {
|
||||
public RecordData create(RecordData record) {
|
||||
save(record);
|
||||
return record;
|
||||
}
|
||||
@Override
|
||||
public List<Record> page(IPage<Record> page, String clientId) {
|
||||
LambdaQueryWrapper<Record> queryWrapper = new LambdaQueryWrapper<>();
|
||||
public List<RecordData> page(IPage<RecordData> page, String clientId) {
|
||||
LambdaQueryWrapper<RecordData> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (clientId != null) {
|
||||
queryWrapper.eq(Record::getClientId, clientId);
|
||||
queryWrapper.eq(RecordData::getClientId, clientId);
|
||||
return baseMapper.selectList(page, queryWrapper);
|
||||
}
|
||||
return baseMapper.selectList(page, queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Record> recordPhoto(String clientId) {
|
||||
public List<RecordData> recordPhoto(String clientId) {
|
||||
LocalDateTime recordTime = LocalDateTime.parse(redisUtils.get("serve:sendTime:photograph:" + clientId));
|
||||
List<Record> records = baseMapper.findAllByClientIdAndRecordTimeAfter(clientId, recordTime);
|
||||
Optional<Record> first = records.stream().max(Comparator.comparing(Record::getRecordTime));
|
||||
List<RecordData> records = baseMapper.findAllByClientIdAndRecordTimeAfter(clientId, recordTime);
|
||||
Optional<RecordData> first = records.stream().max(Comparator.comparing(RecordData::getRecordTime));
|
||||
if (first.isPresent()) {
|
||||
String recordTimeStr = (String) first.get().getContent().get("recordTimeStr");
|
||||
return baseMapper.findByRecordTimeStr(recordTimeStr);
|
@ -25,7 +25,6 @@ public class EventController {
|
||||
* 创建事件
|
||||
*
|
||||
* @param dto 创建的事件
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
public Event create(@RequestBody EventDto dto) {
|
||||
@ -52,20 +51,10 @@ public class EventController {
|
||||
* @return Page<Device> 事件分页数据
|
||||
*/
|
||||
@GetMapping
|
||||
public IPage<Event> page(Page<Event> page, EventQuery query) {
|
||||
return service.page(page, query);
|
||||
public Page<Event> page(Page<Event> page, EventQuery query) {
|
||||
return service.page(page, query.wrapper());
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 查询事件
|
||||
// *
|
||||
// * @param query 事件的查询表单
|
||||
// * @return Page<Device> 事件分页数据
|
||||
// */
|
||||
// @GetMapping("list")
|
||||
// public List<Event> list(EventQuery query) {
|
||||
// return service.findByProductId(query.productId);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 删除事件
|
||||
|
@ -55,17 +55,6 @@ public class PropertyController {
|
||||
public Page<Property> query(PropertyQuery query, Page<Property> page) {
|
||||
return service.page(page, query.wrapper());
|
||||
}
|
||||
// /**
|
||||
// * 查询属性
|
||||
// *
|
||||
// * @param query 属性的查询表单
|
||||
// * @return Page<Device> 属性分页数据
|
||||
// */
|
||||
// @GetMapping("list")
|
||||
// public List<Property> list(PropertyQuery query) {
|
||||
// return service.findByProductIdAndIoType(query);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 删除属性
|
||||
*
|
||||
|
@ -52,20 +52,9 @@ public class ServeController {
|
||||
* @return Page<Device> 服务分页数据
|
||||
*/
|
||||
@GetMapping
|
||||
public IPage<Serve> page(Page<Serve> page, ServeQuery query) {
|
||||
return serveService.page(page, query);
|
||||
public Page<Serve> page(Page<Serve> page, ServeQuery query) {
|
||||
return serveService.page(page, query.wrapper());
|
||||
}
|
||||
//
|
||||
// /**
|
||||
// * 查询服务
|
||||
// *
|
||||
// * @param query 服务的查询表单
|
||||
// * @return Page<Device> 服务分页数据
|
||||
// */
|
||||
// @GetMapping("list")
|
||||
// public List<Serve> list(ServeQuery query) {
|
||||
// return serveService.findByProductId(query.productId);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 删除服务
|
||||
|
@ -6,6 +6,9 @@ import com.zsc.edu.gateway.modules.iot.tsl.entity.Event;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Mapper(componentModel = "spring", uses = {ParamMapper.class}, unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface EventMapper extends BaseMapper<EventDto, Event> {
|
||||
}
|
||||
|
@ -3,6 +3,12 @@ package com.zsc.edu.gateway.modules.iot.tsl.mapper;
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.ParamDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Param;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface ParamMapper extends BaseMapper<ParamDto, Param> {
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author Yao
|
||||
* @author zhuang
|
||||
*/
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface PropertyMapper extends BaseMapper<PropertyDto, Property> {
|
||||
|
@ -6,6 +6,9 @@ import com.zsc.edu.gateway.modules.iot.tsl.entity.Serve;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Mapper(componentModel = "spring", uses = {ParamMapper.class}, unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface ServeMapper extends BaseMapper<ServeDto, Serve> {
|
||||
}
|
||||
|
@ -1,6 +1,12 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.query;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Event;
|
||||
import lombok.Data;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
@ -31,4 +37,13 @@ public class EventQuery {
|
||||
*/
|
||||
public Long productId;
|
||||
|
||||
public LambdaQueryWrapper<Event> wrapper() {
|
||||
LambdaQueryWrapper<Event> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.like(StringUtils.hasText(this.name), Event::getName, this.name);
|
||||
queryWrapper.eq(StringUtils.hasText(this.identifier), Event::getIdentifier, this.identifier);
|
||||
queryWrapper.eq(StringUtils.hasText(this.level), Event::getType, this.level);
|
||||
queryWrapper.eq(Objects.nonNull(this.productId), Event::getProductId, this.productId);
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,12 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.query;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Event;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Serve;
|
||||
import lombok.Data;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author 15864
|
||||
@ -22,4 +28,12 @@ public class ServeQuery {
|
||||
* 名称
|
||||
*/
|
||||
public Long productId;
|
||||
|
||||
public LambdaQueryWrapper<Serve> wrapper() {
|
||||
LambdaQueryWrapper<Serve> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.like(StringUtils.hasText(this.name), Serve::getName, this.name);
|
||||
queryWrapper.eq(StringUtils.hasText(this.identifier), Serve::getIdentifier, this.identifier);
|
||||
queryWrapper.eq(Objects.nonNull(this.productId), Serve::getProductId, this.productId);
|
||||
return queryWrapper;
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public interface EventRepository extends BaseMapper<Event> {
|
||||
|
||||
// List<Event> findByProductId(Long productId);
|
||||
|
||||
IPage<Event> page(Page<Event> page, @Param("query") EventQuery query);
|
||||
// IPage<Event> page(Page<Event> page, @Param("query") EventQuery query);
|
||||
|
||||
Event selectById(@Param("id") Long id);
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import java.util.List;
|
||||
public interface PropertyRepository extends BaseMapper<Property> {
|
||||
|
||||
|
||||
IPage<Property> page(Page<Property> page, @Param("query") PropertyQuery query);
|
||||
// IPage<Property> page(Page<Property> page, @Param("query") PropertyQuery query);
|
||||
|
||||
Property selectById(@Param("id") Long id);
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public interface ServeRepository extends BaseMapper<Serve> {
|
||||
|
||||
// List<Serve> findByProductId(Long productId);
|
||||
|
||||
IPage<Serve> page(Page<Serve> page, @Param("query") ServeQuery query);
|
||||
// IPage<Serve> page(Page<Serve> page, @Param("query") ServeQuery query);
|
||||
|
||||
Serve selectById(@Param("id") Long id);
|
||||
|
||||
|
@ -15,7 +15,7 @@ public interface EventService extends IService<Event> {
|
||||
|
||||
Event update(EventDto dto, Long id);
|
||||
|
||||
IPage<Event> page(Page<Event> page, EventQuery query);
|
||||
// IPage<Event> page(Page<Event> page, EventQuery query);
|
||||
|
||||
Event detail(Long id);
|
||||
|
||||
|
@ -0,0 +1,30 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zsc.edu.gateway.modules.iot.product.dto.ProductDto;
|
||||
import com.zsc.edu.gateway.modules.iot.product.entity.ProductParam;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.EventDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.ParamDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.ServeDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.EventParam;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Param;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.ServeParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
public interface ParamService extends IService<Param> {
|
||||
List<EventParam> eventParamCreate(EventDto dto, Long eventId);
|
||||
|
||||
List<ProductParam> productParamCreate(ProductDto dto, Long productId);
|
||||
|
||||
List<ServeParam> serveParamCreate(ServeDto dto, Long serveId);
|
||||
|
||||
boolean eventParamUpdate(List<ParamDto> paramDto, Long eventId);
|
||||
|
||||
boolean productParamUpdate(List<ParamDto> paramDto, Long productId);
|
||||
|
||||
boolean serveParamUpdate(List<ParamDto> paramDto, Long serveId);
|
||||
}
|
@ -15,7 +15,7 @@ public interface ServeService extends IService<Serve> {
|
||||
|
||||
Serve update(ServeDto dto, Long id);
|
||||
|
||||
IPage<Serve> page(Page<Serve> page, ServeQuery query);
|
||||
// IPage<Serve> page(Page<Serve> page, ServeQuery query);
|
||||
|
||||
Serve detail(Long id);
|
||||
|
||||
|
@ -17,6 +17,7 @@ import com.zsc.edu.gateway.modules.iot.tsl.repo.EventParamRepository;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.repo.EventRepository;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.repo.ParamRepository;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.service.EventService;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.service.ParamService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -29,10 +30,11 @@ import java.util.List;
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class EventServiceImpl extends ServiceImpl<EventRepository, Event> implements EventService {
|
||||
|
||||
private final EventMapper mapper;
|
||||
private final ParamMapper paramMapper;
|
||||
private final ParamRepository paramRepo;
|
||||
private final EventParamRepository eventParamRepo;
|
||||
private final ParamService paramService;
|
||||
|
||||
/**
|
||||
* 新建物模型事件
|
||||
@ -42,24 +44,9 @@ public class EventServiceImpl extends ServiceImpl<EventRepository, Event> implem
|
||||
if (baseMapper.findByName(dto.getName()) != null) {
|
||||
throw new ConstraintException("该事件已存在!");
|
||||
}
|
||||
Event event = new Event();
|
||||
event.setName(dto.getName());
|
||||
event.setIdentifier(dto.getIdentifier());
|
||||
event.setType(dto.getType());
|
||||
event.setProductId(dto.getProductId());
|
||||
Event event = mapper.toEntity(dto);
|
||||
save(event);
|
||||
List<Long> eventIds = new ArrayList<>();
|
||||
if (dto.getOutputs() != null) {
|
||||
dto.getOutputs().forEach(paramDto -> {
|
||||
Param param = paramMapper.toEntity(paramDto);
|
||||
paramRepo.insert(param);
|
||||
eventIds.add(param.getId());
|
||||
});
|
||||
}
|
||||
List<EventParam> eventParams = eventIds.stream()
|
||||
.map(eventId -> new EventParam(event.getId(), eventId))
|
||||
.toList();
|
||||
eventParamRepo.insert(eventParams);
|
||||
eventParamRepo.insert(paramService.eventParamCreate(dto, event.getId()));
|
||||
return event;
|
||||
}
|
||||
/**
|
||||
@ -67,28 +54,11 @@ public class EventServiceImpl extends ServiceImpl<EventRepository, Event> implem
|
||||
*/
|
||||
@Override
|
||||
public Event update(EventDto dto, Long id) {
|
||||
this.lambdaUpdate().eq(Event::getId, id)
|
||||
.set(Event::getName, dto.getName())
|
||||
.set(Event::getIdentifier, dto.getIdentifier())
|
||||
.set(Event::getType, dto.getType())
|
||||
.set(Event::getProductId, dto.getProductId())
|
||||
.update();
|
||||
LambdaQueryWrapper<EventParam> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(EventParam::getEventId, id);
|
||||
List<EventParam> eventParams = eventParamRepo.selectList(wrapper);
|
||||
List<Long> paramIds = eventParams.stream()
|
||||
.map(EventParam::getParamId)
|
||||
.toList();
|
||||
List<Param> params = paramRepo.selectByIds(paramIds);
|
||||
if (dto.getOutputs() != null && !dto.getOutputs().isEmpty()) {
|
||||
for (int i = 0; i < dto.getOutputs().size(); i++) {
|
||||
ParamDto paramDto = dto.getOutputs().get(i);
|
||||
Param param = params.get(i);
|
||||
paramMapper.convert(paramDto, param);
|
||||
paramRepo.updateById(param);
|
||||
}
|
||||
}
|
||||
return this.getById(id);
|
||||
Event event = baseMapper.selectById(id);
|
||||
mapper.convert(dto, event);
|
||||
updateById(event);
|
||||
paramService.eventParamUpdate(dto.getOutputs(), id);
|
||||
return event;
|
||||
}
|
||||
/**
|
||||
* 分页查询物模型事件
|
||||
@ -96,10 +66,10 @@ public class EventServiceImpl extends ServiceImpl<EventRepository, Event> implem
|
||||
* @param query 查询表单
|
||||
* @param page 分页参数
|
||||
*/
|
||||
@Override
|
||||
public IPage<Event> page(Page<Event> page, EventQuery query) {
|
||||
return baseMapper.page(page, query);
|
||||
}
|
||||
// @Override
|
||||
// public IPage<Event> page(Page<Event> page, EventQuery query) {
|
||||
// return baseMapper.page(page, query);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 查询详情
|
||||
|
@ -0,0 +1,112 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zsc.edu.gateway.modules.iot.product.dto.ProductDto;
|
||||
import com.zsc.edu.gateway.modules.iot.product.entity.ProductParam;
|
||||
import com.zsc.edu.gateway.modules.iot.product.repo.ProductParamRepository;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.EventDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.ParamDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.ServeDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.EventParam;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Param;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.ServeParam;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.mapper.ParamMapper;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.repo.EventParamRepository;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.repo.ParamRepository;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.repo.ServeParamRepository;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.service.ParamService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
public class ParamServiceImpl extends ServiceImpl<ParamRepository, Param> implements ParamService {
|
||||
private final ParamMapper mapper;
|
||||
private final ParamMapper paramMapper;
|
||||
private final EventParamRepository eventParamRepository;
|
||||
private final ProductParamRepository productParamRepository;
|
||||
private final ServeParamRepository serveParamRepository;
|
||||
|
||||
public List<Long> paramCreate(List<ParamDto> params) {
|
||||
List<Long> paramIds = new ArrayList<>();
|
||||
params.forEach(paramDto -> {
|
||||
Param param = mapper.toEntity(paramDto);
|
||||
baseMapper.insert(param);
|
||||
paramIds.add(param.getId());
|
||||
});
|
||||
return paramIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EventParam> eventParamCreate(EventDto dto, Long eventId) {
|
||||
return paramCreate(dto.getOutputs()).stream()
|
||||
.map(paramId -> new EventParam(eventId, paramId))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProductParam> productParamCreate(ProductDto dto, Long productId) {
|
||||
return paramCreate(dto.getParams()).stream()
|
||||
.map(paramId -> new ProductParam(productId, paramId))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ServeParam> serveParamCreate(ServeDto dto, Long serveId) {
|
||||
List<ServeParam> serveParams = new ArrayList<>();
|
||||
serveParams.addAll(paramCreate(dto.getInputs()).stream()
|
||||
.map(paramId -> new ServeParam(serveId, paramId))
|
||||
.toList());
|
||||
serveParams.addAll(paramCreate(dto.getOutputs()).stream()
|
||||
.map(paramId -> new ServeParam(serveId, paramId))
|
||||
.toList());
|
||||
return serveParams;
|
||||
}
|
||||
|
||||
public boolean paramUpdate(List<ParamDto> paramDto, List<Long> paramIds) {
|
||||
List<Param> params = baseMapper.selectByIds(paramIds);
|
||||
if (!params.isEmpty() && !paramDto.isEmpty()) {
|
||||
for (int i = 0; i < Math.min(params.size(), paramDto.size()); i++) {
|
||||
Param param = params.get(i);
|
||||
ParamDto dto = paramDto.get(i);
|
||||
paramMapper.convert(dto, param);
|
||||
baseMapper.updateById(param);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean eventParamUpdate(List<ParamDto> paramDto, Long eventId) {
|
||||
return paramUpdate(paramDto, eventParamRepository.selectList(new LambdaQueryWrapper<EventParam>()
|
||||
.eq(EventParam::getEventId, eventId))
|
||||
.stream()
|
||||
.map(EventParam::getParamId)
|
||||
.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean productParamUpdate(List<ParamDto> paramDto, Long productId) {
|
||||
return paramUpdate(paramDto, productParamRepository.selectList(new LambdaQueryWrapper<ProductParam>()
|
||||
.eq(ProductParam::getProductId, productId))
|
||||
.stream()
|
||||
.map(ProductParam::getParamId)
|
||||
.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean serveParamUpdate(List<ParamDto> paramDto, Long serveId) {
|
||||
return paramUpdate(paramDto, serveParamRepository.selectList(new LambdaQueryWrapper<ServeParam>()
|
||||
.eq(ServeParam::getServeId, serveId))
|
||||
.stream()
|
||||
.map(ServeParam::getParamId)
|
||||
.toList());
|
||||
}
|
||||
}
|
@ -1,18 +1,12 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.PropertyDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Event;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Property;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.mapper.PropertyMapper;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.query.PropertyQuery;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.repo.PropertyRepository;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.service.PropertyService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
|
@ -14,6 +14,7 @@ import com.zsc.edu.gateway.modules.iot.tsl.query.ServeQuery;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.repo.ParamRepository;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.repo.ServeParamRepository;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.repo.ServeRepository;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.service.ParamService;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.service.ServeService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -33,6 +34,7 @@ public class ServeServiceImpl extends ServiceImpl<ServeRepository, Serve> implem
|
||||
private final ParamMapper paramMapper;
|
||||
private final ParamRepository paramRepository;
|
||||
private final ServeParamRepository serveParamRepository;
|
||||
private final ParamService paramService;
|
||||
/**
|
||||
* 新建功能
|
||||
*/
|
||||
@ -41,30 +43,9 @@ public class ServeServiceImpl extends ServiceImpl<ServeRepository, Serve> implem
|
||||
if (baseMapper.findByName(dto.getName()) != null) {
|
||||
throw new ConstraintException("该事件已存在!");
|
||||
}
|
||||
Serve serve = new Serve();
|
||||
serve.setProductId(dto.getProductId());
|
||||
serve.setName(dto.getName());
|
||||
serve.setIdentifier(dto.getIdentifier());
|
||||
Serve serve = mapper.toEntity(dto);
|
||||
save(serve);
|
||||
List<Long> serveIds = new ArrayList<>();
|
||||
if (dto.getInputs() != null) {
|
||||
dto.getInputs().forEach(paramDto -> {
|
||||
Param param = paramMapper.toEntity(paramDto);
|
||||
paramRepository.insert(param);
|
||||
serveIds.add(param.getId());
|
||||
});
|
||||
}
|
||||
if (dto.getOutputs() != null) {
|
||||
dto.getOutputs().forEach(paramDto -> {
|
||||
Param param = paramMapper.toEntity(paramDto);
|
||||
paramRepository.insert(param);
|
||||
serveIds.add(param.getId());
|
||||
});
|
||||
}
|
||||
List<ServeParam> serveParams = serveIds.stream()
|
||||
.map(serveId -> new ServeParam(serve.getId(), serveId))
|
||||
.toList();
|
||||
serveParamRepository.insert(serveParams);
|
||||
serveParamRepository.insert(paramService.serveParamCreate(dto, serve.getId()));
|
||||
return serve;
|
||||
}
|
||||
/**
|
||||
@ -72,35 +53,12 @@ public class ServeServiceImpl extends ServiceImpl<ServeRepository, Serve> implem
|
||||
*/
|
||||
@Override
|
||||
public Serve update(ServeDto dto, Long id) {
|
||||
this.lambdaUpdate().eq(Serve::getId, id)
|
||||
.set(Serve::getName, dto.getName())
|
||||
.set(Serve::getIdentifier, dto.getIdentifier())
|
||||
.set(Serve::getProductId, dto.getProductId())
|
||||
.update();
|
||||
|
||||
LambdaQueryWrapper<ServeParam> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ServeParam::getServeId, id);
|
||||
List<ServeParam> serveParams = serveParamRepository.selectList(wrapper);
|
||||
List<Long> paramIds = serveParams.stream()
|
||||
.map(ServeParam::getParamId)
|
||||
.toList();
|
||||
List<Param> params = paramRepository.selectByIds(paramIds);
|
||||
List<ParamDto> allParamsDto = new ArrayList<>();
|
||||
if (dto.getInputs() != null && !dto.getInputs().isEmpty()) {
|
||||
allParamsDto.addAll(dto.getInputs());
|
||||
}
|
||||
if (dto.getOutputs() != null && !dto.getOutputs().isEmpty()) {
|
||||
allParamsDto.addAll(dto.getOutputs());
|
||||
}
|
||||
|
||||
for (int i = 0; i < allParamsDto.size(); i++) {
|
||||
ParamDto paramDto = allParamsDto.get(i);
|
||||
Param param = params.get(i);
|
||||
paramMapper.convert(paramDto, param);
|
||||
paramRepository.updateById(param);
|
||||
}
|
||||
|
||||
return this.getById(id);
|
||||
Serve serve = baseMapper.selectById(id);
|
||||
mapper.convert(dto, serve);
|
||||
updateById(serve);
|
||||
paramService.serveParamUpdate(dto.getInputs(), id);
|
||||
paramService.serveParamUpdate(dto.getOutputs(), id);
|
||||
return serve;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,10 +67,10 @@ public class ServeServiceImpl extends ServiceImpl<ServeRepository, Serve> implem
|
||||
* @param query 查询表单
|
||||
* @param page 分页参数
|
||||
*/
|
||||
@Override
|
||||
public IPage<Serve> page(Page<Serve> page, ServeQuery query) {
|
||||
return baseMapper.page(page, query);
|
||||
}
|
||||
// @Override
|
||||
// public IPage<Serve> page(Page<Serve> page, ServeQuery query) {
|
||||
// return baseMapper.page(page, query);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 查询详情
|
||||
|
@ -45,9 +45,9 @@ public class BulletinController {
|
||||
* @return 分页数据
|
||||
*/
|
||||
@GetMapping("/self")
|
||||
public IPage<BulletinVo> getBulletins(Page<BulletinVo> pageParam, BulletinQuery query) {
|
||||
public Page<Bulletin> getBulletins(Page<Bulletin> page, BulletinQuery query) {
|
||||
query.setState(Bulletin.State.publish);
|
||||
return service.selectPageByConditions(pageParam, query);
|
||||
return service.page(page, query.wrapper());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -9,8 +9,8 @@ import com.zsc.edu.gateway.common.enums.IState;
|
||||
* @author zhuang
|
||||
*/
|
||||
public enum MessageType implements IEnum<Integer>, IState<MessageType> {
|
||||
other(1,"其他"),
|
||||
resetThePassword(2,"重置密码");
|
||||
other(1, "消息"),
|
||||
resetThePassword(2, "通知");
|
||||
|
||||
private final Integer value;
|
||||
private final String name;
|
||||
|
@ -3,6 +3,7 @@ package com.zsc.edu.gateway.modules.notice.query;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.BulletinVo;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Authority;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -23,12 +24,20 @@ import java.util.Objects;
|
||||
|
||||
public class BulletinQuery {
|
||||
|
||||
private Integer pageNum = 1;
|
||||
private Integer pageSize = 10;
|
||||
private String title;
|
||||
private Bulletin.State state;
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime publishTimeBegin;
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime publishTimeEnd;
|
||||
|
||||
public LambdaQueryWrapper<Bulletin> wrapper() {
|
||||
LambdaQueryWrapper<Bulletin> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.like(StringUtils.hasText(this.title), Bulletin::getTitle, this.title);
|
||||
queryWrapper.eq(Objects.nonNull(this.state), Bulletin::getState, this.state);
|
||||
if (publishTimeBegin != null && publishTimeEnd != null) {
|
||||
queryWrapper.between(Bulletin::getPublishTime, this.publishTimeBegin, this.publishTimeEnd);
|
||||
}
|
||||
return queryWrapper;
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
package com.zsc.edu.gateway.modules.notice.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.zsc.edu.gateway.modules.attachment.vo.AttachmentVo;
|
||||
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
@ -94,6 +93,6 @@ public class BulletinVo {
|
||||
/**
|
||||
* 附件
|
||||
*/
|
||||
List<AttachmentVo> attachmentVos;
|
||||
List<Attachment> attachments;
|
||||
|
||||
}
|
||||
|
@ -1,17 +1,9 @@
|
||||
package com.zsc.edu.gateway.modules.notice.vo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
|
||||
import com.zsc.edu.gateway.modules.attachment.vo.AttachmentVo;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Message;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessageType;
|
||||
import com.zsc.edu.gateway.modules.system.entity.User;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
|
@ -21,7 +21,7 @@
|
||||
<result column="update_time" jdbcType="DATE" property="deviceUpdateTime"/>
|
||||
<result column="remark" jdbcType="VARCHAR" property="deviceRemark"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="type_string" jdbcType="VARCHAR" property="typeString"/>
|
||||
<result column="product_type" jdbcType="VARCHAR" property="productType"/>
|
||||
<result column="model" property="model"/>
|
||||
<result column="link" property="link"/>
|
||||
<result column="create_by" jdbcType="VARCHAR" property="createBy"/>
|
||||
@ -41,33 +41,6 @@
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<select id="query" resultMap="BaseResultMap">
|
||||
select d.*,p.*,
|
||||
ip.id as param_id,ip.data_type as param_data_type,ip.uint as param_uint,ip.type as param_type,ip.identifier as
|
||||
param_identifier,ip.name as param_name,ip.remark as param_remark
|
||||
from iot_device d
|
||||
left join iot_product p on d.product_id = p.id
|
||||
left join iot_product_param pp on p.id = pp.product_id
|
||||
left join iot_param ip on pp.param_id = ip.id
|
||||
<where>
|
||||
<if test="query.name != null and query.name != ''">
|
||||
and d.name = #{query.name}
|
||||
</if>
|
||||
<if test="query.clientId != null and query.clientId != ''">
|
||||
and d.client_id = #{query.clientId}
|
||||
</if>
|
||||
<if test="query.productId != null">
|
||||
and d.product_id = #{query.productId}
|
||||
</if>
|
||||
<if test="query.status != null">
|
||||
and d.status = #{query.status}
|
||||
</if>
|
||||
<if test="query.isOnline != null">
|
||||
and d.online = #{query.isOnline}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="findById" resultMap="BaseResultMap">
|
||||
select d.*,
|
||||
p.*,
|
||||
|
@ -22,25 +22,6 @@
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<select id="page" resultMap="EventMap">
|
||||
select e.*,ip.id as param_id,ip.data_type as param_data_type,ip.uint as param_uint,ip.type as
|
||||
param_type,ip.identifier as param_identifier,ip.name as param_name,ip.remark as param_remark
|
||||
from iot_event e
|
||||
left join iot_event_param ep on e.id=ep.event_id
|
||||
left join iot_param ip on ep.param_id = ip.id
|
||||
<where>
|
||||
<if test="query.name != null and query.name != ''">
|
||||
and e.name like CONCAT('%', #{query.name}, '%')
|
||||
</if>
|
||||
<if test="query.level != null and query.level != ''">
|
||||
and e.level = #{query.level}
|
||||
</if>
|
||||
<if test="query.productId !=null">
|
||||
and e.product_id = #{query.productId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectById" resultMap="EventMap">
|
||||
select e.*,
|
||||
ip.id as param_id,
|
||||
|
@ -7,7 +7,7 @@
|
||||
<id column="id" property="id"/>
|
||||
<result column="dept_id" property="deptId"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="type_string" property="typeString"/>
|
||||
<result column="type_string" property="productType"/>
|
||||
<result column="model" property="model"/>
|
||||
<result column="link" property="link"/>
|
||||
<result column="create_by" jdbcType="VARCHAR" property="createBy"/>
|
||||
@ -27,25 +27,6 @@
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<select id="page" resultMap="BaseResultMap">
|
||||
select p.*, ip.id as param_id,ip.data_type as param_data_type,ip.uint as param_uint,ip.type as
|
||||
param_type,ip.identifier as param_identifier,ip.name as param_name,ip.remark as param_remark
|
||||
from iot_product p
|
||||
left join iot_product_param pp on p.id = pp.product_id
|
||||
left join iot_param ip on pp.param_id = ip.id
|
||||
<where>
|
||||
<if test="query.name != null and query.name != ''">
|
||||
and p.name like CONCAT('%', #{query.name}, '%')
|
||||
</if>
|
||||
<if test="query.type != null and query.type != ''">
|
||||
and p.type = #{query.type}
|
||||
</if>
|
||||
<if test="query.links != null and query.links != ''">
|
||||
and p.link = #{query.links}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectById" resultMap="BaseResultMap">
|
||||
select p.*,
|
||||
ip.id as param_id,
|
||||
|
@ -71,69 +71,4 @@
|
||||
WHERE s.id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="page" resultMap="ServeMap">
|
||||
SELECT
|
||||
s.id,
|
||||
s.product_id,
|
||||
s.identifier,
|
||||
s.name,
|
||||
s.remark,
|
||||
input_params.id as input_param_id,
|
||||
input_params.data_type as input_param_data_type,
|
||||
input_params.uint as input_param_uint,
|
||||
input_params.type as input_param_type,
|
||||
input_params.identifier as input_param_identifier,
|
||||
input_params.name as input_param_name,
|
||||
input_params.remark as input_param_remark,
|
||||
output_params.id as output_param_id,
|
||||
output_params.data_type as output_param_data_type,
|
||||
output_params.uint as output_param_uint,
|
||||
output_params.type as output_param_type,
|
||||
output_params.identifier as output_param_identifier,
|
||||
output_params.name as output_param_name,
|
||||
output_params.remark as output_param_remark
|
||||
FROM iot_serve s
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
sp.serve_id,
|
||||
ip.id,
|
||||
ip.data_type,
|
||||
ip.uint,
|
||||
ip.type,
|
||||
ip.identifier,
|
||||
ip.name,
|
||||
ip.remark
|
||||
FROM iot_serve_param sp
|
||||
JOIN iot_param ip ON sp.param_id = ip.id
|
||||
WHERE ip.type = 1
|
||||
) input_params ON s.id = input_params.serve_id
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
sp.serve_id,
|
||||
ip.id,
|
||||
ip.data_type,
|
||||
ip.uint,
|
||||
ip.type,
|
||||
ip.identifier,
|
||||
ip.name,
|
||||
ip.remark
|
||||
FROM iot_serve_param sp
|
||||
JOIN iot_param ip ON sp.param_id = ip.id
|
||||
WHERE ip.type = 2
|
||||
) output_params ON s.id = output_params.serve_id
|
||||
<where>
|
||||
<where>
|
||||
<if test="query.name != null and query.name != ''">
|
||||
and s.name like CONCAT('%', #{query.name}, '%')
|
||||
</if>
|
||||
<if test="query.identifier != null and query.identifier != ''">
|
||||
and s.level = #{query.identifier}
|
||||
</if>
|
||||
<if test="query.productId !=null">
|
||||
and s.product_id = #{query.productId}
|
||||
</if>
|
||||
</where>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
@ -23,28 +23,23 @@
|
||||
<result column="create_time" jdbcType="DATE" property="createTime"/>
|
||||
<result column="update_time" jdbcType="DATE" property="updateTime"/>
|
||||
<result column="remark" jdbcType="VARCHAR" property="remark"/>
|
||||
<collection property="attachmentVos" ofType="com.zsc.edu.gateway.modules.attachment.vo.AttachmentVo"
|
||||
<collection property="attachments" ofType="com.zsc.edu.gateway.modules.attachment.entity.Attachment"
|
||||
autoMapping="true" columnPrefix="attachment_">
|
||||
<id column="id" jdbcType="VARCHAR" property="attachmentId"/>
|
||||
<result column="url" jdbcType="VARCHAR" property="url"/>
|
||||
<result column="file_ame" jdbcType="VARCHAR" property="fileName"/>
|
||||
<id column="id" jdbcType="VARCHAR" property="id"/>
|
||||
<result column="file_name" jdbcType="VARCHAR" property="fileName"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
<select id="selectByBulletinId" resultMap="BulletinMap">
|
||||
SELECT sb.*, a.id as attachment_id,a.url as attachment_url,a.file_name as attachment_file_name
|
||||
SELECT sb.*, a.id as attachment_id, a.file_name as attachment_file_name
|
||||
FROM
|
||||
sys_bulletin sb
|
||||
LEFT JOIN sys_bulletin_attach sba ON sb.id = sba.bulletin_id
|
||||
LEFT JOIN attachment a ON a.id = sba.attachment_id
|
||||
<where>
|
||||
<if test="bulletinId !=null">
|
||||
sb.id = #{bulletinId}
|
||||
</if>
|
||||
</where>
|
||||
where sb.id = #{bulletinId}
|
||||
</select>
|
||||
|
||||
<select id="selectPageByConditions" resultMap="BulletinMap">
|
||||
SELECT sb.*, a.id as attachment_id,a.file_name as attachment_file_name,a.url as attachment_url
|
||||
SELECT sb.*, a.id as attachment_id,a.file_name as attachment_file_name
|
||||
FROM
|
||||
sys_bulletin sb
|
||||
LEFT JOIN sys_bulletin_attach sba ON sb.id = sba.bulletin_id
|
||||
|
@ -28,7 +28,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
|
||||
@WebMvcTest(RoleController.class)
|
||||
public class RoleControllerTest extends MockMvcConfigBase {
|
||||
//TODO 公告部分测试
|
||||
private static Role role1;
|
||||
|
||||
private static Role role2;
|
||||
|
Loading…
Reference in New Issue
Block a user