package com.ruoyi.web.work.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.work.domain.FollowTemplate;
import com.ruoyi.web.work.service.IFollowTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 回访模板管理
 *
 * @author lsw
 * @date 2024-07-11
 */
@RestController
@RequestMapping("/work/follow/template")
public class FollowTemplateController extends BaseController {
    @Autowired
    private IFollowTemplateService followTemplateService;

    @PreAuthorize("@ss.hasPermi('work:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(FollowTemplate followTemplate) {
        startPage();
        List<FollowTemplate> list = followTemplateService.selectList(followTemplate);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('work:template:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id) {
        return AjaxResult.success(followTemplateService.getById(id));
    }

    @PreAuthorize("@ss.hasPermi('work:template:add')")
    @Log(title = "回访模板管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FollowTemplate followTemplate) {
        return toAjax(followTemplateService.save(followTemplate));
    }

    @PreAuthorize("@ss.hasPermi('work:template:edit')")
    @Log(title = "回访模板管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody FollowTemplate followTemplate) {
        return toAjax(followTemplateService.updateById(followTemplate));
    }

    @PreAuthorize("@ss.hasPermi('work:template:remove')")
    @Log(title = "回访模板管理", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(followTemplateService.removeByIds(Arrays.asList(ids)));
    }
}
