安卓工具类------->AppUtils.java


import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

//跟App相关的辅助类
public class AppUtils
{

	private AppUtils()
	{
		/* cannot be instantiated */
		throw new UnsupportedOperationException("cannot be instantiated");

	}

	/**
	 * 获取应用程序名称
	 */
	public static String getAppName(Context context)
	{
		try
		{
			PackageManager packageManager = context.getPackageManager();
			PackageInfo packageInfo = packageManager.getPackageInfo(
					context.getPackageName(), 0);
			int labelRes = packageInfo.applicationInfo.labelRes;
			return context.getResources().getString(labelRes);
		} catch (NameNotFoundException e)
		{
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * [获取应用程序版本名称信息]
	 * 
	 * @param context
	 * @return 当前应用的版本名称
	 */
	public static String getVersionName(Context context)
	{
		try
		{
			PackageManager packageManager = context.getPackageManager();
			PackageInfo packageInfo = packageManager.getPackageInfo(
					context.getPackageName(), 0);
			return packageInfo.versionName;

		} catch (NameNotFoundException e)
		{
			e.printStackTrace();
		}
		return null;
	}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
private void checkGoodsStock(Goods goods, Integer buyNum) { //商品为现货商品,判断商品现货可用库存 if (GoodsSaleType.SPOT == GoodsSaleType.findSaleType(goods.getSaleType())) { //单个商品、意向商品 if (GoodsShelveType.SINGLE.getShelveType() == goods.getShelveType() || GoodsShelveType.INTENTION.getShelveType() == goods.getShelveType()) { BaseGoods baseGoods = iBaseGoodsService.getOne(Wrappers.<BaseGoods>lambdaQuery().in(BaseGoods::getModel, goods.getModel()).last("for update")); if (buyNum > baseGoods.getSpotOccupyStock()) { throw new ServiceException(ErrorMessage.STOCK_ERROR); } } //组合商品 if (GoodsShelveType.COMBINATION.getShelveType() == goods.getShelveType()) { //查询组合商品子商品信息 List<GoodsChilds> goodsChildsList = goodsChildsService.lambdaQuery().eq(GoodsChilds::getParentId, goods.getId()).eq(GoodsChilds::getIsGift, 0).list(); if (CollectionUtils.isEmpty(goodsChildsList)) { throw new ServiceException("组合商品子商品信息为空"); } //子商品所有商品型号 List<String> goodsChildsModelList = goodsChildsList.stream().map(GoodsChilds::getModel).collect(Collectors.toList()); List<BaseGoods> baseGoodsList = iBaseGoodsService.list(Wrappers.<BaseGoods>lambdaQuery().in(BaseGoods::getModel, goodsChildsModelList).last("for update")); Map<String, BaseGoods> baseGoodsMap = AppUtils.listToMap(baseGoodsList, BaseGoods::getModel); for (GoodsChilds goodsChilds : goodsChildsList) { BaseGoods baseGoods = baseGoodsMap.get(goodsChilds.getModel()); if (baseGoods == null) { throw new ServiceException("商品型号不存在"); } //子商品总购买数 Integer goodsChildsBuyNum = goodsChilds.getNumberCoefficient().multiply(new BigDecimal(buyNum)).intValue(); if (goodsChildsBuyNum > baseGoods.getSpotOccupyStock()) { throw new ServiceException(ErrorMessage.STOCK_ERROR); } } } } //非现货商品,判断上架库存 if (GoodsSaleType.SPOT != GoodsSaleType.findSaleType(goods.getSaleType()) && buyNum > goods.getStock()) { throw new ServiceException(ErrorMessage.STOCK_ERROR); } }优化该段代码
最新发布
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值