package com.sooka.system.medicine.platform.controller;


import com.sooka.common.annotation.Log;
import com.sooka.common.core.controller.BaseController;
import com.sooka.common.core.domain.AjaxResult;
import com.sooka.common.core.page.TableDataInfo;
import com.sooka.common.enums.BusinessType;
import com.sooka.common.utils.poi.ExcelUtil;
import com.sooka.system.medicine.plant.domain.TGuijiMedicinePlant;
import com.sooka.system.medicine.platform.domain.TGuijiMedicinePlatform;
import com.sooka.system.medicine.platform.service.ITGuijiMedicinePlatformService;
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 java.util.List;

/**
 * 平台采集Controller
 *
 * @author lei
 * @date 2022-08-22
 */
@Controller
@RequestMapping("/system/medicine/platform")
public class TGuijiMedicinePlatformController extends BaseController
{
    private String prefix = "system/medicine/platform";

    @Autowired
    private ITGuijiMedicinePlatformService tGuijiMedicinePlatformService;

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

    /**
     * 查询平台采集列表
     */
    @RequiresPermissions("system:platform:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TGuijiMedicinePlatform tGuijiMedicinePlatform)
    {
        startPage();
        List<TGuijiMedicinePlatform> list = tGuijiMedicinePlatformService.selectTGuijiMedicinePlatformList(tGuijiMedicinePlatform);
        return getDataTable(list);
    }

    /**
     * 导出平台采集列表
     */
    @RequiresPermissions("system:platform:export")
    @Log(title = "平台采集", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TGuijiMedicinePlatform tGuijiMedicinePlatform)
    {
        List<TGuijiMedicinePlatform> list = tGuijiMedicinePlatformService.selectTGuijiMedicinePlatformList(tGuijiMedicinePlatform);
        ExcelUtil<TGuijiMedicinePlatform> util = new ExcelUtil<TGuijiMedicinePlatform>(TGuijiMedicinePlatform.class);
        return util.exportExcel(list, "platform");
    }

    /**
     * 新增平台采集
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存平台采集
     */
    @RequiresPermissions("system:platform:add")
    @Log(title = "平台采集", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TGuijiMedicinePlatform tGuijiMedicinePlatform)
    {
        return toAjax(tGuijiMedicinePlatformService.insertTGuijiMedicinePlatform(tGuijiMedicinePlatform));
    }

    /**
     * 修改平台采集
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        TGuijiMedicinePlatform tGuijiMedicinePlatform = tGuijiMedicinePlatformService.selectTGuijiMedicinePlatformById(id);
        mmap.put("tGuijiMedicinePlatform", tGuijiMedicinePlatform);
        return prefix + "/edit";
    }

    /**
     * 修改保存平台采集
     */
    @RequiresPermissions("system:platform:edit")
    @Log(title = "平台采集", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TGuijiMedicinePlatform tGuijiMedicinePlatform)
    {
        return toAjax(tGuijiMedicinePlatformService.updateTGuijiMedicinePlatform(tGuijiMedicinePlatform));
    }

    /**
     * 删除平台采集
     */
    @RequiresPermissions("system:platform:remove")
    @Log(title = "平台采集", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tGuijiMedicinePlatformService.deleteTGuijiMedicinePlatformByIds(ids));
    }

    /**
     * 平台采集详情
     */
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") String id, ModelMap mmap)
    {
        TGuijiMedicinePlatform tGuijiMedicinePlatform = tGuijiMedicinePlatformService.selectTGuijiMedicinePlatformById(id);
        mmap.put("tGuijiMedicinePlatform", tGuijiMedicinePlatform);
        return prefix + "/detail";
    }
}
