package com.op.mes.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.op.mes.domain.ProOrderWorkorder;
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.op.common.log.annotation.Log;
import com.op.common.log.enums.BusinessType;
import com.op.common.security.annotation.RequiresPermissions;
import com.op.mes.domain.ProWetMaterialPlan;
import com.op.mes.service.IProWetMaterialPlanService;
import com.op.common.core.web.controller.BaseController;
import com.op.common.core.web.domain.AjaxResult;
import com.op.common.core.utils.poi.ExcelUtil;
import com.op.common.core.web.page.TableDataInfo;

/**
 * 湿料计划管理Controller
 *
 * @author Open Platform
 * @date 2023-07-24
 */
@RestController
@RequestMapping("/plan")
public class ProWetMaterialPlanController extends BaseController {
    @Autowired
    private IProWetMaterialPlanService proWetMaterialPlanService;

    /**
     * 提交湿料计划接口
     *
     * @param proOrderWorkorderList
     * @return
     */
    @PostMapping("/addWetPlan")
    public AjaxResult addWetPlan(@RequestBody List<ProOrderWorkorder> proOrderWorkorderList) {
        return proWetMaterialPlanService.addWetPlan(proOrderWorkorderList);
    }

    /**
     * 通过计划日期获取当前已经分配的料罐、物料、班次信息list
     *
     * @param planTime
     * @return
     */
    @GetMapping("/getBMSList")
    public AjaxResult getBMSList(Date planTime) {
        return proWetMaterialPlanService.getBMSList(planTime);
    }

    /**
     * 获取物料信息list
     *
     * @return
     */
    @GetMapping("/getProductList")
    public AjaxResult getProductList() {
        return proWetMaterialPlanService.getProductList();
    }

    /**
     * 查询料罐list
     *
     * @return
     */
    @GetMapping("/getBucketList")
    public AjaxResult getBucketList() {
        return proWetMaterialPlanService.getBucketList();
    }

    /**
     * 通过工单生产日期查询所有底层工单（排除已经分配过的工单）
     *
     * @return
     */
    @GetMapping("/getWorkOrderByTime")
    public AjaxResult getWorkOrderByTime(Date productDate) {
        return proWetMaterialPlanService.getWorkOrderByTime(productDate);
    }

    /**
     * 查询湿料计划管理列表
     */
    @RequiresPermissions("mes:plan:list")
    @GetMapping("/list")
    public TableDataInfo list(ProWetMaterialPlan proWetMaterialPlan) {
        startPage();
        List<ProWetMaterialPlan> list = proWetMaterialPlanService.selectProWetMaterialPlanList(proWetMaterialPlan);
        return getDataTable(list);
    }

    /**
     * 导出湿料计划管理列表
     */
    @RequiresPermissions("mes:plan:export")
    @Log(title = "湿料计划管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProWetMaterialPlan proWetMaterialPlan) {
        List<ProWetMaterialPlan> list = proWetMaterialPlanService.selectProWetMaterialPlanList(proWetMaterialPlan);
        ExcelUtil<ProWetMaterialPlan> util = new ExcelUtil<ProWetMaterialPlan>(ProWetMaterialPlan.class);
        util.exportExcel(response, list, "湿料计划管理数据");
    }

    /**
     * 获取湿料计划管理详细信息
     */
    @RequiresPermissions("mes:plan:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(proWetMaterialPlanService.selectProWetMaterialPlanById(id));
    }

    /**
     * 新增湿料计划管理
     */
    @RequiresPermissions("mes:plan:add")
    @Log(title = "湿料计划管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProWetMaterialPlan proWetMaterialPlan) {
        return toAjax(proWetMaterialPlanService.insertProWetMaterialPlan(proWetMaterialPlan));
    }

    /**
     * 修改湿料计划管理
     */
    @RequiresPermissions("mes:plan:edit")
    @Log(title = "湿料计划管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProWetMaterialPlan proWetMaterialPlan) {
        return toAjax(proWetMaterialPlanService.updateProWetMaterialPlan(proWetMaterialPlan));
    }

    /**
     * 删除湿料计划管理
     */
    @RequiresPermissions("mes:plan:remove")
    @Log(title = "湿料计划管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(proWetMaterialPlanService.deleteProWetMaterialPlanByIds(ids));
    }
}
