package com.huiju.estateagents.sample.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huiju.estateagents.base.ResponseBean;
import com.huiju.estateagents.common.CommConstant;
import com.huiju.estateagents.sample.entity.TaContact;
import com.huiju.estateagents.sample.mapper.TaContactMapper;
import com.huiju.estateagents.sample.mapper.TaH5SampleMapper;
import com.huiju.estateagents.sample.service.ITaContactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * 联系人表  服务实现类
 * </p>
 *
 * @author fxf
 * @since 2020-03-18
 */
@Service
public class TaContactServiceImpl extends ServiceImpl<TaContactMapper, TaContact> implements ITaContactService {

    @Autowired
    private TaContactMapper taContactMapper;

    @Autowired
    private TaH5SampleMapper taH5SampleMapper;

    @Override
    public IPage<TaContact> taContactInfoBySampleId(String id, Integer pageNum, Integer pageSize) {
        IPage<TaContact> pg = new Page<>(pageNum, pageSize);
        return taContactMapper.taContactInfoBySampleId(pg, id);
    }

    @Override
    public ResponseBean batchDelete(List<TaContact> taContactList, Integer userId) {
        ResponseBean responseBean = new ResponseBean();

        List<TaContact> updateList = new ArrayList<>();
        TaContact newContact;
        for (TaContact taContact : taContactList) {
            newContact = new TaContact();
            newContact.setContactId(taContact.getContactId());
            newContact.setStatus(CommConstant.STATUS_DELETE);
            updateList.add(newContact);
        }

        // 更新样例表状态
//        taH5SampleMapper.batchUpdateStatus(updateList, userId);

        responseBean.addSuccess(updateBatchById(updateList));
        return responseBean;
    }
}
