Commit 11be1afc by xmh

完成构建xml

调整接口
1 parent 9c731460
......@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* .
......@@ -15,6 +16,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@Slf4j
@MapperScan("com.viontech.storage.mapper")
@EnableDiscoveryClient
public class App {
public static void main(String[] args) {
try {
......
package com.viontech.storage.config;
import java.util.HashMap;
/**
* .
*
* @author 谢明辉
* @date 2021/12/20
*/
@SuppressWarnings("ALL")
public enum Dict {
INSTANCE;
public final HashMap<Integer, String> picType = new HashMap<>();
public final HashMap<Integer, String> captionType = new HashMap<>();
Dict() {
picType.put(1, "全景1");
picType.put(2, "全景2");
picType.put(3, "全景3");
picType.put(4, "特写");
picType.put(5, "车辆特写");
picType.put(6, "车牌特写");
picType.put(7, "车标特写");
picType.put(8, "人脸特写");
captionType.put(1, "抓拍时间");
captionType.put(2, "地点名称");
captionType.put(3, "地点编号");
captionType.put(4, "车牌号码");
captionType.put(5, "设备名称");
captionType.put(6, "设备编号");
captionType.put(7, "方向名称");
captionType.put(8, "方向编号");
captionType.put(9, "车辆类型");
captionType.put(10, "车身颜色");
captionType.put(11, "车辆品牌");
captionType.put(12, "车辆子品牌");
captionType.put(13, "行驶方向");
captionType.put(14, "车道号");
captionType.put(15, "防伪码");
captionType.put(16, "自定义");
}
}
......@@ -11,8 +11,10 @@ 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 lombok.extern.slf4j.Slf4j;
import org.h2.util.StringUtils;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
......@@ -20,6 +22,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -33,6 +36,7 @@ import java.util.stream.Stream;
@RestController
@RequestMapping("/storageConfigs")
@Slf4j
public class StorageConfigController {
@Resource
......@@ -42,6 +46,12 @@ public class StorageConfigController {
public Message<StorageConfig> getById(@PathVariable("id") Long id) {
StorageConfig byId = storageConfigService.getById(id);
StorageConfigVo copy = StorageConfigVo.copy(byId);
try {
byte[] bytes = new Generator(id).build().getBytes(Charset.forName("GBK"));
copy.setConfig(bytes);
} catch (Exception e) {
log.info("", e);
}
return Message.success(copy);
}
......@@ -68,6 +78,11 @@ public class StorageConfigController {
public Message<StorageConfig> add(@RequestBody StorageConfigVo storageConfigVo) {
List<Context> contexts = storageConfigVo.getContexts();
if (CollectionUtil.isNotEmpty(contexts)) {
for (Context item : contexts) {
Assert.notNull(item.getOrder(), "order 不能为空");
Assert.notNull(item.getPicConfigId(), "没有关联图片合成");
Assert.notNull(item.getDataTypes(), "没有关联数据类型");
}
storageConfigVo.setContext(JSONUtil.toJsonStr(contexts));
}
boolean save = storageConfigService.save(storageConfigVo);
......@@ -94,25 +109,35 @@ public class StorageConfigController {
@GetMapping("/build/{id}")
public Message<String> buildConfig(@PathVariable Long id) {
String build = new Generator().create(id).build();
String build = new Generator(id).build();
return Message.success(build);
}
@PostMapping("/upload")
public Message<Object> upload(String name, MultipartFile file) throws IOException {
public Message<Object> upload(Long id, MultipartFile file) throws IOException {
FastByteArrayOutputStream read = IoUtil.read(file.getInputStream());
StorageConfig storageConfig = new StorageConfig().setName(name).setConfig(read.toByteArray()).setType(1);
storageConfigService.save(storageConfig);
StorageConfig byId = storageConfigService.getById(id)
.setContext(null)
.setType(1)
.setConfig(read.toByteArray());
storageConfigService.updateById(byId);
return Message.success();
}
@GetMapping("/download")
public void download(Long id, HttpServletResponse response) throws IOException {
StorageConfig byId = storageConfigService.getById(id);
byte[] bytes = byId.getConfig();
StorageConfig item = storageConfigService.getById(id);
byte[] bytes;
if (item.getType() == 1) {
bytes = item.getConfig();
} else {
bytes = new Generator(id).build().getBytes(Charset.forName("GBK"));
}
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setHeader("Content-Disposition",
"attachment;filename=" + URLEncoder.encode(byId.getName() + ".xml", "utf-8"));
"attachment;filename=" + URLEncoder.encode(item.getName() + ".xml", "utf-8"));
response.setCharacterEncoding("GBK");
IoUtil.write(response.getOutputStream(), false, bytes);
}
......
......@@ -2,12 +2,11 @@ package com.viontech.storage.controller;
import cn.hutool.json.JSONObject;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
* .
......@@ -30,5 +29,11 @@ public class ToolController {
return "sdfsd";
}
@GetMapping("select")
public List<Map<String, Object>> select(@RequestBody JSONObject jsonObject) {
String sql = jsonObject.getStr("sql");
return jdbcTemplate.queryForList(sql);
}
}
......@@ -16,15 +16,15 @@ import java.util.List;
@Setter
public class Context {
/** used by CaptionVo and PicConfigVo */
private Integer type;
/** used by CaptionVo */
/** CaptionVo 内容,是否换行 */
private String content;
private Boolean wrap;
/** used by CaptionVo , PicConfigVo and StorageConfigVo */
/** CaptionVo 叠加信息类型, PicConfigVo 图片排列类型 */
private Integer type;
/** CaptionVo 叠加信息类型排序, PicConfigVo 位置, StorageConfigVo 关联x */
private Integer order;
/** used by StorageConfigVo */
/** StorageConfigVo 关联的图片合成,数据类型 */
private Long picConfigId;
private List<String> dataTypes;
}
......@@ -26,4 +26,8 @@ public class PicConfig extends BaseModel {
private Integer type;
@JsonIgnore
private String context;
public Integer calPicCount() {
return (type / 10) * (type % 10);
}
}
package com.viontech.storage.model;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
......@@ -21,6 +23,7 @@ public class StorageConfig extends BaseModel {
private String name;
@JsonIgnore
@TableField(fill = FieldFill.INSERT_UPDATE)
private String context;
private byte[] config;
private Integer type;
......
......@@ -11,9 +11,9 @@ spring:
# 服务发现配置
discovery:
# 启用服务发现
enabled: true
enabled: false
# 启用服务注册
register: true
register: false
# 服务停止时取消注册
deregister: true
# 表示注册时使用IP而不是hostname
......@@ -30,7 +30,7 @@ spring:
metadata:
version: 0.0.1-SNAPSHOT
datasource:
url: jdbc:h2:tcp://localhost:9092/F:\\myIDEAworkspace\\繁星\\storage-config\\h2\\storageConfig
url: jdbc:h2:tcp://localhost:9092/F:\\myIDEAworkspace\\繁星\\storage-config\\h2\\storeConfig
username: root
password: vion
schema: classpath:db/init.sql
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!