package com.kcim.web;

import com.kcim.common.constants.NumberConstant;
import com.kcim.common.util.Result;
import com.kcim.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @program: CostAccount
 * @description: 月度数据采集合并接口
 * @author: Wang.YS
 * @create: 2024-03-21 14:57
 **/
@RestController
@Slf4j
@Api(tags = "月度数据采集合并接口")
@RequestMapping("costData")
@AllArgsConstructor
public class CostDataController {
    CostDataService costDataService;

    @ApiOperation("月度数据采集-获取检查列表")
    @GetMapping("getCheckList")
    public Result getCheckList(
            @RequestParam(required = false, defaultValue = "1") Integer current,
            @RequestParam(required = false, defaultValue = "10") Integer pageSize,
            @RequestParam String computeDate,
            @RequestParam(required = false) String resultType) {

        return Result.ok(costDataService.getCheckList(current,pageSize,computeDate, resultType));
    }

    @ApiOperation("月度数据采集-检查")
    @PostMapping("check")
    public Result check(@RequestParam String computeDate) {
        return Result.ok(costDataService.check(computeDate));
    }

    @ApiOperation("月度数据采集-一键获取")
    @PostMapping("getAllData")
    public Result getData(@RequestParam String computeDate) {
        costDataService.getAllData(computeDate);
        return Result.ok();
    }

    @ApiOperation("月度数据采集-获取")
    @PostMapping("getData")
    public Result getData(@RequestParam String computeDate,
                          @RequestParam String type) {
        costDataService.getData(computeDate,type);
        return Result.ok();
    }
    CostCostingGroupService costCostingGroupService;
    CostIncomeGroupService incomeGroupService;

    ShareParamValueService shareParamValueService;

    EmpCostImportService empCostImportService;

    ResponsibilityService responsibilityService;
    PatientInfoImportService patientInfoImportService;

    PatientItemImportService patientItemImportService;
    CostIncomeFileService costIncomeFileService;
    @ApiOperation("月度数据采集-撤销")
    @PostMapping("removeData")
    public Result removeData(@RequestParam String computeDate,
                          @RequestParam Integer type) {
        if(type.equals(NumberConstant.ONE)){
            incomeGroupService.removeIncome(computeDate);
            costIncomeFileService.removeByComputeAndFileType(computeDate,type);
        } else if (type.equals(NumberConstant.TWO)) {
            costCostingGroupService.removeCost(computeDate);
            costIncomeFileService.removeByComputeAndFileType(computeDate,type);
        } else if (type.equals(NumberConstant.THREE)) {
            shareParamValueService.removeShareParam(computeDate);
            costIncomeFileService.removeByComputeAndFileType(computeDate,type);
        } else if (type.equals(NumberConstant.FOUR)) {
            empCostImportService.removeEmpCost(computeDate);
            costIncomeFileService.removeByComputeAndFileType(computeDate,type);
        } else if (type.equals(NumberConstant.FIVE)) {
            patientInfoImportService.removePatientInfo(computeDate);
            costIncomeFileService.removeByComputeAndFileType(computeDate,type);
        } else if (type.equals(NumberConstant.SIX)) {
            patientItemImportService.removePatientItem(computeDate);
            costIncomeFileService.removeByComputeAndFileType(computeDate,type);
        }
        return Result.ok();
    }

    @ApiOperation("月度数据采集-收入数据-科室列表")
    @GetMapping("getIncomeDepartment")
    public Result getIncomeDepartment(@RequestParam String computeDate,
                             @RequestParam Integer type,@RequestParam(required = false)
                                      String departmentName) {
        return Result.ok(incomeGroupService.getDepartment(type,computeDate,departmentName));
    }

    @ApiOperation("月度数据采集-成本数据-科室列表")
    @GetMapping("getCostDepartment")
    public Result getCostDepartment(@RequestParam String computeDate,
                                      @RequestParam Integer type,@RequestParam(required = false)
                                      String departmentName) {

        return Result.ok(costCostingGroupService.getDepartment(type,computeDate,departmentName));
    }

    @ApiOperation("月度数据采集-成本分摊参数-责任中心")
    @GetMapping("getShareParamDepartment")
    public Result getShareParamDepartment( @RequestParam(required = false) String departmentName) {
        return Result.ok(responsibilityService.getList(departmentName));
    }


    @ApiOperation("月度数据采集-患者信息-科室")
    @GetMapping("getPatientInfoDepartment")
    public Result getPatientInfoDepartment( @RequestParam String computeDate,
                                            @RequestParam Integer type,
                                            @RequestParam(required = false) String filter) {        //1门诊3住院2急诊
        return Result.ok(patientInfoImportService.getPatientInfoDepartment(type,filter,computeDate));
    }

    @ApiOperation("月度数据采集-患者收费项目-患者信息")
    @GetMapping("getPatientItemPatientInfo")
    public Result getPatientItemPatientInfo( @RequestParam(defaultValue = "1", name = "current", required = false) Integer current,
                                             @RequestParam(defaultValue = "10", name = "pageSize", required = false) Integer pageSize,
                                             @RequestParam String computeDate,
                                             @RequestParam(required = false) String filter) {
        return Result.ok(patientItemImportService.getPatientItemPatientInfo(current,pageSize,filter,computeDate));
    }
}
