Просмотр исходного кода

修改数据库方言,修改ifnull函数为coalesce

suntg 8 лет назад
Родитель
Сommit
82cdfbc526

+ 1 - 1
src/main/java/com/uas/platform/b2c/common/help/dao/HelpNavDao.java

@@ -27,7 +27,7 @@ public interface HelpNavDao extends JpaSpecificationExecutor<HelpNav>, JpaReposi
      * @param parentId 父导航id
      * @return 子导航最大序号
      */
-    @Query("select ifnull(max(h.detno),0) from HelpNav h where h.parentId = :parentId")
+    @Query("select coalesce(max(h.detno),0) from HelpNav h where h.parentId = :parentId")
     Short findMaxDetno(@Param("parentId") Long parentId);
 
     /**

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

@@ -80,7 +80,7 @@ public interface GoodsDao extends JpaSpecificationExecutor<Goods>, JpaRepository
      * @param status the status 状态
      * @return double
      */
-    @Query("select sum(ifnull(g.reserve, 0)) from Goods g where g.uuid=:uuid and g.status =:status")
+    @Query("select sum(coalesce(g.reserve)) from Goods g where g.uuid=:uuid and g.status =:status")
 	Double findTotalReserveByUuid(@Param("uuid") String uuid, @Param("status") Integer status);
 
     /**
@@ -199,7 +199,7 @@ public interface GoodsDao extends JpaSpecificationExecutor<Goods>, JpaRepository
      * @param status the status 状态
      * @return double
      */
-    @Query("select sum(ifnull(g.sampleQty, 0) - ifnull(g.sampleAppliedQty, 0)) from Goods g where g.uuid=:uuid and g.status =:status")
+    @Query("select sum(coalesce(g.sampleQty, 0) - coalesce(g.sampleAppliedQty, 0)) from Goods g where g.uuid=:uuid and g.status =:status")
 	Double findAvailableSampleQtyByUuid(@Param("uuid") String uuid, @Param("status") Integer status);
 
     /**
@@ -209,7 +209,7 @@ public interface GoodsDao extends JpaSpecificationExecutor<Goods>, JpaRepository
      * @param status the status 状态
      * @return double
      */
-    @Query("select sum(ifnull(g.reserve, 0)) from Goods g where g.uuid=:uuid and g.original=1311 and g.status =:status")
+    @Query("select sum(coalesce(g.reserve, 0)) from Goods g where g.uuid=:uuid and g.original=1311 and g.status =:status")
 	Double findOriginalQtyByUuid(@Param("uuid") String uuid, @Param("status") Integer status);
 
     /**
@@ -219,7 +219,7 @@ public interface GoodsDao extends JpaSpecificationExecutor<Goods>, JpaRepository
      * @param status the status 状态
      * @return double
      */
-    @Query("select sum(ifnull(g.reserve, 0)) from Goods g where g.uuid=:uuid and g.original=1312 and g.status =:status")
+    @Query("select sum(coalesce(g.reserve, 0)) from Goods g where g.uuid=:uuid and g.original=1312 and g.status =:status")
 	Double findInactionStockQtyByUuid(@Param("uuid") String uuid, @Param("status") Integer status);
 
     /**
@@ -229,7 +229,7 @@ public interface GoodsDao extends JpaSpecificationExecutor<Goods>, JpaRepository
      * @param status the status 状态
      * @return double
      */
-    @Query(value = "select sum(ifnull(g.sampleAppliedQty, 0)) from Goods g where g.uuid=:uuid and g.status =:status")
+    @Query(value = "select sum(coalesce(g.sampleAppliedQty, 0)) from Goods g where g.uuid=:uuid and g.status =:status")
 	Double findApplyedSampleQty(@Param("uuid") String uuid, @Param("status") Integer status);
 
 	/**
@@ -248,7 +248,7 @@ public interface GoodsDao extends JpaSpecificationExecutor<Goods>, JpaRepository
      * @param qty the qty 数量
      * @return list
      */
-    @Query(value = "select * from (select * from trade$goods g where ifnull(g.go_sampleqty, 0) - ifnull(g.go_sampleappliedqty, 0) >0 order by go_id desc) where rownum<=:qty", nativeQuery = true)
+    @Query(value = "select * from (select * from trade$goods g where coalesce(g.go_sampleqty, 0) - coalesce(g.go_sampleappliedqty, 0) >0 order by go_id desc) where rownum<=:qty", nativeQuery = true)
 	List<Goods> findAvailableSampleQty(@Param("qty") Integer qty);
 
     /**
@@ -361,7 +361,7 @@ public interface GoodsDao extends JpaSpecificationExecutor<Goods>, JpaRepository
      * @param storeid the storeid 店铺uuid
      * @return double
      */
-    @Query(value = "select sum(ifnull(g.reserve, 0)) from Goods g where g.enUU =:enUU and g.storeid =:storeid")
+    @Query(value = "select sum(coalesce(g.reserve, 0)) from Goods g where g.enUU =:enUU and g.storeid =:storeid")
 	Double findSumReserveByEnuuAndStoreid(@Param("enUU") Long enuu, @Param("storeid") String storeid);
 
     /**
@@ -379,7 +379,7 @@ public interface GoodsDao extends JpaSpecificationExecutor<Goods>, JpaRepository
      * @param enuu the enuu 企业的enuu
      * @return double
      */
-    @Query(value = "select sum(g.reserve * ifnull(g.maxPriceRMB, 0)) from Goods g where g.enUU =:enUU")
+    @Query(value = "select sum(g.reserve * coalesce(g.maxPriceRMB, 0)) from Goods g where g.enUU =:enUU")
 	public Double findSumRMBByEnuu(@Param("enUU") Long enuu);
 
     /**

+ 1 - 1
src/main/java/com/uas/platform/b2c/prod/product/kind/dao/KindDao.java

@@ -29,7 +29,7 @@ public interface KindDao extends JpaSpecificationExecutor<Kind>, JpaRepository<K
 	 * @param parentid
 	 * @return
 	 */
-	@Query("select ifnull(max(k.detno), 0) from Kind k where k.parentid = :parentid")
+	@Query("select coalesce(max(k.detno), 0) from Kind k where k.parentid = :parentid")
 	public short findLastNumberByParentid(@Param("parentid") Long parentid);
 
 	/**

+ 2 - 2
src/main/java/com/uas/platform/b2c/prod/store/dao/StoreInDao.java

@@ -69,7 +69,7 @@ public interface StoreInDao extends JpaSpecificationExecutor<StoreIn>, JpaReposi
 	 *
 	 * @return List<StoreIn>
 	 */
-	@Query(nativeQuery = true, value = "select ifnull(s,0) m, i.* from (select sum(ifnull(go_reserve,0)) s, go_storeid" +
+	@Query(nativeQuery = true, value = "select coalesce(s,0) m, i.* from (select sum(coalesce(go_reserve,0)) s, go_storeid" +
 			" from trade$goods g group by go_storeid ) a right join store$info i " +
 			" on a.go_storeid=i.ST_UUID where i.ST_TYPE ='AGENCY' or i.ST_TYPE ='DISTRIBUTION' order by m DESC")
 	List<StoreIn> findAGENCYStoreIn();
@@ -79,7 +79,7 @@ public interface StoreInDao extends JpaSpecificationExecutor<StoreIn>, JpaReposi
 	 *
 	 * @return List<StoreIn>
 	 */
-	@Query(nativeQuery = true, value = "select ifnull(s,0) m, i.* from (select sum(ifnull(go_reserve,0)) s, go_storeid" +
+	@Query(nativeQuery = true, value = "select coalesce(s,0) m, i.* from (select sum(coalesce(go_reserve,0)) s, go_storeid" +
 			" from trade$goods g group by go_storeid ) a right join store$info i " +
 			" on a.go_storeid=i.ST_UUID where i.ST_TYPE ='ORIGINAL_FACTORY' order by m DESC")
 	List<StoreIn> findOriginalStoreIn();

+ 1 - 1
src/main/java/com/uas/platform/b2c/trade/order/dao/PurchaseDao.java

@@ -173,7 +173,7 @@ public interface PurchaseDao extends JpaSpecificationExecutor<Purchase>, JpaRepo
 	 * @param storeid    店铺的id(代表自营或代售)
 	 * @return sum price by currency and selleruu and storeid
 	 */
-	@Query(value = "select sum(ifnull(p.ensurePrice, 0)) from trade.Purchase p where p.sellerenuu=:sellerenuu and p.storeid =:storeid and p.currency =:currency")
+	@Query(value = "select sum(coalesce(p.ensurePrice, 0)) from trade.Purchase p where p.sellerenuu=:sellerenuu and p.storeid =:storeid and p.currency =:currency")
 	Double getSumPriceByCurrencyAndSelleruuAndStoreid(@Param("currency") String crname, @Param("sellerenuu") Long sellerenuu, @Param("storeid") String storeid);
 
 	/**

+ 1 - 1
src/main/java/com/uas/platform/b2c/trade/order/dao/PurchaseDetailDao.java

@@ -44,7 +44,7 @@ public interface PurchaseDetailDao extends JpaSpecificationExecutor<PurchaseDeta
 	 * @param status    the status
 	 * @return the total by batch code
 	 */
-	@Query(value = "select sum(ifnull(p.number, 0)) from PurchaseDetail p where p.batchCode =:batchCode and p.status in :status")
+	@Query(value = "select sum(coalesce(p.number, 0)) from PurchaseDetail p where p.batchCode =:batchCode and p.status in :status")
 	Double getTotalByBatchCode(@Param("batchCode") String batchCode, @Param("status") List<Integer> status);
 
 	/**

+ 1 - 1
src/main/resources/META-INF/persistence.xml

@@ -11,7 +11,7 @@
 				value="true" />
 			<property name="hibernate.cache.region.factory_class"
 				value="org.hibernate.cache.ehcache.EhCacheRegionFactory" />
-			<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
+			<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
 			<!-- value="create" to build a new database on each run; value="update" 
 				to modify an existing database; value="create-drop" means the same as "create" 
 				but also drops tables when Hibernate closes; value="validate" makes no changes 

+ 1 - 1
src/main/resources/spring/context.xml

@@ -110,7 +110,7 @@
 		<property name="jpaVendorAdapter">
 			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
 				<property name="generateDdl" value="false" />
-				<property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" />
+				<property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
 				<property name="showSql" value="false" />
 			</bean>
 		</property>