Commit c0d99f74 authored by 董国亮's avatar 董国亮

优化下发,处理异常

parent 7a246d65
......@@ -80,27 +80,27 @@ public class InduceSendServiceImpl implements InduceSendService {
public void send(MessageParam param) throws IOException, TemplateException {
//生成诱导屏推送sourceId
String messageId = UUID.randomUUID().toString().toLowerCase();
InduceHist induceHist=new InduceHist();
InduceHist induceHist = new InduceHist();
param.setSourceId(messageId);
induceHist.setSourceId(messageId);
GreenwaveInduces greenwaveinduces=greenwaveInducesService.getById(param.getInduceId());
GreenwaveInduces greenwaveinduces = greenwaveInducesService.getById(param.getInduceId());
// 读取图片模板参数
InduceTemplate induceTemplate = induceTemplateService.getById(param.getTemplateId());
if(param.getFlg()==1) {
if (param.getFlg() == 1) {
LambdaQueryWrapper<DeviceInduces> deviceQueryWrapper = new LambdaQueryWrapper<>();
deviceQueryWrapper.eq(DeviceInduces::getEquipCode, induceTemplate.getEquipCode());
DeviceInduces deviceInduces = deviceInducesService.getOne(deviceQueryWrapper);
if(Objects.nonNull(deviceInduces)) {
if (Objects.nonNull(deviceInduces)) {
param.setResolutionWidth(deviceInduces.getResolutionWidth().intValue());
param.setResolutionHeight(deviceInduces.getResolutionHeight().intValue());
}
}
// 获取图片字节数组
byte[] imageBytes = induceTemplate.getFileContent();
if (imageBytes != null || imageBytes.length > 0) {
// 将字节数组转换为字节对象
BufferedImage image =null;
try {
BufferedImage image = null;
try {
byte[] imageBytes = induceTemplate.getFileContent();
if (imageBytes != null || imageBytes.length > 0) {
// 将字节数组转换为字节对象
image = ImageIO.read(new ByteArrayInputStream(imageBytes));
// 修改图像中文字
//addTextToImage(image, param.getContents(), induceTemplate.getTextX(), induceTemplate.getTextY(), induceTemplate.getTextSize(), induceTemplate.getTextSign());
......@@ -117,26 +117,26 @@ public class InduceSendServiceImpl implements InduceSendService {
// 图片生成操作
boolean upDown = param.getContents()[0].contains("▲") || param.getContents()[0].contains("▼");
createImageWithText(induceTemplate, image, param.getContents(), induceTemplate.getTextSign(), upDown, topLeftX, topLeftY, bottomRightX, bottomRightY);
}catch (Exception ex){
log.error(ex.getMessage());
}
// 测试阶段保存图片到本地
} catch (Exception ex) {
log.error(ex.getMessage());
}
// 测试阶段保存图片到本地
// ImageIO.write(image, "bmp", new File("D:\\tmp\\" + induceTemplate.getFileName()));
// 上传文件至ftp
if (param.getFlg() == 1) {
String dirName=LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
String fileName=param.getEquipCode()+"_"+UUID.randomUUID().toString()+".bmp";
String filePath = uploadFile(image,dirName, fileName);
param.setFtpPath(filePath);
induceHist.setFilePath(PATH + dirName+"/"+fileName);
if(Objects.nonNull(param.getContents()) && param.getContents().length>0) {
induceHist.setInduceSpeed(param.getContents()[0]);
}
if(Objects.nonNull(greenwaveinduces)) {
greenwaveinduces.setSourceId(PATH + dirName + "/" + fileName);
}
// 上传文件至ftp
String dirName = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
String fileName = param.getEquipCode() + "_" + UUID.randomUUID().toString() + ".bmp";
String filePath = uploadFile(image, dirName, fileName);
param.setFtpPath(filePath);
induceHist.setFilePath(PATH + dirName + "/" + fileName);
if (Objects.nonNull(param.getContents()) && param.getContents().length > 0) {
induceHist.setInduceSpeed(param.getContents()[0]);
}
if (Objects.nonNull(greenwaveinduces)) {
greenwaveinduces.setSourceId(PATH + dirName + "/" + fileName);
}
log.info("上传文件至ftp-filePath:{}", param.getFtpPath());
}
// //如果已发布,则调用下屏服务
// if(greenwaveinduces.getStatus()==1){
// param.setFlg(2);
......@@ -154,34 +154,34 @@ public class InduceSendServiceImpl implements InduceSendService {
// Message messageSend = new Message(message.getBytes(), messageProperties);
// rabbitTemplate.convertAndSend("",queueName, messageSend);
// }
// 推送mq消息
String message = convertMessage(param.getFlg()==1?"induce_up.xml":"induce_down.xml",param);
// 去掉所有转义字符(\n、\t、\b、等)
// 推送mq消息
String message = convertMessage(param.getFlg() == 1 ? "induce_up.xml" : "induce_down.xml", param);
// 去掉所有转义字符(\n、\t、\b、等)
// message = message.replaceAll("[\\n\\t\\r]", ""); // 可以根据需要添加更多字符
// 可以去掉反斜杠
// 可以去掉反斜杠
// message = message.replace("\\", "");
// 创建MessageProperties并设置内容类型
// 创建MessageProperties并设置内容类型
// MessageProperties messageProperties = new MessageProperties();
// messageProperties.setContentType("text/plain"); // 设置内容类型为text/plain
// 创建Message并设置内容
// 创建Message并设置内容
// Message messageSend = new Message(message.getBytes(), messageProperties);
if(sending)
{
rabbitTemplate.convertAndSend("", queueName, message);
}
log.info("mqtt发送信息-topic:{},queueName:{},message:{}", queueName, message);
//1、增加下发记录log 2、计数 3、标记已发布状体
if (sending) {
rabbitTemplate.convertAndSend("", queueName, message);
}
log.info("mqtt发送信息-topic:{},queueName:{},message:{}", queueName, message);
//1、增加下发记录log 2、计数 3、标记已发布状体
if (Objects.nonNull(induceTemplate) && Objects.nonNull(induceTemplate.getEquipCode()) && param.getFlg() == 1) {
induceHist.setEquipCode(induceTemplate.getEquipCode());
induceHist.setGreenId(param.getGreenId());
induceHistService.save(induceHist);
//保存诱导状态信息
if(Objects.nonNull(greenwaveinduces) && param.getFlg()==1) {
greenwaveinduces.setInducesCount(Objects.isNull(greenwaveinduces.getInducesCount()) ? 0 : greenwaveinduces.getInducesCount() + ((param.getFlg()==1)?1:0));
greenwaveinduces.setStatus(param.getFlg()==1?1:0);
greenwaveInducesService.saveOrUpdate(greenwaveinduces);
}
}
}
//保存诱导状态信息
if (Objects.nonNull(greenwaveinduces)) {
greenwaveinduces.setInducesCount(Objects.isNull(greenwaveinduces.getInducesCount()) ? 0 : greenwaveinduces.getInducesCount() + ((param.getFlg() == 1) ? 1 : 0));
greenwaveinduces.setStatus(param.getFlg() == 1 ? 1 : 0);
greenwaveInducesService.saveOrUpdate(greenwaveinduces);
}
}
@Override
public String uploadFile(BufferedImage image,String directoryName, String fileName) {
......
......@@ -5,7 +5,7 @@
<mapper namespace="net.wanji.opt.dao.mapper.StrategyGreenOptHistMapper">
<select id="selectByGreenId" resultType="net.wanji.opt.po.StrategyGreenOptHistEntity" parameterType="String" >
select * from t_strategy_green_opt_hist where `green_id` = #{greenId} and TIMESTAMPDIFF(SECOND,`control_time`, now()) &lt; `control_duration` order by create_time desc limit 2;
select * from t_strategy_green_opt_hist where `green_id` = #{greenId} and `control_method`=1 and TIMESTAMPDIFF(SECOND,`control_time`, now()) &lt; `control_duration` order by create_time desc limit 2;
</select>
</mapper>
\ No newline at end of file
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