package com.skr.mdm.controller;

import com.skr.mdm.constant.CmdTypeConstants;
import com.skr.mdm.dto.LoginUserDTO;
import com.skr.mdm.result.ResponseResult;
import com.skr.mdm.service.CmdHandlerService;
import com.skr.mdm.service.StrategyFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @ProjectName: mdm_new
 * @Package: com.skr.mdm.controller
 * @ClassName: EquipmentMobileController
 * @Author: Tty
 * @Description: 开启移动数据回调
 * @Date: 2020/11/26 17:27
 * @Version: 1.0
 */
@RestController
@RequestMapping("restoreFactory")
@Api(tags = "恢复出厂")
public class EquipmentRestoreFactoryController {

	@PostMapping("upload")
	@ApiOperation("恢复出厂回调")
	public ResponseResult uploadMobileData(@RequestParam @ApiParam(value = "回调内容", required = true) String data,
										   @ApiIgnore Authentication authentication) {
		LoginUserDTO loginUserDTO = (LoginUserDTO) authentication.getPrincipal();
		CmdHandlerService strategy = StrategyFactory.getStrategy(CmdTypeConstants.RESTORE_FACTORY);
		return strategy.cmdHandler(loginUserDTO.getId(), data);
	}
}
