Browse Source

物料库 上架设为调公共接口

wangdy 8 years ago
parent
commit
9244e4ce2d

+ 5 - 0
pom.xml

@@ -447,6 +447,11 @@
 			<groupId>javax.servlet</groupId>
 			<artifactId>servlet-api</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>com.uas.ps</groupId>
+			<artifactId>ps-entity</artifactId>
+			<version>0.0.1-SNAPSHOT</version>
+		</dependency>
 		<!--Hutool POI工具类(对MS Office操作)-->
 		<!--<dependency>
 			<groupId>org.apache.poi</groupId>

+ 8 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/dao/ReleaseProductByBatchDao.java

@@ -44,6 +44,14 @@ public interface ReleaseProductByBatchDao
      */
     public List<ReleaseProductByBatch> findByPublisherUu(Long publisherUu);
 
+	/**
+	 *
+	 * @param batch
+	 * @return List<ReleaseProductByBatch> list
+	 * @author wangdy
+	 */
+	public List<ReleaseProductByBatch> findByRelbatchid(String batch);
+
     /**
      * 获取某一次上传多少的条数据
      *

+ 72 - 15
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ReleaseProductByBatchServiceImpl.java

@@ -29,6 +29,7 @@ import com.uas.platform.b2c.prod.store.model.StoreIn;
 import com.uas.platform.b2c.prod.store.model.StoreStatus;
 import com.uas.platform.b2c.prod.store.service.StoreInService;
 import com.uas.platform.b2c.trade.order.StringConstant.Currency;
+import com.uas.platform.b2c.trade.presale.model.Collection;
 import com.uas.platform.core.exception.IllegalOperatorException;
 import com.uas.platform.core.model.PageInfo;
 import com.uas.platform.core.persistence.criteria.CriterionExpression;
@@ -47,6 +48,8 @@ import org.springframework.jdbc.core.StatementCallback;
 import org.springframework.stereotype.Service;
 import org.springframework.ui.ModelMap;
 import org.springframework.util.StringUtils;
+import org.springframework.web.client.RestTemplate;
+
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
@@ -96,6 +99,9 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 	@Autowired
 	private ProductDao productDao;
 
+	@Autowired
+	private RestTemplate restTemplate;
+
 	@Override
 	public ReleaseProductByBatch save(ReleaseProductByBatch releaseProductByBatch) {
 		return releaseProductByBatch;
@@ -983,9 +989,18 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 
 	@Override
 	public String publishByBatch(String batch) {
+
+		List<ReleaseProductByBatch> releaseProductByBatchList =
+				releaseProductByBatchDao.findByRelbatchid(batch);
+		if (!CollectionUtils.isEmpty(releaseProductByBatchList)) {
+			List<com.uas.ps.entity.Product> products = convertProduct(releaseProductByBatchList);
+			// TODO 什么接口
+			restTemplate.postForEntity("", products, String.class);
+		}
+
 		Enterprise enterprise = SystemSession.getUser().getEnterprise();
 		final Object[] obj = new Object[]{enterprise.getUu(), enterprise.getEnName(), batch};
-		String sql = "/*#mycat:db_type=master*/ set @enuu = %s; set @enName = '%s'; set @batch = '%s'; call RELEASE_TO_PRODUCT_V1(@enuu, @enName, @batch, @out); select @out";
+		String sql = "/*#mycat:db_type=master*/ set @enuu = %s; set @enName = '%s'; set @batch = '%s'; call RELEASE_TO_GOODS_V1(@enuu, @enName, @batch, @out); select @out";
 		final String updateSql = String.format(sql, obj);
 		String num = jdbcTemplate.execute(new StatementCallback<String>() {
 
@@ -1000,21 +1015,63 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 				return "0";
 			}
 		});
-		if (!"0".equals(num)) {
-			List<Goods> goodsList = goodsDao.findByBatchid(batch);
-			Set<String> uuids = new HashSet<String>();
-			for (Goods goods : goodsList) {
-				if (goods.getUuid() != null) {
-					uuids.add(goods.getUuid());
-//					goodsService.saveOrUpdatePriceInfos(goods, "NORMAL");
-				}
-			}
-			// TODO 之后删除
-			for (String uuid : uuids) {
-				goodsService.updateComponentTradeInfos(uuid);
-			}
-		}
+
+
+//		Enterprise enterprise = SystemSession.getUser().getEnterprise();
+//		final Object[] obj = new Object[]{enterprise.getUu(), enterprise.getEnName(), batch};
+//		String sql = "/*#mycat:db_type=master*/ set @enuu = %s; set @enName = '%s'; set @batch = '%s'; call RELEASE_TO_PRODUCT_V1(@enuu, @enName, @batch, @out); select @out";
+//		final String updateSql = String.format(sql, obj);
+//		String num = jdbcTemplate.execute(new StatementCallback<String>() {
+//
+//			@Override
+//			public String doInStatement(Statement stmt) throws SQLException, DataAccessException {
+//				stmt.executeQuery(updateSql);
+//				ResultSet rs = stmt.getResultSet();
+//				if (null != rs) {
+//					rs.next();
+//					return rs.getString(1);
+//				}
+//				return "0";
+//			}
+//		});
+//		if (!"0".equals(num)) {
+//			List<Goods> goodsList = goodsDao.findByBatchid(batch);
+//			Set<String> uuids = new HashSet<String>();
+//			for (Goods goods : goodsList) {
+//				if (goods.getUuid() != null) {
+//					uuids.add(goods.getUuid());
+////					goodsService.saveOrUpdatePriceInfos(goods, "NORMAL");
+//				}
+//			}
+//			// TODO 之后删除
+//			for (String uuid : uuids) {
+//				goodsService.updateComponentTradeInfos(uuid);
+//			}
+//		}
 		return StringUtilB2C.getStr(num);
 	}
 
+
+	private  List<com.uas.ps.entity.Product> convertProduct (List<ReleaseProductByBatch> releaseProductByBatchList ) {
+		if (CollectionUtils.isEmpty(releaseProductByBatchList)) {
+			return null;
+		}
+		List<com.uas.ps.entity.Product> products = new ArrayList<>();
+		for (ReleaseProductByBatch releaseProductByBatch : releaseProductByBatchList) {
+			com.uas.ps.entity.Product product = new com.uas.ps.entity.Product();
+			// releaseProductByBatch.getCode(); 在公有库生成
+			product.setMinPack(releaseProductByBatch.getMinPackage());
+			product.setCmpImg(releaseProductByBatch.getImg());
+			product.setEnUU(SystemSession.getUser().getEnterprise().getUu());
+			product.setBrand(releaseProductByBatch.getBrandNameEn());
+			product.setCmpCode(releaseProductByBatch.getCode());
+			product.setCmpUuid(releaseProductByBatch.getComponentUuId());
+			product.setKind(releaseProductByBatch.getKindName());
+			product.setKindId(releaseProductByBatch.getKindUuid());
+			product.setStandard(releaseProductByBatch.getReleaseCode().shortValue());
+			products.add(product);
+		}
+		return products;
+	}
+
 }