package com.sw.mes.yb.production.controller;

import com.sw.mes.mqtt.service.NotificationService;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sw.mes.core.response.Result;
import com.sw.mes.core.response.ResultGenerator;
import com.sw.mes.yb.production.notification.AgainTaskDetailMessage;
import com.sw.mes.yb.production.notification.AgainTaskMessage;

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

/**
 * @Author @Description：
 * @Date: Create in
 * @Modified By:
 */
@RestController
@RequestMapping("/processtest")
@Api(description = "专用测试接口")
public class TestController {
	@Autowired
	ModelMapper modelMapper;

	@Autowired
	private NotificationService notificationService;



	@SuppressWarnings("rawtypes")
	@ApiOperation(value = "发送复投Mqtt")
	@PostMapping("/sendMqttAgainTask")
	public Result sendMqttAgainTask(String series,String area,String equipmentCode,String lotNo,Long taskId) {
		try {
		//发送MQTT通知
		AgainTaskMessage message = new AgainTaskMessage();
		message.setArea(area);
		message.setEquipmentCode(equipmentCode);
		message.setId(taskId);
		message.setLotNo(lotNo);
		message.setSeries(series);
		notificationService.sendNotification(message);
		return ResultGenerator.success();
		}catch (Exception e) {
			return ResultGenerator.fail(e.getMessage());
		}
	}


	@SuppressWarnings("rawtypes")
	@ApiOperation(value = "发送复投呼叫Mqtt")
	@PostMapping("/sendMqttAgainTaskDetail")
	public Result sendMqttAgainTaskDetail(String series,String area,String equipmentCode,String lotNo,Long taskId) {
		try {
			//发送MQTT通知
			AgainTaskDetailMessage message = new AgainTaskDetailMessage();
			message.setArea(area);
			message.setEquipmentCode(equipmentCode);
			message.setId(taskId);
			message.setLotNo(lotNo);
			message.setSeries(series);
			notificationService.sendNotification(message);
			return ResultGenerator.success();
		}catch (Exception e) {
			return ResultGenerator.fail(e.getMessage());
		}
	}

}
