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.CostOtherPaymentsEditDto;
import com.kcim.vo.CostOtherPaymentsSaveDto;
import com.kcim.vo.CostOtherPaymentsVO;
import com.kcim.service.CostOtherPaymentsService;
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 17:53:22
 */
@RestController
@RequestMapping("costotherpayments")
@Api(tags = "全院其他收支设置操作")
public class CostOtherPaymentsController {
    @Autowired
    private CostOtherPaymentsService costOtherPaymentsService;

    /**
     * 分页查询列表
     * 查询的是
     */
    @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 = costOtherPaymentsService.queryList(current,pageSize,name,hospId);
        return Result.ok(pageUtils);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation("根据Id查询全院其他收支设置数据")
    public Result info(@PathVariable("id") Long id){
		CostOtherPaymentsVO costOtherPaymentsVO = costOtherPaymentsService.getByParamsId(id);
        return Result.ok(costOtherPaymentsVO);
    }
    /**
     * 查询全院其他收支设置数据列表
     */
    @GetMapping("/getAll")
    @ApiOperation("查询全院其他收支设置列表")
    public Result getAll(){
        Long hospId = UserContext.getHospId();
        List<CostOtherPaymentsVO> costOtherPaymentsVOList = costOtherPaymentsService.getAll(hospId);
        return Result.ok(costOtherPaymentsVOList);
    }
    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("保存全院其他收支设置数据")
    public Result save(@RequestBody @Valid CostOtherPaymentsSaveDto costOtherPaymentsSaveDto){
		costOtherPaymentsService.addOtherPayment(costOtherPaymentsSaveDto);
        return Result.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation("修改全院其他收支设置数据")
    public Result update(@RequestBody @Valid CostOtherPaymentsEditDto costOtherPaymentsEditDto){
		costOtherPaymentsService.updateOtherPaymentById(costOtherPaymentsEditDto);
        return Result.ok();
    }

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

}
