package com.fs.qw.service.impl;

import com.alibaba.fastjson.JSON;
import com.fs.common.utils.DateUtils;
import com.fs.company.mapper.CompanyUserMapper;
import com.fs.his.vo.OptionsVO;
import com.fs.qw.domain.QwContactWay;
import com.fs.qw.domain.QwContactWayLogs;
import com.fs.qw.domain.QwUser;
import com.fs.qw.mapper.QwContactWayLogsMapper;
import com.fs.qw.mapper.QwContactWayMapper;
import com.fs.qw.mapper.QwUserMapper;
import com.fs.qw.service.IQwContactWayLogsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * 联系我日志Service业务层处理
 * 
 * @author fs
 * @date 2024-07-23
 */
@Service
public class QwContactWayLogsServiceImpl implements IQwContactWayLogsService 
{
    @Autowired
    private QwContactWayLogsMapper qwContactWayLogsMapper;
    @Autowired
    private QwContactWayMapper qwContactWayMapper;
    @Autowired
    private QwUserMapper qwUserMapper;

    /**
     * 查询联系我日志
     * 
     * @param id 联系我日志主键
     * @return 联系我日志
     */
    @Override
    public QwContactWayLogs selectQwContactWayLogsById(Long id)
    {
        return qwContactWayLogsMapper.selectQwContactWayLogsById(id);
    }

    /**
     * 查询联系我日志列表
     * 
     * @param qwContactWayLogs 联系我日志
     * @return 联系我日志
     */
    @Override
    public List<QwContactWayLogs> selectQwContactWayLogsList(QwContactWayLogs qwContactWayLogs)
    {
        return qwContactWayLogsMapper.selectQwContactWayLogsList(qwContactWayLogs);
    }

    /**
     * 新增联系我日志
     * 
     * @param qwContactWayLogs 联系我日志
     * @return 结果
     */
    @Override
    public int insertQwContactWayLogs(QwContactWayLogs qwContactWayLogs)
    {
        qwContactWayLogs.setCreateTime(DateUtils.getNowDate());
        return qwContactWayLogsMapper.insertQwContactWayLogs(qwContactWayLogs);
    }

    /**
     * 修改联系我日志
     * 
     * @param qwContactWayLogs 联系我日志
     * @return 结果
     */
    @Override
    public int updateQwContactWayLogs(QwContactWayLogs qwContactWayLogs)
    {
        return qwContactWayLogsMapper.updateQwContactWayLogs(qwContactWayLogs);
    }

    /**
     * 批量删除联系我日志
     * 
     * @param ids 需要删除的联系我日志主键
     * @return 结果
     */
    @Override
    public int deleteQwContactWayLogsByIds(Long[] ids)
    {
        return qwContactWayLogsMapper.deleteQwContactWayLogsByIds(ids);
    }

    /**
     * 删除联系我日志信息
     * 
     * @param id 联系我日志主键
     * @return 结果
     */
    @Override
    public int deleteQwContactWayLogsById(Long id)
    {
        return qwContactWayLogsMapper.deleteQwContactWayLogsById(id);
    }

    @Override
    public List<QwUser> getCompanyUserList(Long id) {
        QwContactWay qwContactWay = qwContactWayMapper.selectQwContactWayById(id);
        List<String> ids = JSON.parseArray(qwContactWay.getUserIds(), String.class);
        return qwUserMapper.getCompanyUserListByWxIdAndCorpId(ids, qwContactWay.getCorpId());
    }
}
