package com.yanzhu.manage.controller;

import com.yanzhu.common.core.domain.R;
import com.yanzhu.common.core.utils.bean.BeanUtils;
import com.yanzhu.common.core.utils.poi.ExcelUtil;
import com.yanzhu.common.core.web.controller.BaseController;
import com.yanzhu.common.core.web.domain.AjaxResult;
import com.yanzhu.common.core.web.page.TableDataInfo;
import com.yanzhu.common.log.annotation.Log;
import com.yanzhu.common.log.enums.BusinessType;
import com.yanzhu.common.security.annotation.InnerAuth;
import com.yanzhu.common.security.annotation.RequiresPermissions;
import com.yanzhu.manage.domain.ProProjectInfo;
import com.yanzhu.manage.service.IProProjectInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 项目信息Controller
 * 
 * @author JiangYuQi
 * @date 2024-08-25
 */
@RestController
@RequestMapping("/proProjectInfo")
public class ProProjectInfoController extends BaseController
{
    @Autowired
    private IProProjectInfoService proProjectInfoService;

    /**
     * 查询项目信息列表
     */
    @RequiresPermissions("manage:proProjectInfo:list")
    @GetMapping("/list")
    public TableDataInfo list(ProProjectInfo proProjectInfo)
    {
        startPage();
        List<ProProjectInfo> list = proProjectInfoService.selectProProjectInfoList(proProjectInfo);
        return getDataTable(list);
    }

    /**
     * 导出项目信息列表
     */
    @RequiresPermissions("manage:proProjectInfo:export")
    @Log(title = "项目信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProProjectInfo proProjectInfo)
    {
        List<ProProjectInfo> list = proProjectInfoService.selectProProjectInfoList(proProjectInfo);
        ExcelUtil<ProProjectInfo> util = new ExcelUtil<ProProjectInfo>(ProProjectInfo.class);
        util.exportExcel(response, list, "项目信息数据");
    }

    /**
     * 获取项目信息详细信息
     */
    @RequiresPermissions("manage:proProjectInfo:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(proProjectInfoService.selectProProjectInfoById(id));
    }

    /**
     * 获取项目信息详细信息
     */
    @InnerAuth
    @GetMapping("/info/{id}")
    public R<Map<String, Object>> info(@PathVariable("id") Long id)
    {
        ProProjectInfo info = proProjectInfoService.selectProProjectInfoById(id);
        try {
            Map<String, Object> data = BeanUtils.beanToMap(info);
            return R.ok(data);
        }catch (Exception e){
            return R.fail("项目信息异常！！！");
        }
    }

    /**
     * 新增项目信息
     */
    @RequiresPermissions("manage:proProjectInfo:add")
    @Log(title = "项目信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProProjectInfo proProjectInfo)
    {
        return toAjax(proProjectInfoService.insertProProjectInfo(proProjectInfo));
    }

    /**
     * 修改项目信息
     */
    @RequiresPermissions("manage:proProjectInfo:edit")
    @Log(title = "项目信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProProjectInfo proProjectInfo)
    {
        return toAjax(proProjectInfoService.updateProProjectInfo(proProjectInfo));
    }

    /**
     * 删除项目信息
     */
    @RequiresPermissions("manage:proProjectInfo:remove")
    @Log(title = "项目信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(proProjectInfoService.deleteProProjectInfoByIds(ids));
    }

    /**
     * 获取我的项目列表
     */
    @GetMapping("/findMyProjectList")
    public TableDataInfo findMyProjectList(ProProjectInfo proProjectInfo)
    {
        startPage();
        List<ProProjectInfo> list = proProjectInfoService.selectProProjectInfoList(proProjectInfo);
        return getDataTable(list);
    }
}
