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

优化下发,处理异常

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