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.MesBaseProcessInfo;
import com.hw.mes.service.IMesBaseProcessInfoService;
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-24
 */
@RestController
@RequestMapping("/processInfo")
public class MesBaseProcessInfoController extends BaseController
{
    @Autowired
    private IMesBaseProcessInfoService mesBaseProcessInfoService;

    /**
     * 查询工序信息列表
     */
    @RequiresPermissions("mes:processInfo:list")
    @GetMapping("/list")
    public TableDataInfo list(MesBaseProcessInfo mesBaseProcessInfo)
    {
        startPage();
        List<MesBaseProcessInfo> list = mesBaseProcessInfoService.selectMesBaseProcessInfoList(mesBaseProcessInfo);
        return getDataTable(list);
    }

    /**
     * 查询工序下拉框列表
     */
    @GetMapping("/findProcessList")
    public AjaxResult findProcessList(MesBaseProcessInfo mesBaseProcessInfo)
    {
        List<MesBaseProcessInfo> list = mesBaseProcessInfoService.selectMesBaseProcessInfoList(mesBaseProcessInfo);
        return success(list);
    }

    /**
     * 导出工序信息列表
     */
    @RequiresPermissions("mes:processInfo:export")
    @Log(title = "工序信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesBaseProcessInfo mesBaseProcessInfo)
    {
        List<MesBaseProcessInfo> list = mesBaseProcessInfoService.selectMesBaseProcessInfoList(mesBaseProcessInfo);
        ExcelUtil<MesBaseProcessInfo> util = new ExcelUtil<MesBaseProcessInfo>(MesBaseProcessInfo.class);
        util.exportExcel(response, list, "工序信息数据");
    }

    /**
     * 获取工序信息详细信息
     */
    @RequiresPermissions("mes:processInfo:query")
    @GetMapping(value = "/{processId}")
    public AjaxResult getInfo(@PathVariable("processId") Long processId)
    {
        return success(mesBaseProcessInfoService.selectMesBaseProcessInfoByProcessId(processId));
    }

    /**
     * 获取工序用户信息详细信息
     */
    @RequiresPermissions("mes:processInfo:query")
    @GetMapping(value = "/user/{processId}")
    public AjaxResult getUserInfo(@PathVariable("processId") Long processId)
    {
        return success(mesBaseProcessInfoService.selectMesBaseProcessInfoUserByProcessId(processId));
    }

    /**
     * 新增工序信息
     */
    @RequiresPermissions("mes:processInfo:add")
    @Log(title = "工序信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesBaseProcessInfo mesBaseProcessInfo)
    {
        mesBaseProcessInfo.setCreateBy(SecurityUtils.getLoginUser().getUsername());
        return toAjax(mesBaseProcessInfoService.insertMesBaseProcessInfo(mesBaseProcessInfo));
    }

    /**
     * 修改工序信息
     */
    @RequiresPermissions("mes:processInfo:edit")
    @Log(title = "工序信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesBaseProcessInfo mesBaseProcessInfo)
    {
        mesBaseProcessInfo.setUpdateBy(SecurityUtils.getLoginUser().getUsername());
        return toAjax(mesBaseProcessInfoService.updateMesBaseProcessInfo(mesBaseProcessInfo));
    }

    /**
     * 修改工序关联人员信息
     */
    @RequiresPermissions("mes:processInfo:edit")
    @Log(title = "工序信息", businessType = BusinessType.UPDATE)
    @PutMapping("/user")
    public AjaxResult editUser(@RequestBody MesBaseProcessInfo mesBaseProcessInfo)
    {
        return toAjax(mesBaseProcessInfoService.updateMesBaseProcessInfoUser(mesBaseProcessInfo));
    }

    /**
     * 删除工序信息
     */
    @RequiresPermissions("mes:processInfo:remove")
    @Log(title = "工序信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{processIds}")
    public AjaxResult remove(@PathVariable Long[] processIds)
    {
        return toAjax(mesBaseProcessInfoService.deleteMesBaseProcessInfoByProcessIds(processIds));
    }
}
