package com.usoft.credit.rest.domain;

import com.usoft.credit.dal.entity.User;
import com.usoft.credit.dal.mapper.UserMapper;
import com.usoft.credit.rest.api.protobuf.EnterpriseQueryRequest;
import com.usoft.credit.rest.api.protobuf.PersonQueryRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liuam
 * @since 2018/8/7 0007 下午 14:32
 */
@Service
public class UserDomain {

    @Autowired
    private UserMapper userMapper;

    /**
     * 验证 EnterpriseQueryRequest 的 user 信息是否正确
     * @return true 正确
     */
    public boolean verifyEnterprise(EnterpriseQueryRequest request) {
        String password = request.getUser().getPassword();
        int useruu = request.getUser().getUseruu();
        int enuu = request.getUser().getEnuu();
        User user = new User();
        user.setPassword(password);
        user.setEnuu(enuu);
        user.setUseruu(useruu);
        User selectUser = userMapper.selectByUser(user);
        if (selectUser == null) {
            return false;
        }
        return true;
    }

    /**
     * 验证 PersonQueryRequest 的 user 信息是否正确
     * @return true 正确
     */
    public boolean verifyPerson(PersonQueryRequest request) {
        String password = request.getUser().getPassword();
        int useruu = request.getUser().getUseruu();
        int enuu = request.getUser().getEnuu();
        User user = new User();
        user.setPassword(password);
        user.setEnuu(enuu);
        user.setUseruu(useruu);
        User selectUser = userMapper.selectByUser(user);
        if (selectUser == null) {
            return false;
        }
        return true;
    }
}
