Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wanbang-java
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
单欣鑫
wanbang-java
Commits
95961974
Commit
95961974
authored
Aug 25, 2026
by
haoxuyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
去掉无用的 javascript ,处理首页查询商品,更新历史搜索记录导致行锁的问题
parent
c745b0a1
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
90 additions
and
77 deletions
+90
-77
MallSalesmanController.java
...ava/com/ruoyi/mall/controller/MallSalesmanController.java
+0
-1
MallMemberSearchHistoryMapper.java
.../com/ruoyi/mall/mapper/MallMemberSearchHistoryMapper.java
+6
-0
IMallMemberSearchHistoryService.java
...m/ruoyi/mall/service/IMallMemberSearchHistoryService.java
+5
-0
IMallSalesmanService.java
...ain/java/com/ruoyi/mall/service/IMallSalesmanService.java
+0
-1
MallGoodsGoodsServiceImpl.java
...om/ruoyi/mall/service/impl/MallGoodsGoodsServiceImpl.java
+51
-74
MallMemberSearchHistoryServiceImpl.java
...mall/service/impl/MallMemberSearchHistoryServiceImpl.java
+19
-0
MallSalesmanServiceImpl.java
.../com/ruoyi/mall/service/impl/MallSalesmanServiceImpl.java
+0
-1
MallMemberSearchHistoryMapper.xml
...n/resources/mapper/mall/MallMemberSearchHistoryMapper.xml
+9
-0
No files found.
xiaoniu-admin/src/main/java/com/ruoyi/mall/controller/MallSalesmanController.java
View file @
95961974
...
...
@@ -13,7 +13,6 @@ import com.ruoyi.mall.domain.MallShopShop;
import
com.ruoyi.mall.service.IMallMemberUserService
;
import
com.ruoyi.mall.service.IMallShopShopService
;
import
com.ruoyi.system.service.ISysUserService
;
import
netscape.javascript.JSObject
;
import
org.apache.commons.lang3.ObjectUtils
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
xiaoniu-system/src/main/java/com/ruoyi/mall/mapper/MallMemberSearchHistoryMapper.java
View file @
95961974
package
com
.
ruoyi
.
mall
.
mapper
;
import
java.util.List
;
import
org.apache.ibatis.annotations.Param
;
import
com.ruoyi.mall.domain.MallMemberSearchHistory
;
import
com.ruoyi.mall.domain.MallMemberSearchHistoryDto
;
...
...
@@ -28,6 +29,11 @@ public interface MallMemberSearchHistoryMapper
*/
public
List
<
MallMemberSearchHistoryDto
>
selectMallMemberSearchHistoryList
(
MallMemberSearchHistory
mallMemberSearchHistory
);
/**
* 按用户+搜索词精确匹配最近一条
*/
MallMemberSearchHistory
selectByUserIdAndGoodName
(
@Param
(
"userId"
)
Long
userId
,
@Param
(
"goodName"
)
String
goodName
);
/**
* 新增mall
*
...
...
xiaoniu-system/src/main/java/com/ruoyi/mall/service/IMallMemberSearchHistoryService.java
View file @
95961974
...
...
@@ -36,6 +36,11 @@ public interface IMallMemberSearchHistoryService
*/
public
int
insertMallMemberSearchHistory
(
MallMemberSearchHistory
mallMemberSearchHistory
);
/**
* 记录或刷新用户搜索词(独立短事务,避免拖住商品列表)
*/
void
saveOrTouchSearchHistory
(
Long
userId
,
String
goodName
);
/**
* 修改mall
*
...
...
xiaoniu-system/src/main/java/com/ruoyi/mall/service/IMallSalesmanService.java
View file @
95961974
...
...
@@ -7,7 +7,6 @@ import com.alibaba.fastjson.JSONObject;
import
com.ruoyi.common.core.domain.AjaxResult
;
import
com.ruoyi.common.utils.ApiResult
;
import
com.ruoyi.mall.domain.MallSalesman
;
import
netscape.javascript.JSObject
;
/**
* 业务员Service接口
...
...
xiaoniu-system/src/main/java/com/ruoyi/mall/service/impl/MallGoodsGoodsServiceImpl.java
View file @
95961974
...
...
@@ -7,7 +7,6 @@ import com.ruoyi.common.core.domain.model.LoginUser;
import
com.ruoyi.common.utils.DateUtils
;
import
com.ruoyi.common.utils.SecurityUtils
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.utils.bean.BeanUtils
;
import
com.ruoyi.mall.domain.*
;
import
com.ruoyi.mall.domain.VO.SeckillGoodsVO
;
import
com.ruoyi.mall.domain.vo.GoodsProductVO
;
...
...
@@ -17,8 +16,9 @@ import com.ruoyi.mall.domain.vo.MemberCollectVO;
import
com.ruoyi.mall.mapper.*
;
import
com.ruoyi.mall.service.*
;
import
org.apache.commons.lang3.ObjectUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -27,9 +27,9 @@ import java.math.BigDecimal;
import
java.math.RoundingMode
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.CountDownLatch
;
/**
* 商品Service业务层处理
...
...
@@ -39,6 +39,9 @@ import java.util.concurrent.CountDownLatch;
*/
@Service
public
class
MallGoodsGoodsServiceImpl
implements
IMallGoodsGoodsService
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
MallGoodsGoodsServiceImpl
.
class
);
@Resource
private
MallGoodsGoodsMapper
mallGoodsGoodsMapper
;
@Resource
...
...
@@ -65,8 +68,6 @@ public class MallGoodsGoodsServiceImpl implements IMallGoodsGoodsService {
IMallGoodsProductService
mallGoodsProductService
;
@Resource
private
MallShopSupplierMapper
mallShopSupplierMapper
;
@Resource
private
ThreadPoolTaskExecutor
threadPoolTaskExecutor
;
/**
* 查询商品
...
...
@@ -185,51 +186,44 @@ public class MallGoodsGoodsServiceImpl implements IMallGoodsGoodsService {
* @param mallGoodsGoods 商品
* @return 商品
*/
@Transactional
@Override
public
PageInfo
<
IndexGoodsVO
>
selectMallGoodsGoodsListByPage
(
Integer
pageNum
,
Integer
pageSize
,
MallGoodsGoodsDTO
mallGoodsGoods
,
String
userId
)
{
if
(!
StringUtils
.
isEmpty
(
mallGoodsGoods
.
getGoodsName
())
&&
!
StringUtils
.
isEmpty
(
userId
))
{
MallMemberSearchHistory
search
=
new
MallMemberSearchHistory
();
search
.
setGoodName
(
mallGoodsGoods
.
getGoodsName
());
search
.
setUserId
(
Long
.
parseLong
(
userId
));
List
<
MallMemberSearchHistoryDto
>
list
=
searchHistoryService
.
selectMallMemberSearchHistoryList
(
search
);
if
(
list
.
size
()
>
0
)
{
MallMemberSearchHistoryDto
mallMemberSearchHistory
=
list
.
get
(
0
);
MallMemberSearchHistory
result
=
new
MallMemberSearchHistory
();
BeanUtils
.
copyProperties
(
mallMemberSearchHistory
,
result
);
result
.
setCreateAt
(
DateUtils
.
getTime
());
searchHistoryService
.
updateMallMemberSearchHistory
(
result
);
}
else
{
MallMemberSearchHistory
searchHistory
=
new
MallMemberSearchHistory
();
searchHistory
.
setCreateAt
(
DateUtils
.
getTime
());
searchHistory
.
setGoodName
(
mallGoodsGoods
.
getGoodsName
());
searchHistory
.
setUserId
(
Long
.
parseLong
(
userId
));
searchHistoryService
.
insertMallMemberSearchHistory
(
searchHistory
);
}
}
saveSearchHistoryQuietly
(
mallGoodsGoods
,
userId
);
PageHelper
.
startPage
(
pageNum
,
pageSize
);
// List<IndexGoodsVO> list = mallGoodsGoodsMapper.selectMallGoodsGoodsListVO(mallGoodsGoods);
List
<
IndexGoodsVO
>
list
=
mallGoodsGoodsMapper
.
selectMallGoodsGoodsListDTO
(
mallGoodsGoods
);
if
(!
list
.
isEmpty
())
{
MallMemberUser
mallMemberUser
=
new
MallMemberUser
();
// 用户信息
MallMemberUser
mallMemberUser
=
null
;
if
(
StringUtils
.
isNotBlank
(
userId
))
{
mallMemberUser
=
userService
.
selectMallMemberUserById
(
Long
.
parseLong
(
userId
));
}
for
(
IndexGoodsVO
indexGoodsVO
:
list
)
{
fillGoodsSpecAndPrice
(
indexGoodsVO
,
mallMemberUser
);
}
}
return
new
PageInfo
<>(
list
);
}
private
void
saveSearchHistoryQuietly
(
MallGoodsGoodsDTO
mallGoodsGoods
,
String
userId
)
{
if
(
mallGoodsGoods
==
null
||
StringUtils
.
isEmpty
(
mallGoodsGoods
.
getGoodsName
())
||
StringUtils
.
isEmpty
(
userId
))
{
return
;
}
try
{
CountDownLatch
countDownLatch
=
new
CountDownLatch
(
list
.
size
());
for
(
IndexGoodsVO
indexGoodsVO
:
list
)
{
MallMemberUser
finalMallMemberUser
=
mallMemberUser
;
threadPoolTaskExecutor
.
execute
(()
->
{
searchHistoryService
.
saveOrTouchSearchHistory
(
Long
.
parseLong
(
userId
),
mallGoodsGoods
.
getGoodsName
());
}
catch
(
Exception
e
)
{
log
.
warn
(
"保存搜索历史失败, userId={}, keyword={}"
,
userId
,
mallGoodsGoods
.
getGoodsName
(),
e
);
}
}
Long
goodsId
=
indexGoodsVO
.
getId
();
//规格列表
//indexGoodsVO.setProList(mallGoodsProductMapper.selectMallGoodsProductByGoodsIdVO(goodsId));
List
<
GoodsProductVO
>
proList
=
mallGoodsProductMapper
.
selectMallGoodsProductByGoodsIdVO
(
goodsId
);
private
void
fillGoodsSpecAndPrice
(
IndexGoodsVO
indexGoodsVO
,
MallMemberUser
mallMemberUser
)
{
List
<
GoodsProductVO
>
proList
=
mallGoodsProductMapper
.
selectMallGoodsProductByGoodsIdVO
(
indexGoodsVO
.
getId
());
if
(
proList
==
null
)
{
proList
=
Collections
.
emptyList
();
}
indexGoodsVO
.
setProList
(
proList
);
// VIP价
if
(
finalMallMemberUser
!=
null
&&
"1"
.
equals
(
finalMallMemberUser
.
getVip
()))
{
if
(
proList
.
isEmpty
())
{
return
;
}
if
(
mallMemberUser
!=
null
&&
"1"
.
equals
(
mallMemberUser
.
getVip
()))
{
if
(
proList
.
size
()
>
1
)
{
indexGoodsVO
.
setVipPriceRangeHigh
(
proList
.
get
(
0
).
getPriceVip
().
toString
());
indexGoodsVO
.
setVipPriceRangeLow
(
proList
.
get
(
proList
.
size
()
-
1
).
getPriceVip
().
toString
());
...
...
@@ -240,32 +234,15 @@ public class MallGoodsGoodsServiceImpl implements IMallGoodsGoodsService {
}
else
{
indexGoodsVO
.
setPriceVip
(
null
);
}
if
(
proList
.
size
()
>=
1
)
{
indexGoodsVO
.
setPriceRangeHigh
(
proList
.
get
(
0
).
getPrice
().
toString
());
indexGoodsVO
.
setPriceRangeLow
(
proList
.
get
(
proList
.
size
()
-
1
).
getPrice
().
toString
());
if
(
indexGoodsVO
.
getKilograms
()!=
null
)
{
if
(
indexGoodsVO
.
getKilograms
()
!=
null
&&
indexGoodsVO
.
getKilograms
()>
0
)
{
BigDecimal
kilograms
=
new
BigDecimal
(
indexGoodsVO
.
getKilograms
());
BigDecimal
pricePerKg
=
proList
.
get
(
0
).
getPrice
()
.
divide
(
kilograms
,
2
,
RoundingMode
.
HALF_UP
)
.
divide
(
new
BigDecimal
(
2
),
2
,
RoundingMode
.
HALF_UP
);
BigDecimal
bigDecimal
=
pricePerKg
.
setScale
(
2
,
RoundingMode
.
HALF_UP
);
indexGoodsVO
.
setKilogramsPrice
(
bigDecimal
);
}
}
else
{
indexGoodsVO
.
setPriceRangeHigh
(
proList
.
get
(
0
).
getPrice
().
toString
());
indexGoodsVO
.
setPriceRangeLow
(
indexGoodsVO
.
getPriceRangeHigh
());
}
countDownLatch
.
countDown
();
});
}
countDownLatch
.
await
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
indexGoodsVO
.
setKilogramsPrice
(
pricePerKg
.
setScale
(
2
,
RoundingMode
.
HALF_UP
));
}
PageInfo
<
IndexGoodsVO
>
pageInfo
=
new
PageInfo
<>(
list
);
return
pageInfo
;
}
...
...
xiaoniu-system/src/main/java/com/ruoyi/mall/service/impl/MallMemberSearchHistoryServiceImpl.java
View file @
95961974
package
com
.
ruoyi
.
mall
.
service
.
impl
;
import
com.ruoyi.common.utils.DateUtils
;
import
com.ruoyi.mall.domain.MallMemberSearchHistory
;
import
com.ruoyi.mall.domain.MallMemberSearchHistoryDto
;
import
com.ruoyi.mall.mapper.MallMemberSearchHistoryMapper
;
import
com.ruoyi.mall.service.IMallMemberSearchHistoryService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
...
...
@@ -53,6 +56,22 @@ public class MallMemberSearchHistoryServiceImpl implements IMallMemberSearchHist
return
mallMemberSearchHistoryMapper
.
insertMallMemberSearchHistory
(
mallMemberSearchHistory
);
}
@Override
@Transactional
(
propagation
=
Propagation
.
REQUIRES_NEW
,
rollbackFor
=
Exception
.
class
)
public
void
saveOrTouchSearchHistory
(
Long
userId
,
String
goodName
)
{
MallMemberSearchHistory
exist
=
mallMemberSearchHistoryMapper
.
selectByUserIdAndGoodName
(
userId
,
goodName
);
if
(
exist
!=
null
)
{
exist
.
setCreateAt
(
DateUtils
.
getTime
());
mallMemberSearchHistoryMapper
.
updateMallMemberSearchHistory
(
exist
);
return
;
}
MallMemberSearchHistory
searchHistory
=
new
MallMemberSearchHistory
();
searchHistory
.
setUserId
(
userId
);
searchHistory
.
setGoodName
(
goodName
);
searchHistory
.
setCreateAt
(
DateUtils
.
getTime
());
mallMemberSearchHistoryMapper
.
insertMallMemberSearchHistory
(
searchHistory
);
}
/**
* 修改mall
*
...
...
xiaoniu-system/src/main/java/com/ruoyi/mall/service/impl/MallSalesmanServiceImpl.java
View file @
95961974
...
...
@@ -30,7 +30,6 @@ import com.ruoyi.system.mapper.SysDictDataMapper;
import
com.ruoyi.system.mapper.SysUserMapper
;
import
com.ruoyi.system.mapper.SysUserPostMapper
;
import
com.ruoyi.system.mapper.SysUserRoleMapper
;
import
netscape.javascript.JSObject
;
import
org.apache.commons.collections4.MapUtils
;
import
org.apache.commons.lang3.ObjectUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
xiaoniu-system/src/main/resources/mapper/mall/MallMemberSearchHistoryMapper.xml
View file @
95961974
...
...
@@ -37,6 +37,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by create_at desc
</select>
<select
id=
"selectByUserIdAndGoodName"
resultMap=
"MallMemberSearchHistoryResult"
>
select id, user_id, good_name, create_at
from mall_member_search_history
where user_id = #{userId}
and good_name = #{goodName}
order by id desc
limit 1
</select>
<select
id=
"selectMallMemberSearchHistoryById"
parameterType=
"Long"
resultMap=
"MallMemberSearchHistoryResult"
>
<include
refid=
"selectMallMemberSearchHistoryVo"
/>
where id = #{id}
...
...
Write
Preview
Markdown
is supported
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