From 3909a95495f8fc9c8c97e5dc30d0cb950ef41523 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Tue, 16 Apr 2019 23:31:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E7=AB=AF=EF=BC=9A=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=20MyBatis=20JSONTypeHandler=20=E5=90=8E=E7=AB=AF=EF=BC=9A?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8C=87=E5=AE=9A=E5=95=86=E5=93=81=E7=9A=84?= =?UTF-8?q?=E4=BF=83=E9=94=80=E4=BB=B7=E6=A0=BC=E8=AE=A1=E7=AE=97=20?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=EF=BC=9A=E5=95=86=E5=93=81=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E9=A1=B5=EF=BC=8C=E5=A2=9E=E5=8A=A0=E4=BF=83=E9=94=80=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/common-framework/pom.xml | 19 ++- .../framework/mybatis/JSONTypeHandler.java | 70 ++++++++++ mobile-web/src/api/order.js | 10 ++ mobile-web/src/page/product/detail.vue | 86 ++++++------ .../controller/users/UsersCartController.java | 13 ++ .../application/convert/CartConvert.java | 4 + .../application/vo/UsersCalcSkuPriceVO.java | 34 +++++ .../iocoder/mall/order/api/CartService.java | 26 ++-- .../order/biz/service/CartServiceImpl.java | 70 ++++++++-- .../service/ProductSpuServiceImpl.java | 3 +- .../mall/promotion/api/bo/BannerBO.java | 3 +- .../mall/promotion/api/bo/BannerPageBO.java | 3 +- .../mall/promotion/api/bo/CouponCardBO.java | 3 +- .../promotion/api/bo/CouponCardPageBO.java | 3 +- .../promotion/api/bo/CouponTemplateBO.java | 3 +- .../api/bo/CouponTemplatePageBO.java | 3 +- .../promotion/api/bo/ProductRecommendBO.java | 3 +- .../api/bo/ProductRecommendPageBO.java | 3 +- .../promotion/api/bo/PromotionActivityBO.java | 22 +-- .../api/constant/PreferentialTypeEnum.java | 4 +- .../promotion/api/constant/RangeTypeEnum.java | 8 +- .../biz/convert/ProductRecommendConvert.java | 10 +- .../biz/convert/PromotionActivityConvert.java | 28 ++++ .../biz/dao/PromotionActivityMapper.java | 19 +++ .../biz/dataobject/PromotionActivityDO.java | 8 +- .../promotion/biz/mybatis/TestHandler.java | 12 ++ .../service/PromotionActivityServiceImpl.java | 85 ++++++++++++ .../mapper/PromotionActivityMapper.xml | 131 ++++++++++++++++++ .../src/main/resources/mybatis-config.xml | 2 +- .../mall/promotion/biz/Application.java | 7 + .../biz/dao/PromotionActivityMapperTest.java | 94 +++++++++++++ .../mall/promotion/biz/package-info.java | 1 + 32 files changed, 686 insertions(+), 104 deletions(-) create mode 100644 common/common-framework/src/main/java/cn/iocoder/common/framework/mybatis/JSONTypeHandler.java create mode 100644 order/order-application/src/main/java/cn/iocoder/mall/order/application/vo/UsersCalcSkuPriceVO.java create mode 100644 promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/convert/PromotionActivityConvert.java create mode 100644 promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/PromotionActivityMapper.java create mode 100644 promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/mybatis/TestHandler.java create mode 100644 promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/PromotionActivityServiceImpl.java create mode 100644 promotion/promotion-service-impl/src/main/resources/mapper/PromotionActivityMapper.xml create mode 100644 promotion/promotion-service-impl/src/test/java/cn/iocoder/mall/promotion/biz/Application.java create mode 100644 promotion/promotion-service-impl/src/test/java/cn/iocoder/mall/promotion/biz/dao/PromotionActivityMapperTest.java create mode 100644 promotion/promotion-service-impl/src/test/java/cn/iocoder/mall/promotion/biz/package-info.java diff --git a/common/common-framework/pom.xml b/common/common-framework/pom.xml index e5ba85817..e88edb5ff 100644 --- a/common/common-framework/pom.xml +++ b/common/common-framework/pom.xml @@ -64,8 +64,25 @@ org.apache.commons commons-lang3 + + org.mybatis + mybatis + 3.5.0 + + + com.fasterxml.jackson.core + jackson-databind + 2.9.8 + compile + + + com.fasterxml.jackson.core + jackson-annotations + 2.9.7 + compile + - \ No newline at end of file + diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/mybatis/JSONTypeHandler.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/mybatis/JSONTypeHandler.java new file mode 100644 index 000000000..b68ced706 --- /dev/null +++ b/common/common-framework/src/main/java/cn/iocoder/common/framework/mybatis/JSONTypeHandler.java @@ -0,0 +1,70 @@ +package cn.iocoder.common.framework.mybatis; + +import com.alibaba.fastjson.JSON; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +/** + * TODO 芋艿 + * + * 参考 https://www.cnblogs.com/waterystone/p/5547254.html + * + * 后续,补充下注释和测试类,以及文章。 + * + * @param + */ +public class JSONTypeHandler extends BaseTypeHandler { + + private Class clazz; + + public JSONTypeHandler(Class clazz) { + if (clazz == null) throw new IllegalArgumentException("Type argument cannot be null"); + this.clazz = clazz; + } + + @Override + public void setNonNullParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException { + ps.setString(i, this.toJson(parameter)); + } + + @Override + public T getNullableResult(ResultSet rs, String columnName) throws SQLException { + return this.toObject(rs.getString(columnName), clazz); + } + + @Override + public T getNullableResult(ResultSet rs, int columnIndex) throws SQLException { + return this.toObject(rs.getString(columnIndex), clazz); + } + + @Override + public T getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { + return this.toObject(cs.getString(columnIndex), clazz); + } + + private String toJson(T object) { + try { + return JSON.toJSONString(object); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private T toObject(String content, Class clazz) { + if (content != null && !content.isEmpty()) { + try { + return (T) JSON.parseObject(content, clazz); + } catch (Exception e) { + throw new RuntimeException(e); + } + } else { + return null; + } + } + +} diff --git a/mobile-web/src/api/order.js b/mobile-web/src/api/order.js index edc977caa..fda924a28 100644 --- a/mobile-web/src/api/order.js +++ b/mobile-web/src/api/order.js @@ -120,6 +120,16 @@ export function getCartConfirmCreateOrder(skuId, quantity) { }); } +export function getCartCalcSkuPrice(skuId) { + return request({ + url: '/order-api/users/cart/calc_sku_price', + method: 'get', + params: { + skuId, + } + }); +} + // 物流信息 export function getLogisticsInfo(params) { diff --git a/mobile-web/src/page/product/detail.vue b/mobile-web/src/page/product/detail.vue index a69c48a60..759ce9e9a 100644 --- a/mobile-web/src/page/product/detail.vue +++ b/mobile-web/src/page/product/detail.vue @@ -7,27 +7,13 @@ -
-
- ¥2.8 -
-
¥14
-
限时抢购
-
-
-
-

距离结束仅剩

-
714202
-
-
- - - {{ formatPrice(initialSku.price) }} - -
{{ spu.name }}
-
{{spu.sellPoint}}
-
+ + {{ formatPrice(initialSku.price) }} + +
{{ spu.name }}
+
{{spu.sellPoint}}
+
@@ -79,6 +65,25 @@
+ + + + + + + + + + + + +

图文详情

@@ -99,28 +104,6 @@ - - - - - - - - - - - - - - - - - - - - - - @@ -181,8 +164,8 @@