package com.ruoyi.web.controller.baseinfo;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.ruoyi.baseinfo.domain.BaseDeviceInfo;
import com.ruoyi.baseinfo.domain.BaseGroupInfo;
import com.ruoyi.baseinfo.domain.BaseShiftInfo;
import com.ruoyi.baseinfo.service.IBaseDeviceInfoService;
import com.ruoyi.baseinfo.service.IBaseGroupInfoService;
import com.ruoyi.baseinfo.service.IBaseShiftInfoService;
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.BaseShiftmasterInfo;
import com.ruoyi.baseinfo.service.IBaseShiftmasterInfoService;
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-28
 */
@Controller
@RequestMapping("/baseinfo/shiftmasterinfo")
public class BaseShiftmasterInfoController extends BaseController
{
    private String prefix = "baseinfo/shiftmasterinfo";

    @Autowired
    private IBaseShiftmasterInfoService baseShiftmasterInfoService;
    @Autowired
    private IBaseDeviceInfoService baseDeviceInfoService;
    @Autowired
    private IBaseShiftInfoService baseShiftInfoService;
    @Autowired
    private IBaseGroupInfoService baseGroupInfoService;

    @RequiresPermissions("baseinfo:shiftmasterinfo:view")
    @GetMapping()
    public String shiftmasterinfo(ModelMap mmap)
    {
        BaseDeviceInfo baseDeviceInfo = new BaseDeviceInfo();
        BaseShiftInfo baseShiftInfo = new BaseShiftInfo();
        BaseGroupInfo baseGroupInfo = new BaseGroupInfo();
        mmap.put("cbdeviceInfo",baseDeviceInfoService.selectBaseDeviceInfoList(baseDeviceInfo));
        mmap.put("cbshitfInfo",baseShiftInfoService.selectBaseShiftInfoList(baseShiftInfo));
        mmap.put("cbgroupInfo",baseGroupInfoService.selectBaseGroupInfoList(baseGroupInfo));
        return prefix + "/shiftmasterinfo";
    }

    /**
     * 查询交接班基础信息列表
     */
    @RequiresPermissions("baseinfo:shiftmasterinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaseShiftmasterInfo baseShiftmasterInfo)
    {
        startPage();
        List<BaseShiftmasterInfo> list = baseShiftmasterInfoService.selectBaseShiftmasterInfoList(baseShiftmasterInfo);
        return getDataTable(list);
    }

    /**
     * 导出交接班基础信息列表
     */
    @RequiresPermissions("baseinfo:shiftmasterinfo:export")
    @Log(title = "交接班基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BaseShiftmasterInfo baseShiftmasterInfo)
    {
        List<BaseShiftmasterInfo> list = baseShiftmasterInfoService.selectBaseShiftmasterInfoList(baseShiftmasterInfo);
        ExcelUtil<BaseShiftmasterInfo> util = new ExcelUtil<BaseShiftmasterInfo>(BaseShiftmasterInfo.class);
        return util.exportExcel(list, "shiftmasterinfo");
    }

    /**
     * 新增交接班基础信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存交接班基础信息
     */
    @RequiresPermissions("baseinfo:shiftmasterinfo:add")
    @Log(title = "交接班基础信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaseShiftmasterInfo baseShiftmasterInfo)
    {
        String code = new SimpleDateFormat("yyMMddHHmmss").format(new Date());
        baseShiftmasterInfo.setShiftNo(code);
        return toAjax(baseShiftmasterInfoService.insertBaseShiftmasterInfo(baseShiftmasterInfo));
    }

    /**
     * 修改交接班基础信息
     */
    @GetMapping("/edit/{shiftNo}")
    public String edit(@PathVariable("shiftNo") String shiftNo, ModelMap mmap)
    {
        BaseShiftmasterInfo baseShiftmasterInfo = baseShiftmasterInfoService.selectBaseShiftmasterInfoById(shiftNo);
        mmap.put("baseShiftmasterInfo", baseShiftmasterInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存交接班基础信息
     */
    @RequiresPermissions("baseinfo:shiftmasterinfo:edit")
    @Log(title = "交接班基础信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaseShiftmasterInfo baseShiftmasterInfo)
    {
        return toAjax(baseShiftmasterInfoService.updateBaseShiftmasterInfo(baseShiftmasterInfo));
    }

    /**
     * 删除交接班基础信息
     */
    @RequiresPermissions("baseinfo:shiftmasterinfo:remove")
    @Log(title = "交接班基础信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(baseShiftmasterInfoService.deleteBaseShiftmasterInfoByIds(ids));
    }
}
