👍 修改为本地数据库。

This commit is contained in:
2023-01-11 14:10:41 +08:00
parent c8ca54f026
commit eb76349932
5 changed files with 144 additions and 172 deletions
@@ -1,11 +1,11 @@
/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
* 注意:
* 本软件为www.yixiang.co开发研制,未经购买不得使用
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
*/
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
* 注意:
* 本软件为www.yixiang.co开发研制,未经购买不得使用
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
*/
package co.yixiang.modules.hotList.service.impl;
import cn.hutool.core.date.DateUtil;
@@ -61,9 +61,9 @@ import java.util.*;
/**
* @author ssj
* @date 2022-10-08
*/
* @author ssj
* @date 2022-10-08
*/
@Service
@AllArgsConstructor
//@CacheConfig(cacheNames = "yxStoreHotList")
@@ -83,24 +83,25 @@ public class YxStoreHotListServiceImpl extends BaseServiceImpl<YxStoreHotListMap
@Autowired
private ApplicationEventPublisher publisher;
@SneakyThrows
@Override
//@Cacheable
public PageResult<YxStoreHotListVo> queryAll(YxStoreHotListQueryCriteria criteria, Pageable pageable) {
getPage(pageable);
PageInfo<YxStoreHotList> page = new PageInfo<>(queryAll(criteria));
PageResult<YxStoreHotListVo> result=generator.convertPageInfo(page, YxStoreHotListVo.class);
result.getContent().forEach(hotListVo->{
PageResult<YxStoreHotListVo> result = generator.convertPageInfo(page, YxStoreHotListVo.class);
result.getContent().forEach(hotListVo -> {
List<Integer> productArr = JSONUtil.toList(hotListVo.getProductList(), Integer.class);
ArrayList<YxStoreProduct> list1 =new ArrayList<>();
productArr.forEach(productId->{
ArrayList<YxStoreProduct> list1 = new ArrayList<>();
productArr.forEach(productId -> {
LambdaQueryWrapper<YxStoreProduct> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(YxStoreProduct::getIsShow, ShopCommonEnum.SHOW_1.getValue())
.eq(YxStoreProduct::getId, productId);
//这里需要有一个非空判断
YxStoreProduct storeProduct = storeProductMapper.selectOne(wrapper);
// YxStoreProduct storeProduct=storeProductMapper.selectById(productId);
if (ObjectUtil.isNotNull(storeProduct)){
if (ObjectUtil.isNotNull(storeProduct)) {
list1.add(storeProduct);
}
});
@@ -112,12 +113,12 @@ public class YxStoreHotListServiceImpl extends BaseServiceImpl<YxStoreHotListMap
@Override
//@Cacheable
public List<YxStoreHotList> queryAll(YxStoreHotListQueryCriteria criteria){
public List<YxStoreHotList> queryAll(YxStoreHotListQueryCriteria criteria) {
//查出所有用户拥有的券使用时间小于24小时且未使用的券
Date now=new Date();
Date endTime = DateUtil.offsetDay(now,1);
List<YxStoreCouponUser> storeCouponUsers=yxStoreCouponUserMapper.selectUserCouponList(endTime);
storeCouponUsers.forEach(storeCouponUser->{
Date now = new Date();
Date endTime = DateUtil.offsetDay(now, 1);
List<YxStoreCouponUser> storeCouponUsers = yxStoreCouponUserMapper.selectUserCouponList(endTime);
storeCouponUsers.forEach(storeCouponUser -> {
//这里调用微信订阅模板发送消息
TemplateBean templateBean = TemplateBean.builder()
.couponId(storeCouponUser.getCid())
@@ -135,15 +136,15 @@ public class YxStoreHotListServiceImpl extends BaseServiceImpl<YxStoreHotListMap
public void download(List<YxStoreHotListDto> all, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (YxStoreHotListDto yxStoreHotList : all) {
Map<String,Object> map = new LinkedHashMap<>();
Map<String, Object> map = new LinkedHashMap<>();
map.put("榜单名称", yxStoreHotList.getListName());
map.put("排序", yxStoreHotList.getSort());
map.put("商品列表", yxStoreHotList.getProductList());
map.put("是否显示", yxStoreHotList.getIsShow());
map.put("添加时间", yxStoreHotList.getCreateTime());
map.put(" updateTime", yxStoreHotList.getUpdateTime());
map.put(" updateTime", yxStoreHotList.getUpdateTime());
map.put("删除状态", yxStoreHotList.getIsDel());
map.put(" tenantId", yxStoreHotList.getTenantId());
map.put(" tenantId", yxStoreHotList.getTenantId());
list.add(map);
}
FileUtil.downloadExcel(list, response);
@@ -152,59 +153,62 @@ public class YxStoreHotListServiceImpl extends BaseServiceImpl<YxStoreHotListMap
/***
*获取所有拥有榜单的月份,并获取对应榜单
* ***/
public Map<String,Object>getHotListDataList(){
Map<String, Object> map=new HashMap<>();
public Map<String, Object> getHotListDataList() {
Map<String, Object> map = new HashMap<>();
LambdaQueryWrapper<YxStoreHotListRecord> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(YxStoreHotListRecord::getIsShow, ShopCommonEnum.SHOW_1.getValue());
wrapper.eq(YxStoreHotListRecord::getIsDel, CommonEnum.DEL_STATUS_0.getValue());
//获取所有榜单记录列表(后期限制一年?)
List<YxStoreHotListRecord> list=yxStoreHotListRecordMapper.selectList(wrapper);
if(list.isEmpty()){
List<YxStoreHotListRecord> list = yxStoreHotListRecordMapper.selectList(wrapper);
if (list.isEmpty()) {
return null;
}
//获取月份
LinkedHashSet<String> mouthList=new LinkedHashSet<>();
LinkedHashSet<String> mouthList = new LinkedHashSet<>();
list.forEach(yxStoreHotListRecord -> mouthList.add(yxStoreHotListRecord.getMouth()));
map.put("mouthList",mouthList);
mouthList.forEach(mouth->{
LambdaQueryWrapper<YxStoreHotListRecord> wrapper2= SerializationUtils.clone(wrapper);
map.put("mouthList", mouthList);
mouthList.forEach(mouth -> {
LambdaQueryWrapper<YxStoreHotListRecord> wrapper2 = SerializationUtils.clone(wrapper);
//当前月份的所有榜单记录信息
List<YxStoreHotListRecord> recordList=yxStoreHotListRecordMapper.selectList(wrapper2.eq(YxStoreHotListRecord::getMouth,mouth));
LinkedHashSet<Integer> hotIdList=new LinkedHashSet<>();
List<YxStoreHotListRecord> recordList = yxStoreHotListRecordMapper.selectList(wrapper2.eq(YxStoreHotListRecord::getMouth, mouth));
LinkedHashSet<Integer> hotIdList = new LinkedHashSet<>();
//获得不重复的榜单信息
recordList.forEach(cate->{
if(ObjectUtil.isNotNull(yxStoreHotListMapper.selectById(cate.getHotListId()))){
recordList.forEach(cate -> {
if (ObjectUtil.isNotNull(yxStoreHotListMapper.selectById(cate.getHotListId()))) {
hotIdList.add(cate.getHotListId());
}
});
//批量查询榜单信息,并进行排序
LambdaQueryWrapper<YxStoreHotList> wrapperList=new LambdaQueryWrapper<>();
wrapperList.in(YxStoreHotList::getId,hotIdList).orderByAsc(YxStoreHotList::getSort);
ArrayList <Integer> list1=new ArrayList<>();
yxStoreHotListMapper.selectList(wrapperList).forEach(yxHotList->list1.add(yxHotList.getId()));
ArrayList<HotListDTO> hotListDTOS=new ArrayList<>();
list1.forEach(hotId->{
LambdaQueryWrapper<YxStoreHotListRecord> wrapper1= SerializationUtils.clone(wrapper);
//查出当前月份当前榜单的记录
List<YxStoreHotListRecord> recordCateList=yxStoreHotListRecordMapper.selectList(wrapper1.eq(YxStoreHotListRecord::getHotListId,hotId).eq(YxStoreHotListRecord::getMouth,mouth));
LinkedHashSet<String> cateIdList=new LinkedHashSet<>();
//获得不重复的商品分类id
recordCateList.forEach(cate->{
if(ObjectUtil.isNotNull(storeCategoryMapper.selectById(cate.getCateId())))
cateIdList.add(cate.getCateId());
});
ArrayList<CateDto> cateDtos=new ArrayList<>();
//把该榜单下的分类封为一个数组
cateIdList.forEach(cateId->cateDtos.add(new CateDto().setCateId(Long.valueOf(cateId)).setCateName(storeCategoryMapper.selectById(cateId).getCateName())));
hotListDTOS.add(new HotListDTO().setId(Math.toIntExact(hotId)).setListName(yxStoreHotListMapper.selectById(hotId).getListName())
.setCateDtos(cateDtos)
.setListImage(yxStoreHotListMapper.selectById(hotId).getListImage()));
LambdaQueryWrapper<YxStoreHotList> wrapperList = new LambdaQueryWrapper<>();
wrapperList.in(YxStoreHotList::getId, hotIdList).orderByAsc(YxStoreHotList::getSort);
ArrayList<Integer> list1 = new ArrayList<>();
yxStoreHotListMapper.selectList(wrapperList).forEach(yxHotList -> list1.add(yxHotList.getId()));
ArrayList<HotListDTO> hotListDTOS = new ArrayList<>();
list1.forEach(hotId -> {
LambdaQueryWrapper<YxStoreHotListRecord> wrapper1 = SerializationUtils.clone(wrapper);
//查出当前月份当前榜单的记录
List<YxStoreHotListRecord> recordCateList = yxStoreHotListRecordMapper.selectList(wrapper1.eq(YxStoreHotListRecord::getHotListId, hotId).eq(YxStoreHotListRecord::getMouth, mouth));
LinkedHashSet<String> cateIdList = new LinkedHashSet<>();
//获得不重复的商品分类id
recordCateList.forEach(cate -> {
if (ObjectUtil.isNotNull(storeCategoryMapper.selectById(cate.getCateId())))
cateIdList.add(cate.getCateId());
});
ArrayList<CateDto> cateDtos = new ArrayList<>();
//把该榜单下的分类封为一个数组
cateIdList.forEach(cateId -> cateDtos.add(new CateDto().setCateId(Long.valueOf(cateId)).setCateName(storeCategoryMapper.selectById(cateId).getCateName())));
hotListDTOS.add(new HotListDTO().setId(Math.toIntExact(hotId)).setListName(yxStoreHotListMapper.selectById(hotId).getListName())
.setCateDtos(cateDtos)
.setListImage(yxStoreHotListMapper.selectById(hotId).getListImage()));
});
map.put(mouth,new HotListDataDto().setHotListDTOS(hotListDTOS));
map.put(mouth, new HotListDataDto().setHotListDTOS(hotListDTOS));
//当前月份所有的商品分类
});
return map;
};
}
;
/***
*根据榜单,分类,时间等获取商品信息
* ***/
@@ -214,15 +218,15 @@ public class YxStoreHotListServiceImpl extends BaseServiceImpl<YxStoreHotListMap
wrapper.eq(YxStoreHotListRecord::getIsShow, ShopCommonEnum.SHOW_1.getValue());
wrapper.eq(YxStoreHotListRecord::getIsDel, CommonEnum.DEL_STATUS_0.getValue());
//按照商品分类id
if (queryParam.getCateId()!=null){
wrapper.eq(YxStoreHotListRecord::getCateId,queryParam.getCateId());
if (queryParam.getCateId() != null) {
wrapper.eq(YxStoreHotListRecord::getCateId, queryParam.getCateId());
}
//评测id
if (queryParam.getHotListId()!=null){
wrapper.eq(YxStoreHotListRecord::getHotListId,queryParam.getHotListId());
if (queryParam.getHotListId() != null) {
wrapper.eq(YxStoreHotListRecord::getHotListId, queryParam.getHotListId());
}
if (StringUtils.isNotBlank(queryParam.getMouth())){
wrapper.eq(YxStoreHotListRecord::getMouth,queryParam.getMouth());
if (StringUtils.isNotBlank(queryParam.getMouth())) {
wrapper.eq(YxStoreHotListRecord::getMouth, queryParam.getMouth());
}
//默认销量降序排序
if (SortEnum.DESC.getValue().equals(queryParam.getSalesOrder())) {
@@ -239,65 +243,71 @@ public class YxStoreHotListServiceImpl extends BaseServiceImpl<YxStoreHotListMap
Page<YxStoreHotListRecord> pageModel = new Page<>(queryParam.getPage(), queryParam.getLimit());
IPage<YxStoreHotListRecord> pageList = yxStoreHotListRecordMapper.selectPage(pageModel, wrapper);
List<YxStoreProduct> list =new ArrayList<>();
List<YxStoreProduct> list = new ArrayList<>();
pageList.getRecords().forEach(yxStoreHotListRecord -> {
YxStoreProduct yxStoreProduct=storeProductMapper.selectById(yxStoreHotListRecord.getProductId());
if (ObjectUtil.isNotNull(yxStoreProduct)){
YxStoreProduct yxStoreProduct = storeProductMapper.selectById(yxStoreHotListRecord.getProductId());
if (ObjectUtil.isNotNull(yxStoreProduct)) {
yxStoreProduct.setHotSales(yxStoreHotListRecord.getHotSales());
list.add(yxStoreProduct);
}
});
return list;
}
;
@Override
public List<HotListDTO> getList() {
LambdaQueryWrapper<YxStoreHotListRecord> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(YxStoreHotListRecord::getIsShow, ShopCommonEnum.SHOW_1.getValue());
wrapper.eq(YxStoreHotListRecord::getIsDel, CommonEnum.DEL_STATUS_0.getValue());
//获取所有榜单记录列表(后期限制一年?)
List<YxStoreHotListRecord> list=yxStoreHotListRecordMapper.selectList(wrapper);
if(list.isEmpty()){
List<YxStoreHotListRecord> list = yxStoreHotListRecordMapper.selectList(wrapper);
if (list.isEmpty()) {
return null;
}
//获取月份
LinkedHashSet<String> mouthList=new LinkedHashSet<>();
LinkedHashSet<String> mouthList = new LinkedHashSet<>();
list.forEach(yxStoreHotListRecord -> mouthList.add(yxStoreHotListRecord.getMouth()));
String mouth=Collections.max(mouthList);//设定月份为最近的月份
String mouth = Collections.max(mouthList);//设定月份为最近的月份
//获取当前月份的榜单记录
List<YxStoreHotListRecord> recordList=yxStoreHotListRecordMapper.selectList(wrapper.eq(YxStoreHotListRecord::getMouth,mouth));
LinkedHashSet<Integer> hotIdList=new LinkedHashSet<>();
List<YxStoreHotListRecord> recordList = yxStoreHotListRecordMapper.selectList(wrapper.eq(YxStoreHotListRecord::getMouth, mouth));
// ???
LinkedHashSet<Integer> hotIdList = new LinkedHashSet<>();
//获得不重复的榜单id
recordList.forEach(cate->{
if(ObjectUtil.isNotNull(yxStoreHotListMapper.selectById(cate.getHotListId()))){
recordList.forEach(cate -> {
if (ObjectUtil.isNotNull(yxStoreHotListMapper.selectById(cate.getHotListId()))) {
hotIdList.add(cate.getHotListId());
}
});
//批量查询榜单信息,并进行排序
LambdaQueryWrapper<YxStoreHotList> wrapperList=new LambdaQueryWrapper<>();
wrapperList.in(YxStoreHotList::getId,hotIdList).orderByAsc(YxStoreHotList::getSort);
ArrayList <Integer> list1=new ArrayList<>();
yxStoreHotListMapper.selectList(wrapperList).forEach(yxHotList->list1.add(yxHotList.getId()));
ArrayList<HotListDTO> hotListDTOS=new ArrayList<>();
LambdaQueryWrapper<YxStoreHotList> wrapperList = new LambdaQueryWrapper<>();
wrapperList.in(YxStoreHotList::getId, hotIdList).orderByAsc(YxStoreHotList::getSort);
// 榜单ID
ArrayList<Integer> list1 = new ArrayList<>();
yxStoreHotListMapper.selectList(wrapperList).forEach(
yxHotList -> list1.add(yxHotList.getId())
);
ArrayList<HotListDTO> hotListDTOS = new ArrayList<>();
//已经排序过的榜单
list1.forEach(hotId->{
LambdaQueryWrapper<YxStoreHotListRecord> wrapper1= SerializationUtils.clone(wrapper);
list1.forEach(hotId -> {
LambdaQueryWrapper<YxStoreHotListRecord> wrapper1 = SerializationUtils.clone(wrapper);
//查出当前月份当前榜单的记录
List<YxStoreHotListRecord> recordCateList=yxStoreHotListRecordMapper.selectList(wrapper1.eq(YxStoreHotListRecord::getHotListId,hotId).eq(YxStoreHotListRecord::getMouth,mouth));
List<YxStoreHotListRecord> recordCateList = yxStoreHotListRecordMapper.selectList(wrapper1.eq(YxStoreHotListRecord::getHotListId, hotId).eq(YxStoreHotListRecord::getMouth, mouth));
//获得不重复的商品分类id
LinkedHashSet<String> cateIdList=new LinkedHashSet<>();
LinkedHashSet<String> cateIdList = new LinkedHashSet<>();
//当前榜单下的商品信息
List<YxStoreProduct> productInfo=new ArrayList<>();
List<YxStoreProduct> productInfo = new ArrayList<>();
//获得不重复的商品分类id
recordCateList.forEach(cate->{
if(ObjectUtil.isNotNull(storeCategoryMapper.selectById(cate.getCateId()))){
recordCateList.forEach(cate -> {
if (ObjectUtil.isNotNull(storeCategoryMapper.selectById(cate.getCateId()))) {
cateIdList.add(cate.getCateId());
}
productInfo.add(storeProductMapper.selectById(cate.getProductId()).setHotSales(cate.getHotSales()));
});
ArrayList<CateDto> cateDtos=new ArrayList<>();
ArrayList<CateDto> cateDtos = new ArrayList<>();
//把该榜单下的分类封为一个数组
cateIdList.forEach(cateId->cateDtos.add(new CateDto().setCateId(Long.valueOf(cateId)).setCateName(storeCategoryMapper.selectById(cateId).getCateName())));
cateIdList.forEach(cateId -> cateDtos.add(new CateDto().setCateId(Long.valueOf(cateId)).setCateName(storeCategoryMapper.selectById(cateId).getCateName())));
hotListDTOS.add(new HotListDTO().setId(Math.toIntExact(hotId)).setListName(yxStoreHotListMapper.selectById(hotId).getListName())
.setCateDtos(cateDtos)
.setProductInfo(productInfo)
@@ -307,7 +317,7 @@ public class YxStoreHotListServiceImpl extends BaseServiceImpl<YxStoreHotListMap
}
private List<HotListDTO> getHotListDTOS(LambdaQueryWrapper<YxStoreHotList> wrapper) {
List<HotListDTO> list = generator.convert(baseMapper.selectList(wrapper),HotListDTO.class);
List<HotListDTO> list = generator.convert(baseMapper.selectList(wrapper), HotListDTO.class);
// list.forEach(hotListDto->{
// List<Integer> productArr = JSONUtil.toList(hotListDto.getProductList(), Integer.class);
// List<YxStoreProduct> list1 =new ArrayList<>();