修复易联云对接获取token的bug,修改获取行政区列表接口逻辑
This commit is contained in:
parent
f9c7354301
commit
6f41eb2599
@ -31,7 +31,7 @@ public class GenerateQRCodeImage {
|
||||
public static String generateQRCodeUrl(String deviceName, String deviceCode, String companyName){
|
||||
try {
|
||||
// 二维码内容
|
||||
String qrCodeContent = ACTIVATE_URL+"?deviceName="+deviceName+"&deviceCode="+deviceCode;
|
||||
String qrCodeContent =deviceCode;
|
||||
|
||||
// 生成二维码
|
||||
BitMatrix bitMatrix = generateQRCode(qrCodeContent, 220, 220);
|
||||
|
@ -0,0 +1,88 @@
|
||||
package com.fastbee.data.controller.printer.yilianyun;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.MultiFormatWriter;
|
||||
import com.google.zxing.WriterException;
|
||||
import com.google.zxing.client.j2se.MatrixToImageWriter;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.print.Printable;
|
||||
import java.awt.print.PrinterJob;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.print.PrintService;
|
||||
import javax.print.PrintServiceLookup;
|
||||
|
||||
public class MainPrint {
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// 二维码内容
|
||||
String qrCodeContent = "https://www.example.com";
|
||||
|
||||
// 生成二维码
|
||||
BitMatrix bitMatrix = generateQRCode(qrCodeContent, 180, 180);
|
||||
|
||||
// 将二维码转换为BufferedImage
|
||||
BufferedImage qrCodeImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
|
||||
|
||||
// 创建一个新的BufferedImage,包含二维码和文字
|
||||
int qrCodeWidth = qrCodeImage.getWidth();
|
||||
int qrCodeHeight = qrCodeImage.getHeight();
|
||||
int textWidth = 200; // 文字区域宽度
|
||||
int textHeight = qrCodeHeight; // 文字区域高度,与二维码相同
|
||||
int imageWidth = qrCodeWidth + textWidth + 20; // 间距20像素
|
||||
int imageHeight = qrCodeHeight;
|
||||
|
||||
BufferedImage finalImage = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g2d = finalImage.createGraphics();
|
||||
|
||||
// 绘制背景颜色
|
||||
g2d.setColor(Color.WHITE);
|
||||
g2d.fillRect(0, 0, imageWidth, imageHeight);
|
||||
|
||||
// 绘制二维码
|
||||
g2d.drawImage(qrCodeImage, 0, 0, qrCodeWidth, qrCodeHeight, null);
|
||||
|
||||
// 绘制文字
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.setFont(new Font("黑体", Font.BOLD, 15));
|
||||
String text1 = "设备名称";
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||
int textX = qrCodeWidth ; // 间距20像素
|
||||
int textY1 = (imageHeight - fontMetrics.getHeight()) / 2 + fontMetrics.getAscent()-40;
|
||||
g2d.drawString(text1, textX, textY1);
|
||||
|
||||
// 绘制第二段文字
|
||||
String text2 = "设备编码";
|
||||
int textY2 = textY1 + fontMetrics.getHeight() + 20; // 在第一段文字下方添加一些间距
|
||||
g2d.drawString(text2, textX, textY2);
|
||||
// 绘制第三段文字
|
||||
String text3 = "XXXX公司";
|
||||
int textY3 = textY2 + fontMetrics.getHeight() + 20; // 在第一段文字下方添加一些间距
|
||||
g2d.drawString(text3, textX, textY3);
|
||||
// 释放Graphics2D资源
|
||||
g2d.dispose();
|
||||
|
||||
// 保存图片到文件
|
||||
File outputfile = new File("C:\\Users\\admin\\Desktop\\sa.png");
|
||||
ImageIO.write(finalImage, "png", outputfile);
|
||||
|
||||
System.out.println("二维码和文字图片已生成:" + outputfile.getAbsolutePath());
|
||||
} catch (WriterException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private static BitMatrix generateQRCode(String text, int width, int height) throws WriterException {
|
||||
Map<EncodeHintType, Object> hints = new HashMap<>();
|
||||
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
|
||||
return new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, width, height, hints);
|
||||
}
|
||||
}
|
@ -39,7 +39,7 @@ public class YiLianYunAuthorizationService {
|
||||
// System.err.println("从服务器获取token:"+token);
|
||||
// return token;
|
||||
stringRedisTemplate.opsForValue().set("yilianyun:user:token",token,3600*24*20, TimeUnit.MILLISECONDS);
|
||||
return stringRedisTemplate.opsForValue().get("yilianyun:access_token");
|
||||
return stringRedisTemplate.opsForValue().get("yilianyun:user:token");
|
||||
}
|
||||
|
||||
public String getAuth() {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.fastbee.deviceData.service.impl;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
@ -121,7 +122,7 @@ public class DeviceRealtimedataMeteorologyServiceImpl extends ServiceImpl<Device
|
||||
devicePropertiesList.add(DeviceProperties.builder().name("空气温度").value(meteorology.getAirTemp().toString()).unit("°C").build());
|
||||
devicePropertiesList.add(DeviceProperties.builder().name("空气湿度").value(meteorology.getAirHumi().toString()).unit("%").build());
|
||||
devicePropertiesList.add(DeviceProperties.builder().name("风速").value(meteorology.getWindSpeed().toString()).unit("m/s").build());
|
||||
devicePropertiesList.add(DeviceProperties.builder().name("风向").value(meteorology.getWindDir().toString()).unit("°").build());
|
||||
devicePropertiesList.add(DeviceProperties.builder().name("风向").value(windDirMap(meteorology.getWindDir())).unit("风").build());
|
||||
devicePropertiesList.add(DeviceProperties.builder().name("大气压力").value(meteorology.getAirPre().toString()).unit("hPa").build());
|
||||
devicePropertiesList.add(DeviceProperties.builder().name("光照度").value(meteorology.getGuangzhao().toString()).unit("lx").build());
|
||||
devicePropertiesList.add(DeviceProperties.builder().name("光合有效辐射").value(meteorology.getFushe().toString()).unit("Lux").build());
|
||||
@ -142,4 +143,28 @@ public class DeviceRealtimedataMeteorologyServiceImpl extends ServiceImpl<Device
|
||||
/**
|
||||
* 风向数据映射
|
||||
*/
|
||||
private String windDirMap(BigDecimal windDir){
|
||||
//8个风向
|
||||
if (windDir.compareTo(new BigDecimal("0")) >= 0 && windDir.compareTo(new BigDecimal("22.5")) < 0) {
|
||||
return "北";
|
||||
} else if (windDir.compareTo(new BigDecimal("22.5")) >= 0 && windDir.compareTo(new BigDecimal("67.5")) < 0) {
|
||||
return "东北";
|
||||
} else if (windDir.compareTo(new BigDecimal("67.5")) >= 0 && windDir.compareTo(new BigDecimal("112.5")) < 0) {
|
||||
return "东";
|
||||
} else if (windDir.compareTo(new BigDecimal("112.5")) >= 0 && windDir.compareTo(new BigDecimal("157.5")) < 0) {
|
||||
return "东南";
|
||||
} else if (windDir.compareTo(new BigDecimal("157.5")) >= 0 && windDir.compareTo(new BigDecimal("202.5")) < 0) {
|
||||
return "南";
|
||||
} else if (windDir.compareTo(new BigDecimal("202.5")) >= 0 && windDir.compareTo(new BigDecimal("247.5")) < 0) {
|
||||
return "西南";
|
||||
} else if (windDir.compareTo(new BigDecimal("247.5")) >= 0 && windDir.compareTo(new BigDecimal("292.5")) < 0) {
|
||||
return "西";
|
||||
} else if (windDir.compareTo(new BigDecimal("292.5")) >= 0 && windDir.compareTo(new BigDecimal("337.5")) < 0) {
|
||||
return "西北";
|
||||
} else if (windDir.compareTo(new BigDecimal("337.5")) >= 0 && windDir.compareTo(new BigDecimal("360")) < 0) {
|
||||
return "北";
|
||||
} else {
|
||||
return "无数据";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -647,17 +647,22 @@ public class ProjectServiceImpl implements IProjectService
|
||||
//过滤后项目列表
|
||||
List<Project> projectFilterList =new ArrayList<>();
|
||||
for (Project project : projectAllList) {
|
||||
// System.err.println("-----------"+project.getProjectName()+"------------");
|
||||
String administrativeAreaCode = project.getAdministrativeAreaCode();
|
||||
if(StringUtils.isNotBlank(administrativeAreaCode)){
|
||||
JSONArray areaCodeArrays = JSONUtil.parseArray(administrativeAreaCode);
|
||||
if(!areaCodeArrays.isEmpty()){
|
||||
JSONArray areaCodeArray = JSONUtil.parseArray(areaCodeArrays.get(0));
|
||||
for(Object areaCodeArrayObj:areaCodeArrays){
|
||||
JSONArray areaCodeArray = JSONUtil.parseArray(areaCodeArrayObj.toString());
|
||||
for (Object o : areaCodeArray) {
|
||||
// System.err.println("项目行政区划代码:"+o);
|
||||
if(o.equals(areaCode)){
|
||||
projectFilterList.add(project);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return projectFilterList;
|
||||
|
@ -239,15 +239,15 @@ public class SysDistrictServiceImpl implements ISysDistrictService
|
||||
}
|
||||
List<SysDistrict> sysDistrictList = getDistricts(SysDistricts, map, roots);
|
||||
//处理直辖市情况
|
||||
for (SysDistrict sysDistrict : sysDistrictList) {
|
||||
if(isMunicipality(sysDistrict.getName())&&sysDistrict.getLevel()==1){
|
||||
List<SysDistrict> children = sysDistrict.getChildren();
|
||||
SysDistrict district = children.get(0);
|
||||
children.remove(0);
|
||||
sysDistrict.setChildren(Collections.singletonList(district));
|
||||
sysDistrict.getChildren().get(0).setChildren(children);
|
||||
}
|
||||
}
|
||||
// for (SysDistrict sysDistrict : sysDistrictList) {
|
||||
// if(isMunicipality(sysDistrict.getName())&&sysDistrict.getLevel()==1){
|
||||
// List<SysDistrict> children = sysDistrict.getChildren();
|
||||
// SysDistrict district = children.get(0);
|
||||
// children.remove(0);
|
||||
// sysDistrict.setChildren(Collections.singletonList(district));
|
||||
// sysDistrict.getChildren().get(0).setChildren(children);
|
||||
// }
|
||||
// }
|
||||
return sysDistrictList;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user