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.MesBaseRoute;
import com.hw.mes.service.IMesBaseRouteService;
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-25
 */
@RestController
@RequestMapping("/baseRoute")
public class MesBaseRouteController extends BaseController
{
    @Autowired
    private IMesBaseRouteService mesBaseRouteService;

    /**
     * 查询工艺路线列表
     */
    @RequiresPermissions("mes:baseRoute:list")
    @GetMapping("/list")
    public TableDataInfo list(MesBaseRoute mesBaseRoute)
    {
        startPage();
        List<MesBaseRoute> list = mesBaseRouteService.selectMesBaseRouteList(mesBaseRoute);
        return getDataTable(list);
    }

    /**
     * 查询工艺路线下拉框列表
     */
    @GetMapping("/findRouteList")
    public AjaxResult findRouteList(MesBaseRoute mesBaseRoute)
    {
        List<MesBaseRoute> list = mesBaseRouteService.selectMesBaseRouteList(mesBaseRoute);
        return success(list);
    }

    /**
     * 导出工艺路线列表
     */
    @RequiresPermissions("mes:baseRoute:export")
    @Log(title = "工艺路线", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesBaseRoute mesBaseRoute)
    {
        List<MesBaseRoute> list = mesBaseRouteService.selectMesBaseRouteList(mesBaseRoute);
        ExcelUtil<MesBaseRoute> util = new ExcelUtil<MesBaseRoute>(MesBaseRoute.class);
        util.exportExcel(response, list, "工艺路线数据");
    }

    /**
     * 获取工艺路线详细信息
     */
    @RequiresPermissions("mes:baseRoute:query")
    @GetMapping(value = "/{routeId}")
    public AjaxResult getInfo(@PathVariable("routeId") Long routeId)
    {
        return success(mesBaseRouteService.selectMesBaseRouteByRouteId(routeId));
    }

    /**
     * 新增工艺路线
     */
    @RequiresPermissions("mes:baseRoute:add")
    @Log(title = "工艺路线", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesBaseRoute mesBaseRoute)
    {
        mesBaseRoute.setCreateBy(SecurityUtils.getLoginUser().getUsername());
        return toAjax(mesBaseRouteService.insertMesBaseRoute(mesBaseRoute));
    }

    /**
     * 修改工艺路线
     */
    @RequiresPermissions("mes:baseRoute:edit")
    @Log(title = "工艺路线", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesBaseRoute mesBaseRoute)
    {
        mesBaseRoute.setUpdateBy(SecurityUtils.getLoginUser().getUsername());
        return toAjax(mesBaseRouteService.updateMesBaseRoute(mesBaseRoute));
    }

    /**
     * 删除工艺路线
     */
    @RequiresPermissions("mes:baseRoute:remove")
    @Log(title = "工艺路线", businessType = BusinessType.DELETE)
	@DeleteMapping("/{routeIds}")
    public AjaxResult remove(@PathVariable Long[] routeIds)
    {
        return toAjax(mesBaseRouteService.deleteMesBaseRouteByRouteIds(routeIds));
    }

    /**
     * 根据工艺路线ID查询工位信息
     * @param routeId
     * @return
     */
    @GetMapping(value = "/getStationByRouteId/{routeId}")
    public AjaxResult getStationByRouteId(@PathVariable("routeId") Long routeId)
    {
        return success(mesBaseRouteService.getStationByRouteId(routeId));
    }
}
