微信小程序分类查询(优惠券错误)完成

This commit is contained in:
yovinchen 2023-09-29 00:50:27 +08:00
parent fb902f09da
commit 211f1028f2
23 changed files with 286 additions and 72 deletions

View File

@ -16,6 +16,7 @@
<module name="service-sys" />
<module name="service-user-client" />
<module name="service-util" />
<module name="service-activity-client" />
<module name="service-acl" />
<module name="service-product" />
<module name="service-user" />
@ -33,6 +34,7 @@
<module name="service" options="" />
<module name="service-acl" options="-parameters" />
<module name="service-activity" options="-parameters" />
<module name="service-activity-client" options="-parameters" />
<module name="service-client" options="" />
<module name="service-gateway" options="-parameters" />
<module name="service-home" options="-parameters" />

View File

@ -7,6 +7,7 @@
<file url="file://$PROJECT_DIR$/guigu-ssyx-parent/common/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/guigu-ssyx-parent/common/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/guigu-ssyx-parent/model/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/guigu-ssyx-parent/service-client/service-activity-client/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/guigu-ssyx-parent/service-client/service-product-client/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/guigu-ssyx-parent/service-client/service-search-client/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/guigu-ssyx-parent/service-client/service-user-client/src/main/java" charset="UTF-8" />

View File

@ -1,17 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="nacos-service" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/nacos/bin/startup.sh" />
<option name="SCRIPT_OPTIONS" value="-m standalone" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$/nacos" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="/bin/bash" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="true" />
<envs />
<method v="2" />
</configuration>
</component>

View File

@ -902,7 +902,6 @@
return lang;
}
}
// export function initI18n() {
// const localeKeys = Object.keys(__uniConfig.locales || {})
// if (localeKeys.length) {
@ -9096,7 +9095,6 @@
var OBJECTTYPE = '[object Object]';
var NULLTYPE = '[object Null]';
var UNDEFINEDTYPE = '[object Undefined]';
// const FUNCTIONTYPE = '[object Function]'
function diff(current, pre) {
@ -10886,7 +10884,6 @@
exports.default = void 0;
var _typeof2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/typeof */ 13));
var _deepClone = _interopRequireDefault(__webpack_require__(/*! ./deepClone */ 37));
// JS对象深度合并
function deepMerge() {
var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@ -10938,7 +10935,6 @@
});
exports.default = void 0;
var _typeof2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/typeof */ 13));
// 判断arr是否为一个数组返回一个bool值
function isArray(arr) {
return Object.prototype.toString.call(arr) === '[object Array]';
@ -11293,7 +11289,7 @@
};
for (var key in data) {
var _ret = _loop(key);
if (_ret === "continue") continue;
if (_ret === "continue") ;
}
return _result.length ? prefix + _result.join('&') : '';
}
@ -22354,9 +22350,9 @@
if (ret) {
fmt = fmt.replace(ret[1], ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, "0"));
}
;
}
;
return fmt;
}
@ -22511,7 +22507,7 @@
return sColor;
}
}
;
// 将rgb表示方式转换为hex表示方式
function rgbToHex(rgb) {
@ -22797,7 +22793,6 @@
value: true
});
exports.default = void 0;
// 打乱数组
function randomArray() {
var array = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
@ -22829,7 +22824,6 @@
});
exports.default = addUnit;
var _test = _interopRequireDefault(__webpack_require__(/*! ./test.js */ 38));
// 添加单位如果有rpx%px等单位结尾或者值为auto直接返回否则加上rpx单位结尾
function addUnit() {
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'auto';
@ -23069,7 +23063,7 @@
function os() {
return uni.getSystemInfoSync().platform;
}
;
function sys() {
return uni.getSystemInfoSync();
@ -23178,7 +23172,7 @@
}
}
}
;
var _default = throttle;
exports.default = _default;
@ -25794,7 +25788,7 @@
if (Object(_i) !== _i) return;
_n = !1;
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) {
;
}
} catch (err) {
_d = !0, _e = err;

View File

@ -15,6 +15,7 @@
<module>service-product-client</module>
<module>service-user-client</module>
<module>service-search-client</module>
<module>service-activity-client</module>
</modules>
<dependencies>
<dependency>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.atguigu</groupId>
<artifactId>service-client</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>service-activity-client</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -0,0 +1,22 @@
package com.atguigu.ssyx.client.activity;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
import java.util.Map;
/**
* ClassName: ActivityFeignClient
* Package: com.atguigu.ssyx.client.activity
*
* @author yovinchen
* @Create 2023/9/26 14:10
*/
@FeignClient(value = "service-activity")
public interface ActivityFeignClient {
@PostMapping("/api/activity/inner/findActivity")
Map<Long, List<String>> findActivity(@RequestBody List<Long> skuIdList);
}

View File

@ -22,5 +22,5 @@ public interface UserFeignClient {
* @return
*/
@GetMapping("/api/user/leader/inner/getUserAddressByUserId/{userId}")
LeaderAddressVo getUserAddressByUserId(@PathVariable(value = "userId") Long userId);
LeaderAddressVo getUserAddressByUserId(@PathVariable("userId") Long userId);
}

View File

@ -0,0 +1,37 @@
package com.atguigu.ssyx.activity.api;
import com.atguigu.ssyx.activity.service.ActivityInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
* ClassName: ActivityInfoController
* Package: com.atguigu.ssyx.activity.api
*
* @author yovinchen
* @Create 2023/9/26 14:12
*/
@Api(tags = "促销与优惠券接口")
@RestController
@RequestMapping("/api/activity")
@Slf4j
public class ActivityApiController {
@Resource
private ActivityInfoService activityInfoService;
@ApiOperation(value = "根据skuId列表获取促销信息")
@PostMapping("inner/findActivity")
public Map<Long, List<String>> findActivity(@RequestBody List<Long> skuIdList) {
return activityInfoService.findActivity(skuIdList);
}
}

View File

@ -19,7 +19,19 @@ import java.util.List;
@Repository
public interface ActivityInfoMapper extends BaseMapper<ActivityInfo> {
List<ActivityRule> selectActivityRuleList(Long skuId);
/**
* 查询两张表判断 activity_info activity_sku编写SQL语句实现
*
* @param skuIdList
* @return
*/
List<Long> selectSkuIdListExist(@Param("skuIdList") List<Long> skuIdList);
/**
* 根据skuId进行查询查询sku对应活动里面规则列表
*
* @param skuId
* @return
*/
List<ActivityRule> findActivityRule(Long skuId);
}

View File

@ -2,7 +2,6 @@ package com.atguigu.ssyx.activity.service;
import com.atguigu.ssyx.model.activity.ActivityInfo;
import com.atguigu.ssyx.model.activity.ActivityRule;
import com.atguigu.ssyx.model.product.SkuInfo;
import com.atguigu.ssyx.vo.activity.ActivityRuleVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
@ -55,10 +54,10 @@ public interface ActivityInfoService extends IService<ActivityInfo> {
List<SkuInfo> findSkuInfoByKeyword(String keyword);
/**
* 根据skuId获取促销规则信息
* 根据skuId列表获取促销信息
*
* @param skuId
* @param skuIdList
* @return
*/
List<ActivityRule> findActivityRule(Long skuId);
Map<Long, List<String>> findActivity(List<Long> skuIdList);
}

View File

@ -172,23 +172,6 @@ public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, Act
return findSkuList;
}
/**
* 查询商品获取规则数据
*
* @param skuId
* @return
*/
@Override
public List<ActivityRule> findActivityRule(Long skuId) {
List<ActivityRule> activityRuleList = activityInfoMapper.selectActivityRuleList(skuId);
if (!CollectionUtils.isEmpty(activityRuleList)) {
for (ActivityRule activityRule : activityRuleList) {
activityRule.setRuleDesc(this.getRuleDesc(activityRule));
}
}
return activityRuleList;
}
private String getRuleDesc(ActivityRule activityRule) {
ActivityType activityType = activityRule.getActivityType();
StringBuffer ruleDesc = new StringBuffer();
@ -207,4 +190,32 @@ public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, Act
}
return ruleDesc.toString();
}
/**
* 根据skuId列表获取促销信息
*
* @param skuIdList
* @return
*/
@Override
public Map<Long, List<String>> findActivity(List<Long> skuIdList) {
Map<Long, List<String>> result = new HashMap<>();
//skuIdList遍历得到每个skuId
skuIdList.forEach(skuId -> {
//根据skuId进行查询查询sku对应活动里面规则列表
List<ActivityRule> activityRuleList = baseMapper.findActivityRule(skuId);
//数据封装规则名称
if (!CollectionUtils.isEmpty(activityRuleList)) {
List<String> ruleList = new ArrayList<>();
//把规则名称处理
for (ActivityRule activityRule : activityRuleList) {
ruleList.add(this.getRuleDesc(activityRule));
}
result.put(skuId, ruleList);
}
});
return result;
}
}

View File

@ -58,13 +58,13 @@
<!--//根据skuId进行查询查询sku对应活动里面规则列表-->
<select id="findActivityRule" resultMap="ActivityRuleMap">
select info.activity_type as activityType,
rule.id,
rule.activity_id,
rule.condition_amount,
rule.condition_num,
rule.benefit_amount,
rule.benefit_discount
select DISTINCT rule.id,
info.activity_type as activityType,
rule.activity_id,
rule.condition_amount,
rule.condition_num,
rule.benefit_amount,
rule.benefit_discount
from activity_info info
inner join activity_sku sku on info.id = sku.activity_id
inner join activity_rule rule on info.id = rule.activity_id
@ -89,6 +89,4 @@
</where>
and now() between info.start_time and info.end_time
</select>
<select id="selectActivityRuleList" resultType="com.atguigu.ssyx.model.activity.ActivityRule"></select>
</mapper>

View File

@ -1,5 +1,6 @@
package com.atguigu.ssyx.home.controller;
import com.atguigu.ssyx.client.product.ProductFeignClient;
import com.atguigu.ssyx.common.auth.AuthContextHolder;
import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.home.service.HomeService;
@ -10,6 +11,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
@ -26,7 +28,8 @@ import java.util.Map;
@RequestMapping("api/home")
public class HomeApiController {
@Resource
private ProductFeignClient productFeignClient;
@Autowired
private HomeService homeService;
@ -39,4 +42,13 @@ public class HomeApiController {
return Result.ok(map);
}
@ApiOperation(value = "获取分类信息")
@GetMapping("category")
public Result category() {
return Result.ok(productFeignClient.findAllCategoryList());
}
}

View File

@ -28,6 +28,12 @@
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.atguigu</groupId>
<artifactId>service-activity-client</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>8</maven.compiler.source>

View File

@ -0,0 +1,11 @@
package com.atguigu.ssyx.search.api;
/**
* ClassName: SearchApiController
* Package: com.atguigu.ssyx.search.api
*
* @author yovinchen
* @Create 2023/9/26 14:21
*/
public class SearchApiController {
}

View File

@ -3,8 +3,13 @@ package com.atguigu.ssyx.search.controller;
import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.model.search.SkuEs;
import com.atguigu.ssyx.search.service.SkuService;
import com.atguigu.ssyx.vo.search.SkuEsQueryVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@ -45,4 +50,16 @@ public class SkuApiController {
public List<SkuEs> findHotSkuList() {
return skuService.findHotSkuList();
}
@ApiOperation(value = "搜索分类商品")
@GetMapping("{page}/{limit}")
public Result list(
@ApiParam(name = "page", value = "当前页码", required = true) @PathVariable Integer page,
@ApiParam(name = "limit", value = "每页记录数", required = true) @PathVariable Integer limit,
@ApiParam(name = "searchParamVo", value = "查询对象", required = false) SkuEsQueryVo searchParamVo) {
Pageable pageable = PageRequest.of(page - 1, limit);
Page<SkuEs> pageModel = skuService.search(pageable, searchParamVo);
return Result.ok(pageModel);
}
}

View File

@ -6,9 +6,6 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import java.net.ContentHandler;
import java.util.List;
/**
* ClassName: SkuRepository
* Package: com.atguigu.ssyx.search.repository
@ -20,4 +17,23 @@ public interface SkuRepository extends ElasticsearchRepository<SkuEs, Long> {
//获取爆款商品
Page<SkuEs> findByOrderByHotScoreDesc(Pageable pageable);
/**
* 根据仓库id + 分类id查询
*
* @param categoryId
* @param wareId
* @param pageable
* @return
*/
Page<SkuEs> findByCategoryIdAndWareId(Long categoryId, Long wareId, Pageable pageable);
/**
* 仓库id + keyword进行查询
*
* @param keyword
* @param wareId
* @param pageable
* @return
*/
Page<SkuEs> findByKeywordAndWareId(String keyword, Long wareId, Pageable pageable);
}

View File

@ -1,6 +1,9 @@
package com.atguigu.ssyx.search.service;
import com.atguigu.ssyx.model.search.SkuEs;
import com.atguigu.ssyx.vo.search.SkuEsQueryVo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.List;
@ -36,4 +39,13 @@ public interface SkuService {
* @return
*/
List<SkuEs> findHotSkuList();
/**
* 搜索分类商品
*
* @param pageable
* @param searchParamVo
* @return
*/
Page<SkuEs> search(Pageable pageable, SkuEsQueryVo searchParamVo);
}

View File

@ -1,22 +1,29 @@
package com.atguigu.ssyx.search.service.impl;
import com.alibaba.fastjson.JSON;
import com.atguigu.ssyx.client.activity.ActivityFeignClient;
import com.atguigu.ssyx.client.product.ProductFeignClient;
import com.atguigu.ssyx.common.auth.AuthContextHolder;
import com.atguigu.ssyx.enums.SkuType;
import com.atguigu.ssyx.model.product.Category;
import com.atguigu.ssyx.model.product.SkuInfo;
import com.atguigu.ssyx.model.search.SkuEs;
import com.atguigu.ssyx.search.repository.SkuRepository;
import com.atguigu.ssyx.search.service.SkuService;
import com.atguigu.ssyx.vo.search.SkuEsQueryVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* ClassName: SkuServiceImpl
@ -31,6 +38,8 @@ public class SkuServiceImpl implements SkuService {
@Autowired
private ProductFeignClient productFeignClient;
@Autowired
private ActivityFeignClient activityFeignClient;
@Autowired
private SkuRepository skuRepository;
@ -95,4 +104,55 @@ public class SkuServiceImpl implements SkuService {
List<SkuEs> skuEsList = page.getContent();
return skuEsList;
}
/**
* 搜索分类商品
*
* @param pageable
* @param skuEsQueryVo
* @return
*/
@Override
public Page<SkuEs> search(Pageable pageable, SkuEsQueryVo skuEsQueryVo) {
//1 向SkuEsQueryVo设置wareId当前登录用户的仓库id
skuEsQueryVo.setWareId(AuthContextHolder.getWareId());
Page<SkuEs> pageModel = null;
//2 调用SkuRepository方法根据springData命名规则定义方法进行条件查询
//// 判断keyword是否为空如果为空 根据仓库id + 分类id查询
String keyword = skuEsQueryVo.getKeyword();
if (StringUtils.isEmpty(keyword)) {
pageModel = skuRepository.findByCategoryIdAndWareId(skuEsQueryVo.getCategoryId(), skuEsQueryVo.getWareId(), pageable);
} else {
///如果keyword不为空根据仓库id + keyword进行查询
pageModel = skuRepository.findByKeywordAndWareId(skuEsQueryVo.getKeyword(), skuEsQueryVo.getWareId(), pageable);
}
//3 查询商品参加优惠活动
List<SkuEs> skuEsList = pageModel.getContent();
if (!CollectionUtils.isEmpty(skuEsList)) {
//遍历skuEsList得到所有skuId
List<Long> skuIdList = skuEsList.stream()
.map(SkuEs::getId)
.collect(Collectors.toList());
//根据skuId列表远程调用调用service-activity里面的接口得到数据
//返回Map<Long,List<String>>
//// map集合key就是skuId值Long类型
//// map集合value是List集合sku参与活动里面多个规则名称列表
///// 一个商品参加一个活动一个活动里面可以有多个规则
////// 比如有活动中秋节满减活动
////// 一个活动可以有多个规则
////// 中秋节满减活动有两个规则满20元减1元满58元减5元
Map<Long, List<String>> skuIdToRuleListMap = activityFeignClient.findActivity(skuIdList);//远程调用
//封装获取数据到skuEs里面 ruleList属性里面
if (skuIdToRuleListMap != null) {
skuEsList.forEach(skuEs -> {
skuEs.setRuleList(skuIdToRuleListMap.get(skuEs.getId()));
});
}
}
return pageModel;
}
}

View File

@ -28,7 +28,7 @@ spring:
acknowledge-mode: manual #消费端手动确认
redis:
host: localhost
host: 82.157.68.223
port: 6379
database: 0
timeout: 1800000

View File

@ -28,7 +28,7 @@ public class LeaderAddressController {
@ApiOperation("提货点地址信息")
@GetMapping("inner/getUserAddressByUserId/{userId}")
public LeaderAddressVo getUserAddressByUserId(@PathVariable(value = "userId") Long userId) {
public LeaderAddressVo getUserAddressByUserId(@PathVariable("userId") Long userId) {
return userService.getLeaderAddressByUserId(userId);
}
}

View File

@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.*;
* @Create 2023/9/22 16:23
*/
@RestController
@RequestMapping("/api/user/weixin")
@RequestMapping("api/user/weixin")
public class WeixinApiController {
@Autowired
@ -27,12 +27,12 @@ public class WeixinApiController {
//用户微信授权登录
@ApiOperation(value = "微信登录获取openid(小程序)")
@GetMapping("/wxLogin/{code}")
@GetMapping("wxLogin/{code}")
public Result loginWx(@PathVariable String code) {
return Result.ok(loginWxService.loginWx(code));
}
@PostMapping("/auth/updateUser")
@PostMapping("auth/updateUser")
@ApiOperation(value = "更新用户昵称与头像")
public Result updateUser(@RequestBody User user) {
userService.updateUser(user);