|
|
@@ -0,0 +1,175 @@
|
|
|
+package com.uas.platform.b2c.trade.vendor.service.impl;
|
|
|
+
|
|
|
+import com.uas.platform.b2c.common.base.dao.CommonDao;
|
|
|
+import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
+import com.uas.platform.b2c.prod.commodity.dao.V_ProductPrivateDao;
|
|
|
+import com.uas.platform.b2c.prod.commodity.model.V_ProductPrivate;
|
|
|
+import com.uas.platform.b2c.trade.vendor.model.VendorIntroduction;
|
|
|
+import com.uas.platform.b2c.trade.vendor.service.VendorIntroductionService;
|
|
|
+import com.uas.sso.support.Page;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * The type VendorIntroductionService.
|
|
|
+ * @version 2018年4月26日 17:25:03
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class VendorIntroductionServiceImpl implements VendorIntroductionService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CommonDao commonDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private V_ProductPrivateDao v_productPrivateDao;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取供应商资源列表
|
|
|
+ * @param page 页码
|
|
|
+ * @param size 每页大小
|
|
|
+ * @param keyword 关键词
|
|
|
+ * @return 供应商资源page
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Page<VendorIntroduction> getVendorIntroduction(int page, int size, String keyword) {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ Long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
+ // 查询所有物料个数
|
|
|
+ Integer total = getTotalCount(enUU, keyword);
|
|
|
+ // 查询企业
|
|
|
+ List<VendorIntroduction> vendorIntroductions = getEnterpriseWithCondition(enUU, keyword, page, size);
|
|
|
+ System.out.println("查找完企业UU" + (System.currentTimeMillis() - start));
|
|
|
+ return new Page<VendorIntroduction>(page, size, vendorIntroductions, total);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据vendUU获取企业物料列表
|
|
|
+ *
|
|
|
+ * @param page 页码
|
|
|
+ * @param size 每页尺寸
|
|
|
+ * @param vendUU 可开发供应商企业UU
|
|
|
+ * @param keyword 关键词
|
|
|
+ * @return 物料page
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Page<V_ProductPrivate> getVendorProductList(int page, int size, Long vendUU, String keyword) {
|
|
|
+ String whereCondition = " 1 = 1 ";
|
|
|
+ if (!StringUtils.isEmpty(keyword)) {
|
|
|
+ // 物料名称、规格、品牌、原厂型号、单位
|
|
|
+ whereCondition = " (pr_title like '%" + keyword + "%' or pr_spec like '%" + keyword + "%' or pr_brand like '%"
|
|
|
+ + keyword + "%' or pr_cmpcode like '%" + keyword + "%' or pr_unit like '%" + keyword + "%' or pr_kind like '%"
|
|
|
+ + keyword + "%') ";
|
|
|
+ }
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ String prodSql = "select a.* from (select pr_id id, pr_code prodNum, pr_title prodName, pr_spec spec, pr_cmpcode cmpCode, pr_unit unit, pr_kind kind, "
|
|
|
+ + " pr_brand brand, pr_standard standard from v$product$private where ifnull(pr_b2cenabled, 1) <> 0 and pr_enuu = "
|
|
|
+ + vendUU + " and pr_issale = 1 and ifnull(pr_b2cenabled, 1) <> 0 and Pr_Title not like '%测试%' and lower(Pr_Title) not like '%test%' and Pr_code not like '%测试%' and lower(Pr_code) not like '%test%' and "
|
|
|
+ + whereCondition + " order by pr_issale desc, pr_standard desc, pr_id desc) a limit " + (page - 1) * size + "," + size;
|
|
|
+ System.out.println("prod:" + prodSql);
|
|
|
+ String countSql = "select count(1) from v$product$private where pr_enuu = " + vendUU
|
|
|
+ + " and pr_issale = 1 and ifnull(pr_b2cenabled, 1) <> 0 and Pr_Title not like '%测试%' and lower(Pr_Title) not like '%test%' and Pr_code not like '%测试%' and lower(Pr_code) not like '%test%' and "
|
|
|
+ + whereCondition;
|
|
|
+ Integer count = commonDao.queryForObject(countSql, Integer.class);
|
|
|
+ List<V_ProductPrivate> products = commonDao.query(prodSql, V_ProductPrivate.class);
|
|
|
+ System.out.println("耗时" + (System.currentTimeMillis() - start));
|
|
|
+ return new Page<>(page, size, products, count);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id获取物料详情
|
|
|
+ *
|
|
|
+ * @param id 物料id
|
|
|
+ * @return 物料信息
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public V_ProductPrivate getVendorProductDetail(Long id) {
|
|
|
+ return v_productPrivateDao.findOne(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取供应商资源信息
|
|
|
+ * @param enUU 本企业UU
|
|
|
+ * @param keyword 关键词
|
|
|
+ * @param page 页码
|
|
|
+ * @param size 尺寸
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<VendorIntroduction> getEnterpriseWithCondition(Long enUU, String keyword, int page, int size) {
|
|
|
+ StringBuilder enterpriseSql = new StringBuilder();
|
|
|
+ // 查询所有符合条件的enUU的语句,按待售物料数量排序
|
|
|
+ String enUUSql = getEnUUGroupByEnUUOrderByCount(enUU, keyword);
|
|
|
+ // 获取企业sql
|
|
|
+ enterpriseSql.append("select en.en_uu enUU, en.en_name enName, en.en_shortname enShortname, en.en_address enAddress, en.en_tel enTel, " +
|
|
|
+ "en.en_email enEmail, en.en_corporation enCorporation, en.en_businesscode enBusinesscode, en.en_profession enProfession, en.en_tags enTags " +
|
|
|
+ " from sec$enterprises en right join (").append(enUUSql)
|
|
|
+ .append(" ) a on en.en_uu = a.en_uu order by en.en_weight desc, counts desc");
|
|
|
+ // rownum 控制
|
|
|
+ String rownumSql = ") s limit " + (page - 1) * size + "," + size ;
|
|
|
+// // 查询企业简要物料信息语句
|
|
|
+// String prodInfoSql = "select wm_concat(pr_title || (case when pr_brand is not null then '(' || pr_brand || ')' else ' ' end)) from v$product$private where pr_enuu=en_uu and "
|
|
|
+// + " and pr_issale = 1 and pr_b2cenabled = 1 and rownum<5 ";
|
|
|
+ // 查询企业是否开店语句
|
|
|
+ // 查找非供应商的卖当前商品的企业UU
|
|
|
+ String vendorIntroductionUusSql = "select s.*, ( select 1 from store$info where st_enuu = enUU) isStore, " +
|
|
|
+ "(select 1 from v$product$private where ifnull(pr_b2cenabled, 1) = 1 and pr_enuu = enUU) hasProduct from ("
|
|
|
+ + enterpriseSql + rownumSql;
|
|
|
+// String vendorIntroductionUusSql = "select s.*,( " + prodInfoSql + ") productInfo, (" + storeSql +
|
|
|
+// ") isStore from (select t.*,rownum as r1 from (" + enterpriseSql + rownumSql;
|
|
|
+ return commonDao.query(vendorIntroductionUusSql, VendorIntroduction.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取所有符合条件企业数量
|
|
|
+ * @param enUU 本企业UU
|
|
|
+ * @param keyword 关键词
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Integer getTotalCount(Long enUU, String keyword) {
|
|
|
+ StringBuilder enCountSql = new StringBuilder();
|
|
|
+ // 含名称、地址、、行业、经营范围搜索 物料型号、名称
|
|
|
+ if (!StringUtils.isEmpty(keyword)) {
|
|
|
+ String keywordSql = getKeywordSql(enUU, keyword);
|
|
|
+ enCountSql.append("select count(1) from (select count(1) from ").append(keywordSql);
|
|
|
+ } else {
|
|
|
+ enCountSql.append("select count(1) from (select count(1) from (select * from sec$enterprises where en_name not like '%测试%' " +
|
|
|
+ " and lower(en_name) not like '%test%') en left join products on en.en_uu = pr_enuu where en_uu <> ").append(enUU);
|
|
|
+ }
|
|
|
+ enCountSql.append(" group by en_uu ) a");
|
|
|
+ return commonDao.queryForObject(enCountSql.toString(), Integer.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 拼接关键词Sql
|
|
|
+ * @param enUU
|
|
|
+ * @param keyword
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getKeywordSql(Long enUU, String keyword) {
|
|
|
+ return "(select * from sec$enterprises where en_name not like '%测试%' and lower(en_name) not like '%test%' and (en_name like '%"
|
|
|
+ + keyword + "%' or en_address like '%" + keyword + "%' or en_tags like '%" + keyword + "%' or en_profession like '%" + keyword
|
|
|
+ + "%')) en left join (select * from products where pr_cmpcode like '%" + keyword + "%' or pr_brand like '%" + keyword
|
|
|
+ + "%') pr on en.en_uu = pr.pr_enuu where en_uu <> " + enUU;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 拼接所有待售物料所属企业UU,按enUU分组,按物料数量倒序
|
|
|
+ * @param enUU 当前企业UU
|
|
|
+ * @param keyword 搜索关键词
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getEnUUGroupByEnUUOrderByCount(Long enUU, String keyword) {
|
|
|
+ StringBuilder enUUSql = new StringBuilder();
|
|
|
+ // 含名称、企业执照号、地址、邮箱、电话、行业、经营范围搜索
|
|
|
+ if (!StringUtils.isEmpty(keyword)) {
|
|
|
+ enUUSql.append("select en_uu, count(1) as counts from ").append(getKeywordSql(enUU, keyword));
|
|
|
+ } else {
|
|
|
+ enUUSql.append("select en_uu, count(1) as counts from (select * from sec$enterprises where en_name not like '%测试%' " +
|
|
|
+ " and lower(en_name) not like '%test%') en left join products on en.en_uu = pr_enuu where en.en_uu <> ").append(enUU);
|
|
|
+ }
|
|
|
+ enUUSql.append(" group by en_uu order by count(1) desc ");
|
|
|
+ return enUUSql.toString();
|
|
|
+ }
|
|
|
+}
|