package com.ruoyi.hezhi.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.common.utils.poi.ExcelUtil;
import com.ruoyi.hezhi.domain.TbExpressKdCode;
import com.ruoyi.hezhi.service.ITbExpressKdCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 快递编码Controller
 *
 * @author ruoyi
 * @date 2024-11-20
 */
@RestController
@RequestMapping("/hezhi/expressKdCode")
public class TbExpressKdCodeController extends BaseController
{
    @Autowired
    private ITbExpressKdCodeService tbExpressKdCodeService;

    /**
     * 查询快递编码列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:expressKdCode:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbExpressKdCode tbExpressKdCode)
    {
        startPage();
        List<TbExpressKdCode> list = tbExpressKdCodeService.selectTbExpressKdCodeList(tbExpressKdCode);
        return getDataTable(list);
    }

    /**
     * 导出快递编码列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:expressKdCode:export')")
    @Log(title = "快递编码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbExpressKdCode tbExpressKdCode)
    {
        List<TbExpressKdCode> list = tbExpressKdCodeService.selectTbExpressKdCodeList(tbExpressKdCode);
        ExcelUtil<TbExpressKdCode> util = new ExcelUtil<TbExpressKdCode>(TbExpressKdCode.class);
        util.exportExcel(response, list, "快递编码数据");
    }

    /**
     * 获取快递编码详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:expressKdCode:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbExpressKdCodeService.selectTbExpressKdCodeById(id));
    }

    /**
     * 新增快递编码
     */
    @PreAuthorize("@ss.hasPermi('hezhi:expressKdCode:add')")
    @Log(title = "快递编码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbExpressKdCode tbExpressKdCode)
    {
        return toAjax(tbExpressKdCodeService.insertTbExpressKdCode(tbExpressKdCode));
    }

    /**
     * 修改快递编码
     */
    @PreAuthorize("@ss.hasPermi('hezhi:expressKdCode:edit')")
    @Log(title = "快递编码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbExpressKdCode tbExpressKdCode)
    {
        return toAjax(tbExpressKdCodeService.updateTbExpressKdCode(tbExpressKdCode));
    }

    /**
     * 删除快递编码
     */
    @PreAuthorize("@ss.hasPermi('hezhi:expressKdCode:remove')")
    @Log(title = "快递编码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbExpressKdCodeService.deleteTbExpressKdCodeByIds(ids));
    }
}
