package com.ruoyi.web.controller.nanjing;

import java.util.List;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.nanjing.domain.TBdProducttype;
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.nanjing.domain.TBdProductinfo;
import com.ruoyi.nanjing.service.ITBdProductinfoService;
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 limy
 * @date 2021-01-25
 */
@Controller
@RequestMapping("/nanjing/ProductInfo")
public class TBdProductinfoController extends BaseController
{
    private String prefix = "nanjing/ProductInfo";

    @Autowired
    private ITBdProductinfoService tBdProductinfoService;

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

    /**
     * 查询产品信息列表
     */
    @RequiresPermissions("nanjing:ProductInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TBdProductinfo tBdProductinfo)
    {
        startPage();
        List<TBdProductinfo> list = tBdProductinfoService.selectTBdProductinfoList(tBdProductinfo);
        return getDataTable(list);
    }

    /**
     * 导出产品信息列表
     */
    @RequiresPermissions("nanjing:ProductInfo:export")
    @Log(title = "产品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TBdProductinfo tBdProductinfo)
    {
        List<TBdProductinfo> list = tBdProductinfoService.selectTBdProductinfoList(tBdProductinfo);
        ExcelUtil<TBdProductinfo> util = new ExcelUtil<TBdProductinfo>(TBdProductinfo.class);
        return util.exportExcel(list, "ProductInfo");
    }

    /**
     * 新增产品信息
     */
    @GetMapping("/add")
    public String add(ModelMap map)
    {
        List<TBdProductinfo> list = tBdProductinfoService.selectTBdProductinfo();
        int max = Convert.toInt(list.get(0).getProductID());
        list.get(0).setProductID(max+1L);
        map.addAttribute("pt",list);
        return prefix + "/add";
    }

    /**
     * 新增保存产品信息
     */
    @RequiresPermissions("nanjing:ProductInfo:add")
    @Log(title = "产品信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TBdProductinfo tBdProductinfo)
    {
        return toAjax(tBdProductinfoService.insertTBdProductinfo(tBdProductinfo));
    }

    /**
     * 修改产品信息
     */
    @GetMapping("/edit/{ID}")
    public String edit(@PathVariable("ID") Long ID, ModelMap mmap)
    {
        TBdProductinfo tBdProductinfo = tBdProductinfoService.selectTBdProductinfoById(ID);
        mmap.put("tBdProductinfo", tBdProductinfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存产品信息
     */
    @RequiresPermissions("nanjing:ProductInfo:edit")
    @Log(title = "产品信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TBdProductinfo tBdProductinfo)
    {
        return toAjax(tBdProductinfoService.updateTBdProductinfo(tBdProductinfo));
    }

    /**
     * 删除产品信息
     */
    @RequiresPermissions("nanjing:ProductInfo:remove")
    @Log(title = "产品信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tBdProductinfoService.deleteTBdProductinfoByIds(ids));
    }
}
