在开阀关阀时添加一条刷卡记录;将userId保存到灌溉记录中

This commit is contained in:
童丽然 2025-01-06 14:08:48 +08:00
parent 5bfa0cc659
commit 5d2ee2ae05

View File

@ -3,6 +3,7 @@ package com.fastbee.mq.redischannel.consumer;
import cn.hutool.core.date.DateTime;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.fastbee.common.constant.FastBeeConstant;
@ -10,7 +11,9 @@ import com.fastbee.common.core.domain.entity.SysUser;
import com.fastbee.common.core.mq.DeviceReportBo;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.iot.domain.DeviceReportInfo;
import com.fastbee.iot.domain.NgCardSwipeRecords;
import com.fastbee.iot.mapper.DeviceReportInfoMapper;
import com.fastbee.iot.mapper.NgCardSwipeRecordsMapper;
import com.fastbee.mq.redischannel.producer.IssueInstructionsProducer;
import com.fastbee.mq.service.impl.DeviceOtherMsgHandler;
import com.fastbee.mqttclient.PubMqttClient;
@ -69,6 +72,9 @@ public class DeviceOtherMsgConsumer {
@Autowired
private UserRechargeCardsMapper userRechargeCardsMapper;
@Autowired
private NgCardSwipeRecordsMapper ngCardSwipeRecordsMapper;
@Autowired
private SysUserMapper sysUserMapper;
@ -96,9 +102,11 @@ public class DeviceOtherMsgConsumer {
System.err.println(topic.endsWith("/info/up"));
//设备上报数据消息---------------------------------------------------------------------------------
if(topic.endsWith("/info/up")){
deviceDataReportHandler(productId,serialNumber,JSONUtil.parseObj(new String(data)));
/*deviceDataReportHandler(productId,serialNumber,JSONUtil.parseObj(new String(data)));
//更新设备在线状态
updateDeviceOnlineStatus( productId,serialNumber);//拼成一个唯一的key只要key存在则设备在线
updateDeviceOnlineStatus( productId,serialNumber);//拼成一个唯一的key只要key存在则设备在线*/
// updateDeviceOnlineStatusDb(serialNumber);
//保存使用记录
NgWaterPumpUsageRecords pumpUsageRecords=new NgWaterPumpUsageRecords();
@ -242,10 +250,10 @@ public class DeviceOtherMsgConsumer {
}
//开阀门关阀门
else if("startPump".equals(JSONUtil.parseObj(data1).get("action"))|| "stopPump".equals(JSONUtil.parseObj(data1).get("action"))){
int i = ngWaterPumpUsageRecordsMapper.insertNgWaterPumpUsageRecords(pumpUsageRecords);
/*int i = ngWaterPumpUsageRecordsMapper.insertNgWaterPumpUsageRecords(pumpUsageRecords);
if(i<1){
System.err.println("--------------------------保存使用记录失败!---------------------------");
}
}*/
JSONObject dataJson=jsonObject.getJSONObject("data");
System.err.println(jsonObject);
System.err.println(dataJson);
@ -262,28 +270,26 @@ public class DeviceOtherMsgConsumer {
userIrrigationRecord.setCardNumber(cardNumber);//卡号
System.err.println("cardNumber"+cardNumber);
UserRechargeCards cardInfo=userRechargeCardsMapper.selectUserRechargeCardsByCardnumber(cardNumber);
if(cardInfo==null)
String areaCode=dataJson.getStr("areaCode");
userIrrigationRecord.setAreaCode(areaCode);//区域号
System.err.println("areaCode"+areaCode);
QueryWrapper queryWrapper=new QueryWrapper<>(userRechargeCardsMapper);
queryWrapper.eq("card_number",cardNumber);
UserRechargeCards userRechargeCards=userRechargeCardsMapper.selectOne(queryWrapper);//获取充值卡信息
if(userRechargeCards==null)
{
System.err.println("用户不存在");
}
Long deptId= null;//获取deptId
if (cardInfo != null) {
deptId = cardInfo.getDeptId();
log.error("用户不存在");
}
userIrrigationRecord.setDeptId(deptId);
if (userRechargeCards!=null && userRechargeCards.getDeptId() != null) {
userIrrigationRecord.setDeptId(userRechargeCards.getDeptId());//机构id
}
/*Long userId=null;
System.err.println("userId");
if(userRechargeCardsMapper.selectUserRechargeCardsByCardNumber(cardNumber)==null)
if(userRechargeCards!=null && userRechargeCards.getUserId()!=null)
{
throw new Exception("订单信息不存在");
userIrrigationRecord.setUserId(userRechargeCards.getUserId());//用户id
}
userId=userRechargeCardsMapper.selectUserRechargeCardsByCardNumber(cardNumber).getUserId();
userIrrigationRecord.setUserId(userId);
System.err.println("userId"+userId);*/
DateTime currentTime=DateTime.now();//获取当前时间作为开阀时间
userIrrigationRecord.setStartTime(currentTime);//开阀时间
@ -294,10 +300,6 @@ public class DeviceOtherMsgConsumer {
userIrrigationRecord.setOpenCumFlow(openCumFlow);//用户开阀时使用水量
System.err.println("openCumFlow"+openCumFlow);
String areaCode=dataJson.getStr("areaCode");
userIrrigationRecord.setAreaCode(areaCode);//区域号
System.err.println("areaCode"+areaCode);
userIrrigationRecord.setStatus(1);//状态改为灌溉中
System.out.println(userIrrigationRecord);
@ -305,19 +307,42 @@ public class DeviceOtherMsgConsumer {
userIrrigationRecord.setCreateTime(DateUtils.getNowDate());
//对充值卡余额的操作
UserRechargeCards userRechargeCards = userRechargeCardsMapper.selectUserRechargeCardsByCardNumber(cardNumber);//获取充值卡信息
BigDecimal balance=dataJson.getBigDecimal("userBalance");//获取当前用户金额
userRechargeCards.setBalance(balance);//同步用户余额
//UserRechargeCards userRechargeCards = userRechargeCardsMapper.selectUserRechargeCardsByCardNumber(cardNumber);//获取充值卡信息
if(userRechargeCards!=null)
{
BigDecimal balance=dataJson.getBigDecimal("userBalance");//获取当前用户金额
userRechargeCards.setBalance(balance);//同步用户余额
}
int flag=userIrrigationRecordMapper.insertUserIrrigationRecord(userIrrigationRecord);//开阀时添加一条灌溉记录
if(flag<1)
{
System.err.println("灌溉记录添加失败");
log.error("灌溉记录添加失败");
}else{
flag=userRechargeCardsMapper.updateUserRechargeCards(userRechargeCards);//同步充值卡余额
if(flag<1)
{
System.err.println("充值卡金额同步失败");
log.error("充值卡金额同步失败");
}else{
//添加一条刷卡记录
NgCardSwipeRecords ngCardSwipeRecords=new NgCardSwipeRecords();
ngCardSwipeRecords.setCardNumber(cardNumber);//卡号
ngCardSwipeRecords.setDeviceNumber(serialNumber);//设备编码
ngCardSwipeRecords.setAreaCode(areaCode);//区域号
ngCardSwipeRecords.setCardSwipeType(0);//开阀
ngCardSwipeRecords.setCardSwipeTime(DateUtils.getNowDate());//刷卡时间
if(userRechargeCards!=null && userRechargeCards.getUserId()!=null){
ngCardSwipeRecords.setUserId(userRechargeCards.getUserId());//用户id
}
if(userRechargeCards!=null && userRechargeCards.getUserName()!=null){
ngCardSwipeRecords.setUserName(userRechargeCards.getUserName());//用户名称
}
flag=ngCardSwipeRecordsMapper.insertNgCardSwipeRecords(ngCardSwipeRecords);
if(flag!=1)
{
log.error("刷卡记录添加失败");
}
}
}
}else if("stopPump".equals(JSONUtil.parseObj(data1).get("action"))){
@ -355,13 +380,34 @@ public class DeviceOtherMsgConsumer {
int flag=userIrrigationRecordMapper.updateUserIrrigationRecord(userIrrigationRecord);//关阀时修改一条灌溉记录
if(flag<1)
{
System.err.println("灌溉记录修改失败");
log.error("灌溉记录修改失败");
}else{
flag=userRechargeCardsMapper.updateUserRechargeCards(userRechargeCards);//同步充值卡余额
if(flag<1)
{
System.err.println("充值卡金额同步失败");
log.error("充值卡金额同步失败");
}else{
//添加一条刷卡记录
String areaCode=dataJson.getStr("areaCode");
NgCardSwipeRecords ngCardSwipeRecords=new NgCardSwipeRecords();
ngCardSwipeRecords.setCardNumber(cardNumber);//卡号
ngCardSwipeRecords.setDeviceNumber(serialNumber);//设备编码
ngCardSwipeRecords.setAreaCode(areaCode);//区域号
ngCardSwipeRecords.setCardSwipeType(1);//关阀
ngCardSwipeRecords.setCardSwipeTime(DateUtils.getNowDate());//刷卡时间
if(userRechargeCards!=null && userRechargeCards.getUserId()!=null){
ngCardSwipeRecords.setUserId(userRechargeCards.getUserId());//用户id
}
if(userRechargeCards!=null && userRechargeCards.getUserName()!=null){
ngCardSwipeRecords.setUserName(userRechargeCards.getUserName());//用户名称
}
flag=ngCardSwipeRecordsMapper.insertNgCardSwipeRecords(ngCardSwipeRecords);
if(flag<1)
{
log.error("刷卡记录添加失败");
}
}
}
}
}
@ -575,7 +621,7 @@ public class DeviceOtherMsgConsumer {
+ " \"meterIns\": 6100,"
+ " \"meterStatus\": 1,"
+ " \"userSumFlow\": 640000,"
+ " \"cardId\": 402,"
+ " \"cardId\": 403,"
+ " \"action\": \"startPump\","
+ " \"meterSum\": 6400,"
+ " \"pumpState\": 0,"