package com.hw.mes.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.hw.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hw.common.log.annotation.Log;
import com.hw.common.log.enums.BusinessType;
import com.hw.common.security.annotation.RequiresPermissions;
import com.hw.mes.domain.MesBaseFactoryInfo;
import com.hw.mes.service.IMesBaseFactoryInfoService;
import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.core.utils.poi.ExcelUtil;
import com.hw.common.core.web.page.TableDataInfo;

/**
 * 工厂信息Controller
 * 
 * @author Yinq
 * @date 2024-01-23
 */
@RestController
@RequestMapping("/baseFactoryInfo")
public class MesBaseFactoryInfoController extends BaseController
{
    @Autowired
    private IMesBaseFactoryInfoService mesBaseFactoryInfoService;

    /**
     * 查询工厂信息列表
     */
    @RequiresPermissions("mes:baseFactoryInfo:list")
    @GetMapping("/list")
    public TableDataInfo list(MesBaseFactoryInfo mesBaseFactoryInfo)
    {
        startPage();
        List<MesBaseFactoryInfo> list = mesBaseFactoryInfoService.selectMesBaseFactoryInfoList(mesBaseFactoryInfo);
        return getDataTable(list);
    }

    /**
     * 查询工厂信息下拉框列表
     */
    @GetMapping("/findFactoryList")
    public AjaxResult findFactoryList(MesBaseFactoryInfo mesBaseFactoryInfo)
    {
        List<MesBaseFactoryInfo> list = mesBaseFactoryInfoService.selectMesBaseFactoryInfoList(mesBaseFactoryInfo);
        return success(list);
    }

    /**
     * 导出工厂信息列表
     */
    @RequiresPermissions("mes:baseFactoryInfo:export")
    @Log(title = "工厂信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesBaseFactoryInfo mesBaseFactoryInfo)
    {
        List<MesBaseFactoryInfo> list = mesBaseFactoryInfoService.selectMesBaseFactoryInfoList(mesBaseFactoryInfo);
        ExcelUtil<MesBaseFactoryInfo> util = new ExcelUtil<MesBaseFactoryInfo>(MesBaseFactoryInfo.class);
        util.exportExcel(response, list, "工厂信息数据");
    }

    /**
     * 获取工厂信息详细信息
     */
    @RequiresPermissions("mes:baseFactoryInfo:query")
    @GetMapping(value = "/{factoryId}")
    public AjaxResult getInfo(@PathVariable("factoryId") Long factoryId)
    {
        return success(mesBaseFactoryInfoService.selectMesBaseFactoryInfoByFactoryId(factoryId));
    }

    /**
     * 新增工厂信息
     */
    @RequiresPermissions("mes:baseFactoryInfo:add")
    @Log(title = "工厂信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesBaseFactoryInfo mesBaseFactoryInfo)
    {
        mesBaseFactoryInfo.setCreateBy(SecurityUtils.getLoginUser().getUsername());
        return toAjax(mesBaseFactoryInfoService.insertMesBaseFactoryInfo(mesBaseFactoryInfo));
    }

    /**
     * 修改工厂信息
     */
    @RequiresPermissions("mes:baseFactoryInfo:edit")
    @Log(title = "工厂信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesBaseFactoryInfo mesBaseFactoryInfo)
    {
        mesBaseFactoryInfo.setUpdateBy(SecurityUtils.getLoginUser().getUsername());
        return toAjax(mesBaseFactoryInfoService.updateMesBaseFactoryInfo(mesBaseFactoryInfo));
    }

    /**
     * 删除工厂信息
     */
    @RequiresPermissions("mes:baseFactoryInfo:remove")
    @Log(title = "工厂信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{factoryIds}")
    public AjaxResult remove(@PathVariable Long[] factoryIds)
    {
        return toAjax(mesBaseFactoryInfoService.deleteMesBaseFactoryInfoByFactoryIds(factoryIds));
    }
}
