JAVA扫码点餐(2)-项目过程

项目框架

maven项目:分为三个项目:
输入图片说明
online-foods-services:公共框架,封装13张表的增删改查且一些业务封装方法。
online-foods-oms:后台管理操作。
输入图片说明
输入图片说明
online-foods-controller:前端页面展示,可以在支付宝扫一扫中打开的H5页面。

代码片段

public class AlipayClientHelper {
	private static Logger LOGGER = LoggerFactory.getLogger(AlipayClientHelper.class);

	private static String url = null;
	private static String appId = null;
	private static String appPrivateKey = null;
	private static String format = null;
	private static String charset = null;
	private static String alipayPublicKey = null;
	private static String signType = null;

	static {
		url = Properties.getString(PropertiesEnum.ALIPAY_URL.getIndex());
		appId = Properties.getString(PropertiesEnum.ALIPAY_APP_ID.getIndex());
		appPrivateKey = Properties.getString(PropertiesEnum.ALIPAY_APP_PRIVATE_KEY.getIndex());
		format = Properties.getString(PropertiesEnum.ALIPAY_FORMAT.getIndex());
		charset = Properties.getString(PropertiesEnum.ALIPAY_CHARSET.getIndex());
		alipayPublicKey = Properties.getString(PropertiesEnum.ALIPAY_ALIPAY_PUBLIC_KEY.getIndex());
		signType = Properties.getString(PropertiesEnum.ALIPAY_SIGN_TYPE.getIndex());
	}

	public static AlipayClient getAlipayClient() {
		LOGGER.info("url = {}, appId = {},  appPrivateKey={}, format = {}, charset={}, alipayPublicKey = {}, signType = {}", url, appId, "", format, charset, "", signType);
		// AlipayClient alipayClient = new DefaultAlipayClient(url, appId, appPrivateKey, "json", "UTF-8", alipayPublicKey, "RSA2");
		AlipayClient alipayClient = new DefaultAlipayClient(url, appId, appPrivateKey, format, charset, alipayPublicKey, signType);
		return alipayClient;
	}

}

订单倒计时实现:

public class CountDownThread extends Thread {
	private static Logger LOGGER = LoggerFactory.getLogger(CountDownThread.class);
	public volatile boolean exit = false;
	private String orderNo;
	private int countdown;

	public CountDownThread() {

	}

	public CountDownThread(String orderNo) {
		this.orderNo = orderNo;
		// 默认15分钟倒计时
		this.countdown = 900;
	}

	public CountDownThread(String orderNo, int countdown) {
		this.orderNo = orderNo;
		this.countdown = countdown;
	}

	public String getOrderNo() {
		return orderNo;
	}

	public int getCountdown() {
		return countdown;
	}

	@Override
	public void run() {
		while (countdown > 0) {
			if (exit) {
				break;
			}
			countdown--;
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				LOGGER.error("订单倒计时线程发生错误:", e);
			}
		}
		OnlineFoodOrderService onlineFoodOrderService = (OnlineFoodOrderService) SpringHelper.getBean(OnlineFoodOrderService.class);

		OnlineFoodOrder onlineFoodOrder1 = new OnlineFoodOrder();
		onlineFoodOrder1.setOrderNo(orderNo);
		onlineFoodOrder1.setOrderState(OrderStateEnum.OrderState_1.getIndex());
		OnlineFoodOrder onlineFoodOrder2 = new OnlineFoodOrder();
		onlineFoodOrder2.setOrderState(OrderStateEnum.OrderState_2.getIndex());
		int count = onlineFoodOrderService.updateOnlineFoodOrderByCriteriaSelective(onlineFoodOrder1, onlineFoodOrder2);
		LOGGER.warn("订单倒计时取消,订单号:{} ,取消到:{} 条", orderNo, count);
	}
}

订单倒计时Cache:

public class AppcationCache {
	private static AppcationCache appcationCache;

	private Map<String, CountDownThread> orderCountDownMap = new ConcurrentHashMap<String, CountDownThread>();

	private Map<String, String> phoneMap = new ConcurrentHashMap<String, String>();

	public static AppcationCache getInstance() {
		if (appcationCache == null) {
			synchronized (AppcationCache.class) {
				if (appcationCache == null) {
					appcationCache = new AppcationCache();
				}
			}
		}
		return appcationCache;
	}

	public Map<String, CountDownThread> getOrderCountDownMap() {
		return orderCountDownMap;
	}

	public Map<String, String> getPhoneMap() {
		return phoneMap;
	}
}

为啥要贴着3段代码?

  1. 很多人在调用 支付宝支付的时候,总会有一些奇奇怪怪的问题,所以我这里封装起来了。注意:支付宝公钥,不是应用的公钥,一定是要支付宝的公钥。要不然调用就会出现sign验证不通过。
  2. 订单倒计时,我百度了一圈,没看到实现得较好的代码,所以我这里用一种最简单的方案,自己缓存倒计时。可能有人会问,为啥不用redis,我阿里云ECS 1核2G, 不想引用一些第三方的组件。

     

有意做类似软件的可以私信我,买源码也可以私信我。可做毕业设计,有成功案例!

客官,既然都看到这里了,帮忙扫个码测试下呗,拿出支付宝扫一扫,谢谢!

转载请注明出处:【https://blog.csdn.net/hncdyj/article/details/83650155】

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值