小程序主页接口
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package com.czg.service.product.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.account.entity.PlatformDict;
|
||||
|
||||
/**
|
||||
* 平台配置 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-28
|
||||
*/
|
||||
public interface PlatformDictMapper extends BaseMapper<PlatformDict> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.czg.service.product.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.account.entity.PlatformDictType;
|
||||
|
||||
/**
|
||||
* 平台配置类型 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-28
|
||||
*/
|
||||
public interface PlatformDictTypeMapper extends BaseMapper<PlatformDictType> {
|
||||
|
||||
}
|
||||
@@ -32,4 +32,7 @@ public interface ProductMapper extends BaseMapper<Product> {
|
||||
List<ShopProductVo> selectGroupProductList(@Param("shopId") Long shopId);
|
||||
|
||||
ShopProductInfoVo selectOneProductInfo(@Param("id") Long id, @Param("shopId") Long shopId);
|
||||
}
|
||||
|
||||
List<Product> selectCouponProBySaleNum();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.czg.service.product.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.account.entity.SysDict;
|
||||
|
||||
/**
|
||||
* 数据字典 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-28
|
||||
*/
|
||||
public interface SysDictMapper extends BaseMapper<SysDict> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package com.czg.service.product.service.impl;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.account.entity.PlatformDict;
|
||||
import com.czg.account.entity.ShopInfo;
|
||||
import com.czg.account.entity.SysDict;
|
||||
import com.czg.product.service.HomePageService;
|
||||
import com.czg.product.service.PlatformDictService;
|
||||
import com.czg.product.service.SysDictService;
|
||||
import com.czg.account.vo.home.BannerInfoVo;
|
||||
import com.czg.account.vo.home.HomePageVO;
|
||||
import com.czg.account.vo.home.HotRankingVO;
|
||||
import com.czg.enums.LogoEnum;
|
||||
import com.czg.product.entity.Product;
|
||||
import com.czg.product.service.ProdSkuService;
|
||||
import com.czg.product.service.ProductService;
|
||||
import com.czg.service.product.mapper.ProductMapper;
|
||||
import com.czg.utils.JoinQueryWrapper;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@Service
|
||||
public class HomePageServiceImpl implements HomePageService {
|
||||
private static final Character[] CHINESE_CHARS_ARRAY = {
|
||||
'你', '我', '他', '她', '它', '们', '这', '里', '那', '里', '多', '少', '是', '否',
|
||||
'好', '坏', '快', '慢', '上', '下', '左', '右', '前', '后', '高', '低', '大', '小',
|
||||
'长', '短', '方', '圆', '胖', '瘦', '黑', '白', '红', '绿', '蓝', '黄', '紫', '粉',
|
||||
'红', '桔', '红', '橙', '黄', '棕', '灰', '褐'
|
||||
};
|
||||
|
||||
|
||||
@Resource
|
||||
private PlatformDictService platformDictService;
|
||||
@Resource
|
||||
private SysDictService sysDictService;
|
||||
@Resource
|
||||
private ProductService productService;
|
||||
@Resource
|
||||
private ProductMapper productMapper;
|
||||
@Resource
|
||||
private ProdSkuService prodSkuService;
|
||||
|
||||
/**
|
||||
* 小条幅随机数据
|
||||
* @return
|
||||
*/
|
||||
private List<BannerInfoVo> bannerVoRandom(){
|
||||
List<BannerInfoVo> bannerInfoList = new ArrayList<>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
String nickName = RandomUtil.randomEle(CHINESE_CHARS_ARRAY) + "***";
|
||||
BannerInfoVo bannerInfoVo = new BannerInfoVo();
|
||||
bannerInfoVo.setName(nickName);
|
||||
bannerInfoVo.setLogo(LogoEnum.getValueByKey(RandomUtil.randomInt()));
|
||||
// 生成 0 到 1000 之间的随机金额,保留两位小数
|
||||
double amount = RandomUtil.randomDouble(0, 1000);
|
||||
// 格式化为两位小数
|
||||
bannerInfoVo.setMoney(String.format("%.2f", amount));
|
||||
bannerInfoList.add(bannerInfoVo);
|
||||
}
|
||||
return bannerInfoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HomePageVO getHomeInfo() {
|
||||
HomePageVO homeUpVO = new HomePageVO();
|
||||
//轮播图
|
||||
|
||||
List<PlatformDict> platformDictList = platformDictService.list(new QueryWrapper().in(PlatformDict::getType, "carousel", "homeDistrict"));;
|
||||
Map<String, List<PlatformDict>> groupedByType = platformDictList.stream()
|
||||
.collect(Collectors.groupingBy(PlatformDict::getType));
|
||||
//轮播图
|
||||
homeUpVO.setBannerList(groupedByType.get("carousel"));
|
||||
//金刚区
|
||||
homeUpVO.setDistrict(groupedByType.get("homeDistrict"));
|
||||
//小条幅
|
||||
homeUpVO.setFreeBannerList(bannerVoRandom());
|
||||
|
||||
// 销量榜
|
||||
List<Product> productList = productMapper.selectCouponProBySaleNum();
|
||||
HotRankingVO hotRankingVO = new HotRankingVO();
|
||||
hotRankingVO.setHotList(productList);
|
||||
homeUpVO.setHotRanking(hotRankingVO);
|
||||
|
||||
List<SysDict> sysDictList = sysDictService.list(new QueryWrapper().eq(SysDict::getType, "home").eq(SysDict::getStatus, 1));
|
||||
for (SysDict sysDict : sysDictList) {
|
||||
if (sysDict.getIsChild().equals(1)) {
|
||||
sysDict.setDetail(sysDictService.list(new QueryWrapper().eq(SysDict::getReleId, sysDict.getId()).eq(SysDict::getStatus, 1)));
|
||||
}
|
||||
sysDict.setIsChild((sysDict.getIsChild() == null || sysDict.getIsChild().equals(0)) ? 0 : 1);
|
||||
}
|
||||
homeUpVO.setMenuList(sysDictList);
|
||||
|
||||
return homeUpVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getProd(String lng, String lat, String address, Integer classify, Integer orderType, Integer distanceType) {
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
if (StrUtil.isNotBlank(address)) {
|
||||
queryWrapper.and(JoinQueryWrapper.column(ShopInfo::getCities).like(address).or(JoinQueryWrapper.column(ShopInfo::getDistricts).like(address)));
|
||||
}
|
||||
if (classify != null) {
|
||||
queryWrapper.eq(Product::getCategoryId, classify);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.czg.service.product.service.impl;
|
||||
|
||||
import com.czg.service.product.mapper.PlatformDictMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.account.entity.PlatformDict;
|
||||
import com.czg.product.service.PlatformDictService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 平台配置 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-28
|
||||
*/
|
||||
@Service
|
||||
public class PlatformDictServiceImpl extends ServiceImpl<PlatformDictMapper, PlatformDict> implements PlatformDictService{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.czg.service.product.service.impl;
|
||||
|
||||
import com.czg.service.product.mapper.PlatformDictTypeMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.account.entity.PlatformDictType;
|
||||
import com.czg.product.service.PlatformDictTypeService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 平台配置类型 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-28
|
||||
*/
|
||||
@Service
|
||||
public class PlatformDictTypeServiceImpl extends ServiceImpl<PlatformDictTypeMapper, PlatformDictType> implements PlatformDictTypeService{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.czg.service.product.service.impl;
|
||||
|
||||
import com.czg.service.product.mapper.SysDictMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.account.entity.SysDict;
|
||||
import com.czg.product.service.SysDictService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 数据字典 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-28
|
||||
*/
|
||||
@Service
|
||||
public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> implements SysDictService{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.product.mapper.PlatformDictMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.product.mapper.PlatformDictTypeMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -150,4 +150,13 @@
|
||||
and t1.id = #{id}
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
<select id="selectCouponProBySaleNum" resultType="com.czg.product.entity.Product">
|
||||
SELECT a.*
|
||||
FROM tb_product AS a
|
||||
LEFT JOIN tb_prod_sku AS b ON a.id = b.product_id
|
||||
WHERE a.type = 'coupon'
|
||||
ORDER BY b.real_sales_number
|
||||
LIMIT 2
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.product.mapper.SysDictMapper">
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user