From 94177b25819c11f6113cfcb13246f4953c74d84d Mon Sep 17 00:00:00 2001 From: tiger_zhou <123456> Date: Wed, 22 Feb 2023 10:45:37 +0800 Subject: [PATCH] =?UTF-8?q?proto=E5=8F=8A=20rtss=20=20cros=E9=85=8D?= =?UTF-8?q?=E7=BD=AE(=E4=BF=AE=E6=94=B9=E5=9F=BA=E4=BA=8Eboot=202.7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ncc/pom.xml | 5 + .../joylink/ncc/constants/NccTypeEnum.java | 5 + .../ncc/controller/NccManageController.java | 29 + .../club/joylink/ncc/dao/NccMapDataDAO.java | 40 ++ .../club/joylink/ncc/entity/NccMapData.java | 32 ++ .../joylink/ncc/entity/NccMapDataExample.java | 543 ++++++++++++++++++ .../club/joylink/ncc/services/EcsSystem.java | 9 + .../joylink/ncc/services/MapDataService.java | 13 + .../ncc/services/impl/MapDataServiceImpl.java | 65 +++ .../club/joylink/ncc/vo/NccMapDataVO.java | 35 ++ .../mybatis/mapper/NccMapDataDAO.xml | 278 +++++++++ ncc/src/test/java/club/joylink/ncc/Data.java | 79 +++ .../test/java/club/joylink/ncc/Service.java | 52 ++ 13 files changed, 1185 insertions(+) create mode 100644 ncc/src/main/java/club/joylink/ncc/constants/NccTypeEnum.java create mode 100644 ncc/src/main/java/club/joylink/ncc/controller/NccManageController.java create mode 100644 ncc/src/main/java/club/joylink/ncc/dao/NccMapDataDAO.java create mode 100644 ncc/src/main/java/club/joylink/ncc/entity/NccMapData.java create mode 100644 ncc/src/main/java/club/joylink/ncc/entity/NccMapDataExample.java create mode 100644 ncc/src/main/java/club/joylink/ncc/services/EcsSystem.java create mode 100644 ncc/src/main/java/club/joylink/ncc/services/MapDataService.java create mode 100644 ncc/src/main/java/club/joylink/ncc/services/impl/MapDataServiceImpl.java create mode 100644 ncc/src/main/java/club/joylink/ncc/vo/NccMapDataVO.java create mode 100644 ncc/src/main/resources/mybatis/mapper/NccMapDataDAO.xml create mode 100644 ncc/src/test/java/club/joylink/ncc/Data.java create mode 100644 ncc/src/test/java/club/joylink/ncc/Service.java diff --git a/ncc/pom.xml b/ncc/pom.xml index 0d6d71001..4cbd49091 100644 --- a/ncc/pom.xml +++ b/ncc/pom.xml @@ -32,6 +32,11 @@ jl-ecs 0.1 + + junit + junit + test + diff --git a/ncc/src/main/java/club/joylink/ncc/constants/NccTypeEnum.java b/ncc/src/main/java/club/joylink/ncc/constants/NccTypeEnum.java new file mode 100644 index 000000000..1daf5302a --- /dev/null +++ b/ncc/src/main/java/club/joylink/ncc/constants/NccTypeEnum.java @@ -0,0 +1,5 @@ +package club.joylink.ncc.constants; + +public class NccTypeEnum { + +} diff --git a/ncc/src/main/java/club/joylink/ncc/controller/NccManageController.java b/ncc/src/main/java/club/joylink/ncc/controller/NccManageController.java new file mode 100644 index 000000000..444cdef42 --- /dev/null +++ b/ncc/src/main/java/club/joylink/ncc/controller/NccManageController.java @@ -0,0 +1,29 @@ +package club.joylink.ncc.controller; + +import club.joylink.ncc.services.MapDataService; +import club.joylink.ncc.vo.NccMapDataVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/ncc/manage") +public class NccManageController { + @Autowired + private MapDataService mapDataService; + + @PostMapping("saveOrUpdate") + public void saveOrUpdate(@RequestBody NccMapDataVO dataVO){ + this.mapDataService.saveOrUpdate(dataVO); + } + + @GetMapping() + public NccMapDataVO findId(Long id){ + return this.mapDataService.findById(id); + } + + @GetMapping("/{id}/change/{state}") + public void changeState(@PathVariable("id") Long id, @PathVariable("state") NccMapDataVO.MapDataEnum state){ + this.mapDataService.changeState(id,state); + } + +} diff --git a/ncc/src/main/java/club/joylink/ncc/dao/NccMapDataDAO.java b/ncc/src/main/java/club/joylink/ncc/dao/NccMapDataDAO.java new file mode 100644 index 000000000..34f37b7bf --- /dev/null +++ b/ncc/src/main/java/club/joylink/ncc/dao/NccMapDataDAO.java @@ -0,0 +1,40 @@ +package club.joylink.ncc.dao; + +import club.joylink.ncc.entity.NccMapData; +import club.joylink.ncc.entity.NccMapDataExample; +import java.util.List; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +@Mapper +@Repository +public interface NccMapDataDAO { + long countByExample(NccMapDataExample example); + + int deleteByExample(NccMapDataExample example); + + int deleteByPrimaryKey(Long id); + + int insert(NccMapData record); + + int insertSelective(NccMapData record); + + List selectByExampleWithBLOBs(NccMapDataExample example); + + List selectByExample(NccMapDataExample example); + + NccMapData selectByPrimaryKey(Long id); + + int updateByExampleSelective(@Param("record") NccMapData record, @Param("example") NccMapDataExample example); + + int updateByExampleWithBLOBs(@Param("record") NccMapData record, @Param("example") NccMapDataExample example); + + int updateByExample(@Param("record") NccMapData record, @Param("example") NccMapDataExample example); + + int updateByPrimaryKeySelective(NccMapData record); + + int updateByPrimaryKeyWithBLOBs(NccMapData record); + + int updateByPrimaryKey(NccMapData record); +} diff --git a/ncc/src/main/java/club/joylink/ncc/entity/NccMapData.java b/ncc/src/main/java/club/joylink/ncc/entity/NccMapData.java new file mode 100644 index 000000000..04c6ae9c3 --- /dev/null +++ b/ncc/src/main/java/club/joylink/ncc/entity/NccMapData.java @@ -0,0 +1,32 @@ +package club.joylink.ncc.entity; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.Date; + +import club.joylink.ncc.vo.NccMapDataVO; +import lombok.Data; + +/** + * @author + * + */ +@Data +public class NccMapData implements Serializable { + private Long id; + + private String name; + + private LocalDateTime createTime; + + private LocalDateTime updateTime; + + /** + * 状态0=发布,1=编辑,2=删除 + */ + private NccMapDataVO.MapDataEnum state; + + private byte[] mapData; + + private static final long serialVersionUID = 1L; +} diff --git a/ncc/src/main/java/club/joylink/ncc/entity/NccMapDataExample.java b/ncc/src/main/java/club/joylink/ncc/entity/NccMapDataExample.java new file mode 100644 index 000000000..146675e4b --- /dev/null +++ b/ncc/src/main/java/club/joylink/ncc/entity/NccMapDataExample.java @@ -0,0 +1,543 @@ +package club.joylink.ncc.entity; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class NccMapDataExample { + protected String orderByClause; + + protected boolean distinct; + + protected List oredCriteria; + + private Integer limit; + + private Long offset; + + public NccMapDataExample() { + oredCriteria = new ArrayList(); + } + + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + public String getOrderByClause() { + return orderByClause; + } + + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + public boolean isDistinct() { + return distinct; + } + + public List getOredCriteria() { + return oredCriteria; + } + + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.size() == 0) { + oredCriteria.add(criteria); + } + return criteria; + } + + protected Criteria createCriteriaInternal() { + Criteria criteria = new Criteria(); + return criteria; + } + + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + public void setLimit(Integer limit) { + this.limit = limit; + } + + public Integer getLimit() { + return limit; + } + + public void setOffset(Long offset) { + this.offset = offset; + } + + public Long getOffset() { + return offset; + } + + protected abstract static class GeneratedCriteria { + protected List criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); + } + criteria.add(new Criterion(condition)); + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value)); + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value1, value2)); + } + + public Criteria andIdIsNull() { + addCriterion("id is null"); + return (Criteria) this; + } + + public Criteria andIdIsNotNull() { + addCriterion("id is not null"); + return (Criteria) this; + } + + public Criteria andIdEqualTo(Long value) { + addCriterion("id =", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotEqualTo(Long value) { + addCriterion("id <>", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThan(Long value) { + addCriterion("id >", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThanOrEqualTo(Long value) { + addCriterion("id >=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThan(Long value) { + addCriterion("id <", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThanOrEqualTo(Long value) { + addCriterion("id <=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdIn(List values) { + addCriterion("id in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdNotIn(List values) { + addCriterion("id not in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdBetween(Long value1, Long value2) { + addCriterion("id between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andIdNotBetween(Long value1, Long value2) { + addCriterion("id not between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andNameIsNull() { + addCriterion("`name` is null"); + return (Criteria) this; + } + + public Criteria andNameIsNotNull() { + addCriterion("`name` is not null"); + return (Criteria) this; + } + + public Criteria andNameEqualTo(String value) { + addCriterion("`name` =", value, "name"); + return (Criteria) this; + } + + public Criteria andNameNotEqualTo(String value) { + addCriterion("`name` <>", value, "name"); + return (Criteria) this; + } + + public Criteria andNameGreaterThan(String value) { + addCriterion("`name` >", value, "name"); + return (Criteria) this; + } + + public Criteria andNameGreaterThanOrEqualTo(String value) { + addCriterion("`name` >=", value, "name"); + return (Criteria) this; + } + + public Criteria andNameLessThan(String value) { + addCriterion("`name` <", value, "name"); + return (Criteria) this; + } + + public Criteria andNameLessThanOrEqualTo(String value) { + addCriterion("`name` <=", value, "name"); + return (Criteria) this; + } + + public Criteria andNameLike(String value) { + addCriterion("`name` like", value, "name"); + return (Criteria) this; + } + + public Criteria andNameNotLike(String value) { + addCriterion("`name` not like", value, "name"); + return (Criteria) this; + } + + public Criteria andNameIn(List values) { + addCriterion("`name` in", values, "name"); + return (Criteria) this; + } + + public Criteria andNameNotIn(List values) { + addCriterion("`name` not in", values, "name"); + return (Criteria) this; + } + + public Criteria andNameBetween(String value1, String value2) { + addCriterion("`name` between", value1, value2, "name"); + return (Criteria) this; + } + + public Criteria andNameNotBetween(String value1, String value2) { + addCriterion("`name` not between", value1, value2, "name"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNull() { + addCriterion("create_time is null"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNotNull() { + addCriterion("create_time is not null"); + return (Criteria) this; + } + + public Criteria andCreateTimeEqualTo(Date value) { + addCriterion("create_time =", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotEqualTo(Date value) { + addCriterion("create_time <>", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThan(Date value) { + addCriterion("create_time >", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThanOrEqualTo(Date value) { + addCriterion("create_time >=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThan(Date value) { + addCriterion("create_time <", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThanOrEqualTo(Date value) { + addCriterion("create_time <=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeIn(List values) { + addCriterion("create_time in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotIn(List values) { + addCriterion("create_time not in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeBetween(Date value1, Date value2) { + addCriterion("create_time between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotBetween(Date value1, Date value2) { + addCriterion("create_time not between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeIsNull() { + addCriterion("update_time is null"); + return (Criteria) this; + } + + public Criteria andUpdateTimeIsNotNull() { + addCriterion("update_time is not null"); + return (Criteria) this; + } + + public Criteria andUpdateTimeEqualTo(Date value) { + addCriterion("update_time =", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotEqualTo(Date value) { + addCriterion("update_time <>", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeGreaterThan(Date value) { + addCriterion("update_time >", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeGreaterThanOrEqualTo(Date value) { + addCriterion("update_time >=", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeLessThan(Date value) { + addCriterion("update_time <", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeLessThanOrEqualTo(Date value) { + addCriterion("update_time <=", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeIn(List values) { + addCriterion("update_time in", values, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotIn(List values) { + addCriterion("update_time not in", values, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeBetween(Date value1, Date value2) { + addCriterion("update_time between", value1, value2, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotBetween(Date value1, Date value2) { + addCriterion("update_time not between", value1, value2, "updateTime"); + return (Criteria) this; + } + + public Criteria andStateIsNull() { + addCriterion("`state` is null"); + return (Criteria) this; + } + + public Criteria andStateIsNotNull() { + addCriterion("`state` is not null"); + return (Criteria) this; + } + + public Criteria andStateEqualTo(String value) { + addCriterion("`state` =", value, "state"); + return (Criteria) this; + } + + public Criteria andStateNotEqualTo(String value) { + addCriterion("`state` <>", value, "state"); + return (Criteria) this; + } + + public Criteria andStateGreaterThan(String value) { + addCriterion("`state` >", value, "state"); + return (Criteria) this; + } + + public Criteria andStateGreaterThanOrEqualTo(String value) { + addCriterion("`state` >=", value, "state"); + return (Criteria) this; + } + + public Criteria andStateLessThan(String value) { + addCriterion("`state` <", value, "state"); + return (Criteria) this; + } + + public Criteria andStateLessThanOrEqualTo(String value) { + addCriterion("`state` <=", value, "state"); + return (Criteria) this; + } + + public Criteria andStateLike(String value) { + addCriterion("`state` like", value, "state"); + return (Criteria) this; + } + + public Criteria andStateNotLike(String value) { + addCriterion("`state` not like", value, "state"); + return (Criteria) this; + } + + public Criteria andStateIn(List values) { + addCriterion("`state` in", values, "state"); + return (Criteria) this; + } + + public Criteria andStateNotIn(List values) { + addCriterion("`state` not in", values, "state"); + return (Criteria) this; + } + + public Criteria andStateBetween(String value1, String value2) { + addCriterion("`state` between", value1, value2, "state"); + return (Criteria) this; + } + + public Criteria andStateNotBetween(String value1, String value2) { + addCriterion("`state` not between", value1, value2, "state"); + return (Criteria) this; + } + } + + /** + */ + public static class Criteria extends GeneratedCriteria { + + protected Criteria() { + super(); + } + } + + public static class Criterion { + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + public String getCondition() { + return condition; + } + + public Object getValue() { + return value; + } + + public Object getSecondValue() { + return secondValue; + } + + public boolean isNoValue() { + return noValue; + } + + public boolean isSingleValue() { + return singleValue; + } + + public boolean isBetweenValue() { + return betweenValue; + } + + public boolean isListValue() { + return listValue; + } + + public String getTypeHandler() { + return typeHandler; + } + + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + } +} diff --git a/ncc/src/main/java/club/joylink/ncc/services/EcsSystem.java b/ncc/src/main/java/club/joylink/ncc/services/EcsSystem.java new file mode 100644 index 000000000..329343f7b --- /dev/null +++ b/ncc/src/main/java/club/joylink/ncc/services/EcsSystem.java @@ -0,0 +1,9 @@ +package club.joylink.ncc.services; + +import club.joylink.ecs.World; + +public interface EcsSystem { + void addSystem(World world); + Object type(); + +} diff --git a/ncc/src/main/java/club/joylink/ncc/services/MapDataService.java b/ncc/src/main/java/club/joylink/ncc/services/MapDataService.java new file mode 100644 index 000000000..454a2bd8d --- /dev/null +++ b/ncc/src/main/java/club/joylink/ncc/services/MapDataService.java @@ -0,0 +1,13 @@ +package club.joylink.ncc.services; + +import club.joylink.ncc.entity.NccMapData; +import club.joylink.ncc.vo.NccMapDataVO; + +public interface MapDataService { + NccMapDataVO findById(Long id); + + void saveOrUpdate(NccMapDataVO mapDataVO); + + void changeState(Long id, NccMapDataVO.MapDataEnum state); + +} diff --git a/ncc/src/main/java/club/joylink/ncc/services/impl/MapDataServiceImpl.java b/ncc/src/main/java/club/joylink/ncc/services/impl/MapDataServiceImpl.java new file mode 100644 index 000000000..3486db42b --- /dev/null +++ b/ncc/src/main/java/club/joylink/ncc/services/impl/MapDataServiceImpl.java @@ -0,0 +1,65 @@ +package club.joylink.ncc.services.impl; + +import club.joylink.exception.BusinessExceptionAssertEnum; +import club.joylink.ncc.dao.NccMapDataDAO; +import club.joylink.ncc.entity.NccMapData; +import club.joylink.ncc.services.MapDataService; +import club.joylink.ncc.vo.NccMapDataVO; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDateTime; +import java.util.Objects; + +@Service +@Slf4j +@Transactional +public class MapDataServiceImpl implements MapDataService { + + @Autowired + private NccMapDataDAO nccMapDataDAO; + + private NccMapData byId(Long id){ + BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(Objects.nonNull(id),"id信息不能为空"); + NccMapData nccMapData = this.nccMapDataDAO.selectByPrimaryKey(id); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(nccMapData),"未找到对应的数据"); + return nccMapData; + } + @Override + public NccMapDataVO findById(Long id) { + NccMapData mapData = this.byId(id); + return new NccMapDataVO(mapData); + } + + @Override + public void saveOrUpdate(NccMapDataVO mapDataVO) { + BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(Objects.nonNull(mapDataVO.getName()),"名称信息不能为空"); + NccMapData mapData = mapDataVO.convert(); + + LocalDateTime dateTime = LocalDateTime.now(); + if(Objects.nonNull(mapData.getId())){ + mapData = this.byId(mapData.getId()); + + mapData.setMapData(mapData.getMapData()); + mapData.setUpdateTime(dateTime); + this.nccMapDataDAO.updateByPrimaryKey(mapData); + }else{ + mapData.setState(NccMapDataVO.MapDataEnum.EDIT); + mapData.setCreateTime(dateTime); + mapData.setUpdateTime(dateTime); + this.nccMapDataDAO.insert(mapData); + } + } + + @Override + public void changeState(Long id, NccMapDataVO.MapDataEnum state) { + this.byId(id); + NccMapData newData = new NccMapData(); + newData.setId(id); + newData.setUpdateTime(LocalDateTime.now()); + newData.setState(state); + this.nccMapDataDAO.updateByPrimaryKeySelective(newData); + } +} diff --git a/ncc/src/main/java/club/joylink/ncc/vo/NccMapDataVO.java b/ncc/src/main/java/club/joylink/ncc/vo/NccMapDataVO.java new file mode 100644 index 000000000..d7175b4e0 --- /dev/null +++ b/ncc/src/main/java/club/joylink/ncc/vo/NccMapDataVO.java @@ -0,0 +1,35 @@ +package club.joylink.ncc.vo; + +import club.joylink.ncc.entity.NccMapData; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +@Data +public class NccMapDataVO implements Serializable { + @Serial + private static final long serialVersionUID = 5757927953903823727L; + private Long id; + private String name; + private byte[] data; + private MapDataEnum state; + public NccMapDataVO(NccMapData mapData){ + this.id = mapData.getId(); + this.name = mapData.getName(); + this.data = mapData.getMapData(); + this.state = mapData.getState(); + } + + public NccMapData convert(){ + NccMapData mapData = new NccMapData(); + mapData.setMapData(this.data); + mapData.setId(this.id); + mapData.setName(this.name); + mapData.setState(this.getState()); + return mapData; + } + public enum MapDataEnum{ + PUBLISH,EDIT,DELETE; + } +} diff --git a/ncc/src/main/resources/mybatis/mapper/NccMapDataDAO.xml b/ncc/src/main/resources/mybatis/mapper/NccMapDataDAO.xml new file mode 100644 index 000000000..e2aac72b2 --- /dev/null +++ b/ncc/src/main/resources/mybatis/mapper/NccMapDataDAO.xml @@ -0,0 +1,278 @@ + + + + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + id, `name`, create_time, update_time, `state` + + + map_data + + + + + + delete from ncc_map_data + where id = #{id,jdbcType=BIGINT} + + + delete from ncc_map_data + + + + + + insert into ncc_map_data (`name`, create_time, update_time, + `state`, map_data) + values (#{name,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, + #{state,jdbcType=VARCHAR}, #{mapData,jdbcType=LONGVARBINARY}) + + + insert into ncc_map_data + + + `name`, + + + create_time, + + + update_time, + + + `state`, + + + map_data, + + + + + #{name,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + #{state,jdbcType=VARCHAR}, + + + #{mapData,jdbcType=LONGVARBINARY}, + + + + + + update ncc_map_data + + + id = #{record.id,jdbcType=BIGINT}, + + + `name` = #{record.name,jdbcType=VARCHAR}, + + + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + + + update_time = #{record.updateTime,jdbcType=TIMESTAMP}, + + + `state` = #{record.state,jdbcType=VARCHAR}, + + + map_data = #{record.mapData,jdbcType=LONGVARBINARY}, + + + + + + + + update ncc_map_data + set id = #{record.id,jdbcType=BIGINT}, + `name` = #{record.name,jdbcType=VARCHAR}, + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + update_time = #{record.updateTime,jdbcType=TIMESTAMP}, + `state` = #{record.state,jdbcType=VARCHAR}, + map_data = #{record.mapData,jdbcType=LONGVARBINARY} + + + + + + update ncc_map_data + set id = #{record.id,jdbcType=BIGINT}, + `name` = #{record.name,jdbcType=VARCHAR}, + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + update_time = #{record.updateTime,jdbcType=TIMESTAMP}, + `state` = #{record.state,jdbcType=VARCHAR} + + + + + + update ncc_map_data + + + `name` = #{name,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + `state` = #{state,jdbcType=VARCHAR}, + + + map_data = #{mapData,jdbcType=LONGVARBINARY}, + + + where id = #{id,jdbcType=BIGINT} + + + update ncc_map_data + set `name` = #{name,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + update_time = #{updateTime,jdbcType=TIMESTAMP}, + `state` = #{state,jdbcType=VARCHAR}, + map_data = #{mapData,jdbcType=LONGVARBINARY} + where id = #{id,jdbcType=BIGINT} + + + update ncc_map_data + set `name` = #{name,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + update_time = #{updateTime,jdbcType=TIMESTAMP}, + `state` = #{state,jdbcType=VARCHAR} + where id = #{id,jdbcType=BIGINT} + + diff --git a/ncc/src/test/java/club/joylink/ncc/Data.java b/ncc/src/test/java/club/joylink/ncc/Data.java new file mode 100644 index 000000000..911bfe904 --- /dev/null +++ b/ncc/src/test/java/club/joylink/ncc/Data.java @@ -0,0 +1,79 @@ +package club.joylink.ncc; + +import club.joylink.ncc.proto.LineProto; +import club.joylink.ncc.proto.RoadSectionProto; +import club.joylink.ncc.proto.StationProto; +import club.joylink.ncc.proto.StorageProto; +import com.google.common.base.Strings; + +public class Data { + public StorageProto.Storage createStorage(){ + StorageProto.Storage.Builder storageBuild = StorageProto.Storage.newBuilder(); + createLine(storageBuild); + this.createStation(storageBuild); + this.createSection(storageBuild); + return storageBuild.build(); + } + + private void createLine(StorageProto.Storage.Builder storageBuild){ + + for(var i = 1 ; i <=1;i++){ + LineProto.Line.Builder lineBuild = LineProto.Line.newBuilder(); + String code = Strings.padStart(i + "",4,'0'); + lineBuild.setCode("line-" + code); + lineBuild.setName("line-" + code); + storageBuild.addLines(lineBuild); + } + + } + private void createStation(StorageProto.Storage.Builder storageBuild){ + for(var d = 1 ; d <= 20;d++){ + StationProto.Station.Builder stationBuild = StationProto.Station.newBuilder(); + String code = Strings.padStart(d + "",4,'0'); + String nameCode = "station-" + code; + stationBuild.setCode(nameCode); + stationBuild.setName(nameCode); + stationBuild.setTransfer(false); + if(d % 2 == 0){ + stationBuild.setTransfer(true); + } + storageBuild.addStations(stationBuild); + } + } + + + private void createSection(StorageProto.Storage.Builder storageBuild){ + String lineCode = "line-001"; + for(var i = 1 ; i <= 19;i++){ + RoadSectionProto.RoadSection.Builder section = RoadSectionProto.RoadSection.newBuilder(); + String code = Strings.padStart(i + "",4,'0'); + String nameCode = "section-" + code; + section.setCode(nameCode); + section.setName(nameCode); + + section.setLeftStationId(this.findStartStation(i)); + section.setRightStationId(this.findEndStation(i,19)); + section.setLineId(lineCode); + storageBuild.addSections(section); + } + } + private String findStartStation(int d){ + int tmpD = d; + if(d <= 1){ + tmpD = 1; + }/*else{ + --tmpD; + }*/ + String code = Strings.padStart(tmpD + "",4,'0'); + return String.format("station-%s",code); + } + + private String findEndStation(int d ,int max){ + int tmpD = d + 1; + if(d > max){ + tmpD = d; + } + String code = Strings.padStart(tmpD + "",4,'0'); + return String.format("station-%s",code); + } +} diff --git a/ncc/src/test/java/club/joylink/ncc/Service.java b/ncc/src/test/java/club/joylink/ncc/Service.java new file mode 100644 index 000000000..a26896141 --- /dev/null +++ b/ncc/src/test/java/club/joylink/ncc/Service.java @@ -0,0 +1,52 @@ +package club.joylink.ncc; + +import club.joylink.ecs.World; +import club.joylink.ecs.WorldManage; +import club.joylink.ncc.proto.LineProto; +import club.joylink.ncc.proto.RoadSectionProto; +import club.joylink.ncc.proto.StationProto; +import club.joylink.ncc.proto.StorageProto; +import com.google.common.base.Strings; +import com.google.common.collect.Lists; + +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; +import java.util.stream.Collectors; + + +public class Service { + + public static void main(String[] args) { + Service service = new Service(); + StorageProto.Storage storage = service.loadData(); + + } + + public void addTrain(boolean upWay){ + + } + + + private StorageProto.Storage loadData(){ + Data data = new Data(); + StorageProto.Storage storageBuild = data.createStorage(); + Map tmpLineMap = storageBuild.getLinesList().stream().collect(Collectors.toMap(k->k.getCode(), Function.identity())); + lineMap.putAll(tmpLineMap); + Map tmpStationMaper = storageBuild.getStationsList().stream().collect(Collectors.toMap(d->d.getCode(),Function.identity())); + for (RoadSectionProto.RoadSection rs : storageBuild.getSectionsList()) { + List stationList = lineIdStationMap.computeIfAbsent(rs.getLineId(),k-> Lists.newArrayList()); + if(stationList.stream().noneMatch(d-> Objects.equals(d.getCode(),rs.getLeftStationId()))){ + stationList.add(tmpStationMaper.get(rs.getLeftStationId())); + } + if(stationList.stream().noneMatch(d-> Objects.equals(d.getCode(),rs.getRightStationId()))){ + stationList.add(tmpStationMaper.get(rs.getRightStationId())); + } + } + return storageBuild; + } + private static Map lineMap = new ConcurrentHashMap<>(); + private static Map> lineIdStationMap = new ConcurrentHashMap<>(); +}