Browse Source

自动询价发送邮件通知,建立供应商关系,并且供应商注册后自动传回ERP同步更新供应商信息;

hejq 8 years ago
parent
commit
1c8b0ee878

+ 127 - 19
src/main/java/com/uas/platform/b2b/controller/FileController.java

@@ -1,21 +1,25 @@
 package com.uas.platform.b2b.controller;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import javax.servlet.http.HttpServletResponse;
-
+import com.alibaba.fastjson.JSONObject;
 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.service.AttachService;
+import com.uas.platform.b2b.support.FileUploadHttp;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.ui.ModelMap;
+import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.client.RestTemplate;
 
-import com.uas.platform.b2b.model.Attach;
-import com.uas.platform.b2b.service.AttachService;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * 平台文件
@@ -33,6 +37,12 @@ public class FileController {
 	@Autowired
 	private FileClient fileClient;
 
+	@Autowired
+    private CommonDao commonDao;
+
+	@Autowired
+    private AttachDao attachDao;
+
 	/**
 	 * 文件下载
 	 * 
@@ -62,16 +72,114 @@ public class FileController {
 			// 其他的当做是存放在本地服务器上,去本地服务器根据文件路径去获取
 			File file = new File(attach.getPath());
 			if(!file.exists()) throw new IllegalArgumentException("附件不存在");
-			response.addHeader("Content-Length", String.valueOf(file.length()));
-			InputStream in = new FileInputStream(file);
-			OutputStream os = response.getOutputStream();
-			int data = 0;
-			while ((data = in.read()) != -1) {
-				os.write(data);
-			}
-			in.close();
-			os.close();
+            InputStream in = new FileInputStream(path);
+            OutputStream os = response.getOutputStream();
+            response.addHeader("Content-Disposition", "attachment;filename=" + new String(attach.getName().getBytes("utf-8"), "iso-8859-1"));
+            response.addHeader("Content-Length", String.valueOf(file.length()));
+            response.setCharacterEncoding("utf-8");
+            response.setContentType("application/octec-stream");
+            int data = 0;
+            while ((data = in.read()) != -1) {
+                os.write(data);
+            }
+            in.close();
+            os.close();
 		}
 	}
 
+    /**
+     * 更新文件路径到文件服务器
+     *
+     * @return
+     */
+	@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);
+                        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+                        byte[] buffer = new byte[1024];
+                        int len = 0;
+                        while( (len=in.read(buffer)) != -1 ){
+                            outStream.write(buffer, 0, len);
+                        }
+                        in.close();
+                        path = fileClient.upload(outStream.toByteArray(), attach.getSize(), name, null);
+//                        FileUploadHttp.Response response = FileUploadHttp.upload(null, filePath, null);
+//                        if (response.getStatusCode() == 200) {
+//                            JSONObject obj = JSONObject.parseObject(response.getResponseText());
+//                            if(obj.get("path").toString() != null) path = obj.get("path").toString();
+//                        }
+                    } 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());
+                    }
+                }
+
+            }
+            convertPath(successIds, failedIds);
+        }
+    }
+
+
+    @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 URLDecoder.decode(Base64.toBase64String(imgByte), "UTF-8");
+        return path;
+    }
+
 }

+ 31 - 0
src/main/java/com/uas/platform/b2b/v2/controller/PartnerShipController.java

@@ -0,0 +1,31 @@
+package com.uas.platform.b2b.v2.controller;
+
+import com.uas.account.entity.PartnershipRecord;
+import com.uas.platform.b2b.v2.service.PartnerShipService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+/**
+ * Created by hejq on 2017-09-29.
+ *
+ * 账户中心建立合作关系后如果有后续操作同步到平台进行
+ *
+ */
+@Controller("v2.PartnerShipController")
+@RequestMapping(value = "/public/partenrship")
+public class PartnerShipController {
+
+    @Autowired
+    private PartnerShipService partnerShipService;
+
+    @RequestMapping(method = RequestMethod.POST)
+    @ResponseBody
+    public void addVendor(PartnershipRecord record) throws Exception {
+        if(null != record) {
+            partnerShipService.addVendor(record);
+        }
+    }
+}

+ 14 - 0
src/main/java/com/uas/platform/b2b/v2/service/PartnerShipService.java

@@ -0,0 +1,14 @@
+package com.uas.platform.b2b.v2.service;
+
+import com.uas.account.entity.PartnershipRecord; /**
+ * Created by hejq on 2017-09-29.
+ */
+public interface PartnerShipService {
+
+    /**
+     * 通过合作伙伴关系添加供应商
+     *
+     * @param record
+     */
+    void addVendor(PartnershipRecord record);
+}

+ 59 - 0
src/main/java/com/uas/platform/b2b/v2/service/impl/PartnerShipServiceImpl.java

@@ -0,0 +1,59 @@
+package com.uas.platform.b2b.v2.service.impl;
+
+import com.uas.account.entity.PartnershipRecord;
+import com.uas.platform.b2b.core.util.StringUtil;
+import com.uas.platform.b2b.dao.EnterpriseDao;
+import com.uas.platform.b2b.dao.VendorDao;
+import com.uas.platform.b2b.model.Enterprise;
+import com.uas.platform.b2b.model.Vendor;
+import com.uas.platform.b2b.v2.service.PartnerShipService;
+import com.uas.platform.core.model.Constant;
+import com.uas.platform.core.model.Status;
+import org.apache.axis.utils.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.List;
+
+/**
+ * Created by hejq on 2017-09-29.
+ */
+@Service("v2.PartnerShipService")
+public class PartnerShipServiceImpl implements PartnerShipService{
+
+    @Autowired
+    private VendorDao vendorDao;
+
+    @Autowired
+    private EnterpriseDao enterpriseDao;
+
+    @Override
+    public void addVendor(PartnershipRecord record) {
+        Enterprise myEn = enterpriseDao.findEnterpriseByEnBussinessCode(record.getCustUID());
+        Enterprise vendEn = enterpriseDao.findEnterpriseByEnBussinessCode(record.getVendUID());
+        if(null != myEn && null != vendEn) {
+            List<Vendor> vendors = vendorDao.findByMyEnBusinessCodeAndVendBusinessCode(record.getCustUID(), record.getVendUID());
+            Vendor vendor = new Vendor();
+            if(!CollectionUtils.isEmpty(vendors)) {
+                vendor = vendors.get(0);
+                vendor.setErpstatus(Status.NOT_UPLOAD.value());
+            } else {
+                //客户
+                vendor.setErpstatus(Status.NOT_UPLOAD.value());
+                vendor.setMyUserUU(Long.valueOf(record.getCustUserCode()));
+                vendor.setMyEnUU(myEn.getUu());
+
+                //供应商
+                vendor.setVendUserUU(vendEn.getEnAdminuu());
+                vendor.setVendEnUU(vendEn.getUu());
+                vendor.setSynchStatus(Constant.YES);
+                vendor.setVendswitch(Constant.YES);
+                vendor.setCustswitch(Constant.YES);
+            }
+            if(null != vendor) {
+               vendorDao.save(vendor);
+            }
+        }
+    }
+}

+ 1 - 1
src/main/webapp/resources/tpl/index/purc/addOrder.html

@@ -2,7 +2,7 @@
 <html lang="en">
 <head>
 <meta charset="UTF-8" />
-<title>B2B商务采购变更-添加</title>
+<title>B2B商务采购-添加</title>
 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
 <meta name="Keywords" content="" />
 <meta name="Description" content="" />