package cn.iocoder.lyzsys.module.tjt.controller.admin.outputsplit;

import cn.iocoder.lyzsys.framework.common.pojo.CommonResult;
import cn.iocoder.lyzsys.module.tjt.controller.admin.outputsplit.vo.ProjectOutputSplitRespVO;
import cn.iocoder.lyzsys.module.tjt.controller.admin.outputsplit.vo.ProjectOutputSplitSaveReqVO;
import cn.iocoder.lyzsys.module.tjt.service.outputsplit.ProjectOutputSplitService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.lyzsys.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 特建投页面4拆分比例")
@RestController
@RequestMapping("/tjt/output-split")
@Validated
public class ProjectOutputSplitController {

    @Resource
    private ProjectOutputSplitService projectOutputSplitService;

    @GetMapping("/get-by-planning")
    @Operation(summary = "根据合约规划获得页面4拆分比例")
    @Parameter(name = "planningId", description = "合约规划 ID", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('tjt:output-split:query')")
    public CommonResult<ProjectOutputSplitRespVO> getProjectOutputSplitByPlanningId(@RequestParam("planningId") Long planningId) {
        return success(projectOutputSplitService.getProjectOutputSplit(planningId));
    }

    @PutMapping("/save")
    @Operation(summary = "保存页面4拆分比例")
    @PreAuthorize("@ss.hasPermission('tjt:output-split:update')")
    public CommonResult<Long> saveProjectOutputSplit(@Valid @RequestBody ProjectOutputSplitSaveReqVO reqVO) {
        return success(projectOutputSplitService.saveProjectOutputSplit(reqVO));
    }

}
