Browse Source

【客户资料】+【客户关系建立】+【在平台中去建立客户关系】+【审核后、设置UU号后建立】

git-svn-id: svn+ssh://10.10.101.21/source/platform/platform-b2b@3443 f3bf4e98-0cf0-11e4-a00c-a99a8b9d557d
shenj 10 years ago
parent
commit
e2c1fe6f01

+ 69 - 0
src/main/java/com/uas/platform/b2b/erp/controller/RelationshipController.java

@@ -0,0 +1,69 @@
+package com.uas.platform.b2b.erp.controller;
+
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.stereotype.Controller;
+import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+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.support.SystemSession;
+
+
+@Controller
+@RequestMapping("/erp/relationship")
+public class RelationshipController {
+
+	@Autowired
+	private VendorDao vendorDao;
+	@Autowired
+	private EnterpriseDao enterpriseDao;
+	
+	@RequestMapping(method = RequestMethod.POST)
+	@ResponseBody
+	@ResponseStatus(value = HttpStatus.OK)
+	public Map<String, Object> relationship(Long otheruu) throws UnsupportedEncodingException {
+		Map<String, Object> infos = new HashMap<String, Object>();
+		boolean ok = true;
+		String error = null;
+		long enUU = SystemSession.getUser().getEnterprise().getUu();
+		if (!StringUtils.isEmpty(otheruu)) {			
+			Enterprise enterprise=enterpriseDao.findEnterpriseByUu(otheruu);
+			if(enterprise!=null){
+				List<Vendor> vendors = vendorDao.findByMyEnUUAndVendUU(otheruu, enUU);
+				Vendor vendor = null;
+				if (vendors.size() == 0) {//供应商资料在平台上不存在
+					vendor = addVendor(otheruu,enUU);//添加企业的供应商资料
+				}
+			}else{
+				ok = false;
+				error="企业UU号错误,请联系管理员!";
+			}			 
+		}
+		infos.put("ok", ok);
+		infos.put("error", error);
+		return infos;
+	}
+	
+	private Vendor addVendor(Long enuu,Long venduu) {
+		Vendor vendor = new Vendor();
+		vendor.setMyEnUU(enuu);
+		Enterprise enEnterprise = enterpriseDao.findOne(enuu);
+		vendor.setMyUserUU(enEnterprise.getEnAdminuu());
+		Enterprise vendEnterprise = enterpriseDao.findOne(enuu);
+		vendor.setVendEnUU(venduu);
+		vendor.setVendUserUU(vendEnterprise.getEnAdminuu());
+		return vendorDao.save(vendor);		
+	}
+}