From 084fe820a4b1a6541005b0bbab9e813899188962 Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Wed, 3 Jun 2020 22:36:20 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=88=B8][=E6=96=B0=E5=A2=9E]:=E5=88=B8?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=AF=8C=E6=96=87=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/market/WxCouponController.java | 9 +++ .../db/migration/V202006032111__COUPON_H5.sql | 3 + .../controller/WxCouponOrderController.java | 66 +++++++++++++++---- .../controller/WxCouponController.java | 65 ++++++++++++++++++ .../java/com/iformall/domain/po/WxCoupon.java | 5 ++ .../iformall/domain/vo/WxCouponChannelVo.java | 3 + .../iformall/enums/EnumCouponContentType.java | 37 +++++++++++ .../com/iformall/service/WxCouponService.java | 2 + .../service/impl/WxCouponServiceImpl.java | 12 ++++ .../mapper/WxCouponChannelMapper.xml | 7 +- .../main/resources/mapper/WxCouponMapper.xml | 18 +++-- 11 files changed, 207 insertions(+), 20 deletions(-) create mode 100644 mallinkAdmin/src/main/resources/db/migration/V202006032111__COUPON_H5.sql create mode 100644 mallinkService/src/main/java/com/iformall/enums/EnumCouponContentType.java diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponController.java b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponController.java index fd92888e1..cf89ae966 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponController.java @@ -355,4 +355,13 @@ public class WxCouponController extends BaseController { couponPasswordService.exportData(request, response, wxCouponPassword); } + @ApiOperation("根据id获取富文本接口") + @GetMapping("/getHtml") + @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) + @SystemControllerLog(description = "券投放-富文本获取") + public ResultData getHtml(@RequestParam Long id) { + logger.debug("[" + getIpAddr() + "] WxCouponController::findById"); + return new ResultData(wxCouponService.getHtmlById(id)); + } + } diff --git a/mallinkAdmin/src/main/resources/db/migration/V202006032111__COUPON_H5.sql b/mallinkAdmin/src/main/resources/db/migration/V202006032111__COUPON_H5.sql new file mode 100644 index 000000000..6136306b9 --- /dev/null +++ b/mallinkAdmin/src/main/resources/db/migration/V202006032111__COUPON_H5.sql @@ -0,0 +1,3 @@ +ALTER TABLE `wx_coupon` +ADD COLUMN `content_type` tinyint(1) NULL COMMENT '内容类型(0:小程序页面类型,1:富文本类型)' AFTER `approval_type`, +ADD COLUMN `html` mediumtext NULL COMMENT '富文本内容' AFTER `content_type`; \ No newline at end of file diff --git a/mallinkBApi/src/main/java/com/iformall/controller/WxCouponOrderController.java b/mallinkBApi/src/main/java/com/iformall/controller/WxCouponOrderController.java index 2a8c705cf..6588a09d9 100644 --- a/mallinkBApi/src/main/java/com/iformall/controller/WxCouponOrderController.java +++ b/mallinkBApi/src/main/java/com/iformall/controller/WxCouponOrderController.java @@ -5,10 +5,7 @@ import com.iformall.annotation.RedisCache; import com.iformall.common.ErrorCode; import com.iformall.common.Result; import com.iformall.common.ResultData; -import com.iformall.domain.po.WxCUserBasicInfo; -import com.iformall.domain.po.WxCouponOrder; -import com.iformall.domain.po.WxMerchant; -import com.iformall.domain.po.WxMerchantBUser; +import com.iformall.domain.po.*; import com.iformall.domain.vo.WxCouponCVo; import com.iformall.domain.vo.WxCouponOrderCVo; import com.iformall.enums.EnumCouponValidType; @@ -83,8 +80,8 @@ public class WxCouponOrderController extends BaseController { @GetMapping("listUnverified") @ApiImplicitParams({ @ApiImplicitParam(name = "date", value = "日期yyyy-MM-dd", dataType = "string", paramType = "query"), - @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query",required = true), - @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query",required = true)}) + @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), + @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) public ResultData listUnverified(String date, Integer pageNum, Integer pageSize) { return wxCouponOrderService.listOnDateAsPage(getUser().getId(), date, pageNum, pageSize, false); } @@ -93,8 +90,8 @@ public class WxCouponOrderController extends BaseController { @GetMapping("listVerified") @ApiImplicitParams({ @ApiImplicitParam(name = "date", value = "日期yyyy-MM-dd", dataType = "string", paramType = "query"), - @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query",required = true), - @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query",required = true)}) + @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), + @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) public ResultData listVerified(String date, Integer pageNum, Integer pageSize) { return wxCouponOrderService.listOnDateAsPage(getUser().getId(), date, pageNum, pageSize, true); } @@ -124,8 +121,8 @@ public class WxCouponOrderController extends BaseController { @ApiImplicitParams({ @ApiImplicitParam(name = "couponOrderId", value = "券ID", dataType = "string", paramType = "query", required = true) }) - public ResultData detail(String couponOrderId) { - if(couponOrderId == null) { + public ResultData detail(String couponOrderId) { + if (couponOrderId == null) { return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); } Long bUserId = getUser().getId(); @@ -185,10 +182,53 @@ public class WxCouponOrderController extends BaseController { return new ResultData(wxCouponOrderCVo); } + @ApiOperation(value = "卡券富文本接口") + @GetMapping("html") + @ApiImplicitParams({ + @ApiImplicitParam(name = "couponOrderId", value = "券ID", dataType = "string", paramType = "query", required = true) + }) + public ResultData getHtml(String couponOrderId) { + if (couponOrderId == null) { + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); + } + WxCouponOrderCVo wxCouponOrderCVo = null; + try { + wxCouponOrderCVo = wxCouponOrderService.simpleDetailCUserVo(couponOrderId); + } catch (Exception e) { + return new ResultData(ErrorCode.COUPON_ORDER_IS_NULL); + } + if (wxCouponOrderCVo == null) { + return new ResultData(ErrorCode.COUPON_ORDER_IS_NULL); + } + WxCouponCVo wxCouponCVo = null; + String key = "ch:" + wxCouponOrderCVo.getCouponId(); + ValueOperations operations = cdRedisTemplate.opsForValue(); + // 缓存 + boolean hasKey = cdRedisTemplate.hasKey(key); + if (hasKey) { + // 从缓存获取用户信息 + wxCouponCVo = operations.get(key); + if (wxCouponCVo == null) { + return new ResultData(ErrorCode.COUPON_IS_EMPTY); + } + } else { + WxCoupon wxCoupon = wxCouponService.getById(wxCouponOrderCVo.getCouponId()); + if (wxCoupon == null) { + return new ResultData(ErrorCode.COUPON_IS_EMPTY); + } + wxCouponCVo = new WxCouponCVo(); + wxCouponCVo.setId(wxCouponOrderCVo.getCouponId()); + wxCouponCVo.setHtml(wxCoupon.getHtml()); + // 插入缓存 + operations.set(key, wxCouponCVo, 3600, TimeUnit.SECONDS); + } + return new ResultData(wxCouponOrderCVo); + } + @ApiOperation(value = "核销接口", notes = "{\"couponOrderId\":\"string\"}") @PostMapping("verify") public ResultData verify(@RequestBody Map paramMap) { - logger.info("couponOrderController.verify:"+paramMap.toString()); + logger.info("couponOrderController.verify:" + paramMap.toString()); String couponOrderIdStr = paramMap.get("couponOrderId"); if (StringUtils.isBlank(couponOrderIdStr)) { logger.error("couponOrderId不能为空: " + paramMap.toString()); @@ -253,7 +293,7 @@ public class WxCouponOrderController extends BaseController { return new ResultData(ErrorCode.VERIFY_ERROR, e.getMessage()); } - if(couponOrder != null) { + if (couponOrder != null) { wxCouponOrderService.sendInsideCouponVerifyMsg(couponOrder, couponOrderId, wxMerchantBUser.getId()); } @@ -292,6 +332,4 @@ public class WxCouponOrderController extends BaseController { } - - } diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxCouponController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxCouponController.java index 01ba206ce..4b4c8ed21 100644 --- a/mallinkCApi/src/main/java/com/iformall/controller/WxCouponController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxCouponController.java @@ -128,6 +128,53 @@ public class WxCouponController extends BaseController { return new ResultData(wxCouponCVo); } + + @ApiOperation("根据id(couponChannel)查询富文本接口") + @GetMapping("/html") + @ApiImplicitParams({ + @ApiImplicitParam(name = "couponChannelId", value = "couponChannelId", dataType = "String", paramType = "query", required = true), + @ApiImplicitParam(name = "couponId", value = "couponId", dataType = "String", paramType = "query", required = false)}) + public ResultData getHtml(String couponChannelId, String couponId) { + if (StringUtils.isBlank(couponChannelId) || couponChannelId.equalsIgnoreCase(Constant.UNDEFINED)) { + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId/couponId为空"); + } + Long couponChannelIdL = 0L, couponIdL = 0L; + try { + couponChannelIdL = Long.valueOf(couponChannelId); + if (StringUtils.isNotBlank(couponId) && !couponId.equalsIgnoreCase(Constant.UNDEFINED)) { + couponIdL = Long.valueOf(couponId); + } + } catch (NumberFormatException e) { + logger.error("id转换失败" + couponChannelId); + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId转换失败" + couponChannelId); + } + + String key = "ch:" + couponChannelId; + + ValueOperations operations = cdRedisTemplate.opsForValue(); + // 缓存 + boolean hasKey = cdRedisTemplate.hasKey(key); + if (hasKey) { + // 从缓存获取用户信息 + WxCouponCVo wxCouponCVo = operations.get(key); + return new ResultData(wxCouponCVo); + } + WxCouponCVo wxCouponCVo = null; + try { + wxCouponCVo = generateWxCouponCVoForHtml(couponChannelIdL, couponIdL); + } catch (Exception e) { + logger.error("coupon html fail: " + couponChannelId,e); + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "coupon html fail: " + couponChannelId); + } + if (wxCouponCVo == null) { + return new ResultData(ErrorCode.COUPON_IS_EMPTY); + } + + // 插入缓存 + operations.set(key, wxCouponCVo, 3600, TimeUnit.SECONDS); + + return new ResultData(wxCouponCVo); + } private WxCouponCVo generateWxCouponCVo(Long couponChannelIdL) { WxCouponChannel cc = wxCouponChannelService.getById(couponChannelIdL); @@ -148,6 +195,24 @@ public class WxCouponController extends BaseController { return couponCVo; } + private WxCouponCVo generateWxCouponCVoForHtml(Long couponChannelIdL, Long couponIdL) { + WxCouponChannel cc = wxCouponChannelService.getById(couponChannelIdL); + if (cc == null) { + return null; + } + + WxCoupon c = couponService.getHtmlById(cc.getCouponId()); + if (c == null) { + return null; + } + + WxCouponCVo couponCVo = new WxCouponCVo(); + couponCVo.setId(cc.getId()); + couponCVo.setCouponId(cc.getCouponId()); + couponCVo.setHtml(c.getHtml()); + return couponCVo; + } + private WxCouponCVo generateWxCouponCVoex(Long couponChannelIdL) throws IllegalAccessException, InvocationTargetException { WxCouponChannel cc = wxCouponChannelService.getById(couponChannelIdL); diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java index fba0cbd9d..e755815ed 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java @@ -174,6 +174,11 @@ public class WxCoupon extends TenantEntity { @io.swagger.annotations.ApiModelProperty(value="作废审批状态",name="cancleApplyStatus") private Integer cancleApplyStatus; + @io.swagger.annotations.ApiModelProperty(value="内容类型(0:小程序页面类型,1:富文本类型)",name="contentType") + private Integer contentType; + @io.swagger.annotations.ApiModelProperty(value="富文本内容",name="html") + private String html; + @TableField(exist = false) @SortColumn(column = "press_count") private Integer pressSendCount; diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/WxCouponChannelVo.java b/mallinkService/src/main/java/com/iformall/domain/vo/WxCouponChannelVo.java index ab4c989d7..34ae78199 100644 --- a/mallinkService/src/main/java/com/iformall/domain/vo/WxCouponChannelVo.java +++ b/mallinkService/src/main/java/com/iformall/domain/vo/WxCouponChannelVo.java @@ -69,6 +69,9 @@ public class WxCouponChannelVo extends WxCouponChannel implements Serializable { @io.swagger.annotations.ApiModelProperty(value="领取条件",name="condition") private String conditions; + @io.swagger.annotations.ApiModelProperty(value="内容类型(0:小程序页面类型,1:富文本类型)",name="contentType") + private Integer contentType; + @TableField(exist = false) private String salePriceStr; diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumCouponContentType.java b/mallinkService/src/main/java/com/iformall/enums/EnumCouponContentType.java new file mode 100644 index 000000000..12563be3e --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumCouponContentType.java @@ -0,0 +1,37 @@ +package com.iformall.enums; + +/** + * Created by Stormeye on 2018/08/09. + */ +public enum EnumCouponContentType { + + // 0: 小程序页面, 1: 富文本页面 + NORMAL(0, "小程序页面"), + HTML(1,"富文本") + ; + + public static EnumCouponContentType getEnum(Integer code) { + for (EnumCouponContentType value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + private Integer code; + private String message; + + EnumCouponContentType(Integer code, String message) { + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/mallinkService/src/main/java/com/iformall/service/WxCouponService.java b/mallinkService/src/main/java/com/iformall/service/WxCouponService.java index aec2933b7..d3534a79e 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCouponService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCouponService.java @@ -54,6 +54,8 @@ public interface WxCouponService { */ WxCoupon getById(Long id); + WxCoupon getHtmlById(Long id); + WxCouponCVo getVoById(Long id); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java index 4b31c2d05..a998d6c0c 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java @@ -172,6 +172,12 @@ public class WxCouponServiceImpl implements WxCouponService { @Override public WxCoupon getById(Long id) { + // TODO 富文本优化 + return wxCouponMapper.selectById(id); + } + + @Override + public WxCoupon getHtmlById(Long id) { return wxCouponMapper.selectById(id); } @@ -267,6 +273,12 @@ public class WxCouponServiceImpl implements WxCouponService { } } + if (record.getContentType().equals(EnumCouponContentType.HTML.getCode())) { + if (StringUtils.isEmpty(record.getHtml())) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请填写富文本内容"); + } + } + List merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); //有价券判断商户是否配置了分账账号 if (record.getSalePrice() != null && record.getSalePrice() > 0) { diff --git a/mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml index 7320c3180..07ee95f3c 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml @@ -138,7 +138,7 @@ , c.remain_inventory,c.inventory,c.cover_img,c.title,c.sub_title,c.sale_price, c.use_price,c.price,c.unit,c.use_limit_quantity,c.send_type,c.support_transfer,c.press_limit_num,c.auto_refund,c.conditions, - c.valid_type,c.valid_start_date,c.valid_end_date,c.valid_days,c.credit_price + c.valid_type,c.valid_start_date,c.valid_end_date,c.valid_days,c.credit_price,c.content_type @@ -175,6 +175,7 @@ + @@ -266,6 +267,7 @@ + + - - - @@ -503,6 +511,7 @@ + +