package com.iformall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iformall.common.IdWorker;
import com.iformall.domain.po.base.TenantEntity;
import com.iformall.domain.po.WxPayAccountBill;
import com.iformall.mapper.WxBillPropertyMapper;
import com.iformall.mapper.WxBillRentMapper;
import com.iformall.mapper.WxPayAccountBillMapper;
import com.iformall.service.WxPayAccountBillService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WxPayAccountBillServiceImpl implements WxPayAccountBillService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
    WxPayAccountBillMapper wxPayAccountBillMapper;

    @Autowired
    WxBillRentMapper wxBillRentMapper;

    @Autowired
    WxBillPropertyMapper wxBillPropertyMapper;

    @Override
    public PageInfo<WxPayAccountBill> listAsPage(WxPayAccountBill record, Integer pageIndex, Integer pageSize) {
        return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxPayAccountBillMapper.findList(record));
    }

    @Override
    public WxPayAccountBill getById(Long id) {
        return wxPayAccountBillMapper.selectById(id);
    }

    @Override
    public WxPayAccountBill getByTenantInfo(TenantEntity tenantEntity) {
        WxPayAccountBill payAccountBillQ = new WxPayAccountBill();
        payAccountBillQ.updateTenantInfo(tenantEntity);
        return wxPayAccountBillMapper.selectOne(new QueryWrapper(payAccountBillQ));
    }

    @Override
    public void saveOrUpdate(WxPayAccountBill record) {
        if (record.getId() == null) {
            final IdWorker idWorker = IdWorker.get();
        	record.setId(idWorker.nextId());
            wxPayAccountBillMapper.insert(record);
        } else {
            wxPayAccountBillMapper.updateById(record);
        }

        //更新手续费
        wxBillRentMapper.updateServiceCharge(record);
        wxBillPropertyMapper.updateServiceCharge(record);

    }

    @Override
    public void deleteById(Long id) {
        wxPayAccountBillMapper.deleteById(id);
    }
    
    
    
    
    
    
    
    
}
