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.HsProbationPeriodScore;
import com.willalp.vacation.service.IHsProbationPeriodScoreService;
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/score")
public class HsProbationPeriodScoreController extends BaseController
{
    @Resource
    private IHsProbationPeriodScoreService hsProbationPeriodScoreService;

    /**
     * 查询试用期考评列表
     */
    @PreAuthorize("@ss.hasPermi('clocking:score:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsProbationPeriodScore hsProbationPeriodScore)
    {
        startPage();
        List<HsProbationPeriodScore> list = hsProbationPeriodScoreService.selectHsProbationPeriodScoreList(hsProbationPeriodScore);
        return getDataTable(list);
    }

    /**
     * 导出试用期考评列表
     */
    @PreAuthorize("@ss.hasPermi('clocking:score:export')")
    @Log(title = "试用期考评", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsProbationPeriodScore hsProbationPeriodScore)
    {
        List<HsProbationPeriodScore> list = hsProbationPeriodScoreService.selectHsProbationPeriodScoreList(hsProbationPeriodScore);
        ExcelUtil<HsProbationPeriodScore> util = new ExcelUtil<HsProbationPeriodScore>(HsProbationPeriodScore.class);
        return util.exportExcel(list, "试用期考评数据");
    }

    /**
     * 获取试用期考评详细信息
     */
    @PreAuthorize("@ss.hasPermi('clocking:score:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(hsProbationPeriodScoreService.getById(id));
    }

    /**
     * 新增试用期考评
     */
    @PreAuthorize("@ss.hasPermi('clocking:score:add')")
    @Log(title = "试用期考评", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsProbationPeriodScore hsProbationPeriodScore)
    {
        hsProbationPeriodScore.setCreateBy(SecurityUtils.getUsername());
        hsProbationPeriodScore.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsProbationPeriodScoreService.save(hsProbationPeriodScore));
    }

    /**
     * 修改试用期考评
     */
    @PreAuthorize("@ss.hasPermi('clocking:score:edit')")
    @Log(title = "试用期考评", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsProbationPeriodScore hsProbationPeriodScore)
    {
        hsProbationPeriodScore.setUpdateBy(SecurityUtils.getUsername());
        hsProbationPeriodScore.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsProbationPeriodScoreService.updateById(hsProbationPeriodScore));
    }

    /**
     * 删除试用期考评
     */
    @PreAuthorize("@ss.hasPermi('clocking:score:remove')")
    @Log(title = "试用期考评", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(hsProbationPeriodScoreService.removeByIds(Arrays.asList(ids)));
    }
}
