package com.flossom.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.flossom.common.core.domain.entity.WxUserRemark;
import com.flossom.common.core.domain.req.WxUserRemarkReq;
import com.flossom.common.core.enums.Status;
import com.flossom.common.core.mapper.WxUserMemberMapper;
import com.flossom.common.core.mapper.WxUserRemarkMapper;
import com.flossom.common.core.utils.DateUtils;
import com.flossom.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.flossom.system.service.IWxUserRemarkService;

/**
 * 微信用户备注列Service业务层处理
 *
 * @author flossom
 * @date 2023-12-21
 */
@Service
public class WxUserRemarkServiceImpl implements IWxUserRemarkService {

    @Autowired
    private WxUserRemarkMapper wxUserRemarkMapper;

    @Autowired
    private WxUserMemberMapper wxUserMemberMapper;

    /**
     * 查询微信用户备注列
     *
     * @param id 微信用户备注列主键
     * @return 微信用户备注列
     */
    @Override
    public WxUserRemark selectWxUserRemarkById(Long id) {
        return wxUserRemarkMapper.selectWxUserRemarkById(id);
    }

    /**
     * 查询微信用户备注列列表
     *
     * @param wxUserRemark 微信用户备注列
     * @return 微信用户备注列
     */
    @Override
    public List<WxUserRemark> selectWxUserRemarkList(WxUserRemark wxUserRemark) {
        return wxUserRemarkMapper.selectWxUserRemarkList(wxUserRemark);
    }

    /**
     * 新增微信用户备注列
     *
     * @param wxUserRemark 微信用户备注列
     * @return 结果
     */
    @Override
    public int insertWxUserRemark(WxUserRemark wxUserRemark) {
        wxUserRemark.setCreateTime(DateUtils.getNowDate());
        return wxUserRemarkMapper.insertWxUserRemark(wxUserRemark);
    }

    /**
     * 修改微信用户备注列
     *
     * @param wxUserRemark 微信用户备注列
     * @return 结果
     */
    @Override
    public int updateWxUserRemark(WxUserRemark wxUserRemark) {
        wxUserRemark.setUpdateTime(DateUtils.getNowDate());
        return wxUserRemarkMapper.updateWxUserRemark(wxUserRemark);
    }

    /**
     * 批量删除微信用户备注列
     *
     * @param ids 需要删除的微信用户备注列主键
     * @return 结果
     */
    @Override
    public int deleteWxUserRemarkByIds(Long[] ids) {
        return wxUserRemarkMapper.deleteWxUserRemarkByIds(ids);
    }

    /**
     * 删除微信用户备注列信息
     *
     * @param id 微信用户备注列主键
     * @return 结果
     */
    @Override
    public int deleteWxUserRemarkById(Long id) {
        return wxUserRemarkMapper.deleteWxUserRemarkById(id);
    }

    @Override
    public void batchAddRemark(WxUserRemarkReq wxUserRemarkReq) {
        if (wxUserRemarkReq.getUserIdList() != null && wxUserRemarkReq.getUserIdList().size() > 0) {
            WxUserRemark wxUserRemark = new WxUserRemark();
            for (Long userId : wxUserRemarkReq.getUserIdList()) {
                wxUserRemark.setUserId(userId);
                wxUserRemark.setContent(wxUserRemarkReq.getContent());
                wxUserRemark.setStatus(Status.OK.getCode());
                wxUserRemark.setCreateTime(DateUtils.getNowDate());
//                wxUserRemark.setCreateBy(SecurityUtils.getUsername());
                wxUserRemarkMapper.insertWxUserRemark(wxUserRemark);
            }
        }
    }
}
