From eb7634993201c3dc71bc589146df7eea49399b25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A0=E6=B0=B8=E8=BE=89?= <654612@qq.com> Date: Wed, 11 Jan 2023 14:10:41 +0800 Subject: [PATCH] =?UTF-8?q?:+1:=20=E4=BF=AE=E6=94=B9=E4=B8=BA=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E6=95=B0=E6=8D=AE=E5=BA=93=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/sync.sh | 2 +- .../config/YudaoMybatisAutoConfiguration.java | 18 -- .../src/main/resources/application-local.yaml | 71 +++---- .../src/main/resources/application-prod.yaml | 35 ++-- .../impl/YxStoreHotListServiceImpl.java | 190 +++++++++--------- 5 files changed, 144 insertions(+), 172 deletions(-) diff --git a/bin/sync.sh b/bin/sync.sh index e0d0d278..1d9967a1 100644 --- a/bin/sync.sh +++ b/bin/sync.sh @@ -1 +1 @@ -rsync yudao-server/target/yudao-server.jar root@39.105.46.0:/root/project/zen/yudao.jar \ No newline at end of file +rsync -v ../yudao-server/target/yudao-server.jar root@47.108.56.75:/www/wwwroot/yudao/yudao-server.jar \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/YudaoMybatisAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/YudaoMybatisAutoConfiguration.java index 6d9bcb8c..48e7790e 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/YudaoMybatisAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/YudaoMybatisAutoConfiguration.java @@ -41,7 +41,6 @@ import java.util.Map; @MapperScans({ @MapperScan(basePackages ={"co.yixiang.**.service.mapper", "co.yixiang.config"},sqlSessionFactoryRef = "shangcheng"), - @MapperScan(basePackages = {"com.zsw.erp.datasource.mappers"},sqlSessionFactoryRef = "erp"), @MapperScan(basePackages = {"${yudao.info.base-package}", "cn.iocoder.yudao"}, annotationClass = Mapper.class, lazyInitialization = "${mybatis.lazy-initialization:false}") // Mapper 懒加载,目前仅用于单元测试 }) @@ -89,23 +88,6 @@ public class YudaoMybatisAutoConfiguration { return getSqlSessionFactory(factory); } - @Bean("erpDataSource") - @ConfigurationProperties("spring.datasource.dynamic.datasource.erp") - public DataSource erpDataSource(){ - return new DruidDataSource(); - } - @Bean("erp") - public SqlSessionFactory erpSqlSessionFactory(@Qualifier("erpDataSource") DataSource dataSource) throws Exception { - MybatisSqlSessionFactoryBean factory = new MybatisSqlSessionFactoryBean(); - Resource[] resources = new PathMatchingResourcePatternResolver().getResources("classpath*:/erp_mapper/*.xml"); - Arrays.stream(resources).forEach(resource -> { - log.info("erp mapper:{}",resource.getFilename()); - }); - factory.setMapperLocations(resources); - factory.setDataSource(dataSource); - return getSqlSessionFactory(factory); - } - private SqlSessionFactory getSqlSessionFactory(MybatisSqlSessionFactoryBean factory) throws Exception { GlobalConfig globalConfig = new GlobalConfig(); diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index ce9696fc..709a5180 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -1,3 +1,11 @@ +# 自定义数据库 +mysql: + url: 47.108.56.75 + port: 3306 + vue-username: vue_pro + vue-password: CrnPu&g8HqbBikrA&DH-llRgtvpIrG#- + bxg_username: vue_pro_bxg + bxg_password: CrnPu&g8HqbBikrA&DH-llRgtvpIrG#- server: port: 48080 @@ -42,56 +50,23 @@ spring: test-on-return: false datasource: master: - url: jdbc:p6spy:mysql://192.168.10.250:3306/vue_pro?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai - driver-class-name: com.p6spy.engine.spy.P6SpyDriver - username: root - password: root + name: vue_pro + url: jdbc:mysql://${mysql.url}:${mysql.port}/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true + driver-class-name: com.mysql.cj.jdbc.Driver + username: ${mysql.vue-username} + password: ${mysql.vue-password} slave: # 模拟从库,可根据自己需要修改 - url: jdbc:p6spy:mysql://192.168.10.250:3306/vue_pro?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai - driver-class-name: com.p6spy.engine.spy.P6SpyDriver - username: root - password: root + name: vue_pro + url: jdbc:mysql://${mysql.url}:${mysql.port}/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true + driver-class-name: com.mysql.cj.jdbc.Driver + username: ${mysql.vue-username} + password: ${mysql.vue-password} bxg: # 农场数据源 - url: jdbc:p6spy:mysql://192.168.10.250:3306/vue_pro_bxg?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai - driver-class-name: com.p6spy.engine.spy.P6SpyDriver - username: root - password: root - erp: # 进销存 - url: jdbc:p6spy:mysql://192.168.10.250:3306/vue_pro_erp?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai - driver-class-name: com.p6spy.engine.spy.P6SpyDriver - username: root - password: root - farm: # 农场数据源 - url: jdbc:p6spy:mysql://192.168.10.250:3306/zsw-farm?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai - driver-class-name: com.p6spy.engine.spy.P6SpyDriver - username: root - password: root -# datasource: -# master: -# url: jdbc:p6spy:mysql://localhost:3306/vue_pro?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai -# driver-class-name: com.p6spy.engine.spy.P6SpyDriver -# username: root -# password: 123456 -# slave: # 模拟从库,可根据自己需要修改 -# url: jdbc:p6spy:mysql://localhost:3306/vue_pro?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai -# driver-class-name: com.p6spy.engine.spy.P6SpyDriver -# username: root -# password: 123456 -# bxg: # 农场数据源 -# url: jdbc:p6spy:mysql://localhost:3306/vue_pro_bxg?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai -# driver-class-name: com.p6spy.engine.spy.P6SpyDriver -# username: root -# password: 123456 -# erp: # 进销存 -# url: jdbc:p6spy:mysql://localhost/vue_pro_erp?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai -# driver-class-name: com.p6spy.engine.spy.P6SpyDriver -# username: root -# password: 123456 -# farm: # 农场数据源 -# url: jdbc:p6spy:mysql://localhost/zsw-farm?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai -# driver-class-name: com.p6spy.engine.spy.P6SpyDriver -# username: root -# password: 123456 + name: vue_pro_bxg + url: jdbc:mysql://${mysql.url}:${mysql.port}/${spring.datasource.dynamic.datasource.bxg.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true + driver-class-name: com.mysql.cj.jdbc.Driver + username: ${mysql.bxg-username} + password: ${mysql.bxg-password} # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 redis: diff --git a/yudao-server/src/main/resources/application-prod.yaml b/yudao-server/src/main/resources/application-prod.yaml index b00b186d..9b723a96 100644 --- a/yudao-server/src/main/resources/application-prod.yaml +++ b/yudao-server/src/main/resources/application-prod.yaml @@ -1,3 +1,11 @@ +# 自定义数据库 +mysql: + url: 127.0.0.1 + port: 3306 + vue-username: vue_pro + vue-password: CrnPu&g8HqbBikrA&DH-llRgtvpIrG#- + bxg_username: vue_pro_bxg + bxg_password: CrnPu&g8HqbBikrA&DH-llRgtvpIrG#- server: port: 48080 @@ -47,28 +55,22 @@ spring: # ip: rm-2zey92ofhilzm3p4j0o.mysql.rds.aliyuncs.com:3306 master: name: vue_pro - url: jdbc:mysql://rm-2zey92ofhilzm3p4j0o.mysql.rds.aliyuncs.com:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true + url: jdbc:mysql://${mysql.url}:${mysql.port}/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true driver-class-name: com.mysql.cj.jdbc.Driver - username: vue_pro - password: CrnPu&g8HqbBikrA&DH-llRgtvpIrG#- + username: ${mysql.vue-username} + password: ${mysql.vue-password} slave: # 模拟从库,可根据自己需要修改 name: vue_pro - url: jdbc:mysql://rm-2zey92ofhilzm3p4j0o.mysql.rds.aliyuncs.com:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true + url: jdbc:mysql://${mysql.url}:${mysql.port}/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true driver-class-name: com.mysql.cj.jdbc.Driver - username: vue_pro - password: CrnPu&g8HqbBikrA&DH-llRgtvpIrG#- + username: ${mysql.vue-username} + password: ${mysql.vue-password} bxg: # 农场数据源 name: vue_pro_bxg - url: jdbc:mysql://rm-2zey92ofhilzm3p4j0o.mysql.rds.aliyuncs.com:3306/${spring.datasource.dynamic.datasource.bxg.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true + url: jdbc:mysql://${mysql.url}:${mysql.port}/${spring.datasource.dynamic.datasource.bxg.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true driver-class-name: com.mysql.cj.jdbc.Driver - username: vue_pro - password: CrnPu&g8HqbBikrA&DH-llRgtvpIrG#- - erp: # 农场数据源 - name: vue_pro_erp - url: jdbc:mysql://rm-2zey92ofhilzm3p4j0o.mysql.rds.aliyuncs.com:3306/${spring.datasource.dynamic.datasource.erp.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true - driver-class-name: com.mysql.cj.jdbc.Driver - username: vue_pro - password: CrnPu&g8HqbBikrA&DH-llRgtvpIrG#- + username: ${mysql.bxg-username} + password: ${mysql.bxg-password} # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 redis: @@ -76,6 +78,9 @@ spring: port: 6379 # 端口 database: 15 # 数据库索引 +flowable: + database-schema-update: false + --- #################### 定时任务相关配置 #################### # Quartz 配置项,对应 QuartzProperties 配置类 diff --git a/zsw-bxg/src/main/java/co/yixiang/modules/hotList/service/impl/YxStoreHotListServiceImpl.java b/zsw-bxg/src/main/java/co/yixiang/modules/hotList/service/impl/YxStoreHotListServiceImpl.java index 4cd91ddc..ee34a40f 100644 --- a/zsw-bxg/src/main/java/co/yixiang/modules/hotList/service/impl/YxStoreHotListServiceImpl.java +++ b/zsw-bxg/src/main/java/co/yixiang/modules/hotList/service/impl/YxStoreHotListServiceImpl.java @@ -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 queryAll(YxStoreHotListQueryCriteria criteria, Pageable pageable) { getPage(pageable); PageInfo page = new PageInfo<>(queryAll(criteria)); - PageResult result=generator.convertPageInfo(page, YxStoreHotListVo.class); - result.getContent().forEach(hotListVo->{ + PageResult result = generator.convertPageInfo(page, YxStoreHotListVo.class); + result.getContent().forEach(hotListVo -> { List productArr = JSONUtil.toList(hotListVo.getProductList(), Integer.class); - ArrayList list1 =new ArrayList<>(); - productArr.forEach(productId->{ + ArrayList list1 = new ArrayList<>(); + productArr.forEach(productId -> { LambdaQueryWrapper 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 queryAll(YxStoreHotListQueryCriteria criteria){ + public List queryAll(YxStoreHotListQueryCriteria criteria) { //查出所有用户拥有的券使用时间小于24小时且未使用的券 - Date now=new Date(); - Date endTime = DateUtil.offsetDay(now,1); - List storeCouponUsers=yxStoreCouponUserMapper.selectUserCouponList(endTime); - storeCouponUsers.forEach(storeCouponUser->{ + Date now = new Date(); + Date endTime = DateUtil.offsetDay(now, 1); + List storeCouponUsers = yxStoreCouponUserMapper.selectUserCouponList(endTime); + storeCouponUsers.forEach(storeCouponUser -> { //这里调用微信订阅模板发送消息 TemplateBean templateBean = TemplateBean.builder() .couponId(storeCouponUser.getCid()) @@ -135,15 +136,15 @@ public class YxStoreHotListServiceImpl extends BaseServiceImpl all, HttpServletResponse response) throws IOException { List> list = new ArrayList<>(); for (YxStoreHotListDto yxStoreHotList : all) { - Map map = new LinkedHashMap<>(); + Map 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 BaseServiceImplgetHotListDataList(){ - Map map=new HashMap<>(); + public Map getHotListDataList() { + Map map = new HashMap<>(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(YxStoreHotListRecord::getIsShow, ShopCommonEnum.SHOW_1.getValue()); wrapper.eq(YxStoreHotListRecord::getIsDel, CommonEnum.DEL_STATUS_0.getValue()); //获取所有榜单记录列表(后期限制一年?) - List list=yxStoreHotListRecordMapper.selectList(wrapper); - if(list.isEmpty()){ + List list = yxStoreHotListRecordMapper.selectList(wrapper); + if (list.isEmpty()) { return null; } //获取月份 - LinkedHashSet mouthList=new LinkedHashSet<>(); + LinkedHashSet mouthList = new LinkedHashSet<>(); list.forEach(yxStoreHotListRecord -> mouthList.add(yxStoreHotListRecord.getMouth())); - map.put("mouthList",mouthList); - mouthList.forEach(mouth->{ - LambdaQueryWrapper wrapper2= SerializationUtils.clone(wrapper); + map.put("mouthList", mouthList); + mouthList.forEach(mouth -> { + LambdaQueryWrapper wrapper2 = SerializationUtils.clone(wrapper); //当前月份的所有榜单记录信息 - List recordList=yxStoreHotListRecordMapper.selectList(wrapper2.eq(YxStoreHotListRecord::getMouth,mouth)); - LinkedHashSet hotIdList=new LinkedHashSet<>(); + List recordList = yxStoreHotListRecordMapper.selectList(wrapper2.eq(YxStoreHotListRecord::getMouth, mouth)); + LinkedHashSet 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 wrapperList=new LambdaQueryWrapper<>(); - wrapperList.in(YxStoreHotList::getId,hotIdList).orderByAsc(YxStoreHotList::getSort); - ArrayList list1=new ArrayList<>(); - yxStoreHotListMapper.selectList(wrapperList).forEach(yxHotList->list1.add(yxHotList.getId())); - ArrayList hotListDTOS=new ArrayList<>(); - list1.forEach(hotId->{ - LambdaQueryWrapper wrapper1= SerializationUtils.clone(wrapper); - //查出当前月份当前榜单的记录 - List recordCateList=yxStoreHotListRecordMapper.selectList(wrapper1.eq(YxStoreHotListRecord::getHotListId,hotId).eq(YxStoreHotListRecord::getMouth,mouth)); - LinkedHashSet cateIdList=new LinkedHashSet<>(); - //获得不重复的商品分类id - recordCateList.forEach(cate->{ - if(ObjectUtil.isNotNull(storeCategoryMapper.selectById(cate.getCateId()))) - cateIdList.add(cate.getCateId()); - }); - ArrayList 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 wrapperList = new LambdaQueryWrapper<>(); + wrapperList.in(YxStoreHotList::getId, hotIdList).orderByAsc(YxStoreHotList::getSort); + ArrayList list1 = new ArrayList<>(); + yxStoreHotListMapper.selectList(wrapperList).forEach(yxHotList -> list1.add(yxHotList.getId())); + ArrayList hotListDTOS = new ArrayList<>(); + list1.forEach(hotId -> { + LambdaQueryWrapper wrapper1 = SerializationUtils.clone(wrapper); + //查出当前月份当前榜单的记录 + List recordCateList = yxStoreHotListRecordMapper.selectList(wrapper1.eq(YxStoreHotListRecord::getHotListId, hotId).eq(YxStoreHotListRecord::getMouth, mouth)); + LinkedHashSet cateIdList = new LinkedHashSet<>(); + //获得不重复的商品分类id + recordCateList.forEach(cate -> { + if (ObjectUtil.isNotNull(storeCategoryMapper.selectById(cate.getCateId()))) + cateIdList.add(cate.getCateId()); + }); + ArrayList 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 pageModel = new Page<>(queryParam.getPage(), queryParam.getLimit()); IPage pageList = yxStoreHotListRecordMapper.selectPage(pageModel, wrapper); - List list =new ArrayList<>(); + List 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 getList() { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(YxStoreHotListRecord::getIsShow, ShopCommonEnum.SHOW_1.getValue()); wrapper.eq(YxStoreHotListRecord::getIsDel, CommonEnum.DEL_STATUS_0.getValue()); //获取所有榜单记录列表(后期限制一年?) - List list=yxStoreHotListRecordMapper.selectList(wrapper); - if(list.isEmpty()){ + List list = yxStoreHotListRecordMapper.selectList(wrapper); + if (list.isEmpty()) { return null; } //获取月份 - LinkedHashSet mouthList=new LinkedHashSet<>(); + LinkedHashSet mouthList = new LinkedHashSet<>(); list.forEach(yxStoreHotListRecord -> mouthList.add(yxStoreHotListRecord.getMouth())); - String mouth=Collections.max(mouthList);//设定月份为最近的月份 + String mouth = Collections.max(mouthList);//设定月份为最近的月份 //获取当前月份的榜单记录 - List recordList=yxStoreHotListRecordMapper.selectList(wrapper.eq(YxStoreHotListRecord::getMouth,mouth)); - LinkedHashSet hotIdList=new LinkedHashSet<>(); + List recordList = yxStoreHotListRecordMapper.selectList(wrapper.eq(YxStoreHotListRecord::getMouth, mouth)); + // ??? + LinkedHashSet 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 wrapperList=new LambdaQueryWrapper<>(); - wrapperList.in(YxStoreHotList::getId,hotIdList).orderByAsc(YxStoreHotList::getSort); - ArrayList list1=new ArrayList<>(); - yxStoreHotListMapper.selectList(wrapperList).forEach(yxHotList->list1.add(yxHotList.getId())); - ArrayList hotListDTOS=new ArrayList<>(); + LambdaQueryWrapper wrapperList = new LambdaQueryWrapper<>(); + wrapperList.in(YxStoreHotList::getId, hotIdList).orderByAsc(YxStoreHotList::getSort); + // 榜单ID + ArrayList list1 = new ArrayList<>(); + yxStoreHotListMapper.selectList(wrapperList).forEach( + yxHotList -> list1.add(yxHotList.getId()) + ); + ArrayList hotListDTOS = new ArrayList<>(); //已经排序过的榜单 - list1.forEach(hotId->{ - LambdaQueryWrapper wrapper1= SerializationUtils.clone(wrapper); + list1.forEach(hotId -> { + LambdaQueryWrapper wrapper1 = SerializationUtils.clone(wrapper); //查出当前月份当前榜单的记录 - List recordCateList=yxStoreHotListRecordMapper.selectList(wrapper1.eq(YxStoreHotListRecord::getHotListId,hotId).eq(YxStoreHotListRecord::getMouth,mouth)); + List recordCateList = yxStoreHotListRecordMapper.selectList(wrapper1.eq(YxStoreHotListRecord::getHotListId, hotId).eq(YxStoreHotListRecord::getMouth, mouth)); //获得不重复的商品分类id - LinkedHashSet cateIdList=new LinkedHashSet<>(); + LinkedHashSet cateIdList = new LinkedHashSet<>(); //当前榜单下的商品信息 - List productInfo=new ArrayList<>(); + List 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 cateDtos=new ArrayList<>(); + ArrayList 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 getHotListDTOS(LambdaQueryWrapper wrapper) { - List list = generator.convert(baseMapper.selectList(wrapper),HotListDTO.class); + List list = generator.convert(baseMapper.selectList(wrapper), HotListDTO.class); // list.forEach(hotListDto->{ // List productArr = JSONUtil.toList(hotListDto.getProductList(), Integer.class); // List list1 =new ArrayList<>();