Browse Source

处理Mycat环境下带输出参数存储过程问题

hulh 8 years ago
parent
commit
d2ef662d56

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

@@ -449,7 +449,8 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		}
 		commonDao.save(releaseProductByBatchs, ReleaseProductByBatch.class);
 		Long userUU = SystemSession.getUser().getUserUU();
-		releaseProductByBatchDao.callValidProcedure(userUU, batch);
+		Long enuu = SystemSession.getUser().getEnterprise().getUu();
+		callValidProcedure(enuu, batch);
 		Integer failure = releaseProductByBatchDao.getCountPublisherUuAndBatchAndReleaseCode(userUU, batch, ReleaseStatus.failure.value());
 		Integer success = releaseProductByBatchDao.getCountPublisherUuAndBatchAndReleaseCode(userUU, batch, ReleaseStatus.success.value());
 		modelMap.put("total", total);
@@ -460,6 +461,25 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		return modelMap;
 	}
 
+	/**
+	 * 使用mycat注解方式调用存储过程
+	 * @param enuu  卖家uu
+	 * @param batch 批次号
+	 */
+	private void callValidProcedure(Long enuu, String batch) {
+		final Object[] obj = new Object[]{enuu, batch};
+		String sql = "/*#mycat:db_type=master*/ call PRODUCT_RELEASE_VALID(%s, '%s')";
+		final String updateSql = String.format(sql, obj);
+		String num = jdbcTemplate.execute(new StatementCallback<String>() {
+
+			@Override
+			public String doInStatement(Statement stmt) throws SQLException, DataAccessException {
+				Integer count = stmt.executeUpdate(updateSql);
+				return count.toString();
+			}
+		});
+	}
+
 	/**
 	 * 分析分段的价格
  	 */
@@ -822,14 +842,13 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 	public String publishByBatch(String batch) {
 		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 product_release_batch_publish(@enuu, @enName, @batch, @out)";
+		String sql = "/*#mycat:db_type=master*/ set @enuu = %s; set @enName = '%s'; set @batch = '%s'; call product_release_batch_publish(@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.executeUpdate(updateSql);
-				stmt.execute("select @out");
+				stmt.executeQuery(updateSql);
 				ResultSet rs = stmt.getResultSet();
 				if (null != rs) {
 					rs.next();