package com.moka.gdtauto.service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.util.DigestUtils;

import com.moka.gdtauto.GdtAutoApplication;
import com.moka.gdtauto.entity.SysUser;

/**
 * mvn test -Dtest=SysUserTest#createNewUser -Dspring.profiles.active=test
 */
@SpringBootTest(classes = GdtAutoApplication.class)
@ActiveProfiles("test")
public class SysUserTest {
    
    //默认密码
    private static final String DEFAULT_PASSWORD = "123456";
    //工号
    private static final String JOB_NUMBER = "12016";
    private static final String NAME = "黄瀚文";

    static class User {
        String jobNumber;
        String name;
        String phone;
    }

    @Autowired
    private SysUserService sysUserService;
    
    private static List<User> users = List.of(
        new User(){{
            jobNumber = "12960";
            name = "范展鹏";
            phone = "12345678901";
        }}
    );

    @Test
    public void createNewUser() {
        for (User user : users) {
            String pwd = DEFAULT_PASSWORD + "#" + user.jobNumber;
            System.out.println(pwd);
            String password = DigestUtils.md5DigestAsHex(pwd.getBytes());
            SysUser sysUser = new SysUser();
            sysUser.setPhone(user.phone);
            sysUser.setJobNumber(user.jobNumber);
            sysUser.setPassword(password);
            sysUser.setStatus(1);
            sysUser.setDefaultPwd(1);
            sysUser.setName(user.name);
            sysUserService.save(sysUser);
            System.out.println(sysUser.getId());
        }
    }
}
