package com.shulead.datasync.controller;

import cn.hutool.core.exceptions.ExceptionUtil;
import com.shulead.datasync.bo.Response;
import com.shulead.datasync.manager.DataSyncManager;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname DataSyncController
 * @Description TODO
 * @Version 1.0.0
 * @Date 2024/5/8 10:10
 * @Created by liuxiangshun
 */
@Slf4j
@RestController
@RequestMapping("/datasync")
public class DataSyncController {
    @Resource
    private DataSyncManager dataSyncManager;

    @GetMapping("init/student/{start}/{limit}")
    public Boolean initStudent(@PathVariable("start") Long start, @PathVariable("limit") Integer limit) {
        new Thread(() -> dataSyncManager.initSyncStudent(start, limit)).start();
        return true;
    }

    @GetMapping("init/class/{start}/{limit}")
    public Boolean initClass(@PathVariable("start") Long start, @PathVariable("limit") Integer limit) {
        new Thread(() -> dataSyncManager.initSyncClass(start, limit)).start();
        return true;
    }

    @GetMapping("init/hzqu")
    public Boolean initHzqy() {
        new Thread(() -> dataSyncManager.initSyncHzqy()).start();
        return true;
    }

    @GetMapping("init/consociation")
    public Boolean initConsociation() {
        new Thread(() -> dataSyncManager.initSyncConsociation()).start();
        return true;
    }

    @GetMapping("getStudentByMobile/{mobile}")
    public Response getStudentByMobile(@PathVariable String mobile) {
        return Response.success(dataSyncManager.getStudentByMobile(mobile));
    }

    @GetMapping("createHz06/{id}")
    public Response createHz06(@PathVariable String id) {
        try {
            return Response.success(dataSyncManager.createHz06(id, "FORM-040619C0CE6744EDA4154B4BBBF1843F49JY"));
        } catch (Exception e) {
            log.error(ExceptionUtil.getMessage(e));
            return Response.fail(null);
        }
    }

    @GetMapping("createHz06School/{id}")
    public Response createHz06School(@PathVariable String id) {
        try {
            return Response.success(dataSyncManager.createHz06School(id, "FORM-3326B8C175744D73B8580505401D2C5FCFOZ"));
        } catch (Exception e) {
            log.error(ExceptionUtil.getMessage(e));
            return Response.fail(null);
        }
    }

    @GetMapping("createCoupon/{id}")
    public Response createCoupon(@PathVariable String id) {
        try {
            return Response.success(dataSyncManager.createCoupon(id, "FORM-6BE5643A8A4142BBB1A7F7CE90F50E787NAF"));
        } catch (Exception e) {
            log.error(ExceptionUtil.getMessage(e));
            return Response.fail(null);
        }
    }
}
