diff --git a/src/main/java/com/yingjun/ssm/service/impl/GoodsServiceImpl.java b/src/main/java/com/yingjun/ssm/service/impl/GoodsServiceImpl.java index b477bb28d2da9b29f5cd753482ce15d41c7b606d..3d7447acddeb2a66f31594125ba3e53137a8b9ee 100644 --- a/src/main/java/com/yingjun/ssm/service/impl/GoodsServiceImpl.java +++ b/src/main/java/com/yingjun/ssm/service/impl/GoodsServiceImpl.java @@ -1,100 +1,36 @@ package com.yingjun.ssm.service.impl; -import com.yingjun.ssm.dao.GoodsDao; -import com.yingjun.ssm.dao.OrderDao; -import com.yingjun.ssm.dao.UserDao; + import com.yingjun.ssm.entity.Goods; -import com.yingjun.ssm.entity.User; -import com.yingjun.ssm.enums.ResultEnum; -import com.yingjun.ssm.exception.BizException; + import com.yingjun.ssm.service.GoodsService; -import org.apache.commons.collections.MapUtils; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; + import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.HashMap; + import java.util.List; -import java.util.Map; + @Service public class GoodsServiceImpl implements GoodsService { private final Logger LOG = LoggerFactory.getLogger(this.getClass()); - @Autowired - private GoodsDao goodsDao; - @Autowired - private OrderDao orderDao; - @Autowired - private UserDao userDao; + @Override public List getGoodsList(int offset, int limit) { -// String cache_key = RedisCache.CAHCENAME + "|getGoodsList|" + offset + "|" + limit; -// List result_cache = cache.getListCache(cache_key, Goods.class); -// if (result_cache != null) { -// LOG.info("get cache with key:" + cache_key); -// } else { -// // 缓存中没有再去数据库取,并插入缓存(缓存时间为60秒) -// result_cache = goodsDao.queryAll(offset, limit); -// cache.putListCacheWithExpireTime(cache_key, result_cache, RedisCache.CAHCETIME); -// LOG.info("put cache with key:" + cache_key); -// return result_cache; -// } + return null; } @Transactional @Override public void buyGoods(long userPhone, long goodsId, boolean useProcedure) { - // 用户校验 - User user = userDao.queryByPhone(userPhone); - if (user == null) { - throw new BizException(ResultEnum.INVALID_USER.getMsg()); - } - if (useProcedure) { - // 通过存储方式的方法进行操作 - Map map = new HashMap(); - map.put("userId", user.getUserId()); - map.put("goodsId", goodsId); - map.put("title", "抢购"); - map.put("result", null); - goodsDao.bugWithProcedure(map); - int result = MapUtils.getInteger(map, "result", -1); - if (result <= 0) { - // 买卖失败 - throw new BizException(ResultEnum.INNER_ERROR.getMsg()); - } else { - // 买卖成功 - // 此时缓存中的数据不是最新的,需要对缓存进行清理(具体的缓存策略还是要根据具体需求制定) - //cache.deleteCacheWithPattern("getGoodsList*"); - LOG.info("delete cache with key: getGoodsList*"); - return; - } - } else { - - int inserCount = orderDao.insertOrder(user.getUserId(), goodsId, "普通买卖"); - if (inserCount <= 0) { - // 买卖失败 - throw new BizException(ResultEnum.DB_UPDATE_RESULT_ERROR.getMsg()); - } else { - // 减库存 - int updateCount = goodsDao.reduceNumber(goodsId); - if (updateCount <= 0) { - // 减库存失败 - throw new BizException(ResultEnum.DB_UPDATE_RESULT_ERROR.getMsg()); - } else { - // 买卖成功 - // 此时缓存中的数据不再是最新的,需要对缓存进行清理(具体的缓存策略还是要根据具体需求制定) - //cache.deleteCacheWithPattern("getGoodsList*"); - LOG.info("delete cache with key: getGoodsList*"); - return; - } - } - } } } diff --git a/src/main/java/com/yingjun/ssm/service/impl/UserServiceImpl.java b/src/main/java/com/yingjun/ssm/service/impl/UserServiceImpl.java index 74967d42e5c76dfd6d6f9678fa6fee84f91b4d0f..7e6786335de90e18c7da234c91f19f054da51d88 100644 --- a/src/main/java/com/yingjun/ssm/service/impl/UserServiceImpl.java +++ b/src/main/java/com/yingjun/ssm/service/impl/UserServiceImpl.java @@ -1,37 +1,19 @@ package com.yingjun.ssm.service.impl; -import com.yingjun.ssm.dao.UserDao; + import com.yingjun.ssm.entity.User; import com.yingjun.ssm.service.UserService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; + import org.springframework.stereotype.Service; import java.util.List; @Service public class UserServiceImpl implements UserService { - - private final Logger LOG = LoggerFactory.getLogger(this.getClass()); - @Autowired - private UserDao userDao; - - @Override public List getUserList(int offset, int limit) { -// String cache_key=RedisCache.CAHCENAME+"|getUserList|"+offset+"|"+limit; -// //先去缓存中取 -// List result_cache=cache.getListCache(cache_key, User.class); -// if(result_cache==null){ -// //缓存中没有再去数据库取,并插入缓存(缓存时间为60秒) -// result_cache=userDao.queryAll(offset, limit); -// cache.putListCacheWithExpireTime(cache_key, result_cache, RedisCache.CAHCETIME); -// LOG.info("put cache with key:"+cache_key); -// }else{ -// LOG.info("get cache with key:"+cache_key); -// } + return null; }