package com.fs.repeat.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fs.common.utils.uuid.IdUtils;
import com.fs.qw.domain.QwExternalContact;
import com.fs.qw.service.IQwExternalContactService;
import com.fs.repeat.vo.RepeatUploadVo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@AllArgsConstructor
public class RepeatService {
    private final IQwExternalContactService qwExternalContactService;

    public void repeatQw(RepeatUploadVo vo) {
        List<QwExternalContact> externalContactList = qwExternalContactService.list(new QueryWrapper<QwExternalContact>().eq("external_user_id", vo.getExternalUserId()));
        if(!externalContactList.isEmpty()){
            String no = IdUtils.simpleUUID();
            log.info("外部联系人：{}重粉,外部联系人识别编号：{}", vo.getExternalUserId(), no);
            externalContactList.forEach(e -> {
                e.setRepeatNo(no);
                e.setIsRepeat(1);
            });
            qwExternalContactService.updateBatchById(externalContactList);
        }else{
            log.info("外部联系人：{}并非重粉", vo.getExternalUserId());
        }
    }

    public void repeatFsUser(RepeatUploadVo vo) {
        List<QwExternalContact> qwExternalContacts = qwExternalContactService.list(new QueryWrapper<QwExternalContact>().eq("fs_user_id", vo.getFsUserId()));
        if(qwExternalContacts.size() > 1){
            String no = IdUtils.simpleUUID();
            qwExternalContacts.forEach(e -> {
                e.setRepeatNo(no);
                e.setIsRepeat(1);
                e.setUserRepeat(1);
            });
            log.info("fs_user：{}重粉,外部联系人识别编号：{}", vo.getFsUserId(), no);
            qwExternalContactService.updateBatchById(qwExternalContacts);
        }else{
            log.info("fs_user：{}并非重粉", vo.getFsUserId());
        }
    }

    public void userAddOrder(RepeatUploadVo vo) {
        List<QwExternalContact> qwExternalContacts = qwExternalContactService.list(new QueryWrapper<QwExternalContact>().eq("fs_user_id", vo.getFsUserId()));
        qwExternalContacts.forEach(e -> e.setPayOrder(1));
        qwExternalContactService.updateBatchById(qwExternalContacts);
    }
}
