Browse Source

修改带输出参数存储过程的写法

hulh 8 years ago
parent
commit
d69b9c9a44

+ 22 - 20
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ProductServiceImpl.java

@@ -46,9 +46,8 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.Sort;
 import org.springframework.data.jpa.domain.Specification;
-import org.springframework.jdbc.core.CallableStatementCallback;
-import org.springframework.jdbc.core.CallableStatementCreator;
 import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.StatementCallback;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.StringUtils;
@@ -58,9 +57,9 @@ import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 import java.lang.reflect.Field;
-import java.sql.CallableStatement;
-import java.sql.Connection;
+import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Statement;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -320,23 +319,26 @@ public class ProductServiceImpl implements ProductService {
 
     @Override
     public Integer matchAll() {
-//        jdbcTemplate.execute("call TRADE_UPDATE_AVAILABLE_DAYS(" + SystemSession.getUser().getEnterprise().getUu() + ")");
-        Integer updateCount = (Integer) jdbcTemplate.execute(
-            new CallableStatementCreator() {
-                public CallableStatement createCallableStatement(Connection con) throws SQLException {
-                    String sp = "{call vendor_match_products(?,?)}";
-                    CallableStatement cs = con.prepareCall(sp);
-                    cs.setLong(1, SystemSession.getUser().getEnterprise().getUu());
-                    cs.registerOutParameter(2, OracleType.STYLE_INT);
-                    return cs;
-                }
-            }, new CallableStatementCallback() {
-                public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
-                    cs.execute();
-                    return cs.getInt(2);
+        Long enuu = SystemSession.getUser().getEnterprise().getUu();
+        String sql = "/*#mycat:db_type=master*/ call vendor_match_products(%s, @out); select @out";
+        final String querySql = String.format(sql, enuu);
+        String updateCount = jdbcTemplate.execute(new StatementCallback<String>() {
+
+            @Override
+            public String doInStatement(Statement stmt) throws SQLException, DataAccessException {
+                stmt.executeQuery(querySql);
+                ResultSet rs = stmt.getResultSet();
+                if (rs != null) {
+                    rs.next();
+                    return rs.getString(1);
                 }
-            });
-        return updateCount;
+                return null;
+            }
+        });
+        if (StringUtils.isEmpty(updateCount)) {
+            return 0;
+        }
+        return Integer.valueOf(updateCount);
     }
 
 

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

@@ -470,7 +470,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		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>() {
+		jdbcTemplate.execute(new StatementCallback<String>() {
 
 			@Override
 			public String doInStatement(Statement stmt) throws SQLException, DataAccessException {