package com.hai.service.impl;

import com.hai.dao.HighUserPayPasswordMapper;
import com.hai.entity.HighUserPayPassword;
import com.hai.entity.HighUserPayPasswordExample;
import com.hai.service.HighUserPayPasswordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service("highUserPayPasswordService")
public class HighUserPayPasswordServiceImpl implements HighUserPayPasswordService {

    @Resource
    private HighUserPayPasswordMapper highUserPayPasswordMapper;

    @Override
    public void editUserPayPwd(HighUserPayPassword highUserPayPassword) {
        if (highUserPayPassword.getId() != null) {
            highUserPayPassword.setUpdateTime(new Date());
            highUserPayPasswordMapper.updateByPrimaryKey(highUserPayPassword);
        } else {
            highUserPayPassword.setCreateTime(new Date());
            highUserPayPassword.setUpdateTime(new Date());
            highUserPayPasswordMapper.insert(highUserPayPassword);
        }
    }

    @Override
    public HighUserPayPassword getDetailByUser(Long userId) {
        HighUserPayPasswordExample example = new HighUserPayPasswordExample();
        example.createCriteria().andUserIdEqualTo(userId);
        List<HighUserPayPassword> list = highUserPayPasswordMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public Boolean isSetPayPwd(Long userId) {
        HighUserPayPassword data = getDetailByUser(userId);
        if (data != null) {
            return true;
        }
        return false;
    }
}
