【Spring Boot+Kafka+Mysql+HBase】实现分布式优惠券后台应用系统(附源码)

需要全部代码请点赞关注收藏后评论区留言私信~~~

一、系统简介

分布式优惠券后台应用系统服务于两类用户群体,一类是商户,商户可以根据自己的实际情况即进行优惠券投放,另一类是平台消费用户,用户可以去领取商户发放的优惠券

二、整体架构

分布式优惠券后台应用系统采用SpringBoot作为主体开发框架,使用Kafka消息队列实现优惠券从商户到用户的传递,Mysql存储商户信息,HBase存储用户信息,优惠券信息等,Redis保存优惠券的缓存信息 系统整体架构如下

 对于商户投放子系统,商户注册生成对应的商户实体信息,并保存到Mysql数据库,商户可以投放自己商家的优惠券,且优惠券有自己的Token存放于Redis中,投放的优惠券信息将由Kafka向用户消费子系统发送,而商户投放的优惠券并不在Mysql中进行存储,而是在商户投放子系统中放送消息给Kafka,用户消费子系统通过侦听Kafka消息获得Kafka分布式信息并存储到HBase中,用户通过读取Redis中的优惠券信息领取消费券,并将自己领取到的优惠券信息存放在HBase中

三、表结构设计

mysql表结果设计如何 存放商户基本信息

HBase表结构设计

在HBase中建立三个表,分别是消费用户表,优惠券表和优惠券领取表

 

 

 

四、系统实现

1:新建MAVEN工程 引入相关依赖包

2:修改applicaiton.yml文件 包括mysql和kafka的连接相关配置

3:建立各个类包存放路径

4:核心代码实现

 

 五、效果展示

商户投放子系统成功启动效果如下

 用户子系统成功启动效果如下

 发放优惠券界面如下

 数据库表插入情况如下

 六、部分代码

部分代码如下 需要全部代码请点赞关注收藏后评论区留言私信~~~
 

package com.coupon.passbook.controller;

import com.coupon.passbook.log.LogConstants;
import com.coupon.passbook.log.LogGenerator;
import com.coupon.passbook.service.IUserService;
import com.coupon.passbook.vo.Response;
import com.coupon.passbook.vo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <h1>创建用户服务</h1>
 * Created by Qinyi.
 */
@Slf4j
@RestController
@RequestMapping("/passbook")
public class CreateUserController {

    /** 创建用户服务 */
    private final IUserService userService;

    /** HttpServletRequest */
    private final HttpServletRequest httpServletRequest;

    @Autowired
    public CreateUserController(IUserService userService,
                                HttpServletRequest httpServletRequest) {
        this.userService = userService;
        this.httpServletRequest = httpServletRequest;
    }

    /**
     * <h2>创建用户</h2>
     * @param user {@link User}
     * @return {@link Response}
     * */
    @ResponseBody
    @PostMapping("/createuser")
    Response createUser(@RequestBody User user) throws Exception {

        LogGenerator.genLog(
                httpServletRequest,
                user.getId(),
                LogConstants.ActionName.CREATE_USER,
                user
        );
        return userService.createUser(user);
    }
}

控制器2

package com.coupon.passbook.controller;

import com.coupon.passbook.log.LogConstants;
import com.coupon.passbook.log.LogGenerator;
import com.coupon.passbook.service.IFeedbackService;
import com.coupon.passbook.service.IGainPassTemplateService;
import com.coupon.passbook.service.IInventoryService;
import com.coupon.passbook.service.IUserPassService;
import com.coupon.passbook.vo.Feedback;
import com.coupon.passbook.vo.GainPassTemplateRequest;
import com.coupon.passbook.vo.Pass;
import com.coupon.passbook.vo.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <h1>Passbook Rest Controller</h1>
 * Created by Qinyi.
 */
@Slf4j
@RestController
@RequestMapping("/passbook")
public class PassbookController {

    /** 用户优惠券服务 */
    private final IUserPassService userPassService;

    /** 优惠券库存服务 */
    private final IInventoryService inventoryService;

    /** 领取优惠券服务 */
    private final IGainPassTemplateService gainPassTemplateService;

    /** 反馈服务 */
    private final IFeedbackService feedbackService;

    /** HttpServletRequest */
    private final HttpServletRequest httpServletRequest;

    @Autowired
    public PassbookController(IUserPassService userPassService,
                              IInventoryService inventoryService,
                              IGainPassTemplateService gainPassTemplateService,
                              IFeedbackService feedbackService,
                              HttpServletRequest httpServletRequest) {
        this.userPassService = userPassService;
        this.inventoryService = inventoryService;
        this.gainPassTemplateService = gainPassTemplateService;
        this.feedbackService = feedbackService;
        this.httpServletRequest = httpServletRequest;
    }

    /**
     * <h2>获取用户个人的优惠券信息</h2>
     * @param userId 用户 id
     * @return {@link Response}
     * */
    @ResponseBody
    @GetMapping("/userpassinfo")
    Response userPassInfo(Long userId) throws Exception {

        LogGenerator.genLog(
                httpServletRequest,
                userId,
                LogConstants.ActionName.USER_PASS_INFO,
                null
        );
        return userPassService.getUserPassInfo(userId);
    }

    /**
     * <h2>获取用户使用了的优惠券信息</h2>
     * @param userId 用户 id
     * @return {@link Response}
     * */
    @ResponseBody
    @GetMapping("userusedpassinfo")
    Response userUsedPassInfo(Long userId) throws Exception {

        LogGenerator.genLog(
                httpServletRequest,
                userId, LogConstants.ActionName.USER_USED_PASS_INFO,
                null
        );
        return userPassService.getUserUsedPassInfo(userId);
    }

    /**
     * <h2>用户使用优惠券</h2>
     * @param pass {@link Pass}
     * @return {@link Response}
     * */
    @ResponseBody
    @PostMapping("/userusepass")
    Response userUsePass(@RequestBody Pass pass) {

        LogGenerator.genLog(
                httpServletRequest,
                pass.getUserId(),
                LogConstants.ActionName.USER_USE_PASS,
                pass
        );
        return userPassService.userUsePass(pass);
    }

    /**
     * <h2>获取库存信息</h2>
     * @param userId 用户 id
     * @return {@link Response}
     * */
    @ResponseBody
    @GetMapping("/inventoryinfo")
    Response inventoryInfo(Long userId) throws Exception {

        LogGenerator.genLog(
                httpServletRequest,
                userId,
                LogConstants.ActionName.INVENTORY_INFO,
                null
        );
        return inventoryService.getInventoryInfo(userId);
    }

    /**
     * <h2>用户领取优惠券</h2>
     * @param request {@link GainPassTemplateRequest}
     * @return {@link Response}
     * */
    @ResponseBody
    @PostMapping("/gainpasstemplate")
    Response gainPassTemplate(@RequestBody GainPassTemplateRequest request)
            throws Exception {

        LogGenerator.genLog(
                httpServletRequest,
                request.getUserId(),
                LogConstants.ActionName.GAIN_PASS_TEMPLATE,
                request
        );
        return gainPassTemplateService.gainPassTemplate(request);
    }

    /**
     * <h2>用户创建评论</h2>
     * @param feedback {@link Feedback}
     * @return {@link Response}
     * */
    @ResponseBody
    @PostMapping("/createfeedback")
    Response createFeedback(@RequestBody Feedback feedback) {

        LogGenerator.genLog(
                httpServletRequest,
                feedback.getUserId(),
                LogConstants.ActionName.CREATE_FEEDBACK,
                feedback
        );
        return feedbackService.createFeedback(feedback);
    }

    /**
     * <h2>用户获取评论信息</h2>
     * @param userId 用户 id
     * @return {@link Response}
     * */
    @ResponseBody
    @GetMapping("/getfeedback")
    Response getFeedback(Long userId) {

        LogGenerator.genLog(
                httpServletRequest,
                userId,
                LogConstants.ActionName.GET_FEEDBACK,
                null
        );
        return feedbackService.getFeedback(userId);
    }

    /**
     * <h2>异常演示接口</h2>
     * @return {@link Response}
     * */
    @ResponseBody
    @GetMapping("/exception")
    Response exception() throws Exception {
        throw new Exception("Welcome To IMOOC");
    }
}

 创作不易 觉得有帮助请点赞关注收藏~~~

  • 16
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 25
    评论
项目描述 本系统是一套极速开发微信小程序的商城系统,主要包括用户管理、角色管理、部门管理、菜单管 理、定时任务、文件上传、数据权限、Redis 缓存、前后台统一异常处理等系统通用功能,还拥有一套完整的商城后台管理系统、微信小程序源码、小程序接口服务、以及完善的支付流程,极大缩短项目的开发周期。 项目特点 ◆ shop-wechat-mall 采用 Spring、MyBatis、Shiro、swagger 框架开发。 ◆ 灵活的权限控制,可控制到页面或按钮,满足绝大部分的权限需求。 ◆ 完善的部门管理及数据权限,通过注解实现数据权限的控制。 ◆ 支持 MySQL 数据库。◆ 多个团队协作开发,有效降低核心代码泄露。 ◆ 推荐使用阿里云服务器部署本系统项目介绍 shop-admin 后台模块,也是系统的核心,用来开发后台管理系统。 shop-api 接口模块,是小程序商城的接口开发模块。实现了微信用户登录、接口权限认证、获取登录用户、商城首页、专题、分类、 购物车、个人中心等功能,为小程序商城接口的安全调用,提供一套完整的解决方案。 shop-common 公共模块,其他模块以 jar 包的形式引入进去,主要提供些工具类,以 及 shop-admin、shop-api 模块公共的 entity、mapper、dao、service 服务,防止一个功能重复多次编写代码。 shop-framework 系统 web 合并模块,最终项目打包部署模块。最后会介绍为什么会设计此模块,以及设计此模块的意图。 shop-gen 代码生成器模块,只需在数据库里,创建好表结构,就可以生成增、删、改、查等操作的代码,包括 entity、mapper、 dao、service、controller、页面等所有代码,项目开发神器。 shop-schedule 定时任务模块,使用开源框架 quartz 实现分布式定时任务,动态添加、修改、删除、暂停、恢复、立即执行定时任务。 shop-shop 商城后台管理系统实现了商城的后台管理功能。 wx-mall 商城小程序端源码 开发使用到的软件和工具 Xshell6、Xftp6、Tomcat8.0.33、jdk1.8、MySQL5.7、redis4.0.1 本地部署 ◆ 配置环境(推荐 jdk1.8、maven3.3、tomcat8、mysql5.5+、redis4.0.1) 本机启动 redis 服务、mysql 数据库初始化项目 ◆ 创建数据库 shop-shop,数据库编码为 UTF-8,执行数据库脚本_sql/shop.sql、sys_region.sql、更新脚本.sq ◆ 启动项目之前修改 dev/shop.properties,修改数据库账号和密码,wx.appId、wx.secret、wx.mchId、wx.paySignKey ◆ 修改 j2cache.propertie 配置 redis.hosts 和 redis.password 使用 IDEA 启动项目 配置 tomcat启动成功,访问 http://localhost账号密码:admin/admin Swagger 路径 http://localhost/swagger-ui.html 小程序接口路径 http://localhost/api/ 使用微信 web 开发者工具启动 wx-mall 导入 wx-mall 到微信 web 开发者工具修改 config/api.js 配置开发模式设置     
评论 25
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

showswoller

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值