package com.ruoyi.gysl.controller;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.gysl.entity.Xmxl;
import com.ruoyi.gysl.entity.request.ZwIdPageReq;
import com.ruoyi.gysl.service.BasicInformationService;
import com.ruoyi.gysl.service.XmxlService;
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;

/**
 * 项目巡礼(Xmxl)表控制层
 *
 * @author makejava
 * @since 2025-03-21 14:15:34
 */
@Api(tags ="项目巡礼" )
@RestController
@RequestMapping("/gysl/xmxl")
public class XmxlController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private XmxlService xmxlService;

    /**
     * 基本信息
     */
    @Resource
    private BasicInformationService basicInformationService;

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

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

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

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

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

