package com.yanzhu.manage.controller;

import com.yanzhu.common.core.domain.R;
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.ProProjectInfoUsers;
import com.yanzhu.manage.service.IProProjectInfoUsersService;
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("/proProjectInfoUsers")
public class ProProjectInfoUsersController extends BaseController
{
    @Autowired
    private IProProjectInfoUsersService proProjectInfoUsersService;

    /**
     * 查询项目人员列表
     */
    @RequiresPermissions("manage:proProjectInfoUsers:list")
    @GetMapping("/list")
    public TableDataInfo list(ProProjectInfoUsers proProjectInfoUsers)
    {
        startPage();
        List<ProProjectInfoUsers> list = proProjectInfoUsersService.selectProProjectInfoUsersList(proProjectInfoUsers);
        return getDataTable(list);
    }

    /**
     * 导出项目人员列表
     */
    @RequiresPermissions("manage:proProjectInfoUsers:export")
    @Log(title = "项目人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProProjectInfoUsers proProjectInfoUsers)
    {
        List<ProProjectInfoUsers> list = proProjectInfoUsersService.selectProProjectInfoUsersList(proProjectInfoUsers);
        ExcelUtil<ProProjectInfoUsers> util = new ExcelUtil<ProProjectInfoUsers>(ProProjectInfoUsers.class);
        util.exportExcel(response, list, "项目人员数据");
    }

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

    /**
     * 新增项目人员
     */
    @RequiresPermissions("manage:proProjectInfoUsers:add")
    @Log(title = "项目人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProProjectInfoUsers proProjectInfoUsers)
    {
        return toAjax(proProjectInfoUsersService.insertProProjectInfoUsers(proProjectInfoUsers));
    }

    /**
     * 修改项目人员
     */
    @RequiresPermissions("manage:proProjectInfoUsers:edit")
    @Log(title = "项目人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProProjectInfoUsers proProjectInfoUsers)
    {
        return toAjax(proProjectInfoUsersService.updateProProjectInfoUsers(proProjectInfoUsers));
    }

    /**
     * 删除项目人员
     */
    @RequiresPermissions("manage:proProjectInfoUsers:remove")
    @Log(title = "项目人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(proProjectInfoUsersService.deleteProProjectInfoUsersByIds(ids));
    }

    /**
     * 修改为默认项目
     */
    @GetMapping("/changeDefaultProject/{id}")
    public AjaxResult changeDefaultProject(@PathVariable("id") Long id)
    {
        return toAjax(proProjectInfoUsersService.editDefaultProjectById(id));
    }

    /**
     * 获取当前用户入场项目信息
     */
    @InnerAuth
    @GetMapping("/projects/{userId}")
    public R<List<Map<String, Object>>> getProjects(@PathVariable("userId") Long userId)
    {
        List<Map<String, Object>> list = proProjectInfoUsersService.selectProjectsByUserId(userId);
        return R.ok(list);
    }
}
