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.CostShareLevelEditDto;
import com.kcim.dao.model.dto.CostShareLevelSaveDto;
import com.kcim.vo.CostShareLevelVO;
import com.kcim.service.CostShareLevelService;
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-07-27 14:19:09
 */
@RestController
@RequestMapping("costsharelevel")
@Api(tags = "分摊层级相关操作")
public class CostShareLevelController {
    @Autowired
    private CostShareLevelService costShareLevelService;

    /**
     * 分页查询列表
     */
    @GetMapping("/list")
    @ApiOperation("分页查询分摊层级数据")
    public Result list(@RequestParam(defaultValue = "1", value = "current") Integer current,
                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                       @RequestParam(value = "name", required = false) String name){
//        User user = (User) SecurityUtils.getSubject().getPrincipal();
        Long hospId = UserContext.getHospId();
        PageUtils pageUtils= costShareLevelService.queryList(current,pageSize,name,hospId);
        return Result.ok(pageUtils);
    }


//    /**
//     * 信息
//     */
//    @RequestMapping("/info/{id}")
//    public Result info(@PathVariable("id") Integer id){
//		CostShareLevel costShareLevel = costShareLevelService.getById(id);
//        return Result.ok(costShareLevel);
//    }

    @GetMapping("/getAll")
    @ApiOperation("查询所有分摊层级数据")
    public Result getAll(){
//        User user = (User) SecurityUtils.getSubject().getPrincipal();
        Long hospId = UserContext.getHospId();
        List<CostShareLevelVO> costShareLevelVOList = costShareLevelService.getAll(hospId);
        return Result.ok(costShareLevelVOList);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("保存分摊层级数据")
    public Result save(@RequestBody @Valid CostShareLevelSaveDto costShareLevelSaveDto){
		costShareLevelService.addCostShareLevel(costShareLevelSaveDto);
        return Result.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation("修改分摊层级数据")
    public Result update(@RequestBody CostShareLevelEditDto costShareLevelEditDto){
		costShareLevelService.updateByCostShareLevel(costShareLevelEditDto);
        return Result.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation("删除分摊层级数据")
    public Result delete(@RequestBody Integer[] ids){
        costShareLevelService.deleteByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
