package com.ruoyi.gysl.controller;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.gysl.entity.ProjectLegend;
import com.ruoyi.gysl.entity.request.ZwIdPageReq;
import com.ruoyi.gysl.service.BasicInformationService;
import com.ruoyi.gysl.service.ProjectLegendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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

/**
 * 项目图例(ProjectLegend)表控制层
 *
 * @author makejava
 * @since 2025-03-19 10:12:34
 */
@Api(tags = "项目图例")
@RestController
@RequestMapping("/gysl/projectLegend")
public class ProjectLegendController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ProjectLegendService projectLegendService;

    @Resource
    private BasicInformationService basicInformationService;

    /**
     * 根据项目id查询所有数据
     *
     * @param projectLegend 查询实体
     * @return 所有数据
     */
    @ApiOperation("根据项目id查询所有数据")
    @GetMapping("/page")
    public AjaxResult selectAll(@Valid ZwIdPageReq projectLegend) {
        basicInformationService.testXmId(projectLegend.getXmId());
        return success(projectLegendService.page(projectLegend));
    }


    /**
     * 新增数据
     *
     * @param projectLegend 实体对象
     * @return 新增结果
     */
    @ApiOperation("新增数据")
    @PostMapping("/add")
    public AjaxResult insert(@RequestBody ProjectLegend projectLegend) {
        basicInformationService.testXmId(projectLegend.getXmId());
        return success(projectLegendService.save(projectLegend));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "通过主键查询单条数据",response = ProjectLegend.class )
    public AjaxResult selectOne(@PathVariable Serializable id) {
        ProjectLegend byId = projectLegendService.getById(id);
        basicInformationService.testXmId(byId.getXmId());
        return success(byId);
    }

    /**
     * 修改数据
     *
     * @param projectLegend 实体对象
     * @return 修改结果
     */
    @ApiOperation("修改数据")
    @PutMapping("/edit")
    public AjaxResult update(@RequestBody ProjectLegend projectLegend) {
        basicInformationService.testXmId(projectLegend.getXmId());
        return success(projectLegendService.updateById(projectLegend));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @ApiOperation("删除数据")
    @DeleteMapping("/delete")
    public AjaxResult delete(@RequestParam("idList") List<Long> idList) {
        return success(projectLegendService.removeByIds(idList));
    }
}

