Commit e2c74f33 by xmh

初次提交

0 parents
Showing 34 changed files with 1176 additions and 0 deletions
/h2/
.idea/
target
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.viontech</groupId>
<artifactId>storage-config</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
</parent>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.16</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3.4</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file \ No newline at end of file
package com.viontech.storage;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@SpringBootApplication
@Slf4j
@MapperScan("com.viontech.storage.mapper")
public class App {
public static void main(String[] args) {
try {
SpringApplication.run(App.class, args);
} catch (Exception e) {
log.error("app start error", e);
}
}
}
package com.viontech.storage.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Bean
public CorsFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOrigin("*");
config.setAllowCredentials(true);
config.addAllowedMethod("*");
config.addAllowedHeader("*");
config.setMaxAge(3600L);
UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
configSource.registerCorsConfiguration("/**", config);
return new CorsFilter(configSource);
}
}
package com.viontech.storage.controller;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import com.viontech.storage.entity.Context;
import com.viontech.storage.entity.Message;
import com.viontech.storage.model.Caption;
import com.viontech.storage.service.CaptionService;
import com.viontech.storage.vo.CaptionVo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@RequestMapping("captions")
@RestController
public class CaptionController {
@Resource
private CaptionService captionService;
@GetMapping("/{id}")
public Message<Caption> getById(@PathVariable("id") Long id) {
Caption byId = captionService.getById(id);
CaptionVo copy = CaptionVo.copy(byId);
return Message.success(copy);
}
@GetMapping
public Message<List<Caption>> listAll(CaptionVo captionVo) {
List<Caption> list = captionService.list(
captionService.query().ge("caption_set_id", captionVo.getCaptionSetId())
.getWrapper()
);
List<Caption> collect = list.stream().map(CaptionVo::copy).collect(Collectors.toList());
return Message.success(collect);
}
@PostMapping
public Message<Caption> add(@RequestBody CaptionVo item) {
List<Context> texts = item.getContexts();
if (CollectionUtil.isNotEmpty(texts)) {
item.setContext(JSONUtil.toJsonStr(texts));
}
boolean save = captionService.save(item);
return Message.success(item);
}
@PutMapping("/{id}")
public Message<Caption> updateById(@PathVariable Long id, @RequestBody CaptionVo item) {
List<Context> texts = item.getContexts();
if (CollectionUtil.isNotEmpty(texts)) {
item.setContext(JSONUtil.toJsonStr(texts));
}
item.setId(id);
captionService.updateById(item);
return Message.success(item);
}
@DeleteMapping("/{id}")
public Message<Caption> deleteById(@PathVariable Long id) {
boolean b = captionService.removeById(id);
return Message.success();
}
}
package com.viontech.storage.controller;
import com.viontech.storage.entity.Message;
import com.viontech.storage.model.CaptionSet;
import com.viontech.storage.service.CaptionSetService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@RestController
@RequestMapping("/captionSets")
public class CaptionSetController {
@Resource
private CaptionSetService captionSetService;
@GetMapping("/{id}")
public Message<CaptionSet> getById(@PathVariable("id") Long id) {
CaptionSet byId = captionSetService.getById(id);
return Message.success(byId);
}
@GetMapping
public Message<List<CaptionSet>> listAll() {
List<CaptionSet> list = captionSetService.list();
return Message.success(list);
}
@PostMapping
public Message<CaptionSet> add(@RequestBody CaptionSet captionSet) {
boolean save = captionSetService.save(captionSet);
if (save) {
return Message.success(captionSet);
} else {
return Message.error();
}
}
@PutMapping("/{id}")
public Message<CaptionSet> updateById(@PathVariable Long id, @RequestBody CaptionSet captionSet) {
captionSet.setId(id);
boolean b = captionSetService.updateById(captionSet);
return Message.success(captionSet);
}
@DeleteMapping("/{id}")
public Message<CaptionSet> deleteById(@PathVariable Long id) {
boolean b = captionSetService.removeById(id);
return Message.success();
}
}
package com.viontech.storage.controller;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import com.viontech.storage.entity.Context;
import com.viontech.storage.entity.Message;
import com.viontech.storage.model.PicConfig;
import com.viontech.storage.service.PicConfigService;
import com.viontech.storage.vo.PicConfigVo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* .
*
* @author 谢明辉
* @date 2021/11/9
*/
@RestController
@RequestMapping("/picConfigs")
public class PicConfigController {
@Resource
private PicConfigService picConfigService;
@GetMapping("/{id}")
public Message<PicConfig> getById(@PathVariable("id") Long id) {
PicConfig byId = picConfigService.getById(id);
PicConfigVo copy = PicConfigVo.copy(byId);
return Message.success(copy);
}
@GetMapping
public Message<List<PicConfig>> listAll(PicConfigVo captionVo) {
List<PicConfig> list = picConfigService.list();
List<PicConfig> collect = list.stream().map(PicConfigVo::copy).collect(Collectors.toList());
return Message.success(collect);
}
@PostMapping
public Message<PicConfig> add(@RequestBody PicConfigVo item) {
List<Context> contexts = item.getContexts();
if (CollectionUtil.isNotEmpty(contexts)) {
item.setContext(JSONUtil.toJsonStr(contexts));
}
boolean save = picConfigService.save(item);
return Message.success(item);
}
@PutMapping("/{id}")
public Message<PicConfig> updateById(@PathVariable Long id, @RequestBody PicConfigVo item) {
List<Context> contexts = item.getContexts();
if (CollectionUtil.isNotEmpty(contexts)) {
item.setContext(JSONUtil.toJsonStr(contexts));
}
item.setId(id);
picConfigService.updateById(item);
return Message.success(item);
}
@DeleteMapping("/{id}")
public Message<PicConfig> deleteById(@PathVariable Long id) {
boolean b = picConfigService.removeById(id);
return Message.success();
}
}
package com.viontech.storage.controller;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import com.viontech.storage.entity.Context;
import com.viontech.storage.entity.Generator;
import com.viontech.storage.entity.Message;
import com.viontech.storage.model.StorageConfig;
import com.viontech.storage.service.StorageConfigService;
import com.viontech.storage.vo.StorageConfigVo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* .
*
* @author 谢明辉
* @date 2021/11/9
*/
@RestController
@RequestMapping("/storageConfigs")
public class StorageConfigController {
@Resource
private StorageConfigService storageConfigService;
@GetMapping("/{id}")
public Message<StorageConfig> getById(@PathVariable("id") Long id) {
StorageConfig byId = storageConfigService.getById(id);
StorageConfigVo copy = StorageConfigVo.copy(byId);
return Message.success(copy);
}
@GetMapping
public Message<List<StorageConfig>> listAll() {
List<StorageConfig> list = storageConfigService.list();
List<StorageConfig> collect = list.stream().map(StorageConfigVo::copy).collect(Collectors.toList());
return Message.success(collect);
}
@PostMapping
public Message<StorageConfig> add(@RequestBody StorageConfigVo storageConfigVo) {
List<Context> contexts = storageConfigVo.getContexts();
if (CollectionUtil.isNotEmpty(contexts)) {
storageConfigVo.setContext(JSONUtil.toJsonStr(contexts));
}
boolean save = storageConfigService.save(storageConfigVo);
return Message.success(storageConfigVo);
}
@PutMapping("/{id}")
public Message<StorageConfig> updateById(@PathVariable Long id, @RequestBody StorageConfigVo storageConfigVo) {
List<Context> contexts = storageConfigVo.getContexts();
if (CollectionUtil.isNotEmpty(contexts)) {
storageConfigVo.setContext(JSONUtil.toJsonStr(contexts));
}
storageConfigVo.setId(id);
boolean b = storageConfigService.updateById(storageConfigVo);
return Message.success(storageConfigVo);
}
@DeleteMapping("/{id}")
public Message<StorageConfig> deleteById(@PathVariable Long id) {
boolean b = storageConfigService.removeById(id);
return Message.success();
}
@GetMapping("/build/{id}")
public Message<String> buildConfig(@PathVariable Long id) {
String build = new Generator().create(id).build();
return Message.success(build);
}
}
package com.viontech.storage.entity;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2021/11/9
*/
@Getter
@Setter
public class Context {
/** used by CaptionVo and PicConfigVo */
private Integer type;
/** used by CaptionVo */
private String content;
/** used by CaptionVo , PicConfigVo and StorageConfigVo */
private Integer order;
/** used by StorageConfigVo */
private Long picConfigId;
private List<String> dataTypes;
}
package com.viontech.storage.entity;
import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import cn.hutool.core.util.XmlUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.viontech.storage.model.Caption;
import com.viontech.storage.model.PicConfig;
import com.viontech.storage.model.StorageConfig;
import com.viontech.storage.service.CaptionService;
import com.viontech.storage.service.PicConfigService;
import com.viontech.storage.service.StorageConfigService;
import com.viontech.storage.vo.CaptionVo;
import com.viontech.storage.vo.PicConfigVo;
import com.viontech.storage.vo.StorageConfigVo;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* .
*
* @author 谢明辉
* @date 2021/11/9
*/
public class Generator {
private static final String ROOT_ELEMENT_NAME = "StorageConfig";
private static final String FILE_VERSION = "001-012-000-000";
private static final TimedCache<Long, String> STORAGE_CONFIG_ID_RESULT_CACHE = CacheUtil.newTimedCache(20 * 1000);
private StorageConfigVo storageConfigVo;
/** key: picConfigVoId */
private Map<Long, PicConfigVo> picConfigVoMap;
/** key: captionSetId */
private Map<Long, List<CaptionVo>> captionMap;
public Generator create(Long storageConfigId) {
StorageConfigService storageConfigService = SpringUtil.getBean(StorageConfigService.class);
PicConfigService picConfigService = SpringUtil.getBean(PicConfigService.class);
CaptionService captionService = SpringUtil.getBean(CaptionService.class);
StorageConfig storageConfig0 = storageConfigService.getById(storageConfigId);
this.storageConfigVo = StorageConfigVo.copy(storageConfig0);
List<Long> picConfigIds = storageConfigVo.getContexts().stream().map(Context::getPicConfigId).collect(Collectors.toList());
List<PicConfig> picConfigs = picConfigService.listByIds(picConfigIds);
this.picConfigVoMap = new HashMap<>(picConfigs.size());
ArrayList<Long> captionSetIds = new ArrayList<>();
for (PicConfig item : picConfigs) {
PicConfigVo copy = PicConfigVo.copy(item);
picConfigVoMap.put(copy.getId(), copy);
captionSetIds.add(copy.getCaptionSetId());
}
List<Caption> captions = captionService.list(
captionService.query().in("caption_set_id", captionSetIds)
);
this.captionMap = captions.stream().map(CaptionVo::copy).collect(Collectors.groupingBy(CaptionVo::getCaptionSetId, Collectors.toList()));
return this;
}
public String build() {
Document root = XmlUtil.createXml("StorageConfig");
Element fileVersion = root.createElement("FileVersion");
fileVersion.setTextContent(FILE_VERSION);
Element standard = root.createElement("Standard");
return XmlUtil.toStr(root, "GBK", false);
}
}
package com.viontech.storage.entity;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@Getter
@Setter
@Accessors(chain = true)
public class Message<T> {
private String msg;
private boolean success;
private Integer code;
private T data;
public static <T> Message<T> success(String msg, T data) {
return new Message<T>().setMsg(msg).setCode(200).setSuccess(true).setData(data);
}
public static <T> Message<T> success(T data) {
return new Message<T>().setMsg("成功").setCode(200).setSuccess(true).setData(data);
}
public static <T> Message<T> success() {
return new Message<T>().setMsg("成功").setCode(200).setSuccess(true).setData(null);
}
public static <T> Message<T> error(String msg, T data) {
return new Message<T>().setMsg(msg).setCode(500).setData(data);
}
public static <T> Message<T> error(T data) {
return new Message<T>().setMsg("失败").setCode(500).setData(data);
}
public static <T> Message<T> error() {
return new Message<T>().setMsg("失败").setCode(500).setData(null);
}
}
package com.viontech.storage.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.viontech.storage.model.Caption;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
public interface CaptionMapper extends BaseMapper<Caption> {
}
package com.viontech.storage.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.viontech.storage.model.CaptionSet;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
public interface CaptionSetMapper extends BaseMapper<CaptionSet> {
}
package com.viontech.storage.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.viontech.storage.model.PicConfig;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
public interface PicConfigMapper extends BaseMapper<PicConfig> {
}
package com.viontech.storage.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.viontech.storage.model.StorageConfig;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
public interface StorageConfigMapper extends BaseMapper<StorageConfig> {
}
package com.viontech.storage.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@Getter
@Setter
public class BaseModel {
@TableId(type = IdType.AUTO)
private Long id;
private String unid;
private Date createTime;
}
package com.viontech.storage.model;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@Getter
@Setter
@Accessors(chain = true)
@TableName("CAPTION")
public class Caption extends BaseModel {
private Long captionSetId;
private Boolean enabled;
private Integer picType;
private Integer bgColor;
private Integer bgTransparency;
private Integer font;
private Integer fontSize;
private Integer fgColor;
private String dateFormat;
@JsonIgnore
private String context;
}
package com.viontech.storage.model;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@Getter
@Setter
@Accessors(chain = true)
@TableName("CAPTION_SET")
public class CaptionSet extends BaseModel{
private String name;
private String intro;
}
package com.viontech.storage.model;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@Getter
@Setter
@Accessors(chain = true)
@TableName("PIC_CONFIG")
public class PicConfig extends BaseModel {
private String name;
private Boolean enabled;
private Long captionSetId;
private Integer pictureQuality;
private Integer type;
@JsonIgnore
private String context;
}
package com.viontech.storage.model;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@Getter
@Setter
@Accessors(chain = true)
@TableName("STORAGE_CONFIG")
public class StorageConfig extends BaseModel {
private String name;
@JsonIgnore
private String context;
}
package com.viontech.storage.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.viontech.storage.mapper.CaptionMapper;
import com.viontech.storage.model.Caption;
import org.springframework.stereotype.Service;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@Service
public class CaptionService extends ServiceImpl<CaptionMapper, Caption> implements IService<Caption> {
}
package com.viontech.storage.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.viontech.storage.mapper.CaptionSetMapper;
import com.viontech.storage.model.CaptionSet;
import org.springframework.stereotype.Service;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@Service
public class CaptionSetService extends ServiceImpl<CaptionSetMapper, CaptionSet> implements IService<CaptionSet> {
}
package com.viontech.storage.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.viontech.storage.mapper.PicConfigMapper;
import com.viontech.storage.model.PicConfig;
import org.springframework.stereotype.Service;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@Service
public class PicConfigService extends ServiceImpl<PicConfigMapper,PicConfig> implements IService<PicConfig> {
}
package com.viontech.storage.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.viontech.storage.mapper.StorageConfigMapper;
import com.viontech.storage.model.StorageConfig;
import org.springframework.stereotype.Service;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@Service
public class StorageConfigService extends ServiceImpl<StorageConfigMapper, StorageConfig> implements IService<StorageConfig> {
}
package com.viontech.storage.vo;
import com.viontech.storage.model.CaptionSet;
import lombok.Getter;
import lombok.Setter;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@Getter
@Setter
public class CaptionSetVo extends CaptionSet {
}
package com.viontech.storage.vo;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.viontech.storage.entity.Context;
import com.viontech.storage.model.Caption;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@Getter
@Setter
public class CaptionVo extends Caption {
private List<Context> contexts;
public static CaptionVo copy(Caption caption) {
if (caption == null) {
return null;
}
CaptionVo captionVo = new CaptionVo();
BeanUtil.copyProperties(caption, captionVo, true);
if (captionVo.getContext() != null) {
captionVo.setContexts(JSONUtil.toList(captionVo.getContext(), Context.class));
}
return captionVo;
}
}
package com.viontech.storage.vo;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.viontech.storage.entity.Context;
import com.viontech.storage.model.Caption;
import com.viontech.storage.model.PicConfig;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@Getter
@Setter
public class PicConfigVo extends PicConfig{
List<Context> contexts;
public static PicConfigVo copy(PicConfig picConfig) {
if (picConfig == null) {
return null;
}
PicConfigVo picConfigVo = new PicConfigVo();
BeanUtil.copyProperties(picConfig, picConfigVo, true);
if (picConfigVo.getContext() != null) {
picConfigVo.setContexts(JSONUtil.toList(picConfigVo.getContext(), Context.class));
}
return picConfigVo;
}
}
package com.viontech.storage.vo;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.viontech.storage.entity.Context;
import com.viontech.storage.model.StorageConfig;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@Getter
@Setter
public class StorageConfigVo extends StorageConfig {
private List<Context> contexts;
public static StorageConfigVo copy(StorageConfig storageConfig) {
if (storageConfig == null) {
return null;
}
StorageConfigVo storageConfigVo = new StorageConfigVo();
BeanUtil.copyProperties(storageConfig, storageConfigVo, true);
if (storageConfigVo.getContext() != null) {
storageConfigVo.setContexts(JSONUtil.toList(storageConfigVo.getContext(), Context.class));
}
return storageConfigVo;
}
}
#spring.datasource.url=jdbc:h2:file:./h2/storageConfig
spring.datasource.url=jdbc:h2:tcp://localhost:9092/F:\\myIDEAworkspace\\\u7E41\u661F\\storage-config\\h2\\storageConfig
spring.datasource.username=root
spring.datasource.password=vion
spring.datasource.schema=classpath:db/init.sql
spring.h2.console.enabled=true
spring.h2.console.settings.web-allow-others=true
\ No newline at end of file \ No newline at end of file
spring.datasource.url=jdbc:h2:tcp://localhost:9092/F:\\myIDEAworkspace\\\u7E41\u661F\\storage-config\\h2\\storageConfig
spring.datasource.username=root
spring.datasource.password=vion
\ No newline at end of file \ No newline at end of file
spring:
profiles:
active: dev
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
default-property-inclusion: non_null
\ No newline at end of file \ No newline at end of file
-- 字幕集表
create table if not exists caption_set
(
id int8 not null primary key AUTO_INCREMENT,
unid varchar(36) not null default RANDOM_UUID(),
name varchar(128) not null,
intro text,
create_time timestamp not null default current_timestamp
);
comment on table caption_set is '字幕集表,每行数据对应多个字幕数据';
comment on column caption_set.name is '名称';
comment on column caption_set.intro is '描述';
comment on column caption_set.create_time is '创建时间';
create index if not exists caption_set_unid_idx on caption_set (unid);
-- 字幕表
create table if not exists caption
(
id int8 not null primary key AUTO_INCREMENT,
unid varchar(36) not null default RANDOM_UUID(),
caption_set_id int8 not null,
enabled boolean not null default true,
pic_type int4,
bg_color int4,
bg_transparency int4 not null default 100,
font int4,
font_size int4,
fg_color int4,
date_format varchar(48),
context text,
create_time timestamp not null default current_timestamp,
foreign key (caption_set_id) references caption_set (id) on delete cascade on update no action
);
comment on table caption is '字幕表';
comment on column caption.caption_set_id is '字幕集ID';
comment on column caption.enabled is '是否启用文字叠加';
comment on column caption.pic_type is '图片类型:全景图,车辆特写,人脸特写等';
comment on column caption.bg_color is '背景颜色';
comment on column caption.bg_transparency is '背景颜色透明度';
comment on column caption.font is '字体';
comment on column caption.font_size is '字体大小';
comment on column caption.fg_color is '字体颜色';
comment on column caption.date_format is '日期格式';
comment on column caption.context is '叠加信息(JSON)';
create index if not exists caption_caption_set_id_idx on caption (caption_set_id);
create index if not exists caption_unid_idx on caption (unid);
-- 图片合成配置表
create table if not exists pic_config
(
id int8 not null primary key AUTO_INCREMENT,
unid varchar(36) not null default RANDOM_UUID(),
name varchar(128) not null,
enabled boolean not null default true,
caption_set_id int8,
picture_quality int4,
type int4,
context text,
create_time timestamp not null default current_timestamp,
foreign key (caption_set_id) references caption_set (id) on delete set null on update no action
);
comment on table pic_config is '图片合成配置表';
comment on column pic_config.name is '名称';
comment on column pic_config.enabled is '是否启用图片合成';
comment on column pic_config.caption_set_id is '对应字幕集';
comment on column pic_config.picture_quality is '图片质量,KB';
comment on column pic_config.type is '图片排列类型';
comment on column pic_config.context is '排列方式(JSON)';
comment on column pic_config.create_time is '创建时间';
create index if not exists pic_config_caption_set_id_idx on pic_config (caption_set_id);
create index if not exists pic_config_unid_idx on pic_config (unid);
-- 存储方案表
create table if not exists storage_config
(
id int8 not null primary key AUTO_INCREMENT,
unid varchar(36) not null default RANDOM_UUID(),
name varchar(128) not null,
context text,
create_time timestamp not null default current_timestamp
);
comment on table storage_config is '存储方案表';
comment on column storage_config.name is '名称';
comment on column storage_config.context is '排列方式(JSON)';
comment on column storage_config.create_time is '创建时间';
create index if not exists storage_config_unid_idx on storage_config (unid);
\ No newline at end of file \ No newline at end of file
package com.viontech.storage.mapper;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.viontech.storage.mapper.CaptionSetMapper;
import com.viontech.storage.model.CaptionSet;
import com.viontech.storage.service.CaptionService;
import com.viontech.storage.service.CaptionSetService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles("test")
public class CaptionSetTest {
@Resource
private CaptionSetService captionSetService;
@Test
public void insetCaptionSet() {
CaptionSet captionSet = new CaptionSet();
captionSet.setName("name");
captionSet.setIntro("intro");
boolean save = captionSetService.save(captionSet);
System.out.println(JSONUtil.toJsonStr(captionSet));
}
@Test
public void selectCaptionSet() {
List<CaptionSet> captionSets = captionSetService.list();
captionSets.forEach(x -> System.out.println(JSONUtil.toJsonStr(x)));
}
}
package com.viontech.storage.mapper;
import cn.hutool.json.JSONConfig;
import cn.hutool.json.JSONUtil;
import com.viontech.storage.model.Caption;
import com.viontech.storage.model.CaptionSet;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles("test")
public class CaptionTest {
@Resource
private CaptionMapper captionMapper;
@Test
public void insetCaptionSet() {
Caption caption = new Caption()
.setCaptionSetId(1L)
.setEnabled(true)
.setBgColor(1)
.setBgTransparency(1)
.setDateFormat("yyyy-MM-dd HH:mm:ss:xxx")
.setFont(1)
.setFontSize(10)
.setPicType(1)
.setFgColor(1)
.setContext("testContext");
int insert = captionMapper.insert(caption);
System.out.println(insert);
}
@Test
public void captionTest() {
List<Caption> captions = captionMapper.selectList(null);
captions.forEach(x -> System.out.println(JSONUtil.toJsonStr(x, JSONConfig.create().setDateFormat("yyyy-MM-dd HH:mm:ss"))));
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!