Просмотр исходного кода

Merge branch 'oa_2022-03-29' of http://git.dayaedu.com/yonge/mec into master_saas

zouxuan 3 лет назад
Родитель
Сommit
e196b25756

+ 10 - 3
mec-biz/src/main/java/com/ym/mec/biz/service/impl/FinancialExpenditureServiceImpl.java

@@ -31,6 +31,7 @@ import com.ym.mec.util.ini.IniFileUtil;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.hssf.record.WriteAccessRecord;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -491,7 +492,7 @@ public class FinancialExpenditureServiceImpl extends BaseServiceImpl<Long, Finan
                 }
                 String submitForm = oaInputDto.getModel();
                 List<HashMap> hashMaps = JSONObject.parseArray(formData.get(submitForm).toString(), HashMap.class);
-                for (HashMap hashMap : hashMaps) {
+                nullUser: for (HashMap hashMap : hashMaps) {
                     FinancialExpenditure financialExpenditure = new FinancialExpenditure();
                     List<OaColumnDto> columns = oaInputDto.getColumns();
                     if(columns != null && columns.size() > 0){
@@ -523,6 +524,8 @@ public class FinancialExpenditureServiceImpl extends BaseServiceImpl<Long, Finan
                                         if(o != null){
                                             financialExpenditure.setStudentId(Integer.parseInt(o.toString()));
                                             continue;
+                                        }else {
+                                            continue nullUser;
                                         }
                                     }else if(name.contains("金额")){
                                         Object o = hashMap.get(inputDto.getModel());
@@ -538,6 +541,9 @@ public class FinancialExpenditureServiceImpl extends BaseServiceImpl<Long, Finan
                     financialExpenditureList.add(financialExpenditure);
                 }
             }
+            if(CollectionUtils.isEmpty(financialExpenditureList)){
+                return;
+            }
             //课程退费
             if(tplInfoId.equals("11")){
                 long count = financialExpenditureList.stream().filter(e -> StringUtils.isEmpty(e.getGroupType()) ||
@@ -545,7 +551,7 @@ public class FinancialExpenditureServiceImpl extends BaseServiceImpl<Long, Finan
                         Objects.isNull(e.getStudentId()) ||
                         Objects.isNull(e.getVipGroupId())).count();
                 if(count > 0l){
-                    throw new BizException("参数校验失败");
+                    throw new BizException("表单信息有误,请核实");
                 }
                 for (FinancialExpenditure financialExpenditure : financialExpenditureList) {
                     ReturnFeeDto returnFeeDto = new ReturnFeeDto();
@@ -564,9 +570,10 @@ public class FinancialExpenditureServiceImpl extends BaseServiceImpl<Long, Finan
             }else {
                 long count = financialExpenditureList.stream().
                         filter(e -> StringUtils.isEmpty(e.getMusicGroupId()) ||
+                        Objects.isNull(e.getAmount()) ||
                         Objects.isNull(e.getStudentId())).count();
                 if(count > 0l){
-                    throw new BizException("参数校验失败");
+                    throw new BizException("表单信息有误,请核实");
                 }
                 for (FinancialExpenditure financialExpenditure : financialExpenditureList) {
                     musicGroupService.checkDirectQuitMusicGroupOa(financialExpenditure);

+ 26 - 18
mec-web/src/main/java/com/ym/mec/web/controller/ImportController.java

@@ -29,6 +29,8 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
@@ -95,27 +97,33 @@ public class ImportController extends BaseController {
     @PostMapping(value = "oaUploadFile")
     public Object uploadFile(@ApiParam(value = "上传的文件", required = true) @RequestParam("file") MultipartFile file,Integer processId) throws Exception {
         if (file != null && StringUtils.isNotBlank(file.getOriginalFilename())) {
-            String filename = file.getOriginalFilename();
-            String prefix = filename.substring(filename.lastIndexOf("."));
-            File excelFile = File.createTempFile(UUID.randomUUID().toString(), prefix);
-            file.transferTo(excelFile);
-            //如果是乐团退费,校验excel
-            if(processId != null && processId.equals(19)){
-                if(!"xls".equals(prefix.substring(1)) && !"xlsx".equals(prefix.substring(1))){
-                    throw new BizException("请上传Excel文件");
-                }
-                financialExpenditureService.checkOaQuitMusicGroupExcel(FileUtils.readFileToByteArray(excelFile),filename);
-            }
-            UploadReturnBean bean = uploadFileService.uploadFile(FileUtils.openInputStream(excelFile), UploadUtil.getExtension(filename));
+            String fileName = UploadUtil.getExtension(file.getOriginalFilename());
+            UploadReturnBean bean = uploadFileService.uploadFile(file.getInputStream(),fileName);
             bean.setName(file.getOriginalFilename());
-            if (bean.isStatus()) {
+            if(bean.isStatus()){
+                //如果是乐团退费,校验excel
+                if(processId != null && processId.equals(19)){
+                    if(!"xls".equals(fileName) && !"xlsx".equals(fileName)){
+                        throw new BizException("请上传Excel文件");
+                    }
+                    URL url = new URL(bean.getUrl());
+                    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+                    conn.setConnectTimeout(3*1000);
+                    File excelFile = File.createTempFile(UUID.randomUUID().toString(), ".xls");
+                    try {
+                        FileUtils.copyInputStreamToFile(conn.getInputStream(),excelFile);
+                        financialExpenditureService.checkOaQuitMusicGroupExcel(FileUtils.readFileToByteArray(excelFile),fileName);
+                    }finally {
+                        //删除临时文件
+                        if (excelFile.exists()) {
+                            excelFile.delete();
+                        }
+                    }
+                }
                 return succeed(bean);
+            }else {
+                return failed(bean.getMessage());
             }
-            //删除临时文件
-            if (excelFile.exists()) {
-                excelFile.delete();
-            }
-            return failed(bean.getMessage());
         }
         return failed("上传失败");
     }