fix: 订单和商品服务错误修复

This commit is contained in:
hxr 2024-03-05 00:25:00 +08:00
parent f71ce019c0
commit 4b81b1e864
7 changed files with 57 additions and 61 deletions

View File

@ -50,7 +50,7 @@ public class OrderControllerTest {
@Autowired @Autowired
private RestTemplate restTemplate; private RestTemplate restTemplate;
private final String mobile = "18866668888";// 商城会员手机号 private final String mobile = "18866668888";// 商城会员手机号
private final String verifyCode = "666666";// 短信验证码666666是免校验验证码 private final String code = "666666";// 短信验证码666666是免校验验证码
private final Long skuId = 1L;// 购买商品ID private final Long skuId = 1L;// 购买商品ID
@ -61,7 +61,7 @@ public class OrderControllerTest {
void testPurchaseFlow_Normal() throws Exception { void testPurchaseFlow_Normal() throws Exception {
// 会员登录 // 会员登录
String accessToken = acquireTokenByLogin(mobile, verifyCode); // 获取 accessToken填充请求头用于身份认证 String accessToken = acquireTokenByLogin(mobile, code); // 获取 accessToken填充请求头用于身份认证
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.setBearerAuth(accessToken); headers.setBearerAuth(accessToken);
@ -86,7 +86,7 @@ public class OrderControllerTest {
void testPurchaseFlow_PaymentTimeout() throws Exception { void testPurchaseFlow_PaymentTimeout() throws Exception {
// 会员登录 // 会员登录
String accessToken = acquireTokenByLogin(mobile, verifyCode); // 获取 accessToken填充请求头用于身份认证 String accessToken = acquireTokenByLogin(mobile, code); // 获取 accessToken填充请求头用于身份认证
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.setBearerAuth(accessToken); headers.setBearerAuth(accessToken);
@ -204,10 +204,10 @@ public class OrderControllerTest {
* 登录获取访问令牌 * 登录获取访问令牌
* *
* @param mobile 手机号 * @param mobile 手机号
* @param verifyCode 短信验证码 * @param code 短信验证码
* @return * @return
*/ */
private String acquireTokenByLogin(String mobile, String verifyCode) { private String acquireTokenByLogin(String mobile, String code) {
String clientId = "mall-app"; String clientId = "mall-app";
String clientSecret = "123456"; String clientSecret = "123456";
String tokenUrl = "http://localhost:9000/oauth2/token"; String tokenUrl = "http://localhost:9000/oauth2/token";
@ -222,7 +222,7 @@ public class OrderControllerTest {
requestBody.add("client_id", clientId); requestBody.add("client_id", clientId);
requestBody.add("client_secret", clientSecret); requestBody.add("client_secret", clientSecret);
requestBody.add("mobile", mobile); requestBody.add("mobile", mobile);
requestBody.add("code", verifyCode); requestBody.add("code", code);
// 创建 Basic Auth 头部 // 创建 Basic Auth 头部
String authHeader = clientId + ":" + clientSecret; String authHeader = clientId + ":" + clientSecret;

View File

@ -30,8 +30,8 @@ public class PmsSpuController {
@Operation(summary = "商品分页列表") @Operation(summary = "商品分页列表")
@GetMapping("/page") @GetMapping("/page")
public PageResult getSpuPage(SpuPageQuery queryParams) { public PageResult listPagedSpu(SpuPageQuery queryParams) {
IPage<PmsSpuPageVO> result = spuService.getSpuPage(queryParams); IPage<PmsSpuPageVO> result = spuService.listPagedSpu(queryParams);
return PageResult.success(result); return PageResult.success(result);
} }

View File

@ -29,8 +29,8 @@ public class SpuController {
@Operation(summary = "商品分页列表") @Operation(summary = "商品分页列表")
@GetMapping("/pages") @GetMapping("/pages")
public PageResult getSpuPageForApp(SpuPageQuery queryParams) { public PageResult<SpuPageVO> listPagedSpuForApp(SpuPageQuery queryParams) {
IPage<SpuPageVO> result = spuService.getSpuPageForApp(queryParams); IPage<SpuPageVO> result = spuService.listPagedSpuForApp(queryParams);
return PageResult.success(result); return PageResult.success(result);
} }

View File

@ -16,20 +16,20 @@ public interface PmsSpuMapper extends BaseMapper<PmsSpu> {
/** /**
* Admin-商品分页列表 * Admin-商品分页列表
* *
* @param page * @param page 分页参数
* @param queryParams * @param queryParams 查询参数
* @return * @return 商品分页列表
*/ */
List<PmsSpuPageVO> getSpuPage(Page<PmsSpuPageVO> page, SpuPageQuery queryParams); List<PmsSpuPageVO> listPagedSpu(Page<PmsSpuPageVO> page, SpuPageQuery queryParams);
/** /**
* 应用端商品分页列表 * APP-商品分页列表
* *
* @param page * @param page 分页参数
* @param queryParams * @param queryParams 查询参数
* @return * @return 商品分页列表
*/ */
List<SpuPageVO> getSpuPageForApp(Page<SpuPageVO> page, SpuPageQuery queryParams); List<SpuPageVO> listPagedSpuForApp(Page<SpuPageVO> page, SpuPageQuery queryParams);
} }

View File

@ -24,7 +24,7 @@ public interface SpuService extends IService<PmsSpu> {
* @param queryParams * @param queryParams
* @return * @return
*/ */
IPage<PmsSpuPageVO> getSpuPage(SpuPageQuery queryParams); IPage<PmsSpuPageVO> listPagedSpu(SpuPageQuery queryParams);
/** /**
* 应用端商品分页列表 * 应用端商品分页列表
@ -32,7 +32,7 @@ public interface SpuService extends IService<PmsSpu> {
* @param queryParams * @param queryParams
* @return * @return
*/ */
IPage<SpuPageVO> getSpuPageForApp(SpuPageQuery queryParams); IPage<SpuPageVO> listPagedSpuForApp(SpuPageQuery queryParams);
/** /**

View File

@ -33,12 +33,11 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* 商品业务实现类 * 商品业务实现类
* *
* @author <a href="mailto:xianrui0365@163.com">haoxr</a> * @author Ray Hao
* @date 2021/8/8 * @since 2021/08/08
*/ */
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@ -47,35 +46,33 @@ public class SpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implements
private final SkuService skuService; private final SkuService skuService;
private final SpuAttributeService spuAttributeService; private final SpuAttributeService spuAttributeService;
private final MemberFeignClient memberFeignClient; private final MemberFeignClient memberFeignClient;
private final SpuConverter spuConverter; private final SpuConverter spuConverter;
private final SpuAttributeConverter spuAttributeConverter; private final SpuAttributeConverter spuAttributeConverter;
/** /**
* Admin-商品分页列表 * Admin-商品分页列表
* *
* @param queryParams * @param queryParams 查询参数
* @return * @return 商品分页列表 IPage<PmsSpuPageVO>
*/ */
@Override @Override
public IPage<PmsSpuPageVO> getSpuPage(SpuPageQuery queryParams) { public IPage<PmsSpuPageVO> listPagedSpu(SpuPageQuery queryParams) {
Page<PmsSpuPageVO> page = new Page<>(queryParams.getPageNum(), queryParams.getPageSize()); Page<PmsSpuPageVO> page = new Page<>(queryParams.getPageNum(), queryParams.getPageSize());
List<PmsSpuPageVO> list = this.baseMapper.getSpuPage(page, queryParams); List<PmsSpuPageVO> list = this.baseMapper.listPagedSpu(page, queryParams);
page.setRecords(list); page.setRecords(list);
return page; return page;
} }
/** /**
* 应用端商品分页列表 * APP-商品分页列表
* *
* @param queryParams * @param queryParams 查询参数
* @return * @return 商品分页列表 IPage<SpuPageVO>
*/ */
@Override @Override
public IPage<SpuPageVO> getSpuPageForApp(SpuPageQuery queryParams) { public IPage<SpuPageVO> listPagedSpuForApp(SpuPageQuery queryParams) {
Page<SpuPageVO> page = new Page<>(queryParams.getPageNum(), queryParams.getPageSize()); Page<SpuPageVO> page = new Page<>(queryParams.getPageNum(), queryParams.getPageSize());
List<SpuPageVO> list = this.baseMapper.getSpuPageForApp(page, queryParams); List<SpuPageVO> list = this.baseMapper.listPagedSpuForApp(page, queryParams);
page.setRecords(list); page.setRecords(list);
return page; return page;
} }
@ -84,7 +81,7 @@ public class SpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implements
* App-获取商品详情 * App-获取商品详情
* *
* @param spuId 商品ID * @param spuId 商品ID
* @return * @return 商品详情
*/ */
@Override @Override
public SpuDetailVO getSpuDetailForApp(Long spuId) { public SpuDetailVO getSpuDetailForApp(Long spuId) {
@ -178,7 +175,7 @@ public class SpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implements
* 获取商品详情 * 获取商品详情
* *
* @param spuId 商品ID * @param spuId 商品ID
* @return * @return 商品详情
*/ */
@Override @Override
public PmsSpuDetailVO getSpuDetail(Long spuId) { public PmsSpuDetailVO getSpuDetail(Long spuId) {
@ -212,8 +209,8 @@ public class SpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implements
/** /**
* 添加商品 * 添加商品
* *
* @param formData * @param formData 商品表单
* @return * @return 是否成功
*/ */
@Override @Override
@Transactional @Transactional
@ -245,7 +242,7 @@ public class SpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implements
* *
* @param spuId 商品ID * @param spuId 商品ID
* @param formData 商品表单 * @param formData 商品表单
* @return * @return 是否成功
*/ */
@Transactional @Transactional
@Override @Override
@ -277,7 +274,7 @@ public class SpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implements
* 删除商品 * 删除商品
* *
* @param ids 商品ID多个以英文逗号(,)分割 * @param ids 商品ID多个以英文逗号(,)分割
* @return * @return 是否成功
*/ */
@Override @Override
@Transactional @Transactional
@ -301,7 +298,7 @@ public class SpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implements
/** /**
* 获取商品秒杀接口 * 获取商品秒杀接口
* *
* @return * @return 商品秒杀列表
*/ */
@Override @Override
public List<SeckillingSpuVO> listSeckillingSpu() { public List<SeckillingSpuVO> listSeckillingSpu() {
@ -309,27 +306,26 @@ public class SpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implements
.select(PmsSpu::getId, PmsSpu::getName, PmsSpu::getPicUrl, PmsSpu::getPrice) .select(PmsSpu::getId, PmsSpu::getName, PmsSpu::getPicUrl, PmsSpu::getPrice)
.orderByDesc(PmsSpu::getCreateTime) .orderByDesc(PmsSpu::getCreateTime)
); );
List<SeckillingSpuVO> list = spuConverter.entity2SeckillingVO(entities); return spuConverter.entity2SeckillingVO(entities);
return list;
} }
/** /**
* 保存SKU需要替换提交表单中的临时规格ID * 保存SKU需要替换提交表单中的临时规格ID
* *
* @param goodsId * @param spuId 商品ID
* @param skuList * @param skuList SKU列表
* @param specTempIdIdMap * @param specTempIdIdMap 临时规格ID和持久化数据库得到的规格ID的映射
* @return * @return 是否成功
*/ */
private boolean saveSku(Long goodsId, List<PmsSku> skuList, Map<String, Long> specTempIdIdMap) { private boolean saveSku(Long spuId, List<PmsSku> skuList, Map<String, Long> specTempIdIdMap) {
// 删除SKU // 删除SKU
List<Long> formSkuIds = skuList.stream().map(PmsSku::getId).collect(Collectors.toList()); List<Long> formSkuIds = skuList.stream().map(PmsSku::getId).toList();
List<Long> dbSkuIds = skuService.list(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, goodsId) List<Long> dbSkuIds = skuService.list(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, spuId)
.select(PmsSku::getId)).stream().map(PmsSku::getId) .select(PmsSku::getId)).stream().map(PmsSku::getId)
.collect(Collectors.toList()); .toList();
List<Long> removeSkuIds = dbSkuIds.stream().filter(dbSkuId -> !formSkuIds.contains(dbSkuId)).collect(Collectors.toList()); List<Long> removeSkuIds = dbSkuIds.stream().filter(dbSkuId -> !formSkuIds.contains(dbSkuId)).collect(Collectors.toList());
@ -344,7 +340,7 @@ public class SpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implements
.map(specId -> specId.startsWith(ProductConstants.SPEC_TEMP_ID_PREFIX) ? specTempIdIdMap.get(specId) + "" : specId) .map(specId -> specId.startsWith(ProductConstants.SPEC_TEMP_ID_PREFIX) ? specTempIdIdMap.get(specId) + "" : specId)
.collect(Collectors.joining("_")); .collect(Collectors.joining("_"));
sku.setSpecIds(specIds); sku.setSpecIds(specIds);
sku.setSpuId(goodsId); sku.setSpuId(spuId);
return sku; return sku;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
return skuService.saveOrUpdateBatch(pmsSkuList); return skuService.saveOrUpdateBatch(pmsSkuList);
@ -366,14 +362,14 @@ public class SpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implements
List<Long> retainAttrIds = attrList.stream() List<Long> retainAttrIds = attrList.stream()
.filter(item -> item.getId() != null) .filter(item -> item.getId() != null)
.map(item -> Convert.toLong(item.getId())) .map(item -> Convert.toLong(item.getId()))
.collect(Collectors.toList()); .toList();
// 1.2 获取原商品属性ID集合 // 1.2 获取原商品属性ID集合
List<Long> originAttrIds = spuAttributeService.list(new LambdaQueryWrapper<PmsSpuAttribute>() List<Long> originAttrIds = spuAttributeService.list(new LambdaQueryWrapper<PmsSpuAttribute>()
.eq(PmsSpuAttribute::getSpuId, spuId).eq(PmsSpuAttribute::getType, AttributeTypeEnum.ATTR.getValue()) .eq(PmsSpuAttribute::getSpuId, spuId).eq(PmsSpuAttribute::getType, AttributeTypeEnum.ATTR.getValue())
.select(PmsSpuAttribute::getId)) .select(PmsSpuAttribute::getId))
.stream() .stream()
.map(PmsSpuAttribute::getId) .map(PmsSpuAttribute::getId)
.collect(Collectors.toList()); .toList();
// 1.3 需要删除的商品属性原商品属性-此次提交保留的属性 // 1.3 需要删除的商品属性原商品属性-此次提交保留的属性
List<Long> removeAttrValIds = originAttrIds.stream() List<Long> removeAttrValIds = originAttrIds.stream()
.filter(id -> !retainAttrIds.contains(id)) .filter(id -> !retainAttrIds.contains(id))
@ -413,7 +409,7 @@ public class SpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implements
List<Long> retainSpuSpecIds = specList.stream() List<Long> retainSpuSpecIds = specList.stream()
.filter(item -> !item.getId().startsWith(ProductConstants.SPEC_TEMP_ID_PREFIX)) .filter(item -> !item.getId().startsWith(ProductConstants.SPEC_TEMP_ID_PREFIX))
.map(item -> Convert.toLong(item.getId())) .map(item -> Convert.toLong(item.getId()))
.collect(Collectors.toList()); .toList();
// 1.2 原商品规格 // 1.2 原商品规格
List<Long> originSpuSpecIds = spuAttributeService.list(new LambdaQueryWrapper<PmsSpuAttribute>() List<Long> originSpuSpecIds = spuAttributeService.list(new LambdaQueryWrapper<PmsSpuAttribute>()
@ -421,7 +417,7 @@ public class SpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implements
.eq(PmsSpuAttribute::getType, AttributeTypeEnum.SPEC.getValue()) .eq(PmsSpuAttribute::getType, AttributeTypeEnum.SPEC.getValue())
.select(PmsSpuAttribute::getId)) .select(PmsSpuAttribute::getId))
.stream().map(PmsSpuAttribute::getId) .stream().map(PmsSpuAttribute::getId)
.collect(Collectors.toList()); .toList();
// 1.3 需要删除的商品规格原商品规格-此次提交保留的规格 // 1.3 需要删除的商品规格原商品规格-此次提交保留的规格
List<Long> removeSpuSpecIds = originSpuSpecIds.stream().filter(id -> !retainSpuSpecIds.contains(id)) List<Long> removeSpuSpecIds = originSpuSpecIds.stream().filter(id -> !retainSpuSpecIds.contains(id))

View File

@ -33,7 +33,7 @@
</resultMap> </resultMap>
<!--Admin-商品分页列表--> <!--Admin-商品分页列表-->
<select id="getSpuPage" resultMap="BaseResultMap"> <select id="listPagedSpu" resultMap="BaseResultMap">
SELECT SELECT
t1.id, t1.id,
t1.name, t1.name,
@ -65,7 +65,7 @@
<!--「应用端」商品分页列表--> <!--「应用端」商品分页列表-->
<select id="listSpuPages" resultType="com.youlai.mall.pms.model.vo.SpuPageVO"> <select id="listPagedSpuForApp" resultType="com.youlai.mall.pms.model.vo.SpuPageVO">
SELECT SELECT
id, id,
NAME, NAME,
@ -84,7 +84,7 @@
</where> </where>
ORDER BY ORDER BY
<if test='queryParams.sortField!=null and queryParams.sortField.trim() neq "" and queryParams.sortField !=null and queryParams.sort.trim() neq ""'> <if test='queryParams.sortField!=null and queryParams.sortField.trim() neq "" and queryParams.sortField !=null and queryParams.sort.trim() neq ""'>
#{queryParams.sortField} #{queryParams.sort} , ${queryParams.sortField} ${queryParams.sort} ,
</if> </if>
create_time desc create_time desc
</select> </select>