package com.sw.mes.webservice.controller;

import java.util.Date;

import com.sw.mes.core.response.Result;
import com.sw.mes.core.response.ResultGenerator;
import com.sw.mes.third.entity.SoapInDto;
import com.sw.mes.third.entity.SoapOutDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
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;

import com.alibaba.fastjson.JSONObject;
import com.sw.mes.webservice.scheduled.ProcessYieldAndHourRun;
import com.sw.mes.webservice.service.GrService;
import com.sw.mes.webservice.service.MyWebService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author @Description：
 * @Date: Create in
 * @Modified By:
 */
@RestController
@RequestMapping("/webServiceTest")
@Slf4j
@Api(description = "SAPService测试")
public class WebServiceTestController {

	@Autowired
	private MyWebService myWebService;
	
	@Autowired
	private ProcessYieldAndHourRun processYieldAndHourRun; 
	
	@Autowired
	private GrService grService;
	

	@ApiOperation(value = "WebService测试接口")
	@PostMapping("/data")
	public Result data(@RequestBody SoapInDto soapInDto, BindingResult bindingResult) {
		try {
			SoapOutDto out = myWebService.SAP_TO_1031MES_Request(soapInDto);
			return ResultGenerator.success(out);
		} catch (Exception e) {
			return ResultGenerator.fail(e.getMessage());
		}
	}
	
	//测试调用 请求数据发送sap {"date":"2022-02-28 10:03:00"}
	@ApiOperation(value = "向sap发送数据")
	@PostMapping("/sendDataToSap")
	public Result sendDataToSap(@RequestBody JSONObject json) {
		try {
			processYieldAndHourRun.sendYieldAndHourOfCrystalPulling();
			return ResultGenerator.success("成功");
		} catch (Exception e) {
			return ResultGenerator.fail(e.getMessage());
		}
	}
	
	//测试调用 请求数据发送sap {"date":"2022-02-28 10:03:00"}
	@ApiOperation(value = "向sap发送数据")
	@PostMapping("/sendGrDataToSap")
	public Result sendGrDataToSap(@RequestBody JSONObject json) {
		try {
			Date date = json.getDate("date");
			grService.sendGrData();
			return ResultGenerator.success("成功");
		} catch (Exception e) {
			return ResultGenerator.fail(e.getMessage());
		}
	}

	public static void main(String[] args) {
		String str = "";
		System.out.println(str);
	}

}
