package cn.ezhizao.project.business.controller;

import cn.ezhizao.framework.web.page.TableDataInfo;
import cn.ezhizao.project.business.domain.*;
import cn.ezhizao.framework.web.controller.BaseController;

import java.util.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import cn.ezhizao.project.business.service.IBizProductionPlanDetailSubDetailEquipmentService;
import cn.ezhizao.project.business.service.IBizProductionPlanDetailSubDetailService;
import cn.ezhizao.project.business.service.IBizTechnologicalProcessDetailService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ProductionTaskController
 * 这个控制器，针对【调机班长需要对所需设备，指定操作者】，设置响应的方法
 * @author ezhizao
 */
@RestController
@RequestMapping("/business/productionTask")
public class ProductionTaskController extends BaseController {

    @Resource
    private IBizProductionPlanDetailSubDetailService productionPlanDetailSubDetailService;

    @Resource
    private IBizTechnologicalProcessDetailService technologicalProcessDetailService;

    @Resource
    private IBizProductionPlanDetailSubDetailEquipmentService productionPlanDetailSubDetailEquipmentService;
    @Resource
    HttpServletRequest request;

    /**
     * 获取工段长添加的投产信息，数据表是 biz_production_plan_detail_sub_detail
     */
//    @PreAuthorize("@ss.hasPermi('business:productionTask:query')")
    @GetMapping(value = "/getSubDetails")
    private TableDataInfo getSubDetails(BizProductionPlanDetailSubDetail data) {
//        String tenantId = request.getHeader("tenantId");
//        data.setTenantId(Long.valueOf(tenantId));
        // 获取工段长添加的投产数据【biz_production_plan_detail_sub_detail】，并分页显示
        // 根据【产品描述】，获取投产数据【biz_production_plan_detail_sub_detail】列表，并分页显示
        startPage();
        List<BizProductionPlanDetailSubDetail> subDetails = productionPlanDetailSubDetailService.getListByKeywords(data);
        return getDataTable(subDetails);
    }

    /**
     * 根据工艺id，获取对应的工序列表
     */
    @PostMapping(value = "/getProcessDetailsByTechnicalProcessId")
    public TableDataInfo getProcessDetailsByTechnicalProcessId(@RequestBody Map<String, Object> data) {
        // 根据【工艺id】，获取工艺对应的工序【biz_technological_process_detail】列表，并分页显示
        Long technologicalProcessId = Long.valueOf(data.get("technologicalProcessId").toString());
//        startPage();
        List<BizTechnologicalProcessDetail> processDetails = technologicalProcessDetailService.getProcessDetailsByTechnicalProcessId(technologicalProcessId);

        return getDataTable(processDetails);
    }

    /**
     * 根据工序id，获取对应的设备列表
     * @param data 前端传递的数据
     * @return List<BizProcess> 返回数据
     */
    @GetMapping(value = "/getSubDetailProcessEquipments")
    public TableDataInfo getSubDetailProcessEquipments( BizProductionPlanDetailSubDetailEquipment data) {
        // 根据【工序id】，获取工序【biz_process】列表，并分页显示
        startPage();
        List<BizProductionPlanDetailSubDetailEquipment> equipments = productionPlanDetailSubDetailEquipmentService.getList(data);

        return getDataTable(equipments);
    }
}
