package com.kcim.web;

import com.kcim.common.util.PageUtils;
import com.kcim.common.util.Result;
import com.kcim.common.util.UserContext;
import com.kcim.dao.model.dto.CostNumberBedSetEditDto;
import com.kcim.dao.model.dto.CostNumberBedSetSaveDto;
import com.kcim.vo.CheckShareParamStatusVO;
import com.kcim.vo.CostNumberBedSetVO;
import com.kcim.vo.ReportFormVO;
import com.kcim.service.CostNumberBedSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;


/**
 * 诊次/床日设置
 *
 * @author KCYG
 * @date 2021-08-09 11:11:06
 */
@RestController
@RequestMapping("costnumberbedset")
@Api(tags = "诊次/床日设置操作")
public class CostNumberBedSetController {
    @Autowired
    private CostNumberBedSetService costNumberBedSetService;

    /**
     * 分页查询列表
     * 查询的是
     */
    @GetMapping("/list")
    @ApiOperation("分页查询诊次/床日成本设置")
    public Result list(@RequestParam(value = "current", defaultValue = "1") Integer current,
                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                       @RequestParam(value = "name",required = false) String name){
        Long hospId = UserContext.getHospId();
        PageUtils pageUtils = costNumberBedSetService.queryList(current,pageSize,name,hospId);
        return Result.ok(pageUtils);
    }


    /**
     * 信息
     */
    @GetMapping("/info")
    @ApiOperation("根据Id获取诊次/床日成本设置")
    public Result info( Long id){
		CostNumberBedSetVO costNumberBedSetVO = costNumberBedSetService.getByNumberBedId(id);
        return Result.ok(costNumberBedSetVO);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("保存诊次/床日成本设置")
    public Result save(@RequestBody @Valid CostNumberBedSetSaveDto costNumberBedSetSaveDto){
        Long hospId = UserContext.getHospId();
        costNumberBedSetService.addNumberBedSet(costNumberBedSetSaveDto,hospId);
        return Result.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation("修改获取诊次/床日成本设置")
    public Result update(@RequestBody CostNumberBedSetEditDto costNumberBedSetEditDto){
        Long hospId = UserContext.getHospId();
        costNumberBedSetService.updateNumberBedById(costNumberBedSetEditDto,hospId);
        return Result.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation("根据Id的集合删除")
    public Result delete(@RequestBody Long[] ids){
        costNumberBedSetService.deleteByIds(Arrays.asList(ids));
        return Result.ok();
    }
    /**
     * 获取当前诊次/床日设置里面关联的成本分摊参数
     */
    @GetMapping("/getNumberBedSetShareParam")
    @ApiOperation("获取所有分摊参数里面与当前对用有关联的")
    public Result getNumberBedSetShareParam(Long id){
        Long hospId = UserContext.getHospId();
        List<CheckShareParamStatusVO> checkShareParamStatusVOList=costNumberBedSetService.checkStatus(id,hospId);
        return Result.ok(checkShareParamStatusVOList);
    }
    /**
     * 获取报表  显示报表被选中的状态
     * @param reportType 报表类型
     */
    @GetMapping("/getReportNumberBedStatus")
    @ApiOperation("获取损益表 全院损益表关联的状态")
    public Result getReportNumberBedStatus(Integer reportType,Integer id){
        Long hospId = UserContext.getHospId();
        List<ReportFormVO> reportNumberBedStatus = costNumberBedSetService.getReportNumberBedStatus(reportType, hospId,id);
        return Result.ok(reportNumberBedStatus);
    }

}
