package com.yonge.cooleshow.biz.dal.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yonge.cooleshow.biz.dal.entity.PaymentDivMember;
import com.yonge.cooleshow.biz.dal.mapper.PaymentDivMemberMapper;
import com.yonge.cooleshow.biz.dal.service.PaymentDivMemberService;
import com.yonge.cooleshow.biz.dal.wrapper.PaymentDivMemberWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 分账子账户配置
 * 2023-07-28 16:53:51
 */
@Slf4j
@Service
public class PaymentDivMemberServiceImpl extends ServiceImpl<PaymentDivMemberMapper, PaymentDivMember> implements PaymentDivMemberService {

	/**
     * 查询详情
     * @param id 详情ID
     * @return PaymentDivMember
     */
	@Override
    public PaymentDivMember detail(Long id) {
        
        return baseMapper.selectById(id);
    }
    
    /**
     * 分页查询
     * @param page IPage<PaymentDivMember>
     * @param query PaymentDivMemberWrapper.PaymentDivMemberQuery
     * @return IPage<PaymentDivMember>
     */
    @Override
    public IPage<PaymentDivMember> selectPage(IPage<PaymentDivMember> page, PaymentDivMemberWrapper.PaymentDivMemberQuery query) {
        
        return page.setRecords(baseMapper.selectPage(page, query));
    }
	
    /**
     * 添加
     * @param paymentDivMember PaymentDivMemberWrapper.PaymentDivMember
     * @return Boolean
     */
    @Override
    public Boolean add(PaymentDivMemberWrapper.PaymentDivMember paymentDivMember) {    	
        
        return this.save(JSON.parseObject(paymentDivMember.jsonString(), PaymentDivMember.class));
    }

    /**
     * 更新
     * @param paymentDivMember PaymentDivMemberWrapper.PaymentDivMember
     * @return Boolean
     */
    @Override
    public Boolean update(PaymentDivMemberWrapper.PaymentDivMember paymentDivMember){

        return this.updateById(JSON.parseObject(paymentDivMember.jsonString(), PaymentDivMember.class));       
    }

    /**
     * 子账户
     *
     * @param appId
     * @param tenantId
     * @return
     */
    @Override
    public PaymentDivMember getByAppIdAndTenantId(String appId, Long tenantId) {
        return this.lambdaQuery()
                .eq(PaymentDivMember::getAppId, appId)
                .eq(PaymentDivMember::getTenantId, tenantId)
                .last("limit 1")
                .one();

    }
}