package com.web.jhsop.websocket.controller; import com.alibaba.fastjson.JSON; import com.app.base.control.WebController; import com.app.base.data.ApiResponseResult; import com.web.jhsop.websocket.entity.SopFile; import com.web.jhsop.websocket.service.SopSendService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import java.util.Map; @Api(description = "SOP公共接口") @CrossOrigin @ControllerAdvice // @RestController @Controller @RequestMapping(value = "/sop") public class SopController extends WebController { @Autowired private SopSendService sopSendService; @ApiOperation(value = "sop分发", notes = "sop分发") @RequestMapping(value = "/sendSop", method = RequestMethod.GET) @ResponseBody public ApiResponseResult sendSop(@RequestParam(value = "deviceId", required = false) String deviceCode, @RequestParam(value = "url", required = false) String url, @RequestParam(value = "account", required = false) String account, @RequestParam(value = "password", required = false) String password, @RequestParam(value = "path", required = false) String path, @RequestParam(value = "root", required = false) String root, @RequestParam(value = "fileName", required = false) String fileName, @RequestParam(value = "workOrder", required = false) String workOrder, @RequestParam(value = "processLine",required = false)String processLine, @RequestParam(value = "page",required = false)Integer page) throws Exception{ try{ return sopSendService.sendSop(deviceCode,url,account,password,path,root,fileName,workOrder,processLine,page); }catch (Exception e){ e.printStackTrace(); return ApiResponseResult.failure("sop分发失败"); } } @ApiOperation(value = "sop分发", notes = "sop分发") @RequestMapping(value = "/sendAllSop", method = RequestMethod.GET) @ResponseBody public ApiResponseResult sendAllSop( @RequestParam(value = "url", required = false) String url, @RequestParam(value = "account", required = false) String account, @RequestParam(value = "password", required = false) String password, @RequestParam(value = "path", required = false) String path, @RequestParam(value = "root", required = false) String root, @RequestParam(value = "fileName", required = false) String fileName, @RequestParam(value = "workOrder", required = false) String workOrder, @RequestParam(value = "processLine",required = false)String processLine, @RequestParam(value = "page",required = false)Integer page) throws Exception{ try{ return sopSendService.sendAllSop(url,account,password,path,root,fileName,workOrder,processLine,page); }catch (Exception e){ e.printStackTrace(); return ApiResponseResult.failure("sop分发失败"); } } @ApiOperation(value = "获取ftp文件 返回文件流", notes = "获取ftp文件 返回文件流") @RequestMapping(value = "/getFtpFile", method = RequestMethod.GET) @ResponseBody public ApiResponseResult getFtpFile(@RequestParam(value = "deviceId", required = false) String deviceCode, @RequestParam(value = "url", required = false) String url, @RequestParam(value = "account", required = false) String account, @RequestParam(value = "password", required = false) String password, @RequestParam(value = "path", required = false) String path, @RequestParam(value = "root", required = false) String root, @RequestParam(value = "fileName", required = false) String fileName) throws Exception{ try{ return sopSendService.getFtpFile(deviceCode,url,account,password,path,root,fileName,getResponse()); }catch (Exception e){ e.printStackTrace(); return ApiResponseResult.failure("获取ftp文件 返回文件流失败"); } } @ApiOperation(value = "跳转到对应sheet", notes = "跳转到对应sheet") @RequestMapping(value = "/toSheetByPage", method = RequestMethod.GET) @ResponseBody public ApiResponseResult toSheetByPage(@RequestParam(value = "deviceId", required = false) String deviceId, @RequestParam(value = "page", required = false) String page) throws Exception{ try{ return sopSendService.toSheetByPage(deviceId,page); }catch (Exception e){ e.printStackTrace(); return ApiResponseResult.failure("跳转到对应sheet失败"); } } @ApiOperation(value = "获取所有的设备", notes = "获取所有的设备") @RequestMapping(value = "/getAllDevice", method = RequestMethod.GET) @ResponseBody public ApiResponseResult getAllDevice() throws Exception{ try{ return sopSendService.getAllDevice(); }catch (Exception e){ e.printStackTrace(); return ApiResponseResult.failure("获取所有的设备失败"); } } @ApiOperation(value = "获取sop文件", notes = "获取sop文件") @RequestMapping(value = "/getSopFile", method = RequestMethod.GET) @ResponseBody public ApiResponseResult getSopFile() throws Exception{ try{ return sopSendService.getSopFile(); }catch (Exception e){ e.printStackTrace(); return ApiResponseResult.failure("获取sop文件失败"); } } @ApiOperation(value = "sop文件分发", notes = "sop文件分发") @RequestMapping(value = "/distributeFile", method = RequestMethod.POST) @ResponseBody public ApiResponseResult distributeFile(@RequestBody Map map ) throws Exception{ try{ String deviceId = map.get("deviceId").toString(); SopFile sopFile = JSON.parseObject(JSON.toJSONString(map.get("file")), SopFile.class); String order = map.get("order").toString(); return sopSendService.distributeFile(deviceId,sopFile,order); }catch (Exception e){ e.printStackTrace(); return ApiResponseResult.failure("sop文件分发失败"); } } }