|
|
@@ -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;
|
|
|
- }
|
|
|
-
|
|
|
}
|