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.CostOtherPaymentsData;
import com.kcim.dao.model.dto.CostOtherPaymentsDataEditDto;
import com.kcim.dao.model.dto.CostOtherPaymentsDataSaveDto;
import com.kcim.service.CostOtherPaymentsDataService;
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;


/**
 * 全院其他收支数据
 *
 * @author KCYG
 * @date 2021-08-17 08:53:35
 */
@RestController
@RequestMapping("costotherpaymentsdata")
@Api(tags = "全院其他收支数据操作")
public class CostOtherPaymentsDataController {
    @Autowired
    private CostOtherPaymentsDataService costOtherPaymentsDataService;

    /**
     * 分页查询列表
     * 查询的是
     */
    @GetMapping("/list")
    @ApiOperation("分页查询全院其他收支数据")
    public Result list(@RequestParam(value = "current", defaultValue = "1") Integer current,
                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                       @RequestParam(value = "dateTime",required = false) String dateTime){
        Long hospId = UserContext.getHospId();
        PageUtils pageUtils = costOtherPaymentsDataService.queryList(current,pageSize,dateTime,hospId);
        return Result.ok(pageUtils);
    }


    /**
     * 信息
     */
    @GetMapping("/info")
    public Result info( Long id){
		CostOtherPaymentsData costOtherPaymentsData = costOtherPaymentsDataService.getById(id);
        return Result.ok(costOtherPaymentsData);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("保存全院其他收支数据")
    public Result save(@RequestBody @Valid CostOtherPaymentsDataSaveDto costOtherPaymentsDataSaveDto){
        Long hospId = UserContext.getHospId();
        costOtherPaymentsDataService.addOtherPaymentData(costOtherPaymentsDataSaveDto,hospId);
        return Result.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation("修改全院其他收支数据")
    public Result update(@RequestBody @Valid CostOtherPaymentsDataEditDto costOtherPaymentsDataEditDto){
        Long hospId = UserContext.getHospId();
        costOtherPaymentsDataService.updateOtherPaymentData(costOtherPaymentsDataEditDto,hospId);
        return Result.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation("批量删除全院其他收支数据")
    public Result delete(@RequestBody Long[] ids){
        costOtherPaymentsDataService.deleteByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
