package com.kcim.web;

import com.kcim.common.util.PageUtils;
import com.kcim.common.util.Result;
import com.kcim.dao.model.dto.CollectDTO;
import com.kcim.service.ResponsibilityService;
import com.kcim.vo.CollectDataFormVO;
import com.kcim.service.IncomeCollectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 归集后列表
 *
 * @author huangrui
 * @date 2021-08-09 15:26:28
 */
@Api(tags = "归集后查询相关")
@RestController
@RequestMapping("incomeCollection")
public class IncomeCollectionController extends AbstractController {

    /**
     * 收入归集后
     */
    private final IncomeCollectionService incomeCollectionService;
    private final ResponsibilityService responsibilityService;

    public IncomeCollectionController(IncomeCollectionService incomeCollectionService, ResponsibilityService responsibilityService) {
        this.incomeCollectionService = incomeCollectionService;
        this.responsibilityService = responsibilityService;
    }

    @ApiOperation("收入归集列表")
    @GetMapping("/getCollections")
    public Result getCollections(@RequestParam(value = "current", defaultValue = "1") Integer current,
                                 @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                 @RequestParam(value = "date") String date) {
        PageUtils pageUtils = incomeCollectionService.getCollections(current, pageSize, date, getHospId());
        return Result.ok(pageUtils);
    }

    @ApiOperation("归集操作(开始归集)")
    @PostMapping("/collect")
    public Result collect(@RequestParam Integer year, @RequestParam Integer month) {
        incomeCollectionService.collect(year, month, getHospId());
        return Result.ok();
    }

    @ApiOperation("撤销归集")
    @PostMapping("/cancelCollect")
    public Result cancelCollect(@RequestParam Integer year, @RequestParam Integer month) {
        incomeCollectionService.cancelCollect(year, month, getHospId());
        return Result.ok();
    }

    @ApiOperation("归集后数据列表")
    @GetMapping("/collectList")
    public Result collectList(@ModelAttribute @Valid CollectDTO collectDTO) {
        collectDTO.setHospId(getHospId());
        PageUtils pageUtils = incomeCollectionService.collectList(collectDTO);
        return Result.ok(pageUtils);
    }

    @ApiOperation("归集后数据报表")
    @GetMapping("/collectDataForm")
    public Result collectDataForm(@ModelAttribute @Valid CollectDTO collectDTO) {
        collectDTO.setHospId(getHospId());
        CollectDataFormVO form = incomeCollectionService.collectDataForm(collectDTO);
        return Result.ok(form);
    }

    @ApiOperation("归集-获取责任中心")
    @GetMapping("getResponsibilityList")
    public Result getResponsibilityList(@RequestParam(required = false)String filter ){
        return Result.ok(responsibilityService.getList(filter));
    }
}
