package com.xunmei.system.controller;

import com.xunmei.common.core.web.controller.BaseController;
import com.xunmei.common.core.web.domain.AjaxResult;
import com.xunmei.common.core.web.page.TableDataInfo;
import com.xunmei.common.log.annotation.Log;
import com.xunmei.common.log.enums.BusinessType;
import com.xunmei.common.security.annotation.RequiresPermissions;
import com.xunmei.system.domain.SysWorkTimeSet;
import com.xunmei.system.service.ISysWorkTimeSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Calendar;

/**
 * 作息设置Controller
 *
 * @author xunmei
 * @date 2023-08-14
 */
@Api(tags = {"SysWorkTimeSet"})
@RestController
@RequestMapping("/work/timeSet")
public class SysWorkTimeSetController extends BaseController {
    @Autowired
    private ISysWorkTimeSetService sysWorkTimeSetService;

    /**
     * 查询作息设置列表
     */
    @ApiOperation(value = "查询SysWorkTimeSet列表")
    @RequiresPermissions("system:set:list")
    @GetMapping("/list")
    public TableDataInfo<SysWorkTimeSet> list(SysWorkTimeSet sysWorkTimeSet) {

        return sysWorkTimeSetService.selectPage(sysWorkTimeSet);
    }

    /**
     * 查询作息设置列表
     */
    @ApiOperation(value = "find查询SysWorkTimeSet列表")
    @RequiresPermissions("system:set:find")
    @GetMapping("/find")
    public AjaxResult find(SysWorkTimeSet sysWorkTimeSet) {

        return sysWorkTimeSetService.workTimePageList(sysWorkTimeSet);
    }

    /**
     * 查询作息设置列表
     */
    @ApiOperation(value = "findId")
    @RequiresPermissions("system:set:find")
    @GetMapping("/findId")
    public AjaxResult findId(SysWorkTimeSet sysWorkTimeSet) {
        SysWorkTimeSet workTimeSet;
        Long id = sysWorkTimeSet.getId();

        if (id == null || id.longValue() == 0) {
            workTimeSet = new SysWorkTimeSet();
            workTimeSet.setYear((long) Calendar.getInstance().get(Calendar.YEAR));
        } else {
            workTimeSet = sysWorkTimeSetService.selectSysWorkTimeSetById(id);
        }
        if (workTimeSet!=null) {
            workTimeSet.setMonthEnable(1L);
        }
        return success(workTimeSet);
    }


    /**
     * 获取作息设置详细信息
     */
    @ApiOperation(value = "获取SysWorkTimeSet详细信息")
    @RequiresPermissions("system:set:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysWorkTimeSetService.selectSysWorkTimeSetById(id));
    }

    /**
     * 新增作息设置
     */
    @ApiOperation(value = "add")
    @RequiresPermissions("system:set:add")
    @Log(title = "作息设置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysWorkTimeSet sysWorkTimeSet) {
        return success(sysWorkTimeSetService.add(sysWorkTimeSet));
    }

    /**
     * 修改作息设置
     */
    @ApiOperation(value = "修改SysWorkTimeSet")
    @RequiresPermissions("system:set:edit")
    @Log(title = "作息设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysWorkTimeSet sysWorkTimeSet) {
        return toAjax(sysWorkTimeSetService.updateSysWorkTimeSet(sysWorkTimeSet));
    }




    /**
     * 删除作息设置
     */
    @ApiOperation(value = "删除SysWorkTimeSet")
    @RequiresPermissions("system:set:remove")
    @Log(title = "作息设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysWorkTimeSetService.deleteSysWorkTimeSetByIds(ids));
    }
}
