秒杀服务工程搭建

63 阅读2分钟

持续创作,加速成长!这是我参与「掘金日新计划 · 10 月更文挑战」的第24天,点击查看活动详情

每日英语:

All great and precious things are lonely.

翻译:一切伟大而珍贵的东西都是孤独的。 ——约翰·斯坦贝克

秒杀服务工程搭建

我们需要单独搭建秒杀工程,实现秒杀功能的操作。

Api工程创建

搭建mall-seckill-api工程,并创建对应实体Bean

坐标如下:

<modelVersion>4.0.0</modelVersion>
<version>0.0.1-SNAPSHOT</version>
<artifactId>mall-seckill-api</artifactId>

创建com.xz.mall.seckill.model.SeckillActivity

@Data
@AllArgsConstructor
@NoArgsConstructor
//MyBatisPlus表映射注解
@TableName(value = "seckill_activity")
public class SeckillActivity {
​
    @TableId(type = IdType.ASSIGN_UUID)
    private String id;
    private String activityName;
    private Integer type;   //活动分类 0shop秒杀、1 每日特价、2 大牌闪购、3 品类秒杀、4 节日活动
    private Date startTime;
    private Date endTime;
}

创建com.xz.mall.seckill.model.SeckillGoods

@Data
@AllArgsConstructor
@NoArgsConstructor
//MyBatisPlus表映射注解
@TableName(value = "seckill_goods")
public class SeckillGoods {
​
    @TableId(type = IdType.ASSIGN_UUID)
    private String id;
    private String supId;
    private String skuId;
    private String name;
    private String images;
    private String content;
    private Integer price;
    private Integer seckillPrice;
    private Integer num;
    private Integer storeCount;
    private Date createTime;
    private String activityId;
}

创建com.xz.mall.seckill.model.SeckillOrder

@Data
@AllArgsConstructor
@NoArgsConstructor
//MyBatisPlus表映射注解
@TableName(value = "seckill_order")
public class SeckillOrder {
​
    @TableId(type = IdType.ASSIGN_UUID)
    private String id;
    private String seckillGoodsId;
    private String weixinTransactionId;
    private String username;
    private Integer money;
    private Integer status;
    private Date createTime;
    private Date payTime;
    private Integer num;    //抢购数量
}

Service工程搭建

创建mall-seckill-service工程

1)pom.xml

<dependencies>
    <dependency>
        <groupId>com.xz.mall</groupId>
        <artifactId>mall-seckill-api</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

2)bootstrap.yml

server:
  port: 8092
spring:
  application:
    name: mall-seckill
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://192.168.xxx.xxx:3306/shop_seckill?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
    username: root
    password: 123456
  cloud:
    nacos:
      config:
        file-extension: yaml
        server-addr: 192.168.xxx.xxx:8848
      discovery:
        #Nacos的注册地址
        server-addr: 192.168.xxx.xxx:8848
# ====================MybatisPlus====================
mybatis-plus:
  mapper-locations: mapper/*.xml
  type-aliases-package: com.xz.mall.*.model
  configuration:
    map-underscore-to-camel-case: true
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

#日志配置
logging:
  pattern:
    console: "%msg%n"

3)启动类

创建启动类com.xz.mall.seckill.SeckillApplication

@SpringBootApplication
public class SeckillApplication {
​
    public static void main(String[] args) {
        SpringApplication.run(SeckillApplication.class,args);
    }
}

4)Service/dao

我们使用MyBatisPlus创建对应的controller、service、mapper,直接将创建好的空类引入到工程中。

总结

本篇主要介绍了一下秒杀服务工程的基本搭建,下一篇会主要介绍一下活动管理部分。