/**
 * @filename:SeparateAccountsServiceImpl 2024-10-23
 * @project KJT v1.1.0 Copyright(c) 2024 wanglang Co. Ltd. All right reserved.
 */
package com.trade.service.business.separateaccounts.service.impl;

import java.time.LocalDateTime;
import java.util.List;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.trade.service.business.separateaccounts.domain.SeparateAccounts;
import com.trade.service.business.separateaccounts.dto.SeparateAccountsSearchDto;
import com.trade.service.business.separateaccounts.mapper.SeparateAccountsMapper;
import com.trade.service.business.separateaccounts.service.SeparateAccountsService;
import com.trade.service.business.separateaccounts.vo.SeparateAccountsPageVo;
import org.slf4j.Logger;
import org.springframework.stereotype.Service;

import com.trade.common.utils.LoggerUtil;
import com.trade.common.utils.bean.BeanCopyUtils;
import com.trade.service.finance.constant.BillingConstant;
import com.trade.service.finance.paymentcollection.domain.BillingIncome;
import com.trade.service.finance.paymentcollection.domain.PaymentCollectionOperate;
import com.trade.service.finance.paymentcollection.service.PaymentCollectionOperateService;

/**
 * @Description:分账表服务实现
 * @version: v1.1.0
 * @author: wanglang
 */
@Service
public class SeparateAccountsServiceImpl extends ServiceImpl<SeparateAccountsMapper, SeparateAccounts> implements SeparateAccountsService {

    private static final Logger log = LoggerUtil.logger(LoggerUtil.LogFileNameEnum.SERVICES_LOG);
    @Resource
    private PaymentCollectionOperateService paymentCollectionOperateService;

    @Override
    public boolean saveSeparateAccounts(BillingIncome income, String operator) {
        SeparateAccounts separateAccounts = BeanCopyUtils.copy(income, SeparateAccounts.class);
        separateAccounts.setBillingIncomeId(income.getId());
        separateAccounts.setEntryDate(income.getActualEntryDate());
        separateAccounts.setStatus(BillingConstant.ENTRY_STATUS_UNCONFIRMED);
        separateAccounts.setId(null);
        this.save(separateAccounts);
        PaymentCollectionOperate paymentCollectionOperate = new PaymentCollectionOperate(separateAccounts.getId(), 3);
        paymentCollectionOperate.setApplicant(operator);
        paymentCollectionOperate.setApplyDate(LocalDateTime.now());
        paymentCollectionOperateService.save(paymentCollectionOperate);
        return true;
    }

    @Override
    public List<SeparateAccountsPageVo> selectByPage(SeparateAccountsSearchDto searchDto) {
        return this.baseMapper.selectByPage(searchDto);
    }
}
