import com.gic.haoban.manage.service.dao.mapper.content.TabHaobanPotentialCustomerMapper;
import com.gic.haoban.manage.service.entity.content.TabHaobanPotentialCustomer;
import com.gic.haoban.manage.service.pojo.bo.content.context.InteractRecordMessageContext;
import com.gic.haoban.manage.service.service.content.adaptor.InteractRecordMessageBuilder;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author MUSI
 * @Date 2023/4/23 11:48 PM
 * @Description
 * @Version
 **/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-conf.xml"})
public class BugFixTest {


    @Autowired
    TabHaobanPotentialCustomerMapper potentialCustomerMapper;

    @Autowired
    private InteractRecordMessageBuilder interactRecordMessageBuilder;

    @Test
    public void fixMemberInfo(){

        List<TabHaobanPotentialCustomer> tabHaobanPotentialCustomers = new ArrayList<>();
        if (CollectionUtils.isEmpty(tabHaobanPotentialCustomers)) {
            System.out.println("错误数据为空");
            return;
        }

        for (TabHaobanPotentialCustomer tabHaobanPotentialCustomer : tabHaobanPotentialCustomers) {
            if (StringUtils.isBlank(tabHaobanPotentialCustomer.getMemberId())) {
                System.out.println("会员ID为空 >>>>>>");
                continue;
            }
            InteractRecordMessageContext.MemberInfo memberInfo = interactRecordMessageBuilder.queryMemberInfo(tabHaobanPotentialCustomer.getMemberId());
            if (memberInfo == null) {
                continue;
            }
            if (StringUtils.isAllBlank(memberInfo.getMemberPhone(), memberInfo.getMemberNickName(), memberInfo.getMemberName(), memberInfo.getMemberImgUrl())) {
                System.out.println(tabHaobanPotentialCustomer.getMemberId() + "信息全是空");
                continue;
            }
            TabHaobanPotentialCustomer temp = new TabHaobanPotentialCustomer();
            temp.setId(tabHaobanPotentialCustomer.getId());
            temp.setMemberName(memberInfo.getMemberName());
            temp.setMemberNickName(memberInfo.getMemberNickName());
            temp.setMemberPhone(memberInfo.getMemberPhone());
            temp.setMemberImageUrl(memberInfo.getMemberImgUrl());
            int update = potentialCustomerMapper.update(temp);
            System.out.println("更新 memberId: " + tabHaobanPotentialCustomer.getMemberId() + " 结果: " + update);
        }
    }
}
