|
@@ -1,12 +1,19 @@
|
|
|
package com.ruoyi.benyun;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.ruoyi.benyun.constant.RedisContant;
|
|
|
import com.ruoyi.benyun.constant.RedisInitContant;
|
|
|
+import com.ruoyi.benyun.entity.Brand;
|
|
|
+import com.ruoyi.benyun.entity.StoreWd;
|
|
|
+import com.ruoyi.benyun.mapper.BrandMapper;
|
|
|
+import com.ruoyi.benyun.mapper.StoreWdDao;
|
|
|
import com.ruoyi.benyun.mapper.WdInfoDao;
|
|
|
import com.ruoyi.benyun.service.WriteService;
|
|
|
import com.ruoyi.benyun.utils.WdRedisStoreage;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
import org.springframework.data.redis.core.BoundValueOperations;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
@@ -18,6 +25,7 @@ import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@SpringBootTest
|
|
|
class BenyunCoreApplicationTests {
|
|
@@ -36,8 +44,74 @@ class BenyunCoreApplicationTests {
|
|
|
@Autowired
|
|
|
WriteService writeService;
|
|
|
|
|
|
+ @Value("${clear.BrandNames}")
|
|
|
+ String[] brandNames;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ BrandMapper brandMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ StoreWdDao storeWdDao;
|
|
|
+
|
|
|
@Test
|
|
|
void contextLoads() {
|
|
|
+ ArrayList<String> moreBrandName = new ArrayList<>();
|
|
|
+ ArrayList<String> existBrandName = new ArrayList<>();
|
|
|
+ for (String brandName : brandNames) {
|
|
|
+ //1.找到主品牌
|
|
|
+ QueryWrapper<Brand> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.select("brand_id","brand_name");
|
|
|
+ queryWrapper.eq("brand_name",brandName);
|
|
|
+ try {
|
|
|
+ Brand brand = brandMapper.selectOne(queryWrapper);
|
|
|
+ if (brand == null){
|
|
|
+ existBrandName.add(brandName);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //2.找到其他类似的品牌名
|
|
|
+ QueryWrapper<Brand> queryWrapper1 = new QueryWrapper<>();
|
|
|
+ queryWrapper1.select("brand_id","brand_name");
|
|
|
+ queryWrapper1.like("brand_name",brandName);
|
|
|
+
|
|
|
+ queryWrapper1.and(brandQueryWrapper -> {
|
|
|
+ brandQueryWrapper.ne("brand_id",brand.getBrandId());
|
|
|
+ });
|
|
|
+ List<Brand> brands = brandMapper.selectList(queryWrapper1);
|
|
|
+
|
|
|
+ //3.修改对应的品牌绑定
|
|
|
+ List<Object> collect = brands.stream().map(item -> {
|
|
|
+ return item.getBrandId();
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ if (collect.isEmpty())
|
|
|
+ continue;
|
|
|
+
|
|
|
+ UpdateWrapper<StoreWd> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.set("brand_id",brand.getBrandId());
|
|
|
+ updateWrapper.set("brand_name",brand.getBrandName());
|
|
|
+ updateWrapper.in("brand_id",collect);
|
|
|
+ storeWdDao.update(null,updateWrapper);
|
|
|
+
|
|
|
+ //4.修改完毕后,删除对应的品牌信息
|
|
|
+ QueryWrapper<Brand> queryWrapper2 = new QueryWrapper<>();
|
|
|
+ queryWrapper2.in("brand_id",collect);
|
|
|
+ brandMapper.delete(queryWrapper2);
|
|
|
+ }catch (Exception exception){
|
|
|
+ exception.printStackTrace();
|
|
|
+ moreBrandName.add(brandName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println("不存在品牌:");
|
|
|
+ for (String s : existBrandName) {
|
|
|
+ System.out.println(s);
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println("出错品牌:");
|
|
|
+ for (String s : moreBrandName) {
|
|
|
+ System.out.println(s);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|