package com.ruoyi.generator.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.generator.domain.SourceProject;
import com.ruoyi.generator.service.ISourceProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/generator/sourceProject")
public class SourceProjectController extends BaseController
{
    @Autowired
    private ISourceProjectService sourceProjectService;

    @PreAuthorize("@ss.hasPermi('generator:sourceProject:list')")
    @GetMapping("/list")
    public TableDataInfo list(SourceProject sourceProject)
    {
        startPage();
        List<SourceProject> list = sourceProjectService.selectSourceProjectList(sourceProject);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('generator:sourceProject:export')")
    @Log(title = "源码项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SourceProject sourceProject)
    {
        List<SourceProject> list = sourceProjectService.selectSourceProjectList(sourceProject);
        ExcelUtil<SourceProject> util = new ExcelUtil<SourceProject>(SourceProject.class);
        util.exportExcel(response, list, "源码项目数据");
    }

    @PreAuthorize("@ss.hasPermi('generator:sourceProject:query')")
    @GetMapping(value = "/{projectId}")
    public AjaxResult getInfo(@PathVariable("projectId") Long projectId)
    {
        return success(sourceProjectService.selectSourceProjectByProjectId(projectId));
    }

    @PreAuthorize("@ss.hasPermi('generator:sourceProject:add')")
    @Log(title = "源码项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SourceProject sourceProject)
    {
        return toAjax(sourceProjectService.insertSourceProject(sourceProject));
    }

    @PreAuthorize("@ss.hasPermi('generator:sourceProject:edit')")
    @Log(title = "源码项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SourceProject sourceProject)
    {
        return toAjax(sourceProjectService.updateSourceProject(sourceProject));
    }

    @PreAuthorize("@ss.hasPermi('generator:sourceProject:edit')")
    @Log(title = "源码项目状态", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody SourceProject sourceProject)
    {
        return toAjax(sourceProjectService.changeSourceProjectStatus(sourceProject));
    }

    @PreAuthorize("@ss.hasPermi('generator:sourceProject:remove')")
    @Log(title = "源码项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{projectIds}")
    public AjaxResult remove(@PathVariable Long[] projectIds)
    {
        return toAjax(sourceProjectService.deleteSourceProjectByProjectIds(projectIds));
    }
}
