package com.hai.service.impl;

import com.hai.dao.HighCompanyTwoPwdMapper;
import com.hai.entity.HighCompanyTwoPwd;
import com.hai.entity.HighCompanyTwoPwdExample;
import com.hai.service.HighCompanyTwoPwdService;
import org.springframework.stereotype.Service;

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

@Service("companyTwoPwdService")
public class HighCompanyTwoPwdServiceImpl implements HighCompanyTwoPwdService {

    @Resource
    private HighCompanyTwoPwdMapper companyTwoPwdMapper;

    @Override
    public void editData(HighCompanyTwoPwd companyTwoPwd) {
        if (companyTwoPwd.getId() == null) {
            companyTwoPwd.setCreateTime(new Date());
            companyTwoPwd.setUpdateTime(new Date());
            companyTwoPwd.setStatus(1);
            companyTwoPwdMapper.insert(companyTwoPwd);
        } else {
            companyTwoPwd.setUpdateTime(new Date());
            companyTwoPwdMapper.updateByPrimaryKey(companyTwoPwd);
        }
    }

    @Override
    public HighCompanyTwoPwd getTwoPwdByOrg(Long orgId) {
        HighCompanyTwoPwdExample example = new HighCompanyTwoPwdExample();
        example.createCriteria().andStatusEqualTo(1).andOrgIdEqualTo(orgId);
        List<HighCompanyTwoPwd> list = companyTwoPwdMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
