刷卡todo:理清表关系,调用订单服务

This commit is contained in:
ZZ 2022-01-11 18:25:41 +08:00
parent 01314496c2
commit dd56f871de
4 changed files with 50 additions and 16 deletions

View File

@ -122,8 +122,12 @@ public class NotificationChargeOrderInfo4BonusTask extends CoreDispatcher {
} }
public static String transferInternetOrderNo(String orderKeyOrNo, String operatorId) { public static String transferInternetOrderNo(String orderKeyOrNo, String operatorId) {
// "80836000010001012110191723410021"; //80836000010001012110191723410021
//MA6DFCTD5202201111742100140
String orderNo = orderKeyOrNo.replace("order:", ""); String orderNo = orderKeyOrNo.replace("order:", "");
if (operatorId.length() > 9) {
operatorId = operatorId.substring(0, 9);
}
return operatorId.concat(DateUtil.getYYYY()).concat(orderNo.substring(18)); return operatorId.concat(DateUtil.getYYYY()).concat(orderNo.substring(18));
} }

View File

@ -73,6 +73,7 @@ public class HexUtils {
public static byte[] toBytes(String hex) { public static byte[] toBytes(String hex) {
if (hex == null) return null;
hex = hex.trim(); hex = hex.trim();
if (hex.length() == 0 || hex.length() % 2 != 0) if (hex.length() == 0 || hex.length() % 2 != 0)
return null; return null;
@ -172,7 +173,7 @@ public class HexUtils {
final StringBuilder result = new StringBuilder(); final StringBuilder result = new StringBuilder();
for (byte b: bytes) { for (byte b: bytes) {
for (int i=0; i<8; i++) { for (int i=0; i<8; i++) {
result. append((int)(b >> (8-(i+1)) & 0x0001)); result.append(b >> (8 - (i + 1)) & 0x0001);
} }
} }
return result. toString(); return result. toString();

View File

@ -3,22 +3,26 @@ package com.xhpc.pp.logic;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.xhpc.common.data.up.PileStartChargingData; import com.xhpc.common.data.up.PileStartChargingData;
import com.xhpc.common.enums.StationDeviceEnum; import com.xhpc.common.enums.StationDeviceEnum;
import com.xhpc.pp.domain.IccardInfo;
import com.xhpc.pp.domain.IccardInfoExample;
import com.xhpc.pp.domain.XhpcDeviceMessage; import com.xhpc.pp.domain.XhpcDeviceMessage;
import com.xhpc.pp.mapper.ServiceFieldMapper; import com.xhpc.pp.mapper.IccardInfoMapper;
import com.xhpc.pp.mapper.XhpcDeviceMessageMapper; import com.xhpc.pp.mapper.XhpcDeviceMessageMapper;
import com.xhpc.pp.tx.ServiceParameter; import com.xhpc.pp.tx.ServiceParameter;
import com.xhpc.pp.tx.ServiceResult; import com.xhpc.pp.tx.ServiceResult;
import com.xhpc.pp.tx.logic.ServiceLogic; import com.xhpc.pp.tx.logic.ServiceLogic;
import com.xhpc.pp.utils.HexUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static com.xhpc.pp.tx.ServiceResult.HEX_00;
@Lazy @Lazy
@Component("PileStartChargingDataLogic") @Component("PileStartChargingDataLogic")
public class PileStartChargingDataLogic implements ServiceLogic { public class PileStartChargingDataLogic implements ServiceLogic {
@ -28,34 +32,60 @@ public class PileStartChargingDataLogic implements ServiceLogic {
@Resource @Resource
private XhpcDeviceMessageMapper deviceMessageMapper; private XhpcDeviceMessageMapper deviceMessageMapper;
@Resource @Resource
private ServiceFieldMapper fieldMapper; private IccardInfoMapper iccardInfoMapper;
@Override @Override
public ServiceResult service(ServiceParameter sp) throws Exception { public ServiceResult service(ServiceParameter sp) throws Exception {
String resultStr = null;
String result = ServiceResult.FAIL;
Map<String, Object> req = sp.getParameters(); Map<String, Object> req = sp.getParameters();
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
PileStartChargingData pileStartChargingData = objectMapper.convertValue(req, PileStartChargingData.class); PileStartChargingData pileStartChargingData = objectMapper.convertValue(req, PileStartChargingData.class);
String terminalId = pileStartChargingData.getPileNo().concat(pileStartChargingData.getGunId()); String connectorId = pileStartChargingData.getPileNo().concat(pileStartChargingData.getGunId());
String accountOrCardNo = pileStartChargingData.getAccountOrCardNo(); String accountOrCardNo = pileStartChargingData.getAccountOrCardNo();
String corpNo = terminalId.substring(0, 6); String corpNo = connectorId.substring(0, 6);
String balance = "0000";
String cardNo = "00000000";
if (pileStartChargingData.getStartType().equals("01")) { //刷卡启动 if (pileStartChargingData.getStartType().equals("01")) { //刷卡启动
String sql = "select i.* from t_iccard_info i where cardNo='" + accountOrCardNo + "' and corpNo = '" + corpNo + IccardInfoExample example = new IccardInfoExample();
"'"; IccardInfoExample.Criteria criteria = example.createCriteria();
Map<String, String> param = new HashMap<>(); criteria.andCardidEqualTo(accountOrCardNo).andCorpnoEqualTo(corpNo);
param.put("sql", sql); List<IccardInfo> iccardInfos = iccardInfoMapper.selectByExample(example);
List<Map<String, Object>> resultMap = fieldMapper.querySQL(param); if (iccardInfos.size() == 1) {
IccardInfo iccardInfo = iccardInfos.get(0);
cardNo = iccardInfo.getCardno();
//todo 桩停用
if (!iccardInfo.getCorpno().equals(corpNo)) {
resultStr = "06";
} else if (HEX_00.equals(pileStartChargingData.getPasswordRequired())
|| (HEX_00.equals(pileStartChargingData.getPasswordRequired()) && pileStartChargingData.getPassword().equals(iccardInfo.getPassword()))) {
int balanceInt = iccardInfo.getBalance();
balance = HexUtils.toHexInt(balanceInt);
if (balanceInt < 100) {
resultStr = "01";
result = ServiceResult.OK;
} else {
resultStr = "03";
}
} else if (iccardInfo.getStatus() != 1) {
result = "02";
}
} else {
result = "01";
}
} }
String remark = "充电桩主动申请起动充电"; String remark = "充电桩主动申请起动充电";
XhpcDeviceMessage deviceMessage = new XhpcDeviceMessage(); XhpcDeviceMessage deviceMessage = new XhpcDeviceMessage();
deviceMessage.setType(StationDeviceEnum.PILE.getCode()); deviceMessage.setType(StationDeviceEnum.PILE.getCode());
deviceMessage.setSerialNumber(terminalId); deviceMessage.setSerialNumber(connectorId);
deviceMessage.setRemark(remark); deviceMessage.setRemark(remark);
deviceMessage.setStatus(0); deviceMessage.setStatus(0);
deviceMessage.setContent((String) req.get("hex")); deviceMessage.setContent((String) req.get("hex"));
deviceMessageMapper.insertByDomain(deviceMessage); deviceMessageMapper.insertByDomain(deviceMessage);
return new ServiceResult(false); String hex = "orderNo".concat(connectorId).concat(cardNo).concat(balance).concat(resultStr).concat(result); //todo
// 调用订单接口
return new ServiceResult(HexUtils.toBytes(hex), result);
} }
} }

View File

@ -43,7 +43,6 @@ public class PileTimeConfigReplyDataLogic implements ServiceLogic {
cachePile.put("configTime", configTime); cachePile.put("configTime", configTime);
REDIS.setCacheMap(pk, cachePile); REDIS.setCacheMap(pk, cachePile);
log.debug("({}) set time success√: [{}]", pileNo, configTime); log.debug("({}) set time success√: [{}]", pileNo, configTime);
String remark = "充电桩同步时钟"; String remark = "充电桩同步时钟";
XhpcDeviceMessage deviceMessage = new XhpcDeviceMessage(); XhpcDeviceMessage deviceMessage = new XhpcDeviceMessage();
deviceMessage.setType(StationDeviceEnum.PILE.getCode()); deviceMessage.setType(StationDeviceEnum.PILE.getCode());