Commit 709ddb7f authored by zhouleilei's avatar zhouleilei

诱导屏更新

parent 280cba58
...@@ -4,14 +4,14 @@ import com.baomidou.mybatisplus.annotation.IdType; ...@@ -4,14 +4,14 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.Date;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import org.apache.ibatis.type.BlobTypeHandler; import org.apache.ibatis.type.BlobTypeHandler;
import java.io.Serializable;
import java.util.Date;
/** /**
* <p> * <p>
* 诱导屏-发布模板 * 诱导屏-发布模板
...@@ -97,5 +97,21 @@ public class InduceTemplate implements Serializable { ...@@ -97,5 +97,21 @@ public class InduceTemplate implements Serializable {
@TableField("gmt_modified") @TableField("gmt_modified")
private Date gmtModified; private Date gmtModified;
/**
* 图片宽度
*/
@TableField("file_width")
private Integer fileWidth;
/**
* 图片高度
*/
@TableField("file_height")
private Integer fileHeight;
/**
* 速度值
*/
@TableField("text_send")
private String textSend;
} }
...@@ -115,8 +115,8 @@ public class InduceSendServiceImpl implements InduceSendService { ...@@ -115,8 +115,8 @@ public class InduceSendServiceImpl implements InduceSendService {
int bottomRightX = Integer.parseInt(bottomRight[0]); int bottomRightX = Integer.parseInt(bottomRight[0]);
int bottomRightY = Integer.parseInt(bottomRight[1]); int bottomRightY = Integer.parseInt(bottomRight[1]);
// 图片生成操作 // 图片生成操作
boolean upDown = param.getContents()[0].contains("▲") || param.getContents()[0].contains("▼"); //boolean upDown = param.getContents()[0].contains("▲") || param.getContents()[0].contains("▼");
createImageWithText(induceTemplate, image, param.getContents(), upDown, topLeftX, topLeftY, bottomRightX, bottomRightY); createImageWithText(induceTemplate, image, param.getContents(), true, topLeftX, topLeftY, bottomRightX, bottomRightY);
} }
} catch (Exception ex) { } catch (Exception ex) {
log.error(ex.getMessage()); log.error(ex.getMessage());
...@@ -136,6 +136,8 @@ public class InduceSendServiceImpl implements InduceSendService { ...@@ -136,6 +136,8 @@ public class InduceSendServiceImpl implements InduceSendService {
greenwaveinduces.setSourceId(PATH + dirName + "/" + fileName); greenwaveinduces.setSourceId(PATH + dirName + "/" + fileName);
} }
log.info("上传文件至ftp-filePath:{}", param.getFtpPath()); log.info("上传文件至ftp-filePath:{}", param.getFtpPath());
induceTemplateService.updateById(induceTemplate);
} }
// //如果已发布,则调用下屏服务 // //如果已发布,则调用下屏服务
// if(greenwaveinduces.getStatus()==1){ // if(greenwaveinduces.getStatus()==1){
...@@ -287,15 +289,6 @@ public class InduceSendServiceImpl implements InduceSendService { ...@@ -287,15 +289,6 @@ public class InduceSendServiceImpl implements InduceSendService {
} }
/**
* 根据绘制的区域,动态调整字体大小,以适应文本区域
*
* @param g2d graphics2d对象
* @param sign 绘制方向标识
* @param text 绘制内容
* @param width 绘制区域宽度
* @param height 绘制区域高度
*/
/** /**
* 根据绘制的区域,动态调整字体大小,以适应文本区域 * 根据绘制的区域,动态调整字体大小,以适应文本区域
* *
...@@ -304,7 +297,7 @@ public class InduceSendServiceImpl implements InduceSendService { ...@@ -304,7 +297,7 @@ public class InduceSendServiceImpl implements InduceSendService {
* @param width 绘制区域宽度 * @param width 绘制区域宽度
* @param height 绘制区域高度 * @param height 绘制区域高度
*/ */
private static FontMetrics autoFont(Graphics2D g2d, InduceTemplate drawParam,String[] contents, int width, int height) { private static FontMetrics autoFont(Graphics2D g2d, InduceTemplate drawParam, String[] contents, int width, int height) {
// 初始化字体 // 初始化字体
Font font = new Font(drawParam.getTextFont(), Font.BOLD, 1); Font font = new Font(drawParam.getTextFont(), Font.BOLD, 1);
g2d.setFont(font); g2d.setFont(font);
...@@ -317,26 +310,29 @@ public class InduceSendServiceImpl implements InduceSendService { ...@@ -317,26 +310,29 @@ public class InduceSendServiceImpl implements InduceSendService {
font = new Font(drawParam.getTextFont(), Font.BOLD, fontSize); font = new Font(drawParam.getTextFont(), Font.BOLD, fontSize);
g2d.setFont(font); g2d.setFont(font);
metrics = g2d.getFontMetrics(); metrics = g2d.getFontMetrics();
drawParam.setTextSize(fontSize);
// 确保绘制区域能够容纳文本,考虑字体长度和高度 // 确保绘制区域能够容纳文本,考虑字体长度和高度
// if (drawParam.getTextDirection()) { if (true) {
// // 高度考虑上下边距 // 高度只考虑上边距
// if (metrics.stringWidth(contents[0]) > width || (metrics.getHeight() - 4) > height) { if (metrics.stringWidth(contents[0]) > width || (metrics.getHeight() - 4) > height) {
// // 设置字体大小 // 设置字体大小
// font = new Font(drawParam.getTextFont(), Font.BOLD, --fontSize); font = new Font(drawParam.getTextFont(), Font.BOLD, --fontSize);
// g2d.setFont(font); g2d.setFont(font);
// metrics = g2d.getFontMetrics(); metrics = g2d.getFontMetrics();
// return metrics; drawParam.setTextSize(fontSize);
// } return metrics;
// } else { }
} else {
// 高度只考虑上边距 // 高度只考虑上边距
if (metrics.stringWidth(contents[0]) > width || (metrics.getHeight() - 1) * contents.length > height) { if (metrics.stringWidth(contents[0]) > width || (metrics.getHeight() - 1) * contents.length > height) {
// 设置字体大小 // 设置字体大小
font = new Font(drawParam.getTextFont(), Font.BOLD, --fontSize); font = new Font(drawParam.getTextFont(), Font.BOLD, --fontSize);
g2d.setFont(font); g2d.setFont(font);
metrics = g2d.getFontMetrics(); metrics = g2d.getFontMetrics();
drawParam.setTextSize(fontSize);
return metrics; return metrics;
} }
// } }
} }
// 若字体大小超出限制,则返回最小字体 // 若字体大小超出限制,则返回最小字体
return metrics; return metrics;
...@@ -347,7 +343,6 @@ public class InduceSendServiceImpl implements InduceSendService { ...@@ -347,7 +343,6 @@ public class InduceSendServiceImpl implements InduceSendService {
* *
* @param image 图片 * @param image 图片
* @param text 内容数组 * @param text 内容数组
* @param sign 绘制方向
* @param topLeftX 区域左上角x坐标 * @param topLeftX 区域左上角x坐标
* @param topLeftY 区域左上角y坐标 * @param topLeftY 区域左上角y坐标
* @param bottomRightX 区域右下角x坐标 * @param bottomRightX 区域右下角x坐标
...@@ -364,7 +359,7 @@ public class InduceSendServiceImpl implements InduceSendService { ...@@ -364,7 +359,7 @@ public class InduceSendServiceImpl implements InduceSendService {
int width = bottomRightX - topLeftX; int width = bottomRightX - topLeftX;
int height = bottomRightY - topLeftY; int height = bottomRightY - topLeftY;
// 动态调整字体大小,以适应文本区域 // 动态调整字体大小,以适应文本区域
FontMetrics metrics = autoFont( g2d,pictureFile, text, width, height); FontMetrics metrics = autoFont(g2d, pictureFile, text, width, height);
// 绘制坐标点 // 绘制坐标点
int textWidth; int textWidth;
// 考虑文字绘制方向、文字居中。垂直居中要根据文字高度,水平居中要根据文字宽度。 // 考虑文字绘制方向、文字居中。垂直居中要根据文字高度,水平居中要根据文字宽度。
...@@ -385,6 +380,7 @@ public class InduceSendServiceImpl implements InduceSendService { ...@@ -385,6 +380,7 @@ public class InduceSendServiceImpl implements InduceSendService {
currentX = topLeftX + (width - textWidth) / 2; currentX = topLeftX + (width - textWidth) / 2;
// 计算居中的y坐标 // 计算居中的y坐标
currentY = currentY + (height - metrics.getHeight()) / 2; currentY = currentY + (height - metrics.getHeight()) / 2;
textSend(pictureFile, text, g2d, 2, currentY);
g2d.drawString(text[0], currentX, currentY); g2d.drawString(text[0], currentX, currentY);
} else { } else {
// 计算每个文本内容的竖向绘制坐标 // 计算每个文本内容的竖向绘制坐标
...@@ -404,6 +400,41 @@ public class InduceSendServiceImpl implements InduceSendService { ...@@ -404,6 +400,41 @@ public class InduceSendServiceImpl implements InduceSendService {
g2d.dispose(); g2d.dispose();
} }
/**
* 判断是否包含“km/h”,若包含,对比上次绘制的速度值,追加上升或下降符号
*
* @param pictureFile
* @param text
* @param g2d
* @param currentX
* @param currentY
* @return
*/
public static void textSend(InduceTemplate pictureFile, String[] text, Graphics2D g2d, int currentX, int currentY) {
// 获取速度值
if (text.length > 0 && text[0].contains("km/h") && pictureFile.getFileWidth() > 128 && pictureFile.getFileHeight() > 64) {
String[] split = text[0].split("km/h");
if (split.length > 0) {
// 若存在上次的速度值,则对比
if (pictureFile.getTextSend() != null) {
String[] newSend = split[0].split("-");
String[] oldSend = pictureFile.getTextSend().split("-");
// 对比两组速度值,判断是否需要追加符号
if (newSend.length > 1 && oldSend.length > 1) {
int newSpeed = Integer.parseInt(newSend[0].trim()) + Integer.parseInt(newSend[1].trim());
int oldSpeed = Integer.parseInt(oldSend[0].trim()) + Integer.parseInt(oldSend[1].trim());
if (newSpeed > oldSpeed) {
g2d.drawString("▲ ", currentX, currentY);
} else if (newSpeed < oldSpeed) {
g2d.drawString("▼ ", currentX, currentY);
}
}
}
pictureFile.setTextSend(split[0]);
}
}
}
/** /**
* 在指定位置添加文字到图像 * 在指定位置添加文字到图像
* *
......
package net.wanji.opt.task; package net.wanji.opt.task;
import com.alibaba.druid.support.json.JSONUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
...@@ -12,7 +11,6 @@ import net.wanji.common.utils.tool.DateUtil; ...@@ -12,7 +11,6 @@ import net.wanji.common.utils.tool.DateUtil;
import net.wanji.common.utils.tool.JacksonUtils; import net.wanji.common.utils.tool.JacksonUtils;
import net.wanji.common.utils.tool.StringUtils; import net.wanji.common.utils.tool.StringUtils;
import net.wanji.databus.dao.entity.GreenwaveCrossPO; import net.wanji.databus.dao.entity.GreenwaveCrossPO;
import net.wanji.databus.dao.entity.GreenwaveCrossPOExt;
import net.wanji.databus.dao.entity.GreenwaveInfoPO; import net.wanji.databus.dao.entity.GreenwaveInfoPO;
import net.wanji.databus.dao.mapper.CrossDataRealtimeMapper; import net.wanji.databus.dao.mapper.CrossDataRealtimeMapper;
import net.wanji.databus.dao.mapper.GreenwaveCrossMapper; import net.wanji.databus.dao.mapper.GreenwaveCrossMapper;
...@@ -32,7 +30,6 @@ import net.wanji.opt.service.induce.InduceTemplateService; ...@@ -32,7 +30,6 @@ import net.wanji.opt.service.induce.InduceTemplateService;
import net.wanji.opt.synthesis.pojo.StrategyControlDetailList; import net.wanji.opt.synthesis.pojo.StrategyControlDetailList;
import net.wanji.opt.synthesis.pojo.StrategyDailyPlanInfoEntity; import net.wanji.opt.synthesis.pojo.StrategyDailyPlanInfoEntity;
import net.wanji.opt.synthesis.pojo.StrategyPlanInfoEntity; import net.wanji.opt.synthesis.pojo.StrategyPlanInfoEntity;
import net.wanji.opt.vo.GreenBeltInfoVO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -196,10 +193,10 @@ public class InducesMonitorTask { ...@@ -196,10 +193,10 @@ public class InducesMonitorTask {
// 计算绿波速度变化趋势 // 计算绿波速度变化趋势
if (Objects.nonNull(greenwaveInducesHist.getMinSpeed()) && Objects.nonNull(greenwaveInducesHist.getMaxSpeed()) && Objects.nonNull(greenOptHistEntity.getMinSpeed()) && Objects.nonNull(greenOptHistEntity.getMaxSpeed())) { if (Objects.nonNull(greenwaveInducesHist.getMinSpeed()) && Objects.nonNull(greenwaveInducesHist.getMaxSpeed()) && Objects.nonNull(greenOptHistEntity.getMinSpeed()) && Objects.nonNull(greenOptHistEntity.getMaxSpeed())) {
if (greenwaveInducesHist.getMinSpeed() > greenOptHistEntity.getMinSpeed() || greenwaveInducesHist.getMaxSpeed() > greenOptHistEntity.getMaxSpeed()) { if (greenwaveInducesHist.getMinSpeed() > greenOptHistEntity.getMinSpeed() || greenwaveInducesHist.getMaxSpeed() > greenOptHistEntity.getMaxSpeed()) {
upDown = ""; upDown = "";
} }
if (greenwaveInducesHist.getMinSpeed() < greenOptHistEntity.getMinSpeed() || greenwaveInducesHist.getMaxSpeed() < greenOptHistEntity.getMaxSpeed()) { if (greenwaveInducesHist.getMinSpeed() < greenOptHistEntity.getMinSpeed() || greenwaveInducesHist.getMaxSpeed() < greenOptHistEntity.getMaxSpeed()) {
upDown = ""; upDown = "";
} }
} }
greenwaveInducesHist.setMinSpeed(greenOptHistEntity.getMinSpeed()); greenwaveInducesHist.setMinSpeed(greenOptHistEntity.getMinSpeed());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment