Commit 3766bfce authored by 王夏晖's avatar 王夏晖

Merge remote-tracking branch 'origin/develop' into develop

parents 6f47a7b6 4a2dd352
...@@ -340,7 +340,11 @@ ...@@ -340,7 +340,11 @@
<artifactId>weixin-java-mp</artifactId> <artifactId>weixin-java-mp</artifactId>
<version>3.0.0</version> <version>3.0.0</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.3.2</version>
</dependency>
</dependencies> </dependencies>
......
...@@ -3,6 +3,7 @@ package org.rcisoft.business.device.assets.controller; ...@@ -3,6 +3,7 @@ package org.rcisoft.business.device.assets.controller;
/*固定导入*/ /*固定导入*/
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -10,6 +11,7 @@ import org.apache.poi.hssf.usermodel.*; ...@@ -10,6 +11,7 @@ import org.apache.poi.hssf.usermodel.*;
import org.rcisoft.business.device.assets.entity.BusDevice; import org.rcisoft.business.device.assets.entity.BusDevice;
import org.rcisoft.business.device.assets.service.BusDeviceService; import org.rcisoft.business.device.assets.service.BusDeviceService;
import org.rcisoft.business.device.assets.vo.DeviceAssetStatisticVo; import org.rcisoft.business.device.assets.vo.DeviceAssetStatisticVo;
import org.rcisoft.business.device.assets.vo.DeviceParamsVo;
import org.rcisoft.core.constant.MessageConstant; import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.controller.PaginationController; import org.rcisoft.core.controller.PaginationController;
import org.rcisoft.core.model.GridModel; import org.rcisoft.core.model.GridModel;
...@@ -37,6 +39,7 @@ import java.util.List; ...@@ -37,6 +39,7 @@ import java.util.List;
/** /**
* Created by on 2018-4-12 15:33:23. * Created by on 2018-4-12 15:33:23.
*/ */
@Api(tags = "项目评估--参数库")
@RestController @RestController
@RequestMapping("busdevice") @RequestMapping("busdevice")
public class BusDeviceController extends PaginationController<BusDevice> { public class BusDeviceController extends PaginationController<BusDevice> {
...@@ -172,6 +175,10 @@ public class BusDeviceController extends PaginationController<BusDevice> { ...@@ -172,6 +175,10 @@ public class BusDeviceController extends PaginationController<BusDevice> {
webDataBinder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); webDataBinder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
} }
@ApiOperation(value="参数库导出", notes="参数库导出功能,需要将页面上的名称、编号以json对象数组的形式传到后台")
@RequestMapping("/downloadExcel")
public void downloadExcel(HttpServletResponse response, @RequestBody List<DeviceParamsVo> list) {
busDeviceServiceImpl.downloadExcel(response, list);
}
} }
...@@ -76,9 +76,23 @@ public interface BusDeviceRepository extends BaseMapper<BusDevice> { ...@@ -76,9 +76,23 @@ public interface BusDeviceRepository extends BaseMapper<BusDevice> {
"group by d.DEV_ID,d.SHUT_POWER,d.RUN_TM</script>") "group by d.DEV_ID,d.SHUT_POWER,d.RUN_TM</script>")
List<Map<String, Object>> addRunTime(@Param("time") String time); List<Map<String, Object>> addRunTime(@Param("time") String time);
/**
* 批量更新设备的运行时长
* @param list
* @return
*/
@Update("<script><foreach collection=\"list\" item=\"item\" separator=\";\">" + @Update("<script><foreach collection=\"list\" item=\"item\" separator=\";\">" +
"update bus_device set RUN_TM=#{item.runTm} where DEV_ID=#{item.devId}" + "update bus_device set RUN_TM=#{item.runTm} where DEV_ID=#{item.devId}" +
"</foreach></script>") "</foreach></script>")
Integer batchUpdateRunTm(List<BusDevice> list); Integer batchUpdateRunTm(List<BusDevice> list);
/**
* 查询该项目下所有设备的故障数量和运行时长
* @param proId
* @return
*/
@Select("<script>select DEV_NM,RUN_TM,ERROR_NUM from bus_device where PRO_ID=#{proId}</script>")
@ResultMap(value = "BaseResultMap")
List<BusDevice> selectErrorandRuntime(@Param("proId") String proId);
} }
...@@ -47,5 +47,7 @@ public class BusDevice implements Serializable{ ...@@ -47,5 +47,7 @@ public class BusDevice implements Serializable{
private BigDecimal runTm; private BigDecimal runTm;
private Integer errorNum;
} }
...@@ -2,9 +2,11 @@ package org.rcisoft.business.device.assets.service; ...@@ -2,9 +2,11 @@ package org.rcisoft.business.device.assets.service;
import org.rcisoft.business.device.assets.entity.BusDevice; import org.rcisoft.business.device.assets.entity.BusDevice;
import org.rcisoft.business.device.assets.vo.DeviceAssetStatisticVo; import org.rcisoft.business.device.assets.vo.DeviceAssetStatisticVo;
import org.rcisoft.business.device.assets.vo.DeviceParamsVo;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.aop.PageUtil; import org.rcisoft.core.aop.PageUtil;
import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -82,4 +84,10 @@ public interface BusDeviceService { ...@@ -82,4 +84,10 @@ public interface BusDeviceService {
* @return * @return
*/ */
Integer addRunTime(); Integer addRunTime();
/**
* 参数库导出
* @param response
*/
void downloadExcel(HttpServletResponse response, List<DeviceParamsVo> list);
} }
package org.rcisoft.business.device.assets.service.impl; package org.rcisoft.business.device.assets.service.impl;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType;
import org.rcisoft.business.device.assets.dao.BusDeviceRepository; import org.rcisoft.business.device.assets.dao.BusDeviceRepository;
import org.rcisoft.business.device.assets.service.BusDeviceService; import org.rcisoft.business.device.assets.service.BusDeviceService;
import org.rcisoft.business.device.assets.vo.DeviceAssetStatisticVo; import org.rcisoft.business.device.assets.vo.DeviceAssetStatisticVo;
import org.rcisoft.business.device.assets.vo.DeviceParamsVo;
import org.rcisoft.business.manage.dao.BusLibraryParamRepository; import org.rcisoft.business.manage.dao.BusLibraryParamRepository;
import org.rcisoft.business.manage.entity.BusDevicetpParam; import org.rcisoft.business.manage.entity.BusDevicetpParam;
import org.rcisoft.business.manage.entity.BusLibraryParam; import org.rcisoft.business.manage.entity.BusLibraryParam;
...@@ -20,13 +25,20 @@ import org.springframework.transaction.annotation.Propagation; ...@@ -20,13 +25,20 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example;
import javax.servlet.http.HttpServletResponse;
/** /**
* Created by on 2018-4-12 15:33:23. * Created by on 2018-4-12 15:33:23.
*/ */
...@@ -214,4 +226,40 @@ public class BusDeviceServiceImpl implements BusDeviceService { ...@@ -214,4 +226,40 @@ public class BusDeviceServiceImpl implements BusDeviceService {
return 0; return 0;
} }
@Override
public void downloadExcel(HttpServletResponse response, List<DeviceParamsVo> list) {
try (OutputStream outputStream = response.getOutputStream()) {
response.setHeader("Content-disposition", "attachment;filename=download.xls");
outputStream.write(this.createExcel(list));
outputStream.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
private byte[] createExcel(List<DeviceParamsVo> list) throws IOException {
HSSFWorkbook workbook = null;
try(ByteArrayOutputStream os = new ByteArrayOutputStream()) {
workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("sheet1");
//表头
String[] title = new String[]{"名称", "编号"};
HSSFRow title_row = sheet.createRow(0);
for (int i = 0; i < title.length; i++) {
title_row.createCell(i, CellType.STRING).setCellValue(title[i]);
}
//内容
for (int i = 0; i < list.size(); i++) {
HSSFRow row = sheet.createRow(i + 1);
DeviceParamsVo deviceParamsVo = list.get(i);
row.createCell(0, CellType.STRING).setCellValue(deviceParamsVo.getName());
row.createCell(1, CellType.STRING).setCellValue(deviceParamsVo.getNum());
}
workbook.write(os);
return os.toByteArray();
} finally {
workbook.close();
}
}
} }
package org.rcisoft.business.device.assets.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Created by JiChao on 2018/5/25.
*/
@NoArgsConstructor
@AllArgsConstructor
@Data
public class DeviceParamsVo {
private String name;
private String num;
}
...@@ -85,6 +85,8 @@ public class AdaptiveServiceImpl implements AdaptiveService { ...@@ -85,6 +85,8 @@ public class AdaptiveServiceImpl implements AdaptiveService {
BigDecimal hswd = (BigDecimal) json.get(code_array[1]); BigDecimal hswd = (BigDecimal) json.get(code_array[1]);
//水流量 //水流量
BigDecimal sll = (BigDecimal) json.get(code_array[2]); BigDecimal sll = (BigDecimal) json.get(code_array[2]);
//如果其中任何一个数据为空,继续下一条
if (gswd == null || hswd == null || sll == null) return;
//公式计算 //公式计算
Float building = Math.abs(gswd.subtract(hswd).multiply(sll).multiply(new BigDecimal(4.12)).divide(new BigDecimal(3.6), 1, BigDecimal.ROUND_HALF_UP).floatValue()); Float building = Math.abs(gswd.subtract(hswd).multiply(sll).multiply(new BigDecimal(4.12)).divide(new BigDecimal(3.6), 1, BigDecimal.ROUND_HALF_UP).floatValue());
buildingList.set(hour, building); buildingList.set(hour, building);
......
package org.rcisoft.business.system.controller; package org.rcisoft.business.system.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.RestController;
* Created by JiChao on 2018/5/2. * Created by JiChao on 2018/5/2.
* 系统模块 * 系统模块
*/ */
@Api(tags = "系统检测")
@RestController @RestController
@RequestMapping("system") @RequestMapping("system")
public class SystemController { public class SystemController {
...@@ -47,4 +49,41 @@ public class SystemController { ...@@ -47,4 +49,41 @@ public class SystemController {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, systemServiceImpl.burdenHour(proId)); return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, systemServiceImpl.burdenHour(proId));
} }
@ApiOperation(value="故障报修 and 运行时长", notes="根据项目id查询所有设备的错误数量和运行时长,10分钟查询一次")
@ApiImplicitParams({
@ApiImplicitParam(name = "proId", value = "项目主键", required = true, dataType = "字符串")
})
@RequestMapping("/selectErrorandRuntime")
public Result selectErrorandRuntime(@RequestParam String proId) {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, systemServiceImpl.selectErrorandRuntime(proId));
}
@ApiOperation(value="查询参数列表", notes="根据设备num查询所有参数")
@ApiImplicitParams({
@ApiImplicitParam(name = "devNum", value = "设备num", required = true, dataType = "字符串")
})
@RequestMapping("/selectDeviceParamList")
public Result selectDeviceParamList(@RequestParam String devNum) {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, systemServiceImpl.selectDeviceParamList(devNum));
}
@ApiOperation(value="查询参数数据", notes="查询缓存中的数据,10秒钟查询1次")
@ApiImplicitParams({
@ApiImplicitParam(name = "proId", value = "项目主键", required = true, dataType = "字符串")
})
@RequestMapping("/selectDataByCache")
public String selectDataByCache(@RequestParam String proId) {
return systemServiceImpl.selectDataByCache(proId);
// return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, systemServiceImpl.selectDataByCache(proId));
}
@ApiOperation(value="查询传感器code", notes="查询传感器code")
@ApiImplicitParams({
@ApiImplicitParam(name = "proId", value = "项目主键", required = true, dataType = "字符串")
})
@RequestMapping("/selectSensorCode")
public Result selectSensorCode(@RequestParam String proId) {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, systemServiceImpl.selectSensorCode(proId));
}
} }
package org.rcisoft.business.system.dao;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.rcisoft.business.system.entity.DeviceParam;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* Created by JiChao on 2018/5/24.
*/
@Repository
public interface DeviceParamRepository {
/**
* 查询参数列表
* @param devNum
* @return
*/
@Select("<script>select d.PARAM,p.PARAM_NM,p.P_SOURCE,p.P_MIN,p.P_MAX,p.SYMBOL,p.FLAG,p.PARAM_UNIT " +
"from bus_device_param d,bus_devicetp_param p " +
"where d.PARAM_CODE=p.PARAM_CODE and d.DEV_NUM=#{devNum}</script>")
@ResultMap("BaseResultMap")
List<DeviceParam> selectDeviceParamList(@Param("devNum") String devNum);
@Select("<script>select OTHER_PARAM from bus_param_refer where PRO_ID=#{proId} and OWN_PARAM='sensor'</script>")
@ResultType(String.class)
String selectSensorCode(@Param("proId") String proId);
}
package org.rcisoft.business.system.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import java.math.BigDecimal;
/**
* Created by JiChao on 2018/5/24.
*/
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DeviceParam {
private String param;
private String paramNm;
private String source;
private BigDecimal min;
private BigDecimal max;
private String symbol;
private String flag;
private String paramUnit;
}
package org.rcisoft.business.system.service; package org.rcisoft.business.system.service;
import org.rcisoft.business.device.assets.entity.BusDevice;
import org.rcisoft.business.system.entity.DeviceParam;
import org.rcisoft.business.system.vo.ClimateStatistics; import org.rcisoft.business.system.vo.ClimateStatistics;
import java.util.List; import java.util.List;
...@@ -30,4 +32,32 @@ public interface SystemService { ...@@ -30,4 +32,32 @@ public interface SystemService {
*/ */
List<Object> burdenHour(String proId); List<Object> burdenHour(String proId);
/**
* 查询该项目下所有设备的故障数量和运行时长
* @param proId
* @return
*/
List<BusDevice> selectErrorandRuntime(String proId);
/**
* 根据devNum查询参数列表
* @param devNum
* @return
*/
List<DeviceParam> selectDeviceParamList(String devNum);
/**
* 查询传感器code
* @param proId
* @return
*/
String selectSensorCode(String proId);
/**
* 查询缓存中的数据,10秒钟查询1次
* @param proId
* @return
*/
String selectDataByCache(String proId);
} }
...@@ -2,6 +2,8 @@ package org.rcisoft.business.system.service.impl; ...@@ -2,6 +2,8 @@ package org.rcisoft.business.system.service.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.rcisoft.business.device.assets.dao.BusDeviceRepository;
import org.rcisoft.business.device.assets.entity.BusDevice;
import org.rcisoft.business.mainte.adaptive.dao.BusParamReferRepository; import org.rcisoft.business.mainte.adaptive.dao.BusParamReferRepository;
import org.rcisoft.business.mainte.adaptive.dao.BusTemperatureRepository; import org.rcisoft.business.mainte.adaptive.dao.BusTemperatureRepository;
import org.rcisoft.business.mainte.adaptive.dao.TotalSensorRepository; import org.rcisoft.business.mainte.adaptive.dao.TotalSensorRepository;
...@@ -15,8 +17,11 @@ import org.rcisoft.business.overview.dao.BusProjectRepository; ...@@ -15,8 +17,11 @@ import org.rcisoft.business.overview.dao.BusProjectRepository;
import org.rcisoft.business.overview.dao.EnergyCountMRepository; import org.rcisoft.business.overview.dao.EnergyCountMRepository;
import org.rcisoft.business.overview.entity.BusProject; import org.rcisoft.business.overview.entity.BusProject;
import org.rcisoft.business.overview.vo.EnergyCountMVo; import org.rcisoft.business.overview.vo.EnergyCountMVo;
import org.rcisoft.business.system.dao.DeviceParamRepository;
import org.rcisoft.business.system.entity.DeviceParam;
import org.rcisoft.business.system.service.SystemService; import org.rcisoft.business.system.service.SystemService;
import org.rcisoft.business.system.vo.ClimateStatistics; import org.rcisoft.business.system.vo.ClimateStatistics;
import org.rcisoft.core.service.RcRedisService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -42,6 +47,12 @@ public class SystemServiceImpl implements SystemService { ...@@ -42,6 +47,12 @@ public class SystemServiceImpl implements SystemService {
private EnergyCountMRepository energyCountMRepository; private EnergyCountMRepository energyCountMRepository;
@Autowired @Autowired
private AdaptiveService adaptiveServiceImpl; private AdaptiveService adaptiveServiceImpl;
@Autowired
private BusDeviceRepository busDeviceRepository;
@Autowired
private DeviceParamRepository deviceParamRepository;
@Autowired
private RcRedisService redisServiceImpl;
private String getCode(String proId) { private String getCode(String proId) {
BusProject b = new BusProject(); BusProject b = new BusProject();
...@@ -119,4 +130,33 @@ public class SystemServiceImpl implements SystemService { ...@@ -119,4 +130,33 @@ public class SystemServiceImpl implements SystemService {
Params params = new Params(proId, time, this.getCode(proId)); Params params = new Params(proId, time, this.getCode(proId));
return adaptiveServiceImpl.buildingList(params); return adaptiveServiceImpl.buildingList(params);
} }
@Override
public List<BusDevice> selectErrorandRuntime(String proId) {
List<BusDevice> list = busDeviceRepository.selectErrorandRuntime(proId);
list.forEach(busDevice -> {
BigDecimal runTm = busDevice.getRunTm();
runTm = runTm == null ? new BigDecimal(0) : runTm;
Integer errorNum = busDevice.getErrorNum();
errorNum = errorNum == null ? 0 : errorNum;
busDevice.setRunTm(runTm);
busDevice.setErrorNum(errorNum);
});
return list;
}
@Override
public List<DeviceParam> selectDeviceParamList(String devNum) {
return deviceParamRepository.selectDeviceParamList(devNum);
}
@Override
public String selectSensorCode(String proId) {
return deviceParamRepository.selectSensorCode(proId);
}
@Override
public String selectDataByCache(String proId) {
return redisServiceImpl.get(proId);
}
} }
package org.rcisoft.core.util;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.font.ImageGraphicAttribute;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import javax.imageio.ImageIO;
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.BufferedImageLuminanceSource;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
public class QRCodeUtils {
/**
* 定义二维码的参数
*/
HashMap hints=new HashMap();
/** 数据字符编码格式 **/
private static String codeFormate="UTF-8";
/** 二维码纠错等级 **/
private static ErrorCorrectionLevel QRCodeErrorLevel=ErrorCorrectionLevel.M;
/** 图片边距 **/
private static int imagePadding=0;
/** 二维码尺寸 **/
private static int QRCODE_SIZE = 400;
/** 输出图片格式 **/
private static String FORMAT_NAME = "JPG";
/** 是否去除外部的边框 **/
private static boolean cleanPadding=false;
private static BufferedImage createQRCodeImage(String dataInfo,Hashtable<EncodeHintType, Object>hints) throws WriterException{
if(hints==null || hints.isEmpty()){
hints = new Hashtable<EncodeHintType, Object>();
hints.put(EncodeHintType.ERROR_CORRECTION, QRCodeErrorLevel);
hints.put(EncodeHintType.CHARACTER_SET, codeFormate);
hints.put(EncodeHintType.MARGIN, imagePadding);
}
BitMatrix bitMatrix = new MultiFormatWriter().encode(dataInfo, BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE, hints);
//此处判断是否需要将图片两边的留白进行处理
BufferedImage resultImage=null;
if(cleanPadding){
//1.1去白边
int[] rec = bitMatrix.getEnclosingRectangle();
int resWidth = rec[2] + 5;
int resHeight = rec[3] + 5;
BitMatrix resMatrix = new BitMatrix(resWidth, resHeight);
resMatrix.clear();
for (int i = 0; i < resWidth; i++) {
for (int j = 0; j < resHeight; j++) {
if (bitMatrix.get(i + rec[0], j + rec[1])) {
resMatrix.set(i, j);
}
}
}
//2
int width = resMatrix.getWidth();
int height = resMatrix.getHeight();
resultImage = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
resultImage.setRGB(x, y, resMatrix.get(x, y) == true ? Color.BLACK.getRGB():Color.WHITE.getRGB());
}
}
}else{
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
resultImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
resultImage.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);
}
}
}
//此处开始将图片输出出来
return resultImage;
}
public static String createQRCodeFile(String dataInfo,String filePath,String fileName) throws WriterException, IOException{
//输出二维码
BufferedImage QRCodeImage = createQRCodeImage(dataInfo,null);
//判断文件路径是否存在
File saveDir=new File(filePath);
if(!saveDir.exists()){
saveDir.mkdirs();
}
String filepathStr=filePath+"/"+fileName+"."+FORMAT_NAME;
//开始写文件啦
ImageIO.write(QRCodeImage, FORMAT_NAME, new File(filepathStr));
return filepathStr;
}
/**
* 批量生成纯二维码
* @param dataList
* @param filePath
* @param fileName
* @return
* @throws WriterException
* @throws IOException
*/
public static String createQRCodeFileList(List<String>dataList,String filePath,List<String> fileNameList) throws WriterException, IOException{
Hashtable<EncodeHintType, Object>hints = new Hashtable<EncodeHintType, Object>();
hints.put(EncodeHintType.ERROR_CORRECTION, QRCodeErrorLevel);
hints.put(EncodeHintType.CHARACTER_SET, codeFormate);
hints.put(EncodeHintType.MARGIN, imagePadding);
//判断文件路径是否存在
File saveDir=new File(filePath);
if(!saveDir.exists()){
saveDir.mkdirs();
}
if(dataList!=null && !dataList.isEmpty() && fileNameList!=null && !dataList.isEmpty()){
if(dataList.size()==fileNameList.size()){
for(int i=0;i<dataList.size();i++){
String dataInfo=dataList.get(i);
//输出二维码
BufferedImage QRCodeImage = createQRCodeImage(dataInfo,hints);
String filepathStr=filePath+"/"+fileNameList.get(i)+"."+FORMAT_NAME;
//开始写文件啦
ImageIO.write(QRCodeImage, FORMAT_NAME, new File(filepathStr));
System.out.println("当前输出第"+(i+1)+"个,共计:"+dataList.size()+"个");
}
return "SUCCESS";
}else{
return "ERROR";
}
}else{
return "ERROR";
}
}
public static String createQRCordAndCompositeImage(String dataInfo,String backgroundFilePath, String filePath,String fileName,int x,int y,int QRCodeSize) throws IOException, WriterException{
//判断文件路径是否存在
File saveDir=new File(filePath);
if(!saveDir.exists()){
saveDir.mkdirs();
}
//读取背景图
BufferedImage backGroundImage = ImageIO.read(new File(backgroundFilePath));
//获取背景图大小
Graphics graphics = backGroundImage.getGraphics();
BufferedImage QRCodeImage = createQRCodeImage(dataInfo,null);
graphics.drawImage(QRCodeImage, x, y,QRCodeSize,QRCodeSize, null);
graphics.dispose();
String filepathStr=filePath+"/"+fileName+"."+FORMAT_NAME;
ImageIO.write(backGroundImage, FORMAT_NAME, new File(filepathStr));
return filepathStr;
}
public static String createQRCodeAndCompImageList(List<String>dataList,String backgroundFilePath,String filePath,List<String> fileNameList,int x,int y,int QRCodeSize) throws IOException, WriterException{
//判断文件路径是否存在
File saveDir=new File(filePath);
if(!saveDir.exists()){
saveDir.mkdirs();
}
//读取背景图
BufferedImage backGroundImage = ImageIO.read(new File(backgroundFilePath));
//获取背景图大小
int height = backGroundImage.getHeight();
int width = backGroundImage.getWidth();
//构建二维码配置信息
Hashtable<EncodeHintType, Object>hints = new Hashtable<EncodeHintType, Object>();
hints.put(EncodeHintType.ERROR_CORRECTION, QRCodeErrorLevel);
hints.put(EncodeHintType.CHARACTER_SET, codeFormate);
hints.put(EncodeHintType.MARGIN, imagePadding);
if(dataList!=null && !dataList.isEmpty() && fileNameList!=null && !dataList.isEmpty()){
if(dataList.size()==fileNameList.size()){
for(int i=0;i<dataList.size();i++){
String dataInfo=dataList.get(i);
//输出二维码
BufferedImage QRCodeImage = createQRCodeImage(dataInfo,hints);
Graphics graphics = backGroundImage.getGraphics();
graphics.drawImage(QRCodeImage, x, y,QRCodeSize,QRCodeSize, null);
graphics.dispose();
String filepathStr=filePath+"/"+fileNameList.get(i)+"."+FORMAT_NAME;
//开始写文件啦
ImageIO.write(backGroundImage, FORMAT_NAME, new File(filepathStr));
System.out.println("当前输出第"+(i+1)+"个,共计:"+dataList.size()+"个");
}
return "SUCCESS";
}else{
return "ERROR";
}
}else{
return "ERROR";
}
}
public static String getCodeFormate() {
return codeFormate;
}
public static void setCodeFormate(String codeFormate) {
QRCodeUtils.codeFormate = codeFormate;
}
public static ErrorCorrectionLevel getQRCodeErrorLevel() {
return QRCodeErrorLevel;
}
public static void setQRCodeErrorLevel(char errorLevel) {
switch (errorLevel) {
case 'H':
QRCodeErrorLevel=ErrorCorrectionLevel.H;
break;
case 'L':
QRCodeErrorLevel=ErrorCorrectionLevel.L;
break;
case 'M':
QRCodeErrorLevel=ErrorCorrectionLevel.M;
break;
case 'Q':
QRCodeErrorLevel=ErrorCorrectionLevel.Q;
break;
}
}
public static int getImagePadding() {
return imagePadding;
}
public static void setImagePadding(int imagePadding) {
QRCodeUtils.imagePadding = imagePadding;
}
public static int getQRCODE_SIZE() {
return QRCODE_SIZE;
}
public static void setQRCODE_SIZE(int qRCODE_SIZE) {
QRCODE_SIZE = qRCODE_SIZE;
}
public static String getFORMAT_NAME() {
return FORMAT_NAME;
}
public static void setFORMAT_NAME(String fORMAT_NAME) {
FORMAT_NAME = fORMAT_NAME;
}
}
...@@ -43,6 +43,7 @@ public class MqttClient { ...@@ -43,6 +43,7 @@ public class MqttClient {
referMap = totalService.queryBusParamRefer(map); referMap = totalService.queryBusParamRefer(map);
devStr = totalService.queryDevByPro(jwnum); devStr = totalService.queryDevByPro(jwnum);
String time = jb.getString("TIME");//时间 String time = jb.getString("TIME");//时间
JSONObject jbody = jb.getJSONObject("body");//数据体
//String time = DateUtil.getSimepleDate("yyyyMMddHHmmss",new Date()); //String time = DateUtil.getSimepleDate("yyyyMMddHHmmss",new Date());
if(DateUtil.getParseDate("yyyyMMddhhmmss",time)!=null){//时间格式正常 if(DateUtil.getParseDate("yyyyMMddhhmmss",time)!=null){//时间格式正常
String minute = time.substring(10,12); String minute = time.substring(10,12);
...@@ -52,13 +53,13 @@ public class MqttClient { ...@@ -52,13 +53,13 @@ public class MqttClient {
* 用作拓扑图点击设备查看实时参数及10秒级的能耗 * 用作拓扑图点击设备查看实时参数及10秒级的能耗
*/ */
if(Integer.parseInt(sec)%10==0){ if(Integer.parseInt(sec)%10==0){
rcRedisService.set(jwnum, jbody.toJSONString());
//rcRedisService.set("old","old"+new Date() + rcRedisService.get("new")); //rcRedisService.set("old","old"+new Date() + rcRedisService.get("new"));
//rcRedisService.set("new","new"+new Date() + content); //rcRedisService.set("new","new"+new Date() + content);
} }
System.out.println("++++++++++++++++++++++++++++++++++"+minute+"-----"+sec); System.out.println("++++++++++++++++++++++++++++++++++"+minute+"-----"+sec);
if(Integer.parseInt(minute)%10==0 && sec.equalsIgnoreCase("00")){//10分钟级的数据,进行存储 if(Integer.parseInt(minute)%10==0 && sec.equalsIgnoreCase("00")){//10分钟级的数据,进行存储
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
JSONObject jbody = jb.getJSONObject("body");//数据体
List<TotalOriginal> originalList = new ArrayList<>(); List<TotalOriginal> originalList = new ArrayList<>();
List<TotalSensor> sensorList = new ArrayList<>(); List<TotalSensor> sensorList = new ArrayList<>();
//遍历数据体内对象 //遍历数据体内对象
......
package org.rcisoft.wechat;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.rcisoft.wechat.service.WxPortalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
/**
* 网页授权微信回调接口
*
* @author David
*/
@Controller
@RequestMapping("/wechat")
public class WechatRedirectController {
@Resource
private WxPortalService service;
@Autowired
private WxMpService wxService;
@RequestMapping(value = {"/index"})
public String index(String code) {
try {
WxMpUser wxUser = this.service.oauth2UserInfo(code);
System.out.println("微信返回的code: " + code);
System.out.println("WxPortalController授权完毕后获取到的OpenId是:" + wxUser.getOpenId());
return "redirect:http://weega.cn.tunnel.qydev.com/login.html?openId=" + wxUser.getOpenId();
} catch (Exception exception) {
exception.printStackTrace();
return "redirect:http://weega.cn.tunnel.qydev.com/error.html";
}
}
@RequestMapping(value = {"/getConfig"})
@ResponseBody
public Map<String, Object> getConfig(String url) {
try {
WxJsapiSignature wxJsapiSignature = service.getJsApiTicket(url);
Map<String, Object> map = new HashMap<>(4);
map.put("timestamp", wxJsapiSignature.getTimestamp());
map.put("nonceStr", wxJsapiSignature.getNonceStr());
map.put("signature", wxJsapiSignature.getSignature());
map.put("appId", wxJsapiSignature.getAppId());
return map;
} catch (WxErrorException e) {
e.printStackTrace();
}
return null;
}
}
package org.rcisoft.wechat.service;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 获取微信用户信息
* @author david
*/
@Service
public class WxPortalService extends WxMpServiceImpl {
@Value("${wechat.mp.appId}")
String appId;
@Value("${wechat.mp.secret}")
String secret;
@Value("${wechat.mp.token}")
String token;
@Value("${wechat.mp.aesKey}")
String aesKey;
private final Logger logger = LoggerFactory.getLogger(this.getClass());
public WxPortalService() {
}
@PostConstruct
public void init() {
WxMpInMemoryConfigStorage config = new WxMpInMemoryConfigStorage();
config.setAppId(appId);
config.setSecret(secret);
config.setToken(token);
config.setAesKey(aesKey);
super.setWxMpConfigStorage(config);
}
public WxMpOAuth2AccessToken oauth2AccessToken(String code) throws WxErrorException {
WxMpOAuth2AccessToken token = this.oauth2getAccessToken(code);
System.out.println("token:" + token.getAccessToken() + "; code: " + code);
return token;
}
public WxMpUser oauth2UserInfo(String code) throws WxErrorException {
WxMpOAuth2AccessToken token = this.oauth2AccessToken(code);
return token != null?this.oauth2getUserInfo(token, (String)null):null;
}
public WxJsapiSignature getJsApiTicket(String url) throws WxErrorException {
return this.createJsapiSignature(url);
}
}
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
<result column="PRO_ID" jdbcType="VARCHAR" property="proId"/> <result column="PRO_ID" jdbcType="VARCHAR" property="proId"/>
<result column="SYS_ID" jdbcType="VARCHAR" property="sysId"/> <result column="SYS_ID" jdbcType="VARCHAR" property="sysId"/>
<result column="OWN_ID" jdbcType="VARCHAR" property="ownId"/> <result column="OWN_ID" jdbcType="VARCHAR" property="ownId"/>
<result column="SHUT_POWER" jdbcType="DECIMAL" property="shutPower"/>
<result column="RUN_TM" jdbcType="DECIMAL" property="runTm"/>
<result column="ERROR_NUM" jdbcType="INTEGER" property="errorNum"/>
</resultMap> </resultMap>
<resultMap id="DeviceAssetStatistics" type="org.rcisoft.business.device.assets.vo.DeviceAssetStatisticVo"> <resultMap id="DeviceAssetStatistics" type="org.rcisoft.business.device.assets.vo.DeviceAssetStatisticVo">
<result column="DEV_NM" jdbcType="VARCHAR" property="devNm"></result> <result column="DEV_NM" jdbcType="VARCHAR" property="devNm"></result>
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.rcisoft.business.system.dao.DeviceParamRepository">
<resultMap id="BaseResultMap" type="org.rcisoft.business.system.entity.DeviceParam">
<result column="PARAM" jdbcType="VARCHAR" property="param"/>
<result column="DEV_NUM" jdbcType="VARCHAR" property="paramNm"/>
<result column="P_SOURCE" jdbcType="VARCHAR" property="source"/>
<result column="P_MIN" jdbcType="DECIMAL" property="min"/>
<result column="P_MAX" jdbcType="DECIMAL" property="max"/>
<result column="SYMBOL" jdbcType="VARCHAR" property="symbol"/>
<result column="FLAG" jdbcType="VARCHAR" property="flag"/>
<result column="PARAM_UNIT" jdbcType="VARCHAR" property="paramUnit"/>
</resultMap>
</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