package com.aucma.base.controller;

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

import com.aucma.common.utils.DateUtils;
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.aucma.common.annotation.Log;
import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.common.enums.BusinessType;
import com.aucma.base.domain.BaseTeamMembers;
import com.aucma.base.service.IBaseTeamMembersService;
import com.aucma.common.utils.poi.ExcelUtil;
import com.aucma.common.core.page.TableDataInfo;

/**
 * 班组信息Controller
 *
 * @author Yinq
 * @date 2023-09-19
 */
@RestController
@RequestMapping("/base/teamMembers" )
public class BaseTeamMembersController extends BaseController {
    @Autowired
    private IBaseTeamMembersService baseTeamMembersService;

/**
 * 查询班组信息列表
 */
@PreAuthorize("@ss.hasPermi('base:teamMembers:list')" )
@GetMapping("/list" )
    public TableDataInfo list(BaseTeamMembers baseTeamMembers) {
        startPage();
        List<BaseTeamMembers> list = baseTeamMembersService.selectBaseTeamMembersList(baseTeamMembers);
        return getDataTable(list);
    }

    /**
     * 导出班组信息列表
     */
    @PreAuthorize("@ss.hasPermi('base:teamMembers:export')" )
    @Log(title = "班组信息" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, BaseTeamMembers baseTeamMembers) {
        List<BaseTeamMembers> list = baseTeamMembersService.selectBaseTeamMembersList(baseTeamMembers);
        ExcelUtil<BaseTeamMembers> util = new ExcelUtil<BaseTeamMembers>(BaseTeamMembers. class);
        util.exportExcel(response, list, "班组信息数据" );
    }

    /**
     * 获取班组信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:teamMembers:query')" )
    @GetMapping(value = "/{objId}" )
    public AjaxResult getInfo(@PathVariable("objId" ) Long objId) {
        return success(baseTeamMembersService.selectBaseTeamMembersByObjId(objId));
    }

    /**
     * 新增班组信息
     */
    @PreAuthorize("@ss.hasPermi('base:teamMembers:add')" )
    @Log(title = "班组信息" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseTeamMembers baseTeamMembers) {
        baseTeamMembers.setCreatedBy(getUsername());
        baseTeamMembers.setCreatedTime(DateUtils.getNowDate());
        return toAjax(baseTeamMembersService.insertBaseTeamMembers(baseTeamMembers));
    }

    /**
     * 修改班组信息
     */
    @PreAuthorize("@ss.hasPermi('base:teamMembers:edit')" )
    @Log(title = "班组信息" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseTeamMembers baseTeamMembers) {
        baseTeamMembers.setUpdatedBy(getUsername());
        baseTeamMembers.setUpdatedTime(DateUtils.getNowDate());
        return toAjax(baseTeamMembersService.updateBaseTeamMembers(baseTeamMembers));
    }

    /**
     * 删除班组信息
     */
    @PreAuthorize("@ss.hasPermi('base:teamMembers:remove')" )
    @Log(title = "班组信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{objIds}" )
    public AjaxResult remove(@PathVariable Long[] objIds) {
        return toAjax(baseTeamMembersService.deleteBaseTeamMembersByObjIds(objIds));
    }
}
