Przeglądaj źródła

新增通过筛选企业过滤品牌功能

JensionDzero 1 rok temu
rodzic
commit
c9f5ba5cfb

+ 6 - 8
ruoyi-demo/src/main/java/com/ruoyi/demo/controller/BrandController.java

@@ -1,10 +1,13 @@
 package com.ruoyi.demo.controller;
 
 import cn.dev33.satoken.stp.StpUtil;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.helper.LoginHelper;
 import com.ruoyi.demo.constant.RedisContant;
 import com.ruoyi.demo.entity.bo.BrandGeoLabelBo;
+import com.ruoyi.demo.entity.bo.BrandSearch;
 import com.ruoyi.demo.entity.vo.BrandEvolveVo;
 import com.ruoyi.demo.entity.vo.ListQueryBody;
 import com.ruoyi.demo.entity.vo.OpcloseTimeVo;
@@ -50,10 +53,8 @@ public class BrandController extends BaseController {
      */
     @PostMapping("/list")
     public R list(ListQueryBody body) {
-        String loginId = String.valueOf(StpUtil.getLoginId());
-        Long userid = Long.valueOf(loginId.split(":")[1]);
-        String userId = userid.toString();
-        return R.ok(brandService.searchListByMulti(body, userId));
+        Page<BrandSearch> brandSearchPage = brandService.searchListByMulti(body, String.valueOf(LoginHelper.getUserId()));
+        return R.ok(brandSearchPage);
     }
 
     /**
@@ -64,10 +65,7 @@ public class BrandController extends BaseController {
      */
     @GetMapping("/info")
     public R info(String brandId) {
-        String loginId = String.valueOf(StpUtil.getLoginId());
-        Long userid = Long.valueOf(loginId.split(":")[1]);
-        String userId = userid.toString();
-        return R.ok(brandService.searchByBrandId(brandId, userId));
+        return R.ok(brandService.searchByBrandId(brandId, String.valueOf(LoginHelper.getUserId())));
     }
 
     /**

+ 1 - 0
ruoyi-demo/src/main/java/com/ruoyi/demo/entity/vo/ListQueryBody.java

@@ -34,6 +34,7 @@ public class ListQueryBody implements Serializable {
     private Integer pageSize;
 
     //企业过滤条件
+    private Boolean isOpenEnterprise = false; //是否开启企业过滤
     private String enterpriseName;
     private String businessStatus;
     private String enterpriseType;

+ 4 - 1
ruoyi-demo/src/main/java/com/ruoyi/demo/mapper/BrandMapper.java

@@ -1,9 +1,12 @@
 package com.ruoyi.demo.mapper;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
+import com.baomidou.mybatisplus.core.toolkit.Constants;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.demo.entity.Brand;
+import com.ruoyi.demo.entity.Enterprise;
 import com.ruoyi.demo.entity.bo.BrandSearch;
 import com.ruoyi.demo.entity.vo.BrandVo;
 import org.apache.ibatis.annotations.Mapper;
@@ -15,7 +18,7 @@ import java.util.List;
 public interface BrandMapper extends BaseMapper<Brand> {
     List<Brand> searchByIndustryCodeList(String brandId, String manageTypeCode);
 
-    List<BrandSearch> searchSearchByMulti(@Param("text") String text, @Param("industryCode") List<String> industryCode, @Param("countUp") Integer countUp, @Param("countDown") Integer countDown, @Param("coverUp") Integer coverUp, @Param("coverDown") Integer coverDown);
+    Page<BrandSearch> searchSearchByMulti(Page<BrandSearch> page, @Param("text") String text, @Param("countUp") Integer countUp, @Param("countDown") Integer countDown, @Param("coverUp") Integer coverUp, @Param("coverDown") Integer coverDown, @Param(Constants.WRAPPER) QueryWrapper<Enterprise> queryWrapper);
 
     //管理中心:品牌回收站
     Page<Brand> list(Page<Brand> page,@Param("brand") BrandVo brandVo);

+ 1 - 1
ruoyi-demo/src/main/java/com/ruoyi/demo/service/BrandService.java

@@ -30,7 +30,7 @@ public interface BrandService {
 
     BrandDisCloud searchDisCloudByBrandId(String brandId);
 
-    PageInfo<List<BrandSearch>> searchListByMulti(ListQueryBody body, String userId);
+    Page<BrandSearch> searchListByMulti(ListQueryBody body, String userId);
 
     List<BrandTotal> searchTotal(Integer pageSize);
 

+ 48 - 25
ruoyi-demo/src/main/java/com/ruoyi/demo/service/impl/BrandServiceImpl.java

@@ -23,6 +23,7 @@ import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
 public class BrandServiceImpl implements BrandService {
@@ -63,6 +64,7 @@ public class BrandServiceImpl implements BrandService {
     @Autowired
     BrandCityTierMapper tierMapper;
 
+
     @Override
     public List<BrandSearch> searchByLikeName(String text) {
         // 根据品牌名称模糊查询
@@ -73,18 +75,18 @@ public class BrandServiceImpl implements BrandService {
 
         List<BrandSearch> sList = new ArrayList<>();
         // 补齐品牌的企业信息
-        for (Brand brand : list) {
-            QueryWrapper<Enterprise> enterpriseQueryWrapper = new QueryWrapper<>();
-            enterpriseQueryWrapper.eq("enterprise_usci", brand.getEnterpriseUsci());
-            Enterprise enterprise = enterpriseMapper.selectOne(enterpriseQueryWrapper);
-            BrandSearch bs = new BrandSearch();
-            bs.setBrandId(brand.getBrandId());
-            bs.setBrandName(brand.getBrandName());
-            if (enterprise != null)
-                bs.setEnterpriseName(enterprise.getEnterpriseName());
-            bs.setUpdateTime(brand.getUpdateTime());
-            sList.add(bs);
-        }
+//        for (Brand brand : list) {
+//            QueryWrapper<Enterprise> enterpriseQueryWrapper = new QueryWrapper<>();
+//            enterpriseQueryWrapper.eq("enterprise_usci", brand.getEnterpriseUsci());
+//            Enterprise enterprise = enterpriseMapper.selectOne(enterpriseQueryWrapper);
+//            BrandSearch bs = new BrandSearch();
+//            bs.setBrandId(brand.getBrandId());
+//            bs.setBrandName(brand.getBrandName());
+//            if (enterprise != null)
+//                bs.setEnterpriseName(enterprise.getEnterpriseName());
+//            bs.setUpdateTime(brand.getUpdateTime());
+//            sList.add(bs);
+//        }
         return sList;
     }
 
@@ -98,7 +100,7 @@ public class BrandServiceImpl implements BrandService {
 
         if (brand == null)
             return null;
-        // 查询企业
+/*        // 查询企业
         QueryWrapper<Enterprise> enterpriseQueryWrapper = new QueryWrapper<>();
         enterpriseQueryWrapper.eq("enterprise_usci", brand.getEnterpriseUsci());
         Enterprise enterprise = enterpriseMapper.selectOne(enterpriseQueryWrapper);
@@ -109,12 +111,13 @@ public class BrandServiceImpl implements BrandService {
             industryCategoryQueryWrapper.eq("industry_code", brand.getIndustryCode());
             IndustryCategory industryCategory = industryCategoryDao.selectOne(industryCategoryQueryWrapper);
             info.setIndustryName(industryCategory != null ? industryCategory.getSubCategory() : null);
-        } else info.setIndustryName(null);
+        } else info.setIndustryName(null);*/
         // 是否已经关注
         QueryWrapper<AttentionPool> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("brand_id", brandId)
             .eq("wd_id", "");
         AttentionPool pool = attentionPoolDao.selectOne(queryWrapper);
+        BrandInfo info = new BrandInfo(brand,null);
         info.setAttention(pool == null ? 0 : 1);
         return info;
     }
@@ -255,13 +258,32 @@ public class BrandServiceImpl implements BrandService {
     }
 
     @Override
-    public PageInfo<List<BrandSearch>> searchListByMulti(ListQueryBody body, String userId) {
-        PageHelper.startPage(body.getPageNum(), body.getPageSize(), true);
-        List<String> industryCode = body.getIndustryCode();
-        /*
-        industryCode行业类别码,例如101000,但不确定,需要对其拆解,查询其子类别。
-        因数据库数据不齐,这里没有进行相关处理
-         */
+    public Page<BrandSearch> searchListByMulti(ListQueryBody body, String userId) {
+        QueryWrapper<Enterprise> queryWrapper = null;
+        //过滤企业
+        if (body.getIsOpenEnterprise()){
+            queryWrapper = new QueryWrapper<>();
+            queryWrapper.select("enterprise_usci");
+            //获取符合条件的企业id
+            //营业状态
+            if (body.getBusinessStatus() != null && !body.getBusinessStatus().equals("")) {
+                queryWrapper.eq("business_status",body.getBusinessStatus());
+            }
+            //企业类型
+            if (body.getEnterpriseType() != null && !body.getEnterpriseType().equals("")) {
+                queryWrapper.and(stringQueryWrapper -> {
+                    stringQueryWrapper.eq("enterprise_type",body.getEnterpriseType());
+                });
+            }
+            //企业名称
+            if (body.getEnterpriseName() != null && !body.getEnterpriseName().equals("")) {
+                queryWrapper.and(stringQueryWrapper -> {
+                    stringQueryWrapper.like("enterprise_name",body.getEnterpriseName());
+                });
+            }
+        }
+
+        Page<BrandSearch> page = new Page<>(body.getPageNum(), body.getPageSize());
         Integer countDown = null;
         Integer countUp = null;
         Integer coverDown = null;
@@ -282,10 +304,11 @@ public class BrandServiceImpl implements BrandService {
                 coverUp = Integer.parseInt(body.getCoverCityCount().get(1));
             }
         }
-        List<BrandSearch> brandSearches = brandMapper.searchSearchByMulti(body.getText(), industryCode, countUp, countDown, coverUp, coverDown);
+
+        Page<BrandSearch> brandSearches = brandMapper.searchSearchByMulti(page,body.getText(), countUp, countDown, coverUp, coverDown,queryWrapper);
         // 赋予attention字段信息,0:未关注;1:已关注
         if (userId == null || userId.equals("")) { // 用户未登录或无效用户id,都是未关注状态
-            for (BrandSearch search : brandSearches) {
+            for (BrandSearch search : brandSearches.getRecords()) {
                 QueryWrapper<Enterprise> enterpriseQueryWrapper = new QueryWrapper<>();
                 enterpriseQueryWrapper.eq("enterprise_usci", search.getEnterpriseName());
                 Enterprise enterprise = enterpriseMapper.selectOne(enterpriseQueryWrapper);
@@ -297,7 +320,7 @@ public class BrandServiceImpl implements BrandService {
             Map<String, String> map = new HashMap<>();
             for (AttentionPool pool : pools)
                 map.put(pool.getBrandId(), "1");
-            for (BrandSearch search : brandSearches) {
+            for (BrandSearch search : brandSearches.getRecords()) {
                 QueryWrapper<Enterprise> enterpriseQueryWrapper = new QueryWrapper<>();
                 enterpriseQueryWrapper.eq("enterprise_usci", search.getEnterpriseName());
                 Enterprise enterprise = enterpriseMapper.selectOne(enterpriseQueryWrapper);
@@ -305,7 +328,7 @@ public class BrandServiceImpl implements BrandService {
                 search.setAttention(map.get(search.getBrandId()) == null ? 0 : 1);
             }
         }
-        return new PageInfo(brandSearches);
+        return brandSearches;
     }
 
     @Override

+ 6 - 8
ruoyi-demo/src/main/resources/mapper/demo/BrandMapper.xml

@@ -57,14 +57,6 @@
             `bl_brand_statistics` bbs
         WHERE
             bbs.brand_id = db.brand_id and show_delete=0
-        <if test="text != null">
-            AND db.brand_name LIKE concat('%',#{text},'%')
-        </if>
-        <if test="industryCode != null">
-            <foreach collection="industryCode" item="industry_code" open="AND db.industry_code IN (" separator="," close=")">
-                #{industry_code,jdbcType=VARCHAR}
-            </foreach>
-        </if>
         <if test="countDown != null">
             AND #{countDown} <![CDATA[<=]]> total
         </if>
@@ -77,6 +69,12 @@
         <if test="coverUp != null">
             AND cover_city_count <![CDATA[<=]]> #{coverUp}
         </if>
+        <if test="text != null">
+            AND db.brand_name LIKE concat('%',#{text},'%')
+        </if>
+        <if test="ew != null">
+            AND db.enterprise_usci in (select enterprise_usci from ddt_enterprise ${ew.customSqlSegment})
+        </if>
     </select>
     <select id="list" parameterType="com.ruoyi.demo.entity.vo.BrandVo" resultType="com.ruoyi.demo.entity.Brand">
         select * from ddt_brand