diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/riskbusiness/RiskFileMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/riskbusiness/RiskFileMapper.java new file mode 100644 index 000000000..6120db3cd --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/riskbusiness/RiskFileMapper.java @@ -0,0 +1,18 @@ +package au.com.royalpay.payment.manage.mappers.riskbusiness; + +import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper; +import cn.yixblog.support.mybatis.autosql.annotations.AutoSql; +import cn.yixblog.support.mybatis.autosql.annotations.SqlType; +import com.alibaba.fastjson.JSONObject; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@AutoMapper(tablename = "risk_file", pkName = "file_id") +public interface RiskFileMapper { + @AutoSql(type= SqlType.INSERT) + void save(JSONObject file); + + @AutoSql(type= SqlType.SELECT) + List findAllFiles(@Param("material_id") String material_id); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/riskbusiness/RiskMaterialMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/riskbusiness/RiskMaterialMapper.java index 0c4731b95..f5e9f5b9f 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/riskbusiness/RiskMaterialMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/riskbusiness/RiskMaterialMapper.java @@ -1,12 +1,12 @@ package au.com.royalpay.payment.manage.mappers.riskbusiness; -import cn.yixblog.support.mybatis.autosql.annotations.AdvanceSelect; + import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper; import cn.yixblog.support.mybatis.autosql.annotations.AutoSql; import cn.yixblog.support.mybatis.autosql.annotations.SqlType; import com.alibaba.fastjson.JSONObject; import org.apache.ibatis.annotations.Param; -import org.apache.catalina.LifecycleState; + import java.util.List; @@ -15,8 +15,6 @@ public interface RiskMaterialMapper { @AutoSql(type = SqlType.INSERT) void save(JSONObject material); - JSONObject findOperatorById(@Param("risk_id") String risk_id); - - List getRiskMaterial(JSONObject param); + List findAllMaterials(@Param("risk_id") String risk_id); } diff --git a/src/main/java/au/com/royalpay/payment/manage/riskbusiness/core/impl/RiskBusinessServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/riskbusiness/core/impl/RiskBusinessServiceImpl.java index a84fca14d..7aca9ccf3 100644 --- a/src/main/java/au/com/royalpay/payment/manage/riskbusiness/core/impl/RiskBusinessServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/riskbusiness/core/impl/RiskBusinessServiceImpl.java @@ -4,6 +4,7 @@ import au.com.royalpay.payment.core.exceptions.EmailException; import au.com.royalpay.payment.core.exceptions.InvalidShortIdException; import au.com.royalpay.payment.manage.mappers.payment.OrderMapper; import au.com.royalpay.payment.manage.mappers.riskbusiness.RiskEventMapper; +import au.com.royalpay.payment.manage.mappers.riskbusiness.RiskFileMapper; import au.com.royalpay.payment.manage.mappers.riskbusiness.RiskMaterialMapper; import au.com.royalpay.payment.manage.mappers.system.ClientMapper; import au.com.royalpay.payment.manage.mappers.system.ClientBDMapper; @@ -34,16 +35,11 @@ import org.thymeleaf.context.Context; import org.thymeleaf.spring4.SpringTemplateEngine; import javax.servlet.http.HttpServletResponse; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.math.BigDecimal; +import java.io.*; import java.net.URL; import java.util.ArrayList; import java.util.Date; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.Date; import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -78,6 +74,8 @@ public class RiskBusinessServiceImpl implements RiskBusinessService { @Autowired private RiskMaterialMapper riskMaterialMapper; + @Resource + private RiskFileMapper riskFileMapper; @Override public List getRiskEvents(JSONObject params) { @@ -171,19 +169,19 @@ public class RiskBusinessServiceImpl implements RiskBusinessService { response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment;filename=" + downloadFilename); ZipOutputStream zos = new ZipOutputStream(response.getOutputStream()); - String filePath = null; - for (int i = 1; i <= 10; i++) { - filePath = riskMaterial.getString("file" + i + "_url"); - if (filePath != null) { - // 文件名前添加'file' + i是为了防止文件名一样 - zos.putNextEntry(new ZipEntry("file" + i + filePath.substring(filePath.lastIndexOf("/")))); - InputStream inputStream = new URL(filePath).openConnection().getInputStream(); - byte[] buffer = new byte[1024]; - int result = 0; - while ((result = inputStream.read(buffer)) != -1) { - zos.write(buffer, 0, result); + for(int i=1;i<=6;i++){ + if(riskMaterial.containsKey("file"+i)){ + List fileList= (List)riskMaterial.get("file"+i); + for(String fileUrl : fileList){ + zos.putNextEntry(new ZipEntry("file" + i+fileUrl.substring(fileUrl.lastIndexOf("/")))); + InputStream inputStream = new URL(fileUrl).openConnection().getInputStream(); + byte[] buffer = new byte[1024]; + int result = 0; + while ((result = inputStream.read(buffer)) != -1) { + zos.write(buffer, 0, result); + } + inputStream.close(); } - inputStream.close(); } } zos.flush(); @@ -201,12 +199,14 @@ public class RiskBusinessServiceImpl implements RiskBusinessService { final List emailsCcs = ctx.getVariable("emailsCcs")==null?new ArrayList<>():(List)ctx.getVariable("emailsCcs"); final String title = (String)ctx.getVariable("title"); final String content = thymeleaf.process("mail/risk_upload_mail.html", ctx); + final String uploadUrl = (String)ctx.getVariable("uploadUrl"); royalThreadPoolExecutor.execute(() -> { try { String emailId = mailService.sendRiskEmail(title, emailsTos.isEmpty() ? "" : StringUtils.join(emailsTos, ","), emailsCcs.isEmpty() ? "" : StringUtils.join(emailsCcs, ","), content, event.getIntValue("order_type")==3?(List)ctx.getVariable("files"):null,event.getIntValue("order_type")); event.put("email_status",1); event.put("result_type", RiskResultTypeEnum.SEND_EMAIL_TO_BD.getResultType()); + event.put("submit_url",uploadUrl); Integer orderType = event.getInteger("order_type"); if (orderType == RiskOrderTypeEnum.WARNING_ORDER.getOrderType()) { event.put("result_type", RiskResultTypeEnum.ALREADY_HANDLED.getResultType()); @@ -225,6 +225,7 @@ public class RiskBusinessServiceImpl implements RiskBusinessService { ctx.setVariable("refuse",true); final List emailsTos = (List)ctx.getVariable("emailsTos"); final List emailsCcs = ctx.getVariable("emailsCcs")==null?new ArrayList<>():(List)ctx.getVariable("emailsCcs"); + final String uploadUrl = (String)ctx.getVariable("uploadUrl"); final String content = thymeleaf.process("mail/risk_upload_mail.html", ctx); royalThreadPoolExecutor.execute(() -> { try { @@ -232,6 +233,7 @@ public class RiskBusinessServiceImpl implements RiskBusinessService { emailsCcs.isEmpty() ? "" : StringUtils.join(emailsCcs, ","), content, event.getIntValue("order_type")==3?(List)ctx.getVariable("files"):null,event.getIntValue("order_type")); event.put("email_status",2); event.put("result_type",RiskResultTypeEnum.MATERIAL_NOT_PASS.getResultType()); + event.put("submit_url",uploadUrl); riskEventMapper.update(event); } catch (Exception e) { throw new EmailException("Email Sending Failed", e); @@ -339,9 +341,26 @@ public class RiskBusinessServiceImpl implements RiskBusinessService { @Override public JSONObject getRiskMaterial(JSONObject param) { - List riskMaterialList = riskMaterialMapper.getRiskMaterial(param); - if (riskMaterialList != null && riskMaterialList.size() > 0) - return riskMaterialList.get(0); + List riskMaterialList = riskMaterialMapper.findAllMaterials(param.getString("risk_id")); + if (riskMaterialList != null && riskMaterialList.size() > 0){ + List files = riskFileMapper.findAllFiles(riskMaterialList.get(0).getString("material_id")); + JSONObject fileNew = new JSONObject(); + fileNew.put("description",riskMaterialList.get(0).getString("description")); + for(JSONObject file : files){ + int fileType = file.getIntValue("file_type"); + if(!fileNew.containsKey("file"+fileType)){ + List fileList = new ArrayList<>(); + fileList.add(file.getString("file_url")); + fileNew.put("file"+fileType,fileList); + }else{ + List fileList = (List)fileNew.get("file"+fileType); + fileList.add(file.getString("file_url")); + fileNew.put("file"+fileType,fileList); + } + } + return fileNew; + } + return null; } diff --git a/src/main/java/au/com/royalpay/payment/manage/riskbusiness/core/impl/RiskUploadServiceIpml.java b/src/main/java/au/com/royalpay/payment/manage/riskbusiness/core/impl/RiskUploadServiceIpml.java index 1d0f4e945..17133ae4a 100644 --- a/src/main/java/au/com/royalpay/payment/manage/riskbusiness/core/impl/RiskUploadServiceIpml.java +++ b/src/main/java/au/com/royalpay/payment/manage/riskbusiness/core/impl/RiskUploadServiceIpml.java @@ -2,6 +2,7 @@ package au.com.royalpay.payment.manage.riskbusiness.core.impl; import au.com.royalpay.payment.core.exceptions.EmailException; import au.com.royalpay.payment.manage.mappers.riskbusiness.RiskEventMapper; +import au.com.royalpay.payment.manage.mappers.riskbusiness.RiskFileMapper; import au.com.royalpay.payment.manage.mappers.riskbusiness.RiskMaterialMapper; import au.com.royalpay.payment.manage.mappers.system.ClientMapper; import au.com.royalpay.payment.manage.notice.core.MailService; @@ -22,50 +23,39 @@ import org.thymeleaf.spring4.SpringTemplateEngine; import javax.annotation.Resource; import java.text.ParseException; import java.util.Date; +import java.util.List; @Service public class RiskUploadServiceIpml implements RiskUploadService { @Resource private RiskMaterialMapper riskMaterialMapper; @Resource - private RiskEventMapper riskEventMapper; + private RiskFileMapper riskFileMapper; @Resource - private ClientMapper clientMapper; + private RiskEventMapper riskEventMapper; @Resource private StringRedisTemplate stringRedisTemplate; - @Resource - private MailService mailService; - @Resource - private RoyalThreadPoolExecutor royalThreadPoolExecutor; - @Resource - private SpringTemplateEngine thymeleaf; private final String UPLOAD_MAIL_PREFIX = "UPLOAD_MAIL"; @Override public void submitMaterial(JSONObject material) { - riskMaterialMapper.save(material); JSONObject event = riskEventMapper.findById(material.getString("risk_id")); + riskMaterialMapper.save(material); + material.put("material_id",riskMaterialMapper.findAllMaterials(material.getString("risk_id")).get(0).getString("material_id")); + for(int i=1;i<=10;i++){ + if(material.containsKey("file"+i+"_url")){ + List urls = (List)material.get("file"+i+"_url"); + for(String url:urls){ + JSONObject file = new JSONObject(); + file.put("file_url",url); + file.put("file_type",i); + file.put("material_id",material.getString("material_id")); + riskFileMapper.save(file); + } + } + } event.put("result_type", RiskResultTypeEnum.WAIT_FOR_AUDIT.getResultType()); riskEventMapper.update(event); - JSONObject operator = riskMaterialMapper.findOperatorById(material.getString("risk_id")); - if(operator.containsKey("email")){ - JSONObject client = clientMapper.findClientByMoniker(event.getString("client_moniker")); - Context ctx = new Context(); - ctx.setVariable("client_moniker", event.getString("client_moniker")); - ctx.setVariable("short_name", client.getString("short_name")); - ctx.setVariable("create_time", DateFormatUtils.format(event.getDate("create_time"),"yyyy-MM-dd HH:mm:ss")); - ctx.setVariable("operator", operator.getString("display_name")); - final String content = thymeleaf.process("mail/risk_operator_notice", ctx); - royalThreadPoolExecutor.execute(() -> { - try { - String emailId = mailService.sendRiskEmail(event.getString("client_moniker")+" has submitted the material",operator.getString("email") , - "", content, null,event.getIntValue("order_type")); - } catch (Exception e) { - throw new EmailException("Email Sending Failed", e); - } - }); - } - } @Override diff --git a/src/main/java/au/com/royalpay/payment/manage/riskbusiness/web/RiskBusinessController.java b/src/main/java/au/com/royalpay/payment/manage/riskbusiness/web/RiskBusinessController.java index 3ebc945a5..1b635203e 100644 --- a/src/main/java/au/com/royalpay/payment/manage/riskbusiness/web/RiskBusinessController.java +++ b/src/main/java/au/com/royalpay/payment/manage/riskbusiness/web/RiskBusinessController.java @@ -84,7 +84,6 @@ public class RiskBusinessController { public JSONObject getRiskMaterial(@PathVariable("risk_id") String riskId) { JSONObject param = new JSONObject(); param.put("risk_id", riskId); - param.put("orderby_type", "update_time"); return riskBusinessService.getRiskMaterial(param); } diff --git a/src/main/java/au/com/royalpay/payment/manage/riskbusiness/web/RiskFileUploadController.java b/src/main/java/au/com/royalpay/payment/manage/riskbusiness/web/RiskFileUploadController.java index b60ab662f..87099d74a 100644 --- a/src/main/java/au/com/royalpay/payment/manage/riskbusiness/web/RiskFileUploadController.java +++ b/src/main/java/au/com/royalpay/payment/manage/riskbusiness/web/RiskFileUploadController.java @@ -1,5 +1,6 @@ package au.com.royalpay.payment.manage.riskbusiness.web; +import au.com.royalpay.payment.manage.riskbusiness.core.RiskBusinessService; import au.com.royalpay.payment.manage.riskbusiness.core.RiskUploadService; import com.alibaba.fastjson.JSONObject; import org.springframework.web.bind.annotation.*; @@ -12,6 +13,8 @@ import javax.annotation.Resource; public class RiskFileUploadController { @Resource private RiskUploadService riskUploadService; + @Resource + private RiskBusinessService riskBusinessService; /** * 上传材料的链接 @@ -23,9 +26,12 @@ public class RiskFileUploadController { public ModelAndView jumpVerifyMail(@PathVariable String codeKey, @PathVariable String risk_id) { //检查codekey是否有效 riskUploadService.checkUploadMailKey(codeKey,risk_id); + JSONObject event = riskBusinessService.getRiskEventDetail(risk_id); ModelAndView view = new ModelAndView("mail/risk_upload"); view.addObject("codeKey", codeKey); view.addObject("risk_id",risk_id); + view.addObject("order_type",event.getIntValue("order_type")); + view.addObject("short_name",event.getJSONObject("clientInfo").getString("short_name")); return view; } diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/riskbusiness/RiskMaterialMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/riskbusiness/RiskMaterialMapper.xml index fffa7aa0a..9a46cbd81 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/riskbusiness/RiskMaterialMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/riskbusiness/RiskMaterialMapper.xml @@ -12,35 +12,9 @@ LIMIT 1 - - - - - - - - - - - - - - - - - SELECT * - from risk_material - - - AND material_id = #{material_id} - - - AND risk_id = #{risk_id} - - - - ORDER BY ${orderby_type} DESC - + FROM risk_material + ORDER BY update_time DESC - \ No newline at end of file + diff --git a/src/main/resources/templates/mail/risk_upload.html b/src/main/resources/templates/mail/risk_upload.html index a80e0c1c8..87b76bbe3 100644 --- a/src/main/resources/templates/mail/risk_upload.html +++ b/src/main/resources/templates/mail/risk_upload.html @@ -32,6 +32,7 @@ +
Audit Files     Description:
-

+

+
+
+
+ +
+
+

2、用户购买虚拟物品需要提供聊天记录、订单信息、发货凭证截图、虚拟物品最终消费场景(例如何种游戏、软件)、提供消费场景网址/下载链接 + 要求:每笔交易对应的截图必须清晰可见
+ Users need to provide chat records, order information, screenshots of delivery documents, final consumption scenarios of virtual goods (such as games, software); provide consumer scene URL / download link. + Requirement: The screenshot corresponding to each transaction must be clearly visible. +

+

2.提供相应购物清单,订单小票(请提供与被查交易订单号相匹配的交易时间及金额的发票);
+ Provide related shopping lists, invoices. (Please provide the invoices, amount of which matches that of the abnormal transaction); +

+
+
+   
+
+ + + +
+
+ +
+
+
+

3、购物小票/发票存根照片 + 照片应清晰,必须显示商户名称、商户地址、购物时间、物品名称 + 购物金额等
+ Photos of shopping receipts/ invoice stubs + Requirement: The photos should be clear and must show Merchant name, Business address, Transaction time, Product information, Quantity purchased, etc. +

+

3.提供相应的发货证明,报关单(若有消费者在国内购买,请提供物流单据或报关单);
+ Relative proof of delivery, customs declaration (If the consumer purchased from China, please provide shipping receipt or customs declaration); +

+
+
+   
+
-
+
+
+

4、显示商户门牌号码和店头名称的照片 + 要求:清晰可见,至少一张
+ Photos of Merchant Street number & Merchant name + Requirement: At least one visible photo +

+

4.提供您的门店照片(门店照及店铺内的照片各一张, 一张可以看到商户名的门头照,一张可以看到相关商品或服务的店内照片);
+ Photos of the store ( one of each front-store and in-store); +

+
- -
-
- - -
+   
+
+ +
+
+
+

5、显示商户营业场景所场内部情况(如店内商品陈列、收银台等)的照片 + 要求:照片清晰,且能清楚显示商户实际售卖物品或服务,至少三张
+ Photos of internal environment of merchant business (such as in-store merchandise display, checkout counter, etc.) + Requirements: The photos (at least three) showing merchant activities including actual selling-goods or services obviously +

+

5.其他可以还原交易背景的资料,如和消费者的聊天记录等,来佐证被查单号交易的真实性;
+ Other materials that can verify the payment scenario, for example, chatting history, to prove the truth of the transactions; +

+
+
+   
+
+ + + +
+
+ +
+
+
+

6、其他图片
+ Other pictures +

+
+
+   
+
+ + + +
+
+
+ + + + + + + + + + +
diff --git a/src/main/ui/static/riskupload/risk_upload.js b/src/main/ui/static/riskupload/risk_upload.js index 8398b10e9..ed756391a 100644 --- a/src/main/ui/static/riskupload/risk_upload.js +++ b/src/main/ui/static/riskupload/risk_upload.js @@ -1,182 +1,150 @@ // define(['angular', 'static/commons/commons', 'uiBootstrap', 'uiRouter', 'ngBootSwitch', 'ngFileUpload'], function (angular) { // 'use strict'; - var app = angular.module('riskUploadApp',['ngFileUpload']); + var app = angular.module('riskUploadApp',['ngFileUpload','ui.bootstrap']); app.controller('riskUploadCtrl', ['$scope','$http','Upload','$filter',function ($scope,$http,Upload,$filter) { $scope.material={}; $scope.codeKey=document.getElementById('codeKey').value; $scope.material.risk_id=document.getElementById('risk_id').value; + $scope.order_type=document.getElementById('order_type').value; $scope.material.update_time=$filter('date')(new Date(), 'yyyy-MM-dd HH:mm:ss'); - $scope.uploadFile1 = function (file) { - if (file != null) { + $scope.uploadFile1 = function (files) { + if (files && files.length) { + var urls = new Array(); + var value = 0; $scope.file1Progress = {value: 0}; - Upload.upload({ - url: '/attachment/riskFiles', - data: {file: file} - }).then(function (resp) { - delete $scope.file1Progress; - $scope.material.file1_url = resp.data.url; - }, function (resp) { - delete $scope.file1Progress; - commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) - }, function (evt) { - $scope.file1Progress.value = parseInt(100 * evt.loaded / evt.total); - }) + for (var i = 0; i < files.length; i++) { + var file = files[i]; + Upload.upload({ + url: '/attachment/riskFiles', + data: {file: file} + }).then(function (resp) { + urls.push(resp.data.url); + }, function (resp) { + delete $scope.file1Progress; + alert('Upload Failed'); + }, function (evt) { + value += parseInt(100 * evt.loaded / evt.total ); + $scope.file1Progress.value = value/(files.length*2); + }) + } + $scope.material.file1_url = urls; } }; - $scope.uploadFile2 = function (file) { - if (file != null) { + $scope.uploadFile2 = function (files) { + if (files && files.length) { + var urls = new Array(); + var value = 0; $scope.file2Progress = {value: 0}; - Upload.upload({ - url: '/attachment/riskFiles', - data: {file: file} - }).then(function (resp) { - delete $scope.file2Progress; - $scope.material.file2_url = resp.data.url; - }, function (resp) { - delete $scope.file2Progress; - commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) - }, function (evt) { - $scope.file2Progress.value = parseInt(100 * evt.loaded / evt.total); - }) + for (var i = 0; i < files.length; i++) { + var file = files[i]; + Upload.upload({ + url: '/attachment/riskFiles', + data: {file: file} + }).then(function (resp) { + urls.push(resp.data.url); + }, function (resp) { + delete $scope.file2Progress; + alert('Upload Failed'); + }, function (evt) { + value += parseInt(100 * evt.loaded / evt.total ); + $scope.file2Progress.value = value/(files.length*2); + }) + } + $scope.material.file2_url = urls; } }; - $scope.uploadFile3 = function (file) { - if (file != null) { + $scope.uploadFile3 = function (files) { + if (files && files.length) { + var urls = new Array(); + var value = 0; $scope.file3Progress = {value: 0}; - Upload.upload({ - url: '/attachment/riskFiles', - data: {file: file} - }).then(function (resp) { - delete $scope.file3Progress; - $scope.material.file3_url = resp.data.url; - }, function (resp) { - delete $scope.file3Progress; - commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) - }, function (evt) { - $scope.file3Progress.value = parseInt(100 * evt.loaded / evt.total); - }) + for (var i = 0; i < files.length; i++) { + var file = files[i]; + Upload.upload({ + url: '/attachment/riskFiles', + data: {file: file} + }).then(function (resp) { + urls.push(resp.data.url); + }, function (resp) { + delete $scope.file3Progress; + alert('Upload Failed'); + }, function (evt) { + value += parseInt(100 * evt.loaded / evt.total ); + $scope.file3Progress.value = value/(files.length*2); + }) + } + $scope.material.file3_url = urls; } }; - $scope.uploadFile4 = function (file) { - if (file != null) { + $scope.uploadFile4 = function (files) { + if (files && files.length) { + var urls = new Array(); + var value = 0; $scope.file4Progress = {value: 0}; - Upload.upload({ - url: '/attachment/riskFiles', - data: {file: file} - }).then(function (resp) { - delete $scope.file4Progress; - $scope.material.file4_url = resp.data.url; - }, function (resp) { - delete $scope.file4Progress; - commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) - }, function (evt) { - $scope.file4Progress.value = parseInt(100 * evt.loaded / evt.total); - }) + for (var i = 0; i < files.length; i++) { + var file = files[i]; + Upload.upload({ + url: '/attachment/riskFiles', + data: {file: file} + }).then(function (resp) { + urls.push(resp.data.url); + }, function (resp) { + delete $scope.file4Progress; + alert('Upload Failed'); + }, function (evt) { + value += parseInt(100 * evt.loaded / evt.total ); + $scope.file4Progress.value = value/(files.length*2); + }) + } + $scope.material.file4_url = urls; } }; - $scope.uploadFile5 = function (file) { - if (file != null) { + $scope.uploadFile5 = function (files) { + if (files && files.length) { + var urls = new Array(); + var value = 0; $scope.file5Progress = {value: 0}; - Upload.upload({ - url: '/attachment/riskFiles', - data: {file: file} - }).then(function (resp) { - delete $scope.file5Progress; - $scope.material.file5_url = resp.data.url; - }, function (resp) { - delete $scope.file5Progress; - commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) - }, function (evt) { - $scope.file5Progress.value = parseInt(100 * evt.loaded / evt.total); - }) + for (var i = 0; i < files.length; i++) { + var file = files[i]; + Upload.upload({ + url: '/attachment/riskFiles', + data: {file: file} + }).then(function (resp) { + urls.push(resp.data.url); + }, function (resp) { + delete $scope.file5Progress; + alert('Upload Failed'); + }, function (evt) { + value += parseInt(100 * evt.loaded / evt.total ); + $scope.file5Progress.value = value/(files.length*2); + }) + } + $scope.material.file5_url = urls; } }; - $scope.uploadFile6 = function (file) { - if (file != null) { + $scope.uploadFile6 = function (files) { + if (files && files.length) { + var urls = new Array(); + var value = 0; $scope.file6Progress = {value: 0}; - Upload.upload({ - url: '/attachment/riskFiles', - data: {file: file} - }).then(function (resp) { - delete $scope.file6Progress; - $scope.material.file6_url = resp.data.url; - }, function (resp) { - delete $scope.file6Progress; - commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) - }, function (evt) { - $scope.file6Progress.value = parseInt(100 * evt.loaded / evt.total); - }) - } - }; - - $scope.uploadFile7 = function (file) { - if (file != null) { - $scope.file7Progress = {value: 0}; - Upload.upload({ - url: '/attachment/riskFiles', - data: {file: file} - }).then(function (resp) { - delete $scope.file7Progress; - $scope.material.file7_url = resp.data.url; - }, function (resp) { - delete $scope.file7Progress; - commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) - }, function (evt) { - $scope.file7Progress.value = parseInt(100 * evt.loaded / evt.total); - }) - } - }; - $scope.uploadFile8 = function (file) { - if (file != null) { - $scope.file8Progress = {value: 0}; - Upload.upload({ - url: '/attachment/riskFiles', - data: {file: file} - }).then(function (resp) { - delete $scope.file8Progress; - $scope.material.file8_url = resp.data.url; - }, function (resp) { - delete $scope.file8Progress; - commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) - }, function (evt) { - $scope.file8Progress.value = parseInt(100 * evt.loaded / evt.total); - }) - } - }; - $scope.uploadFile9 = function (file) { - if (file != null) { - $scope.file9Progress = {value: 0}; - Upload.upload({ - url: '/attachment/riskFiles', - data: {file: file} - }).then(function (resp) { - delete $scope.file9Progress; - $scope.material.file9_url = resp.data.url; - }, function (resp) { - delete $scope.file9Progress; - commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) - }, function (evt) { - $scope.file9Progress.value = parseInt(100 * evt.loaded / evt.total); - }) - } - }; - $scope.uploadFile10 = function (file) { - if (file != null) { - $scope.file10Progress = {value: 0}; - Upload.upload({ - url: '/attachment/riskFiles', - data: {file: file} - }).then(function (resp) { - delete $scope.file10Progress; - $scope.material.file10_url = resp.data.url; - }, function (resp) { - delete $scope.file10Progress; - commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) - }, function (evt) { - $scope.file10Progress.value = parseInt(100 * evt.loaded / evt.total); - }) + for (var i = 0; i < files.length; i++) { + var file = files[i]; + Upload.upload({ + url: '/attachment/riskFiles', + data: {file: file} + }).then(function (resp) { + urls.push(resp.data.url); + }, function (resp) { + delete $scope.file6Progress; + alert('Upload Failed'); + }, function (evt) { + value += parseInt(100 * evt.loaded / evt.total ); + $scope.file6Progress.value = value/(files.length*2); + }) + } + $scope.material.file6_url = urls; } }; $scope.submit = function (form) { @@ -190,7 +158,8 @@ }); } - }]) + }]); +