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.FollowRecord;
import com.ruoyi.web.work.service.IFollowRecordService;
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-18
 */
@RestController
@RequestMapping("/work/record")
public class FollowRecordController extends BaseController {
    @Autowired
    private IFollowRecordService followRecordService;

    @PreAuthorize("@ss.hasPermi('work:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(FollowRecord followRecord){
        startPage();
        List<FollowRecord> list = followRecordService.selectList(followRecord);
        return getDataTable(list);
    }

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

    @PreAuthorize("@ss.hasPermi('work:record:add')")
    @Log(title = "回访记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FollowRecord followRecord){
        return toAjax(followRecordService.save(followRecord));
    }

    @PreAuthorize("@ss.hasPermi('work:record:edit')")
    @Log(title = "回访记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody FollowRecord followRecord){
        return toAjax(followRecordService.updateById(followRecord));
    }

    @PreAuthorize("@ss.hasPermi('work:record:remove')")
    @Log(title = "回访记录", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(followRecordService.removeByIds(Arrays.asList(ids)));
    }
}
