Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Litemall
Commits
1cb9d20e
Commit
1cb9d20e
authored
Sep 06, 2018
by
Menethil
Browse files
Merge remote-tracking branch 'origin/master'
parents
c4f48302
96208795
Changes
45
Hide whitespace changes
Inline
Side-by-side
litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallUserService.java
View file @
1cb9d20e
...
...
@@ -39,8 +39,8 @@ public class LitemallUserService {
userMapper
.
insertSelective
(
user
);
}
public
void
update
(
LitemallUser
user
)
{
userMapper
.
updateByPrimaryKeySelective
(
user
);
public
int
update
(
LitemallUser
user
)
{
return
userMapper
.
update
WithVersion
ByPrimaryKeySelective
(
user
.
getVersion
(),
user
);
}
public
List
<
LitemallUser
>
querySelective
(
String
username
,
String
mobile
,
Integer
page
,
Integer
size
,
String
sort
,
String
order
)
{
...
...
litemall-db/src/test/java/org/linlinjava/litemall/db/MapperReturnTest.java
0 → 100644
View file @
1cb9d20e
package
org.linlinjava.litemall.db
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.linlinjava.litemall.db.dao.LitemallSystemMapper
;
import
org.linlinjava.litemall.db.domain.LitemallSystem
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
@WebAppConfiguration
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
public
class
MapperReturnTest
{
@Autowired
private
LitemallSystemMapper
systemMapper
;
@Test
public
void
test
()
{
LitemallSystem
system
=
new
LitemallSystem
();
system
.
setKeyName
(
"test-system-key"
);
system
.
setKeyValue
(
"test-system-value"
);
int
updates
=
systemMapper
.
insertSelective
(
system
);
Assert
.
assertEquals
(
updates
,
1
);
updates
=
systemMapper
.
deleteByPrimaryKey
(
system
.
getId
());
Assert
.
assertEquals
(
updates
,
1
);
updates
=
systemMapper
.
updateByPrimaryKey
(
system
);
Assert
.
assertEquals
(
updates
,
0
);
}
}
litemall-db/src/test/java/org/linlinjava/litemall/db/OptimisticLockTest.java
0 → 100644
View file @
1cb9d20e
package
org.linlinjava.litemall.db
;
import
org.junit.After
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.linlinjava.litemall.db.dao.LitemallSystemMapper
;
import
org.linlinjava.litemall.db.domain.LitemallSystem
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
/*
main线程先select,然后睡眠1s,最后做update
another线程则是先select,然后做update
main: select update 2
another: select update 3
如果没有乐观锁,那么最后main线程的update操作是成功的,最终数据库保存的值是2;
如果设置乐观锁,那么最后main线程的update操作是失败的,最终数据库保存的值是3。
在一些业务过程中,需要采用乐观锁,这样可以保证数据更新时不会出现问题。
*/
@WebAppConfiguration
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
public
class
OptimisticLockTest
{
@Autowired
private
LitemallSystemMapper
systemMapper
;
private
Integer
unlockId
;
private
Integer
lockId
;
@Before
public
void
before
()
{
LitemallSystem
unlockSystemConfig
=
new
LitemallSystem
();
unlockSystemConfig
.
setKeyName
(
"test-unlocksystem-key"
);
unlockSystemConfig
.
setKeyValue
(
"test-unlocksystem-value-1"
);
systemMapper
.
insertSelective
(
unlockSystemConfig
);
unlockId
=
unlockSystemConfig
.
getId
();
LitemallSystem
lockSystemConfig
=
new
LitemallSystem
();
lockSystemConfig
.
setKeyName
(
"test-locksystem-key"
);
lockSystemConfig
.
setKeyValue
(
"test-locksystem-value-1"
);
systemMapper
.
insertSelective
(
lockSystemConfig
);
lockId
=
lockSystemConfig
.
getId
();
}
@After
public
void
after
()
{
systemMapper
.
deleteByPrimaryKey
(
unlockId
);
unlockId
=
null
;
systemMapper
.
deleteByPrimaryKey
(
lockId
);
lockId
=
null
;
}
@Test
public
void
runWithOptimisticLock
()
{
LitemallSystem
mainSystem
=
systemMapper
.
selectByPrimaryKey
(
lockId
);
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
LitemallSystem
anotherSystem
=
systemMapper
.
selectByPrimaryKey
(
lockId
);
anotherSystem
.
setKeyValue
(
"test-locksystem-value-3"
);
systemMapper
.
updateWithVersionByPrimaryKey
(
anotherSystem
.
getVersion
(),
anotherSystem
);
}
}).
start
();
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
mainSystem
.
setKeyValue
(
"test-locksystem-value-2"
);
int
updates
=
systemMapper
.
updateWithVersionByPrimaryKey
(
mainSystem
.
getVersion
(),
mainSystem
);
Assert
.
assertEquals
(
updates
,
0
);
mainSystem
=
systemMapper
.
selectByPrimaryKey
(
lockId
);
Assert
.
assertNotEquals
(
mainSystem
.
getKeyValue
(),
"test-locksystem-value-2"
);
Assert
.
assertEquals
(
mainSystem
.
getKeyValue
(),
"test-locksystem-value-3"
);
}
@Test
public
void
runWithoutOptimisticLock
()
{
LitemallSystem
mainSystem
=
systemMapper
.
selectByPrimaryKey
(
unlockId
);
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
LitemallSystem
anotherSystem
=
systemMapper
.
selectByPrimaryKey
(
unlockId
);
anotherSystem
.
setKeyValue
(
"test-unlocksystem-value-3"
);
systemMapper
.
updateByPrimaryKey
(
anotherSystem
);
}
}).
start
();
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
mainSystem
.
setKeyValue
(
"test-unlocksystem-value-2"
);
int
updates
=
systemMapper
.
updateByPrimaryKey
(
mainSystem
);
Assert
.
assertEquals
(
updates
,
1
);
mainSystem
=
systemMapper
.
selectByPrimaryKey
(
unlockId
);
Assert
.
assertEquals
(
mainSystem
.
getKeyValue
(),
"test-unlocksystem-value-2"
);
Assert
.
assertNotEquals
(
mainSystem
.
getKeyValue
(),
"test-unlocksystem-value-3"
);
}
}
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxOrderController.java
View file @
1cb9d20e
...
...
@@ -509,7 +509,7 @@ public class WxOrderController {
// 设置订单已取消状态
order
.
setOrderStatus
(
OrderUtil
.
STATUS_CANCEL
);
order
.
setEndTime
(
LocalDateTime
.
now
());
orderService
.
update
(
order
);
orderService
.
update
ById
(
order
);
// 商品货品数量增加
List
<
LitemallOrderGoods
>
orderGoodsList
=
orderGoodsService
.
queryByOid
(
orderId
);
...
...
@@ -733,7 +733,7 @@ public class WxOrderController {
// 设置订单申请退款状态
order
.
setOrderStatus
(
OrderUtil
.
STATUS_REFUND
);
orderService
.
update
(
order
);
orderService
.
update
ById
(
order
);
//TODO 发送邮件和短信通知,这里采用异步发送
// 有用户申请退款,邮件通知运营人员
...
...
@@ -778,7 +778,7 @@ public class WxOrderController {
order
.
setOrderStatus
(
OrderUtil
.
STATUS_CONFIRM
);
order
.
setConfirmTime
(
LocalDateTime
.
now
());
orderService
.
update
(
order
);
orderService
.
update
ById
(
order
);
return
ResponseUtil
.
ok
();
}
...
...
litemall-wx/config/api.js
View file @
1cb9d20e
// 以下是业务服务器API地址
// 本机开发时使用
var
WxApiRoot
=
'
http://localhost:808
2
/wx/
'
;
var
WxApiRoot
=
'
http://localhost:808
0
/wx/
'
;
// 局域网测试使用
// var WxApiRoot = 'http://192.168.0.101:8080/wx/';
// 云平台部署时使用
// var WxApiRoot = 'http://122.152.206.172:8080/wx/';
// 云平台上线时使用
//var WxApiRoot = 'https://www.menethil.com.cn/wx/';
//
var WxApiRoot = 'https://www.menethil.com.cn/wx/';
module
.
exports
=
{
IndexUrl
:
WxApiRoot
+
'
home/index
'
,
//首页数据接口
...
...
Prev
1
2
3
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment