package com.cool.store.dao;

import com.cool.store.entity.PartnerUserWechatBindDO;
import com.cool.store.mapper.PartnerUserWechatBindMapper;
import com.cool.store.utils.StringUtil;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @Author suzhuhong
 * @Date 2025/2/19 15:09
 * @Version 1.0
 */
@Repository
public class PartnerUserWechatBindDAO {
    
    @Resource
    PartnerUserWechatBindMapper partnerUserWechatBindMapper;


    /**
     * 新增
     * @param partnerUserWechatBindDO
     * @return
     */
    public Integer insertSelective(PartnerUserWechatBindDO partnerUserWechatBindDO) {
        if (partnerUserWechatBindDO == null) {
            return 0;
        }
        return partnerUserWechatBindMapper.insert(partnerUserWechatBindDO);
    }

    /**
     * 更新
     * @param partnerUserWechatBindDO
     * @return
     */
    public Integer update(PartnerUserWechatBindDO partnerUserWechatBindDO) {
        if (partnerUserWechatBindDO == null) {
            return 0;
        }
        return partnerUserWechatBindMapper.update(partnerUserWechatBindDO);
    }

    /**
     * 更新所有的unionId对应的服务号ID
     * @param unionId 开发平台的用户ID
     * @param serviceAccountOpenId 服务号ID
     * @return
     */
    public Integer updateByUnionId(String unionId,String serviceAccountOpenId) {
        return partnerUserWechatBindMapper.updateByUnionId(unionId,serviceAccountOpenId);
    }

    public PartnerUserWechatBindDO getByOpenIdAndPartnerId(String partnerId, String openId) {
        if (StringUtil.isEmpty(partnerId)|| StringUtil.isEmpty(openId)){
            return null;
        }
        return partnerUserWechatBindMapper.selectByPartnerAndOpenId(partnerId,openId);
    }


    
    
}
