package com.fs.wxcid.service.impl;

import java.util.List;
import com.fs.common.utils.DateUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fs.company.domain.CompanyWxAccount;
import com.fs.wxcid.dto.callback.WxCallbackVo;
import org.springframework.stereotype.Service;
import com.fs.wxcid.mapper.WxMsgLogMapper;
import com.fs.wxcid.domain.WxMsgLog;
import com.fs.wxcid.service.IWxMsgLogService;

/**
 * 个微消息记录Service业务层处理
 * 
 * @author fs
 * @date 2025-12-16
 */
@Service
public class WxMsgLogServiceImpl extends ServiceImpl<WxMsgLogMapper, WxMsgLog> implements IWxMsgLogService {

    /**
     * 查询个微消息记录
     * 
     * @param id 个微消息记录主键
     * @return 个微消息记录
     */
    @Override
    public WxMsgLog selectWxMsgLogById(Long id)
    {
        return baseMapper.selectWxMsgLogById(id);
    }

    /**
     * 查询个微消息记录列表
     * 
     * @param wxMsgLog 个微消息记录
     * @return 个微消息记录
     */
    @Override
    public List<WxMsgLog> selectWxMsgLogList(WxMsgLog wxMsgLog)
    {
        return baseMapper.selectWxMsgLogList(wxMsgLog);
    }

    /**
     * 新增个微消息记录
     * 
     * @param wxMsgLog 个微消息记录
     * @return 结果
     */
    @Override
    public int insertWxMsgLog(WxMsgLog wxMsgLog)
    {
        wxMsgLog.setCreateTime(DateUtils.getNowDate());
        return baseMapper.insertWxMsgLog(wxMsgLog);
    }

    /**
     * 修改个微消息记录
     * 
     * @param wxMsgLog 个微消息记录
     * @return 结果
     */
    @Override
    public int updateWxMsgLog(WxMsgLog wxMsgLog)
    {
        wxMsgLog.setUpdateTime(DateUtils.getNowDate());
        return baseMapper.updateWxMsgLog(wxMsgLog);
    }

    /**
     * 批量删除个微消息记录
     * 
     * @param ids 需要删除的个微消息记录主键
     * @return 结果
     */
    @Override
    public int deleteWxMsgLogByIds(Long[] ids)
    {
        return baseMapper.deleteWxMsgLogByIds(ids);
    }

    /**
     * 删除个微消息记录信息
     * 
     * @param id 个微消息记录主键
     * @return 结果
     */
    @Override
    public int deleteWxMsgLogById(Long id)
    {
        return baseMapper.deleteWxMsgLogById(id);
    }

    @Override
    public void insertLog(WxCallbackVo callbackVo, CompanyWxAccount account, int type) {
        String formUser = callbackVo.getMessage().getFromUserName().getStr();
        WxMsgLog logs = new WxMsgLog();
        logs.setAccountId(account.getId());
        logs.setAuthKey(account.getAuthKey());
        logs.setType(callbackVo.getType());
        logs.setMsgId(callbackVo.getMessage().getMsgId());
        logs.setFromUserName(formUser);
        logs.setToUserName(callbackVo.getMessage().getToUserName().getStr());
        logs.setMsgType(callbackVo.getMessage().getMsgType());
        logs.setContent(callbackVo.getMessage().getContent().getStr());
        logs.setImgStatus(callbackVo.getMessage().getImgStatus());
        logs.setImgBuf(callbackVo.getMessage().getImgBuf().getLen());
        logs.setPushContent(callbackVo.getMessage().getPushContent());
        logs.setNewMsgId(callbackVo.getMessage().getNewMsgId());
        logs.setReceiveType(type);
        save(logs);
    }
}
