refactor(iot): 重构设备和事件相关代码
- 更新设备和事件的实体类定义,增加必要的字段和注解 -重构设备和事件的控制器、服务层和数据访问层接口 - 优化分页查询逻辑,使用 MP 的 IPage 接口- 删除不必要的方法和注释- 统一异常处理方式
This commit is contained in:
parent
1e9bf7ec46
commit
ad31cfbd09
@ -2,6 +2,7 @@ package com.zsc.edu.gateway;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
|
@ -6,6 +6,7 @@ import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@ -20,17 +21,22 @@ public class MyMetaObjectHandler implements MetaObjectHandler {
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
|
||||
UserDetailsImpl userInfo = SecurityUtil.getUserInfo();
|
||||
|
||||
this.strictInsertFill(metaObject, "createTime", LocalDateTime::now, LocalDateTime.class);
|
||||
this.strictInsertFill(metaObject, "createdBy", userInfo::getUsername, String.class);
|
||||
if (userInfo.getUsername() == null) {
|
||||
userInfo.setUsername("system");
|
||||
}
|
||||
this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
|
||||
this.strictInsertFill(metaObject, "createBy", String.class, userInfo.getUsername());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
UserDetailsImpl userInfo = SecurityUtil.getUserInfo();
|
||||
if (userInfo.getUsername() == null) {
|
||||
userInfo.setUsername("system");
|
||||
}
|
||||
this.strictUpdateFill(metaObject, "updateTime", LocalDateTime::now, LocalDateTime.class);
|
||||
this.strictUpdateFill(metaObject, "updatedBy", userInfo::getUsername, String.class);
|
||||
this.strictUpdateFill(metaObject, "updateBy", userInfo::getUsername, String.class);
|
||||
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
/**
|
||||
* @author Yao
|
||||
*/
|
||||
@MapperScan(basePackages = "com.zsc.edu.gateway.modules.*.repo")
|
||||
@MapperScan(basePackages = "com.zsc.edu.gateway.modules.**.repo")
|
||||
@Configuration
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
|
@ -81,6 +81,7 @@ public class AttachmentController {
|
||||
|
||||
/**
|
||||
* 批量上传附件
|
||||
* TODO mutipartFile
|
||||
*/
|
||||
@PostMapping("uploadMultipleFiles")
|
||||
public List<Attachment> uploadMultipleFiles(
|
||||
@ -101,6 +102,6 @@ public class AttachmentController {
|
||||
*/
|
||||
@DeleteMapping("delete/{id}")
|
||||
public Boolean delete(@PathVariable("id") String id) {
|
||||
return service.delete(id);
|
||||
return service.removeById(id);
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,4 @@ public interface AttachmentService extends IService<Attachment> {
|
||||
Attachment.Wrapper loadAsWrapper(String id);
|
||||
|
||||
List<Attachment> selectList(List<String> dis);
|
||||
|
||||
Boolean delete(String id);
|
||||
}
|
||||
|
@ -18,6 +18,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.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
@ -45,13 +46,11 @@ public class AttachmentServiceImpl extends ServiceImpl<AttachmentRepository, Att
|
||||
private final AttachmentRepository repo;
|
||||
private final Path attachmentPath;
|
||||
private final Path tempPath;
|
||||
private final BulletinAttachmentRepository bulletin;
|
||||
|
||||
public AttachmentServiceImpl(AttachmentRepository repo, StorageProperties storageProperties, BulletinAttachmentService bulletinAttachmentService, BulletinAttachmentRepository bulletin) {
|
||||
this.repo = repo;
|
||||
this.attachmentPath = Paths.get(storageProperties.attachment);
|
||||
this.tempPath = Paths.get(storageProperties.temp);
|
||||
this.bulletin = bulletin;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
@ -132,7 +131,7 @@ public class AttachmentServiceImpl extends ServiceImpl<AttachmentRepository, Att
|
||||
public Attachment store(Attachment.Type type, Path file) throws IOException {
|
||||
String filename = file.getFileName().toString();
|
||||
MessageDigest digest = DigestUtils.getSha1Digest();
|
||||
if (filename != null) {
|
||||
if (StringUtils.hasText(filename)) {
|
||||
digest.update(filename.getBytes());
|
||||
}
|
||||
Tika tika = new Tika();
|
||||
@ -211,14 +210,4 @@ public class AttachmentServiceImpl extends ServiceImpl<AttachmentRepository, Att
|
||||
return repo.selectList(new LambdaQueryWrapper<Attachment>().in(Attachment::getId, dis));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean delete(String id) {
|
||||
LambdaQueryWrapper<BulletinAttachment> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(BulletinAttachment::getAttachmentId, id);
|
||||
List<BulletinAttachment> bulletinAttachments = bulletin.selectList(wrapper);
|
||||
if (!bulletinAttachments.isEmpty()) {
|
||||
bulletin.delete(wrapper);
|
||||
}
|
||||
return removeById(id);
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,17 @@
|
||||
package com.zsc.edu.gateway.modules.iot.device.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.modules.iot.device.dto.BatchDeviceDto;
|
||||
import com.zsc.edu.gateway.modules.iot.device.dto.DeviceDto;
|
||||
import com.zsc.edu.gateway.modules.iot.device.dto.DeviceServeDto;
|
||||
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.record.entity.Record;
|
||||
import com.zsc.edu.gateway.modules.iot.record.service.RecordService;
|
||||
import com.zsc.edu.gateway.modules.iot.record.service.impl.RecordServiceImpl;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -64,15 +66,12 @@ public class DeviceController {
|
||||
* 查询设备
|
||||
*
|
||||
* @param query 设备的查询表单
|
||||
* @param pageable 分页参数
|
||||
* @param page 分页参数
|
||||
* @return Page<Device> 设备分页数据
|
||||
*/
|
||||
@GetMapping
|
||||
public Page<Device> page(
|
||||
DeviceQuery query,
|
||||
@PageableDefault(sort = {"id"}, direction = Sort.Direction.DESC) Pageable pageable
|
||||
) {
|
||||
return service.page(query, pageable);
|
||||
public IPage<Device> page(Page<Device> page, DeviceQuery query) {
|
||||
return service.page(page, query);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,8 +81,8 @@ public class DeviceController {
|
||||
* @return 被删除的设备
|
||||
*/
|
||||
@DeleteMapping("{id}")
|
||||
public Device delete(@PathVariable("id") Long id) {
|
||||
return service.deleteById(id);
|
||||
public Boolean delete(@PathVariable("id") Long id) {
|
||||
return service.removeById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,24 +111,19 @@ public class DeviceController {
|
||||
} else {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("服务执行失败");
|
||||
}
|
||||
// service.serve(dto);
|
||||
// return ResponseEntity.ok("服务执行成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备上报记录
|
||||
*
|
||||
* @param clientId 设备的查询表单
|
||||
* @param pageable 分页参数
|
||||
* @return Page<Device> 设备分页数据
|
||||
*/
|
||||
@GetMapping("record")
|
||||
public Page<Record> pageRecord(
|
||||
String clientId,
|
||||
@PageableDefault(sort = {"recordTime"}, direction = Sort.Direction.DESC) Pageable pageable
|
||||
) {
|
||||
return recordService.page(clientId, pageable);
|
||||
}
|
||||
// /**
|
||||
// * 查询设备上报记录
|
||||
// *
|
||||
// * @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);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 查询设备上报记录
|
||||
|
@ -3,7 +3,7 @@ package com.zsc.edu.gateway.modules.iot.device.entity;
|
||||
import com.baomidou.mybatisplus.annotation.IEnum;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.zsc.edu.gateway.framework.common.enums.IState;
|
||||
import com.zsc.edu.gateway.common.enums.IState;
|
||||
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
|
||||
import com.zsc.edu.gateway.modules.system.entity.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
@ -3,7 +3,6 @@ package com.zsc.edu.gateway.modules.iot.device.query;
|
||||
import com.zsc.edu.gateway.modules.iot.device.entity.Device;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
|
@ -5,17 +5,24 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.modules.iot.device.entity.Device;
|
||||
import com.zsc.edu.gateway.modules.iot.device.query.DeviceQuery;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
public interface DeviceRepository extends BaseMapper<Device> {
|
||||
@Select("select * from iot_device where name=#{name}")
|
||||
Optional<Device> findByName(@Param("name") String name);
|
||||
Device findByName(@Param("name") String name);
|
||||
|
||||
IPage<Device> page(Page<Device> page, @Param("query") DeviceQuery query);
|
||||
|
||||
Device selectById(@Param("id") Long id);
|
||||
|
||||
@Select("select * from iot_device where client_id=#{clientId} and status=#{status} and online=#{online}")
|
||||
Device findByClientIdAndStateAndOnline(@Param("clientId") String clientId,
|
||||
@Param("status") Device.Status status,
|
||||
@Param("online") Boolean online);
|
||||
}
|
||||
|
@ -1,9 +1,13 @@
|
||||
package com.zsc.edu.gateway.modules.iot.device.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zsc.edu.gateway.modules.iot.device.dto.BatchDeviceDto;
|
||||
import com.zsc.edu.gateway.modules.iot.device.dto.DeviceDto;
|
||||
import com.zsc.edu.gateway.modules.iot.device.dto.DeviceServeDto;
|
||||
import com.zsc.edu.gateway.modules.iot.device.entity.Device;
|
||||
import com.zsc.edu.gateway.modules.iot.device.query.DeviceQuery;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -13,4 +17,10 @@ public interface DeviceService extends IService<Device> {
|
||||
List<Device> batchCreate(BatchDeviceDto dto);
|
||||
|
||||
Device update(DeviceDto dto, Long id);
|
||||
|
||||
IPage<Device> page(Page<Device> page, DeviceQuery query);
|
||||
|
||||
Device detail(Long id);
|
||||
|
||||
Boolean serve(DeviceServeDto dto);
|
||||
}
|
||||
|
@ -1,14 +1,17 @@
|
||||
package com.zsc.edu.gateway.modules.iot.device.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
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.exception.OutlineException;
|
||||
import com.zsc.edu.gateway.framework.redis.RedisUtils;
|
||||
import com.zsc.edu.gateway.modules.iot.device.dto.BatchDeviceDto;
|
||||
import com.zsc.edu.gateway.modules.iot.device.dto.DeviceDto;
|
||||
import com.zsc.edu.gateway.modules.iot.device.dto.DeviceServeDto;
|
||||
import com.zsc.edu.gateway.modules.iot.device.entity.Device;
|
||||
import com.zsc.edu.gateway.modules.iot.device.mapper.DeviceMapper;
|
||||
import com.zsc.edu.gateway.modules.iot.device.query.DeviceQuery;
|
||||
@ -18,9 +21,9 @@ import com.zsc.edu.gateway.modules.iot.product.entity.Product;
|
||||
import com.zsc.edu.gateway.modules.iot.product.repo.ProductRepository;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
@ -28,26 +31,27 @@ import java.util.*;
|
||||
/**
|
||||
* @author 15864
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Slf4j
|
||||
@Service
|
||||
//@RequiredArgsConstructor
|
||||
public class DeviceServiceImpl extends ServiceImpl<DeviceRepository, Device> implements DeviceService {
|
||||
|
||||
@Value("${gatherer.version}")
|
||||
private String gatherer;
|
||||
private final DeviceMapper mapper;
|
||||
// @Value("${gatherer.version}")
|
||||
// private String gatherer;
|
||||
@Resource
|
||||
private final ProductRepository productRepo;
|
||||
private DeviceMapper mapper;
|
||||
@Resource
|
||||
private final DeviceRepository repo;
|
||||
private final RedisUtils redisUtils;
|
||||
private ProductRepository productRepo;
|
||||
@Resource
|
||||
private RedisUtils redisUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 新建设备
|
||||
*/
|
||||
@Override
|
||||
public Device create(DeviceDto dto) {
|
||||
if (repo.findByName(dto.getName()).isPresent()) {
|
||||
if (baseMapper.findByName(dto.getName()) == null) {
|
||||
throw new ConstraintException("该设备已存在!");
|
||||
}
|
||||
Device device = mapper.toEntity(dto);
|
||||
@ -62,26 +66,30 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceRepository, Device> imp
|
||||
@Override
|
||||
public List<Device> batchCreate(BatchDeviceDto dto) {
|
||||
List<Device> devices = new ArrayList<>();
|
||||
productRepo.findById(dto.getProductId()).ifPresent(product -> {
|
||||
String[] names = new String[dto.getNum()];
|
||||
for (int i = 0; i < dto.getNum(); i++) {
|
||||
String name = String.format("%s%05d", dto.getPrefix(), i + 1);
|
||||
names[i] = name;
|
||||
DeviceDto deviceDto = new DeviceDto();
|
||||
deviceDto.setName(name);
|
||||
deviceDto.setProductId(product.id);
|
||||
deviceDto.setExtendParams(dto.getExtendParams());
|
||||
deviceDto.setProperties(dto.getProperties());
|
||||
deviceDto.setFirmwareVersion(dto.getFirmwareVersion());
|
||||
Device device = mapper.toEntity(deviceDto);
|
||||
Integer typeCode = Integer.valueOf(product.getType());
|
||||
device.setClientId(String.format("%s%02d%02d%05d", gatherer, typeCode, 3, i + 1));
|
||||
}
|
||||
if (!findByNameIn(names).isEmpty()) {
|
||||
throw new ConstraintException("设备已存在!");
|
||||
}
|
||||
});
|
||||
repo.insert(devices);
|
||||
Product product = productRepo.selectById(dto.getProductId());
|
||||
if (product == null) {
|
||||
throw new ConstraintException("该产品不存在!");
|
||||
}
|
||||
String[] names = new String[dto.getNum()];
|
||||
for (int i = 0; i < dto.getNum(); i++) {
|
||||
String name = String.format("%s%05d", dto.getPrefix(), i + 1);
|
||||
names[i] = name;
|
||||
DeviceDto deviceDto = new DeviceDto();
|
||||
deviceDto.setName(name);
|
||||
deviceDto.setProductId(product.getId());
|
||||
deviceDto.setExtendParams(dto.getExtendParams());
|
||||
deviceDto.setProperties(dto.getProperties());
|
||||
deviceDto.setFirmwareVersion(dto.getFirmwareVersion());
|
||||
Device device = mapper.toEntity(deviceDto);
|
||||
Integer typeCode = Integer.valueOf(product.getType());
|
||||
device.setClientId(String.format("%s%02d%02d%05d", "001", typeCode, 3, i + 1));
|
||||
}
|
||||
|
||||
if (!findByNameIn(names).isEmpty()) {
|
||||
throw new ConstraintException("设备已存在!");
|
||||
}
|
||||
|
||||
baseMapper.insert(devices);
|
||||
return devices;
|
||||
}
|
||||
|
||||
@ -96,7 +104,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceRepository, Device> imp
|
||||
*/
|
||||
@Override
|
||||
public Device update(DeviceDto dto, Long id) {
|
||||
Device device = repo.selectById(id);
|
||||
Device device = baseMapper.selectById(id);
|
||||
if (!device.getName().equals(dto.getName())) {
|
||||
throw new ConstraintException("deviceName", dto.getName(), "设备名称已存在");
|
||||
}
|
||||
@ -115,72 +123,33 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceRepository, Device> imp
|
||||
* @param query 查询表单
|
||||
* @param page 分页参数
|
||||
*/
|
||||
@Override
|
||||
public IPage<Device> page(Page<Device> page, DeviceQuery query) {
|
||||
return repo.page(page, query);
|
||||
return baseMapper.page(page, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备
|
||||
*
|
||||
* @param id 设备id
|
||||
* @return 删除设备
|
||||
*/
|
||||
public Device delete(Long id) {
|
||||
return deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过Id查找设备
|
||||
* 通过Id查找设备详情
|
||||
*
|
||||
* @param id
|
||||
* @return 查找设备
|
||||
*/
|
||||
public Device getById(Long id) {
|
||||
return findById(id).orElseThrow(NotExistException::new);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过factoryId查找设备
|
||||
*
|
||||
* @param factoryId
|
||||
* @return 查找设备
|
||||
*/
|
||||
public Optional<Device> getByFactoryId(String factoryId) {
|
||||
return repo.findByFactoryId(factoryId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备详情
|
||||
*
|
||||
* @param id
|
||||
* @return Lamp 设备数据
|
||||
* @return 设备详情
|
||||
*/
|
||||
@Override
|
||||
public Device detail(Long id) {
|
||||
Device device = getOne(id);
|
||||
Hibernate.initialize(device.product);
|
||||
return device;
|
||||
}
|
||||
|
||||
public Device findByName(String name) {
|
||||
return repo.findByName(name).orElseThrow(NotExistException::new);
|
||||
return baseMapper.selectById(id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param ids 编号数组
|
||||
* @return
|
||||
*/
|
||||
public Long[] batchDelete(Long[] ids) {
|
||||
repo.deleteAllByIdInBatch(Arrays.asList(ids));
|
||||
return ids;
|
||||
}
|
||||
|
||||
public Optional<Device> findByClientIdAndStateAndOnline(String clientId, Device.Status status, Boolean isOnline) {
|
||||
return repo.findByClientIdAndStateAndOnline(clientId.trim(), status, isOnline);
|
||||
}
|
||||
// /**
|
||||
// * 批量删除
|
||||
// *
|
||||
// * @param ids 编号数组
|
||||
// * @return
|
||||
// */
|
||||
// public Long[] batchDelete(Long[] ids) {
|
||||
// repo.deleteAllByIdInBatch(Arrays.asList(ids));
|
||||
// return ids;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 物模型配置的服务
|
||||
@ -188,13 +157,14 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceRepository, Device> imp
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean serve(DeviceServeDto dto) {
|
||||
Optional<Device> deviceOptional = findByClientIdAndStateAndOnline(dto.clientId, Device.Status.已激活, true);
|
||||
if (deviceOptional.isPresent()) {
|
||||
Device device = baseMapper.findByClientIdAndStateAndOnline(dto.clientId, Device.Status.ACTIVATED, true);
|
||||
if (device != null) {
|
||||
JSONObject json = (JSONObject) JSON.toJSON(dto);
|
||||
json.put("type", "serve");
|
||||
// amqpTemplate.convertAndSend(exchange, "send", json);
|
||||
redisUtils.set("serve:sendTime:" + dto.serveName + ":" + dto.clientId, new Date());
|
||||
redisUtils.set("serve:sendTime:" + dto.serveName + ":" + dto.clientId, String.valueOf(new Date()));
|
||||
return true;
|
||||
} else {
|
||||
throw new OutlineException("设备[" + dto.clientId + "]不在线!");
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.zsc.edu.gateway.modules.iot.product.controller;
|
||||
|
||||
import com.zsc.gateway.framework.log.Log;
|
||||
import com.zsc.gateway.module.iot.product.domain.Product;
|
||||
import com.zsc.gateway.module.iot.product.dto.ProductDto;
|
||||
import com.zsc.gateway.module.iot.product.query.ProductQuery;
|
||||
import com.zsc.gateway.module.iot.product.service.ProductService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
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.impl.ProductServiceImpl;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
@ -15,12 +15,15 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("api/rest/product")
|
||||
public class ProductController {
|
||||
|
||||
private final ProductService service;
|
||||
private final ProductServiceImpl service;
|
||||
|
||||
|
||||
/**
|
||||
@ -30,7 +33,6 @@ public class ProductController {
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
@Log(module = "产品", action = Log.Action.新建)
|
||||
public Product create(@RequestBody ProductDto dto) {
|
||||
return service.create(dto);
|
||||
}
|
||||
@ -42,7 +44,6 @@ public class ProductController {
|
||||
* @return 更新后的产品
|
||||
*/
|
||||
@PatchMapping("{id}")
|
||||
@Log(module = "产品", action = Log.Action.修改)
|
||||
public Product update(@RequestBody ProductDto dto, @PathVariable("id") Long id) {
|
||||
return service.update(dto, id);
|
||||
}
|
||||
@ -52,29 +53,25 @@ public class ProductController {
|
||||
* 查询产品
|
||||
*
|
||||
* @param query 产品的查询表单
|
||||
* @param pageable 分页参数
|
||||
* @param page 分页参数
|
||||
* @return Page<Device> 产品分页数据
|
||||
*/
|
||||
@GetMapping
|
||||
@Log(module = "产品", action = Log.Action.其他)
|
||||
public Page<Product> page(
|
||||
ProductQuery query,
|
||||
@PageableDefault(sort = {"id"}, direction = Sort.Direction.DESC) Pageable pageable
|
||||
) {
|
||||
return service.page(query, pageable);
|
||||
public IPage<Product> page(Page<Product> page, ProductQuery query) {
|
||||
return service.page(page, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 模糊查询部门,最多返回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 Collection<Product> fuzzyQuery(ProductQuery query) {
|
||||
// return service.list(query.name);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 删除产品
|
||||
@ -83,9 +80,8 @@ public class ProductController {
|
||||
* @return 被删除的产品
|
||||
*/
|
||||
@DeleteMapping("{id}")
|
||||
@Log(module = "产品", action = Log.Action.删除)
|
||||
public Product delete(@PathVariable("id") Long id) {
|
||||
return service.deleteById(id);
|
||||
public Boolean delete(@PathVariable("id") Long id) {
|
||||
return service.removeById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,7 +92,6 @@ public class ProductController {
|
||||
* @return 任务
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
@Log(module = "产品详情", action = Log.Action.其他)
|
||||
public Product detail(@PathVariable("id") Long id) {
|
||||
return service.detail(id);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.zsc.edu.gateway.modules.iot.product.dto;
|
||||
|
||||
import com.zsc.gateway.module.iot.product.domain.Product;
|
||||
import com.zsc.gateway.module.iot.tsl.dto.ParamDto;
|
||||
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.ParamDto;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
@ -23,6 +23,7 @@ import java.util.Set;
|
||||
@AllArgsConstructor
|
||||
@TableName("iot_product")
|
||||
public class Product extends BaseEntity {
|
||||
//TODO 部门ID
|
||||
/**
|
||||
* 产品名称
|
||||
*/
|
||||
|
@ -1,12 +1,14 @@
|
||||
package com.zsc.edu.gateway.modules.iot.product.mapper;
|
||||
|
||||
import com.zsc.gateway.module.common.domain.BaseMapper;
|
||||
import com.zsc.gateway.module.iot.product.domain.Product;
|
||||
import com.zsc.gateway.module.iot.product.dto.ProductDto;
|
||||
import com.zsc.gateway.module.iot.tsl.mapper.ParamMapper;
|
||||
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 org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
@Mapper(componentModel = "spring", uses = {ParamMapper.class}, unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
/**
|
||||
* @author lenovo
|
||||
*/
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface ProductMapper extends BaseMapper<ProductDto, Product> {
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.zsc.edu.gateway.modules.iot.product.query;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Data
|
||||
public class ProductQuery {
|
||||
/**
|
||||
|
@ -2,13 +2,22 @@ package com.zsc.edu.gateway.modules.iot.product.repo;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
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;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Yao
|
||||
*/
|
||||
public interface ProductRepository extends BaseMapper<Product> {
|
||||
Optional<Product> findById(Long id);
|
||||
@Select("select * from iot_product where name=#{name}")
|
||||
Product findByName(@Param("name") String name);
|
||||
|
||||
IPage<Product> page(Page<Product> page, @Param("query") ProductQuery query);
|
||||
|
||||
Product selectById(@Param("id") Long id);
|
||||
}
|
||||
|
@ -1,84 +1,19 @@
|
||||
package com.zsc.edu.gateway.modules.iot.product.service;
|
||||
|
||||
import com.zsc.gateway.exception.ConstraintException;
|
||||
import com.zsc.gateway.exception.NotExistException;
|
||||
import com.zsc.gateway.module.common.service.BaseService;
|
||||
import com.zsc.gateway.module.iot.product.domain.Product;
|
||||
import com.zsc.gateway.module.iot.product.dto.ProductDto;
|
||||
import com.zsc.gateway.module.iot.product.mapper.ProductMapper;
|
||||
import com.zsc.gateway.module.iot.product.query.ProductQuery;
|
||||
import com.zsc.gateway.module.iot.product.repo.ProductRepo;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
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.Product;
|
||||
import com.zsc.edu.gateway.modules.iot.product.query.ProductQuery;
|
||||
|
||||
import java.util.Collection;
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
public interface ProductService extends IService<Product> {
|
||||
Product create(ProductDto dto);
|
||||
|
||||
@Service
|
||||
public class ProductService extends BaseService<Product, Long, ProductRepo> {
|
||||
Product update(ProductDto dto, Long id);
|
||||
|
||||
ProductMapper mapper;
|
||||
|
||||
public ProductService(ProductRepo repo, ProductMapper productMapper) {
|
||||
this.repo = repo;
|
||||
this.mapper = productMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建产品
|
||||
*/
|
||||
public Product create(ProductDto dto) {
|
||||
if (repo.existsByName(dto.getName())) {
|
||||
throw new ConstraintException("该设备已存在!");
|
||||
}
|
||||
Product product = mapper.toEntity(dto);
|
||||
return save(product);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新产品
|
||||
*/
|
||||
public Product update(ProductDto dto, Long id) {
|
||||
Product product = getOne(id);
|
||||
if (!product.getName().equals(dto.getName()) && repo.existsByName(dto.getName())) {
|
||||
throw new ConstraintException("deviceName", dto.getName(), "设备名称已存在");
|
||||
}
|
||||
mapper.convert(dto, product);
|
||||
return save(product);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询产品
|
||||
*
|
||||
* @param query 查询表单
|
||||
* @param pageable 分页参数
|
||||
*/
|
||||
public Page<Product> page(ProductQuery query, Pageable pageable) {
|
||||
return repo.page(query, pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除产品
|
||||
*
|
||||
* @param id 事件id
|
||||
* @return 删除事件
|
||||
*/
|
||||
public Product delete(Long id) {
|
||||
return deleteById(id);
|
||||
}
|
||||
|
||||
public Product detail(Long id) {
|
||||
return getOne(id);
|
||||
}
|
||||
|
||||
public Product findByName(String name) {
|
||||
return repo.findByName(name).orElseThrow(() -> new NotExistException("产品不存在"));
|
||||
}
|
||||
|
||||
public Collection<Product> list(String name) {
|
||||
ProductQuery query = new ProductQuery();
|
||||
query.setName(name);
|
||||
return page(query, PageRequest.of(0, 5)).getContent();
|
||||
}
|
||||
IPage<Product> page(Page<Product> page, ProductQuery query);
|
||||
}
|
||||
|
@ -1,21 +1,27 @@
|
||||
package com.zsc.edu.gateway.modules.iot.record.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Document(collection = "t_record")
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("iot_record")
|
||||
public class Record {
|
||||
@Id
|
||||
@TableId
|
||||
private String id;
|
||||
|
||||
private String clientId;
|
||||
|
||||
private String AttachmentId;
|
||||
private String attachmentId;
|
||||
|
||||
private Map<String, Object> content;
|
||||
|
||||
|
@ -1,18 +0,0 @@
|
||||
package com.zsc.edu.gateway.modules.iot.record.repo;
|
||||
|
||||
import com.zsc.gateway.module.iot.record.domain.Record;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
import org.springframework.data.mongodb.repository.Query;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public interface RecordRepo extends MongoRepository<Record, Long> {
|
||||
|
||||
List<Record> findAllByClientIdAndRecordTimeAfter(String clientId, Date recordTime);
|
||||
|
||||
@Query("{'content.recordTimeStr': {$eq: ?0}}")
|
||||
List<Record> findByRecordTimeStr(String recordTimeStr);
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
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 org.mapstruct.Mapper;
|
||||
import org.springframework.data.mongodb.repository.Query;
|
||||
|
||||
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);
|
||||
|
||||
|
||||
}
|
@ -1,52 +1,18 @@
|
||||
package com.zsc.edu.gateway.modules.iot.record.service;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.zsc.gateway.module.iot.record.domain.Record;
|
||||
import com.zsc.gateway.module.iot.record.repo.RecordRepo;
|
||||
import com.zsc.gateway.module.utils.RedisUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.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.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
public class RecordService {
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
public interface RecordService extends IService<Record> {
|
||||
Record create(Record record);
|
||||
|
||||
RecordRepo repo;
|
||||
List<Record> page(IPage<Record> page, String clientId);
|
||||
|
||||
RedisUtils redisUtils;
|
||||
|
||||
public Record create(Record record) {
|
||||
return repo.save(record);
|
||||
}
|
||||
|
||||
public Page<Record> page(String clientId, Pageable pageable) {
|
||||
Record record = new Record();
|
||||
if (!Strings.isNullOrEmpty(clientId)) {
|
||||
record.setClientId(clientId);
|
||||
}
|
||||
Example<Record> example = Example.of(record);
|
||||
return repo.findAll(example, pageable);
|
||||
}
|
||||
|
||||
public List<Record> recordPhoto(String clientId) {
|
||||
Date recordTime = (Date) redisUtils.get("serve:sendTime:photograph:" + clientId);
|
||||
List<Record> records = repo.findAllByClientIdAndRecordTimeAfter(clientId, recordTime);
|
||||
Optional<Record> first = records.stream().sorted(Comparator.comparing(Record::getRecordTime).reversed()).findFirst();
|
||||
if (first.isPresent()) {
|
||||
String recordTimeStr = (String) first.get().getContent().get("recordTimeStr");
|
||||
return repo.findByRecordTimeStr(recordTimeStr);
|
||||
} else {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
}
|
||||
List<Record> recordPhoto(String clientId);
|
||||
}
|
||||
|
@ -1,15 +1,12 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.controller;
|
||||
|
||||
import com.zsc.gateway.framework.log.Log;
|
||||
import com.zsc.gateway.module.iot.tsl.domain.Event;
|
||||
import com.zsc.gateway.module.iot.tsl.dto.EventDto;
|
||||
import com.zsc.gateway.module.iot.tsl.query.EventQuery;
|
||||
import com.zsc.gateway.module.iot.tsl.service.EventService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.EventDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Event;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.query.EventQuery;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.service.EventService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@ -29,7 +26,6 @@ public class EventController {
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
@Log(module = "事件", action = Log.Action.新建)
|
||||
public Event create(@RequestBody EventDto dto) {
|
||||
return service.create(dto);
|
||||
}
|
||||
@ -41,7 +37,6 @@ public class EventController {
|
||||
* @return 更新后的事件
|
||||
*/
|
||||
@PatchMapping("{id}")
|
||||
@Log(module = "产品", action = Log.Action.修改)
|
||||
public Event update(@RequestBody EventDto dto, @PathVariable("id") Long id) {
|
||||
return service.update(dto, id);
|
||||
}
|
||||
@ -51,29 +46,24 @@ public class EventController {
|
||||
* 查询事件
|
||||
*
|
||||
* @param query 事件的查询表单
|
||||
* @param pageable 分页参数
|
||||
* @param page 分页参数
|
||||
* @return Page<Device> 事件分页数据
|
||||
*/
|
||||
@GetMapping
|
||||
@Log(module = "事件", action = Log.Action.其他)
|
||||
public Page<Event> page(
|
||||
EventQuery query,
|
||||
@PageableDefault(sort = {"id"}, direction = Sort.Direction.DESC) Pageable pageable
|
||||
) {
|
||||
return service.page(query, pageable);
|
||||
public IPage<Event> page(Page<Event> page, EventQuery query) {
|
||||
return service.page(page, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询事件
|
||||
*
|
||||
* @param query 事件的查询表单
|
||||
* @return Page<Device> 事件分页数据
|
||||
*/
|
||||
@GetMapping("list")
|
||||
@Log(module = "事件", action = Log.Action.其他)
|
||||
public List<Event> list(EventQuery query) {
|
||||
return service.findByProductId(query.productId);
|
||||
}
|
||||
// /**
|
||||
// * 查询事件
|
||||
// *
|
||||
// * @param query 事件的查询表单
|
||||
// * @return Page<Device> 事件分页数据
|
||||
// */
|
||||
// @GetMapping("list")
|
||||
// public List<Event> list(EventQuery query) {
|
||||
// return service.findByProductId(query.productId);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 删除事件
|
||||
@ -82,9 +72,8 @@ public class EventController {
|
||||
* @return 被删除的事件
|
||||
*/
|
||||
@DeleteMapping("{id}")
|
||||
@Log(module = "事件", action = Log.Action.删除)
|
||||
public Event delete(@PathVariable("id") Long id) {
|
||||
return service.deleteById(id);
|
||||
public Boolean delete(@PathVariable("id") Long id) {
|
||||
return service.removeById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,7 +84,6 @@ public class EventController {
|
||||
* @return 任务
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
@Log(module = "事件详情", action = Log.Action.其他)
|
||||
public Event detail(@PathVariable("id") Long id) {
|
||||
return service.detail(id);
|
||||
}
|
||||
|
@ -1,15 +1,12 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.controller;
|
||||
|
||||
import com.zsc.gateway.framework.log.Log;
|
||||
import com.zsc.gateway.module.iot.tsl.domain.Property;
|
||||
import com.zsc.gateway.module.iot.tsl.dto.PropertyDto;
|
||||
import com.zsc.gateway.module.iot.tsl.query.PropertyQuery;
|
||||
import com.zsc.gateway.module.iot.tsl.service.PropertyService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.PropertyDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Property;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.query.PropertyQuery;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.service.PropertyService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@ -32,7 +29,6 @@ public class PropertyController {
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
@Log(module = "属性", action = Log.Action.新建)
|
||||
public Property create(@RequestBody PropertyDto dto) {
|
||||
return service.create(dto);
|
||||
}
|
||||
@ -44,7 +40,6 @@ public class PropertyController {
|
||||
* @return 更新后的属性
|
||||
*/
|
||||
@PatchMapping("{id}")
|
||||
@Log(module = "属性", action = Log.Action.修改)
|
||||
public Property update(@RequestBody PropertyDto dto, @PathVariable("id") Long id) {
|
||||
return service.update(dto, id);
|
||||
}
|
||||
@ -54,29 +49,24 @@ public class PropertyController {
|
||||
* 查询属性
|
||||
*
|
||||
* @param query 属性的查询表单
|
||||
* @param pageable 分页参数
|
||||
* @param page 分页参数
|
||||
* @return Page<Device> 属性分页数据
|
||||
*/
|
||||
@GetMapping
|
||||
@Log(module = "属性", action = Log.Action.其他)
|
||||
public Page<Property> page(
|
||||
PropertyQuery query,
|
||||
@PageableDefault(sort = {"id"}, direction = Sort.Direction.DESC) Pageable pageable
|
||||
) {
|
||||
return service.page(query, pageable);
|
||||
public IPage<Property> page(Page<Property> page, PropertyQuery query) {
|
||||
return service.page(page, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询属性
|
||||
*
|
||||
* @param query 属性的查询表单
|
||||
* @return Page<Device> 属性分页数据
|
||||
*/
|
||||
@GetMapping("list")
|
||||
@Log(module = "属性", action = Log.Action.其他)
|
||||
public List<Property> list(PropertyQuery query) {
|
||||
return service.findByProductIdAndIoType(query);
|
||||
}
|
||||
// /**
|
||||
// * 查询属性
|
||||
// *
|
||||
// * @param query 属性的查询表单
|
||||
// * @return Page<Device> 属性分页数据
|
||||
// */
|
||||
// @GetMapping("list")
|
||||
// public List<Property> list(PropertyQuery query) {
|
||||
// return service.findByProductIdAndIoType(query);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 删除属性
|
||||
@ -85,9 +75,8 @@ public class PropertyController {
|
||||
* @return 被删除的属性
|
||||
*/
|
||||
@DeleteMapping("{id}")
|
||||
@Log(module = "属性", action = Log.Action.删除)
|
||||
public Property delete(@PathVariable("id") Long id) {
|
||||
return service.deleteById(id);
|
||||
public Boolean delete(@PathVariable("id") Long id) {
|
||||
return service.removeById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,7 +87,6 @@ public class PropertyController {
|
||||
* @return 任务
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
@Log(module = "属性详情", action = Log.Action.其他)
|
||||
public Property detail(@PathVariable("id") Long id) {
|
||||
return service.detail(id);
|
||||
}
|
||||
|
@ -1,18 +1,14 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.controller;
|
||||
|
||||
import com.zsc.gateway.framework.log.Log;
|
||||
import com.zsc.gateway.module.iot.tsl.domain.Serve;
|
||||
import com.zsc.gateway.module.iot.tsl.dto.ServeDto;
|
||||
import com.zsc.gateway.module.iot.tsl.query.ServeQuery;
|
||||
import com.zsc.gateway.module.iot.tsl.service.ServeService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.ServeDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Serve;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.query.ServeQuery;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.service.ServeService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Yao
|
||||
@ -32,7 +28,6 @@ public class ServeController {
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
@Log(module = "服务", action = Log.Action.新建)
|
||||
public Serve create(@RequestBody ServeDto dto) {
|
||||
return serveService.create(dto);
|
||||
}
|
||||
@ -44,7 +39,6 @@ public class ServeController {
|
||||
* @return 更新后的服务
|
||||
*/
|
||||
@PatchMapping("{id}")
|
||||
@Log(module = "服务", action = Log.Action.修改)
|
||||
public Serve update(@RequestBody ServeDto dto, @PathVariable("id") Long id) {
|
||||
return serveService.update(dto, id);
|
||||
}
|
||||
@ -54,29 +48,24 @@ public class ServeController {
|
||||
* 查询服务
|
||||
*
|
||||
* @param query 服务的查询表单
|
||||
* @param pageable 服务参数
|
||||
* @param page 服务参数
|
||||
* @return Page<Device> 服务分页数据
|
||||
*/
|
||||
@GetMapping
|
||||
@Log(module = "服务", action = Log.Action.其他)
|
||||
public Page<Serve> page(
|
||||
ServeQuery query,
|
||||
@PageableDefault(sort = {"id"}, direction = Sort.Direction.DESC) Pageable pageable
|
||||
) {
|
||||
return serveService.page(query, pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询服务
|
||||
*
|
||||
* @param query 服务的查询表单
|
||||
* @return Page<Device> 服务分页数据
|
||||
*/
|
||||
@GetMapping("list")
|
||||
@Log(module = "服务", action = Log.Action.其他)
|
||||
public List<Serve> list(ServeQuery query) {
|
||||
return serveService.findByProductId(query.productId);
|
||||
public IPage<Serve> page(Page<Serve> page, ServeQuery query) {
|
||||
return serveService.page(page, query);
|
||||
}
|
||||
//
|
||||
// /**
|
||||
// * 查询服务
|
||||
// *
|
||||
// * @param query 服务的查询表单
|
||||
// * @return Page<Device> 服务分页数据
|
||||
// */
|
||||
// @GetMapping("list")
|
||||
// public List<Serve> list(ServeQuery query) {
|
||||
// return serveService.findByProductId(query.productId);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 删除服务
|
||||
@ -85,9 +74,8 @@ public class ServeController {
|
||||
* @return 被删除的服务
|
||||
*/
|
||||
@DeleteMapping("{id}")
|
||||
@Log(module = "服务", action = Log.Action.删除)
|
||||
public Serve delete(@PathVariable("id") Long id) {
|
||||
return serveService.deleteById(id);
|
||||
public Boolean delete(@PathVariable("id") Long id) {
|
||||
return serveService.removeById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,7 +86,6 @@ public class ServeController {
|
||||
* @return 任务
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
@Log(module = "服务详情", action = Log.Action.其他)
|
||||
public Serve detail(@PathVariable("id") Long id) {
|
||||
return serveService.detail(id);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.dto;
|
||||
|
||||
import com.zsc.gateway.module.iot.tsl.domain.Event;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Event;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.dto;
|
||||
|
||||
import com.zsc.gateway.module.iot.tsl.domain.DataType;
|
||||
import com.zsc.gateway.module.iot.tsl.domain.Param;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.DataType;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Param;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.dto;
|
||||
|
||||
import com.zsc.gateway.module.iot.tsl.domain.DataType;
|
||||
import com.zsc.gateway.module.iot.tsl.domain.Property;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.DataType;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Property;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -6,6 +6,9 @@ import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
|
@ -1,25 +1,25 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author rehtd
|
||||
* @description 物模型事件
|
||||
* @description 物模型事件
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@MappedSuperclass
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class BaseParam implements Serializable {
|
||||
/**
|
||||
* 序列化主键(有数据库提供,非自增)
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "basic_seq")
|
||||
@SequenceGenerator(name = "basic_seq", sequenceName = "seq_basic")
|
||||
private Long id = -1L;
|
||||
|
||||
/**
|
||||
|
@ -1,34 +1,57 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.entity;
|
||||
|
||||
import com.zsc.gateway.module.common.enums.IState;
|
||||
import com.baomidou.mybatisplus.annotation.IEnum;
|
||||
import com.zsc.edu.gateway.common.enums.IState;
|
||||
|
||||
public enum DataType implements IState<DataType> {
|
||||
/**
|
||||
* @author lenovo
|
||||
*/
|
||||
|
||||
public enum DataType implements IEnum<Integer>, IState<DataType> {
|
||||
/**
|
||||
* 整型
|
||||
*/
|
||||
INT,
|
||||
INT(1, "整型"),
|
||||
/**
|
||||
* 单精度浮点型
|
||||
*/
|
||||
FLOAT,
|
||||
FLOAT(2, "单精度浮点型"),
|
||||
/**
|
||||
* 双精度浮点型
|
||||
*/
|
||||
DOUBLE,
|
||||
DOUBLE(3, "双精度浮点型"),
|
||||
/**
|
||||
* 布尔型
|
||||
*/
|
||||
BOOLEAN,
|
||||
BOOLEAN(4, "布尔型"),
|
||||
/**
|
||||
* 字符串
|
||||
*/
|
||||
STRING,
|
||||
STRING(5, "字符串"),
|
||||
/**
|
||||
* 日期型
|
||||
*/
|
||||
DATE,
|
||||
DATE(6, "日期型"),
|
||||
/**
|
||||
* 透传
|
||||
*/
|
||||
RAW
|
||||
RAW(7, "透传");
|
||||
|
||||
private final int value;
|
||||
private final String description;
|
||||
|
||||
DataType(int value, String description) {
|
||||
this.value = value;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.description;
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,27 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IEnum;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.zsc.edu.gateway.common.enums.IState;
|
||||
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.Fetch;
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
import org.springframework.context.annotation.ImportSelector;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Yao
|
||||
* @desciption 物模型服务
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("iot_event")
|
||||
public class Event extends BaseParam {
|
||||
|
||||
private Long productId;
|
||||
@ -24,26 +29,40 @@ public class Event extends BaseParam {
|
||||
/**
|
||||
* 事件类型
|
||||
*/
|
||||
@Enumerated
|
||||
private Type type;
|
||||
|
||||
/**
|
||||
* 服务输出的参数
|
||||
*/
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@Fetch(FetchMode.SUBSELECT)
|
||||
@TableField(exist = false)
|
||||
private Set<Param> outputs;
|
||||
|
||||
public enum Type {
|
||||
public enum Type implements IEnum<Integer>, IState<Type> {
|
||||
/**
|
||||
* 主动
|
||||
*/
|
||||
主动,
|
||||
ACTIVE(1, "主动"),
|
||||
/**
|
||||
* 被动
|
||||
*/
|
||||
被动
|
||||
PASSIVE(2, "被动");
|
||||
|
||||
private final int value;
|
||||
private final String description;
|
||||
|
||||
Type(int value, String description) {
|
||||
this.value = value;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.description;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,21 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import com.baomidou.mybatisplus.annotation.IEnum;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.zsc.edu.gateway.common.enums.IState;
|
||||
import lombok.*;
|
||||
|
||||
|
||||
/**
|
||||
* @author Yao
|
||||
* @desciption 参数
|
||||
* @desciption 参数
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Getter
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("iot_param")
|
||||
public class Param extends BaseParam {
|
||||
/**
|
||||
* 数据类型
|
||||
@ -31,18 +34,36 @@ public class Param extends BaseParam {
|
||||
private Type type;
|
||||
|
||||
|
||||
public enum Type {
|
||||
public enum Type implements IEnum<Integer>, IState<Type> {
|
||||
/**
|
||||
* 物模型输入
|
||||
*/
|
||||
INPUT,
|
||||
INPUT(1, "Input"),
|
||||
/**
|
||||
* 物模型输出
|
||||
*/
|
||||
OUTPUT,
|
||||
OUTPUT(2, "Output"),
|
||||
/**
|
||||
* 读写属性
|
||||
*/
|
||||
RW
|
||||
RW(3, "Read Write");
|
||||
|
||||
private final int value;
|
||||
private final String description;
|
||||
|
||||
Type(int value, String description) {
|
||||
this.value = value;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.description;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,25 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IEnum;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.zsc.edu.gateway.common.enums.IState;
|
||||
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Enumerated;
|
||||
|
||||
/**
|
||||
* @author Yao
|
||||
* @desciption 物模型属性
|
||||
* @desciption 物模型属性
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("iot_property")
|
||||
public class Property extends BaseParam {
|
||||
|
||||
private Long productId;
|
||||
@ -26,18 +31,35 @@ public class Property extends BaseParam {
|
||||
/**
|
||||
* 读写类型
|
||||
*/
|
||||
@Enumerated
|
||||
private IoType ioType;
|
||||
|
||||
|
||||
public enum IoType {
|
||||
public enum IoType implements IEnum<Integer>, IState<IoType> {
|
||||
/**
|
||||
* 可读写
|
||||
*/
|
||||
读写,
|
||||
READ_WRITE(1, "可读写"),
|
||||
/**
|
||||
* 只读
|
||||
*/
|
||||
只读
|
||||
READ_ONLY(2, "只读");
|
||||
|
||||
private final int value;
|
||||
private final String description;
|
||||
|
||||
IoType(int value, String description) {
|
||||
this.value = value;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.description;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,22 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.Fetch;
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Yao
|
||||
* @desciption 物模型服务
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("iot_serve")
|
||||
public class Serve extends BaseParam {
|
||||
|
||||
private Long productId;
|
||||
@ -27,15 +24,13 @@ public class Serve extends BaseParam {
|
||||
/**
|
||||
* 服务所需参数
|
||||
*/
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@Fetch(FetchMode.SUBSELECT)
|
||||
@TableField(exist = false)
|
||||
private Set<Param> inputs;
|
||||
|
||||
/**
|
||||
* 服务输出的参数
|
||||
*/
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@Fetch(FetchMode.SUBSELECT)
|
||||
@TableField(exist = false)
|
||||
private Set<Param> outputs;
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.mapper;
|
||||
|
||||
import com.zsc.gateway.module.common.domain.BaseMapper;
|
||||
import com.zsc.gateway.module.iot.tsl.domain.Event;
|
||||
import com.zsc.gateway.module.iot.tsl.dto.EventDto;
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.EventDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Event;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
@Mapper(componentModel = "spring", uses = {ParamMapper.class}, unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface EventMapper extends BaseMapper<EventDto, Event> {
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.mapper;
|
||||
|
||||
import com.zsc.gateway.module.common.domain.BaseMapper;
|
||||
import com.zsc.gateway.module.iot.tsl.domain.Param;
|
||||
import com.zsc.gateway.module.iot.tsl.dto.ParamDto;
|
||||
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;
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.mapper;
|
||||
|
||||
import com.zsc.gateway.module.common.domain.BaseMapper;
|
||||
import com.zsc.gateway.module.iot.tsl.domain.Property;
|
||||
import com.zsc.gateway.module.iot.tsl.dto.PropertyDto;
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.PropertyDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Property;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.mapper;
|
||||
|
||||
import com.zsc.gateway.module.common.domain.BaseMapper;
|
||||
import com.zsc.gateway.module.iot.tsl.domain.Serve;
|
||||
import com.zsc.gateway.module.iot.tsl.dto.ServeDto;
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.ServeDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Serve;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
@Mapper(componentModel = "spring", uses = {ParamMapper.class}, unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface ServeMapper extends BaseMapper<ServeDto, Serve> {
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.zsc.edu.gateway.modules.iot.tsl.query;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Data
|
||||
public class EventQuery {
|
||||
|
||||
|
@ -1,8 +1,11 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.query;
|
||||
|
||||
import com.zsc.gateway.module.iot.tsl.domain.Property;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Property;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Data
|
||||
public class PropertyQuery {
|
||||
/**
|
||||
|
@ -1,35 +0,0 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.repo;
|
||||
|
||||
import com.querydsl.core.BooleanBuilder;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
import com.zsc.gateway.module.iot.tsl.domain.Event;
|
||||
import com.zsc.gateway.module.iot.tsl.query.EventQuery;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Yao
|
||||
*/
|
||||
public interface EventRepo extends BaseRepo<Event, Long> {
|
||||
|
||||
default BooleanBuilder predicate(EventQuery query) {
|
||||
BooleanBuilder predicate = new BooleanBuilder();
|
||||
return predicate;
|
||||
}
|
||||
|
||||
default Page<Event> page(EventQuery query, Pageable pageable) {
|
||||
Predicate predicate = predicate(query);
|
||||
if (pageable == null) {
|
||||
return page(predicate, Sort.by(Sort.Direction.ASC, "id"));
|
||||
}
|
||||
return page(predicate, pageable);
|
||||
}
|
||||
|
||||
Optional<Event> findByName(String name);
|
||||
|
||||
List<Event> findByProductId(Long productId);
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.repo;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Event;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.query.EventQuery;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Yao
|
||||
*/
|
||||
public interface EventRepository extends BaseMapper<Event> {
|
||||
@Select("select * from iot_event where name=#{name}")
|
||||
Event findByName(String name);
|
||||
|
||||
// List<Event> findByProductId(Long productId);
|
||||
|
||||
IPage<Event> page(Page<Event> page, @Param("query") EventQuery query);
|
||||
|
||||
Event selectById(@Param("id") Long id);
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.repo;
|
||||
|
||||
import com.querydsl.core.BooleanBuilder;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
import com.zsc.gateway.module.iot.tsl.domain.Property;
|
||||
import com.zsc.gateway.module.iot.tsl.query.PropertyQuery;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PropertyRepo extends BaseRepo<Property, Long> {
|
||||
|
||||
default BooleanBuilder predicate(PropertyQuery query) {
|
||||
BooleanBuilder predicate = new BooleanBuilder();
|
||||
return predicate;
|
||||
}
|
||||
|
||||
default Page<Property> page(PropertyQuery query, Pageable pageable) {
|
||||
Predicate predicate = predicate(query);
|
||||
if (pageable == null) {
|
||||
return page(predicate, Sort.by(Sort.Direction.ASC, "id"));
|
||||
}
|
||||
return page(predicate, pageable);
|
||||
}
|
||||
|
||||
List<Property> findByProductIdAndIoType(Long productId, Property.IoType ioType);
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.repo;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
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.query.PropertyQuery;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PropertyRepository extends BaseMapper<Property> {
|
||||
|
||||
|
||||
IPage<Property> page(Page<Property> page, @Param("query") PropertyQuery query);
|
||||
|
||||
Property selectById(@Param("id") Long id);
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.repo;
|
||||
|
||||
import com.querydsl.core.BooleanBuilder;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
import com.zsc.gateway.module.iot.tsl.domain.Serve;
|
||||
import com.zsc.gateway.module.iot.tsl.query.ServeQuery;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Yao
|
||||
*/
|
||||
public interface ServeRepo extends BaseRepo<Serve, Long> {
|
||||
default BooleanBuilder predicate(ServeQuery query) {
|
||||
BooleanBuilder predicate = new BooleanBuilder();
|
||||
|
||||
return predicate;
|
||||
}
|
||||
|
||||
default Page<Serve> page(ServeQuery query, Pageable pageable) {
|
||||
Predicate predicate = predicate(query);
|
||||
if (pageable == null) {
|
||||
return page(predicate, Sort.by(Sort.Direction.ASC, "id"));
|
||||
}
|
||||
return page(predicate, pageable);
|
||||
}
|
||||
|
||||
Optional<Serve> findByName(String name);
|
||||
|
||||
List<Serve> findByProductId(Long productId);
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.repo;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Property;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Serve;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.query.PropertyQuery;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.query.ServeQuery;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Yao
|
||||
*/
|
||||
public interface ServeRepository extends BaseMapper<Serve> {
|
||||
@Select("select * from iot_serve where name=#{name}")
|
||||
Serve findByName(@Param("name") String name);
|
||||
|
||||
// List<Serve> findByProductId(Long productId);
|
||||
|
||||
IPage<Serve> page(Page<Serve> page, @Param("query") ServeQuery query);
|
||||
|
||||
Serve selectById(@Param("id") Long id);
|
||||
|
||||
}
|
@ -1,85 +1,30 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.service;
|
||||
|
||||
import com.zsc.gateway.exception.ConstraintException;
|
||||
import com.zsc.gateway.exception.NotExistException;
|
||||
import com.zsc.gateway.module.common.service.BaseService;
|
||||
import com.zsc.gateway.module.iot.tsl.domain.Event;
|
||||
import com.zsc.gateway.module.iot.tsl.dto.EventDto;
|
||||
import com.zsc.gateway.module.iot.tsl.mapper.EventMapper;
|
||||
import com.zsc.gateway.module.iot.tsl.query.EventQuery;
|
||||
import com.zsc.gateway.module.iot.tsl.repo.EventRepo;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.EventDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Event;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.query.EventQuery;
|
||||
|
||||
/**
|
||||
* @author Yao
|
||||
* @author zhuang
|
||||
*/
|
||||
@Service
|
||||
public class EventService extends BaseService<Event, Long, EventRepo> {
|
||||
public interface EventService extends IService<Event> {
|
||||
Event create(EventDto dto);
|
||||
|
||||
EventMapper mapper;
|
||||
Event update(EventDto dto, Long id);
|
||||
|
||||
public EventService(EventRepo repo, EventMapper mapper) {
|
||||
this.repo = repo;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
IPage<Event> page(Page<Event> page, EventQuery query);
|
||||
|
||||
/**
|
||||
* 新建物模型事件
|
||||
*/
|
||||
public Event create(EventDto dto) {
|
||||
if (repo.findByName(dto.getName()).isPresent()) {
|
||||
throw new ConstraintException("该事件已存在!");
|
||||
}
|
||||
Event event = mapper.toEntity(dto);
|
||||
return save(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新物模型事件
|
||||
*/
|
||||
public Event update(EventDto dto, Long id) {
|
||||
Event event = this.getOne(id);
|
||||
BeanUtils.copyProperties(dto, event);
|
||||
return save(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询物模型事件
|
||||
*
|
||||
* @param query 查询表单
|
||||
* @param pageable 分页参数
|
||||
*/
|
||||
public Page<Event> page(EventQuery query, Pageable pageable) {
|
||||
return repo.page(query, pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除物模型事件
|
||||
*
|
||||
* @param id 事件id
|
||||
* @return 删除事件
|
||||
*/
|
||||
public Event delete(Long id) {
|
||||
return deleteById(id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据产品ID查找事件
|
||||
*
|
||||
* @param productId 产品id
|
||||
* @return
|
||||
*/
|
||||
public List<Event> findByProductId(Long productId) {
|
||||
return repo.findByProductId(productId);
|
||||
}
|
||||
|
||||
public Event detail(Long id) {
|
||||
return repo.findById(id).orElseThrow(NotExistException::new);
|
||||
}
|
||||
// /**
|
||||
// * 根据产品ID查找事件
|
||||
// *
|
||||
// * @param productId 产品id
|
||||
// * @return
|
||||
// */
|
||||
// public List<Event> findByProductId(Long productId) {
|
||||
// return repo.findByProductId(productId);
|
||||
// }
|
||||
Event detail(Long id);
|
||||
}
|
||||
|
@ -1,81 +1,30 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.service;
|
||||
|
||||
import com.zsc.gateway.exception.NotExistException;
|
||||
import com.zsc.gateway.module.common.service.BaseService;
|
||||
import com.zsc.gateway.module.iot.tsl.domain.Property;
|
||||
import com.zsc.gateway.module.iot.tsl.dto.PropertyDto;
|
||||
import com.zsc.gateway.module.iot.tsl.mapper.PropertyMapper;
|
||||
import com.zsc.gateway.module.iot.tsl.query.PropertyQuery;
|
||||
import com.zsc.gateway.module.iot.tsl.repo.PropertyRepo;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.PropertyDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Property;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.query.PropertyQuery;
|
||||
|
||||
/**
|
||||
* @author 15864
|
||||
* @author zhuang
|
||||
*/
|
||||
@Service
|
||||
public class PropertyService extends BaseService<Property, Long, PropertyRepo> {
|
||||
public interface PropertyService extends IService<Property> {
|
||||
Property create(PropertyDto dto);
|
||||
|
||||
PropertyMapper mapper;
|
||||
Property update(PropertyDto dto, Long id);
|
||||
|
||||
public PropertyService(PropertyRepo repo, PropertyMapper mapper) {
|
||||
this.repo = repo;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
IPage<Property> page(Page<Property> page, PropertyQuery query);
|
||||
|
||||
/**
|
||||
* 新建物模型属性
|
||||
*/
|
||||
public Property create(PropertyDto dto) {
|
||||
Property property = mapper.toEntity(dto);
|
||||
return save(property);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新属性
|
||||
*/
|
||||
public Property update(PropertyDto dto, Long id) {
|
||||
Property property = this.getOne(id);
|
||||
BeanUtils.copyProperties(dto, property);
|
||||
return save(property);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询物模型属性
|
||||
*
|
||||
* @param query 查询表单
|
||||
* @param pageable 分页参数
|
||||
*/
|
||||
public Page<Property> page(PropertyQuery query, Pageable pageable) {
|
||||
return repo.page(query, pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除属性
|
||||
*
|
||||
* @param id 属性id
|
||||
* @return 删除属性
|
||||
*/
|
||||
public Property delete(Long id) {
|
||||
return deleteById(id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据产品ID查找属性
|
||||
*
|
||||
* @param query 查询表单
|
||||
* @return
|
||||
*/
|
||||
public List<Property> findByProductIdAndIoType(PropertyQuery query) {
|
||||
return repo.findByProductIdAndIoType(query.productId, query.type);
|
||||
}
|
||||
|
||||
public Property detail(Long id) {
|
||||
return repo.findById(id).orElseThrow(() -> new NotExistException("属性不存在"));
|
||||
}
|
||||
// /**
|
||||
// * 根据产品ID查找属性
|
||||
// *
|
||||
// * @param query 查询表单
|
||||
// * @return
|
||||
// */
|
||||
// public List<Property> findByProductIdAndIoType(PropertyQuery query) {
|
||||
// return repo.findByProductIdAndIoType(query.productId, query.type);
|
||||
// }
|
||||
Property detail(Long id);
|
||||
}
|
||||
|
@ -1,86 +1,31 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.service;
|
||||
|
||||
import com.zsc.gateway.exception.ConstraintException;
|
||||
import com.zsc.gateway.exception.NotExistException;
|
||||
import com.zsc.gateway.module.common.service.BaseService;
|
||||
import com.zsc.gateway.module.iot.tsl.domain.Serve;
|
||||
import com.zsc.gateway.module.iot.tsl.dto.ServeDto;
|
||||
import com.zsc.gateway.module.iot.tsl.mapper.ServeMapper;
|
||||
import com.zsc.gateway.module.iot.tsl.query.ServeQuery;
|
||||
import com.zsc.gateway.module.iot.tsl.repo.ServeRepo;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.ServeDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Serve;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.query.ServeQuery;
|
||||
|
||||
/**
|
||||
* @author 15864
|
||||
* @author zhuang
|
||||
*/
|
||||
@Service
|
||||
public class ServeService extends BaseService<Serve, Long, ServeRepo> {
|
||||
public interface ServeService extends IService<Serve> {
|
||||
Serve create(ServeDto dto);
|
||||
|
||||
ServeMapper mapper;
|
||||
Serve update(ServeDto dto, Long id);
|
||||
|
||||
public ServeService(ServeRepo repo, ServeMapper mapper) {
|
||||
this.repo = repo;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
IPage<Serve> page(Page<Serve> page, ServeQuery query);
|
||||
|
||||
/**
|
||||
* 新建功能
|
||||
*/
|
||||
public Serve create(ServeDto dto) {
|
||||
if (repo.findByName(dto.getName()).isPresent()) {
|
||||
throw new ConstraintException("该事件已存在!");
|
||||
}
|
||||
Serve entity = mapper.toEntity(dto);
|
||||
return save(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新功能
|
||||
*/
|
||||
public Serve update(ServeDto dto, Long id) {
|
||||
Serve serve = this.getOne(id);
|
||||
BeanUtils.copyProperties(dto, serve);
|
||||
return save(serve);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询功能
|
||||
*
|
||||
* @param query 查询表单
|
||||
* @param pageable 分页参数
|
||||
*/
|
||||
public Page<Serve> page(ServeQuery query, Pageable pageable) {
|
||||
return repo.page(query, pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除事件
|
||||
*
|
||||
* @param id 功能id
|
||||
* @return 删除功能
|
||||
*/
|
||||
public Serve delete(Long id) {
|
||||
return deleteById(id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据产品ID查找服务
|
||||
*
|
||||
* @param productId 产品id
|
||||
* @return
|
||||
*/
|
||||
public List<Serve> findByProductId(Long productId) {
|
||||
return repo.findByProductId(productId);
|
||||
}
|
||||
|
||||
public Serve detail(Long id) {
|
||||
return repo.findById(id).orElseThrow(NotExistException::new);
|
||||
}
|
||||
//
|
||||
// /**
|
||||
// * 根据产品ID查找服务
|
||||
// *
|
||||
// * @param productId 产品id
|
||||
// * @return
|
||||
// */
|
||||
// public List<Serve> findByProductId(Long productId) {
|
||||
// return repo.findByProductId(productId);
|
||||
// }
|
||||
Serve detail(Long id);
|
||||
}
|
||||
|
@ -0,0 +1,74 @@
|
||||
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.exception.ConstraintException;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.EventDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Event;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.mapper.EventMapper;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.query.EventQuery;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.repo.EventRepository;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.service.EventService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author Yao
|
||||
*/
|
||||
@Service
|
||||
public class EventServiceImpl extends ServiceImpl<EventRepository, Event> implements EventService {
|
||||
|
||||
EventMapper mapper;
|
||||
EventRepository repo;
|
||||
|
||||
|
||||
/**
|
||||
* 新建物模型事件
|
||||
*/
|
||||
@Override
|
||||
public Event create(EventDto dto) {
|
||||
if (repo.findByName(dto.getName()) != null) {
|
||||
throw new ConstraintException("该事件已存在!");
|
||||
}
|
||||
Event event = mapper.toEntity(dto);
|
||||
save(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新物模型事件
|
||||
*/
|
||||
@Override
|
||||
public Event update(EventDto dto, Long id) {
|
||||
Event event = repo.selectById(id);
|
||||
BeanUtils.copyProperties(dto, event);
|
||||
updateById(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询物模型事件
|
||||
*
|
||||
* @param query 查询表单
|
||||
* @param page 分页参数
|
||||
*/
|
||||
@Override
|
||||
public IPage<Event> page(Page<Event> page, EventQuery query) {
|
||||
return repo.page(page, query);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 根据产品ID查找事件
|
||||
// *
|
||||
// * @param productId 产品id
|
||||
// * @return
|
||||
// */
|
||||
// public List<Event> findByProductId(Long productId) {
|
||||
// return repo.findByProductId(productId);
|
||||
// }
|
||||
@Override
|
||||
public Event detail(Long id) {
|
||||
return repo.selectById(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
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.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;
|
||||
|
||||
/**
|
||||
* @author 15864
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
public class PropertyServiceImpl extends ServiceImpl<PropertyRepository, Property> implements PropertyService {
|
||||
|
||||
PropertyMapper mapper;
|
||||
@Resource
|
||||
private final PropertyRepository repo;
|
||||
|
||||
/**
|
||||
* 新建物模型属性
|
||||
*/
|
||||
@Override
|
||||
public Property create(PropertyDto dto) {
|
||||
Property property = mapper.toEntity(dto);
|
||||
save(property);
|
||||
return property;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新属性
|
||||
*/
|
||||
@Override
|
||||
public Property update(PropertyDto dto, Long id) {
|
||||
Property property = repo.selectById(id);
|
||||
BeanUtils.copyProperties(dto, property);
|
||||
updateById(property);
|
||||
return property;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询物模型属性
|
||||
*
|
||||
* @param query 查询表单
|
||||
* @param page 分页参数
|
||||
*/
|
||||
@Override
|
||||
public IPage<Property> page(Page<Property> page, PropertyQuery query) {
|
||||
return repo.page(page, query);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 根据产品ID查找属性
|
||||
// *
|
||||
// * @param query 查询表单
|
||||
// * @return
|
||||
// */
|
||||
// public List<Property> findByProductIdAndIoType(PropertyQuery query) {
|
||||
// return repo.findByProductIdAndIoType(query.productId, query.type);
|
||||
// }
|
||||
@Override
|
||||
public Property detail(Long id) {
|
||||
return repo.selectById(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
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.exception.ConstraintException;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.ServeDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Serve;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.mapper.ServeMapper;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.query.ServeQuery;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.repo.ServeRepository;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.service.ServeService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
/**
|
||||
* @author 15864
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
public class ServeServiceImpl extends ServiceImpl<ServeRepository, Serve> implements ServeService {
|
||||
|
||||
ServeMapper mapper;
|
||||
@Resource
|
||||
private final ServeRepository repo;
|
||||
|
||||
/**
|
||||
* 新建功能
|
||||
*/
|
||||
@Override
|
||||
public Serve create(ServeDto dto) {
|
||||
if (repo.findByName(dto.getName()) != null) {
|
||||
throw new ConstraintException("该事件已存在!");
|
||||
}
|
||||
Serve entity = mapper.toEntity(dto);
|
||||
save(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新功能
|
||||
*/
|
||||
@Override
|
||||
public Serve update(ServeDto dto, Long id) {
|
||||
Serve serve = repo.selectById(id);
|
||||
BeanUtils.copyProperties(dto, serve);
|
||||
updateById(serve);
|
||||
return serve;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询功能
|
||||
*
|
||||
* @param query 查询表单
|
||||
* @param page 分页参数
|
||||
*/
|
||||
@Override
|
||||
public IPage<Serve> page(Page<Serve> page, ServeQuery query) {
|
||||
return repo.page(page, query);
|
||||
}
|
||||
|
||||
//
|
||||
// /**
|
||||
// * 根据产品ID查找服务
|
||||
// *
|
||||
// * @param productId 产品id
|
||||
// * @return
|
||||
// */
|
||||
// public List<Serve> findByProductId(Long productId) {
|
||||
// return repo.findByProductId(productId);
|
||||
// }
|
||||
@Override
|
||||
public Serve detail(Long id) {
|
||||
return repo.selectById(id);
|
||||
}
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
package com.zsc.edu.gateway.modules.notice.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IEnum;
|
||||
import com.zsc.edu.gateway.framework.common.enums.IState;
|
||||
import com.zsc.edu.gateway.common.enums.IState;
|
||||
|
||||
/**
|
||||
* 消息类型
|
||||
*
|
||||
* @author zhuang
|
||||
*/
|
||||
public enum MessageType implements IEnum<Integer>,IState<MessageType> {
|
||||
public enum MessageType implements IEnum<Integer>, IState<MessageType> {
|
||||
other(1,"其他"),
|
||||
resetThePassword(2,"重置密码");
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.zsc.edu.gateway.modules.notice.mapper;
|
||||
|
||||
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.BulletinDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
import org.mapstruct.Mapper;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.zsc.edu.gateway.modules.notice.mapper;
|
||||
|
||||
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.UserMessageDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Message;
|
||||
import org.mapstruct.Mapper;
|
||||
|
@ -1,8 +1,5 @@
|
||||
package com.zsc.edu.gateway.modules.notice.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.extension.plugins.pagination.Page;
|
||||
|
@ -1,7 +0,0 @@
|
||||
package com.zsc.edu.gateway.modules.notice.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessageAttachment;
|
||||
|
||||
public interface MessageAttachmentService extends IService<MessageAttachment> {
|
||||
}
|
@ -28,7 +28,7 @@ public interface UserMessageService extends IService<UserMessage> {
|
||||
|
||||
Integer countUnread(UserDetailsImpl userDetails);
|
||||
|
||||
Integer markAsRead(UserDetailsImpl userDetails, List<Long> messageIds);
|
||||
boolean markAsRead(UserDetailsImpl userDetails, List<Long> messageIds);
|
||||
|
||||
|
||||
IPage<AdminMessageVo> getAdminMessagePage(Page<UserMessageVo> page, AdminMessageQuery query);
|
||||
|
@ -73,10 +73,10 @@ public class BulletinServiceImpl extends ServiceImpl<BulletinRepository, Bulleti
|
||||
throw new ConstraintException("title", dto.title, "标题已存在");
|
||||
}
|
||||
Bulletin bulletin=new Bulletin();
|
||||
BeanUtils.copyProperties(dto,bulletin);
|
||||
bulletin.setCreateTime(LocalDateTime.now());
|
||||
bulletin.setCreateBy(userDetails.getName());
|
||||
bulletin.setEditUserId(userDetails.getId());
|
||||
// BeanUtils.copyProperties(dto,bulletin);
|
||||
// bulletin.setCreateTime(LocalDateTime.now());
|
||||
// bulletin.setCreateBy(userDetails.getName());
|
||||
// bulletin.setEditUserId(userDetails.getId());
|
||||
save(bulletin);
|
||||
if (dto.getAttachmentIds() != null) {
|
||||
insertInto(bulletin.getId(), dto.getAttachmentIds());
|
||||
|
@ -1,61 +0,0 @@
|
||||
package com.zsc.edu.gateway.modules.notice.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.BulletinUser;
|
||||
import com.zsc.edu.gateway.modules.notice.repo.BulletinUserRepository;
|
||||
import com.zsc.edu.gateway.modules.notice.service.BulletinUserService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
public class BulletinUserServiceImpl extends ServiceImpl<BulletinUserRepository, BulletinUser> implements BulletinUserService {
|
||||
|
||||
/**
|
||||
* 已读公告,每次已读自动获取用户id与公告id加入联表
|
||||
*
|
||||
* @param userDetails userDetails
|
||||
* @param id id
|
||||
* return true
|
||||
*/
|
||||
@Override
|
||||
public Boolean isRead(UserDetailsImpl userDetails, Long id) {
|
||||
if (id == null || userDetails.getId() == null) {
|
||||
throw new IllegalArgumentException("Bulletin ID and User ID cannot be null");
|
||||
}
|
||||
QueryWrapper<BulletinUser> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("bulletin_id", id)
|
||||
.eq("user_id", userDetails.getId());
|
||||
BulletinUser existingUser = getOne(queryWrapper);
|
||||
if (existingUser == null) {
|
||||
BulletinUser newUser = new BulletinUser();
|
||||
newUser.setBulletinId(id);
|
||||
newUser.setUserId(userDetails.getId());
|
||||
newUser.setIsRead(false);
|
||||
save(newUser);
|
||||
} else {
|
||||
UpdateWrapper<BulletinUser> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("bulletin_id", id).eq("user_id", userDetails.getId()).set("is_read", false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新公告后修改已读状态
|
||||
*
|
||||
* @param id id
|
||||
*/
|
||||
@Override
|
||||
public void toggleIsRead(Long id) {
|
||||
UpdateWrapper<BulletinUser> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("bulletin_id", id).set("is_read", true);
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.zsc.edu.gateway.modules.notice.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessageAttachment;
|
||||
import com.zsc.edu.gateway.modules.notice.repo.MessageAttachmentRepository;
|
||||
import com.zsc.edu.gateway.modules.notice.service.MessageAttachmentService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class MessageAttachmentServiceImpl extends ServiceImpl<MessageAttachmentRepository, MessageAttachment> implements MessageAttachmentService {
|
||||
}
|
@ -2,7 +2,6 @@ package com.zsc.edu.gateway.modules.notice.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@ -17,7 +16,6 @@ import com.zsc.edu.gateway.modules.notice.query.AdminMessageQuery;
|
||||
import com.zsc.edu.gateway.modules.notice.query.UserMessageQuery;
|
||||
import com.zsc.edu.gateway.modules.notice.repo.MessageRepository;
|
||||
import com.zsc.edu.gateway.modules.notice.repo.UserMessageRepository;
|
||||
import com.zsc.edu.gateway.modules.notice.service.MessageAttachmentService;
|
||||
import com.zsc.edu.gateway.modules.notice.service.UserMessageService;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.AdminMessageVo;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.UserMessageVo;
|
||||
@ -47,7 +45,6 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
private final EmailSender emailSender;
|
||||
private final SmsSender smsSender;
|
||||
private final UserMessageRepository userMessageRepository;
|
||||
private final MessageAttachmentService messageAttachmentService;
|
||||
private final UserRepository userRepository;
|
||||
private final MessageMapper messageMapper;
|
||||
/**
|
||||
@ -104,15 +101,15 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
* @return 修改记录数量
|
||||
*/
|
||||
@Override
|
||||
public Integer markAsRead(UserDetailsImpl userDetails, List<Long> messageIds) {
|
||||
public boolean markAsRead(UserDetailsImpl userDetails, List<Long> messageIds) {
|
||||
if (CollectionUtils.isEmpty(messageIds)) {
|
||||
throw new RuntimeException("messageIds is NULL!");
|
||||
}
|
||||
UpdateWrapper<UserMessage> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("user_id", userDetails.getId()).in("message_id", messageIds);
|
||||
updateWrapper.set("is_read", true);
|
||||
updateWrapper.set("read_time", LocalDateTime.now());
|
||||
return userMessageRepository.update(updateWrapper);
|
||||
return this.lambdaUpdate().eq(UserMessage::getUserId, userDetails.getId())
|
||||
.in(UserMessage::getMessageId, messageIds)
|
||||
.set(UserMessage::getIsRead, true)
|
||||
.set(UserMessage::getReadTime, LocalDateTime.now())
|
||||
.update();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.zsc.edu.gateway.modules.system.mapper;
|
||||
|
||||
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.system.dto.AuthorityDto;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Authority;
|
||||
import org.mapstruct.Mapper;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.zsc.edu.gateway.modules.system.mapper;
|
||||
|
||||
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.system.dto.DeptDto;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Dept;
|
||||
import org.mapstruct.Mapper;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.zsc.edu.gateway.modules.system.mapper;
|
||||
|
||||
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.system.dto.RoleAuthorityDto;
|
||||
import com.zsc.edu.gateway.modules.system.entity.RoleAuthority;
|
||||
import org.mapstruct.Mapper;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.zsc.edu.gateway.modules.system.mapper;
|
||||
|
||||
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.system.dto.RoleDto;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Role;
|
||||
import org.mapstruct.Mapper;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.zsc.edu.gateway.modules.system.mapper;
|
||||
|
||||
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.system.dto.UserCreateDto;
|
||||
import com.zsc.edu.gateway.modules.system.entity.User;
|
||||
import org.mapstruct.Mapper;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.zsc.edu.gateway.modules.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zsc.edu.gateway.common.util.TreeUtil;
|
||||
import com.zsc.edu.gateway.exception.ConstraintException;
|
||||
import com.zsc.edu.gateway.framework.common.util.TreeUtil;
|
||||
import com.zsc.edu.gateway.modules.system.dto.DeptDto;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Dept;
|
||||
import com.zsc.edu.gateway.modules.system.mapper.DeptMapper;
|
||||
|
@ -16,6 +16,11 @@ spring:
|
||||
username: gitea
|
||||
password: gitea
|
||||
driver-class-name: org.postgresql.Driver
|
||||
data:
|
||||
redis:
|
||||
host: 43.139.10.64
|
||||
port: 16379
|
||||
password:
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 40MB
|
||||
@ -45,3 +50,4 @@ spring:
|
||||
storage:
|
||||
attachment: ./storage/attachment
|
||||
temp: ./storage/temp
|
||||
|
||||
|
@ -4,4 +4,6 @@ spring:
|
||||
docker:
|
||||
compose:
|
||||
enabled: false
|
||||
|
||||
|
||||
gatherer:
|
||||
version: 001
|
@ -2,7 +2,7 @@
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zsc.edu.gateway.modules.iot.device.entity.Device">
|
||||
<mapper namespace="com.zsc.edu.gateway.modules.iot.device.repo.DeviceRepository">
|
||||
<resultMap id="BaseResultMap" type="com.zsc.edu.gateway.modules.iot.device.entity.Device">
|
||||
<id column="id" property="id"/>
|
||||
<result column="name" property="name"/>
|
||||
@ -15,6 +15,70 @@
|
||||
<result column="product_id" property="productId"/>
|
||||
<result column="extend_params" property="extendParams"/>
|
||||
<result column="properties" property="properties"/>
|
||||
<association property="product" javaType=""
|
||||
<result column="create_by" jdbcType="VARCHAR" property="createBy"/>
|
||||
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
|
||||
<result column="create_time" jdbcType="DATE" property="createTime"/>
|
||||
<result column="update_time" jdbcType="DATE" property="updateTime"/>
|
||||
<result column="remark" jdbcType="VARCHAR" property="remark"/>
|
||||
<association property="product" javaType="com.zsc.edu.gateway.modules.iot.product.entity.Product">
|
||||
<id column="id" property="id"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="type" property="type"/>
|
||||
<result column="model" property="model"/>
|
||||
<result column="link" property="link"/>
|
||||
<result column="create_by" jdbcType="VARCHAR" property="createBy"/>
|
||||
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
|
||||
<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="params" ofType="com.zsc.edu.gateway.modules.iot.tsl.entity.Param">
|
||||
<id column="id" property="id"/>
|
||||
<result column="data_type" property="dataType"/>
|
||||
<result column="uint" property="uint"/>
|
||||
<result column="type" property="type"/>
|
||||
<result column="identifier" property="identifier"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="remark" property="remark"/>
|
||||
</collection>
|
||||
</association>
|
||||
</resultMap>
|
||||
|
||||
<select id="page" resultMap="BaseResultMap">
|
||||
select * 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.is_online = #{query.isOnline}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectById" resultMap="BaseResultMap">
|
||||
select * 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="id!=null">
|
||||
d.id = #{id}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
</mapper>
|
67
src/main/resources/mappers/iotMappers/EventMapper.xml
Normal file
67
src/main/resources/mappers/iotMappers/EventMapper.xml
Normal file
@ -0,0 +1,67 @@
|
||||
<?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.zsc.edu.gateway.modules.iot.tsl.repo.EventRepository">
|
||||
<resultMap id="EventMap" type="com.zsc.edu.gateway.modules.iot.tsl.entity.Event">
|
||||
<id column="id" property="id"/>
|
||||
<result column="product_id" property="productId"/>
|
||||
<result column="type" property="type"/>
|
||||
<result column="identifier" property="identifier"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="remark" property="remark"/>
|
||||
<association property="product" javaType="com.zsc.edu.gateway.modules.iot.product.entity.Product">
|
||||
<id column="id" property="id"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="type" property="type"/>
|
||||
<result column="model" property="model"/>
|
||||
<result column="link" property="link"/>
|
||||
<result column="create_by" jdbcType="VARCHAR" property="createBy"/>
|
||||
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
|
||||
<result column="create_time" jdbcType="DATE" property="createTime"/>
|
||||
<result column="update_time" jdbcType="DATE" property="updateTime"/>
|
||||
<result column="remark" jdbcType="VARCHAR" property="remark"/>
|
||||
</association>
|
||||
<collection property="outputs" ofType="com.zsc.edu.gateway.modules.iot.tsl.entity.Param">
|
||||
<id column="id" property="id"/>
|
||||
<result column="data_type" property="dataType"/>
|
||||
<result column="uint" property="uint"/>
|
||||
<result column="type" property="type"/>
|
||||
<result column="identifier" property="identifier"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="remark" property="remark"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<select id="page" resultMap="EventMap">
|
||||
select * from
|
||||
iot_event e
|
||||
left join iot_product p on e.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 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 * from
|
||||
iot_event e
|
||||
left join iot_product p on e.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="id!=null">
|
||||
e.id = #{id}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
52
src/main/resources/mappers/iotMappers/ProductMapper.xml
Normal file
52
src/main/resources/mappers/iotMappers/ProductMapper.xml
Normal file
@ -0,0 +1,52 @@
|
||||
<?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.zsc.edu.gateway.modules.iot.product.repo.ProductRepository">
|
||||
<resultMap id="BaseResultMap" type="com.zsc.edu.gateway.modules.iot.product.entity.Product">
|
||||
<id column="id" property="id"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="type" property="type"/>
|
||||
<result column="model" property="model"/>
|
||||
<result column="link" property="link"/>
|
||||
<result column="create_by" jdbcType="VARCHAR" property="createBy"/>
|
||||
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
|
||||
<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="params" ofType="com.zsc.edu.gateway.modules.iot.tsl.entity.Param">
|
||||
<id column="id" property="id"/>
|
||||
<result column="data_type" property="dataType"/>
|
||||
<result column="uint" property="uint"/>
|
||||
<result column="type" property="type"/>
|
||||
<result column="identifier" property="identifier"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="remark" property="remark"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<select id="page" resultMap="BaseResultMap">
|
||||
select p.*, ip.* 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.links = #{query.links}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectById" resultMap="BaseResultMap">
|
||||
select p.*, ip.*
|
||||
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 p.id = #{id}
|
||||
</select>
|
||||
</mapper>
|
58
src/main/resources/mappers/iotMappers/PropertyMapper.xml
Normal file
58
src/main/resources/mappers/iotMappers/PropertyMapper.xml
Normal file
@ -0,0 +1,58 @@
|
||||
<?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.zsc.edu.gateway.modules.iot.tsl.repo.PropertyRepository">
|
||||
<resultMap id="ResultMap" type="com.zsc.edu.gateway.modules.iot.tsl.entity.Property">
|
||||
<id column="id" property="id"/>
|
||||
<result column="product_id" property="productId"/>
|
||||
<result column="data_type" property="dataType"/>
|
||||
<result column="io_type" property="ioType"/>
|
||||
<result column="identifier" property="identifier"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="remark" property="remark"/>
|
||||
<association property="product" javaType="com.zsc.edu.gateway.modules.iot.product.entity.Product">
|
||||
<id column="id" property="id"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="type" property="type"/>
|
||||
<result column="model" property="model"/>
|
||||
<result column="link" property="link"/>
|
||||
<result column="create_by" jdbcType="VARCHAR" property="createBy"/>
|
||||
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
|
||||
<result column="create_time" jdbcType="DATE" property="createTime"/>
|
||||
<result column="update_time" jdbcType="DATE" property="updateTime"/>
|
||||
<result column="remark" jdbcType="VARCHAR" property="remark"/>
|
||||
</association>
|
||||
</resultMap>
|
||||
|
||||
<select id="page" resultMap="ResultMap">
|
||||
select * from
|
||||
iot_property p
|
||||
left join iot_product pp on p.product_id = pp.id
|
||||
<where>
|
||||
<if test="query.name != null and query.name != ''">
|
||||
and e.name like CONCAT('%', #{query.name}, '%')
|
||||
</if>
|
||||
<if test="query.identifier != null and query.identifier != ''">
|
||||
and e.identifier like CONCAT('%', #{query.identifier}, '%')
|
||||
</if>
|
||||
<if test="query.type != null and query.type != ''">
|
||||
and e.io_type = #{query.type}
|
||||
</if>
|
||||
<if test="query.productId !=null">
|
||||
and e.product_id = #{query.productId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectById" resultMap="ResultMap">
|
||||
select * from
|
||||
iot_property p
|
||||
left join iot_product pp on p.product_id = pp.id
|
||||
<where>
|
||||
<if test="id!=null">
|
||||
e.id = #{id}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
61
src/main/resources/mappers/iotMappers/ServeMapper.xml
Normal file
61
src/main/resources/mappers/iotMappers/ServeMapper.xml
Normal file
@ -0,0 +1,61 @@
|
||||
<?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.zsc.edu.gateway.modules.iot.tsl.repo.ServeRepository">
|
||||
<resultMap id="ServeMap" type="com.zsc.edu.gateway.modules.iot.tsl.entity.Serve">
|
||||
<id column="id" property="id"/>
|
||||
<result column="product_id" property="productId"/>
|
||||
<result column="identifier" property="identifier"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="remark" property="remark"/>
|
||||
<collection property="inputs" ofType="com.zsc.edu.gateway.modules.iot.tsl.entity.Param">
|
||||
<id column="id" property="id"/>
|
||||
<result column="data_type" property="dataType"/>
|
||||
<result column="uint" property="uint"/>
|
||||
<result column="type" property="type"/>
|
||||
<result column="identifier" property="identifier"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="remark" property="remark"/>
|
||||
</collection>
|
||||
<collection property="outputs" ofType="com.zsc.edu.gateway.modules.iot.tsl.entity.Param">
|
||||
<id column="id" property="id"/>
|
||||
<result column="data_type" property="dataType"/>
|
||||
<result column="uint" property="uint"/>
|
||||
<result column="type" property="type"/>
|
||||
<result column="identifier" property="identifier"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="remark" property="remark"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<select id="page" resultMap="ServeMap">
|
||||
-- select * from iot_serve s
|
||||
-- left join iot_param p on s.id = p.serve_id
|
||||
-- left join iot_param_input pi on pi.param_id = p.id
|
||||
-- left join iot_param_output po on po.param_id = p.id
|
||||
<where>
|
||||
<if test="query.name != null and query.name != ''">
|
||||
and e.name like CONCAT('%', #{query.name}, '%')
|
||||
</if>
|
||||
<if test="query.identifier != null and query.identifier != ''">
|
||||
and e.identifier like CONCAT('%', #{query.identifier}, '%')
|
||||
</if>
|
||||
<if test="query.productId !=null">
|
||||
and e.product_id = #{query.productId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectById" resultMap="ServeMap">
|
||||
-- select * from iot_serve s
|
||||
-- left join iot_param p on s.id = p.serve_id
|
||||
-- left join iot_param_input pi on pi.param_id = p.id
|
||||
-- left join iot_param_output po on po.param_id = p.id
|
||||
<where>
|
||||
<if test="productId != null">
|
||||
and s.id = #{id}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user