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.DepartmentProfitFile;
import com.kcim.service.DepartmentProfitFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;


/**
 * 科室经营报表
 *
 * @author huangrui
 * @date 2021-08-30 13:40:57
 */
@RestController
@RequestMapping("departmentprofitfile")
@Api(tags = "科室经营报表")
public class DepartmentProfitFileController {
    @Autowired
    private DepartmentProfitFileService departmentProfitFileService;

    /**
     * 分页查询列表
     * 查询的是
     */
    @GetMapping("/list")
    @ApiOperation("查询科室经营报表记录")

    public Result list(@RequestParam(value = "current", defaultValue = "1") Integer current,
                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                       @RequestParam(value = "date",required = false) String date,
                       @RequestParam(value = "reportName",required = false) String reportName){
        Long hospId = UserContext.getHospId();
        PageUtils pageUtils= departmentProfitFileService.queryList(current,pageSize,date,reportName,hospId);
        return Result.ok(pageUtils);
    }

    /**
     * 计算科室损益记录
     */
    @PostMapping("addDepartmentProfitFile")
    @ApiOperation("添加科室损益记录")
    public Result addDepartmentProfitFile(String date,Integer reportType){
        Long hospId = UserContext.getHospId();
        departmentProfitFileService.addDepartmentProfitFile(date,reportType,hospId);
        return Result.ok();
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public Result info(@PathVariable("id") Long id){
		DepartmentProfitFile departmentProfitFile = departmentProfitFileService.getById(id);
        return Result.ok(departmentProfitFile);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public Result save(@RequestBody DepartmentProfitFile departmentProfitFile){
		departmentProfitFileService.save(departmentProfitFile);
        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Result update(@RequestBody DepartmentProfitFile departmentProfitFile){
		departmentProfitFileService.updateById(departmentProfitFile);
        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public Result delete(@RequestBody Long[] ids){
        departmentProfitFileService.deleteByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
