package com.ruoyi.project.business.service.impl;

import java.util.List;
import java.util.Objects;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.business.domain.TcLead;
import com.ruoyi.project.business.mapper.TcAccountContactHistoryMapper;
import com.ruoyi.project.business.mapper.TcLeadMapper;
import org.springframework.stereotype.Service;
import com.ruoyi.project.business.mapper.TcAccountContactMapper;
import com.ruoyi.project.business.domain.TcAccountContact;
import com.ruoyi.project.business.service.ITcAccountContactService;

import javax.annotation.Resource;

/**
 * 联系人Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-04-12
 */
@Service
public class TcAccountContactServiceImpl extends ServiceImpl<TcAccountContactMapper, TcAccountContact> implements ITcAccountContactService 
{
    @Resource
    private TcAccountContactMapper tcAccountContactMapper;

    @Resource
    private TcAccountContactHistoryMapper tcAccountContactHistoryMapper;

    /**
     * 查询联系人
     * 
     * @param contactId 联系人主键
     * @return 联系人
     */
    @Override
    public TcAccountContact selectTcAccountContactByContactId(Long contactId)
    {
        return tcAccountContactMapper.selectTcAccountContactByContactId(contactId);
    }

    /**
     * 查询相关联系人
     * 
     * @param accountId 客户Id
     * @return 联系人
     */
    @Override
    public List<TcAccountContact> selectContactlistByAccountId(Long accountId)
    {
        return tcAccountContactMapper.selectContactlistByAccountId(accountId);
    }

    /**
     * 查询联系人列表
     *
     * @param tcAccountContact 联系人
     * @return 联系人
     */
    @Override
    public List<TcAccountContact> selectTcAccountContactList(TcAccountContact tcAccountContact)
    {
        return tcAccountContactMapper.selectTcAccountContactList(tcAccountContact);
    }

    /**
     * 新增联系人
     * 
     * @param tcAccountContact 联系人
     * @return 结果
     */
    @Override
    public int insertTcAccountContact(TcAccountContact tcAccountContact)
    {
        tcAccountContact.setCreateTime(DateUtils.getNowDate());
        return tcAccountContactMapper.insertTcAccountContact(tcAccountContact);
    }

    /**
     * 修改联系人
     * 
     * @param tcAccountContact 联系人
     * @return 结果
     */
    @Override
    public int updateTcAccountContact(TcAccountContact tcAccountContact)
    {
        tcAccountContact.setUpdateTime(DateUtils.getNowDate());
        return tcAccountContactMapper.updateTcAccountContact(tcAccountContact);
    }

    /**
     * 批量删除联系人
     * 
     * @param contactIds 需要删除的联系人主键
     * @return 结果
     */
    @Override
    public int deleteTcAccountContactByContactIds(Long[] contactIds)
    {
        return tcAccountContactMapper.deleteTcAccountContactByContactIds(contactIds);
    }

    /**
     * 删除联系人信息
     * 
     * @param contactId 联系人主键
     * @return 结果
     */
    @Override
    public int deleteTcAccountContactByContactId(Long contactId)
    {
        return tcAccountContactMapper.deleteTcAccountContactByContactId(contactId);
    }

    /**
     * 查询未关联客户联系人
     *
     * @param tcAccountContact 联系人
     * @return 结果
     */
    @Override
    public List<TcAccountContact> getUnRelatedContact(TcAccountContact tcAccountContact) {
        return tcAccountContactMapper.getUnRelatedContact(tcAccountContact);
    }

    private boolean isContactNotEqual(TcAccountContact oldContact, TcAccountContact contact) {
        if (!Objects.equals(oldContact.getContactName(), contact.getContactName())) {
            return true;
        }
        if (!Objects.equals(oldContact.getPhone(), contact.getPhone())) {
            return true;
        }
        if (!Objects.equals(oldContact.getEmail(), contact.getEmail())) {
            return true;
        }
        if (!Objects.equals(oldContact.getAddress(), contact.getAddress())) {
            return true;
        }
        if (!Objects.equals(oldContact.getJobTitle(), contact.getJobTitle())) {
            return true;
        }
        if (!Objects.equals(oldContact.getBirthday(), contact.getBirthday())) {
            return true;
        }
        if (!Objects.equals(oldContact.getHoroscope(), contact.getHoroscope())) {
            return true;
        }
        if (!Objects.equals(oldContact.getMaritalStatus(), contact.getMaritalStatus())) {
            return true;
        }
        if (!Objects.equals(oldContact.getHobbies(), contact.getHobbies())) {
            return true;
        }
        return false;
    }

}
