package com.willalp.web.controller.clockingin;

import com.willalp.common.annotation.Log;
import com.willalp.common.core.controller.BaseController;
import com.willalp.common.core.domain.AjaxResult;
import com.willalp.common.core.page.TableDataInfo;
import com.willalp.common.enums.BusinessType;
import com.willalp.common.utils.DateUtils;
import com.willalp.common.utils.SecurityUtils;
import com.willalp.common.utils.poi.ExcelUtil;
import com.willalp.event.domain.HsAssociationsInfo;
import com.willalp.event.service.IHsAssociationsInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 社团信息Controller
 *
 * @author willalp
 * @date 2023-04-04
 */
@RestController
@RequestMapping("/event/associations")
public class HsAssociationsInfoController extends BaseController
{
    @Resource
    private IHsAssociationsInfoService hsAssociationsInfoService;

    /**
     * 查询社团信息列表
     */
    @PreAuthorize("@ss.hasPermi('event:associations:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsAssociationsInfo hsAssociationsInfo)
    {
        startPage();
        List<HsAssociationsInfo> list = hsAssociationsInfoService.selectHsAssociationsInfoList(hsAssociationsInfo);
        return getDataTable(list);
    }

    /**
     * 导出社团信息列表
     */
    @PreAuthorize("@ss.hasPermi('event:associations:export')")
    @Log(title = "社团信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsAssociationsInfo hsAssociationsInfo)
    {
        List<HsAssociationsInfo> list = hsAssociationsInfoService.selectHsAssociationsInfoList(hsAssociationsInfo);
        ExcelUtil<HsAssociationsInfo> util = new ExcelUtil<HsAssociationsInfo>(HsAssociationsInfo.class);
        return util.exportExcel(list, "社团信息数据");
    }

    /**
     * 获取社团信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('event:associations:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(hsAssociationsInfoService.getById(id));
    }

    /**
     * 新增社团信息
     */
    @PreAuthorize("@ss.hasPermi('event:associations:add')")
    @Log(title = "社团信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsAssociationsInfo hsAssociationsInfo)
    {
        hsAssociationsInfo.setCreateBy(SecurityUtils.getUsername());
        hsAssociationsInfo.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsAssociationsInfoService.save(hsAssociationsInfo));
    }

    /**
     * 修改社团信息
     */
    @PreAuthorize("@ss.hasPermi('event:associations:edit')")
    @Log(title = "社团信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsAssociationsInfo hsAssociationsInfo)
    {
        hsAssociationsInfo.setUpdateBy(SecurityUtils.getUsername());
        hsAssociationsInfo.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsAssociationsInfoService.updateById(hsAssociationsInfo));
    }

    /**
     * 删除社团信息
     */
    @PreAuthorize("@ss.hasPermi('event:associations:remove')")
    @Log(title = "社团信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(hsAssociationsInfoService.removeByIds(Arrays.asList(ids)));
    }
}
