TCP 服务端 数据解码
This commit is contained in:
parent
e13552b692
commit
7eb9dfb23f
|
|
@ -86,7 +86,7 @@ public class IndexController {
|
|||
@PostMapping("getDeviceInfo")
|
||||
@DecryptAndVerify(decryptedClass = ParamsDto.class)
|
||||
public ServerResponse getDeviceInfo(EncryptedReq<ParamsDto> dto) {
|
||||
return service.getDeviceInfo(dto.getData());
|
||||
return service.getDeviceInfo(dto.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ public class DevVO {
|
|||
|
||||
private String devStatus;
|
||||
|
||||
private String warnInfo;
|
||||
|
||||
private String devAtime;
|
||||
|
||||
private String devBtime;
|
||||
|
|
|
|||
|
|
@ -80,6 +80,10 @@ public class DeviceInfoVo {
|
|||
*/
|
||||
private String onlineTime;
|
||||
|
||||
private String stateTime;
|
||||
|
||||
private String warnInfo;
|
||||
|
||||
/**
|
||||
* 查询条件限制
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import com.bonus.aqd.manager.common.util.DateTimeHelper;
|
|||
import com.bonus.aqd.manager.webResult.HttpStatus;
|
||||
import com.bonus.aqd.manager.webResult.ServerResponse;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.sun.javafx.collections.ListListenerHelper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
@ -19,7 +20,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -44,13 +48,75 @@ public class IndexServiceImpl implements IndexService {
|
|||
public ServerResponse getDevicesInfo(ParamsDto dto) {
|
||||
List<DeviceInfoVo> list = new ArrayList<>();
|
||||
try {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
|
||||
list = mapper.getDevicesInfo(dto);
|
||||
if(CollectionUtils.isNotEmpty(list)){
|
||||
list.forEach(vo->{
|
||||
try {
|
||||
if("1".equals(vo.getDevStatus())){
|
||||
Date date = sdf.parse("2024-07-31 09:20:30");
|
||||
String time =getDatePoor(date);
|
||||
vo.setOnlineTime(time);
|
||||
}else{
|
||||
vo.setOnlineTime("00:00:00");
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
return ServerResponse.createSuccess(list);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws ParseException {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date date = sdf.parse("2024-07-31 09:20:30");
|
||||
Date date2=new Date();
|
||||
String time =getDatePoor(date);
|
||||
System.err.println(time);
|
||||
}
|
||||
public static String getDatePoor( Date nowDate) {
|
||||
Date endDate=new Date();
|
||||
long nd = 1000 * 24 * 60 * 60;
|
||||
long nh = 1000 * 60 * 60;
|
||||
long nm = 1000 * 60;
|
||||
long ns = 1000;
|
||||
// 获得两个时间的毫秒时间差异
|
||||
long diff = endDate.getTime() - nowDate.getTime();
|
||||
// 计算差多少天
|
||||
long day = diff / nd;
|
||||
// 计算差多少小时
|
||||
long hour = diff % nd / nh;
|
||||
// 计算差多少分钟
|
||||
long min = diff % nd % nh / nm;
|
||||
// 计算差多少秒//输出结果
|
||||
long sec = diff % nd % nh % nm / ns;
|
||||
StringBuffer sb=new StringBuffer("");
|
||||
if(hour<10){
|
||||
sb.append("0");
|
||||
}
|
||||
sb.append(hour);
|
||||
sb.append(":" );
|
||||
if(min<10){
|
||||
sb.append("0");
|
||||
}
|
||||
sb.append(min);
|
||||
sb.append(":" );
|
||||
|
||||
if(sec<10){
|
||||
sb.append("0");
|
||||
}
|
||||
sb.append(sec);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ServerResponse addDevice(DeviceInfoVo vo) {
|
||||
|
|
@ -98,6 +164,15 @@ public class IndexServiceImpl implements IndexService {
|
|||
DeviceInfoVo vo = new DeviceInfoVo();
|
||||
try {
|
||||
vo = mapper.getDeviceInfo(dto);
|
||||
if(StringUtils.isNotBlank(vo.getWarnInfo())){
|
||||
if("1".equals(vo.getWarnInfo())){
|
||||
vo.setWarnInfo("A钩脱落");
|
||||
}else if("2".equals(vo.getWarnInfo())){
|
||||
vo.setWarnInfo("B钩脱落");
|
||||
}else if("3".equals(vo.getWarnInfo())){
|
||||
vo.setWarnInfo("双钩脱落");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,164 @@
|
|||
package com.bonus.aqd.tcpservice;
|
||||
|
||||
import com.bonus.aqd.base.dao.DevDataMapper;
|
||||
import com.bonus.aqd.base.dao.IndexMapper;
|
||||
import com.bonus.aqd.base.entity.DevVO;
|
||||
import com.bonus.aqd.base.entity.dto.ParamsDto;
|
||||
import com.bonus.aqd.base.entity.vo.DeviceInfoVo;
|
||||
import com.bonus.aqd.manager.common.util.DateTimeHelper;
|
||||
import com.bonus.aqd.manager.common.util.StringHelper;
|
||||
import com.bonus.aqd.manager.core.dao.SysUserDao;
|
||||
import com.bonus.aqd.manager.core.entity.SysUserEntity;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 数据存储业务层
|
||||
* @author 黑子
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SaveDataService {
|
||||
|
||||
private final static String head="55aa";
|
||||
|
||||
@Autowired
|
||||
private DevDataMapper mapper;
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param msg
|
||||
*/
|
||||
@Async
|
||||
public void addDataInfo(String msg){
|
||||
try{
|
||||
String[] msgs=msg.split(head);
|
||||
List<String> list= Arrays.asList(msgs);
|
||||
list.forEach(str->{
|
||||
if(StringHelper.isNotEmpty(str)){
|
||||
insertData(str);
|
||||
}
|
||||
});
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Async
|
||||
public void updateDataStatus(String msg,String channId){
|
||||
try{
|
||||
String[] msgs=msg.split(head);
|
||||
List<String> list= Arrays.asList(msgs);
|
||||
list.forEach(str->{
|
||||
if(StringHelper.isNotEmpty(str)){
|
||||
updateDataStatus2(str,channId);
|
||||
}
|
||||
System.err.println(str);
|
||||
});
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新状态
|
||||
* @param chinnId
|
||||
*/
|
||||
@Async
|
||||
public void downDevStatus(String chinnId){
|
||||
try {
|
||||
DevVO VO = new DevVO();
|
||||
VO.setChannId(chinnId);
|
||||
mapper.downDevStatus(VO);
|
||||
}catch (Exception e){
|
||||
log.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新状态
|
||||
* @param msg
|
||||
*/
|
||||
@Async
|
||||
public void updateDataStatus2(String msg,String chinnId){
|
||||
try {
|
||||
Integer decimal = Integer.parseInt(msg.substring(0, 8), 16);
|
||||
String devCode = decimal.toString();
|
||||
DevVO VO = new DevVO();
|
||||
VO.setDevCode(devCode);
|
||||
VO.setChannId(chinnId);
|
||||
VO.setDevStatus("1");
|
||||
mapper.updateDevStatus(VO);
|
||||
}catch (Exception e){
|
||||
log.error(e.toString());
|
||||
}
|
||||
}
|
||||
@Async
|
||||
public void insertData(String msg){
|
||||
try {
|
||||
Integer decimal = Integer.parseInt(msg.substring(0, 8), 16);
|
||||
String devCode = decimal.toString();
|
||||
//传输类型
|
||||
Integer type = Integer.parseInt(msg.substring(8, 10), 16);
|
||||
//传输类型
|
||||
// Integer direction = Integer.parseInt(msg.substring(10, 12), 16);
|
||||
Integer warn = Integer.parseInt(msg.substring(12, 14), 16);
|
||||
DevVO VO = new DevVO();
|
||||
VO.setDevCode(devCode);
|
||||
VO.setWarnInfo(warn.toString());
|
||||
if (type == 16) {
|
||||
VO.setDevA("1");
|
||||
VO.setDevB("1");
|
||||
mapper.updateData(VO);
|
||||
} else if (type == 17) {
|
||||
String time=DateTimeHelper.getNowTime();
|
||||
if (warn == 0) {
|
||||
VO.setDevA("1");
|
||||
VO.setDevB("1");
|
||||
} else if (warn == 1) {
|
||||
VO.setDevA("0");
|
||||
VO.setDevB("1");
|
||||
VO.setDevAtime(time);
|
||||
} else if (warn == 2) {
|
||||
VO.setDevA("1");
|
||||
VO.setDevB("0");
|
||||
VO.setDevBtime(time);
|
||||
} else if (warn == 3) {
|
||||
VO.setDevA("0");
|
||||
VO.setDevB("0");
|
||||
VO.setDevAtime(time);
|
||||
VO.setDevBtime(time);
|
||||
}
|
||||
mapper.updateData(VO);
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String msg1="78 86 5C CD 10 01 00 00 00 00 00 0D";
|
||||
String msg="78865CCD100100000000000D";
|
||||
int decimal = Integer.parseInt(msg.substring(0,8), 16);
|
||||
String msg11=msg.substring(2,4);
|
||||
String msg2=msg.substring(8,10);
|
||||
String msg3=msg.substring(10,12);
|
||||
String msg4=msg.substring(12,14);
|
||||
System.err.println(msg11);
|
||||
System.err.println(msg2);
|
||||
System.err.println(msg3);
|
||||
System.err.println(msg4);
|
||||
int decimal3= Integer.parseInt(msg.substring(8,10), 16);
|
||||
System.err.println(decimal3);
|
||||
System.err.println(decimal);
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@
|
|||
<if test="devBtime!=null and devBtime!=''">
|
||||
, dev_b_time= #{devBtime}
|
||||
</if>
|
||||
, warn_info=#{warnInfo}
|
||||
,dev_time=now()
|
||||
where dev_code=#{devCode}
|
||||
</update>
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@
|
|||
dev_b_time AS devBTime,
|
||||
dev_status AS devStatus,
|
||||
puid,
|
||||
dev_time AS devTime
|
||||
dev_time AS devTime,
|
||||
state_time stateTime
|
||||
FROM tb_device
|
||||
WHERE del_flag = 0
|
||||
ORDER BY id DESC
|
||||
|
|
@ -71,7 +72,8 @@
|
|||
dev_name AS devName,
|
||||
dev_code AS devCode,
|
||||
dev_modu AS devModu,
|
||||
puid
|
||||
puid,
|
||||
warn_info
|
||||
FROM tb_device WHERE id = #{id}
|
||||
</select>
|
||||
<!--查询设备状态数量-->
|
||||
|
|
|
|||
Loading…
Reference in New Issue