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.CostIncomeGroupSetEditDto;
import com.kcim.dao.model.dto.CostIncomeGroupSetSaveDto;
import com.kcim.dao.model.dto.IncomeAccountDto;
import com.kcim.vo.AccountIncomeSetVO;
import com.kcim.vo.CostIncomeGroupSetVO;
import com.kcim.service.CostIncomeGroupSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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


/**
 * 收入归集设置
 *
 * @author KCYG
 * @date 2021-08-03 08:41:20
 */
@RestController
@RequestMapping("costincomegroupset")
@Api(tags = "收入归集设置操作")
public class CostIncomeGroupSetController{
    private final CostIncomeGroupSetService costIncomeGroupSetService;

    public CostIncomeGroupSetController(CostIncomeGroupSetService costIncomeGroupSetService) {
        this.costIncomeGroupSetService = costIncomeGroupSetService;
    }

    /**
     * 分页查询列表
     */
    @GetMapping("/list")
    @ApiOperation("分页获取收入归集设置数据数据")
    public Result list(@RequestParam(defaultValue = "1", value = "current") Integer current,
                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
        Long hospId = UserContext.getHospId();
        PageUtils pageUtils = costIncomeGroupSetService.queryList(current,pageSize,hospId);
        return Result.ok(pageUtils);
    }


    /**
     * 根据Id获取收入归集设置数据
     */
    @GetMapping("/info/{id}")
    @ApiOperation("根据Id获取收入归集设置数据")
    public Result info(@PathVariable("id") Long id){
        Long hospId = UserContext.getHospId();
        CostIncomeGroupSetVO costIncomeGroupSetVO = costIncomeGroupSetService.getByIncomeGroupId(id,hospId);
        return Result.ok(costIncomeGroupSetVO);
    }

    /**
     * 保存
     */
    @PostMapping("/addCostIncomeGroupSet")
    @ApiOperation("添加收入归集设置数据")
    public Result save(@RequestBody @Valid CostIncomeGroupSetSaveDto costIncomeGroupSetSaveDto){
        Long hospId = UserContext.getHospId();
        costIncomeGroupSetService.addCostIncomeGroupSet(costIncomeGroupSetSaveDto,hospId);
        return Result.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation("修改收入归集设置数据")
    public Result update(@RequestBody @Valid CostIncomeGroupSetEditDto costIncomeGroupSetEditDto){
        Long hospId = UserContext.getHospId();
        costIncomeGroupSetService.updateByIncomeGroup(costIncomeGroupSetEditDto,hospId);
        return Result.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation("删除收入归集设置数据")
    public Result delete(@RequestBody Long[] ids){
		costIncomeGroupSetService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }

    /**
     *  添加排除成本科目
     */
    @PostMapping("/addIncomeAccount")
    @ApiOperation("添加需要排除的成本科目")
    public Result addIncomeAccount(@RequestBody IncomeAccountDto incomeAccountDto){

        costIncomeGroupSetService.updateAccountCode(incomeAccountDto);
        return Result.ok();
    }
    /**
     * 查询所有会计科目里面别当前是收入归集设置绑定的数据
     */
    @GetMapping("/getIncomeAccountStatus")
    @ApiOperation("查询所有会计科目里被当前收入归集设置选中的状态")
    public Result getIncomeAccountStatus(Long id){
        Long hospId = UserContext.getHospId();
        List<AccountIncomeSetVO> accountIncomeSetVOList = costIncomeGroupSetService.getIncomeAccountStatus(id,hospId);
        return Result.ok(accountIncomeSetVOList);
    }
}
