package com.moon.server.controller.data.upload; import com.moon.server.annotation.SysLog; import com.moon.server.controller.all.BaseController; import com.moon.server.entity.all.ResponseMsg; import com.moon.server.entity.all.StaticData; import com.moon.server.entity.ctrl.FmeReqEntity; import com.moon.server.entity.ctrl.RegisterEntity; import com.moon.server.helper.HttpHelper; import com.moon.server.helper.PathHelper; import com.moon.server.helper.StringHelper; import com.moon.server.service.data.FmeService; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; @SuppressWarnings("ALL") public class CheckController extends BaseController { @Autowired protected PathHelper pathHelper; @Autowired protected FmeService fmeService; @SysLog() @ApiOperation(value = "查询任务状态") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "任务ID", dataType = "String", paramType = "query", example = "29db09ee-2aae-4c62-bec0-0b5c5d8084e4") }) @GetMapping(value = "/selectTaskStatus") public Object selectTaskStatus(String id, HttpServletRequest req) { try { if (StringHelper.isEmpty(id)) { return fail("id不能为空"); } return fmeService.getTaskStatus(id, req); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "下载质检结果") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "任务ID", dataType = "String", paramType = "query", example = "29db09ee-2aae-4c62-bec0-0b5c5d8084e4") }) @GetMapping(value = "/downloadResult") public void downloadResult(String id, HttpServletRequest req, HttpServletResponse res) { try { if (!StringHelper.isEmpty(id)) { String url = fmeService.getDownloadUrl(id, req); HttpHelper httpHelper = new HttpHelper(); // res.sendRedirect(url) httpHelper.service(req, res, null, url); } } catch (Exception ex) { log.error(ex.getMessage(), ex); } } @SysLog() @ApiOperation(value = "提交数据质检") @ApiImplicitParams({ @ApiImplicitParam(name = "entity", value = "FME请求实体类", dataType = "FmeReqEntity", paramType = "body") }) @ResponseBody @PostMapping(value = "/uploadChecks") public ResponseMsg uploadChecks(@RequestBody FmeReqEntity entity, HttpServletRequest req) { try { if (StringHelper.isEmpty(entity.names)) { return fail("任务名称不能为空"); } if (StringHelper.isEmpty(entity.zipPath)) { return fail("请选择待质检的zip文件"); } entity.zipPath = getFullPath(entity.zipPath); if (!isZipFile(entity.zipPath)) { return fail("待质检的zip文件不存在"); } if (entity.names.contains(StaticData.CHECK_MAIN)) { entity.wbsPath = getFullPath(entity.wbsPath); if (!isXlsFile(entity.wbsPath)) { return fail("待质检的WBS文件不存在"); } } List list = new ArrayList<>(); for (String name : entity.names.split(StaticData.COMMA)) { String guid = invoke(name, entity, req); list.add(guid); } return success(list); } catch (Exception ex) { return fail(ex, null); } } private String getFullPath(String filePath) { return null == filePath ? null : pathHelper.getConfig().getTempPath() + File.separator + filePath; } private boolean isZipFile(String filePath) { if (null == filePath || !filePath.toLowerCase().endsWith(StaticData.ZIP)) { return false; } File zipFile = new File(filePath); return zipFile.exists() && !zipFile.isDirectory(); } private boolean isXlsFile(String filePath) { if (null == filePath) { return false; } if (!(filePath.toLowerCase().endsWith(StaticData.XLS) || filePath.toLowerCase().endsWith(StaticData.XLSX))) { return false; } File zipFile = new File(filePath); return zipFile.exists() && !zipFile.isDirectory(); } private String invoke(String name, FmeReqEntity entity, HttpServletRequest req) throws Exception { Method method; try { method = FmeService.class.getDeclaredMethod(name, FmeReqEntity.class, HttpServletRequest.class); } catch (Exception ex) { throw new Exception(name + ",该检查方法不存在"); } Object obj = method.invoke(fmeService, entity, req); return null == obj ? null : obj.toString(); } @SysLog() @ApiOperation(value = "服务注册") @GetMapping(value = "/selectServerRegister") public ResponseMsg selectServerRegister(HttpServletRequest req) { try { RegisterEntity rs = fmeService.serverRegister("西气东输四线天然气管道工程(吐鲁番-中卫)(00116DT02)", "http://127.0.0.1/LFData/2d/tiles/01/{z}/{x}/{y}.png", "DOM", req); if (null == rs || StringHelper.isEmpty(rs.getSerialnum())) { return fail("失败"); } return success(rs); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "服务申请") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "服务ID", dataType = "String", paramType = "query", example = "195f77eb-19dd-4e34-afc1-fcff8f758f7b"), @ApiImplicitParam(name = "pubid", value = "发布ID", dataType = "Integer", paramType = "query", example = "1"), }) @GetMapping(value = "/selectServerApply") public ResponseMsg selectServerApply(String id, Integer pubid, HttpServletRequest req) { try { fmeService.serverApply(id, pubid, req); return success("OK"); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "删除资源") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "服务ID", dataType = "String", paramType = "query", example = "6f4b6783-4b98-4d46-a0d9-43cdb5f339dc") }) @GetMapping(value = "/selectDeleteRes") public ResponseMsg selectDeleteRes(String id, HttpServletRequest req) { try { fmeService.deleteRes(id, req); return success("OK"); } catch (Exception ex) { return fail(ex, null); } } }