package com.jeeplus.test.reimbursementAssess.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.reimbursementAssess.domain.dto.AssessReimbursementBusinessTwoDTO;
import com.jeeplus.test.reimbursementAssess.domain.dto.AssessReimbursementDTO;
import com.jeeplus.test.reimbursementAssess.mapper.AssessReimbursementBusinessTwoMapper;
import com.jeeplus.test.reimbursementAssess.service.AssessReimbursementBusinessService;
import com.jeeplus.test.reimbursementAssess.service.AssessReimbursementBusinessTwoService;
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 AssessReimbursementBusinessTwoServiceImpl implements AssessReimbursementBusinessTwoService {

    @Autowired
    private AssessReimbursementBusinessTwoMapper assessReimbursementBusinessTwoMapper;
    @Autowired
    private AssessReimbursementBusinessService reimbursementBusinessService;


    @Override
    public IPage<AssessReimbursementBusinessTwoDTO> findListPage(Page<AssessReimbursementBusinessTwoDTO> page, AssessReimbursementBusinessTwoDTO AssessReimbursementBusiness) {
        return assessReimbursementBusinessTwoMapper.findListPage(page,AssessReimbursementBusiness);
    }

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

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

    @Transactional(readOnly = false)
    @Override
    public void addData(AssessReimbursementBusinessTwoDTO AssessReimbursementBusinessTwoDTO) {
        AssessReimbursementBusinessTwoDTO.preInsert();
        assessReimbursementBusinessTwoMapper.insertAssessReimbursementBusiness(AssessReimbursementBusinessTwoDTO);
    }

    @Override
    public List<AssessReimbursementDTO> findSelectList() {
        return assessReimbursementBusinessTwoMapper.findSelectList();
    }

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

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

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

    @Override
    public AssessReimbursementBusinessTwoDTO findDataById(String id) {
        return assessReimbursementBusinessTwoMapper.findDataById(id);
    }
}
