package com.kcim.web;

import com.kcim.common.util.PageUtils;
import com.kcim.common.util.Result;
import com.kcim.dao.model.dto.AccountingEditDTO;
import com.kcim.dao.model.dto.AccountingSaveDTO;
import com.kcim.vo.AccountVO;
import com.kcim.vo.SelectAccountingVO;
import com.kcim.service.AccountingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;


/**
 * 会计科目管理表
 *
 * @author huangrui
 * @date 2021-07-28 13:52:24
 */
@Api(tags = "会计科目")
@RestController
@RequestMapping("accounting")
public class AccountingController{
    private final AccountingService accountingService;

    public AccountingController(AccountingService accountingService) {
        this.accountingService = accountingService;
    }

    @ApiOperation("获取会计科目列表按收入支出类型")
    @GetMapping("/list")
    @ApiImplicitParam(name = "accountType",value = "会计科目类型1.收入，2.支出")
    public Result list(@RequestParam Integer accountType,
                       Integer shareParamId,
                       Integer incomeGroutSetId,
                       @RequestParam(required = false)String filter){
        List<AccountVO> list = accountingService.getListByAccountType(accountType,shareParamId,incomeGroutSetId,filter);
        PageUtils pageUtils = new PageUtils(list, 0, 0, 0);
        return Result.ok(pageUtils);
    }



    @ApiOperation("保存会计科目")
    @PostMapping("/save")
    public Result save(@RequestBody @Valid AccountingSaveDTO accountingSaveDTO){
		accountingService.saveAccounting(accountingSaveDTO);
        return Result.ok();
    }


    @ApiOperation("选择会计科目列表")
    @GetMapping("/selectAccounting")
    public Result selectAccounting(){
        List<SelectAccountingVO> list = accountingService.selectAccounting();
        return Result.ok(list);
    }


    /**
     * 修改
     */
    @ApiOperation("编辑")
    @PostMapping("/edit")
    public Result update(@RequestBody @Valid AccountingEditDTO accountingEditDTO){
		accountingService.updateAccount(accountingEditDTO);
        return Result.ok();
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public Result delete(@RequestParam Long id){
        accountingService.deleteAccount(id);
        return Result.ok();
    }


    @ApiOperation("获取会计科目类别字典")
    @GetMapping("getAccountTypeDict")
    public Result getAccountTypeDict(@RequestParam Integer type){
        return Result.ok(accountingService.getAccountTypeDict(type));
    }

}
