新增sensor和point表的增删改查
parent
4b84f77cf4
commit
637e67fdb0
@ -0,0 +1,57 @@
|
|||||||
|
package com.xydl.cac.entity;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author jignjing
|
||||||
|
* @date 2024-01-31
|
||||||
|
**/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@Table(name = "n_point")
|
||||||
|
@ApiModel("装置点表")
|
||||||
|
public class NPoint {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "id")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(name = "sensor_id")
|
||||||
|
private String sensorId;
|
||||||
|
|
||||||
|
@Column(name = "filed")
|
||||||
|
private String filed;
|
||||||
|
|
||||||
|
@Column(name = "filed_desc")
|
||||||
|
private Integer filedDesc;
|
||||||
|
|
||||||
|
@Column(name = "point_id")
|
||||||
|
private Integer pointId;
|
||||||
|
|
||||||
|
@Column(name = "type")
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private List<NPoint> children;
|
||||||
|
|
||||||
|
public void addChild(NPoint item) {
|
||||||
|
if (children == null) {
|
||||||
|
children = new ArrayList<>();
|
||||||
|
}
|
||||||
|
children.add(item);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
package com.xydl.cac.entity;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author jignjing
|
||||||
|
* @date 2024-01-31
|
||||||
|
**/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@Table(name = "n_sensor")
|
||||||
|
@ApiModel("装置表")
|
||||||
|
public class NSensor {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "id")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(name = "name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name = "phase")
|
||||||
|
private String phase;
|
||||||
|
|
||||||
|
@Column(name = "table_name")
|
||||||
|
private String tableName;
|
||||||
|
|
||||||
|
@Column(name = "sensor_code")
|
||||||
|
private String sensorCode;
|
||||||
|
|
||||||
|
@Column(name = "equipment_code")
|
||||||
|
private String equipmentId;
|
||||||
|
|
||||||
|
@Column(name = "status")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private List<NSensor> children;
|
||||||
|
|
||||||
|
public void addChild(NSensor item) {
|
||||||
|
if (children == null) {
|
||||||
|
children = new ArrayList<>();
|
||||||
|
}
|
||||||
|
children.add(item);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.xydl.cac.repository;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.NPoint;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface NPointRepository extends JpaRepository<NPoint, Integer>, JpaSpecificationExecutor<NPoint> {
|
||||||
|
|
||||||
|
Optional<NPoint> findById(Integer id);
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.xydl.cac.repository;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.NSensor;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface NSensorRepository extends JpaRepository<NSensor, Integer>, JpaSpecificationExecutor<NSensor> {
|
||||||
|
|
||||||
|
Optional<NSensor> findById(Integer id);
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.xydl.cac.service;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.NPoint;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface NPointService {
|
||||||
|
|
||||||
|
List<NPoint> listAll();
|
||||||
|
|
||||||
|
Page<NPoint> list(int pageNum, int pageSize);
|
||||||
|
|
||||||
|
NPoint add(NPoint item) throws Exception;
|
||||||
|
|
||||||
|
void update(NPoint item) throws Exception;
|
||||||
|
|
||||||
|
void delete(Integer id);
|
||||||
|
|
||||||
|
NPoint detail(Integer id) throws Exception;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.xydl.cac.service;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.NSensor;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface NSensorService {
|
||||||
|
List<NSensor> listAll();
|
||||||
|
|
||||||
|
Page<NSensor> list(int pageNum, int pageSize);
|
||||||
|
|
||||||
|
NSensor add(NSensor item) throws Exception;
|
||||||
|
|
||||||
|
void update(NSensor item) throws Exception;
|
||||||
|
|
||||||
|
void delete(Integer id);
|
||||||
|
|
||||||
|
NSensor detail(Integer id) throws Exception;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
package com.xydl.cac.service.impl;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.NPoint;
|
||||||
|
import com.xydl.cac.entity.NSensor;
|
||||||
|
import com.xydl.cac.repository.NPointRepository;
|
||||||
|
import com.xydl.cac.repository.NSensorRepository;
|
||||||
|
import com.xydl.cac.service.NPointService;
|
||||||
|
import com.xydl.cac.service.NSensorService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class NPointServiceImpl implements NPointService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
NPointRepository repository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<NPoint> listAll() {
|
||||||
|
List<NPoint> list = repository.findAll();
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<NPoint> list(int pageNum, int pageSize) {
|
||||||
|
PageRequest request = PageRequest.of(pageNum, pageSize);
|
||||||
|
Page<NPoint> result = repository.findAll(request);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPoint add(NPoint item) throws Exception {
|
||||||
|
item.setId(null);
|
||||||
|
return repository.save(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(NPoint item) throws Exception {
|
||||||
|
repository.save(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(Integer id) {
|
||||||
|
repository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPoint detail(Integer id) throws Exception {
|
||||||
|
Optional<NPoint> optional = repository.findById(id);
|
||||||
|
if (!optional.isPresent()) {
|
||||||
|
throw new Exception("未找到该记录");
|
||||||
|
}
|
||||||
|
return optional.get();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
package com.xydl.cac.service.impl;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.NSensor;
|
||||||
|
import com.xydl.cac.repository.NSensorRepository;
|
||||||
|
import com.xydl.cac.service.NSensorService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class NSensorServiceImpl implements NSensorService {
|
||||||
|
@Resource
|
||||||
|
NSensorRepository repository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<NSensor> listAll() {
|
||||||
|
List<NSensor> list = repository.findAll();
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<NSensor> list(int pageNum, int pageSize) {
|
||||||
|
PageRequest request = PageRequest.of(pageNum, pageSize);
|
||||||
|
Page<NSensor> result = repository.findAll(request);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NSensor add(NSensor item) throws Exception {
|
||||||
|
item.setId(null);
|
||||||
|
return repository.save(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(NSensor item) throws Exception {
|
||||||
|
repository.save(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(Integer id) {
|
||||||
|
repository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NSensor detail(Integer id) throws Exception {
|
||||||
|
Optional<NSensor> optional = repository.findById(id);
|
||||||
|
if (!optional.isPresent()) {
|
||||||
|
throw new Exception("未找到该记录");
|
||||||
|
}
|
||||||
|
return optional.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue