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.HsActivityAppoint;
import com.willalp.event.service.IHsActivityAppointService;
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/appoint")
public class HsActivityAppointController extends BaseController
{
    @Resource
    private IHsActivityAppointService hsActivityAppointService;

    /**
     * 查询活动预约列列表
     */
    @PreAuthorize("@ss.hasPermi('event:appoint:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsActivityAppoint hsActivityAppoint)
    {
        startPage();
        List<HsActivityAppoint> list = hsActivityAppointService.selectHsActivityAppointList(hsActivityAppoint);
        return getDataTable(list);
    }

    /**
     * 导出活动预约列列表
     */
    @PreAuthorize("@ss.hasPermi('event:appoint:export')")
    @Log(title = "活动预约列", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsActivityAppoint hsActivityAppoint)
    {
        List<HsActivityAppoint> list = hsActivityAppointService.selectHsActivityAppointList(hsActivityAppoint);
        ExcelUtil<HsActivityAppoint> util = new ExcelUtil<HsActivityAppoint>(HsActivityAppoint.class);
        return util.exportExcel(list, "活动预约列数据");
    }

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

    /**
     * 新增活动预约列
     */
    @PreAuthorize("@ss.hasPermi('event:appoint:add')")
    @Log(title = "活动预约列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsActivityAppoint hsActivityAppoint)
    {
        hsActivityAppoint.setCreateBy(SecurityUtils.getUsername());
        hsActivityAppoint.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsActivityAppointService.save(hsActivityAppoint));
    }

    /**
     * 修改活动预约列
     */
    @PreAuthorize("@ss.hasPermi('event:appoint:edit')")
    @Log(title = "活动预约列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsActivityAppoint hsActivityAppoint)
    {
        hsActivityAppoint.setUpdateBy(SecurityUtils.getUsername());
        hsActivityAppoint.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsActivityAppointService.updateById(hsActivityAppoint));
    }

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