import com.gic.haoban.manage.api.dto.qdto.hm.WxUserAddLogQDTO;
import com.gic.haoban.manage.service.dao.mapper.TabHaobanExternalClerkRelatedMapper;
import com.gic.haoban.manage.service.dao.mapper.hm.WxUserAddLogMapper;
import com.gic.haoban.manage.service.entity.TabHaobanExternalClerkRelated;
import com.gic.haoban.manage.service.entity.hm.TabWxUserAddLog;
import com.gic.haoban.manage.service.service.hm.WxUserAddLogService;
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.Arrays;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-conf.xml"})
public class HalfFriendTest {
    
    @Autowired
    private TabHaobanExternalClerkRelatedMapper haobanExternalClerkRelatedMapper ;
    @Autowired
    private WxUserAddLogMapper wxUserAddLogMapper ;
    @Autowired
    private WxUserAddLogService wxUserAddLogService ;
    @Test
    public void tt()  {

        String wxEnterpriseId = "b8f2f238e73844219d8c1ac563cec0db" ;

        String staffId = "c153778c9ec24c189ac31e67748677e3";

        List<TabHaobanExternalClerkRelated> list = this.haobanExternalClerkRelatedMapper.listByWxEnterpriseIdAndWxUserIdAndStatus(wxEnterpriseId, staffId, Arrays.asList(2)) ;
        int count = 0 ;
        for(TabHaobanExternalClerkRelated item : list) {
            String externalUserId = item.getExternalUserId() ;
            // a2d6b466a4fc436099a949db3756f6c1
            // 8be4cae54aec4dbe90079d824f3c1490
            String clerkId =  "8be4cae54aec4dbe90079d824f3c1490" ;
            TabWxUserAddLog log =  this.wxUserAddLogMapper.listNewLog(externalUserId,staffId,clerkId) ;
            if(null == log || log.getStatusFlag()!=3) {
                continue;
            }
            count++ ;
            System.err.println("insert"+externalUserId + " " + count);
            //添加日志
            WxUserAddLogQDTO wxUserAddLogQDTO = new WxUserAddLogQDTO();
            wxUserAddLogQDTO.setWxEnterpriseId(wxEnterpriseId);
            wxUserAddLogQDTO.setEnterpriseId(item.getEnterpriseId());
            wxUserAddLogQDTO.setMemberId(item.getMemberId());
            wxUserAddLogQDTO.setUnionid(item.getUnionid());
            wxUserAddLogQDTO.setDelFlag(true);
            wxUserAddLogQDTO.setExternalUserid(item.getExternalUserId());
            wxUserAddLogQDTO.setStaffId(item.getStaffId());
            wxUserAddLogQDTO.setClerkId(log.getFriendClerkId());
            if(null != item.getAddTime()) {
                wxUserAddLogQDTO.setQwAddTime(item.getAddTime());
            }
            wxUserAddLogQDTO.setFriendClerkId(log.getFriendClerkId());
            wxUserAddLogQDTO.setFriendStoreId(log.getFriendStoreId());
            this.wxUserAddLogService.save(wxUserAddLogQDTO);
        }
    }
}
