package cn.ezhizao.project.business.financialBase.controller;

import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.project.business.company.domain.BizCompany;
import cn.ezhizao.project.business.company.service.IBizCompanyService;
import cn.ezhizao.project.business.finance.IndividualIncomeTaxIsZero.domain.BizFinancialIndividualIncomeTaxDetailIsZero;
import cn.ezhizao.project.business.finance.IndividualIncomeTaxIsZero.service.IBizFinancialIndividualIncomeTaxDetailIsZeroService;
import cn.ezhizao.project.business.financialBase.domain.BizFinancialMerge;
import cn.ezhizao.project.business.financialBase.service.IBizFinancialMergeService;
import cn.ezhizao.project.business.reportTaxIsZero.domain.BizFinancialReportTaxDetail;
import cn.ezhizao.project.business.reportTaxIsZero.service.IBizFinancialReportTaxDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@Api(tags = "FinancialAccountAdjustment数据接口")
@RequestMapping(value = "/business/financialManager/base")
public class FinancialBaseController extends BaseController {

    @Resource
    IBizFinancialMergeService financialMergeService;
    @Resource
    IBizFinancialIndividualIncomeTaxDetailIsZeroService financialIndividualIncomeTaxDetailService;
    @Resource
    IBizFinancialReportTaxDetailService financialReportTaxDetailService;
    @Resource
    IBizCompanyService companyService;

    @ApiOperation("获取合并的税款信息")
    @GetMapping("/getMergeById/{id}")
    @ResponseBody
    public AjaxResult getMergeById(@PathVariable Long id) {
        BizFinancialMerge merge = financialMergeService.getById(id);
        if (merge != null) {
//            Map<String, Object> condition = new HashMap<>(1);
//            condition.put("id", merge.getFinancialReportTaxDetailId());
//            BizFinancialReportTaxDetail condition = new BizFinancialReportTaxDetail();
//            List<BizFinancialReportTaxDetail> reportTaxs = financialReportTaxDetailService.getList(condition);
            BizFinancialReportTaxDetail reportTax = financialReportTaxDetailService.getById(merge.getFinancialReportTaxDetailId());
            BizFinancialIndividualIncomeTaxDetailIsZero personTax = financialIndividualIncomeTaxDetailService.getById(merge.getFinancialIndividualIncomeTaxDetailId());
            Map<String, Object> map = new HashMap<>(5);
            merge.setPersonTax(personTax != null ? personTax : new BizFinancialIndividualIncomeTaxDetailIsZero());
            merge.setReportTax(reportTax != null ? reportTax : new BizFinancialReportTaxDetail());
            if (reportTax != null || personTax != null) {
                BizCompany company = companyService.getById(reportTax == null ? personTax.getCompanyId() : reportTax.getCompanyId());
                map.put("companyName", company.getName());
                map.put("year", reportTax != null ? reportTax.getYear() : personTax.getYear());
                map.put("month", reportTax != null ? reportTax.getMonth() : personTax.getMonth());
            }
            return success(map);
        }
        return error("该划款数据不存在");
    }
}
