package com.ruoyi.demo.utils.statistics;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.demo.entity.AddrCategory;
import com.ruoyi.demo.entity.BrandZone;
import com.ruoyi.demo.mapper.AddrCategoryDao;
import com.ruoyi.demo.mapper.BrandDao;
import com.ruoyi.demo.mapper.BrandZoneDao;
import com.ruoyi.demo.mapper.StoreWdDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.List;
import java.util.UUID;

@Component
public class BrandZoneStat {
    @Autowired
    StoreWdDao storeDao;
    @Autowired
    BrandZoneDao brandZoneDao;
    @Autowired
    AddrCategoryDao addrCategoryDao;
    @Autowired
    BrandDao brandDao;

    public void continueQuicklyInsert(){
        List<String> ins = brandDao.selectAllId();
        List<BrandZone> zones = brandZoneDao.searchQuicklyStatistics(ins);
        int total = zones.size();
        int i = 0;
        for (BrandZone zone : zones) {
            zone.setDisId(UUID.randomUUID().toString().replace("-",""));
            zone.setUpdateTime(LocalDateTime.now(ZoneId.of("Asia/Shanghai")));

            QueryWrapper<AddrCategory> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("addr_code",zone.getAddrCode());
            AddrCategory one = addrCategoryDao.selectOne(queryWrapper);
            if (one != null){
                zone.setZone(one.getDistrict());
                zone.setCity(one.getCity());
                zone.setProvince(one.getProvince());
                zone.setLat(one.getLatGd());
                zone.setLng(one.getLngGd());
            }

            i += brandZoneDao.insert(zone);
            System.out.println(i+"/"+total);
        }
    }
}
