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