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.flow.domain.HsFlowCc;
import com.willalp.flow.service.IHsFlowCcService;
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-02-14
 */
@RestController
@RequestMapping("/flow/cc")
public class HsFlowCcController extends BaseController
{
    @Resource
    private IHsFlowCcService hsFlowCcService;

    /**
     * 查询流程单抄送记录列表
     */
    @PreAuthorize("@ss.hasPermi('flow:cc:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsFlowCc hsFlowCc)
    {
        startPage();
        List<HsFlowCc> list = hsFlowCcService.selectHsFlowCcList(hsFlowCc);
        return getDataTable(list);
    }

    /**
     * 导出流程单抄送记录列表
     */
    @PreAuthorize("@ss.hasPermi('flow:cc:export')")
    @Log(title = "流程单抄送记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsFlowCc hsFlowCc)
    {
        List<HsFlowCc> list = hsFlowCcService.selectHsFlowCcList(hsFlowCc);
        ExcelUtil<HsFlowCc> util = new ExcelUtil<HsFlowCc>(HsFlowCc.class);
        return util.exportExcel(list, "流程单抄送记录数据");
    }

    /**
     * 获取流程单抄送记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('flow:cc:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(hsFlowCcService.getById(id));
    }

    /**
     * 新增流程单抄送记录
     */
    @PreAuthorize("@ss.hasPermi('flow:cc:add')")
    @Log(title = "流程单抄送记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsFlowCc hsFlowCc)
    {
        hsFlowCc.setCreateBy(SecurityUtils.getUsername());
        hsFlowCc.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsFlowCcService.save(hsFlowCc));
    }

    /**
     * 修改流程单抄送记录
     */
    @PreAuthorize("@ss.hasPermi('flow:cc:edit')")
    @Log(title = "流程单抄送记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsFlowCc hsFlowCc)
    {
        hsFlowCc.setUpdateBy(SecurityUtils.getUsername());
        hsFlowCc.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsFlowCcService.updateById(hsFlowCc));
    }

    /**
     * 删除流程单抄送记录
     */
    @PreAuthorize("@ss.hasPermi('flow:cc:remove')")
    @Log(title = "流程单抄送记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(hsFlowCcService.removeByIds(Arrays.asList(ids)));
    }
}
