package com.nokia.tsl_data;

import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import com.nokia.tsl_data.dao.TargetTsRatioMapper;
import com.nokia.tsl_data.service.TaskService;
import com.nokia.tsl_data.service.UserCountService;
import com.nokia.tsl_data.util.TextUtil;

@SpringBootTest
class TslDataApplicationTest {

    @Autowired
    private TaskService taskService;

    @Test
    void test() {
        taskService.generateReportV3("20241202");
    }

    @Test
    void test1() {
        taskService.runTaskForDay("20241205");
    }

    @Autowired
    private UserCountService userCountService;

    @Test
    void test2() {
        String path = "/data/abc.txt";
        List<String> lines = TextUtil.readLines(path, "utf8");
        lines.forEach(line -> {
            String[] split = line.split("\t");
            System.out.println(split[0] + "==" + split[2]);
            userCountService.updateManagementUserCount("202506", split[0], Double.parseDouble(split[2]));
        });
    }

    @Autowired
    private TargetTsRatioMapper targetTsRatioMapper;

    @Test
    void test3() {
        String path = "/data/abc.txt";
        List<String> lines = TextUtil.readLines(path, "utf8");
        lines.forEach(line -> {
            String[] split = line.split("\t");
            for (int i = 1; i < split.length; i++) {
                String city = split[0];
                String month = i < 10 ? "20250" + i : "2025" + i;
                Double target = Double.parseDouble(split[i]);
                System.out.println("地市: " + city + "  月分: " + month + "  率值: " + target);
                int r = targetTsRatioMapper.updateManagementTargetRatio(month, city, target);
                if (r == 1) {
                    System.out.println("更新成功");
                } else {
                    targetTsRatioMapper.insertManagementTargetRatio(month, city, target);
                }
            }
        });
    }

    @Test
    void test4() {
        String path = "/data/abc.txt";
        List<String> lines = TextUtil.readLines(path, "utf8");
        lines.forEach(line -> {
            String[] split = line.split("\t");
            for (int i = 1; i < split.length; i++) {
                String city = split[0];
                String month = i < 10 ? "20250" + i : "2025" + i;
                Double target = Double.parseDouble(split[i]);
                System.out.println("地市: " + city + "  月分: " + month + "  率值: " + target);
                targetTsRatioMapper.updateServiceRequestTargetRatio(month, city, target);
            }
        });
    }

}