package com.ruoyi.gysl.controller;


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

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 项目其他信息(ProjectOtherInfo)表控制层
 *
 * @author makejava
 * @since 2025-03-19 10:49:22
 */
@Api(tags = "项目其他信息")
@RestController
@RequestMapping("/gysl/projectOtherInfo")
public class ProjectOtherInfoController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ProjectOtherInfoService projectOtherInfoService;

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

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


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

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

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

    /**
     * 根据条件导出项目其他信息
     */
    @ApiOperation(value = "根据条件导出项目其他信息")
    @PostMapping(value = "/export")
    public void export(HttpServletResponse response,@Valid ZwIdPageReq zwIdPageReq) throws Exception {
        List<ProjectOtherInfo> filteredList = projectOtherInfoService.searchId(zwIdPageReq);
        ExcelUtil<ProjectOtherInfo> util = new ExcelUtil<>(ProjectOtherInfo.class);
        util.exportExcel(response, filteredList, "项目其他信息");
    }
}

