浏览代码

修改文件限制

zhouyy 6 月之前
父节点
当前提交
f499c6a6fe

+ 13 - 0
fhKeeper/formulahousekeeper/management-platform/pom.xml

@@ -14,6 +14,19 @@
     <version>3.4.0</version>
     <version>3.4.0</version>
 
 
     <dependencies>
     <dependencies>
+
+<!--        <dependency>-->
+<!--            <groupId>cn.hutool</groupId>-->
+<!--            <artifactId>hutool-all</artifactId>-->
+<!--            <version>5.8.9</version>-->
+<!--        </dependency>-->
+<!--        <dependency>-->
+<!--            <groupId>commons-codec</groupId>-->
+<!--            <artifactId>commons-codec</artifactId>-->
+<!--            <version>1.10</version>-->
+<!--        </dependency>-->
+
+
         <dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
             <artifactId>spring-boot-starter-web</artifactId>

+ 3 - 11
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/FinancialAuditController.java

@@ -2,33 +2,25 @@ package com.management.platform.controller;
 
 
 
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.management.platform.entity.FinancialAudit;
 import com.management.platform.entity.FinancialAudit;
-import com.management.platform.entity.Project;
-import com.management.platform.entity.ProjectStage;
 import com.management.platform.entity.User;
 import com.management.platform.entity.User;
 import com.management.platform.mapper.UserMapper;
 import com.management.platform.mapper.UserMapper;
 import com.management.platform.service.FinancialAuditService;
 import com.management.platform.service.FinancialAuditService;
-import com.management.platform.service.ProjectStageService;
 import com.management.platform.util.HttpRespMsg;
 import com.management.platform.util.HttpRespMsg;
-import com.management.platform.util.MessageUtils;
-import io.lettuce.core.pubsub.PubSubOutput;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
-
-import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.RestController;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
 import java.text.ParseException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
-import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeFormatter;
-import java.util.*;
-import java.util.stream.Collectors;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 
 /**
 /**
  * <p>
  * <p>

+ 3 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/WxCorpInfoService.java

@@ -48,7 +48,7 @@ public interface WxCorpInfoService extends IService<WxCorpInfo> {
 
 
     public String getTranslationMediaId(String fileName) throws Exception;
     public String getTranslationMediaId(String fileName) throws Exception;
 
 
-    public String getTranslationJobId(String fileName,WxCorpInfo wxCorpInfo) throws Exception;
+    public String getTranslationJobId(String fileName,String md5,WxCorpInfo wxCorpInfo) throws Exception;
 
 
     public String syncTranslation(String authCorpid,String mediaId,String outPutFileName,String outputFileFormat) throws Exception;
     public String syncTranslation(String authCorpid,String mediaId,String outPutFileName,String outputFileFormat) throws Exception;
 
 
@@ -87,4 +87,6 @@ public interface WxCorpInfoService extends IService<WxCorpInfo> {
     JSONArray getApprovalInfo(Integer companyId, String startDate, String endDate, String newCursor, JSONArray filterArray) throws Exception;
     JSONArray getApprovalInfo(Integer companyId, String startDate, String endDate, String newCursor, JSONArray filterArray) throws Exception;
 
 
     public String applyEvent(HttpServletRequest request, JSONObject data) throws Exception;
     public String applyEvent(HttpServletRequest request, JSONObject data) throws Exception;
+
+    String getAsyncJobResult(String tmpFileJobId,WxCorpInfo wxCorpInfo)  throws Exception;
 }
 }

+ 18 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ExcelExportServiceImpl.java

@@ -13,6 +13,7 @@ import com.management.platform.util.ExcelUtil;
 import com.management.platform.util.HttpRespMsg;
 import com.management.platform.util.HttpRespMsg;
 import com.management.platform.util.MessageUtils;
 import com.management.platform.util.MessageUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.io.FileSystemResource;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
@@ -82,19 +83,33 @@ public class ExcelExportServiceImpl implements ExcelExportService {
         String resp = ExcelUtil.exportGeneralExcelByTitleAndList(title, list, downloadPath);
         String resp = ExcelUtil.exportGeneralExcelByTitleAndList(title, list, downloadPath);
         String fileUrlSuffix = title + ".xlsx";
         String fileUrlSuffix = title + ".xlsx";
         if(wxCorpInfo != null && wxCorpInfo.getSaasSyncContact() == 1){
         if(wxCorpInfo != null && wxCorpInfo.getSaasSyncContact() == 1){
-//            FileSystemResource fileSystemResource = new FileSystemResource(path+fileUrlSuffix);
-//            Long checkSize = 20L*1024*1024;
+            FileSystemResource fileSystemResource = new FileSystemResource(path+fileUrlSuffix);
+//            String md5 = DigestUtils.md5Hex(FileUtil.readBytes(fileSystemResource.getFile()));
+
+            Long checkSize = 20L*1024*1024;
+            if(fileSystemResource.getFile().length() >= checkSize){
+                httpRespMsg.setError("文件过大,请缩短查询日期范围");
+                return httpRespMsg;
+            }
             String jobId = "";
             String jobId = "";
             String mediaId = wxCorpInfoService.getTranslationMediaId(fileUrlSuffix);
             String mediaId = wxCorpInfoService.getTranslationMediaId(fileUrlSuffix);
             jobId = wxCorpInfoService.syncTranslation(wxCorpInfo.getCorpid(),mediaId,fileUrlSuffix, null);
             jobId = wxCorpInfoService.syncTranslation(wxCorpInfo.getCorpid(),mediaId,fileUrlSuffix, null);
 //            if(fileSystemResource.getFile().length() >= checkSize){
 //            if(fileSystemResource.getFile().length() >= checkSize){
-//                jobId = wxCorpInfoService.getTranslationJobId(fileUrlSuffix,wxCorpInfo);
+//                String tmpFileJobId = wxCorpInfoService.getTranslationJobId(fileUrlSuffix,md5,wxCorpInfo);
+//                if(!StringUtils.isEmpty(tmpFileJobId)){
+//                    String mediaId = wxCorpInfoService.getAsyncJobResult(tmpFileJobId,wxCorpInfo);
+//                    jobId = wxCorpInfoService.syncTranslation(wxCorpInfo.getCorpid(),mediaId,fileUrlSuffix, null);
+//                }
 //            }else{
 //            }else{
 //                String mediaId = wxCorpInfoService.getTranslationMediaId(fileUrlSuffix);
 //                String mediaId = wxCorpInfoService.getTranslationMediaId(fileUrlSuffix);
 //                jobId = wxCorpInfoService.syncTranslation(wxCorpInfo.getCorpid(),mediaId,fileUrlSuffix, null);
 //                jobId = wxCorpInfoService.syncTranslation(wxCorpInfo.getCorpid(),mediaId,fileUrlSuffix, null);
 //            }
 //            }
 
 
             System.out.println("上传待转译文件到企业微信, jobId==" + jobId);
             System.out.println("上传待转译文件到企业微信, jobId==" + jobId);
+//            if(StringUtils.isEmpty(jobId)){
+//                httpRespMsg.setError("转义jobId为空,请联系管理员");
+//                return httpRespMsg;
+//            }
             int i = 0;
             int i = 0;
             String syncTranslationResult = null;
             String syncTranslationResult = null;
             /**
             /**

+ 66 - 4
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/WxCorpInfoServiceImpl.java

@@ -174,6 +174,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
     //获取服务商provider_access_token
     //获取服务商provider_access_token
     @Override
     @Override
     public String getProviderAccessToken() throws Exception {
     public String getProviderAccessToken() throws Exception {
+        System.out.println("in getProviderAccessToken  method");
         String access_token="";
         String access_token="";
         String url = "https://qyapi.weixin.qq.com/cgi-bin/service/get_provider_token";
         String url = "https://qyapi.weixin.qq.com/cgi-bin/service/get_provider_token";
         HttpHeaders headers = new HttpHeaders();
         HttpHeaders headers = new HttpHeaders();
@@ -192,6 +193,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
             }
             }
             access_token= json.getString("provider_access_token");
             access_token= json.getString("provider_access_token");
         }
         }
+        System.out.println("end getProviderAccessToken  method");
         return access_token;
         return access_token;
     }
     }
 
 
@@ -230,7 +232,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
     }
     }
 
 
     @Override
     @Override
-    public String getTranslationJobId(String fileName, WxCorpInfo wxCorpInfo) throws Exception {
+    public String getTranslationJobId(String fileName,String md5, WxCorpInfo wxCorpInfo) throws Exception {
         System.out.println("in getTranslationJobId method");
         System.out.println("in getTranslationJobId method");
         String jobId="";
         String jobId="";
         //然后处理文件 通讯录id转译
         //然后处理文件 通讯录id转译
@@ -240,8 +242,10 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
         params.put("scene",1);
         params.put("scene",1);
         params.put("type","file");
         params.put("type","file");
         params.put("filename",fileName);
         params.put("filename",fileName);
-        params.put("url","https://worktime.ttkuaiban.com/upload/"+fileName);
-        params.put("md5","MD5");
+//        params.put("url","https://worktime.ttkuaiban.com/upload/"+fileName);
+        params.put("url","http://47.101.180.183:9097/upload/"+fileName);
+//        System.out.println("uploadJobFileUrl=== "+"http://47.101.180.183:9097/upload/"+fileName);
+        params.put("md5",md5);
         String requestBody = JSONObject.toJSONString(params);
         String requestBody = JSONObject.toJSONString(params);
         HttpEntity<String> entity = new HttpEntity<>(requestBody, headers);
         HttpEntity<String> entity = new HttpEntity<>(requestBody, headers);
         String apiUrl = "https://qyapi.weixin.qq.com/cgi-bin/media/upload_by_url?access_token="+getCorpAccessToken(wxCorpInfo);
         String apiUrl = "https://qyapi.weixin.qq.com/cgi-bin/media/upload_by_url?access_token="+getCorpAccessToken(wxCorpInfo);
@@ -253,7 +257,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
         Map responseObj = objectMapper.readValue(responseBody, Map.class);
         Map responseObj = objectMapper.readValue(responseBody, Map.class);
         if (responseEntity.getStatusCode() == HttpStatus.OK){
         if (responseEntity.getStatusCode() == HttpStatus.OK){
             if(null != responseObj.get("errcode") && 0 == Integer.parseInt(responseObj.get("errcode").toString())){
             if(null != responseObj.get("errcode") && 0 == Integer.parseInt(responseObj.get("errcode").toString())){
-                jobId = responseObj.get("job_id").toString();
+                jobId = responseObj.get("jobid").toString();
             }else{
             }else{
                 System.out.println("error Trans====== "+responseObj.get("errmsg").toString());
                 System.out.println("error Trans====== "+responseObj.get("errmsg").toString());
             }
             }
@@ -2574,4 +2578,62 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
         }
         }
         return "";
         return "";
     }
     }
+
+    @Override
+    public String getAsyncJobResult(String tmpFileJobId,WxCorpInfo wxCorpInfo) throws Exception{
+        System.out.println("in getAsyncJobResult method");
+        String mediaId = "";
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.APPLICATION_JSON);
+        Map<String,Object> params = new HashMap<>();
+        params.put("jobid",tmpFileJobId);
+        String requestBody = JSONObject.toJSONString(params);
+        HttpEntity<String> entity = new HttpEntity<>(requestBody, headers);
+        String apiUrl = "https://qyapi.weixin.qq.com/cgi-bin/media/get_upload_by_url_result?access_token="+getCorpAccessToken(wxCorpInfo);
+        
+        int i = 0;
+        while(i < 100){
+            if (i < 10) {
+                Thread.sleep(300);
+            } else if (i < 20){
+                Thread.sleep(1000);
+            } else {
+                Thread.sleep(3000);
+            }
+            System.out.println("i=="+i+", "+LocalDateTime.now());
+            ResponseEntity<String> responseEntity = restTemplate.exchange(apiUrl, HttpMethod.POST, entity, String.class);
+            String responseBody = responseEntity.getBody();
+            System.out.println("getAsyncJobResult Response from API: " + responseBody);
+            JSONObject jsonRes = JSONObject.parseObject(responseBody);
+            if (responseEntity.getStatusCode() == HttpStatus.OK){
+                if(null != jsonRes.get("errcode") && 0 == Integer.parseInt(jsonRes.get("errcode").toString())){
+                    String status = jsonRes.get("status").toString();
+                    if("1".equals(status)){
+                        //处理中
+                    } else if ("2".equals(status)) {
+                        //已完成
+                        String detailStr = jsonRes.getString("detail");
+                        JSONObject detailJson = JSONObject.parseObject(detailStr);
+                        mediaId = detailJson.getString("media_id");
+                        break;
+                    } else if ("3".equals(status)) {
+                        //报错了
+                        String detailStr = jsonRes.getString("detail");
+                        System.out.println("detailStr==="+detailStr);
+                        JSONObject detailJson = JSONObject.parseObject(detailStr);
+                        System.out.println("企业微信转译报错:"+detailJson.getString("errmsg"));
+                        break;
+                    }
+                }else{
+                    System.out.println("error Trans====== "+jsonRes.get("errmsg").toString());
+                    break;
+                }
+            }
+            i++;
+        }
+
+
+        System.out.println("end getAsyncJobResult method");
+        return mediaId;
+    }
 }
 }