package com.kcim.web;

import com.kcim.common.util.Result;
import com.kcim.dao.model.CostResponsibilityDepartment;
import com.kcim.vo.CostDepartmentVO;
import com.kcim.service.CostResponsibilityDepartmentService;
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;
import java.util.List;


/**
 * 责任中心科室对照表
 *
 * @author KCYG
 * @date 2021-07-27 15:59:58
 */
@RestController
@RequestMapping("costresponsibilitydepartment")
@Api(tags = "责任中心科室对照表")
public class CostResponsibilityDepartmentController {
    @Autowired
    private CostResponsibilityDepartmentService costResponsibilityDepartmentService;

    /**
     * 分页查询列表
     */
    @GetMapping("/list")
    public Result list(@RequestParam(defaultValue = "1", value = "current") Integer current,
                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
//        User user = (User) SecurityUtils.getSubject().getPrincipal();
        return Result.ok();
    }

    /**
     * 根据责任中心的Id查询对应的科室信息的集合
     */
    @GetMapping("/getById")
    @ApiOperation("根据责任中心的Id获取科室信息的集合")
    public Result getById(Integer responsibilityId){
        List<CostDepartmentVO>  departmentList = costResponsibilityDepartmentService.getByResponsibilityId(responsibilityId);
        return Result.ok(departmentList);
    }
    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public Result info(@PathVariable("id") Integer id){
		CostResponsibilityDepartment costResponsibilityDepartment = costResponsibilityDepartmentService.getById(id);
        return Result.ok(costResponsibilityDepartment);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public Result save(@RequestBody CostResponsibilityDepartment costResponsibilityDepartment){
		costResponsibilityDepartmentService.save(costResponsibilityDepartment);
        return Result.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public Result update(@RequestBody CostResponsibilityDepartment costResponsibilityDepartment){
		costResponsibilityDepartmentService.updateById(costResponsibilityDepartment);
        return Result.ok();
    }

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

}
