package com.ygtx.worklog.controller;

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

/**
 * 项目管理Controller
 * 
 * @author ouyj
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/worklog/workProject")
public class WorkProjectController extends BaseController
{
    @Autowired
    private IWorkProjectService workProjectService;

    /**
     * 查询项目管理列表
     */
    @PreAuthorize("@ss.hasPermi('worklog:workProject:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkProject workProject)
    {
        startPage();
        List<WorkProject> list = workProjectService.selectWorkProjectList(workProject);
        return getDataTable(list);
    }

    /**
     * 导出项目管理列表
     */
    @PreAuthorize("@ss.hasPermi('worklog:workProject:export')")
    @Log(title = "项目管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkProject workProject)
    {
        List<WorkProject> list = workProjectService.selectWorkProjectList(workProject);
        ExcelUtil<WorkProject> util = new ExcelUtil<WorkProject>(WorkProject.class);
        util.exportExcel(response, list, "项目管理数据");
    }

    /**
     * 获取项目管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('worklog:workProject:query')")
    @GetMapping(value = "/{projectId}")
    public AjaxResult getInfo(@PathVariable("projectId") Long projectId)
    {
        return success(workProjectService.selectWorkProjectByProjectId(projectId));
    }

    /**
     * 新增项目管理
     */
    @PreAuthorize("@ss.hasPermi('worklog:workProject:add')")
    @Log(title = "项目管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkProject workProject)
    {
        return toAjax(workProjectService.insertWorkProject(workProject));
    }

    /**
     * 修改项目管理
     */
    @PreAuthorize("@ss.hasPermi('worklog:workProject:edit')")
    @Log(title = "项目管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkProject workProject)
    {
        return toAjax(workProjectService.updateWorkProject(workProject));
    }

    /**
     * 删除项目管理
     */
    @PreAuthorize("@ss.hasPermi('worklog:workProject:remove')")
    @Log(title = "项目管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{projectIds}")
    public AjaxResult remove(@PathVariable Long[] projectIds)
    {
        return toAjax(workProjectService.deleteWorkProjectByProjectIds(projectIds));
    }
}