package com.gic.haoban.manage.service.service.fee.impl;

import com.gic.commons.util.UniqueIdUtils;
import com.gic.haoban.manage.service.dao.mapper.fee.TabHaobanQywxFeeOrderAccountMapper;
import com.gic.haoban.manage.service.entity.fee.TabHaobanQywxFeeOrderAccount;
import com.gic.haoban.manage.service.service.fee.HaobanQywxFeeOrderAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 企业微信收费订单账号(激活码)(TabHaobanQywxFeeOrderAccount)表服务实现类
 *
 * @author mozhu
 * @since 2022-08-03 16:12:34
 */
@Service
public class HaobanQywxFeeOrderAccountServiceImpl implements HaobanQywxFeeOrderAccountService {
    @Autowired
    private TabHaobanQywxFeeOrderAccountMapper tabHaobanQywxFeeOrderAccountMapper;

    /**
     * 新增数据
     *
     * @param tabHaobanQywxFeeOrderAccount 实例对象
     * @return 实例对象
     */
    @Override
    public TabHaobanQywxFeeOrderAccount save(TabHaobanQywxFeeOrderAccount activeAccount) {
        String wxEnterpriseId = activeAccount.getWxEnterpriseId() ; 
        String orderId = activeAccount.getOrderId() ;
        String activeCode = activeAccount.getActiveCode() ;
        TabHaobanQywxFeeOrderAccount tab = this.tabHaobanQywxFeeOrderAccountMapper.selectByOrderIdAndCode(wxEnterpriseId, orderId, activeCode) ;
        if(tab==null) {
            activeAccount.setFeeAccountId(UniqueIdUtils.uniqueLong());
            this.tabHaobanQywxFeeOrderAccountMapper.insert(activeAccount);
        }else {
            activeAccount.setFeeAccountId(tab.getFeeAccountId());
            this.tabHaobanQywxFeeOrderAccountMapper.update(activeAccount);
        }
        return activeAccount;
    }

    @Override
    public int countOrderAccountStatus(Integer status, String wxEnterpriseId) {
        return tabHaobanQywxFeeOrderAccountMapper.countOrderAccountStatus(status,wxEnterpriseId);
    }

    @Override
    public List<TabHaobanQywxFeeOrderAccount> selectByWxEnterpriseId(String wxEnterpriseId) {
        return tabHaobanQywxFeeOrderAccountMapper.selectByWxEnterpriseId(wxEnterpriseId);
    }

    @Override
    public void updateByActiveCode(String wxEnterpriseId, String activeCode) {
        tabHaobanQywxFeeOrderAccountMapper.updateByActiveCode(wxEnterpriseId,activeCode);
    }

}
