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.HsEvent;
import com.willalp.event.service.IHsEventService;
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-01-29
 */
@RestController
@RequestMapping("/eventConfig/event")
public class HsEventController extends BaseController
{
    @Resource
    private IHsEventService hsEventService;

    /**
     * 查询活动配置列表
     */
    @PreAuthorize("@ss.hasPermi('eventConfig:event:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsEvent hsEvent)
    {
        startPage();
        List<HsEvent> list = hsEventService.selectHsEventList(hsEvent);
        return getDataTable(list);
    }

    /**
     * 导出活动配置列表
     */
    @PreAuthorize("@ss.hasPermi('eventConfig:event:export')")
    @Log(title = "活动配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsEvent hsEvent)
    {
        List<HsEvent> list = hsEventService.selectHsEventList(hsEvent);
        ExcelUtil<HsEvent> util = new ExcelUtil<HsEvent>(HsEvent.class);
        return util.exportExcel(list, "活动配置数据");
    }

    /**
     * 获取活动配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('eventConfig:event:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(hsEventService.getById(id));
    }

    /**
     * 新增活动配置
     */
    @PreAuthorize("@ss.hasPermi('eventConfig:event:add')")
    @Log(title = "活动配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsEvent hsEvent)
    {
        hsEvent.setCreateBy(SecurityUtils.getUsername());
        hsEvent.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsEventService.save(hsEvent));
    }

    /**
     * 修改活动配置
     */
    @PreAuthorize("@ss.hasPermi('eventConfig:event:edit')")
    @Log(title = "活动配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsEvent hsEvent)
    {
        hsEvent.setUpdateBy(SecurityUtils.getUsername());
        hsEvent.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsEventService.updateById(hsEvent));
    }

    /**
     * 删除活动配置
     */
    @PreAuthorize("@ss.hasPermi('eventConfig:event:remove')")
    @Log(title = "活动配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(hsEventService.removeByIds(Arrays.asList(ids)));
    }
}
