package com.skr.mdm.api.common.service.impl;

import com.skr.mdm.api.common.service.PublicService;
import com.skr.mdm.dao.AuAdminDao;
import com.skr.mdm.entity.AuAdministratorDO;
import com.skr.mdm.enums.ResultCodeEnum;
import com.skr.mdm.result.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @ProjectName: mdm_new
 * @Package: com.skr.mdm.publicController.service
 * @ClassName: AuUserAndDepartmentService
 * @Author: Tty
 * @Description: 下发页面接口实现
 * @Date: 2020/7/31 16:27
 * @Version: 1.0
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class PublicServiceImpl implements PublicService {

    @Autowired
    private AuAdminDao adminDao;
    @Autowired
    private BCryptPasswordEncoder passwordEncoder;


    @Override
    public ResponseResult checkPassword(String password, Integer adminId) {
        AuAdministratorDO administratorDO = adminDao.selectById(adminId);
        boolean matches = false;
        if (administratorDO != null) {
            matches = passwordEncoder.matches(password, administratorDO.getPassword());
        }
        if (matches) {
            return ResponseResult.success();
        }
        return ResponseResult.failure(ResultCodeEnum.PASSWORD_FAILURE);
    }

}