package com.hs.api.controller;

import com.hs.api.common.Result;
import com.hs.api.common.annotations.CurrentUser;
import com.hs.api.common.annotations.Token;
import com.hs.api.model.reqmodel.AddBudgetValue;
import com.hs.api.model.reqmodel.QueryBudgetValue;
import com.hs.api.model.reqmodel.QuerySummary;
import com.hs.api.model.reqmodel.QuerySummary2;
import com.hs.api.service.SerProjValueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@Api(tags = "预算编制Api")
@RestController
public class SerProjValueController {
    @Resource
    private SerProjValueService projValueService;

    @PostMapping("budget/value")
    @Token
    @ApiOperation("查询预算编制数据")
    public Object getProjValue(@ApiIgnore @CurrentUser Long userId,@RequestBody QueryBudgetValue request) throws Throwable {
        Object result = projValueService.getValue(request.getProjectType(),request.getDate(),request.getDeptCode(),userId);
        return Result.success(result);

    }

    @PostMapping("budget/save")
    @Token
    @ApiOperation("保存数据")
    public Object save(@ApiIgnore @CurrentUser Long userId,@RequestBody AddBudgetValue request) throws Throwable {
        boolean result = projValueService.save(userId,request);
        if(result)
            return Result.success(null);
        else
            return Result.error();
    }

    @PostMapping("budget/summary")
    @Token
    @ApiOperation("查询预算编制汇总数据")
    public Object getSummary(@ApiIgnore @CurrentUser Long userId,@RequestBody QuerySummary request) throws Throwable {
        Object result = projValueService.getSummary(request.getDate(),request.getBudgetType(),userId);
        return Result.success(result);
    }

    @PostMapping("budget/summarynew")
    @Token
    @ApiOperation("查询预算编制汇总数据")
    public Object getSummaryNew(@RequestBody QuerySummary req) throws Throwable {
        Object result = projValueService.getData(req.getDate(),req.getPage());
        return Result.success(result);
    }


    @PostMapping("budget/summarynew2")
//    @Token
    @ApiOperation("查询预算编制汇总数据")
    public Object getSummaryNew2(@RequestBody QuerySummary2 req) throws Throwable {
        Object result = projValueService.getDataNew(req.getPage(),req.getDim());
        return Result.success(result);
    }
}
