ncc
This commit is contained in:
parent
eda2131f26
commit
c095ab84c2
|
@ -4,11 +4,18 @@ import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
|||
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.OutputFile;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.DateType;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.Builder;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class MybatisPlusAutoGenerator {
|
||||
|
||||
|
@ -18,8 +25,10 @@ public class MybatisPlusAutoGenerator {
|
|||
;
|
||||
|
||||
public static void main(String[] args) {
|
||||
String baseDir = String.join(File.separator, Arrays.asList(System.getProperty("user.dir"), "jl-rtss-auth", "src", "main"));
|
||||
// String baseDir = System.getProperty("user.dir") + File.separator + "src" + File.separator + "main";
|
||||
GeneratorModule generatorModule = GeneratorModule.SimulationNcc;
|
||||
String[] tableNames = new String[]{"rts_ncc_map_data"};
|
||||
// String baseDir = String.join(File.separator, Arrays.asList(System.getProperty("user.dir"), "jl-rtss-auth", "src", "main"));
|
||||
String baseDir = generatorModule.projectPath;
|
||||
String outBaseDir = baseDir + File.separator + "java";
|
||||
String xmlDir = baseDir + File.separator + "resources" + File.separator + "mapper";
|
||||
System.out.println(outBaseDir);
|
||||
|
@ -31,15 +40,17 @@ public class MybatisPlusAutoGenerator {
|
|||
.outputDir(outBaseDir);
|
||||
})
|
||||
.packageConfig(builder -> {
|
||||
builder.parent("club.joylink.rtss.auth")
|
||||
builder.parent(generatorModule.rootPackAges)
|
||||
.service("repository")
|
||||
.serviceImpl("repository.impl")
|
||||
.pathInfo(Collections.singletonMap(OutputFile.xml, xmlDir));
|
||||
})
|
||||
.strategyConfig(builder -> {
|
||||
builder.addInclude("sys_account", "sys_account_login");
|
||||
|
||||
builder.addInclude(tableNames);
|
||||
// entity生成策略
|
||||
builder.entityBuilder()
|
||||
.enableLombok()
|
||||
.enableFileOverride(); // 覆盖旧文件
|
||||
// mapper生成策略
|
||||
builder.mapperBuilder()
|
||||
|
@ -62,4 +73,24 @@ public class MybatisPlusAutoGenerator {
|
|||
.execute();
|
||||
}
|
||||
|
||||
enum GeneratorModule{
|
||||
Auth("club.joylink.rtss.auth",new String[]{"jl-rtss-auth"})
|
||||
,SimulationNcc("club.joylink.rtss.simulation.ncc",new String[]{"jl-rtss-simulation","ncc"});
|
||||
GeneratorModule(String d,String[] p){
|
||||
this.rootPackAges = d;
|
||||
List<String> projectDir = new ArrayList<>();
|
||||
for (String s : p) {
|
||||
projectDir.add(s);
|
||||
}
|
||||
projectDir.add(0,System.getProperty("user.dir"));
|
||||
projectDir.add("src");
|
||||
projectDir.add("main");
|
||||
this.projectPath = String.join(File.separator, projectDir);
|
||||
|
||||
}
|
||||
private String rootPackAges;
|
||||
private String projectPath;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package club.joylink.rtss.simulation.ncc.controller;
|
||||
|
||||
import club.joylink.rtss.simulation.ncc.dto.NccMapDataDto;
|
||||
import club.joylink.rtss.simulation.ncc.repository.IRtsNccMapDataRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author walker
|
||||
* @since 2023-02-27
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/simulation/v1")
|
||||
public class RtsNccMapDataController {
|
||||
@Autowired
|
||||
private IRtsNccMapDataRepository mapDataService;
|
||||
|
||||
@PostMapping("saveOrUpdate")
|
||||
public void saveOrUpdate(@RequestBody NccMapDataDto dataVO){
|
||||
this.mapDataService.saveOrUpdate(dataVO);
|
||||
}
|
||||
|
||||
@GetMapping()
|
||||
public NccMapDataDto findId(Long id){
|
||||
return this.mapDataService.findById(id);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/change/{state}")
|
||||
public void changeState(@PathVariable("id") Long id, @PathVariable("state") NccMapDataDto.MapDataEnum state){
|
||||
this.mapDataService.changeState(id,state);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package club.joylink.rtss.simulation.ncc.dto;
|
||||
|
||||
import club.joylink.rtss.simulation.ncc.entity.RtsNccMapData;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class NccMapDataDto implements Serializable {
|
||||
private Long id;
|
||||
private String name;
|
||||
private byte[] data;
|
||||
private MapDataEnum state;
|
||||
public NccMapDataDto(RtsNccMapData mapData){
|
||||
this.id = mapData.getId();
|
||||
this.name = mapData.getName();
|
||||
this.data = mapData.getMapData();
|
||||
this.state = mapData.getState();
|
||||
}
|
||||
|
||||
public RtsNccMapData convert(){
|
||||
RtsNccMapData mapData = new RtsNccMapData();
|
||||
mapData.setMapData(this.data);
|
||||
mapData.setId(this.id);
|
||||
mapData.setName(this.name);
|
||||
mapData.setState(this.getState());
|
||||
return mapData;
|
||||
}
|
||||
public enum MapDataEnum{
|
||||
PUBLISH,EDIT,DELETE;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package club.joylink.rtss.simulation.ncc.entity;
|
||||
|
||||
import club.joylink.rtss.simulation.ncc.dto.NccMapDataDto;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author walker
|
||||
* @since 2023-02-27
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("rts_ncc_map_data")
|
||||
public class RtsNccMapData implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private byte[] mapData;
|
||||
|
||||
private LocalDateTime createTime;
|
||||
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 状态0=发布,1=编辑,2=删除
|
||||
*/
|
||||
private NccMapDataDto.MapDataEnum state;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package club.joylink.rtss.simulation.ncc.exception;
|
||||
|
||||
import club.joylink.rtss.auth.exception.ServerExceptionAssert;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
public enum NccExceptionAssertEnum implements ServerExceptionAssert {
|
||||
DataNotExist(4000, "data not exist"),
|
||||
FieldMustUnique(4001, "the unique filed repeat"),
|
||||
RuntimeException(4002,"system runtime exception"),
|
||||
ParamNotEmpty(4003,"param must not empty")
|
||||
;
|
||||
|
||||
NccExceptionAssertEnum(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
int code;
|
||||
|
||||
String message;
|
||||
@Override
|
||||
public int getCode() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package club.joylink.rtss.simulation.ncc.mapper;
|
||||
|
||||
import club.joylink.rtss.simulation.ncc.entity.RtsNccMapData;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author walker
|
||||
* @since 2023-02-27
|
||||
*/
|
||||
@Mapper
|
||||
public interface RtsNccMapDataMapper extends BaseMapper<RtsNccMapData> {
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package club.joylink.rtss.simulation.ncc.repository;
|
||||
|
||||
import club.joylink.rtss.simulation.ncc.dto.NccMapDataDto;
|
||||
import club.joylink.rtss.simulation.ncc.entity.RtsNccMapData;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author walker
|
||||
* @since 2023-02-27
|
||||
*/
|
||||
public interface IRtsNccMapDataRepository extends IService<RtsNccMapData> {
|
||||
void changeState(Long id, NccMapDataDto.MapDataEnum state);
|
||||
void saveOrUpdate(NccMapDataDto mapDataVO);
|
||||
NccMapDataDto findById(Long id);
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package club.joylink.rtss.simulation.ncc.repository.impl;
|
||||
|
||||
import club.joylink.rtss.simulation.ncc.dto.NccMapDataDto;
|
||||
import club.joylink.rtss.simulation.ncc.entity.RtsNccMapData;
|
||||
import club.joylink.rtss.simulation.ncc.exception.NccExceptionAssertEnum;
|
||||
import club.joylink.rtss.simulation.ncc.mapper.RtsNccMapDataMapper;
|
||||
import club.joylink.rtss.simulation.ncc.repository.IRtsNccMapDataRepository;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author walker
|
||||
* @since 2023-02-27
|
||||
*/
|
||||
@Service
|
||||
public class RtsNccMapDataRepository extends ServiceImpl<RtsNccMapDataMapper, RtsNccMapData> implements IRtsNccMapDataRepository {
|
||||
private RtsNccMapData byId(Long id){
|
||||
NccExceptionAssertEnum.ParamNotEmpty.assertTrue(Objects.nonNull(id),"id信息不能为空");
|
||||
RtsNccMapData nccMapData = this.getById(id);
|
||||
NccExceptionAssertEnum.DataNotExist.assertTrue(Objects.nonNull(nccMapData),"未找到对应的数据");
|
||||
return nccMapData;
|
||||
}
|
||||
@Override
|
||||
public void changeState(Long id, NccMapDataDto.MapDataEnum state) {
|
||||
RtsNccMapData newData = this.byId(id);
|
||||
|
||||
newData.setId(id);
|
||||
newData.setUpdateTime(LocalDateTime.now());
|
||||
newData.setState(state);
|
||||
this.getBaseMapper().updateById(newData);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveOrUpdate(NccMapDataDto mapDataVO) {
|
||||
NccExceptionAssertEnum.ParamNotEmpty.assertTrue(Objects.nonNull(mapDataVO.getName()),"名称信息不能为空");
|
||||
RtsNccMapData mapData = mapDataVO.convert();
|
||||
LocalDateTime dateTime = LocalDateTime.now();
|
||||
if(Objects.nonNull(mapData.getId())){
|
||||
mapData = this.byId(mapData.getId());
|
||||
mapData.setMapData(mapData.getMapData());
|
||||
mapData.setUpdateTime(dateTime);
|
||||
}else{
|
||||
mapData.setState(NccMapDataDto.MapDataEnum.EDIT);
|
||||
mapData.setCreateTime(dateTime);
|
||||
mapData.setUpdateTime(dateTime);
|
||||
}
|
||||
this.saveOrUpdate(mapData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NccMapDataDto findById(Long id) {
|
||||
RtsNccMapData mapData = this.byId(id);
|
||||
return new NccMapDataDto(mapData);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue