package com.cool.store.dao;

import com.cool.store.entity.HyPartnerClerkDO;
import com.cool.store.mapper.HyPartnerClerkMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @Author suzhuhong
 * @Date 2023/6/15 10:09
 * @Version 1.0
 */
@Repository
public class HyPartnerClerkDAO {

    @Resource
    HyPartnerClerkMapper hyPartnerClerkMapper;

   public int insertSelective( HyPartnerClerkDO record){
        return hyPartnerClerkMapper.insertSelective(record);
    }

    public int updateByPrimaryKeySelective(HyPartnerClerkDO record){
        return hyPartnerClerkMapper.updateByPrimaryKeySelective(record);
    }

    public List<HyPartnerClerkDO> getHyPartnerClerkList(Long lineId){
        return hyPartnerClerkMapper.getHyPartnerClerkList(lineId);
    }

    public int batchInsert(List<HyPartnerClerkDO> hyPartnerClerkDOList){
        if (CollectionUtils.isEmpty(hyPartnerClerkDOList)){
            return -1;
        }
        return hyPartnerClerkMapper.batchInsert(hyPartnerClerkDOList);
    }

    public void deleteByPartnerIdAndLineId(String partnerId, Long partnerLineId){
        if (StringUtils.isEmpty(partnerId) || Objects.isNull(partnerLineId)){
            return;
        }
        hyPartnerClerkMapper.deleteByPartnerIdAndLineId(partnerId, partnerLineId);
    }

    public List<HyPartnerClerkDO> listByPartnerIdAndLineId(String partnerId, Long partnerLineId){
        if (StringUtils.isEmpty(partnerId) || Objects.isNull(partnerLineId)){
            return Collections.emptyList();
        }
        return hyPartnerClerkMapper.listByPartnerIdAndLineId(partnerId, partnerLineId);
    }

    public  int updateLineId(String newPartnerId,Long newLineId,Long oldLineId){
        if (newLineId==null || Objects.isNull(oldLineId)){
            return 0;
        }
        return hyPartnerClerkMapper.updateLineId(newPartnerId,newLineId, oldLineId);
    }

}
