Commit 11be1afc by xmh

完成构建xml

调整接口
1 parent 9c731460
...@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/** /**
* . * .
...@@ -15,6 +16,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; ...@@ -15,6 +16,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
@Slf4j @Slf4j
@MapperScan("com.viontech.storage.mapper") @MapperScan("com.viontech.storage.mapper")
@EnableDiscoveryClient
public class App { public class App {
public static void main(String[] args) { public static void main(String[] args) {
try { 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; ...@@ -11,8 +11,10 @@ import com.viontech.storage.entity.Message;
import com.viontech.storage.model.StorageConfig; import com.viontech.storage.model.StorageConfig;
import com.viontech.storage.service.StorageConfigService; import com.viontech.storage.service.StorageConfigService;
import com.viontech.storage.vo.StorageConfigVo; import com.viontech.storage.vo.StorageConfigVo;
import lombok.extern.slf4j.Slf4j;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -20,6 +22,7 @@ import javax.annotation.Resource; ...@@ -20,6 +22,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
...@@ -33,6 +36,7 @@ import java.util.stream.Stream; ...@@ -33,6 +36,7 @@ import java.util.stream.Stream;
@RestController @RestController
@RequestMapping("/storageConfigs") @RequestMapping("/storageConfigs")
@Slf4j
public class StorageConfigController { public class StorageConfigController {
@Resource @Resource
...@@ -42,6 +46,12 @@ public class StorageConfigController { ...@@ -42,6 +46,12 @@ public class StorageConfigController {
public Message<StorageConfig> getById(@PathVariable("id") Long id) { public Message<StorageConfig> getById(@PathVariable("id") Long id) {
StorageConfig byId = storageConfigService.getById(id); StorageConfig byId = storageConfigService.getById(id);
StorageConfigVo copy = StorageConfigVo.copy(byId); 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); return Message.success(copy);
} }
...@@ -68,6 +78,11 @@ public class StorageConfigController { ...@@ -68,6 +78,11 @@ public class StorageConfigController {
public Message<StorageConfig> add(@RequestBody StorageConfigVo storageConfigVo) { public Message<StorageConfig> add(@RequestBody StorageConfigVo storageConfigVo) {
List<Context> contexts = storageConfigVo.getContexts(); List<Context> contexts = storageConfigVo.getContexts();
if (CollectionUtil.isNotEmpty(contexts)) { 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)); storageConfigVo.setContext(JSONUtil.toJsonStr(contexts));
} }
boolean save = storageConfigService.save(storageConfigVo); boolean save = storageConfigService.save(storageConfigVo);
...@@ -94,25 +109,35 @@ public class StorageConfigController { ...@@ -94,25 +109,35 @@ public class StorageConfigController {
@GetMapping("/build/{id}") @GetMapping("/build/{id}")
public Message<String> buildConfig(@PathVariable Long 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); return Message.success(build);
} }
@PostMapping("/upload") @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()); FastByteArrayOutputStream read = IoUtil.read(file.getInputStream());
StorageConfig storageConfig = new StorageConfig().setName(name).setConfig(read.toByteArray()).setType(1); StorageConfig byId = storageConfigService.getById(id)
storageConfigService.save(storageConfig); .setContext(null)
.setType(1)
.setConfig(read.toByteArray());
storageConfigService.updateById(byId);
return Message.success(); return Message.success();
} }
@GetMapping("/download") @GetMapping("/download")
public void download(Long id, HttpServletResponse response) throws IOException { public void download(Long id, HttpServletResponse response) throws IOException {
StorageConfig byId = storageConfigService.getById(id); StorageConfig item = storageConfigService.getById(id);
byte[] bytes = byId.getConfig(); 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.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setHeader("Content-Disposition", 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"); response.setCharacterEncoding("GBK");
IoUtil.write(response.getOutputStream(), false, bytes); IoUtil.write(response.getOutputStream(), false, bytes);
} }
......
...@@ -2,12 +2,11 @@ package com.viontech.storage.controller; ...@@ -2,12 +2,11 @@ package com.viontech.storage.controller;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/** /**
* . * .
...@@ -30,5 +29,11 @@ public class ToolController { ...@@ -30,5 +29,11 @@ public class ToolController {
return "sdfsd"; 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; ...@@ -16,15 +16,15 @@ import java.util.List;
@Setter @Setter
public class Context { public class Context {
/** used by CaptionVo and PicConfigVo */ /** CaptionVo 内容,是否换行 */
private Integer type;
/** used by CaptionVo */
private String content; private String content;
private Boolean wrap; private Boolean wrap;
/** used by CaptionVo , PicConfigVo and StorageConfigVo */ /** CaptionVo 叠加信息类型, PicConfigVo 图片排列类型 */
private Integer type;
/** CaptionVo 叠加信息类型排序, PicConfigVo 位置, StorageConfigVo 关联x */
private Integer order; private Integer order;
/** used by StorageConfigVo */ /** StorageConfigVo 关联的图片合成,数据类型 */
private Long picConfigId; private Long picConfigId;
private List<String> dataTypes; private List<String> dataTypes;
} }
...@@ -2,8 +2,11 @@ package com.viontech.storage.entity; ...@@ -2,8 +2,11 @@ package com.viontech.storage.entity;
import cn.hutool.cache.CacheUtil; import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache; import cn.hutool.cache.impl.TimedCache;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Pair;
import cn.hutool.core.util.XmlUtil; import cn.hutool.core.util.XmlUtil;
import cn.hutool.extra.spring.SpringUtil; import cn.hutool.extra.spring.SpringUtil;
import com.viontech.storage.config.Dict;
import com.viontech.storage.model.Caption; import com.viontech.storage.model.Caption;
import com.viontech.storage.model.PicConfig; import com.viontech.storage.model.PicConfig;
import com.viontech.storage.model.StorageConfig; import com.viontech.storage.model.StorageConfig;
...@@ -13,14 +16,14 @@ import com.viontech.storage.service.StorageConfigService; ...@@ -13,14 +16,14 @@ import com.viontech.storage.service.StorageConfigService;
import com.viontech.storage.vo.CaptionVo; import com.viontech.storage.vo.CaptionVo;
import com.viontech.storage.vo.PicConfigVo; import com.viontech.storage.vo.PicConfigVo;
import com.viontech.storage.vo.StorageConfigVo; import com.viontech.storage.vo.StorageConfigVo;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node;
import java.nio.charset.Charset; import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -36,47 +39,309 @@ public class Generator { ...@@ -36,47 +39,309 @@ public class Generator {
private static final String FILE_VERSION = "001-012-000-000"; 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 static final TimedCache<Long, String> STORAGE_CONFIG_ID_RESULT_CACHE = CacheUtil.newTimedCache(20 * 1000);
private StorageConfigVo storageConfigVo; private final Document document = XmlUtil.createXml("StorageConfig");
private final List<Context> contexts;
/** key: picConfigVoId */ /** key: picConfigVoId */
private Map<Long, PicConfigVo> picConfigVoMap; private final Map<Long, PicConfigVo> picConfigMap;
/** key: captionSetId */ /** key: captionSetId */
private Map<Long, List<CaptionVo>> captionMap; private final Map<Long, List<CaptionVo>> captionSetMap;
public Generator create(Long storageConfigId) { public Generator(Long storageConfigId) {
StorageConfigService storageConfigService = SpringUtil.getBean(StorageConfigService.class); StorageConfigService storageConfigService = SpringUtil.getBean(StorageConfigService.class);
PicConfigService picConfigService = SpringUtil.getBean(PicConfigService.class); PicConfigService picConfigService = SpringUtil.getBean(PicConfigService.class);
CaptionService captionService = SpringUtil.getBean(CaptionService.class); CaptionService captionService = SpringUtil.getBean(CaptionService.class);
StorageConfig storageConfig0 = storageConfigService.getById(storageConfigId); StorageConfig storageConfig0 = storageConfigService.getById(storageConfigId);
this.storageConfigVo = StorageConfigVo.copy(storageConfig0); this.contexts = StorageConfigVo.copy(storageConfig0).getContexts();
List<Long> picConfigIds = storageConfigVo.getContexts().stream().map(Context::getPicConfigId).collect(Collectors.toList()); if (contexts == null || contexts.size() == 0) {
throw new RuntimeException("无法构建改配置");
}
List<Long> picConfigIds = contexts.stream().map(Context::getPicConfigId).collect(Collectors.toList());
List<PicConfig> picConfigs = picConfigService.listByIds(picConfigIds); List<PicConfig> picConfigs = picConfigService.listByIds(picConfigIds);
this.picConfigVoMap = new HashMap<>(picConfigs.size()); this.picConfigMap = new HashMap<>(picConfigs.size());
ArrayList<Long> captionSetIds = new ArrayList<>(); ArrayList<Long> captionSetIds = new ArrayList<>();
for (PicConfig item : picConfigs) { for (PicConfig item : picConfigs) {
PicConfigVo copy = PicConfigVo.copy(item); PicConfigVo copy = PicConfigVo.copy(item);
picConfigVoMap.put(copy.getId(), copy); picConfigMap.put(copy.getId(), copy);
captionSetIds.add(copy.getCaptionSetId()); captionSetIds.add(copy.getCaptionSetId());
} }
List<Caption> captions = captionService.list( List<Caption> captions = captionService.list(
captionService.query().in("caption_set_id", captionSetIds) captionService.query().in("caption_set_id", captionSetIds).getWrapper()
); );
this.captionMap = captions.stream().map(CaptionVo::copy).collect(Collectors.groupingBy(CaptionVo::getCaptionSetId, Collectors.toList())); this.captionSetMap = captions.stream().map(CaptionVo::copy).collect(Collectors.groupingBy(CaptionVo::getCaptionSetId, Collectors.toList()));
return this;
} }
public String build() { public String build() {
Document root = XmlUtil.createXml("StorageConfig"); Node rootNode = document.getFirstChild();
Element fileVersion = root.createElement("FileVersion"); rootNode.appendChild(createTextNode("FileVersion", FILE_VERSION));
fileVersion.setTextContent(FILE_VERSION); Element standard = document.createElement("Standard");
Element standard = root.createElement("Standard"); rootNode.appendChild(standard);
standard.appendChild(createTextNode("SolutionNum", String.valueOf(contexts.size())));
Element switchPathConfig = document.createElement("SwitchPathConfig");
switchPathConfig.appendChild(createTextNode("Flag", "1"));
switchPathConfig.appendChild(createTextNode("RootPaths", "/VionData/RecordData/viondata0;/VionData/RecordData/viondata1;/VionData/RecordData/viondata2;/VionData/RecordData/viondata3;"));
switchPathConfig.appendChild(createTextNode("VolumeThreshold", "2048"));
switchPathConfig.appendChild(createTextNode("CountThreshold", "64"));
standard.appendChild(switchPathConfig);
for (Context context : contexts) {
Node solution = buildSolution(context);
if (solution != null) {
standard.appendChild(solution);
}
}
return XmlUtil.toStr(document, "GBK", false);
}
private Node buildSolution(Context context) {
String conditions = combineConditions(context.getDataTypes());
Integer order = context.getOrder();
Long picConfigId = context.getPicConfigId();
PicConfigVo picConfig = picConfigMap.get(picConfigId);
if (picConfig == null || !picConfig.getEnabled()) {
return null;
}
Element solution = document.createElement("Solution" + order);
solution.appendChild(createTextNode("SolutionName", picConfig.getName()));
solution.appendChild(createTextNode("Conditions", conditions));
Element iniInfo = document.createElement("IniInfo");
iniInfo.appendChild(createTextNode("infContent", "(开始时间:YYYY-MM-DD HH:mm:SS_xxx)+(换行分隔符)+EndTime=+(结束时间:YYYY-MM-DD HH:mm:SS xxx)+(换行分隔符)+"));
solution.appendChild(iniInfo);
Element pathConfig = document.createElement("PathConfig");
pathConfig.appendChild(createTextNode("PicRelativePath", "/+(设备编号)+/+(开始时间:YYYYMM/DD/HH)+/+(开始时间:YYYYMMDDHHmmSSxxx)+_+(车牌号码)+_+车道+(车道号)+.jpg;/+(设备编号)+/+(开始时间:YYYYMM/DD/HH)+/+(开始时间:YYYYMMDDHHmmSSxxx)+_+(车牌号码)+_+车道+(车道号)+_2+.jpg;/+(设备编号)+/+(开始时间:YYYYMM/DD/HH)+/+(开始时间:YYYYMMDDHHmmSSxxx)+_+(车牌号码)+_+车道+(车道号)+_3+.jpg;/+(设备编号)+/+(开始时间:YYYYMM/DD/HH)+/+(开始时间:YYYYMMDDHHmmSSxxx)+_+(车牌号码)+_+车道+(车道号)+_4+.jpg;/+(设备编号)+/+(开始时间:YYYYMM/DD/HH)+/+(开始时间:YYYYMMDDHHmmSSxxx)+_+(车牌号码)+_+车道+(车道号)+_5+.jpg;;"));
pathConfig.appendChild(createTextNode("PicRootPath", "/kk/shuju;;;;;"));
pathConfig.appendChild(createTextNode("INIRelativePath", "/+(设备编号)+/+(开始时间:YYYYMM/DD/HH)+/+(开始时间:YYYYMMDDHHmmSSxxx)+_+(车牌号码)+_+车道+(车道号)+.ini"));
pathConfig.appendChild(createTextNode("INIRootPath", "/kk/ini;;;;;"));
pathConfig.appendChild(document.createTextNode("VideoRelativePath"));
pathConfig.appendChild(createTextNode("VideoRootPath", "/kk/video;;;;;"));
solution.appendChild(pathConfig);
Node picConfigNode = buildPicConfig(picConfig);
solution.appendChild(picConfigNode);
return solution;
}
private Node buildPicConfig(PicConfigVo picConfig) {
Element configNode = document.createElement("PicConfig");
configNode.appendChild(createTextNode("PicCount", "1"));
configNode.appendChild(createTextNode("DigPicFlag", "1"));
configNode.appendChild(createTextNode("scImagePrptyCnt", "-858993460"));
configNode.appendChild(createTextNode("CoverCapFlag", "0"));
configNode.appendChild(createTextNode("ImageQualityGlobalFlag", "0"));
Element gamm = XmlUtil.appendChild(configNode, "Gamm");
Element denoiser = XmlUtil.appendChild(configNode, "Denoiser");
Element picQuality = XmlUtil.appendChild(configNode, "PicQuality");
gamm.appendChild(createTextNode("GammFlag", "0"));
gamm.appendChild(createTextNode("GammValue", "0.600000"));
denoiser.appendChild(createTextNode("EnableFlag", "0"));
denoiser.appendChild(createTextNode("Type", "3"));
denoiser.appendChild(createTextNode("Param1", "3"));
denoiser.appendChild(createTextNode("Param2", "3"));
denoiser.appendChild(createTextNode("Param3", "0.000000"));
denoiser.appendChild(createTextNode("Param4", "0.000000"));
Element fixedSizeQuality = XmlUtil.appendChild(picQuality, "FixedSizeQuality");
Element st200wImageQuality = XmlUtil.appendChild(picQuality, "st200WImageQuality");
Element st500wImageQuality = XmlUtil.appendChild(picQuality, "st500WImageQuality");
fixedSizeQuality.appendChild(createTextNode("DayQuality", "500"));
fixedSizeQuality.appendChild(createTextNode("NightQuality", "500"));
st200wImageQuality.appendChild(createTextNode("DayQuality", "80"));
st200wImageQuality.appendChild(createTextNode("NightQuality", "80"));
st500wImageQuality.appendChild(createTextNode("DayQuality", "60"));
st500wImageQuality.appendChild(createTextNode("NightQuality", "60"));
picQuality.appendChild(createTextNode("LightThreshold", "40"));
picQuality.appendChild(createTextNode("UseFixedSize", "0"));
Element pic1 = XmlUtil.appendChild(configNode, "Pic1");
pic1.appendChild(createTextNode("OriPicCount", String.valueOf(picConfig.calPicCount())));
pic1.appendChild(createTextNode("DirectSaveFlag", "0"));
PicConfigCalculator calculator = new PicConfigCalculator(picConfig);
Coordinate[] coordinates = calculator.coordinates;
HashMap<Integer, Coordinate> coordinateMap = calculator.coordinateMap;
for (int i = 0; i < coordinates.length; i++) {
Coordinate item = coordinates[i];
Element oriPic = XmlUtil.appendChild(pic1, "OriPic" + (i + 1));
XmlUtil.appendChild(oriPic, "Content").setTextContent(item.getName());
XmlUtil.appendChild(oriPic, "Type").setTextContent("0");
Element srcCoordinate = XmlUtil.appendChild(oriPic, "SrcCoordinate");
Element desCoordinate = XmlUtil.appendChild(oriPic, "DesCoordinate");
XmlUtil.appendChild(srcCoordinate, "left").setTextContent("0");
XmlUtil.appendChild(srcCoordinate, "top").setTextContent("0");
XmlUtil.appendChild(srcCoordinate, "width").setTextContent(item.getName() + "宽");
XmlUtil.appendChild(srcCoordinate, "height").setTextContent(item.getName() + "高");
XmlUtil.appendChild(desCoordinate, "left").setTextContent(item.getX());
XmlUtil.appendChild(desCoordinate, "top").setTextContent(item.getY());
XmlUtil.appendChild(desCoordinate, "width").setTextContent("全景1宽");
XmlUtil.appendChild(desCoordinate, "height").setTextContent("全景1高");
}
// 字幕
Long captionSetId = picConfig.getCaptionSetId();
List<CaptionVo> captionVos = captionSetMap.get(captionSetId);
Element captionsElement = XmlUtil.appendChild(pic1, "Captions");
int captionCount = 0;
for (int i = 0; i < captionVos.size(); i++) {
CaptionVo caption = captionVos.get(i);
Integer picType = caption.getPicType();
Coordinate coordinate = coordinateMap.get(picType);
if (coordinate == null) {
continue;
}
return XmlUtil.toStr(root, "GBK", false); List<Context> contexts = caption.getContexts();
Pair<String, Integer> combine = combineCaptionContent(contexts);
String content = combine.getKey();
Integer wrapCount = combine.getValue();
Element ele = XmlUtil.appendChild(captionsElement, "Caption" + (i + 1));
XmlUtil.appendChild(ele, "Content").setTextContent(content);
XmlUtil.appendChild(ele, "bgColor").setTextContent(caption.getBgColor().toString());
XmlUtil.appendChild(ele, "Font").setTextContent(caption.getFont().toString());
XmlUtil.appendChild(ele, "FontSize").setTextContent(caption.getFontSize().toString());
XmlUtil.appendChild(ele, "fgColor").setTextContent(caption.getFgColor().toString());
XmlUtil.appendChild(ele, "ShadowColor").setTextContent("4");
XmlUtil.appendChild(ele, "ShadowSize").setTextContent("0");
XmlUtil.appendChild(ele, "bgTransparency").setTextContent(caption.getBgTransparency().toString());
Element coordinateElement = XmlUtil.appendChild(ele, "Coordinate");
// 坐标需要根据positionType来搞
XmlUtil.appendChild(coordinateElement, "left").setTextContent(coordinate.getX());
XmlUtil.appendChild(coordinateElement, "top").setTextContent(coordinate.getY());
XmlUtil.appendChild(coordinateElement, "width").setTextContent(coordinate.getName() + "宽");
int height = wrapCount == 0 ? 80 : caption.getFontSize() * wrapCount;
XmlUtil.appendChild(coordinateElement, "height").setTextContent(String.valueOf(height));
captionCount++;
}
XmlUtil.appendChild(captionsElement, "Count").setTextContent(String.valueOf(captionCount));
return configNode;
}
private Element createTextNode(String name, String text) {
Element node = document.createElement(name);
node.setTextContent(text);
return node;
}
private String combineConditions(List<String> dataTypes) {
return dataTypes.stream().map(x -> "数据类型=" + x).collect(Collectors.joining("+"));
}
private Pair<String, Integer> combineCaptionContent(List<Context> contexts) {
if (CollectionUtil.isEmpty(contexts)) {
return Pair.of(null, null);
}
StringBuilder sb = new StringBuilder();
int wrapCount = 0;
for (Context context : contexts) {
sb.append(Dict.INSTANCE.captionType.get(context.getType())).append(":+").append(context.getContent());
if (context.getWrap()) {
wrapCount++;
sb.append("+(换行分隔符)");
}
}
return Pair.of(sb.toString(), wrapCount);
}
private static class PicConfigCalculator {
public final Coordinate[] coordinates;
/** key : picType */
public final HashMap<Integer, Coordinate> coordinateMap = new HashMap<>();
private final int layoutType;
public PicConfigCalculator(PicConfigVo picConfigVo) {
List<Context> contexts = picConfigVo.getContexts().stream().sorted(Comparator.comparingInt(Context::getOrder)).collect(Collectors.toList());
layoutType = picConfigVo.getType();
this.coordinates = new Coordinate[contexts.size()];
for (int i = 0; i < contexts.size(); i++) {
Context context = contexts.get(i);
Integer picType = context.getType();
calCoordinate(i, picType);
}
}
private void calCoordinate(Integer index, Integer picType) {
String x = "0";
String y = "80";
if (index != 0) {
Coordinate pre = coordinates[index - 1];
switch (layoutType) {
case 21:
case 31:
case 41:
case 51:
case 61:
x = pre.x + "+" + Dict.INSTANCE.picType.get(pre.getType()) + "宽";
y = "80";
break;
case 12:
case 13:
case 14:
case 15:
case 16:
x = "0";
y = pre.y + "+" + Dict.INSTANCE.picType.get(pre.getType()) + "高";
break;
case 22:
case 23:
if (index == 1) {
x = Dict.INSTANCE.picType.get(pre.getType()) + "宽";
y = "80";
} else if (index == 2) {
x = "0";
y = "80" + "+" + Dict.INSTANCE.picType.get(coordinates[0].getType()) + "高";
} else if (index == 3) {
x = Dict.INSTANCE.picType.get(coordinates[2].getType()) + "宽";
y = "80" + "+" + Dict.INSTANCE.picType.get(coordinates[1].getType()) + "高";
} else if (index == 4) {
x = "0";
y = coordinates[2].y + "+" + Dict.INSTANCE.picType.get(coordinates[2].getType()) + "高";
} else if (index == 5) {
x = Dict.INSTANCE.picType.get(coordinates[4].getType()) + "宽";
y = coordinates[3].y + "+" + Dict.INSTANCE.picType.get(coordinates[3].getType()) + "高";
}
break;
case 32:
if (index == 1) {
x = Dict.INSTANCE.picType.get(coordinates[0].getType()) + "宽";
y = "80";
} else if (index == 2) {
x = coordinates[1].x + "+" + Dict.INSTANCE.picType.get(coordinates[1].getType()) + "宽";
y = "80";
} else if (index == 3) {
x = "0";
y = "80" + "+" + Dict.INSTANCE.picType.get(coordinates[0].getType()) + "高";
} else if (index == 4) {
x = Dict.INSTANCE.picType.get(coordinates[3].getType()) + "宽";
y = "80" + "+" + Dict.INSTANCE.picType.get(coordinates[1].getType()) + "高";
} else if (index == 5) {
x = Dict.INSTANCE.picType.get(coordinates[4].getType()) + "宽";
y = "80" + "+" + Dict.INSTANCE.picType.get(coordinates[2].getType()) + "高";
}
break;
default:
throw new RuntimeException("no such type");
}
}
Coordinate coordinate = new Coordinate(picType, Dict.INSTANCE.picType.get(picType), x, y);
coordinates[index] = coordinate;
coordinateMap.put(picType, coordinate);
}
}
public @Getter
@Setter
@AllArgsConstructor
static class Coordinate {
private Integer type;
private String name;
private String x;
private String y;
} }
} }
...@@ -26,4 +26,8 @@ public class PicConfig extends BaseModel { ...@@ -26,4 +26,8 @@ public class PicConfig extends BaseModel {
private Integer type; private Integer type;
@JsonIgnore @JsonIgnore
private String context; private String context;
public Integer calPicCount() {
return (type / 10) * (type % 10);
}
} }
package com.viontech.storage.model; 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.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter; import lombok.Getter;
...@@ -21,6 +23,7 @@ public class StorageConfig extends BaseModel { ...@@ -21,6 +23,7 @@ public class StorageConfig extends BaseModel {
private String name; private String name;
@JsonIgnore @JsonIgnore
@TableField(fill = FieldFill.INSERT_UPDATE)
private String context; private String context;
private byte[] config; private byte[] config;
private Integer type; private Integer type;
......
...@@ -11,9 +11,9 @@ spring: ...@@ -11,9 +11,9 @@ spring:
# 服务发现配置 # 服务发现配置
discovery: discovery:
# 启用服务发现 # 启用服务发现
enabled: true enabled: false
# 启用服务注册 # 启用服务注册
register: true register: false
# 服务停止时取消注册 # 服务停止时取消注册
deregister: true deregister: true
# 表示注册时使用IP而不是hostname # 表示注册时使用IP而不是hostname
...@@ -30,7 +30,7 @@ spring: ...@@ -30,7 +30,7 @@ spring:
metadata: metadata:
version: 0.0.1-SNAPSHOT version: 0.0.1-SNAPSHOT
datasource: 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 username: root
password: vion password: vion
schema: classpath:db/init.sql 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!