package com.sooka.system.medicine.project.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.platform.domain.TGuijiMedicinePlatform;
import com.sooka.system.medicine.project.domain.TGuijiMedicineProject;
import com.sooka.system.medicine.project.service.ITGuijiMedicineProjectService;
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/project")
public class TGuijiMedicineProjectController extends BaseController
{
    private String prefix = "system/medicine/project";

    @Autowired
    private ITGuijiMedicineProjectService tGuijiMedicineProjectService;

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

    /**
     * 查询项目采集列表
     */
    @RequiresPermissions("system:project:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TGuijiMedicineProject tGuijiMedicineProject)
    {
        startPage();
        List<TGuijiMedicineProject> list = tGuijiMedicineProjectService.selectTGuijiMedicineProjectList(tGuijiMedicineProject);
        return getDataTable(list);
    }

    /**
     * 导出项目采集列表
     */
    @RequiresPermissions("system:project:export")
    @Log(title = "项目采集", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TGuijiMedicineProject tGuijiMedicineProject)
    {
        List<TGuijiMedicineProject> list = tGuijiMedicineProjectService.selectTGuijiMedicineProjectList(tGuijiMedicineProject);
        ExcelUtil<TGuijiMedicineProject> util = new ExcelUtil<TGuijiMedicineProject>(TGuijiMedicineProject.class);
        return util.exportExcel(list, "project");
    }

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

    /**
     * 新增保存项目采集
     */
    @RequiresPermissions("system:project:add")
    @Log(title = "项目采集", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TGuijiMedicineProject tGuijiMedicineProject)
    {
        return toAjax(tGuijiMedicineProjectService.insertTGuijiMedicineProject(tGuijiMedicineProject));
    }

    /**
     * 修改项目采集
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        TGuijiMedicineProject tGuijiMedicineProject = tGuijiMedicineProjectService.selectTGuijiMedicineProjectById(id);
        mmap.put("tGuijiMedicineProject", tGuijiMedicineProject);
        return prefix + "/edit";
    }

    /**
     * 修改保存项目采集
     */
    @RequiresPermissions("system:project:edit")
    @Log(title = "项目采集", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TGuijiMedicineProject tGuijiMedicineProject)
    {
        return toAjax(tGuijiMedicineProjectService.updateTGuijiMedicineProject(tGuijiMedicineProject));
    }

    /**
     * 删除项目采集
     */
    @RequiresPermissions("system:project:remove")
    @Log(title = "项目采集", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tGuijiMedicineProjectService.deleteTGuijiMedicineProjectByIds(ids));
    }

    /**
     * 平台项目采集
     */
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") String id, ModelMap mmap)
    {
        TGuijiMedicineProject tGuijiMedicineProject = tGuijiMedicineProjectService.selectTGuijiMedicineProjectById(id);
        mmap.put("tGuijiMedicineProject", tGuijiMedicineProject);
        return prefix + "/detail";
    }
}
