Jelajahi Sumber

供应商资源库接口,不再需要ERP验证,增加参数enUU(可为空),同时为未注册B2B的UAS用户提供服务

dongbw 8 tahun lalu
induk
melakukan
a4e11d819e

+ 9 - 9
src/main/java/com/uas/platform/b2b/erp/controller/VendorRecommendController.java

@@ -5,7 +5,6 @@ import com.uas.platform.b2b.erp.model.VendorRecommend;
 import com.uas.platform.b2b.erp.support.ErpBufferedLogger;
 import com.uas.platform.b2b.model.Product;
 import com.uas.platform.b2b.service.VendorService;
-import com.uas.platform.b2b.support.SystemSession;
 import com.uas.platform.core.logging.BufferedLoggerManager;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -20,7 +19,7 @@ import java.util.List;
  * 18/01/18 14:00.
  */
 @RestController
-@RequestMapping("/erp/recommend")
+@RequestMapping("/public/recommend")
 public class VendorRecommendController {
 
     @Autowired
@@ -38,9 +37,9 @@ public class VendorRecommendController {
      * @return
      */
     @RequestMapping(value = "/list", method = RequestMethod.GET)
-    public Page<VendorRecommend> getVendorRecommend (String productMatchCondition, String enterpriseMatchCondition, int page, int size) {
-        Page<VendorRecommend> vendorRecommendPage = vendorService.getVendorRecommend(productMatchCondition, enterpriseMatchCondition, page, size);
-        logger.log("供应商推荐","获取当前企业推荐供应商:" + SystemSession.getUser().getEnterprise().getUu(), vendorRecommendPage.getNumberOfElements());
+    public Page<VendorRecommend> getVendorRecommend (Long enUU, String productMatchCondition, String enterpriseMatchCondition, int page, int size) {
+        Page<VendorRecommend> vendorRecommendPage = vendorService.getVendorRecommend(enUU, productMatchCondition, enterpriseMatchCondition, page, size);
+//        logger.log("供应商推荐","获取当前企业推荐供应商:" + enUU, vendorRecommendPage.getNumberOfElements());
         return vendorRecommendPage;
     }
 
@@ -54,7 +53,7 @@ public class VendorRecommendController {
     @RequestMapping(value = "/product/associate", method = RequestMethod.GET)
     public List<Product> getProductAssociate (String field, String condition) {
         List<Product> products = vendorService.getProductAssociate(field, condition);
-        logger.log("供应商推荐","根据条件获取物料型号和品牌值对" + SystemSession.getUser().getEnterprise().getUu(), products.size());
+//        logger.log("供应商推荐","根据条件获取物料型号和品牌值对", products.size());
         return products;
     }
 
@@ -62,15 +61,16 @@ public class VendorRecommendController {
      * 获取推荐企业物料列表(匹配到的排前面)
      * @param page 页数
      * @param size 每页条数
+     * @param enUU 当前企业UU
      * @param vendUU 推荐供应商企业UU
      * @param productMatchCondition 列表的物料匹配搜索条件  不带where
      * @param whereCondition where条件(product的筛选条件拼接) 不带where
      * @return
      */
     @RequestMapping(value = "/detail", method = RequestMethod.GET)
-    public Page<Product> getVendorRecommendDetail(int page, int size, Long vendUU, String productMatchCondition, String whereCondition) {
-        Page<Product> productPage = vendorService.getProductsByVendorRecommend(page, size, vendUU, productMatchCondition, whereCondition);
-        logger.log("供应商推荐","获取当前企业推荐供应商:" + SystemSession.getUser().getEnterprise().getUu(), productPage.getNumberOfElements());
+    public Page<Product> getVendorRecommendDetail(int page, int size, Long enUU, Long vendUU, String productMatchCondition, String whereCondition) {
+        Page<Product> productPage = vendorService.getProductsByVendorRecommend(page, size, enUU, vendUU, productMatchCondition, whereCondition);
+//        logger.log("供应商推荐","获取当前企业推荐供应商:" + enUU, productPage.getNumberOfElements());
         return productPage;
     }
 }

+ 5 - 2
src/main/java/com/uas/platform/b2b/service/VendorService.java

@@ -124,6 +124,7 @@ public interface VendorService {
 	/**
 	 * 获取当前企业推荐供应商
 	 *
+     * @param enUU 当前企业UU
 	 * @param productMatchCondition 物料模糊匹配条件
 	 * @param enterpriseMatchCondition 企业搜索匹配条件
 	 * @param productCondition 物料精确匹配条件
@@ -131,7 +132,7 @@ public interface VendorService {
 	 * @param size 每页条数
 	 * @return
 	 */
-	com.uas.account.support.Page<VendorRecommend> getVendorRecommend(String productMatchCondition, String enterpriseMatchCondition, int page, int size);
+	com.uas.account.support.Page<VendorRecommend> getVendorRecommend(Long enUU, String productMatchCondition, String enterpriseMatchCondition, int page, int size);
 
 	/**
 	 * 获取推荐企业物料列表(匹配到的排前面)
@@ -139,9 +140,11 @@ public interface VendorService {
 	 * @param size 每页条数
 	 * @param productMatchCondition 列表的物料匹配搜索条件
 	 * @param whereCondition where条件(product的筛选条件拼接)
+     * @param enUU 当前企业UU
+     * @param vendUU 供应商企业UU
 	 * @return
 	 */
-    com.uas.account.support.Page<Product> getProductsByVendorRecommend(int page, int size, Long vendUU, String productMatchCondition,  String whereCondition);
+    com.uas.account.support.Page<Product> getProductsByVendorRecommend(int page, int size, Long enUU, Long vendUU, String productMatchCondition,  String whereCondition);
 
 	/**
 	 * 根据条件获取物料型号和品牌值对

+ 57 - 47
src/main/java/com/uas/platform/b2b/service/impl/VendorsServiceImpl.java

@@ -306,6 +306,7 @@ public class VendorsServiceImpl implements VendorService {
 	/**
 	 * 获取当前企业推荐供应商
 	 *
+	 * @param enUU 当前企业UU
 	 * @param productMatchCondition 物料模糊匹配条件
 	 * @param enterpriseMatchCondition 企业搜索匹配条件
 	 * @param page 页面
@@ -313,9 +314,9 @@ public class VendorsServiceImpl implements VendorService {
 	 * @return
 	 */
 	@Override
-	public com.uas.account.support.Page<VendorRecommend> getVendorRecommend(String productMatchCondition, String enterpriseMatchCondition, int page, int size) {
+	public com.uas.account.support.Page<VendorRecommend> getVendorRecommend(Long enUU, String productMatchCondition, String enterpriseMatchCondition, int page, int size) {
 		long start = System.currentTimeMillis();
-		final Long enUU = SystemSession.getUser().getEnterprise().getUu();
+//		final Long enUU = SystemSession.getUser().getEnterprise().getUu();
 		if (StringUtils.isEmpty(productMatchCondition)) {
 			productMatchCondition = " 1=1 ";
 		}
@@ -333,8 +334,7 @@ public class VendorsServiceImpl implements VendorService {
 		// 查找非供应商的卖当前商品的企业UU
 		StringBuffer vendorRecommendUusSql = new StringBuffer();
 		vendorRecommendUusSql.append("select s.*,( select wm_concat(pr_title || (case when pr_brand is not null then '(' || pr_brand || ')' else ' ' end)) from v$products where pr_enuu=en_uu and ").append(productMatchCondition)
-				.append(" and exists (select 1 from v$products B where B.pr_cmpcode = pr_cmpcode and B.pr_enuu = ").append(enUU)
-				.append(" and B.pr_ispurchase = 1 and nvl(B.pr_issale, 0) <> 1) and rownum<5 ) productInfo, (select 1 from purc$vendors where ve_vendenuu = en_uu and ve_myenuu = ")
+				.append(" and rownum<5 ) productInfo, (select 1 from purc$vendors where ve_vendenuu = en_uu and ve_myenuu = ")
 				.append(enUU).append(") isVendor from (select t.*,rownum as r1 from (").append(enterpriseSql).append(rownumSql);
 		// 因为需求更改为所有有销售产品的企业都会被返回,所以total直接取除本企业外其他有销售产品的企业数即可,之前的匹配企业数不再返回
 		StringBuffer totalSql = new StringBuffer().append(" select count(1) from (select en_uu from sec$enterprises left join " +
@@ -451,55 +451,65 @@ public class VendorsServiceImpl implements VendorService {
 	 * @return
 	 */
 	@Override
-	public com.uas.account.support.Page<Product> getProductsByVendorRecommend(int page, int size, Long vendUU, String productMatchCondition, String whereCondition) {
-		System.out.println("进入方法:" + System.currentTimeMillis());
+	public com.uas.account.support.Page<Product> getProductsByVendorRecommend(int page, int size, Long enUU, Long vendUU, String productMatchCondition, String whereCondition) {
+		// 如果enUU不为空按之前的处理,为空另外处理
 		if (StringUtils.isEmpty(whereCondition)) {
 			whereCondition = " 1 = 1 ";
 		}
-		long start = System.currentTimeMillis();
-		// UAS企业UU
-		Long enUU = SystemSession.getUser().getEnterprise().getUu();
-		StringBuffer cmpCodesSql = new StringBuffer();
-		cmpCodesSql.append("select 1 from v$products where pr_cmpcode = p1.pr_cmpcode and pr_enuu = ")
-				.append(enUU).append(" and nvl(pr_issale,0) <> 1 and pr_ispurchase = 1 and pr_b2bdisabled <> 1 ");
-		if (null != productMatchCondition) {
-			cmpCodesSql.append(" and ").append(productMatchCondition);
+		List<Product> products = new ArrayList<>();
+		if (null != enUU) {
+			System.out.println("进入方法:" + System.currentTimeMillis());
+			long start = System.currentTimeMillis();
+			// UAS企业UU
+//		Long enUU = SystemSession.getUser().getEnterprise().getUu();
+			StringBuffer cmpCodesSql = new StringBuffer();
+			cmpCodesSql.append("select 1 from v$products where pr_cmpcode = p1.pr_cmpcode and pr_enuu = ")
+					.append(enUU).append(" and nvl(pr_issale,0) <> 1 and pr_ispurchase = 1 and pr_b2bdisabled <> 1 ");
+//			if (null != productMatchCondition) {
+//				cmpCodesSql.append(" and ").append(productMatchCondition);
+//			}
+			// 查找匹配在售物料的语句
+			StringBuffer productsMatchSql = new StringBuffer();
+			productsMatchSql.append("select pr_id from (select pr_id from v$products p1 where exists (").append(cmpCodesSql)
+					.append(") and p1.pr_enuu = ").append(vendUU).append(" and p1.pr_issale = 1 and p1.pr_b2bdisabled <> 1 and ")
+					.append(null != whereCondition ? whereCondition : "").append(" order by pr_code desc)");
+			// 查找不匹配但是在售物料的语句  union all 方便排序
+			StringBuffer notMatchProductsSql = new StringBuffer();
+			notMatchProductsSql.append("select pr_id from (select pr_id from v$products p1 where not exists (").append(cmpCodesSql)
+					.append(") and p1.pr_enuu = ").append(vendUU).append(" and p1.pr_issale = 1 and p1.pr_b2bdisabled <> 1 and ")
+					.append(null != whereCondition ? whereCondition : "").append(" order by pr_code desc)");
+			// 物料id
+			StringBuffer idSql = new StringBuffer();
+			// rownum 控制
+			String rownumSql = " t where rownum <= " + page * size + ") where r1 > " + (page - 1) * size;
+			idSql.append("select pr_id from (select t.*,rownum as r1 from (").append(productsMatchSql).append(" union all ").append(notMatchProductsSql)
+					.append(")").append(rownumSql);
+			List<Long> matchedIds = commonDao.queryForList(productsMatchSql.toString(), Long.class);
+			List<Long> ids = commonDao.queryForList(idSql.toString(), Long.class);
+//			System.out.println("id:" + idSql);
+			for (Long id : ids) {
+				Product product = productDao.findOne(id);
+				if (matchedIds.contains(id)) {
+					StringBuffer matchCodeSql = new StringBuffer();
+					matchCodeSql.append("select wm_concat(pr_code) from v$products where pr_b2bdisabled <> 1 and pr_enuu = ")
+							.append(enUU).append(" and pr_cmpcode = '").append(product.getCmpCode()).append("'").append(" and rownum <= 5");
+					String matchCodes = commonDao.queryForObject(matchCodeSql.toString(), String.class);
+					product.setIfMatched(matchCodes);
+				}
+				products.add(product);
+			}
+			System.out.println("返回数据:" + (System.currentTimeMillis() - start));
+		} else {
+			String prodSql = "select a.* from (select t.*,rownum as r1 from (select pr_id id, pr_code code, pr_title title, pr_spec spec, pr_cmpcode cmpCode, pr_unit unit, pr_kind kind, " +
+					"pr_minpack minPack, pr_minOrder minOrder, pr_brand brand, pr_standard standard from v$products where pr_b2bdisabled <> 1 and pr_issale = 1 and pr_enuu = " + vendUU + " and " +
+					whereCondition + " order by pr_standard desc, pr_id desc) t where rownum <= " + page * size + ") a where r1 > " + (page - 1) * size;
+			System.out.println("无UU:" + prodSql);
+			products = commonDao.query(prodSql, Product.class);
+
 		}
-		// 查找匹配在售物料的语句
-		StringBuffer productsMatchSql = new StringBuffer();
-		productsMatchSql.append("select pr_id from (select pr_id from v$products p1 where exists (").append(cmpCodesSql)
-				.append(") and p1.pr_enuu = ").append(vendUU).append(" and p1.pr_issale = 1 and p1.pr_b2bdisabled <> 1 and ")
-				.append(null != whereCondition ? whereCondition : "").append(" order by pr_code desc)");
-		// 查找不匹配但是在售物料的语句  union all 方便排序
-		StringBuffer notMatchProductsSql = new StringBuffer();
-		notMatchProductsSql.append("select pr_id from (select pr_id from v$products p1 where not exists (").append(cmpCodesSql)
-				.append(") and p1.pr_enuu = ").append(vendUU).append(" and p1.pr_issale = 1 and p1.pr_b2bdisabled <> 1 and ")
-				.append(null != whereCondition ? whereCondition : "").append(" order by pr_code desc)");
-		// 物料id
-		StringBuffer idSql = new StringBuffer();
 		String countSql = "select count(1) from v$products where pr_enuu = " + vendUU + " and pr_issale = 1 and pr_b2bdisabled <> 1 and " + whereCondition;
-		// rownum 控制
-		String rownumSql = " t where rownum <= " + page * size + ") where r1 > " + (page - 1) * size;
-		idSql.append("select pr_id from (select t.*,rownum as r1 from (").append(productsMatchSql).append(" union all ").append(notMatchProductsSql)
-				.append(")").append(rownumSql);
-		List<Long> matchedIds = commonDao.queryForList(productsMatchSql.toString(), Long.class);
 		Integer count = commonDao.queryForObject(countSql, Integer.class);
-		List<Long> ids = commonDao.queryForList(idSql.toString(), Long.class);
-        System.out.println("count:" + countSql);
-        System.out.println("id:" + idSql);
-		List<Product> products = new ArrayList<>();
-		for (Long id : ids) {
-		    Product product = productDao.findOne(id);
-		    if (matchedIds.contains(id)) {
-		    	StringBuffer matchCodeSql = new StringBuffer();
-		    	matchCodeSql.append("select wm_concat(pr_code) from v$products where pr_b2bdisabled <> 1 and pr_enuu = ")
-						.append(enUU).append(" and pr_cmpcode = '").append(product.getCmpCode()).append("'").append(" and rownum <= 20");
-		    	String matchCodes = commonDao.queryForObject(matchCodeSql.toString(), String.class);
-		    	product.setIfMatched(matchCodes);
-			}
-		    products.add(product);
-        }
-		System.out.println("返回数据:" + (System.currentTimeMillis() - start));
+//		System.out.println("count:" + countSql);
 		return new com.uas.account.support.Page<>(page, size, products, count);
 	}