package com.hw.mes.controller;

import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
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.MesMaterialBom;
import com.hw.mes.domain.MesProductPlan;
import com.hw.mes.domain.MesProductPlanDetail;
import com.hw.mes.domain.vo.MesProductPlanDetailVo;
import com.hw.mes.service.IMesMaterialBomService;
import com.hw.mes.service.IMesProductPlanDetailService;
import com.hw.mes.service.IMesProductPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * MES对外提供接口Controller
 *
 * @author Yinq
 * @date 2024-01-30
 */
@RestController
@RequestMapping("/api")
public class MesApiController extends BaseController
{
    @Autowired
    private IMesMaterialBomService mesMaterialBomService;

    @Autowired
    private IMesProductPlanService productPlanService;

    @Autowired
    private IMesProductPlanDetailService productPlanDetailService;

    /**
     * 查询物料BOM信息列表
     */
//    @RequiresPermissions("mes:materialBom:list")
    @GetMapping("/getMaterialBoms")
    public AjaxResult getMaterialBoms(MesMaterialBom mesMaterialBom)
    {
        List<MesMaterialBom> list = mesMaterialBomService.selectMesMaterialBomJoinList(mesMaterialBom);
        return success(list);
    }


    /**
     * 查询车间派工信息列表表
     */
//    @RequiresPermissions("mes:materialBom:list")
    @GetMapping("/getProductPlans")
    public AjaxResult getProductPlans(MesProductPlan mesProductPlan)
    {
        List<MesProductPlan> list = productPlanService.selectMesProductPlanJoinList(mesProductPlan);
        return success(list);
    }


    /**
     * 生成生产计划明细
     */
    @Log(title = "生产计划明细", businessType = BusinessType.INSERT)
    @PostMapping(("/insertProductPlanDetails"))
    public AjaxResult insertProductPlanDetails(@Validated @RequestBody MesProductPlanDetailVo mesProductPlanDetailVo) {
        return toAjax(productPlanDetailService.insertMesProductPlanDetails(mesProductPlanDetailVo));
    }


    /**
     * 根据生产计划ID查询车间生产计划明细表
     */
//    @RequiresPermissions("mes:materialBom:list")
    @GetMapping("/getProductPlanDetails")
    public AjaxResult getProductPlanDetails(MesProductPlanDetail mesProductPlanDetail)
    {
        List<MesProductPlanDetail> list = productPlanDetailService.selectMesProductPlanDetailList(mesProductPlanDetail);
        return success(list);
    }

}
