package com.ruoyi.postCheck.controller;

import java.util.Date;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.postCheck.domain.PostTeamUser;
import com.ruoyi.postCheck.service.IPostTeamUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiImplicitParam;

/**
 * 岗检小组关联成员Controller
 *
 * @author csg
 * @date 2023-12-19
 */
@Api(tags = "2.2.3-岗检小组关联成员接口")
@RestController
@RequestMapping("/postCheck/teamUser")
public class PostTeamUserController extends BaseController {
    @Autowired
    private IPostTeamUserService postTeamUserService;

    /**
     * 查询岗检小组关联成员列表
     */
    @ApiOperation("查询岗检小组关联成员列表")
    @PreAuthorize("@ss.hasPermi('postCheck:teamUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(PostTeamUser postTeamUser) {
        startPage();
        List<PostTeamUser> list = postTeamUserService.selectPostTeamUserList(postTeamUser);
        return getDataTable(list);
    }

    /**
     * 导出岗检小组关联成员列表
     @ApiOperation("导出岗检小组关联成员列表")
     @PreAuthorize("@ss.hasPermi('postCheck:teamUser:export')")
     @Log(title = "岗检小组关联成员", businessType = BusinessType.EXPORT)
     @PostMapping("/export") public void export(HttpServletResponse response, PostTeamUser postTeamUser) {
     List<PostTeamUser> list = postTeamUserService.selectPostTeamUserList(postTeamUser);
     ExcelUtil<PostTeamUser> util = new ExcelUtil<PostTeamUser>(PostTeamUser.class);
     util.exportExcel(response, list, "岗检小组关联成员数据");
     }
     */

    /**
     * 获取岗检小组关联成员详细信息
     */
    @ApiOperation("获取岗检小组关联成员详细信息")
    @PreAuthorize("@ss.hasPermi('postCheck:teamUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(postTeamUserService.selectPostTeamUserById(id));
    }

    /**
     * 新增岗检小组关联成员
     */
    @ApiOperation("新增岗检小组关联成员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "postTeamId", value = "岗检小组ID", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "type", value = "类型（1-组长；2-成员；）", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "delFlag", value = "del_flag", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "createUserId", value = "创建者用户ID", dataType = "Long", dataTypeClass = Long.class),
    })
    @PreAuthorize("@ss.hasPermi('postCheck:teamUser:add')")
    @Log(title = "岗检小组关联成员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<PostTeamUser> postTeamUserList) {
        return toAjax(postTeamUserService.insertPostTeamUser(postTeamUserList));
    }

    /**
     * 前端使用新增，不使用修改，新增接口始终传全量数据
     * 修改岗检小组关联成员
     *
     @ApiOperation("修改岗检小组关联成员")
     @PreAuthorize("@ss.hasPermi('postCheck:teamUser:edit')")
     @Log(title = "岗检小组关联成员", businessType = BusinessType.UPDATE)
     @PutMapping public AjaxResult edit(@RequestBody List<PostTeamUser> postTeamUserList) {
     return toAjax(postTeamUserService.updatePostTeamUser(postTeamUserList));
     }
     */

    /**
     * 删除岗检小组关联成员
     */
    @ApiOperation("删除岗检小组关联成员")
    @PreAuthorize("@ss.hasPermi('postCheck:teamUser:remove')")
    @Log(title = "岗检小组关联成员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(postTeamUserService.deletePostTeamUserByIds(ids));
    }


    @ApiOperation("Tools-根据岗检小组ID查询成员列表（组长的type=1）")
    @GetMapping("/getTeamUserByTeamId/{postTeamId}")
    public AjaxResult list(@PathVariable("postTeamId") Long postTeamId) {
        PostTeamUser postTeamUser = new PostTeamUser();
        postTeamUser.setPostTeamId(postTeamId);
        List<PostTeamUser> list = postTeamUserService.selectPostTeamUserList(postTeamUser);
        return success(list);
    }
}
