package com.ruoyi.project.business.controller;

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

import com.ruoyi.common.utils.SpecialCharacterEscaper;
import com.ruoyi.project.business.domain.TbAgent;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.domain.TbAgentHistory;
import com.ruoyi.project.business.service.ITbAgentHistoryService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 代理商档案Controller
 * 
 * @author ruoyi
 * @date 2024-07-31
 */
@RestController
@RequestMapping("/system/history")
public class TbAgentHistoryController extends BaseController
{
    @Autowired
    private ITbAgentHistoryService tbAgentHistoryService;

    /**
     * 查询代理商档案列表
     */
    // @PreAuthorize("@ss.hasPermi('system:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbAgentHistory tbAgentHistory)
    {
        SpecialCharacterEscaper.escapeSpecialCharacters(tbAgentHistory,TbAgentHistory::getId, TbAgentHistory::getAgentNo, TbAgentHistory::getAgentName, TbAgentHistory::getParentAgentName, TbAgentHistory::getParentSalerName, TbAgentHistory::getPhone,TbAgentHistory::getCity);
        startPage();
        List<TbAgentHistory> list = tbAgentHistoryService.selectTbAgentHistoryList(tbAgentHistory);
        return getDataTable(list);
    }

    /**
     * 导出代理商档案列表
     */
    // @PreAuthorize("@ss.hasPermi('system:history:export')")
    @Log(title = "代理商档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbAgentHistory tbAgentHistory)
    {
        List<TbAgentHistory> list = tbAgentHistoryService.selectTbAgentHistoryList(tbAgentHistory);
        ExcelUtil<TbAgentHistory> util = new ExcelUtil<TbAgentHistory>(TbAgentHistory.class);
        util.exportExcel(response, list, "代理商档案数据");
    }

    /**
     * 获取代理商档案详细信息
     */
    // @PreAuthorize("@ss.hasPermi('system:history:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbAgentHistoryService.selectTbAgentHistoryById(id));
    }

    /**
     * 新增代理商档案
     */
    // @PreAuthorize("@ss.hasPermi('system:history:add')")
    @Log(title = "代理商档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbAgentHistory tbAgentHistory)
    {
        return toAjax(tbAgentHistoryService.insertTbAgentHistory(tbAgentHistory));
    }

    /**
     * 修改代理商档案
     */
    // @PreAuthorize("@ss.hasPermi('system:history:edit')")
    @Log(title = "代理商档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbAgentHistory tbAgentHistory)
    {
        return toAjax(tbAgentHistoryService.updateTbAgentHistory(tbAgentHistory));
    }

    /**
     * 删除代理商档案
     */
    // @PreAuthorize("@ss.hasPermi('system:history:remove')")
    @Log(title = "代理商档案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbAgentHistoryService.deleteTbAgentHistoryByIds(ids));
    }
}
