package com.ruoyi.web.controller.baseinfo;

import java.util.List;

import com.ruoyi.baseinfo.domain.BaseGroupInfo;
import com.ruoyi.baseinfo.domain.BaseMaterialInfo;
import com.ruoyi.baseinfo.domain.BasePlanInfo;
import com.ruoyi.baseinfo.service.IBaseGroupInfoService;
import com.ruoyi.baseinfo.service.IBaseMaterialInfoService;
import com.ruoyi.baseinfo.service.IBasePlanInfoService;
import com.ruoyi.framework.util.ShiroUtils;
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.baseinfo.domain.BasePlandetailInfo;
import com.ruoyi.baseinfo.service.IBasePlandetailInfoService;
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 CaesarBao
 * @date 2020-10-23
 */
@Controller
@RequestMapping("/baseinfo/plandetailinfo")
public class BasePlandetailInfoController extends BaseController
{
    private String prefix = "baseinfo/plandetailinfo";

    @Autowired
    private IBasePlandetailInfoService basePlandetailInfoService;
    @Autowired
    private IBasePlanInfoService basePlanInfoService;
    @Autowired
    private IBaseMaterialInfoService baseMaterialInfoService;
    @Autowired
    private IBaseGroupInfoService baseGroupInfoService;

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

    /**
     * 查询计划明细列表
     */
    @RequiresPermissions("baseinfo:plandetailinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasePlandetailInfo basePlandetailInfo)
    {
        startPage();
        List<BasePlandetailInfo> list = basePlandetailInfoService.selectBasePlandetailInfoList(basePlandetailInfo);
        return getDataTable(list);
    }

    /**
     * 导出计划明细列表
     */
    @RequiresPermissions("baseinfo:plandetailinfo:export")
    @Log(title = "计划明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasePlandetailInfo basePlandetailInfo)
    {
        List<BasePlandetailInfo> list = basePlandetailInfoService.selectBasePlandetailInfoList(basePlandetailInfo);
        ExcelUtil<BasePlandetailInfo> util = new ExcelUtil<BasePlandetailInfo>(BasePlandetailInfo.class);
        return util.exportExcel(list, "plandetailinfo");
    }

    /**
     * 新增计划明细
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存计划明细
     */
    @RequiresPermissions("baseinfo:plandetailinfo:add")
    @Log(title = "计划明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasePlandetailInfo basePlandetailInfo)
    {
        basePlandetailInfo.setCreateBy(ShiroUtils.getLoginName());
        return toAjax(basePlandetailInfoService.insertBasePlandetailInfo(basePlandetailInfo));
    }

    /**
     * 修改计划明细
     */
    @GetMapping("/edit/{objid}")
    public String edit(@PathVariable("objid") Long objid, ModelMap mmap)
    {
        BasePlandetailInfo basePlandetailInfo = basePlandetailInfoService.selectBasePlandetailInfoById(objid);
        mmap.put("basePlandetailInfo", basePlandetailInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存计划明细
     */
    @RequiresPermissions("baseinfo:plandetailinfo:edit")
    @Log(title = "计划明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasePlandetailInfo basePlandetailInfo)
    {
        return toAjax(basePlandetailInfoService.updateBasePlandetailInfo(basePlandetailInfo));
    }

    /**
     * 删除计划明细
     */
    @RequiresPermissions("baseinfo:plandetailinfo:remove")
    @Log(title = "计划明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basePlandetailInfoService.deleteBasePlandetailInfoByIds(ids));
    }

    /**
     * 修改计划信息
     */
    @GetMapping("/plandetail/{planid}")
    public String planedit(@PathVariable("planid") String planid, ModelMap mmap)
    {
//        BasePlanInfo basePlanInfo = basePlanInfoService.selectBasePlanInfoById(planid);
//        mmap.put("basePlanInfo", basePlanInfo);
        BaseMaterialInfo baseMaterialInfo = new BaseMaterialInfo();
        BaseGroupInfo baseGroupInfo = new BaseGroupInfo();
        mmap.put("cbmaterialInfo",baseMaterialInfoService.selectBaseMaterialInfoList(baseMaterialInfo));
        mmap.put("cbGroupInfo",baseGroupInfoService.selectBaseGroupInfoList(baseGroupInfo));

        mmap.put("planid", planid);
        return prefix + "/add";
    }
}
