package com.ruoyi.web.controller.nanjing;

import java.util.List;

import com.ruoyi.common.core.text.Convert;
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.TBdProducttype;
import com.ruoyi.nanjing.service.ITBdProducttypeService;
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-22
 */
@Controller
@RequestMapping("/nanjing/ProductType")
public class TBdProducttypeController extends BaseController
{
    private String prefix = "nanjing/ProductType";

    @Autowired
    private ITBdProducttypeService tBdProducttypeService;

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

    /**
     * 查询机种类型列表
     */
    @RequiresPermissions("nanjing:ProductType:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TBdProducttype tBdProducttype)
    {
        startPage();
        List<TBdProducttype> list = tBdProducttypeService.selectTBdProducttypeList(tBdProducttype);
        return getDataTable(list);
    }

    /**
     * 导出机种类型列表
     */
    @RequiresPermissions("nanjing:ProductType:export")
    @Log(title = "机种类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TBdProducttype tBdProducttype)
    {
        List<TBdProducttype> list = tBdProducttypeService.selectTBdProducttypeList(tBdProducttype);
        ExcelUtil<TBdProducttype> util = new ExcelUtil<TBdProducttype>(TBdProducttype.class);
        return util.exportExcel(list, "ProductType");
    }

    /**
     * 新增机种类型
     */
    @GetMapping("/add")
    public String add(ModelMap map)
    {
        List<TBdProducttype> list = tBdProducttypeService.selectTBdProducttype();
        int max = Convert.toInt(list.get(0).getProductTypeID());
        String oper = max + 1+"";
        list.get(0).setProductTypeID(oper);
        map.addAttribute("pt",list);
        return prefix + "/add";
    }

    /**
     * 新增保存机种类型
     */
    @RequiresPermissions("nanjing:ProductType:add")
    @Log(title = "机种类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TBdProducttype tBdProducttype)
    {
        return toAjax(tBdProducttypeService.insertTBdProducttype(tBdProducttype));
    }

    /**
     * 修改机种类型
     */
    @GetMapping("/edit/{ID}")
    public String edit(@PathVariable("ID") Long ID, ModelMap mmap)
    {
        TBdProducttype tBdProducttype = tBdProducttypeService.selectTBdProducttypeById(ID);
        mmap.put("tBdProducttype", tBdProducttype);
        return prefix + "/edit";
    }

    /**
     * 修改保存机种类型
     */
    @RequiresPermissions("nanjing:ProductType:edit")
    @Log(title = "机种类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TBdProducttype tBdProducttype)
    {
        return toAjax(tBdProducttypeService.updateTBdProducttype(tBdProducttype));
    }

    /**
     * 删除机种类型
     */
    @RequiresPermissions("nanjing:ProductType:remove")
    @Log(title = "机种类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tBdProducttypeService.deleteTBdProducttypeByIds(ids));
    }
}
