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

import cn.iocoder.lyzsys.framework.common.pojo.CommonResult;
import cn.iocoder.lyzsys.framework.common.util.object.BeanUtils;
import cn.iocoder.lyzsys.module.tjt.controller.admin.planningguidedetail.vo.ProjectPlanningGuideDetailBatchSaveReqVO;
import cn.iocoder.lyzsys.module.tjt.controller.admin.planningguidedetail.vo.ProjectPlanningGuideDetailRespVO;
import cn.iocoder.lyzsys.module.tjt.dal.dataobject.planningguidedetail.ProjectPlanningGuideDetailDO;
import cn.iocoder.lyzsys.module.tjt.service.planningguidedetail.ProjectPlanningGuideDetailService;
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.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

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

@Tag(name = "管理后台 - 合约规划指导价法明细")
@RestController
@RequestMapping("/tjt/planning-guide-detail")
@Validated
public class ProjectPlanningGuideDetailController {

    @Resource
    private ProjectPlanningGuideDetailService projectPlanningGuideDetailService;

    @GetMapping("/list-by-planning")
    @Operation(summary = "根据合约规划获得指导价法明细列表")
    @Parameter(name = "planningId", description = "合约规划 ID", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('tjt:planning:query')")
    public CommonResult<List<ProjectPlanningGuideDetailRespVO>> getProjectPlanningGuideDetailListByPlanningId(
            @RequestParam("planningId") Long planningId) {
        List<ProjectPlanningGuideDetailDO> list =
                projectPlanningGuideDetailService.getProjectPlanningGuideDetailListByPlanningId(planningId);
        return success(BeanUtils.toBean(list, ProjectPlanningGuideDetailRespVO.class));
    }

    @PostMapping("/batch-save")
    @Operation(summary = "批量保存指导价法明细")
    @PreAuthorize("@ss.hasPermission('tjt:planning:update')")
    public CommonResult<Boolean> batchSaveProjectPlanningGuideDetail(
            @Valid @RequestBody ProjectPlanningGuideDetailBatchSaveReqVO reqVO) {
        projectPlanningGuideDetailService.batchSaveProjectPlanningGuideDetail(reqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除指导价法明细")
    @Parameter(name = "id", description = "明细 ID", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('tjt:planning:update')")
    public CommonResult<Boolean> deleteProjectPlanningGuideDetail(@RequestParam("id") Long id) {
        projectPlanningGuideDetailService.deleteProjectPlanningGuideDetail(id);
        return success(true);
    }

}
