|
@@ -4,6 +4,7 @@ import cn.hutool.core.convert.Convert;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.tokheim.aifueling.communication.entitys.BaseInfo;
|
|
|
import com.tokheim.aifueling.communication.entitys.CardStatus;
|
|
|
+import com.tokheim.aifueling.communication.entitys.NozzleStatus;
|
|
|
import com.tokheim.aifueling.communication.toInternalInterface.entity.FuelResponse;
|
|
|
import com.tokheim.aifueling.communication.toMachine.MachineWriter;
|
|
|
import com.tokheim.aifueling.utils.BeanUtils;
|
|
@@ -20,8 +21,12 @@ import java.util.Map;
|
|
|
public class InterfaceUtils {
|
|
|
private static final InterfaceApi interfaceApi = BeanUtils.getBean(InterfaceApi.class);
|
|
|
|
|
|
- //存储卡指令
|
|
|
- private static Map<Integer, BaseInfo> cardCommMap = new HashMap<>();
|
|
|
+ //存储指令
|
|
|
+ private static Map<String, BaseInfo> commMap = new HashMap<>();
|
|
|
+ //卡最大可加金额 key 后缀
|
|
|
+ private static final String MAXAMOUNTSUFFIX = "maxAmount";
|
|
|
+ //挂枪 key 后缀
|
|
|
+ private static final String HANG = "hang";
|
|
|
|
|
|
/**
|
|
|
* 发送数据到内部接口
|
|
@@ -30,20 +35,13 @@ public class InterfaceUtils {
|
|
|
*/
|
|
|
public static void sendDataToInternal(Integer dataType, BaseInfo baseInfo) {
|
|
|
try {
|
|
|
- sortCardComm(dataType, baseInfo);
|
|
|
- if (dataType == 1 && baseInfo.getEventType() == 3) log.info("无密码确认");
|
|
|
-
|
|
|
- if (dataType == 1 && baseInfo.getEventType() == 7) return;
|
|
|
+ cleanCache(dataType, baseInfo);
|
|
|
+ if (!sortCarNumComm(dataType, baseInfo)) return;
|
|
|
+ if (!sortBalanceComm(dataType, baseInfo)) return;
|
|
|
|
|
|
String response = interfaceApi.sendData(dataType, baseInfo);
|
|
|
log.info("收到内部接口响应:{}",response);
|
|
|
|
|
|
- //如果发了车牌匹配结果,把缓存的 卡最大可加金额 发出去
|
|
|
- if (dataType == 6) {
|
|
|
- response = interfaceApi.sendData(1, cardCommMap.get(baseInfo.getNozzleNum()));
|
|
|
- log.info("发送卡最大可加金额,收到内部接口响应:{}",response);
|
|
|
- }
|
|
|
-
|
|
|
FuelResponse fuelResponse = new Gson().fromJson(response, FuelResponse.class);
|
|
|
FuelResponse.Data data = fuelResponse.getData();
|
|
|
if (data == null){
|
|
@@ -56,23 +54,28 @@ public class InterfaceUtils {
|
|
|
MachineWriter.sendCarNumber(baseInfo.getIp(),baseInfo.getFuelPoint(), baseInfo.getInternalNum(), data.getLicensePlate());
|
|
|
}
|
|
|
|
|
|
- //若定量金额不为空,则定金额,否则定升数
|
|
|
- if(data.getOilAmount() != null && checkDecimal(data.getOilAmount())) {
|
|
|
- MachineWriter.sendQuantitativeByAmount(baseInfo.getIp(),baseInfo.getFuelPoint(), baseInfo.getInternalNum(), data.getOilAmount());
|
|
|
- return;
|
|
|
- }
|
|
|
- if (data.getOilLiters() != null && checkDecimal(data.getOilLiters())) {
|
|
|
- MachineWriter.sendQuantitativeByVolume(baseInfo.getIp(), baseInfo.getFuelPoint(), baseInfo.getInternalNum(), data.getOilLiters());
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ //处理定量
|
|
|
+ sendQuantitative(data,baseInfo);
|
|
|
} catch (IOException e) {
|
|
|
log.error("发送数据到内部接口失败");
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //发送定量
|
|
|
+ private static void sendQuantitative(FuelResponse.Data data, BaseInfo baseInfo){
|
|
|
+ if (data == null) return;
|
|
|
+ //若定量金额不为空,则定金额,否则定升数
|
|
|
+ if(data.getOilAmount() != null && checkDecimal(data.getOilAmount())) {
|
|
|
+ MachineWriter.sendQuantitativeByAmount(baseInfo.getIp(),baseInfo.getFuelPoint(), baseInfo.getInternalNum(), data.getOilAmount());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (data.getOilLiters() != null && checkDecimal(data.getOilLiters())) {
|
|
|
+ MachineWriter.sendQuantitativeByVolume(baseInfo.getIp(), baseInfo.getFuelPoint(), baseInfo.getInternalNum(), data.getOilLiters());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//检查数值格式
|
|
|
public static boolean checkDecimal(String decimal) {
|
|
|
String decimalStr = decimal.replaceAll(",","");
|
|
@@ -87,15 +90,77 @@ public class InterfaceUtils {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 整理卡命令顺序
|
|
|
+ * 清理缓存
|
|
|
*/
|
|
|
- private static void sortCardComm(Integer dataType, BaseInfo baseInfo) {
|
|
|
+ private static void cleanCache(Integer dataType, BaseInfo baseInfo) {
|
|
|
//如果是发送卡无密码或者卡有密码,表示是一把枪卡加油过程的一个起始,把缓存删除
|
|
|
if (dataType == 1 && (baseInfo.getEventType() == 1 || baseInfo.getEventType() == 2)){
|
|
|
- cardCommMap.remove(baseInfo.getNozzleNum());
|
|
|
+ commMap.remove(baseInfo.getNozzleNum()+MAXAMOUNTSUFFIX);
|
|
|
+ commMap.remove(baseInfo.getNozzleNum()+HANG);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 整理车牌验证命令顺序,先发车牌验证结果,再发卡最大可加金额
|
|
|
+ * @return 是否需要发送其他信息
|
|
|
+ */
|
|
|
+ private static boolean sortCarNumComm(Integer dataType, BaseInfo baseInfo) throws IOException {
|
|
|
//卡最大可加金额指令信息加入缓存
|
|
|
- if (dataType == 1 && baseInfo.getEventType() == 7) cardCommMap.put(baseInfo.getNozzleNum(), baseInfo);
|
|
|
+ if (dataType == 1 && baseInfo.getEventType() == 7) commMap.put(baseInfo.getNozzleNum()+MAXAMOUNTSUFFIX, baseInfo);
|
|
|
+
|
|
|
+ //卡最大可加金额先不发送,等待发完车牌匹配结果后再发送卡最大可加金额
|
|
|
+ if (dataType == 1 && baseInfo.getEventType() == 7) return false;
|
|
|
+
|
|
|
+ if (dataType == 6) {
|
|
|
+ String response = interfaceApi.sendData(dataType, baseInfo);
|
|
|
+ log.info("发送车牌验证结果,收到内部接口响应:{}",response);
|
|
|
+ BaseInfo cache = commMap.get(baseInfo.getNozzleNum() + MAXAMOUNTSUFFIX);
|
|
|
+ if (cache == null) {
|
|
|
+ log.info("最大可加金额无缓存");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ response = interfaceApi.sendData(1, cache);
|
|
|
+ log.info("发送卡最大可加金额,收到内部接口响应:{}",response);
|
|
|
+ FuelResponse fuelResponse = new Gson().fromJson(response, FuelResponse.class);
|
|
|
+ FuelResponse.Data data = fuelResponse.getData();
|
|
|
+ sendQuantitative(data,baseInfo);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 整理挂枪指令顺序,因为实际扣款余额时在弹卡时才扣款,
|
|
|
+ * 因此将弹卡时获取到的卡余额赋值到挂枪指令中,再按挂枪指令->弹卡指令的顺序发送
|
|
|
+ * @return 是否需要发送其他指令
|
|
|
+ */
|
|
|
+ private static boolean sortBalanceComm(Integer dataType, BaseInfo baseInfo) throws IOException {
|
|
|
+ //挂枪指令信息加入缓存
|
|
|
+ if (dataType == 2 && baseInfo.getEventType() == 2) {
|
|
|
+ commMap.put(baseInfo.getNozzleNum()+HANG, baseInfo);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ //收到卡退出指令,先将挂枪指令中的卡余额改为卡退出指令的卡余额,再按挂枪指令->卡退出指令的顺序发送
|
|
|
+ if (dataType == 1 && baseInfo.getEventType() == 6) {
|
|
|
+ //挂枪、卡退出,将卡退出中的余额赋值到挂枪指令中
|
|
|
+ BaseInfo hangup = commMap.get(baseInfo.getNozzleNum()+HANG);
|
|
|
+ CardStatus cardStatus = (CardStatus) baseInfo;
|
|
|
+ String response = "";
|
|
|
+ if (hangup != null) {
|
|
|
+ NozzleStatus nozzleStatus = (NozzleStatus) hangup;
|
|
|
+ nozzleStatus.setBalance(cardStatus.getBalance());
|
|
|
+
|
|
|
+ response = interfaceApi.sendData(2, nozzleStatus);
|
|
|
+ log.info("发送挂枪指令,收到内部接口响应:{}",response);
|
|
|
+ }
|
|
|
+
|
|
|
+ response = interfaceApi.sendData(dataType, cardStatus);
|
|
|
+ log.info("发送弹卡指令,收到内部接口响应:{}",response);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|