package com.xinelu.manage.controller.phonedialrecord;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.phonedialrecord.PhoneDialRecord;
import com.xinelu.manage.service.phonedialrecord.IPhoneDialRecordService;
import com.xinelu.manage.vo.phonedialrecord.BillPhoneDialVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 电话拨打记录Controller
 *
 * @author zh
 * @date 2026-04-17
 */
@RestController
@RequestMapping("/system/phoneDialRecord")
public class PhoneDialRecordController extends BaseController {
    @Resource
    private IPhoneDialRecordService phoneDialRecordService;

    /**
     * 查询电话拨打记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:phoneDialRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(BillPhoneDialVo phoneDialRecord) {
        startPage();
        List<BillPhoneDialVo> list = phoneDialRecordService.selectPhoneDialRecordList(phoneDialRecord);
        return getDataTable(list);
    }

    /**
     * 导出电话拨打记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:phoneDialRecord:export')")
    @Log(title = "电话拨打记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BillPhoneDialVo phoneDialRecord) {
        List<BillPhoneDialVo> list = phoneDialRecordService.selectPhoneDialRecordList(phoneDialRecord);
        ExcelUtil<BillPhoneDialVo> util = new ExcelUtil<>(BillPhoneDialVo.class);
        util.exportExcel(response, list, "电话拨打记录数据");
    }

    /**
     * 获取电话拨打记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:phoneDialRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(phoneDialRecordService.selectPhoneDialRecordById(id));
    }

    /**
     * 新增电话拨打记录
     */
    @PreAuthorize("@ss.hasPermi('system:phoneDialRecord:add')")
    @Log(title = "电话拨打记录", businessType = BusinessType.INSERT)
    //@PostMapping
    public AjaxResult add(@RequestBody PhoneDialRecord phoneDialRecord) {
        return toAjax(phoneDialRecordService.insertPhoneDialRecord(phoneDialRecord));
    }

    /**
     * 修改电话拨打记录
     */
    @PreAuthorize("@ss.hasPermi('system:phoneDialRecord:edit')")
    @Log(title = "电话拨打记录", businessType = BusinessType.UPDATE)
    //@PutMapping
    public AjaxResult edit(@RequestBody PhoneDialRecord phoneDialRecord) {
        return toAjax(phoneDialRecordService.updatePhoneDialRecord(phoneDialRecord));
    }

    /**
     * 删除电话拨打记录
     */
    @PreAuthorize("@ss.hasPermi('system:phoneDialRecord:remove')")
    @Log(title = "电话拨打记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(phoneDialRecordService.deletePhoneDialRecordByIds(ids));
    }

    /**
     * 电话推送统计
     */
    @GetMapping("/phoneCount")
    public AjaxResult phoneCount() {
        return phoneDialRecordService.phoneCount();
    }
}