添加塔吊螺母信息bug修改
This commit is contained in:
parent
b4fe3478b7
commit
3f3bf3e5a4
@ -172,111 +172,9 @@ public class TowerNutController {
|
||||
|
||||
@ApiOperation(value = " 添加塔吊螺母信息", notes = "添加塔吊螺母信息", httpMethod = "POST")
|
||||
@PostMapping(value = "/saveNutData")
|
||||
public void saveNutData(HttpServletRequest request) {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
|
||||
reader = request.getReader();
|
||||
char[] buf = new char[512];
|
||||
int len = 0;
|
||||
StringBuffer contentBuffer = new StringBuffer();
|
||||
while ((len = reader.read(buf)) != -1) {
|
||||
contentBuffer.append(buf, 0, len);
|
||||
}
|
||||
String content = contentBuffer.toString();
|
||||
log.info("--------塔吊螺母接收数据------:" + content);
|
||||
JSONObject json = JSONObject.parseObject(content);
|
||||
//螺母主机ID
|
||||
String nutHostId = json.getString("sn");
|
||||
JSONArray jsonArray = json.getJSONArray("values");
|
||||
List<NutValue> list = jsonArray.toJavaList(NutValue.class);
|
||||
if (list != null && list.size() > 0) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
int nutNum = 0;
|
||||
int offLineNum = 0;
|
||||
int alarmNum = 0;
|
||||
Map<Integer, NutObj> data = new LinkedHashMap<>();
|
||||
for (NutValue value : list) {
|
||||
//质量码 0:未初始化值 1:有效值 2:无效值 3:设值值 4:计算值
|
||||
//去除无效数值
|
||||
if (value.getQds() == 0 || value.getQds() == 2) {
|
||||
continue;
|
||||
}
|
||||
//值类型 0:浮点 1:整形
|
||||
//去除无法识别的值类型
|
||||
if (value.getVt() != 0 && value.getVt() != 1) {
|
||||
continue;
|
||||
}
|
||||
int paramValue = value.getPara();
|
||||
if (paramValue == 1) {
|
||||
nutNum = value.getValue();
|
||||
} else if (paramValue == 2) {
|
||||
offLineNum = value.getValue();
|
||||
} else if (paramValue == 3) {
|
||||
alarmNum = value.getValue();
|
||||
} else {
|
||||
int nutNo = calculateNut(paramValue);
|
||||
NutObj nutObj = data.get(nutNo);
|
||||
if (nutObj == null) {
|
||||
nutObj = new NutObj();
|
||||
}
|
||||
nutObj.setNutNo(nutNo);
|
||||
int temp = paramValue - 100;
|
||||
int remainder = temp % 3;
|
||||
if (value.getVt() == 1) {
|
||||
if (remainder == 0) {
|
||||
nutObj.setAlarm(value.getValue());
|
||||
nutObj.setAlarmTime(sdf.format(new Date(value.getTime())));
|
||||
} else if (remainder == 1) {
|
||||
nutObj.setOnLine(value.getValue());
|
||||
} else if (remainder == 2) {
|
||||
nutObj.setOffLine(value.getValue());
|
||||
nutObj.setOffLineTime(sdf.format(new Date(value.getTime())));
|
||||
}
|
||||
}
|
||||
data.put(nutNo, nutObj);
|
||||
}
|
||||
}
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("nutNum", nutNum);
|
||||
jsonObject.put("offLineNum", offLineNum);
|
||||
jsonObject.put("alarmNum", alarmNum);
|
||||
jsonObject.put("list", data.values());
|
||||
//数据库存储
|
||||
TowerNut smVbean = new TowerNut();
|
||||
smVbean.setNutHostId(nutHostId);
|
||||
smVbean.setBeforeAnalysisData(content);
|
||||
smVbean.setAfterAnalysisData(jsonObject.toString());
|
||||
smVbean.setUpdateTime(new Date());
|
||||
towerNutService.saveNutData(smVbean, data, nutNum, offLineNum, alarmNum);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public static int calculateNut(int paramValue) {
|
||||
int temp = paramValue - 100;
|
||||
int trunc = temp / 3;
|
||||
int remainder = temp % 3;
|
||||
if (remainder == 0) {
|
||||
return trunc;
|
||||
} else {
|
||||
return trunc + 1;
|
||||
public Result saveNutData(HttpServletRequest request) {
|
||||
towerNutService.saveNutData(request);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
long mid = 868089057238341L;
|
||||
long nutHostId = (mid) >> 32;
|
||||
log.info("" + nutHostId);
|
||||
int paramValue = (int) mid & 0xFFFFFFFF;
|
||||
log.info("" + paramValue);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import com.zhgd.jeecg.common.mybatis.EntityMap;
|
||||
import com.zhgd.xmgl.base.NutObj;
|
||||
import com.zhgd.xmgl.modules.bigdevice.entity.TowerNut;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -22,4 +23,6 @@ public interface ITowerNutService extends IService<TowerNut> {
|
||||
TowerNut selectTowerNutByNutHostId(String nutHostId);
|
||||
|
||||
List<EntityMap> selectTowerNutList(Map<String, Object> map);
|
||||
|
||||
void saveNutData(HttpServletRequest request);
|
||||
}
|
||||
|
||||
@ -3,16 +3,29 @@ package com.zhgd.xmgl.modules.bigdevice.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zhgd.jeecg.common.execption.OpenAlertException;
|
||||
import com.zhgd.jeecg.common.mybatis.EntityMap;
|
||||
import com.zhgd.xmgl.base.NutObj;
|
||||
import com.zhgd.xmgl.base.NutValue;
|
||||
import com.zhgd.xmgl.modules.bigdevice.entity.Tower;
|
||||
import com.zhgd.xmgl.modules.bigdevice.entity.TowerNut;
|
||||
import com.zhgd.xmgl.modules.bigdevice.mapper.TowerMapper;
|
||||
import com.zhgd.xmgl.modules.bigdevice.mapper.TowerNutMapper;
|
||||
import com.zhgd.xmgl.modules.bigdevice.service.ITowerNutService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -24,8 +37,11 @@ import java.util.Map;
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class TowerNutServiceImpl extends ServiceImpl<TowerNutMapper, TowerNut> implements ITowerNutService {
|
||||
@Autowired
|
||||
private TowerMapper towerMapper;
|
||||
@Autowired
|
||||
private TowerNutMapper towerNutMapper;
|
||||
|
||||
@ -94,4 +110,113 @@ public class TowerNutServiceImpl extends ServiceImpl<TowerNutMapper, TowerNut> i
|
||||
return towerNutMapper.selectTowerNutList(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveNutData(HttpServletRequest request) {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = request.getReader();
|
||||
char[] buf = new char[512];
|
||||
int len = 0;
|
||||
StringBuffer contentBuffer = new StringBuffer();
|
||||
while ((len = reader.read(buf)) != -1) {
|
||||
contentBuffer.append(buf, 0, len);
|
||||
}
|
||||
String content = contentBuffer.toString();
|
||||
log.info("--------塔吊螺母接收数据------:" + content);
|
||||
JSONObject json = JSONObject.parseObject(content);
|
||||
//螺母主机ID
|
||||
String nutHostId = json.getString("sn");
|
||||
Tower tower = towerMapper.selectOne(new LambdaQueryWrapper<Tower>().eq(Tower::getNutHostId, nutHostId));
|
||||
if (StringUtils.isBlank(nutHostId) || tower == null) {
|
||||
throw new OpenAlertException("螺母主机编号不存在");
|
||||
}
|
||||
JSONArray jsonArray = json.getJSONArray("values");
|
||||
List<NutValue> list = jsonArray.toJavaList(NutValue.class);
|
||||
if (list != null && list.size() > 0) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
int nutNum = 0;
|
||||
int offLineNum = 0;
|
||||
int alarmNum = 0;
|
||||
Map<Integer, NutObj> data = new LinkedHashMap<>();
|
||||
for (NutValue value : list) {
|
||||
//质量码 0:未初始化值 1:有效值 2:无效值 3:设值值 4:计算值
|
||||
//去除无效数值
|
||||
if (value.getQds() == 0 || value.getQds() == 2) {
|
||||
continue;
|
||||
}
|
||||
//值类型 0:浮点 1:整形
|
||||
//去除无法识别的值类型
|
||||
if (value.getVt() != 0 && value.getVt() != 1) {
|
||||
continue;
|
||||
}
|
||||
int paramValue = value.getPara();
|
||||
if (paramValue == 1) {
|
||||
nutNum = value.getValue();
|
||||
} else if (paramValue == 2) {
|
||||
offLineNum = value.getValue();
|
||||
} else if (paramValue == 3) {
|
||||
alarmNum = value.getValue();
|
||||
} else {
|
||||
int nutNo = calculateNut(paramValue);
|
||||
NutObj nutObj = data.get(nutNo);
|
||||
if (nutObj == null) {
|
||||
nutObj = new NutObj();
|
||||
}
|
||||
nutObj.setNutNo(nutNo);
|
||||
int temp = paramValue - 100;
|
||||
int remainder = temp % 3;
|
||||
if (value.getVt() == 1) {
|
||||
if (remainder == 0) {
|
||||
nutObj.setAlarm(value.getValue());
|
||||
nutObj.setAlarmTime(sdf.format(new Date(value.getTime())));
|
||||
} else if (remainder == 1) {
|
||||
nutObj.setOnLine(value.getValue());
|
||||
} else if (remainder == 2) {
|
||||
nutObj.setOffLine(value.getValue());
|
||||
nutObj.setOffLineTime(sdf.format(new Date(value.getTime())));
|
||||
}
|
||||
}
|
||||
data.put(nutNo, nutObj);
|
||||
}
|
||||
}
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("nutNum", nutNum);
|
||||
jsonObject.put("offLineNum", offLineNum);
|
||||
jsonObject.put("alarmNum", alarmNum);
|
||||
jsonObject.put("list", data.values());
|
||||
//数据库存储
|
||||
TowerNut smVbean = new TowerNut();
|
||||
smVbean.setNutHostId(nutHostId);
|
||||
smVbean.setBeforeAnalysisData(content);
|
||||
smVbean.setAfterAnalysisData(jsonObject.toString());
|
||||
smVbean.setUpdateTime(new Date());
|
||||
saveNutData(smVbean, data, nutNum, offLineNum, alarmNum);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static int calculateNut(int paramValue) {
|
||||
int temp = paramValue - 100;
|
||||
int trunc = temp / 3;
|
||||
int remainder = temp % 3;
|
||||
if (remainder == 0) {
|
||||
return trunc;
|
||||
} else {
|
||||
return trunc + 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
long mid = 868089057238341L;
|
||||
long nutHostId = (mid) >> 32;
|
||||
log.info("" + nutHostId);
|
||||
int paramValue = (int) mid & 0xFFFFFFFF;
|
||||
log.info("" + paramValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user