bc_zhang 4 năm trước cách đây
mục cha
commit
204f6d9a30

+ 15 - 0
src/main/java/com/zglc/kg/controller/DeviceController.java

@@ -3,6 +3,7 @@ package com.zglc.kg.controller;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.zglc.kg.base.Result;
+import com.zglc.kg.entity.AircraftSystemRelationEntity;
 import com.zglc.kg.entity.DeleteEntity;
 import com.zglc.kg.entity.DeviceEntity;
 import io.swagger.annotations.Api;
@@ -37,6 +38,20 @@ public class DeviceController {
     @PostMapping("add")
     public Result<String> add(@RequestBody DeviceEntity data){return  deviceService.add(data);}
 
+    @ApiOperation("增添机型系统节点关系")
+    @ApiResponses({
+            @ApiResponse(code = 0, message = "成功")
+    })
+    @PostMapping("addAircraftSystemRelation")
+    public Result<String> add(@RequestBody AircraftSystemRelationEntity data){return  deviceService.addAircraftSystemRelation(data);}
+
+//    @ApiOperation("获得最新添加id")
+//    @ApiResponses({
+//            @ApiResponse(code = 0, message = "成功")
+//    })
+//    @PostMapping("getLastId")
+//    public Result<List<DeviceEntity>> getLastId(){return  Result.success(deviceService.getLastInsert());}
+
     @ApiOperation("删除元器件或系统")
     @ApiResponses({
             @ApiResponse(code = 0, message = "成功")

+ 28 - 0
src/main/java/com/zglc/kg/dao/AircraftSystemRelationDao.java

@@ -0,0 +1,28 @@
+package com.zglc.kg.dao;
+
+import com.zglc.kg.entity.AircraftSystemRelationEntity;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.data.neo4j.annotation.Query;
+import org.springframework.data.neo4j.repository.Neo4jRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface AircraftSystemRelationDao extends Neo4jRepository<AircraftSystemRelationEntity,Long> {
+
+
+    //返回节点n以及n指向或指向n的所有节点与关系
+//    @Query("MATCH p=(n:Person)-[:ACTED_IN]->(m:Movie) WHERE n.name={name1} RETURN p")
+//    @Query("MATCH p=(n:Bot)<-[r:BotRelation]->(m:Bot) WHERE m.name={name} RETURN p")
+    @Query("MATCH p=()-[r:Relation]->() RETURN p LIMIT 25")
+    List<AircraftSystemRelationEntity> findAllBySymptom(@Param("name1") String name);
+
+
+    @Query("MATCH p= (tom:Person)-[:Relation]->(tomHanksMovies) WHERE tom.name={name1} RETURN p")
+    List<AircraftSystemRelationEntity> findAllBySymptom1(@Param("name1") String name1);
+
+//    String nodeSql = String.format("MATCH (n:`%s`) <-[r]->(m) %s return * limit %s", domain, cqWhere,
+//            query.getPageSize());
+}
+

+ 2 - 0
src/main/java/com/zglc/kg/dao/DeviceDao.java

@@ -22,6 +22,8 @@ public interface DeviceDao extends Mapper<DeviceEntity> {
 
 	Integer getCount();
 
+	DeviceEntity getLastInsert();
+
 //	Integer insertNotExists(DeviceEntity device);
 
 //	Integer getIdByType(@Param("type") String type);

+ 69 - 0
src/main/java/com/zglc/kg/entity/Aircraft1Entity.java

@@ -0,0 +1,69 @@
+package com.zglc.kg.entity;
+
+import lombok.Data;
+import org.neo4j.ogm.annotation.NodeEntity;
+import org.neo4j.ogm.annotation.Property;
+
+import javax.persistence.*;
+
+@NodeEntity(label = "aircraft")
+public class Aircraft1Entity {
+
+    @Id
+    @GeneratedValue
+    private Long id;
+
+    @Property(name = "aircraft_type")
+    private String aircraft_type;
+
+    @Property(name = "aircraft_describe")
+    private String aircraft_describe;
+
+    public Aircraft1Entity() {
+    }
+
+    public Aircraft1Entity(Long id, String aircraft_type, String aircraft_describe) {
+        this.id = id;
+        this.aircraft_type = aircraft_type;
+        this.aircraft_describe = aircraft_describe;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getAircraft_type() {
+        return aircraft_type;
+    }
+
+    public void setAircraft_type(String aircraft_type) {
+        this.aircraft_type = aircraft_type;
+    }
+
+    public String getAircraft_describe() {
+        return aircraft_describe;
+    }
+
+    public void setAircraft_describe(String aircraft_describe) {
+        this.aircraft_describe = aircraft_describe;
+    }
+
+
+
+//    @Override
+//    public String toString() {
+//        return "Aircraft1Entity{" +
+//                "id=" + id +
+//                ", aircraft_type='" + aircraft_type + '\'' +
+//                ", aircraft_type='" + aircraft_type + '\'' +
+//                ", aircraft_describe='" + aircraft_describe + '\'' +
+//                ", released='" + released + '\'' +
+//                '}';
+//    }
+
+
+}

+ 1 - 0
src/main/java/com/zglc/kg/entity/AircraftEntity.java

@@ -1,6 +1,7 @@
 package com.zglc.kg.entity;
 
 import lombok.Data;
+import org.neo4j.ogm.annotation.NodeEntity;
 
 import javax.persistence.*;
 

+ 74 - 0
src/main/java/com/zglc/kg/entity/AircraftSystemRelationEntity.java

@@ -0,0 +1,74 @@
+package com.zglc.kg.entity;
+
+import org.neo4j.ogm.annotation.EndNode;
+import org.neo4j.ogm.annotation.Property;
+import org.neo4j.ogm.annotation.RelationshipEntity;
+import org.neo4j.ogm.annotation.StartNode;
+
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+@RelationshipEntity(type = "Relation")
+public class AircraftSystemRelationEntity {
+    @Id
+    @GeneratedValue
+    private Long id;
+    @StartNode
+    private Aircraft1Entity startNode;
+    @EndNode
+    private Device1Entity endNode;
+    @Property
+    private String relation;
+
+    public AircraftSystemRelationEntity() {
+    }
+
+    public AircraftSystemRelationEntity(Long id, Aircraft1Entity startNode, Device1Entity endNode, String relation) {
+        this.id = id;
+        this.startNode = startNode;
+        this.endNode = endNode;
+        this.relation = relation;
+    }
+
+    public String getRelation() {
+        return relation;
+    }
+
+    public void setRelation(String relation) {
+        this.relation = relation;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Aircraft1Entity getStartNode() {
+        return startNode;
+    }
+
+    public void setStartNode(Aircraft1Entity startNode) {
+        this.startNode = startNode;
+    }
+
+    public Device1Entity getEndNode() {
+        return endNode;
+    }
+
+    public void setEndNode(Device1Entity endNode) {
+        this.endNode = endNode;
+    }
+
+    @Override
+    public String toString() {
+        return "RelationEntity{" +
+                "id=" + id +
+                ", startNode=" + startNode +
+                ", endNode=" + endNode +
+                ", relation='" + relation + '\'' +
+                '}';
+    }
+}

+ 145 - 0
src/main/java/com/zglc/kg/entity/Device1Entity.java

@@ -0,0 +1,145 @@
+package com.zglc.kg.entity;
+
+import lombok.Data;
+import org.neo4j.ogm.annotation.NodeEntity;
+import org.neo4j.ogm.annotation.Property;
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+
+@NodeEntity(label = "device")
+public class Device1Entity {
+
+    @Id
+    @GeneratedValue
+    private Long id;
+
+    @Property(name = "device_name")
+    private String device_name;
+
+    @Property(name = "device_type")
+    private Integer device_type;
+
+    @Property(name = "device_describe")
+    private String device_describe;
+
+    @Property(name = "aircraft_id")
+    private Integer aircraft_id;
+
+    @Property(name = "aircraft_type")
+    private String aircraft_type;
+
+    @Property(name = "syst_id")
+    private Integer syst_id;
+
+    @Property(name = "syst_name")
+    private String syst_name;
+
+    @Property(name = "subsys_id")
+    private Integer subsys_id;
+
+    @Property(name = "subsys_name")
+    private String subsys_name;
+
+
+    public Device1Entity() {
+    }
+
+    public Device1Entity(Long id, String device_name, Integer device_type,String device_describe, Integer aircraft_id,
+                         String aircraft_type,Integer syst_id,String syst_name,Integer subsys_id,String subsys_name) {
+        this.id = id;
+        this.device_name = device_name;
+        this.device_type = device_type;
+        this.device_describe = device_describe;
+        this.aircraft_id = aircraft_id;
+        this.aircraft_type = aircraft_type;
+        this.syst_id = syst_id;
+        this.syst_name = syst_name;
+        this.subsys_id = subsys_id;
+        this.subsys_name = subsys_name;
+
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getDevice_name() {
+        return device_name;
+    }
+
+    public void setDevice_name(String device_name) {
+        this.device_name = device_name;
+    }
+
+    public Integer getDevice_type() {
+        return device_type;
+    }
+
+    public void setDevice_type(Integer device_type) {
+        this.device_type = device_type;
+    }
+
+    public String getDevice_describe() {
+        return device_describe;
+    }
+
+    public void setDevice_describe(String device_describe) {
+        this.device_describe = device_describe;
+    }
+
+    public Integer getAircraft_id() {
+        return aircraft_id;
+    }
+
+    public void setAircraft_id(Integer aircraft_id) {
+        this.aircraft_id = aircraft_id;
+    }
+
+    public String getAircraft_type() {
+        return aircraft_type;
+    }
+
+    public void setAircraft_type(String aircraft_type) {
+        this.aircraft_type = aircraft_type;
+    }
+
+    public Integer getSyst_id() {
+        return syst_id;
+    }
+
+    public void setSyst_id(Integer syst_id) {
+        this.syst_id = syst_id;
+    }
+
+    public String getSyst_name() {
+        return syst_name;
+    }
+
+    public void setSyst_name(String syst_name) {
+        this.syst_name = syst_name;
+    }
+
+    public Integer getSubsys_id() {
+        return subsys_id;
+    }
+
+    public void setSubsys_id(Integer subsys_id) {
+        this.subsys_id = subsys_id;
+    }
+
+    public String getSubsys_name() {
+        return subsys_name;
+    }
+
+    public void setSubsys_name(String subsys_name) {
+        this.subsys_name = subsys_name;
+    }
+
+
+}

+ 2 - 4
src/main/java/com/zglc/kg/entity/DeviceEntity.java

@@ -3,6 +3,7 @@ import javax.persistence.*;
 import java.io.Serializable;
 
 import lombok.Data;
+import org.neo4j.ogm.annotation.NodeEntity;
 
 /**
  * 部门
@@ -16,11 +17,8 @@ import lombok.Data;
 @Data
 @Table(name = "t_device")
 public class DeviceEntity implements Serializable {
-    private static final long serialVersionUID = 1L;
+//    private static final long serialVersionUID = 1L;
 
-    /**
-     *
-     */
     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)
     @Column(name = "id")

+ 46 - 2
src/main/java/com/zglc/kg/service/DeviceService.java

@@ -1,6 +1,8 @@
 package com.zglc.kg.service;
-import com.zglc.kg.entity.DeviceEntity;
+import com.zglc.kg.entity.*;
 import com.zglc.kg.dao.DeviceDao;
+import com.zglc.kg.dao.AircraftDao;
+import com.zglc.kg.dao.AircraftSystemRelationDao;
 import org.springframework.stereotype.Service;
 import com.zglc.kg.base.Result;
 import tk.mybatis.mapper.entity.Example;
@@ -10,17 +12,50 @@ import java.util.List;
 
 @Service
 public class DeviceService {
+
     private DeviceDao deviceDao;
+    private AircraftDao aircraftDao;
+    private AircraftSystemRelationDao aircraftSystemRelationDao;
 
-    public DeviceService(DeviceDao deviceDao) {
+    public DeviceService(DeviceDao deviceDao,AircraftSystemRelationDao aircraftSystemRelationDao,AircraftDao aircraftDao) {
         this.deviceDao = deviceDao;
+        this.aircraftSystemRelationDao = aircraftSystemRelationDao;
+        this.aircraftDao = aircraftDao;
     }
 
     public Result<String> add(DeviceEntity data) {
         data.setId(null);
         boolean flag = true;
+        Integer deviceType = data.getDevice_type();
         String msg = "";
         int index = deviceDao.insertSelective(data);
+        switch (deviceType){
+            case 0:{
+                AircraftEntity aircraft = aircraftDao.selectByPrimaryKey(data.getAircraft_id());
+                AircraftSystemRelationEntity aircraftSystemRelation = new AircraftSystemRelationEntity();
+                Aircraft1Entity aircraft1 = new Aircraft1Entity();
+                aircraft1.setId(aircraft.getId().longValue());
+                aircraft1.setAircraft_type(aircraft.getAircraft_type());
+                aircraft1.setAircraft_describe(aircraft.getAircraft_describe());
+                aircraftSystemRelation.setStartNode(aircraft1);
+                DeviceEntity device = deviceDao.getLastInsert();
+                Device1Entity device1 = new Device1Entity();
+                device1.setId(device.getId().longValue());
+                device1.setDevice_name(device.getDevice_name());
+                device1.setDevice_type(device.getDevice_type());
+                device1.setDevice_describe(device.getDevice_describe());
+                device1.setAircraft_id(device.getAircraft_id());
+                device1.setAircraft_type(device.getAircraft_type());
+                device1.setSyst_id(device.getSyst_id());
+                device1.setSyst_name(device.getSubsys_name());
+                device1.setSubsys_id(device.getSubsys_id());
+                device1.setSubsys_name(device.getSubsys_name());
+                aircraftSystemRelation.setEndNode(device1);
+                aircraftSystemRelation.setRelation("包含");
+                aircraftSystemRelationDao.save(aircraftSystemRelation);
+            }
+        }
+
         if (index == 0) {
             flag = false;
             msg = "添加信息失败!";
@@ -30,6 +65,15 @@ public class DeviceService {
         return Result.result(flag, msg, msg);
     }
 
+//    public List<DeviceEntity> getLastInsert(){
+//        return deviceDao.getLastInsert();
+//    }
+
+    public Result<String> addAircraftSystemRelation(AircraftSystemRelationEntity aircraftSystemRelationEntity){
+        aircraftSystemRelationDao.save(aircraftSystemRelationEntity);
+        return Result.success("添加成功!");
+    }
+
     public Result<String> delete(List<Integer> ids) {
         boolean flag = true;
         String msg = "";

+ 4 - 0
src/main/resources/mapping/DeviceDao.xml

@@ -28,6 +28,10 @@
         from t_device
     </select>
 
+    <select id="getLastInsert" resultMap="userMap">
+        SELECT * FROM t_device ORDER BY id DESC LIMIT 1
+    </select>
+
     <select id="findByName" parameterType="String" resultMap="userMap">
         select * FROM t_device where device_name like #{name}
     </select>

BIN
target/classes/com/zglc/kg/controller/DeviceController.class


BIN
target/classes/com/zglc/kg/dao/AircraftSystemRelationDao.class


BIN
target/classes/com/zglc/kg/dao/DeviceDao.class


BIN
target/classes/com/zglc/kg/entity/Aircraft1Entity.class


BIN
target/classes/com/zglc/kg/entity/AircraftEntity.class


BIN
target/classes/com/zglc/kg/entity/AircraftSystemRelationEntity.class


BIN
target/classes/com/zglc/kg/entity/Device1Entity.class


BIN
target/classes/com/zglc/kg/entity/DeviceEntity.class


BIN
target/classes/com/zglc/kg/service/DeviceService.class


+ 4 - 0
target/classes/mapping/DeviceDao.xml

@@ -28,6 +28,10 @@
         from t_device
     </select>
 
+    <select id="getLastInsert" resultMap="userMap">
+        SELECT * FROM t_device ORDER BY id DESC LIMIT 1
+    </select>
+
     <select id="findByName" parameterType="String" resultMap="userMap">
         select * FROM t_device where device_name like #{name}
     </select>