From c509bd8047cfd582c59bba66d148b236e45d038d Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期四, 12 一月 2023 10:15:15 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/controller/data/upload/CheckController.java | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 111 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/lf/server/controller/data/upload/CheckController.java b/src/main/java/com/lf/server/controller/data/upload/CheckController.java index 298321d..a08764f 100644 --- a/src/main/java/com/lf/server/controller/data/upload/CheckController.java +++ b/src/main/java/com/lf/server/controller/data/upload/CheckController.java @@ -2,6 +2,11 @@ import com.lf.server.annotation.SysLog; import com.lf.server.controller.all.BaseController; +import com.lf.server.entity.all.ResponseMsg; +import com.lf.server.entity.all.StaticData; +import com.lf.server.entity.ctrl.FmeReqEntity; +import com.lf.server.helper.HttpHelper; +import com.lf.server.helper.PathHelper; import com.lf.server.helper.StringHelper; import com.lf.server.service.data.FmeService; import io.swagger.annotations.ApiImplicitParam; @@ -9,15 +14,25 @@ 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; /** * 妫�鏌ユ帶鍒跺櫒 * @author WWW */ public class CheckController extends BaseController { + @Autowired + protected PathHelper pathHelper; + @Autowired protected FmeService fmeService; @@ -33,9 +48,7 @@ return fail("id涓嶈兘涓虹┖"); } - Object obj = fmeService.getTaskStatus(id, req); - - return obj; + return fmeService.getTaskStatus(id, req); } catch (Exception ex) { return fail(ex.getMessage(), null); } @@ -51,13 +64,107 @@ try { if (!StringHelper.isEmpty(id)) { String url = fmeService.getDownloadUrl(id, req); - res.sendRedirect(url); + + HttpHelper httpHelper = new HttpHelper(); + // res.sendRedirect(url) + httpHelper.service(req, res, url, null); } } 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<Object> uploadChecks(@RequestBody FmeReqEntity entity, HttpServletRequest req) { + try { + if (StringHelper.isEmpty(entity.names)) { + return fail("浠诲姟鍚嶇О涓嶈兘涓虹┖"); + } + if (StringHelper.isEmpty(entity.zipPath)) { + return fail("璇烽�夋嫨寰呰川妫�鐨剒ip鏂囦欢"); + } + + entity.zipPath = getFullPath(entity.zipPath); + if (!isZipFile(entity.zipPath)) { + return fail("寰呰川妫�鐨剒ip鏂囦欢涓嶅瓨鍦�"); + } + if (entity.names.contains(StaticData.CHECK_MAIN)) { + entity.wbsPath = getFullPath(entity.wbsPath); + if (!isXlsFile(entity.wbsPath)) { + return fail("寰呰川妫�鐨刉BS鏂囦欢涓嶅瓨鍦�"); + } + } + + List<String> 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.getMessage(), null); + } + } + + /** + * 鑾峰彇鏂囦欢璺緞 + */ + private String getFullPath(String filePath) { + return null == filePath ? null : pathHelper.getConfig().getTempPath() + File.separator + filePath; + } + + /** + * 鏄�/鍚︿负Zip鏂囦欢 + */ + 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(); + } + + /** + * 鏄�/鍚︿负Excel鏂囦欢 + */ + 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 = "鏌ヨOSGB妫�鏌�") @GetMapping(value = "/selectCheckOsgb") -- Gitblit v1.9.3