package com.ghy.web.controller.goods;
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.*;
import com.ghy.common.annotation.Log;
import com.ghy.common.enums.BusinessType;
import com.ghy.goods.domain.InsuranceManager;
import com.ghy.goods.service.IInsuranceManagerService;
import com.ghy.common.core.controller.BaseController;
import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.utils.poi.ExcelUtil;
import com.ghy.common.core.page.TableDataInfo;

/**
 * 保险管理Controller
 *
 * @author clunt
 * @date 2024-09-25
 */
@Controller
@RequestMapping("/goods/manager")
public class InsuranceManagerController extends BaseController
{
    private String prefix = "goods/manager";

    @Autowired
    private IInsuranceManagerService insuranceManagerService;

    @RequiresPermissions("goods:manager:view")
    @GetMapping()
    public String manager()
    {
        return prefix + "/manager";
    }

    /**
     * 查询保险管理列表
     */
    @RequiresPermissions("goods:manager:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(InsuranceManager insuranceManager)
    {
        startPage();
        List<InsuranceManager> list = insuranceManagerService.selectInsuranceManagerList(insuranceManager);
        return getDataTable(list);
    }

    /**
     * App查询保险管理列表
     */
    @PostMapping("/app/list")
    @ResponseBody
    public TableDataInfo appList(@RequestBody InsuranceManager insuranceManager)
    {
        startPage();
        List<InsuranceManager> list = insuranceManagerService.selectInsuranceManagerList(insuranceManager);
        return getDataTable(list);
    }


    /**
     * 导出保险管理列表
     */
    @RequiresPermissions("goods:manager:export")
    @Log(title = "保险管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(InsuranceManager insuranceManager)
    {
        List<InsuranceManager> list = insuranceManagerService.selectInsuranceManagerList(insuranceManager);
        ExcelUtil<InsuranceManager> util = new ExcelUtil<InsuranceManager>(InsuranceManager.class);
        return util.exportExcel(list, "保险管理数据");
    }

    /**
     * 新增保险管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存保险管理
     */
    @RequiresPermissions("goods:manager:add")
    @Log(title = "保险管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(InsuranceManager insuranceManager)
    {
        return toAjax(insuranceManagerService.insertInsuranceManager(insuranceManager));
    }

    /**
     * 修改保险管理
     */
    @RequiresPermissions("goods:manager:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        InsuranceManager insuranceManager = insuranceManagerService.selectInsuranceManagerById(id);
        mmap.put("insuranceManager", insuranceManager);
        return prefix + "/edit";
    }

    /**
     * 修改保存保险管理
     */
    @RequiresPermissions("goods:manager:edit")
    @Log(title = "保险管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(InsuranceManager insuranceManager)
    {
        return toAjax(insuranceManagerService.updateInsuranceManager(insuranceManager));
    }

    /**
     * 删除保险管理
     */
    @RequiresPermissions("goods:manager:remove")
    @Log(title = "保险管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(insuranceManagerService.deleteInsuranceManagerByIds(ids));
    }
}
