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.vacation.domain.HsChangeOfficialRecord;
import com.willalp.vacation.service.IHsChangeOfficialRecordService;
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-03-19
 */
@RestController
@RequestMapping("/clocking/changeOfficial")
public class HsChangeOfficialRecordController extends BaseController
{
    @Resource
    private IHsChangeOfficialRecordService hsChangeOfficialRecordService;

    /**
     * 查询转正记录列表
     */
    @PreAuthorize("@ss.hasPermi('clocking:changeOfficial:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsChangeOfficialRecord hsChangeOfficialRecord)
    {
        startPage();
        List<HsChangeOfficialRecord> list = hsChangeOfficialRecordService.selectHsChangeOfficialRecordList(hsChangeOfficialRecord);
        return getDataTable(list);
    }

    /**
     * 导出转正记录列表
     */
    @PreAuthorize("@ss.hasPermi('clocking:changeOfficial:export')")
    @Log(title = "转正记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsChangeOfficialRecord hsChangeOfficialRecord)
    {
        List<HsChangeOfficialRecord> list = hsChangeOfficialRecordService.selectHsChangeOfficialRecordList(hsChangeOfficialRecord);
        ExcelUtil<HsChangeOfficialRecord> util = new ExcelUtil<HsChangeOfficialRecord>(HsChangeOfficialRecord.class);
        return util.exportExcel(list, "转正记录数据");
    }

    /**
     * 获取转正记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('clocking:changeOfficial:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(hsChangeOfficialRecordService.getById(id));
    }

    /**
     * 新增转正记录
     */
    @PreAuthorize("@ss.hasPermi('clocking:changeOfficial:add')")
    @Log(title = "转正记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsChangeOfficialRecord hsChangeOfficialRecord)
    {
        hsChangeOfficialRecord.setCreateBy(SecurityUtils.getUsername());
        hsChangeOfficialRecord.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsChangeOfficialRecordService.save(hsChangeOfficialRecord));
    }

    /**
     * 修改转正记录
     */
    @PreAuthorize("@ss.hasPermi('clocking:changeOfficial:edit')")
    @Log(title = "转正记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsChangeOfficialRecord hsChangeOfficialRecord)
    {
        hsChangeOfficialRecord.setUpdateBy(SecurityUtils.getUsername());
        hsChangeOfficialRecord.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsChangeOfficialRecordService.updateById(hsChangeOfficialRecord));
    }

    /**
     * 删除转正记录
     */
    @PreAuthorize("@ss.hasPermi('clocking:changeOfficial:remove')")
    @Log(title = "转正记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(hsChangeOfficialRecordService.removeByIds(Arrays.asList(ids)));
    }
}
