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.poi.ExcelUtil;
import com.willalp.event.domain.HsEventBusinessRelation;
import com.willalp.event.service.IHsEventBusinessRelationService;
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/relation")
public class HsEventBusinessRelationController extends BaseController {
    @Resource
    private IHsEventBusinessRelationService hsEventBusinessRelationService;

    /**
     * 查询事件相关业务关系列表
     */
    @PreAuthorize("@ss.hasPermi('eventConfig:relation:list')")
    @PostMapping("/submit/binding")
    public AjaxResult submitBinding(@RequestBody HsEventBusinessRelation hsEventBusinessRelation) {
        return toAjax(hsEventBusinessRelationService.doBindingRelation(hsEventBusinessRelation));
    }

    /**
     * 查询事件相关业务关系列表
     */
    @PreAuthorize("@ss.hasPermi('eventConfig:relation:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsEventBusinessRelation hsEventBusinessRelation) {
        startPage();
        List<HsEventBusinessRelation> list = hsEventBusinessRelationService.selectHsEventBusinessRelationList(hsEventBusinessRelation);
        return getDataTable(list);
    }

    /**
     * 导出事件相关业务关系列表
     */
    @PreAuthorize("@ss.hasPermi('eventConfig:relation:export')")
    @Log(title = "事件相关业务关系", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsEventBusinessRelation hsEventBusinessRelation) {
        List<HsEventBusinessRelation> list = hsEventBusinessRelationService.selectHsEventBusinessRelationList(hsEventBusinessRelation);
        ExcelUtil<HsEventBusinessRelation> util = new ExcelUtil<HsEventBusinessRelation>(HsEventBusinessRelation.class);
        return util.exportExcel(list, "事件相关业务关系数据");
    }

    /**
     * 获取事件相关业务关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('eventConfig:relation:query')")
    @GetMapping(value = "/{eventId}")
    public AjaxResult getInfo(@PathVariable("eventId") String eventId) {
        return AjaxResult.success(hsEventBusinessRelationService.getById(eventId));
    }

    /**
     * 新增事件相关业务关系
     */
    @PreAuthorize("@ss.hasPermi('eventConfig:relation:add')")
    @Log(title = "事件相关业务关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsEventBusinessRelation hsEventBusinessRelation) {
        return toAjax(hsEventBusinessRelationService.save(hsEventBusinessRelation));
    }

    /**
     * 修改事件相关业务关系
     */
    @PreAuthorize("@ss.hasPermi('eventConfig:relation:edit')")
    @Log(title = "事件相关业务关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsEventBusinessRelation hsEventBusinessRelation) {
        return toAjax(hsEventBusinessRelationService.updateById(hsEventBusinessRelation));
    }

    /**
     * 删除事件相关业务关系
     */
    @PreAuthorize("@ss.hasPermi('eventConfig:relation:remove')")
    @Log(title = "事件相关业务关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{eventIds}")
    public AjaxResult remove(@PathVariable String[] eventIds) {
        return toAjax(hsEventBusinessRelationService.removeByIds(Arrays.asList(eventIds)));
    }
}
