package cn.com.qmth.examcloud.tool;

import cn.com.qmth.examcloud.tool.cache.LoginSessionManager;
import cn.com.qmth.examcloud.tool.config.SysProperty;
import cn.com.qmth.examcloud.tool.entity.TaskEntity;
import cn.com.qmth.examcloud.tool.service.CommonService;
import cn.com.qmth.examcloud.tool.service.create_random_paper_template.CreateRandomPaperTemplateTask;
import cn.com.qmth.examcloud.tool.service.query_paper_struct.QueryPaperStructTask;
import cn.com.qmth.examcloud.tool.service.reset_student_password.ResetStudentPasswordTask;
import cn.com.qmth.examcloud.tool.utils.JsonMapper;
import cn.com.qmth.examcloud.tool.vo.user.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.HashMap;
import java.util.Map;

@RunWith(SpringRunner.class)
@SpringBootTest
public class ToolTest {

    @Autowired
    private CommonService commonService;

    @Autowired
    private SysProperty sysProperty;

    @Autowired
    private ResetStudentPasswordTask resetStudentPasswordTask;

    @Autowired
    private QueryPaperStructTask queryPaperStructTask;

    @Autowired
    private CreateRandomPaperTemplateTask createRandomPaperTemplateTask;

    @Test
    public void demo() throws Exception {
        User user = doLogin();

        // resetStudentPasswordTask.start(user, 0L);
        // queryPaperStructTask.start(user, 0L);
        // createRandomPaperTemplate(user);
    }

    private void createRandomPaperTemplate(User user) {
        Map<String, Object> params = new HashMap<>();
        params.put("examId", 81);
        params.put("questionPool", 1);
        params.put("structType", 1);
        params.put("structName", "精确结构2023");
        params.put("paperKeywords", "_2,_3");

        TaskEntity task = new TaskEntity();
        task.setUserToken(user.getToken());
        task.setParams(new JsonMapper().toJson(params));
        createRandomPaperTemplateTask.start(task);
    }

    private User doLogin() {
        String serverUrl = "org0.dev39.qmth.com.cn";
        String loginName = "admin9";
        String password = "0";
        String smsCode = "5220";

        User user = commonService.login(serverUrl, loginName, password, smsCode);
        LoginSessionManager.addLoginSession(user);
        return user;
    }

}
