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.group.domain.HsGroupConfig;
import com.willalp.group.service.IHsGroupConfigService;
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 2022-07-22
 */
@RestController
@RequestMapping("/clocking/groupconfig")
public class HsGroupConfigController extends BaseController {
    @Resource
    private IHsGroupConfigService hsGroupConfigService;

    /**
     * 查询群组配置列表
     */
    @PreAuthorize("@ss.hasPermi('clocking:groupconfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsGroupConfig hsGroupConfig) {
        startPage();
        List<HsGroupConfig> list = hsGroupConfigService.selectHsGroupConfigList(hsGroupConfig);
        return getDataTable(list);
    }

    /**
     * 查询群组配置列表
     */
    @PostMapping("/addUser")
    public AjaxResult addUser(@RequestBody HsGroupConfig hsGroupConfig) {
        return AjaxResult.success(hsGroupConfigService.groupAddUser(hsGroupConfig));
    }

    /**
     * 导出群组配置列表
     */
    @PreAuthorize("@ss.hasPermi('clocking:groupconfig:export')")
    @Log(title = "群组配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsGroupConfig hsGroupConfig) {
        List<HsGroupConfig> list = hsGroupConfigService.selectHsGroupConfigList(hsGroupConfig);
        ExcelUtil<HsGroupConfig> util = new ExcelUtil<HsGroupConfig>(HsGroupConfig.class);
        return util.exportExcel(list, "群组配置数据");
    }

    /**
     * 获取群组配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('clocking:groupconfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(hsGroupConfigService.getById(id));
    }

    /**
     * 新增群组配置
     */
    @PreAuthorize("@ss.hasPermi('clocking:groupconfig:add')")
    @Log(title = "群组配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsGroupConfig hsGroupConfig) {
        hsGroupConfig.setCreateBy(SecurityUtils.getUsername());
        hsGroupConfig.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsGroupConfigService.save(hsGroupConfig));
    }

    /**
     * 修改群组配置
     */
    @PreAuthorize("@ss.hasPermi('clocking:groupconfig:edit')")
    @Log(title = "群组配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsGroupConfig hsGroupConfig) {
        hsGroupConfig.setUpdateBy(SecurityUtils.getUsername());
        hsGroupConfig.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsGroupConfigService.updateById(hsGroupConfig));
    }

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