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.ResponsibilityEditDTO;
import com.kcim.dao.model.dto.ResponsibilitySaveDTO;
import com.kcim.vo.CommonVO;
import com.kcim.vo.CostResponsibilityLevelVO;
import com.kcim.vo.CostResponsibilityVO;
import com.kcim.service.ResponsibilityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

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

@Api(tags = "责任中心")
@Slf4j
@RestController
@RequestMapping("responsibility")
public class ResponsibilityController extends AbstractController{

    private final ResponsibilityService responsibilityService;

    public ResponsibilityController(ResponsibilityService responsibilityService) {
        this.responsibilityService = responsibilityService;
    }

    @ApiOperation("责任中心列表")
    @GetMapping("/list")
    public Result list() {
        List<CostResponsibilityVO> list = responsibilityService.getList( );
        PageUtils pageUtils = new PageUtils(list,0,0,0);
        return Result.ok(pageUtils);
    }

    /**
     * 获取指定分摊层级的责任中心列表
     * @param shareId 分摊层级ID列表
     * @param filter 责任中心的过滤条件
     * @return
     */
    @ApiOperation("获取指定分摊层级的责任中心列表")
    @GetMapping("/getSharelevelRespList")
    public Result getSharelevelRespList(@RequestParam(required = false) Integer shareId,
                                        @RequestParam(required = false) String filter) {
        List<CostResponsibilityVO> list = responsibilityService.getSharelevelRespList( shareId,filter);
        PageUtils pageUtils = new PageUtils(list,0,0,0);
        return Result.ok(pageUtils);
    }

    @ApiOperation("收入归集设置需要的责任中心列表")
    @GetMapping("/responsibilityList")
    public Result responsibilityList() {
        List<CostResponsibilityVO> list = responsibilityService.responsibilityList();
        PageUtils pageUtils = new PageUtils(list,0,0,0);
        return Result.ok(pageUtils);
    }

    @GetMapping("/getLevelTwo")
    @ApiOperation("获取不是汇总中心列表")
    public Result getLevelTwo(){
        Long hospId = UserContext.getHospId();
        List<CostResponsibilityLevelVO> costResponsibilityLevelVOList= responsibilityService.getLevelTwo(hospId);
        return Result.ok(costResponsibilityLevelVOList);
    }



    @ApiOperation("新增责任中心")
    @PostMapping("/save")
    public Result save(@RequestBody @Valid ResponsibilitySaveDTO responsibilitySaveDTO) {
        responsibilityService.addResponsibilityCenter(responsibilitySaveDTO);
        return Result.ok();
    }

    @ApiOperation("编辑责任中心")
    @PostMapping("/edit")
    public Result edit(@RequestBody @Valid ResponsibilityEditDTO responsibilityEditDTO) {
        responsibilityService.editResponsibility(responsibilityEditDTO);
        return Result.ok();
    }

    @ApiOperation("删除某个责任中心")
    @PostMapping("/delete")
    public Result delete(@RequestParam Integer id) {
        responsibilityService.deleteCenter(id);
        return Result.ok();
    }


    @ApiOperation("所有第一层父节点")
    @GetMapping("/getParentList")
    public Result getParentList() {
        List<CommonVO> list = responsibilityService.getParentList();
        return Result.ok(list);
    }



    @ApiOperation("获取标准分摊层级")
    @GetMapping("/getStandardShareLevel")
    public Result getStandardShareLevel() {
        return Result.ok(responsibilityService.getStandardShareLevel());
    }


    @ApiOperation("获取责任中心类型")
    @GetMapping("/getResponsibilityType")
    public Result getResponsibilityType() {
        return Result.ok(responsibilityService.getResponsibilityType());
    }

}
