消息日志打印修改

This commit is contained in:
蒾酒 2025-01-07 12:00:44 +08:00
parent c9c9c4f678
commit 2d903fe653
2 changed files with 58 additions and 49 deletions

View File

@ -265,17 +265,36 @@ public class DeviceOtherMsgConsumer {
UserRechargeCards cardInfo=userRechargeCardsMapper.selectUserRechargeCardsByCardNumberAndAreaCode(cardNumber,areaCode);
//根据卡号查询用户所属机构
List<UserRechargeCards> cardList = new LambdaQueryChainWrapper<>(userRechargeCardsMapper)
.select(UserRechargeCards::getUserId,UserRechargeCards::getDeptId)
.select(UserRechargeCards::getUserId,UserRechargeCards::getDeptId,UserRechargeCards::getUserName)
.eq(UserRechargeCards::getCardNumber, cardNumber)
// .ne(UserRechargeCards::getDeptId, null)
.list();
Long deptId= null;//获取deptId
// Long deptId= null;//获取deptId
if(!cardList.isEmpty()){
deptId= cardList.get(0).getDeptId();
// if(cardList.get(0).getDeptId()!=null){
// deptId= cardList.get(0).getDeptId();
// }
//添加一条刷卡记录
NgCardSwipeRecords ngCardSwipeRecords=new NgCardSwipeRecords();
ngCardSwipeRecords.setCardNumber(cardNumber);//卡号
ngCardSwipeRecords.setDeviceNumber(serialNumber);//设备编码
ngCardSwipeRecords.setAreaCode(areaCode);//区域号
ngCardSwipeRecords.setCardSwipeType(0);//开阀
ngCardSwipeRecords.setCardSwipeTime(DateUtils.getNowDate());//刷卡时间
if(cardInfo!=null && cardInfo.getUserId()!=null){
ngCardSwipeRecords.setUserId(cardList.get(0).getUserId());//用户id
}
if(cardInfo!=null && cardInfo.getUserName()!=null){
ngCardSwipeRecords.setUserName(cardList.get(0).getUserName());//用户名称
}
int flag1=ngCardSwipeRecordsMapper.insertNgCardSwipeRecords(ngCardSwipeRecords);
if(flag1<1)
{
log.error("设备{}开阀刷卡记录添加失败",serialNumber);
}
}
userIrrigationRecord.setDeptId(deptId);
// userIrrigationRecord.setDeptId(deptId);
DateTime currentTime=DateTime.now();//获取当前时间作为开阀时间
userIrrigationRecord.setStartTime(currentTime);//开阀时间
@ -286,38 +305,15 @@ public class DeviceOtherMsgConsumer {
userIrrigationRecord.setOpenCumFlow(openCumFlow);//用户开阀时使用水量
System.err.println("openCumFlow"+openCumFlow);
userIrrigationRecord.setStatus(1);//状态改为灌溉中
System.out.println(userIrrigationRecord);
userIrrigationRecord.setCreateTime(DateUtils.getNowDate());
int flag=userIrrigationRecordMapper.insertUserIrrigationRecord(userIrrigationRecord);//开阀时添加一条灌溉记录
if(flag<1)
{
log.error("设备{}灌溉记录添加失败",serialNumber);
}
//添加一条刷卡记录
NgCardSwipeRecords ngCardSwipeRecords=new NgCardSwipeRecords();
ngCardSwipeRecords.setCardNumber(cardNumber);//卡号
ngCardSwipeRecords.setDeviceNumber(serialNumber);//设备编码
ngCardSwipeRecords.setAreaCode(areaCode);//区域号
ngCardSwipeRecords.setCardSwipeType(0);//开阀
ngCardSwipeRecords.setCardSwipeTime(DateUtils.getNowDate());//刷卡时间
if(cardInfo!=null && cardInfo.getUserId()!=null){
ngCardSwipeRecords.setUserId(cardInfo.getUserId());//用户id
}
if(cardInfo!=null && cardInfo.getUserName()!=null){
ngCardSwipeRecords.setUserName(cardInfo.getUserName());//用户名称
}
flag=ngCardSwipeRecordsMapper.insertNgCardSwipeRecords(ngCardSwipeRecords);
if(flag<1)
{
log.error("设备{}开阀刷卡记录添加失败",serialNumber);
}
}
//处理关阀门报文
@ -338,6 +334,12 @@ public class DeviceOtherMsgConsumer {
{
log.error("设备{}灌溉记录不存在",serialNumber);
}else{
//根据卡号查询用户所属机构
List<UserRechargeCards> cardList = new LambdaQueryChainWrapper<>(userRechargeCardsMapper)
.select(UserRechargeCards::getUserId,UserRechargeCards::getDeptId,UserRechargeCards::getUserName)
.eq(UserRechargeCards::getCardNumber, cardNumber)
// .ne(UserRechargeCards::getDeptId, null)
.list();
UserIrrigationRecord userIrrigationRecord=new UserIrrigationRecord();
userIrrigationRecord.setId(irrigationRecordList.get(0).getId());
@ -351,8 +353,6 @@ public class DeviceOtherMsgConsumer {
// System.err.println("用户关阀时总用水量:"+closeCumFlow);
userIrrigationRecord.setCloseCumFlow(closeCumFlow);
BigDecimal currentFlow=closeCumFlow.subtract(irrigationRecordList.get(0).getOpenCumFlow());//计算结果为当前用水量
//当前用水量
log.info("设备{}本次灌溉用户当前用水量{}",serialNumber,currentFlow);
@ -374,7 +374,7 @@ public class DeviceOtherMsgConsumer {
//添加一条刷卡记录
String areaCode=dataJson.getStr("areaCode");
UserRechargeCards cardInfo=userRechargeCardsMapper.selectUserRechargeCardsByCardNumberAndAreaCode(cardNumber,areaCode);//查询卡号+区域号信息
// UserRechargeCards cardInfo=userRechargeCardsMapper.selectUserRechargeCardsByCardNumberAndAreaCode(cardNumber,areaCode);//查询卡号+区域号信息
NgCardSwipeRecords ngCardSwipeRecords=new NgCardSwipeRecords();
ngCardSwipeRecords.setCardNumber(cardNumber);//卡号
@ -382,14 +382,13 @@ public class DeviceOtherMsgConsumer {
ngCardSwipeRecords.setAreaCode(areaCode);//区域号
ngCardSwipeRecords.setCardSwipeType(1);//关阀
ngCardSwipeRecords.setCardSwipeTime(DateUtils.getNowDate());//刷卡时间
if(cardInfo!=null && cardInfo.getUserId()!=null){
ngCardSwipeRecords.setUserId(cardInfo.getUserId());//用户id
}
if(cardInfo!=null && cardInfo.getUserName()!=null){
ngCardSwipeRecords.setUserName(cardInfo.getUserName());//用户名称
}
flag=ngCardSwipeRecordsMapper.insertNgCardSwipeRecords(ngCardSwipeRecords);
if(flag<1)
// ngCardSwipeRecords.setUserId(cardList.get(0).getUserId());//用户id
// ngCardSwipeRecords.setUserName(cardList.get(0).getUserName());//用户名称
int flag1=ngCardSwipeRecordsMapper.insertNgCardSwipeRecords(ngCardSwipeRecords);
if(flag1<1)
{
log.error("设备{}关阀刷卡记录添加失败",serialNumber);
}
@ -447,6 +446,7 @@ public class DeviceOtherMsgConsumer {
}
otherMsgHandler.messageHandler(bo);
}catch (Exception e){
e.printStackTrace();
log.error("=>主题:{}设备消息:{}处理出错:{}",topic,new String(data), e.getMessage());
}
}
@ -534,15 +534,19 @@ public class DeviceOtherMsgConsumer {
* 处理刷卡上报查询报文
*/
private void cardReportHandler(Long productId,String serialNumber,JSONObject dataObj){
System.err.println("收到查询报文");
JSONObject data = dataObj.getJSONObject("data");
//解析消息
String cardId=data.getStr("cardId");//卡号
System.err.println("卡号:"+cardId);
String areaCode=data.getStr("areaCode");//区域码
System.err.println("区域码:"+areaCode);
//先回应代表平台收到了来自设备的查询报文
Map<String,Object> reply=new HashMap<>();
reply.put("pakSn",dataObj.getInt("pakSn"));
System.err.println("包号" + dataObj.getInt("pakSn"));
//默认没有充值的订单
reply.put("cmd",400);
reply.put("code",400);
Map<String,Object> dataValue=new HashMap<>();
reply.put("msg","");
@ -555,22 +559,26 @@ public class DeviceOtherMsgConsumer {
.list();
//如果有待充值的订单则需要下发充值信息如果有多条需要下发的充值订单需要合并充值金额为一条且订单号取最近的一条
if(!orderList.isEmpty()){
System.err.println("amount:"+orderList.get(0).getAmount().doubleValue());
//合并订单充值金额
BigDecimal investBalance=null;
for(int i=0;i<orderList.size()-1;i++){
Double investBalance= 0.00;
for(int i=0;i<=orderList.size()-1;i++){
//累加金额
investBalance=investBalance==null?orderList.get(i).getAmount():investBalance.add(orderList.get(i).getAmount());
investBalance=investBalance+orderList.get(i).getAmount().doubleValue();
}
//取最新的订单号作为合并后的订单
dataValue.put("orderNum",orderList.get(orderList.size()-1).getId());//订单号
reply.put("cmd",410);
dataValue.put("cardNum",cardId);//卡号
dataValue.put("areaCode",areaCode);//区域码
reply.put("code",410);
dataValue.put("cardNum",Integer.parseInt(cardId));//卡号
dataValue.put("areaCode",Integer.parseInt(areaCode));//区域码
dataValue.put("investBalance",investBalance.doubleValue()*100);//充值金额
// dataValue.put("investWater",rechargecardUser.getWater()*100);//充值水量
reply.put("data",dataValue);
pubMqttClient.publish(1,true,"hzlink/"+productId+"/"+serialNumber+"/info/reply", JSONUtil.toJsonStr(reply));
return;
}
reply.put("data",dataValue);
pubMqttClient.publish(1,true,"hzlink/"+productId+"/"+serialNumber+"/info/reply", JSONUtil.toJsonStr(reply));
}
public static void main(String[] args) {

View File

@ -47,7 +47,8 @@ public class DeviceOtherMsgHandler {
String name = topicsUtils.parseTopicName(bo.getTopicName());
if (StringUtils.isEmpty(name) || name.endsWith(TopicType.FUNCTION_GET.getTopicSuffix())) return;
ReportDataBo data = this.buildReportData(bo);
System.err.println("进入消息处理入口:"+data);
// System.err.println("进入消息处理入口:"+data);
log.info("消息内容:"+data.getMessage());
TopicType topicType = TopicType.getType(name);
switch (topicType) {
case INFO_POST: