package com.uas.eis.controller;

import com.uas.eis.sdk.entity.ApiResult;
import com.uas.eis.sdk.resp.ApiResponse;
import com.uas.eis.service.MESDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author xiaost
 * @date 2021/12/20 17:03
 * MES数据写入到中间表
 **/
@RestController
public class MESDataController {

    @Autowired
    private MESDataService mesDataService;

    /**
     * 产品SN工序过站记录
     * @param data
     * @return
     */
    @RequestMapping("/api/mes/snStepPass")
    public ApiResult<List<Map<Object,Object>>> snStepPass(HttpServletRequest request, String data){
        String accessKey = request.getHeader("AccessKey");
        String requestId = request.getHeader("RequestId");
        List<Map<Object,Object>> list = mesDataService.snStepPass(accessKey,requestId,data);
        return ApiResponse.successRsp("0","Success",requestId,list);
    }

    /**
     * 产品SN烧写绑定记录
     * @param data
     * @return
     */
    @RequestMapping("/api/mes/snInfo")
    public ApiResult<List<Map<Object,Object>>> snInfo(HttpServletRequest request, String data){
        String accessKey = request.getHeader("AccessKey");
        String requestId = request.getHeader("RequestId");
        List<Map<Object,Object>> list = mesDataService.snInfo(accessKey,requestId,data);
        return ApiResponse.successRsp("0","Success",requestId,list);
    }

    /**
     * 产品SN烧写转号记录
     * @param data
     * @return
     */
    @RequestMapping("/api/mes/makeSnRelation")
    public ApiResult<List<Map<Object,Object>>> makeSnRelation(HttpServletRequest request, String data){
        String accessKey = request.getHeader("AccessKey");
        String requestId = request.getHeader("RequestId");
        List<Map<Object,Object>> list = mesDataService.makeSnRelation(accessKey,requestId,data);
        return ApiResponse.successRsp("0","Success",requestId,list);
    }

    /**
     * 产品不良现象记录
     * @param data
     * @return
     */
    @RequestMapping("/api/mes/makeBad")
    public ApiResult<List<Map<Object,Object>>> makeBad(HttpServletRequest request, String data){
        String accessKey = request.getHeader("AccessKey");
        String requestId = request.getHeader("RequestId");
        List<Map<Object,Object>> list = mesDataService.MAKEBAD(accessKey,requestId,data);
        return ApiResponse.successRsp("0","Success",requestId,list);
    }

    /**
     * 产品不良维修记录
     * @param data
     * @return
     */
    @RequestMapping("/api/mes/makeBadReason")
    public ApiResult<List<Map<Object,Object>>> makeBadReason(HttpServletRequest request, String data){
        String accessKey = request.getHeader("AccessKey");
        String requestId = request.getHeader("RequestId");
        List<Map<Object,Object>> list = mesDataService.makeBadReason(accessKey,requestId,data);
        return ApiResponse.successRsp("0","Success",requestId,list);
    }

    /**
     * 包装信息
     * @param data
     * @return
     */
    @RequestMapping("/api/mes/package")
    public ApiResult<List<Map<Object,Object>>> packageDetail(HttpServletRequest request, String data){
        String accessKey = request.getHeader("AccessKey");
        String requestId = request.getHeader("RequestId");
        List<Map<Object,Object>> list = mesDataService.packageDetail(accessKey,requestId,data);
        return ApiResponse.successRsp("0","Success",requestId,list);
    }


}
