feat(协议相关服务):
This commit is contained in:
parent
f817669bd0
commit
36d726f3bd
|
@ -0,0 +1,112 @@
|
|||
package com.ruoyi.protocol.sansi;
|
||||
|
||||
import com.ruoyi.board.domain.BoardInfo;
|
||||
import com.ruoyi.board.domain.PresetContent;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.uuid.UUID;
|
||||
import com.ruoyi.protocol.sansi.enums.SanSiFontColor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import zhishuang.wang.sansi.fcms.devinfor.DeviceControl;
|
||||
import zhishuang.wang.sansi.fcms.devinfor.DeviceVar;
|
||||
import zhishuang.wang.sansi.playlist.AreaItem;
|
||||
import zhishuang.wang.sansi.playlist.PageItem;
|
||||
import zhishuang.wang.sansi.playlist.PlayItem;
|
||||
import zhishuang.wang.sansi.playlist.entry.*;
|
||||
import zhishuang.wang.sansi.playlist.fcms.PlayListFcms;
|
||||
import zhishuang.wang.sansi.tools.ReturnData;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SanSiProtocol {
|
||||
private static final Logger log = LoggerFactory.getLogger(SanSiProtocol.class);
|
||||
|
||||
String deviceId = "1";
|
||||
|
||||
public String createTextItem(PresetContent presetContent, BoardInfo boardInfo) {
|
||||
Animation animation = new Animation();
|
||||
animation.setInAnimation(0);
|
||||
animation.setInAnimationSpeed(200);
|
||||
|
||||
TextBase textBase = new TextBase(0, presetContent.getContent());
|
||||
textBase.setFontSize(presetContent.getFontSize()+","+presetContent.getFontSize());
|
||||
textBase.setFontName(presetContent.getFontStyle());
|
||||
textBase.setWordSpace(presetContent.getLetterSpacing());
|
||||
BaseColour fontColour = SanSiFontColor.getBaseColourByColorName(presetContent.getFontColor());
|
||||
if (null == fontColour) {
|
||||
log.error("BaseColour fontColour = SanSiFontColor.getBaseColourByColorName(presetContent.getFontColor()); 没有匹配到相应的字体颜色");
|
||||
return null;
|
||||
}
|
||||
textBase.setFontColour(fontColour);
|
||||
|
||||
PlayTimeBase textPlayTime = new PlayTimeBase(presetContent.getPlayTime());
|
||||
PlayItem textPlayItem = new PlayItem(1, "1", "test", textBase, textPlayTime);
|
||||
textPlayItem.setAnimation(animation);
|
||||
textPlayItem.setX(presetContent.getFontPositionX());
|
||||
textPlayItem.setY(presetContent.getFontPositionY());
|
||||
|
||||
List<PlayItem> playItemList = new ArrayList<>();
|
||||
playItemList.add(textPlayItem);
|
||||
|
||||
String boardSize = boardInfo.getBoardSize();
|
||||
String[] split = StringUtils.split(boardSize, "*");
|
||||
if (split.length < 2) {
|
||||
log.info("尺寸有问题,请重新设置尺寸");
|
||||
return null;
|
||||
}
|
||||
int height = Integer.parseInt(split[0]);
|
||||
int width = Integer.parseInt(split[1]);
|
||||
|
||||
AreaPositon areaPositon = new AreaPositon(0, 0, height, width, 0);
|
||||
AreaItem areaItem = new AreaItem("1", "areaItem", areaPositon, playItemList);
|
||||
|
||||
List<AreaItem> areaItemList = new ArrayList<>();
|
||||
areaItemList.add(areaItem);
|
||||
|
||||
PageItem pageItem = new PageItem("1", "pageItem", areaItemList);
|
||||
PlayListFcms plf = new PlayListFcms();
|
||||
|
||||
String path = "./sansi/" + UUID.fastUUID() + "/play.lst";
|
||||
File file = new File(path);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
|
||||
ReturnData rd = plf.createFcmsPlayList(path, pageItem);
|
||||
System.out.println("====" + rd.getCode());
|
||||
System.out.println("====" + rd.getMessage());
|
||||
if (rd.getCode() != 0) {
|
||||
log.error("生成三思的上传文件出错了");
|
||||
return null;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
private void loginDevice(BoardInfo boardInfo) {
|
||||
DeviceVar.deviceInforInit(deviceId, 1, boardInfo.getBoardIp(), boardInfo.getBoardPort(), 2048);
|
||||
}
|
||||
|
||||
private boolean uploadAndStartPlayList(String path) {
|
||||
ReturnData uploadPlayListRD = DeviceControl.fcmsUploadPlayList(deviceId, path);//上传播放表
|
||||
if (uploadPlayListRD.getCode() != 0) {
|
||||
log.error("上传错误");
|
||||
return false;
|
||||
}
|
||||
ReturnData activePlayListRD = DeviceControl.fcmsActivePlayList(deviceId, "play.lst");
|
||||
if (activePlayListRD.getCode() != 0) {
|
||||
log.error("播放错误");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean publishContent(BoardInfo boardInfo, PresetContent presetContent){
|
||||
loginDevice(boardInfo);
|
||||
String filePath = createTextItem(presetContent, boardInfo);
|
||||
return uploadAndStartPlayList(filePath);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.ruoyi.protocol.sansi.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import zhishuang.wang.sansi.playlist.entry.BaseColour;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Getter
|
||||
public enum SanSiFontColor {
|
||||
|
||||
red("red", new BaseColour(255, 0, 0, 0, 0)),
|
||||
yellow("yellow", new BaseColour(255, 255, 0, 0, 0)),
|
||||
green("green", new BaseColour(0, 255, 0, 0, 0));
|
||||
|
||||
private final String colorName;
|
||||
private final BaseColour colour;
|
||||
|
||||
SanSiFontColor(String colorName, BaseColour colour) {
|
||||
this.colorName = colorName;
|
||||
this.colour = colour;
|
||||
}
|
||||
|
||||
public static BaseColour getBaseColourByColorName(String colorName) {
|
||||
return Stream.of(SanSiFontColor.values())
|
||||
.filter(fontColor -> fontColor.getColorName().equals(colorName))
|
||||
.map(SanSiFontColor::getColour)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package com.ruoyi.protocol.service.impl;
|
||||
|
||||
import com.ruoyi.protocol.service.IProtocolService;
|
||||
|
||||
public class ProtocolServiceImpl implements IProtocolService {
|
||||
}
|
Loading…
Reference in New Issue