From 6c014b6824b10f9f00b91960bfd33bb823caff53 Mon Sep 17 00:00:00 2001 From: whoami <chao.chen@yoho.cn> Date: Wed, 12 Feb 2020 22:13:30 +0800 Subject: [PATCH] add retrieve and update display --- coupon/src/main/java/com/yoho/ufo/coupon/service/impl/CouponServiceImpl.java | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ dal/src/main/java/com/yoho/ufo/dal/CouponDisplayMapper.java | 11 +++++++++++ dal/src/main/java/com/yoho/ufo/dal/model/CouponDisplay.java | 16 ++++++++++++++++ dal/src/main/resources/META-INF/mybatis/CouponDisplayMapper.xml | 20 ++++++++++++++++++++ web/src/main/resources/databases.yml | 1 + web/src/main/webapp/META-INF/autoconf/databases.yml | 1 + 6 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 dal/src/main/java/com/yoho/ufo/dal/CouponDisplayMapper.java create mode 100644 dal/src/main/java/com/yoho/ufo/dal/model/CouponDisplay.java create mode 100644 dal/src/main/resources/META-INF/mybatis/CouponDisplayMapper.xml diff --git a/coupon/src/main/java/com/yoho/ufo/coupon/service/impl/CouponServiceImpl.java b/coupon/src/main/java/com/yoho/ufo/coupon/service/impl/CouponServiceImpl.java index a77a32c..e85eb47 100644 --- a/coupon/src/main/java/com/yoho/ufo/coupon/service/impl/CouponServiceImpl.java +++ b/coupon/src/main/java/com/yoho/ufo/coupon/service/impl/CouponServiceImpl.java @@ -7,11 +7,14 @@ import com.google.common.base.Splitter; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.yoho.core.rabbitmq.YhProducer; +import com.yoho.core.rest.client.ServiceCaller; import com.yoho.error.exception.ServiceException; import com.yoho.ufo.coupon.service.ICouponService; +import com.yoho.ufo.dal.CouponDisplayMapper; import com.yoho.ufo.dal.CouponMapper; import com.yoho.ufo.dal.CouponProductLimitMapper; import com.yoho.ufo.dal.UserCouponMapper; +import com.yoho.ufo.dal.model.CouponDisplay; import com.yoho.ufo.dal.model.UidImportTranItem; import com.yoho.ufo.exception.PlatformException; import com.yoho.ufo.model.coupon.Coupon; @@ -28,7 +31,10 @@ import com.yoho.ufo.service.model.ApiResponse; import com.yohobuy.ufo.coupon.req.*; import com.yohobuy.ufo.model.common.PageResponseBO; import com.yohobuy.ufo.model.order.constants.SkupType; +import com.yohobuy.ufo.model.promotion.CouponDisplayBo; import com.yohobuy.ufo.model.promotion.constant.CouponTypeEnum; +import com.yohobuy.ufo.model.promotion.constant.PositionType; +import com.yohobuy.ufo.model.promotion.constant.Visibility; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang3.StringUtils; @@ -56,6 +62,9 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{ private CouponMapper couponMapper; @Autowired + private CouponDisplayMapper couponDisplayMapper; + + @Autowired private CouponProductLimitMapper couponProductLimitMapper; @Autowired @@ -70,6 +79,9 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{ @Resource(name = "yhProducer") private YhProducer yhProducer; + @Autowired + private ServiceCaller serviceCaller; + @Override public Class getDataClass() { return (Class)request.getAttribute("exportClassType"); @@ -210,7 +222,7 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{ throw new ServiceException(400, "错误:优惠券信息不存在"); } } - + Integer couponId; // 插入 if(Objects.isNull(coupon)){ LOGGER.info("before saveOrUpdateCoupon#insert,req is {}",req); @@ -220,17 +232,18 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{ couponMapper.insertByCouponSaveUpdateReq(req); LOGGER.info("after saveOrUpdateCoupon#insert,req is {}",req); saveProductLimitItems(req, productLimitType, productIds); + couponId = req.getId(); } // 更新 else { LOGGER.info("before saveOrUpdateCoupon#deleteByCouponId,couponId is {}",req.getId()); // 已经有了优惠券的发放记录 - UserCouponNum userCouponNum = userCouponMapper.selectByCouponId(coupon.getId()); + UserCouponNum userCouponNum = userCouponMapper.selectByCouponId(couponId = coupon.getId()); if (Objects.nonNull(userCouponNum) && userCouponNum.getCnt()>0){ LOGGER.info("sendNum bigger than 0, name|couponNu|remark only can update, couponId {}", req.getId()); CouponSaveUpdateReq couponSaveUpdateReq = new CouponSaveUpdateReq(); - couponSaveUpdateReq.setId(coupon.getId()); + couponSaveUpdateReq.setId(couponId); // 名称 couponSaveUpdateReq.setCouponName(req.getCouponName()); @@ -252,6 +265,8 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{ LOGGER.info("has coupon send, saveOrUpdateCoupon#update,req is {}",req); couponMapper.updateByCouponSaveUpdateReq(couponSaveUpdateReq); + + }else{ LOGGER.info("sendNum noting, all info can update, couponId {}", req.getId()); @@ -264,9 +279,7 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{ LOGGER.info("after saveOrUpdateCoupon#update,req is {}",req); } - - - + saveOrUpdateDisplay(couponId, req.getShowInPrdDetail()); return new ApiResponse.ApiResponseBuilder().build(); } @@ -279,6 +292,27 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{ req.setSkupAllowType(Joiner.on(",").join(allowAttributeTypes)); } + private final static String API_ADDORUPDATEDISPLAY = "coupon.addOrUpdateDisplay"; + private void saveOrUpdateDisplay(Integer couponId, String showInPrdDetail){ + LOGGER.info("saveOrUpdateDisplay couponId {} showInPrdDetail {}", couponId, showInPrdDetail); + PositionType positionType = PositionType.PRD_DETAIL; + Visibility visibilityEnum; + if (StringUtils.isNotBlank(showInPrdDetail)&& "Y".equalsIgnoreCase(showInPrdDetail)){ + visibilityEnum = Visibility.YES; + }else{ + visibilityEnum = Visibility.NO; + } + byte visibility = visibilityEnum.getCode(); + + CouponDisplayBo req = CouponDisplayBo.builder().couponId(couponId) + .positionType(positionType.getCode()) + .visibility(visibility) + .build(); + final String api = API_ADDORUPDATEDISPLAY; + LOGGER.info("saveOrUpdateDisplay ready call {}, req {}", api, req); + Integer num = serviceCaller.call(api, req, Integer.class); + LOGGER.info("saveOrUpdateDisplay finish call {}, req {} num {}", api, req, num); + } private void parseSkupForbidType(CouponSaveUpdateReq req) { if (StringUtils.isBlank(req.getSkupForbidType())) { @@ -352,8 +386,29 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{ .orElse(0); coupon.setSendNum(userCouponNum); + // + String showInPrdDetail = "N"; + List<CouponDisplay> pcdList = couponDisplayMapper.selectByCouponId(id); + if (CollectionUtils.isNotEmpty(pcdList)){ + for(CouponDisplay pcd : pcdList){ + Integer positionTypeCode; + if(Objects.isNull(positionTypeCode=pcd.getPositionType())){ + continue; + } + PositionType positionType = PositionType.getPositionTypeByCode(positionTypeCode); + switch (positionType){ + case PRD_DETAIL: + if (pcd.getVisibility() == (byte)1){ + showInPrdDetail = "Y"; + } + break; + } + } + } + JSONObject jsonObject = new JSONObject(); jsonObject.put("coupon",coupon); + jsonObject.put("showInPrdDetail", showInPrdDetail); jsonObject.put("productLimits",productLimitList); return new ApiResponse.ApiResponseBuilder().data(jsonObject).build(); } diff --git a/dal/src/main/java/com/yoho/ufo/dal/CouponDisplayMapper.java b/dal/src/main/java/com/yoho/ufo/dal/CouponDisplayMapper.java new file mode 100644 index 0000000..5bbb309 --- /dev/null +++ b/dal/src/main/java/com/yoho/ufo/dal/CouponDisplayMapper.java @@ -0,0 +1,11 @@ +package com.yoho.ufo.dal; + +import com.yoho.ufo.dal.model.CouponDisplay; + +import java.util.List; + +public interface CouponDisplayMapper { + + List<CouponDisplay> selectByCouponId(Integer id); + +} \ No newline at end of file diff --git a/dal/src/main/java/com/yoho/ufo/dal/model/CouponDisplay.java b/dal/src/main/java/com/yoho/ufo/dal/model/CouponDisplay.java new file mode 100644 index 0000000..7bd768e --- /dev/null +++ b/dal/src/main/java/com/yoho/ufo/dal/model/CouponDisplay.java @@ -0,0 +1,16 @@ +package com.yoho.ufo.dal.model; + +import lombok.Data; + +@Data +public class CouponDisplay { + private Integer id; + + private Integer couponId; + + private Integer positionType; + + private Byte visibility; + + +} \ No newline at end of file diff --git a/dal/src/main/resources/META-INF/mybatis/CouponDisplayMapper.xml b/dal/src/main/resources/META-INF/mybatis/CouponDisplayMapper.xml new file mode 100644 index 0000000..3726ca8 --- /dev/null +++ b/dal/src/main/resources/META-INF/mybatis/CouponDisplayMapper.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="com.yoho.ufo.dal.CouponDisplayMapper"> + <resultMap id="BaseResultMap" type="com.yoho.ufo.dal.model.CouponDisplay"> + <id column="id" jdbcType="INTEGER" property="id" /> + <result column="coupon_id" jdbcType="INTEGER" property="couponId" /> + <result column="position_type" jdbcType="INTEGER" property="positionType" /> + <result column="visibility" jdbcType="TINYINT" property="visibility" /> + </resultMap> + <sql id="Base_Column_List"> + id, coupon_id, position_type, visibility + </sql> + <select id="selectByCouponId" parameterType="java.lang.Integer" resultMap="BaseResultMap"> + select + <include refid="Base_Column_List" /> + from coupon_display + where coupon_id = #{couponId,jdbcType=INTEGER} + </select> + +</mapper> \ No newline at end of file diff --git a/web/src/main/resources/databases.yml b/web/src/main/resources/databases.yml index b764c52..a2d7592 100644 --- a/web/src/main/resources/databases.yml +++ b/web/src/main/resources/databases.yml @@ -116,6 +116,7 @@ datasources: - com.yoho.ufo.dal.PromotionActivityMapper - com.yoho.ufo.dal.PromotionProductScopeMapper - com.yoho.ufo.dal.PromotionTypeConditionMapper + - com.yoho.ufo.dal.CouponDisplayMapper ufo_passport: servers: diff --git a/web/src/main/webapp/META-INF/autoconf/databases.yml b/web/src/main/webapp/META-INF/autoconf/databases.yml index 0481d2c..71f65bc 100644 --- a/web/src/main/webapp/META-INF/autoconf/databases.yml +++ b/web/src/main/webapp/META-INF/autoconf/databases.yml @@ -119,6 +119,7 @@ datasources: - com.yoho.ufo.dal.PromotionActivityMapper - com.yoho.ufo.dal.PromotionProductScopeMapper - com.yoho.ufo.dal.PromotionTypeConditionMapper + - com.yoho.ufo.dal.CouponDisplayMapper ufo_passport: servers: -- libgit2 0.24.0