Browse Source

采购单详情增加附件下载

hejq 8 years ago
parent
commit
e221eea639

+ 38 - 81
src/main/java/com/uas/platform/b2b/controller/FileController.java

@@ -5,9 +5,14 @@ import com.uas.dfs.service.FileClient;
 import com.uas.platform.b2b.dao.AttachDao;
 import com.uas.platform.b2b.dao.CommonDao;
 import com.uas.platform.b2b.model.Attach;
+import com.uas.platform.b2b.model.PurchaseOrder;
+import com.uas.platform.b2b.model.PurchaseOrderAll;
+import com.uas.platform.b2b.model.PurchaseOrderAllItem;
 import com.uas.platform.b2b.service.AttachService;
+import com.uas.platform.b2b.service.PurchaseOrderService;
 import com.uas.platform.b2b.support.HttpUtils;
 import com.uas.platform.b2b.temporary.model.FileUrl;
+import com.uas.platform.core.exception.NotFoundException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.ui.ModelMap;
 import org.springframework.util.CollectionUtils;
@@ -38,10 +43,10 @@ public class FileController {
 	private FileClient fileClient;
 
 	@Autowired
-    private CommonDao commonDao;
+    private PurchaseOrderService purchaseOrderService;
 
 	@Autowired
-    private AttachDao attachDao;
+    private CommonDao commonDao;
 
 	/**
 	 * 文件下载
@@ -65,7 +70,7 @@ public class FileController {
 			OutputStream os = response.getOutputStream();
 			os.write(fileBytes);
 			os.close();
-		} else if(path.startsWith("http://") || path.startsWith("https://") || path.startsWith("ftp://") || path.startsWith("sftp://")) {
+		} else if (path.startsWith("http://") || path.startsWith("https://") || path.startsWith("ftp://") || path.startsWith("sftp://")) {
 			// 存放在其他网络资源中,直接跳转至链接地址
 			response.sendRedirect(path);
 		} else {
@@ -88,87 +93,39 @@ public class FileController {
 	}
 
     /**
-     * 更新文件路径到文件服务器
-     *
-     * @return
+     * 文件批量下载
+     * @param id id是采购单的id,因为这里需要进行处理
      */
-	@RequestMapping(value = "/refreshPath", method = RequestMethod.GET)
-    public ModelMap refreshpath() throws IOException {
-	    ModelMap map = new ModelMap();
-	    List<Long> successIds = new ArrayList<Long>();
-        List<Long> failedIds = new ArrayList<Long>();
-        convertPath(successIds, failedIds);
-        map.put("successIds", successIds);
-        map.put("failedIds", failedIds);
-        return map;
-    }
-
-    /**
-     * 递归更新所有附件信息
-     *
-     * @param successIds
-     * @param failedIds
-     */
-    public void convertPath(List<Long> successIds, List<Long> failedIds) {
-        List<Attach> attaches = new ArrayList<Attach>();
-        String sql = "select at_id as \"id\",at_path path,at_size as \"size\",at_name as \"name\" from attachs where at_path like '/usr/local/wildfly8/%' and nvl(at_status, ' ')<>'failure' and rownum <= 50";
-        attaches = commonDao.query(sql, Attach.class);
-        if(!CollectionUtils.isEmpty(attaches)) {
-            for(Attach attach : attaches) {
-                String path = null;
-                String filePath = "E:\\file\\" + attach.getPath();//下载到本地再进行更新处理
-                File file = new File(filePath);
-                if(file.exists()) {
-                    String name = attach.getName().substring(attach.getName().indexOf(".") + 1, attach.getName().length());
-                    try {
-                        InputStream in = new FileInputStream(filePath);
-                        HttpUtils.Response response = HttpUtils.upload(FileUrl.FILE_UPLOAD, filePath, null);
-                        JSONObject obj = JSONObject.parseObject(response.getResponseText());
-                        path = (String) obj.get("path");
-                    } catch (IOException e) {
-                        failedIds.add(attach.getId());
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                    }
-
-                    if(path != null) {
-                        // update
-                        sql = "update attachs set at_path = '" + path +"',at_status = 'success' where at_id = " + attach.getId();
-                        commonDao.getJdbcTemplate().update(sql);
-                        successIds.add(attach.getId());
-                    } else {
-                        // 上传失败更新状态为failure
-                        sql = "update attachs set at_status = 'failure' where at_id = " + attach.getId();
-                        commonDao.getJdbcTemplate().update(sql);
-                        failedIds.add(attach.getId());
+    @RequestMapping("/batch/{id}")
+    public void batchDownload(@PathVariable("id") long id, HttpServletResponse response) throws IOException {
+        PurchaseOrderAll orderAll = purchaseOrderService.findById(id);
+       String sql = " select at_path path from attachs left join purc$prod$attach on attachs.at_id = purc$prod$attach.at_id " +
+               "left join purc$orderitems on purc$orderitems.pd_id = purc$prod$attach.pd_id where purc$orderitems.pd_puid = " + id;
+       List<Attach> attaches = commonDao.query(sql, Attach.class);
+       StringBuffer idString = null;
+       String url = null;
+       if (!CollectionUtils.isEmpty(attaches)) {
+           for (Attach attach : attaches) {
+               if (attach.getPath().startsWith("http://dfs.ubtob.com")) {// 存储在dfs存储服务器,去dfs存储服务器下载
+                // TODO dfs服务器上打包下载
+               } else if (attach.getPath().startsWith("http://") || attach.getPath().startsWith("https://") || attach.getPath().startsWith("ftp://") || attach.getPath().startsWith("sftp://")) {
+                    if (idString.length() > 0) {
+                        idString.append(";");
                     }
-                }
-
-            }
-            convertPath(successIds, failedIds);
-        }
+                    JSONObject jsonObject = JSONObject.parseObject(attach.getPath());
+                    String atId = jsonObject.get("id").toString();
+                    idString.append(atId);
+                    // 各个ERP对应的路径不一样,采用将单个文件下载路径替换成批量文件下载路径的方法
+                    url = attach.getPath().replace("downloadbyId.action?id=", "downloadbyIds.action?ids=");
+               }
+           }
+       } else {
+           throw new NotFoundException("暂未找到相关附件");
+       }
+       if (idString.length() > 0 && null != url && null != orderAll) {
+           response.sendRedirect(url + idString + "&zipName=" + orderAll.getCode() + "采购明细附件");
+       }
     }
 
 
-    @RequestMapping(value = "/test", method = RequestMethod.GET)
-    public ModelMap  getPath() throws IOException {
-        return new ModelMap("path", getAttachCode());
-    }
-
-    @SuppressWarnings("resource")
-    private String getAttachCode() throws FileNotFoundException, IOException {
-        String path = "E:\\file\\test\\11.jpg";// 文件路径
-        InputStream in = new FileInputStream(path);
-        ByteArrayOutputStream output = new ByteArrayOutputStream();
-        byte[] buffer = new byte[1024];
-        int len = 0;
-        while( (len=in.read(buffer)) != -1 ){
-            output.write(buffer, 0, len);
-        }
-        in.close();
-        byte[] imgByte = output.toByteArray();
-        path = fileClient.upload(imgByte, 373760, "jpg", null);
-        return path;
-    }
-
 }

+ 11 - 3
src/main/webapp/resources/js/index/app.js

@@ -1,6 +1,6 @@
-define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives', 'service/Purc', 'service/Make', 'service/Fa', 'service/Account', 'service/Alert', 'service/CheckTel', 'ui.router', 'ui.bootstrap', 'file-upload', 'ngSanitize', 'service/BaseInfo', 'service/Cart', 'service/ApprovalFlow', 'service/DeputyOrder', 'service/Product', 'service/Token', 'service/ProductUsers'], function () {
+define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives', 'service/Purc', 'service/Make', 'service/Fa', 'service/Account', 'service/Alert', 'service/CheckTel', 'ui.router', 'ui.bootstrap', 'file-upload', 'ngSanitize', 'service/BaseInfo', 'service/Cart', 'service/ApprovalFlow', 'service/DeputyOrder', 'service/Product', 'service/Token', 'service/ProductUsers', 'service/File'], function () {
     'use strict';
-    var app = angular.module('myApp', ['toaster', 'angularCharts', 'ngTable', 'ui.router', 'common.services', 'common.directives', 'PurcServices', 'MakeServices', 'FaServices', 'AccountServices', 'AlertServices', 'ui.bootstrap', 'angularFileUpload', 'ngSanitize', 'CheckTelModule', 'ProductServices', 'CartServices', 'ApprvoalFlowService', 'DeputyOrderService', 'ProductInfoServices', 'TokenService', 'ProductUserService', 'ui.tour']);
+    var app = angular.module('myApp', ['toaster', 'angularCharts', 'ngTable', 'ui.router', 'common.services', 'common.directives', 'PurcServices', 'MakeServices', 'FaServices', 'AccountServices', 'AlertServices', 'ui.bootstrap', 'angularFileUpload', 'ngSanitize', 'CheckTelModule', 'ProductServices', 'CartServices', 'ApprvoalFlowService', 'DeputyOrderService', 'ProductInfoServices', 'TokenService', 'ProductUserService', 'ui.tour', 'FileService']);
     app.init = function () {
         angular.bootstrap(document, ['myApp']);
     };
@@ -3377,7 +3377,7 @@ define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
         }
     }]);
 
-    app.controller('SaleOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', 'CurrentRole', 'token',function ($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService, CurrentRole, token) {
+    app.controller('SaleOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', 'CurrentRole', 'token', 'file', function ($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService, CurrentRole, token, file) {
         // 获取当前用户是否为普通用户
         CurrentRole.isUser({}, {}, function (data) {
             $scope.isUser = data.isUser;
@@ -3492,6 +3492,14 @@ define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
                 }
             }
         };
+
+        $scope.fileDownload = function (id) {
+            file.batch({id: id}, {}, function (data) {
+
+            }, function (res) {
+                toaster.pop('error', '错误', "暂未找到相关附件");
+            });
+        }
     }]);
     app.controller('SaleChangeCtrl', ['$scope', '$filter', 'PurcChange', 'PurcChanges', 'ngTableParams', 'toaster', 'BaseService', 'PurcChangeHis', 'CurrentRole', function ($scope, $filter, PurcChange, PurcChanges, ngTableParams, toaster, BaseService, PurcChangeHis, CurrentRole) {
         BaseService.scrollBackToTop();

+ 9 - 0
src/main/webapp/resources/js/index/services/File.js

@@ -0,0 +1,9 @@
+define([ 'ngResource'], function() {
+    angular.module('FileService', [ 'ngResource']).factory('file', ['$resource', function($resource) {
+        return $resource('file', {}, {
+            batch: {
+                url: 'file/batch/:id'
+            }
+        })
+    }])
+});

+ 4 - 0
src/main/webapp/resources/tpl/index/sale/order_detail.html

@@ -6,6 +6,7 @@
 		<span>客户采购单</span>
 		<div class="p-right">
 			<a ng-click="print(order)" class="pull-right text-simple"><i class="fa fa-print fa-fw"></i>打印</a>
+            <a ng-click="fileDownload(order.id)" class="pull-right text-simple"><i class="fa fa-file fa-fw"></i>附件下载</a>
 		</div>
 	</div>
 	<div class="pane-body">
@@ -118,6 +119,9 @@
 							<div class="text-muted text-bold" ng-if="item.vendspec"><span ng-bind="::item.vendspec"></span></div>
 							<div class="text-bold text-inverse" ng-if="item.factory">送货工厂:<span ng-bind="::item.factory"></span></div>
 							<div class="text-bold text-inverse" ng-if="item.remark">备注:<span ng-bind="::item.remark"></span></div>
+							<div ng-repeat="att in item.attachs" class="text-bold text-bold">
+								<a href="file/{{att.id}}">{{att.name}}</a>
+							</div>
 						</td>
 						<td class="text-center" width="80">
 							<div ng-if="!isUser" class="text-num" ng-bind="::item.price | number:6"></div>