package com.sooka.system.medicine.plant.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.industry.domain.TGuijiMedicineIndustry;
import com.sooka.system.medicine.plant.domain.TGuijiMedicinePlant;
import com.sooka.system.medicine.plant.service.ITGuijiMedicinePlantService;
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/plant")
public class TGuijiMedicinePlantController extends BaseController
{
    private String prefix = "system/medicine/plant";

    @Autowired
    private ITGuijiMedicinePlantService tGuijiMedicinePlantService;

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

    /**
     * 查询种植采集数列表
     */
    @RequiresPermissions("system:plant:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TGuijiMedicinePlant tGuijiMedicinePlant)
    {
        startPage();
        List<TGuijiMedicinePlant> list = tGuijiMedicinePlantService.selectTGuijiMedicinePlantList(tGuijiMedicinePlant);
        return getDataTable(list);
    }

    /**
     * 导出种植采集数列表
     */
    @RequiresPermissions("system:plant:export")
    @Log(title = "种植采集数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TGuijiMedicinePlant tGuijiMedicinePlant)
    {
        List<TGuijiMedicinePlant> list = tGuijiMedicinePlantService.selectTGuijiMedicinePlantList(tGuijiMedicinePlant);
        ExcelUtil<TGuijiMedicinePlant> util = new ExcelUtil<TGuijiMedicinePlant>(TGuijiMedicinePlant.class);
        return util.exportExcel(list, "plant");
    }

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

    /**
     * 新增保存种植采集数
     */
    @RequiresPermissions("system:plant:add")
    @Log(title = "种植采集数", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TGuijiMedicinePlant tGuijiMedicinePlant)
    {
        return toAjax(tGuijiMedicinePlantService.insertTGuijiMedicinePlant(tGuijiMedicinePlant));
    }

    /**
     * 修改种植采集数
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        TGuijiMedicinePlant tGuijiMedicinePlant = tGuijiMedicinePlantService.selectTGuijiMedicinePlantById(id);
        mmap.put("tGuijiMedicinePlant", tGuijiMedicinePlant);
        return prefix + "/edit";
    }

    /**
     * 修改保存种植采集数
     */
    @RequiresPermissions("system:plant:edit")
    @Log(title = "种植采集数", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TGuijiMedicinePlant tGuijiMedicinePlant)
    {
        return toAjax(tGuijiMedicinePlantService.updateTGuijiMedicinePlant(tGuijiMedicinePlant));
    }

    /**
     * 删除种植采集数
     */
    @RequiresPermissions("system:plant:remove")
    @Log(title = "种植采集数", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tGuijiMedicinePlantService.deleteTGuijiMedicinePlantByIds(ids));
    }
    /**
     * 种植采集数详情
     */
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") String id, ModelMap mmap)
    {
        TGuijiMedicinePlant tGuijiMedicinePlant = tGuijiMedicinePlantService.selectTGuijiMedicinePlantById(id);
        mmap.put("tGuijiMedicinePlant", tGuijiMedicinePlant);
        return prefix + "/detail";
    }
}
