Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
beauty_ssm
提交
004eeddc
B
beauty_ssm
项目概览
爱吃血肠
/
beauty_ssm
通知
9
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
beauty_ssm
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
004eeddc
编写于
3月 03, 2018
作者:
爱吃血肠
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
剔除无用代码
上级
20da96bd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
11 addition
and
93 deletion
+11
-93
src/main/java/com/yingjun/ssm/service/impl/GoodsServiceImpl.java
...n/java/com/yingjun/ssm/service/impl/GoodsServiceImpl.java
+8
-72
src/main/java/com/yingjun/ssm/service/impl/UserServiceImpl.java
...in/java/com/yingjun/ssm/service/impl/UserServiceImpl.java
+3
-21
未找到文件。
src/main/java/com/yingjun/ssm/service/impl/GoodsServiceImpl.java
浏览文件 @
004eeddc
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
<
Goods
>
getGoodsList
(
int
offset
,
int
limit
)
{
// String cache_key = RedisCache.CAHCENAME + "|getGoodsList|" + offset + "|" + limit;
// List<Goods> 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
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
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
;
}
}
}
}
}
src/main/java/com/yingjun/ssm/service/impl/UserServiceImpl.java
浏览文件 @
004eeddc
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
<
User
>
getUserList
(
int
offset
,
int
limit
)
{
// String cache_key=RedisCache.CAHCENAME+"|getUserList|"+offset+"|"+limit;
// //先去缓存中取
// List<User> 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
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录