package com.ruoyi.web.controller.business;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.TCusCustomer;
import com.ruoyi.business.service.ITCusCustomerService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 货主管理Controller
 *
 * @author wms
 * @date 2022-06-24
 */
@Controller
@RequestMapping("/business/owner")
public class TOwnerController extends BaseController
{
    private String prefix = "business/owner";

    @Autowired
    private ITCusCustomerService tCusCustomerService;

    @RequiresPermissions("business:owner:view")
    @GetMapping()
    public String customer()
    {
        return prefix + "/ownerMain";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("business:owner:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TCusCustomer tCusCustomer)
    {
        startPage();
        List<TCusCustomer> list = tCusCustomerService.selectTCusCustomerList(tCusCustomer);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("business:owner:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TCusCustomer tCusCustomer)
    {
        List<TCusCustomer> list = tCusCustomerService.selectTCusCustomerList(tCusCustomer);
        ExcelUtil<TCusCustomer> util = new ExcelUtil<TCusCustomer>(TCusCustomer.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("business:owner:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TCusCustomer tCusCustomer)
    {
        return toAjax(tCusCustomerService.insertTCusCustomer(tCusCustomer));
    }

    /**
     * 修改【请填写功能名称】
     */
    @RequiresPermissions("business:owner:edit")
    @GetMapping("/edit/{customerId}")
    public String edit(@PathVariable("customerId") String customerId, ModelMap mmap)
    {
        TCusCustomer tCusCustomer = tCusCustomerService.selectTCusCustomerByCustomerId(customerId);
        mmap.put("tCusCustomer", tCusCustomer);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("business:owner:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TCusCustomer tCusCustomer)
    {
        return toAjax(tCusCustomerService.updateTCusCustomer(tCusCustomer));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("business:owner:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tCusCustomerService.deleteTCusCustomerByCustomerIds(ids));
    }

    /**
     * 弹框表格
     */
    @GetMapping("/modalPage")
    public String table()
    {
        return prefix + "/customerModal";
    }
}
