package com.ningdatech.kqapi.menu;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ningdatech.kqapi.AppTests;
import com.ningdatech.kqapi.user.model.entity.UserAuth;
import com.ningdatech.kqapi.user.model.po.ModifyPasswordReq;
import com.ningdatech.kqapi.user.service.IUserAuthService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.time.LocalDateTime;

/**
 * @Classname DuplicationTest
 * @Description
 * @Date 2023/11/17 10:42
 * @Author PoffyZhang
 */
public class DuplicationTest extends AppTests {

    @Autowired
    private PasswordEncoder passwordEncoder;
    @Autowired
    private IUserAuthService userAuthService;
    @Test
    public void test() {
        ModifyPasswordReq req = new ModifyPasswordReq();
        req.setUserId(1L);
        req.setPassword("123456Aa");
        // 更新密码
        String password = passwordEncoder.encode(req.getPassword());
        Wrapper<UserAuth> update = Wrappers.lambdaUpdate(UserAuth.class)
                .set(UserAuth::getCredential, password)
                .set(UserAuth::getUpdateOn, LocalDateTime.now())
                .eq(UserAuth::getUserId, req.getUserId());
        userAuthService.update(update);
    }

}
