package com.jeeplus.test.reimbursementAccountant.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.sys.utils.StringUtils;
import com.jeeplus.test.reimbursementAccountant.domain.dto.AccountantReimbursementBusinessTwoDTO;
import com.jeeplus.test.reimbursementAccountant.domain.dto.AccountantReimbursementDTO;
import com.jeeplus.test.reimbursementAccountant.mapper.AccountantReimbursementBusinessTwoMapper;
import com.jeeplus.test.reimbursementAccountant.service.AccountantReimbursementBusinessService;
import com.jeeplus.test.reimbursementAccountant.service.AccountantReimbursementBusinessTwoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Service
@Transactional(readOnly = true)
public class AccountantReimbursementBusinessTwoServiceImpl implements AccountantReimbursementBusinessTwoService {

    @Autowired
    private AccountantReimbursementBusinessTwoMapper accountantReimbursementBusinessTwoMapper;
    @Autowired
    private AccountantReimbursementBusinessService reimbursementBusinessService;


    @Override
    public IPage<AccountantReimbursementBusinessTwoDTO> findListPage(Page<AccountantReimbursementBusinessTwoDTO> page, AccountantReimbursementBusinessTwoDTO accountantReimbursementBusiness) {
        return accountantReimbursementBusinessTwoMapper.findListPage(page,accountantReimbursementBusiness);
    }

    @Transactional(readOnly = false)
    @Override
    public void delPhysicsById(String id) {
        accountantReimbursementBusinessTwoMapper.delPhysicsById(id);
    }

    @Transactional(readOnly = false)
    @Override
    public void deleteByList(List <String> idList) {//删除发票信息
        if(idList.size()>0){
            accountantReimbursementBusinessTwoMapper.deleteByList(idList);
        }
    }

    @Transactional(readOnly = false)
    @Override
    public void addData(AccountantReimbursementBusinessTwoDTO accountantReimbursementBusinessTwoDTO) {
        accountantReimbursementBusinessTwoDTO.preInsert();
        accountantReimbursementBusinessTwoMapper.insertAccountantReimbursementBusiness(accountantReimbursementBusinessTwoDTO);
    }

    @Override
    public List<AccountantReimbursementDTO> findSelectList() {
        return accountantReimbursementBusinessTwoMapper.findSelectList();
    }

    @Transactional(readOnly = false)
    @Override
    public void modifyBindCode(String ids,String businessCode) {
        accountantReimbursementBusinessTwoMapper.modifyBindCode(ids,businessCode);
    }

    @Override
    public List<String> findSelectYearList() {
        return accountantReimbursementBusinessTwoMapper.findSelectYearList();
    }

    @Override
    public List<AccountantReimbursementDTO> findSelectCodeListByYear(String year) {
        List<AccountantReimbursementDTO> selectCodeListByYear = accountantReimbursementBusinessTwoMapper.findSelectCodeListByYear(year);
        selectCodeListByYear.forEach(s->{
            AccountantReimbursementDTO businessById = reimbursementBusinessService.getBusinessById(s.getId());
            if(null != businessById){
                s.setAllAlreadyReimbursementQuota(businessById.getAllAlreadyReimbursementQuota());
                s.setCanReimbursementAmount(businessById.getCanReimbursementAmount());
                s.setSurplusReimbursementAmount(businessById.getSurplusReimbursementAmount());
            }
        });
        return selectCodeListByYear;
    }

    @Override
    public AccountantReimbursementBusinessTwoDTO findDataById(String id) {
        return accountantReimbursementBusinessTwoMapper.findDataById(id);
    }
}
