package com.bonus.bracelet.controller;

import com.bonus.bracelet.service.ITeamMgeService;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.entity.bracelet.BraceletParamsDto;
import com.bonus.common.entity.bracelet.vo.TeamPeopleVo;
import com.bonus.common.entity.bracelet.vo.TeamVo;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import com.bonus.common.security.annotation.RequiresPermissions;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @className:TeamMgeController
 * @author:cwchen
 * @date:2024-07-16-10:36
 * @version:1.0
 * @description:班组管理-controller
 */
@RestController
@RequestMapping("/team/")
@Slf4j
public class TeamMgeController extends BaseController {

    @Resource(name = "ITeamMgeService")
    private ITeamMgeService service;

    //    @RequiresPermissions("basic:team:list")
    @GetMapping("list")
    @SysLog(title = "班组管理", businessType = OperaType.QUERY, logType = 0, module = "基础管理->班组管理", details = "查询班组列表")
    public TableDataInfo list(BraceletParamsDto dto) {
        startPage();
        List<TeamVo> list = service.getTeamLists(dto);
        return getDataTable(list);
    }

    //    @RequiresPermissions("basic:team:add")
    @PostMapping("addTeam")
    @SysLog(title = "班组管理", businessType = OperaType.INSERT, logType = 0, module = "基础管理->班组管理", details = "新增班组")
    public AjaxResult addTeam(@Validated @RequestBody TeamVo vo) {
        return service.addTeam(vo);
    }

    //    @RequiresPermissions("basic:team:edit")
    @PostMapping("editTeam")
    @SysLog(title = "班组管理", businessType = OperaType.UPDATE, logType = 0, module = "基础管理->班组管理", details = "修改班组")
    public AjaxResult editTeam(@Validated @RequestBody TeamVo vo) {
        return service.editTeam(vo);
    }

    //    @RequiresPermissions("basic:team:dissolution")
    @PostMapping("dissolutionTeam")
    @SysLog(title = "班组管理", businessType = OperaType.QUERY, logType = 0, module = "基础管理->班组管理", details = "解散班组")
    public AjaxResult dissolutionTeam(@RequestBody BraceletParamsDto dto) {
        return service.dissolutionTeam(dto);
    }

    //    @RequiresPermissions("basic:team:del")
    @PostMapping("delTeam")
    @SysLog(title = "班组管理", businessType = OperaType.QUERY, logType = 0, module = "基础管理->班组管理", details = "删除班组")
    public AjaxResult delTeam(@RequestBody BraceletParamsDto dto) {
        return service.delTeam(dto);
    }

    @PostMapping("getPersonList")
    public AjaxResult getPersonList(@RequestBody BraceletParamsDto dto) {
        return service.getPersonList(dto);
    }

    @PostMapping("getTeamInfo")
    public AjaxResult getTeamInfo(@RequestBody BraceletParamsDto dto) {
        return service.getTeamInfo(dto);
    }

    /**
     * 班组施工和在施人员
     * @param dto
     * @return TableDataInfo
     * @author cwchen
     * @date 2024/7/17 18:28
     */
    @GetMapping("getWorkPersonList")
    public TableDataInfo getWorkPersonList(BraceletParamsDto dto) {
        startPage();
        List<TeamPeopleVo> list = service.getWorkPersonList(dto);
        return getDataTable(list);
    }
}
