package com.ruoyi.test;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ruoyi.demo.entity.AddrCategory;
import com.ruoyi.demo.mapper.AddrCategoryDao;
import com.ruoyi.demo.utils.statistics.BrandCityTierStat;
import org.checkerframework.checker.units.qual.A;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;
import java.util.stream.Collectors;

@SpringBootTest
public class StatTest {
    @Autowired
    BrandCityTierStat brandCityTierStat;

    @Autowired
    AddrCategoryDao addrCategoryDao;
    @Test
    public void test(){
        brandCityTierStat.start();
    }

    @Test
    public void continueTest(){
        brandCityTierStat.continueInsert();
    }

    @Test
    public void cityTier(){
        QueryWrapper<AddrCategory> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type","city");
        queryWrapper.and(categoryQueryWrapper -> {
            categoryQueryWrapper.isNotNull("city_tier");
        });
        List<AddrCategory> addrCategories = addrCategoryDao.selectList(queryWrapper);

        for (AddrCategory addrCategory : addrCategories) {
            UpdateWrapper<AddrCategory> queryWrapper1 = new UpdateWrapper<>();
            queryWrapper1.eq("type","zone");
            queryWrapper1.and(addrCategoryUpdateWrapper -> {
                addrCategoryUpdateWrapper.likeRight("addr_code",addrCategory.getAddrCode().substring(0,4));
            });
            queryWrapper1.set("city_tier",addrCategory.getCityTier());
            addrCategoryDao.update(null,queryWrapper1);
        }
    }

    @Test
    public void newStart(){
        brandCityTierStat.newStart();
    }
}
