package com.dayou.controller;

import com.dayou.vo.TeamVO;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.RestController;
import com.dayou.controller.BaseController;
import com.dayou.service.ITeamService;
import com.dayou.entity.Team;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;
import com.dayou.common.PullDownModel;
import com.dayou.utils.ConvertUtil;
import com.dayou.utils.HttpKit;
import com.dayou.exception.ErrorCode;
import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.http.MediaType;
import org.springframework.web.multipart.MultipartFile;
/**
 * 团队
 *
 * @author wucl
 * @since 2023-04-07
 */
@RestController
@RequestMapping("team")
@Slf4j
public class TeamController extends BaseController {
    @Autowired
    private ITeamService teamService;

    /**
    * 团队列表
    */
    @GetMapping("")
    public RestResponse<Page<TeamVO>> page(TeamVO teamVO, Page page){
        Page<TeamVO> pages=teamService.selectPage(page,teamVO);
        return RestResponse.data(pages);
    }

    /**
     * 团队详情
     */
    @GetMapping("/{id}")
    public RestResponse<Team> detail(@PathVariable Long id){
        Team xTeam =teamService.detail(id);
        return RestResponse.data(xTeam);
     }

    /**
     * 团队新增
     */
    @PostMapping("")
    public RestResponse<Boolean> save(@RequestBody Team team) {
        Boolean ret = teamService.add(team);
        return RestResponse.data(ret);
    }

    /**
     * 团队更新
     */
    @PutMapping("")
    public RestResponse<Boolean> update(@RequestBody Team team) {
        Boolean ret = teamService.update(team);
        return RestResponse.data(ret);
    }

    /**
     * 团队删除
     */
    @DeleteMapping("/{id}")
    public RestResponse<Boolean> delete(@PathVariable Long id) {
        Boolean ret = teamService.delete(id);
        return RestResponse.data(ret);
    }


    /**
     * 团队下拉列表
     */
    @GetMapping("/simpleAll")
    public RestResponse<List<PullDownModel>> simpleAll(){
        LambdaQueryWrapper<Team> lambdaQueryWrapper = new LambdaQueryWrapper<Team>()
        .select(Team::getId,Team::getName)
        .eq(Team::getDeleted,false);
        List<Team> list= teamService.list(lambdaQueryWrapper);
        List<PullDownModel> ret=ConvertUtil.copyList(list, PullDownModel.class);
        return RestResponse.data(ret);
    }
}

