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.CostIncomeGroup;
import com.kcim.service.CostIncomeGroupService;
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;


/**
 * 收入归集
 *
 * @author KCYG
 * @date 2021-08-03 16:15:20
 */
@RestController
@RequestMapping("costincomegroup")
@Api(tags = "收入归集操作")
public class CostIncomeGroupController {
    @Autowired
    private CostIncomeGroupService costIncomeGroupService;

    /**
     * 分页查询列表
     * 根据年月  下拉选择的责任中心Code 会计科目的Code
     */
    @GetMapping("/list")
    @ApiOperation("分页获取收入归集前数据")
    public Result list(@RequestParam(defaultValue = "1", value = "current") Integer current,
                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                       @RequestParam(value = "dateTime") String dateTime,
                       @RequestParam(value = "responsibilityCode",required = false) String responsibilityCode,
                       @RequestParam(value = "productCode",required = false) String productCode,
                       @RequestParam(value = "filter",required = false)String filter,
                       @RequestParam Integer type,
                       @RequestParam String departmentCode){
        Long hospId = UserContext.getHospId();
        PageUtils pageUtils = costIncomeGroupService.queryList(current,pageSize,dateTime,responsibilityCode,productCode,hospId,type,filter,departmentCode);
        return Result.ok(pageUtils);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public Result info(@PathVariable("id") Long id){
		CostIncomeGroup costIncomeGroup = costIncomeGroupService.getById(id);
        return Result.ok(costIncomeGroup);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public Result save(@RequestBody CostIncomeGroup costIncomeGroup){
		costIncomeGroupService.save(costIncomeGroup);
        return Result.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public Result update(@RequestBody CostIncomeGroup costIncomeGroup){
		costIncomeGroupService.updateById(costIncomeGroup);
        return Result.ok();
    }

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

}
