中央热水项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
7.2 KiB

package com.mh.user.controller;
import com.mh.common.utils.DateTimeUtils;
import com.mh.user.constants.Constant;
import com.mh.user.dynamic.datasource.DataSourceContextHolder;
import com.mh.user.dynamic.datasource.DataSourceObject;
import com.mh.user.entity.DBEntity;
import com.mh.user.manage.QuartzManager;
import com.mh.user.mapper.NowDataMapper;
import com.mh.user.serialport.SerialTool;
import com.mh.user.service.NowDataService;
import com.mh.user.service.SysUserService;
import com.mh.user.utils.*;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import purejavacomm.CommPort;
import purejavacomm.CommPortIdentifier;
import purejavacomm.PortInUseException;
import javax.annotation.Resource;
@RestController
public class TestController {
@Autowired
private SysUserService sysUserService;
@Autowired
NowDataService nowDataService;
@Resource
QuartzManager quartzManager;
@RequestMapping("/hello")
public String HelloWord() throws SchedulerException, InterruptedException {
// 停止JobTest
quartzManager.pauseAllJob();
Constant.FLAG = true;
Thread.sleep(2000);
// 开始JobTest
// quartzManager.resumeAllJob();
Constant.FLAG = false;
return "user hello word.";
}
@RequestMapping("/startHello")
public String startHelloWord() throws SchedulerException, InterruptedException {
// 停止JobTest
// quartzManager.pauseAllJob();
// Constant.FLAG = true;
// Thread.sleep(2000);
// 开始JobTest
// quartzManager.resumeAllJob();
// Thread.sleep(2000);
// Constant.FLAG = false;
return "user hello word.";
}
@GetMapping("/testQuery")
public void testQuery(){
// try{
// DBEntity dbEntity = sysUserService.queryDBInfo("admin");
// dbEntity.setDB_Pwd(AESUtil.AESdecrypt(dbEntity.getDB_Pwd()));
// DataSourceObject dataSourceObject = new DataSourceObject();
// String SourceName = "sqlServer-"+dbEntity.getDB_Names();
// dataSourceObject.SwitchSQLServerDataSource(dbEntity,SourceName);
// DataSourceContextHolder.setDBType(SourceName);
// }catch (Exception e){
// e.printStackTrace();
// }
AnalysisReceiveOrder485 analysis=new AnalysisReceiveOrder485();
GetReadOrder485 getReadOrder485=new GetReadOrder485();
// analysis.analysisWtMeterOrder485("5103040003141D953F","","","48");
//analysis.analysisPumpOrder485("05030200004984","0BBD","美的2","80");
// analysis.analysisMeterOrder485("6824095005000068810643C36B7A67335E16","","","63");
// analysis.analysisRelayOrder485("12031000000001000000000000000000000000665F","0010","远向","34");
// analysis.analysisMulTempOrder4852("010310013601290192018F0180F800F800F800AC21","","","1");
// analysis.analysisPressureOrder485("150304400F1ABE00E1","","","22");
// analysis.analysisStateOrder485("6874100000000068810358F3395C16","","","41");
// analysis.analysisTempOrder485("020304013000010900","","","23");
nowDataService.saveNowHistoryData("3","热泵","运行","runState","62");
// nowDataService.updateRunState("70","2","离线");
}
@GetMapping
public String testCollection(String type) throws Exception {
purejavacomm.SerialPort serialPort1 = null;
System.out.println("开始时间==>" + DateTimeUtils.getDateTime());
String returnStr = "未采集到数据";
Constant.WEB_FLAG = true;
try {
if ("0".equals(type)) {
// 采集水表
// 采集水表
try {
serialPort1 = SerialTool.openPort("COM12",
2400,
purejavacomm.SerialPort.DATABITS_8,
purejavacomm.SerialPort.STOPBITS_1,
purejavacomm.SerialPort.PARITY_NONE);
} catch (PortInUseException e) {
System.out.println("进入异常==>");
if (null != serialPort1) {
serialPort1.close();
}
serialPort1 = SerialTool.openPort("COM12",
2400,
purejavacomm.SerialPort.DATABITS_8,
purejavacomm.SerialPort.STOPBITS_1,
purejavacomm.SerialPort.PARITY_NONE);
}
//从串口读取数据 SerialTool.sendToPort(SerialTool.HexString2Bytes(sendStr), serialPort, sendStr, deviceType);
String sendStr = "FE FE FE 68 10 39 87 10 81 00 00 00 01 03 90 1F 00 7C 16".replace(" ","");
SerialTool.sendToPort(SerialTool.HexString2Bytes(sendStr), serialPort1, sendStr, "水表");
Thread.sleep(888);
byte[] bytes = SerialTool.readFromPort(serialPort1);
assert bytes != null;
returnStr = ExchangeStringUtil.parseByte2HexStr(bytes);
System.out.println("控制读取回来的水表报文==>" + returnStr);
serialPort1.close();
}
if ("1".equals(type)) {
// 采集电表
// 采集电表
try {
serialPort1 = SerialTool.openPort("COM12",
1200,
purejavacomm.SerialPort.DATABITS_8,
purejavacomm.SerialPort.STOPBITS_1,
purejavacomm.SerialPort.PARITY_EVEN);
} catch (Exception e) {
System.out.println("进入异常==>");
if (null != serialPort1) {
serialPort1.close();
}
serialPort1 = SerialTool.openPort("COM12",
1200,
purejavacomm.SerialPort.DATABITS_8,
purejavacomm.SerialPort.STOPBITS_1,
purejavacomm.SerialPort.PARITY_EVEN);
}
//从串口读取数据 SerialTool.sendToPort(SerialTool.HexString2Bytes(sendStr), serialPort, sendStr, deviceType);
String sendStr = "FE FE FE 68 69 04 00 70 01 08 68 01 02 43 C3 BF 16".replace(" ","");
SerialTool.sendToPort(SerialTool.HexString2Bytes(sendStr), serialPort1, sendStr, "电表");
Thread.sleep(888);
byte[] bytes = SerialTool.readFromPort(serialPort1);
assert bytes != null;
returnStr = ExchangeStringUtil.parseByte2HexStr(bytes);
System.out.println("控制读取回来的电表报文==>" + returnStr);
serialPort1.close();
}
} finally {
Constant.WEB_FLAG = false;
}
System.out.println("结束时间==>" + DateTimeUtils.getDateTime());
return returnStr;
}
}