Compare commits

..

3 Commits

Author SHA1 Message Date
An Yong Shuai b8ff0aefe2 集成redisson 2024-07-11 15:19:09 +08:00
An Yong Shuai b40b5b908a 秒杀项目初始化 2024-07-10 10:09:14 +08:00
An Yong Shuai 5a88b571ae 秒杀项目初始化 2024-07-10 10:08:34 +08:00
51 changed files with 1550 additions and 60 deletions

View File

@ -8,6 +8,7 @@
<outputRelativeToContentRoot value="true" />
<module name="etl-common" />
<module name="etl-cleaning" />
<module name="etl-spike" />
<module name="etl-gateway" />
</profile>
</annotationProcessing>

View File

@ -11,6 +11,8 @@
<file url="file://$PROJECT_DIR$/etl-common/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/etl-gateway/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/etl-gateway/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/etl-spike/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/etl-spike/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>

File diff suppressed because one or more lines are too long

View File

@ -19,6 +19,11 @@
<spring-boot.version>2.6.13</spring-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.0.5</version>
</dependency>
<!-- Jedis -->
<dependency>
<groupId>redis.clients</groupId>
@ -30,7 +35,6 @@
<artifactId>spring-boot-starter-captcha</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>

View File

@ -3,12 +3,14 @@ package com.etl.cleaning;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
*
*/
@SpringBootApplication
@MapperScan("com.etl.cleaning.mapper")
@EnableScheduling
public class EtlCleaningApplication {
public static void main(String[] args) {
SpringApplication.run(EtlCleaningApplication.class, args);

View File

@ -0,0 +1,42 @@
package com.etl.cleaning.controller;
import com.alibaba.excel.EasyExcel;
import com.etl.cleaning.domian.pojo.DataPlace;
import com.etl.cleaning.service.PlaceService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
/**
*
*/
@RestController
@RequestMapping("/poi/excel")
public class PoiExcelApi {
private final PlaceService placeService;
public PoiExcelApi(PlaceService placeService){
this.placeService=placeService;
}
/**
*
*/
@PostMapping("/outPoi")
public void outPoi(){
//设置文件导出的路径
String path = "D://poi/";
File file=new File( path );
if(!file.isDirectory()){
file.mkdirs();
}
String fileName = path + "User" + System.currentTimeMillis() + ".xlsx";
EasyExcel.write(fileName, DataPlace.class).sheet("数据源管理").doWrite(placeService.list());
}
}

View File

@ -1,5 +1,7 @@
package com.etl.cleaning.domian.pojo;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
@ -8,6 +10,7 @@ import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
@ -23,55 +26,70 @@ public class DataPlace {
* id
*/
@TableId(type = IdType.AUTO)
@ExcelProperty("主键ID")
private Long id;
/**
*
*/
@ExcelProperty("数据源描述")
private String name;
/**
*
*/
@ExcelProperty("备注")
private String bank;
/**
*
*/
@ExcelProperty("修改时间")
private Date updateTime;
/**
* ID
*/
@ExcelProperty("类型ID")
private Long typeId;
/**
*
*/
@ExcelProperty("/连接状态")
private Long statue;
/**
*
*/
@TableField(exist = false)
@ExcelIgnore
private String typeName;
/**
*
*/
@ExcelProperty("用户名")
private String username;
/**
*
*/
@ExcelProperty("密码")
private String password;
/**
*
*/
@ExcelProperty("端口")
private String port;
/**
*
*/
@ExcelProperty("数据库")
private String dataName;
/**
*
*/
@ExcelProperty("配置")
private String yaml;
/**
*
*/
@ExcelProperty("路径")
private String dataUrl;
}

View File

@ -0,0 +1,12 @@
package com.etl.cleaning.job;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class Testaa {
@Scheduled(fixedRate = 1000)
public void test(){
System.out.println ("aaaaaaaa");
}
}

View File

@ -36,8 +36,6 @@ public class PlaceServiceImpl extends ServiceImpl<PlaceMapper, DataPlace> implem
this.typeService = typeService;
this.placeMapper = placeMapper;
}
@Override
public Map<String,Object> showPlacePage(PlaceRequest placeRequest) {
LambdaQueryWrapper<DataPlace> lambdaQueryWrapper = new LambdaQueryWrapper<>();

View File

@ -1,5 +1,5 @@
#Generated by Maven
#Tue Jun 25 19:35:44 CST 2024
#Wed Jul 10 15:32:05 CST 2024
groupId=com.bwie
artifactId=etl-common
version=1.0-SNAPSHOT

33
etl-spike/.gitignore vendored 100644
View File

@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/

151
etl-spike/pom.xml 100644
View File

@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.etl</groupId>
<artifactId>etl-spike</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>etl-spike</name>
<description>etl-spike</description>
<parent>
<groupId>com.bwie</groupId>
<artifactId>etl-cloud</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.6.13</spring-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.3.22</version> <!-- 请根据需要选择合适的版本 -->
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.29</version> <!-- 请根据需要选择合适的版本 -->
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.58</version>
</dependency>
<dependency>
<groupId>com.bwie</groupId>
<artifactId>etl-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-annotation</artifactId>
<version>3.5.7</version>
<scope>compile</scope>
</dependency>
<!--导出pdf相关-->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.10</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-asian</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>com.itextpdf.tool</groupId>
<artifactId>xmlworker</artifactId>
<version>5.5.11</version>
</dependency>
<!--处理html相关 -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.2</version>
</dependency>
<dependency>
<groupId>com.github.jklasd</groupId>
<artifactId>spring-junit-test</artifactId>
<version>2.0.1-RELEASE</version>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>3.5.0</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<configuration>
<mainClass>com.etl.spike.EtlSpikeApplication</mainClass>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,17 @@
package com.etl.spike;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@MapperScan("com.etl.spike.mapper")
@EnableScheduling
@EnableDiscoveryClient
public class EtlSpikeApplication {
public static void main(String[] args) {
SpringApplication.run(EtlSpikeApplication.class, args);
}
}

View File

@ -0,0 +1,34 @@
package com.etl.spike.config;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* redisson
*/
@Configuration
public class RedissonConfig {
@Value ("${redisson.address}")
private String addressUrl;
@Value ("${redisson.password}")
private String password;
/**
*
*/
@Bean
public RedissonClient getRedisson(){
Config config = new Config ();
config.useSingleServer ()
.setAddress (addressUrl).setPassword (password)
.setReconnectionTimeout (10000)
.setRetryInterval (5000)
.setTimeout (10000)
.setConnectTimeout (10000);
return Redisson.create (config);
}
}

View File

@ -0,0 +1,41 @@
package com.etl.spike.controller;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.etl.common.result.Result;
import com.etl.spike.entity.Goods;
import com.etl.spike.service.IGoodsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* <p>
* sku
* </p>
*
* @author test
* @since 2024-07-10
*/
@RestController
@RequestMapping("/goods")
public class GoodsController {
private final IGoodsService goodsService;
public GoodsController(IGoodsService goodsService){
this.goodsService = goodsService;
}
/**
*
* @return
*/
@SentinelResource
@GetMapping("/test")
public Result testList(){
List<Goods> list = goodsService.list ();
return Result.success (list);
}
}

View File

@ -0,0 +1,84 @@
package com.etl.spike.controller;
import cn.hutool.crypto.digest.DigestUtil;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.etl.common.result.Result;
import com.etl.spike.entity.request.OrderRequest;
import com.etl.spike.enums.EnumMsg;
import com.etl.spike.service.IOrderService;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.validation.annotation.Validated;
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.RestController;
import java.util.Objects;
/**
* <p>
*
* </p>
*
* @author test
* @since 2024-07-10
*/
@RestController
@RequestMapping("/order")
public class OrderController {
private final StringRedisTemplate redisTemplate;
private final IOrderService orderService;
public OrderController(StringRedisTemplate redisTemplate , IOrderService orderService){
this.redisTemplate = redisTemplate;
this.orderService = orderService;
}
/**
*
*
* @return
*/
@PostMapping("/orderGoOn")
@SentinelResource
public Result orderGoOn(@RequestBody @Validated OrderRequest orderRequest){
//判断场次是否存在
String key = EnumMsg.REDIS_SMALL_KEY.getMessage () +
orderRequest.getId ();
if ( !redisTemplate.opsForHash ().hasKey (EnumMsg.REDIS_KEY.getMessage () , key) ) {
throw new RuntimeException ("您参与的活动场次不存在");
}
//判断购买数量是否合法
if(orderRequest.getNum () != 1) {
throw new RuntimeException ("您的购买数量不合法");
}
//判断商品id是否在缓存中
String hashKey = EnumMsg.REDIS_SMALL_KEY.getMessage ()+orderRequest.getGoodsId ();
if ( !redisTemplate.opsForHash ().hasKey (EnumMsg.REDIS_KEY.getMessage () , hashKey) ) {
throw new RuntimeException ("商品不存在");
}
//获取当前时间戳()
long timeMillis = System.currentTimeMillis ();
//转换为分钟级的时间戳
long seconds = timeMillis / 1000 / 60;
//加密签名是否合法
String sign = orderRequest.getId ().toString () + orderRequest.getId ().toString () + "&" + seconds;
//生成MD5值
String md5Hex = DigestUtil.md5Hex (sign);
if ( !md5Hex.equals (orderRequest.getSign ()) ) {
throw new RuntimeException ("验签失败");
}
//检验库存
if( !redisTemplate.opsForHash ().hasKey (EnumMsg.REDIS_KEY.getMessage () , orderRequest.getGoodsId ()) ) {
throw new RuntimeException ("该商品库存异常");
}
String num = Objects.requireNonNull (redisTemplate.opsForHash ().get (EnumMsg.REDIS_GOODS_NUM.getMessage () ,
orderRequest.getGoodsId ())).toString ();
long goodsNum = Long.parseLong (num);
if(goodsNum<=0){
throw new RuntimeException ("该商品商品不足");
}
orderService.orderGoOn();
return Result.success ();
}
}

View File

@ -0,0 +1,20 @@
package com.etl.spike.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
*
* </p>
*
* @author test
* @since 2024-07-10
*/
@RestController
@RequestMapping("/order-item")
public class OrderItemController {
}

View File

@ -0,0 +1,29 @@
package com.etl.spike.controller;
import com.etl.common.result.Result;
import com.etl.spike.pdf.ExportPdfTest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/pdf")
public class PdfController {
private final ExportPdfTest exportPdfTest;
public PdfController(ExportPdfTest exportPdfTest){
this.exportPdfTest = exportPdfTest;
}
/**
* pdf
* @return
* @throws Exception
*/
@GetMapping("/test")
public Result test() throws Exception{
exportPdfTest.export ();
return Result.success ();
}
}

View File

@ -0,0 +1,20 @@
package com.etl.spike.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
*
* </p>
*
* @author test
* @since 2024-07-10
*/
@RestController
@RequestMapping("/times")
public class TimesController {
}

View File

@ -0,0 +1,21 @@
package com.etl.spike.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
*
* </p>
*
* @author test
* @since 2024-07-10
*/
@RestController
@RequestMapping("/times-goods")
public class TimesGoodsController {
}

View File

@ -0,0 +1,67 @@
package com.etl.spike.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* <p>
* sku
* </p>
*
* @author test
* @since 2024-07-10
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("goods")
public class Goods implements Serializable {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/**
*
*/
private String name;
/**
*
*/
private BigDecimal price;
/**
*
*/
private String typename;
/**
*
*/
private LocalDateTime time;
/**
*
*/
private String place;
/**
*
*/
private String style;
}

View File

@ -0,0 +1,66 @@
package com.etl.spike.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* <p>
*
* </p>
*
* @author test
* @since 2024-07-10
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("order")
public class Order implements Serializable {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/**
* ID
*/
private Integer goodId;
/**
* ID
*/
private Integer userId;
/**
*
*/
private Integer flag;
/**
*
*/
private LocalDateTime time;
/**
*
*/
private String payType;
/**
*
*/
private String place;
}

View File

@ -0,0 +1,51 @@
package com.etl.spike.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* <p>
*
* </p>
*
* @author test
* @since 2024-07-10
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("order_item")
public class OrderItem implements Serializable {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/**
* ID
*/
private Integer orderId;
/**
*
*/
private Integer num;
/**
*
*/
private BigDecimal price;
}

View File

@ -0,0 +1,61 @@
package com.etl.spike.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* <p>
*
* </p>
*
* @author test
* @since 2024-07-10
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("times")
public class Times implements Serializable {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/**
*
*/
private String name;
/**
*
*/
private LocalDateTime startTime;
/**
*
*/
private LocalDateTime endTime;
/**
* 1- 2- 3-
*/
private String flag;
/**
*
*/
private Integer num;
}

View File

@ -0,0 +1,55 @@
package com.etl.spike.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* <p>
*
* </p>
*
* @author test
* @since 2024-07-10
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("times_goods")
public class TimesGoods implements Serializable {
private static final long serialVersionUID = 1L;
/**
* id
*/
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/**
* ID
*/
private Integer timesId;
/**
* ID
*/
private Integer goodsId;
/**
*
*/
private Integer goodsNum;
/**
*
*/
private Integer goodsEndNum;
}

View File

@ -0,0 +1,39 @@
package com.etl.spike.entity.request;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
*
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class OrderRequest {
/**
* ID
*/
@NotNull(message = "场次编号不能为空")
private Long id;
/**
* ID
*/
@NotNull(message = "商品编号不能为空")
private Long goodsId;
/**
*
*/
@NotBlank(message = "加密签名不能为空")
private String sign;
/**
*
*/
@NotNull(message = "购买数量不能为空")
private Long num;
}

View File

@ -0,0 +1,23 @@
package com.etl.spike.enums;
import lombok.Getter;
/**
*
*/
@Getter
public enum EnumMsg {
// 定义一个带有错误码和描述性字符串的枚举常量
REDIS_KEY(401, "times:"),
REDIS_SMALL_KEY(402, "hashKey:"),
REDIS_GOODS_NUM(403,"goodNum:");
private final int code;
private final String message;
EnumMsg(int code, String message) {
this.code = code;
this.message = message;
}
}

View File

@ -0,0 +1,22 @@
package com.etl.spike.handler;
import com.alibaba.fastjson2.JSONObject;
import com.etl.common.result.Result;
import lombok.extern.log4j.Log4j2;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
*
*/
@RestControllerAdvice
@Configuration
@Log4j2
public class CatchExceptions {
@ExceptionHandler(value = RuntimeException.class)
public Result<String> catchException(RuntimeException exception) {
log.error("请求异常: [{}]",exception.getMessage(),exception);
return Result.error(JSONObject.toJSONString(exception.getMessage()));
}
}

View File

@ -0,0 +1,77 @@
package com.etl.spike.job;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.etl.spike.entity.Times;
import com.etl.spike.entity.TimesGoods;
import com.etl.spike.enums.EnumMsg;
import com.etl.spike.service.ITimesGoodsService;
import com.etl.spike.service.ITimesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
/**
* redis
*/
@Component
@Slf4j
public class GoodsRedisJob {
private final StringRedisTemplate redisTemplate;
private final ITimesService timesService;
private final ITimesGoodsService timesGoodsService;
public GoodsRedisJob(StringRedisTemplate redisTemplate , ITimesService timesService , ITimesGoodsService timesGoodsService){
this.redisTemplate = redisTemplate;
this.timesService = timesService;
this.timesGoodsService = timesGoodsService;
}
/**
* mysqlredis
*/
@Scheduled(cron = "0 0 0 * * ?")
public void testJob(){
log.info ("定时任务执行(-------------- redis场次信息同步 --------------");
//计算三天前的日期
LocalDate localDate = LocalDate.now ().minusDays (3);
//转换类型
LocalDateTime startTime = localDate.atStartOfDay ();
//获取当前时间
LocalDateTime endTime = LocalDateTime.now ();
//查询最近三天的场次
List<Times> timesList = timesService.list (new LambdaQueryWrapper<Times> ().between (Times :: getEndTime ,
startTime ,
endTime));
//校验
if( CollectionUtils.isEmpty (timesList) ){
throw new RuntimeException ("最近三天暂无任何活动");
}
//获取全部的id集合
List<Integer> integers = timesList.stream ().map (Times :: getId).collect (Collectors.toList ());
//查询场次表和商品中间表
List<TimesGoods> timesGoods = timesGoodsService.list (new LambdaQueryWrapper<TimesGoods> ().in (TimesGoods::getTimesId, integers));
//校验
if( CollectionUtils.isEmpty (timesGoods) ){
throw new RuntimeException ("最近三天暂无任何活动");
}
//遍历存入redis
timesGoods.forEach (item -> {
String redisKey = EnumMsg.REDIS_SMALL_KEY.getMessage ()
+ item.getId ();
//存入redis的hash结构,键用event前缀拼接时间戳+场次id
redisTemplate.opsForHash ().put (EnumMsg.REDIS_KEY.getMessage (), redisKey , JSON.toJSONString (item));
//库存存入redis
redisTemplate.opsForHash ().put (EnumMsg.REDIS_GOODS_NUM.getMessage () , item.getGoodsId (), item.getGoodsNum ());
});
}
}

View File

@ -0,0 +1,16 @@
package com.etl.spike.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.etl.spike.entity.Goods;
/**
* <p>
* sku Mapper
* </p>
*
* @author test
* @since 2024-07-10
*/
public interface GoodsMapper extends BaseMapper< Goods > {
}

View File

@ -0,0 +1,17 @@
package com.etl.spike.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.etl.spike.entity.OrderItem;
/**
* <p>
* Mapper
* </p>
*
* @author test
* @since 2024-07-10
*/
public interface OrderItemMapper extends BaseMapper< OrderItem > {
}

View File

@ -0,0 +1,16 @@
package com.etl.spike.mapper;
import com.etl.spike.entity.Order;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* Mapper
* </p>
*
* @author test
* @since 2024-07-10
*/
public interface OrderMapper extends BaseMapper<Order> {
}

View File

@ -0,0 +1,17 @@
package com.etl.spike.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.etl.spike.entity.TimesGoods;
/**
* <p>
* Mapper
* </p>
*
* @author test
* @since 2024-07-10
*/
public interface TimesGoodsMapper extends BaseMapper< TimesGoods > {
}

View File

@ -0,0 +1,16 @@
package com.etl.spike.mapper;
import com.etl.spike.entity.Times;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* Mapper
* </p>
*
* @author test
* @since 2024-07-10
*/
public interface TimesMapper extends BaseMapper<Times> {
}

View File

@ -0,0 +1,97 @@
package com.etl.spike.pdf;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;
import com.itextpdf.tool.xml.XMLWorkerFontProvider;
import com.itextpdf.tool.xml.XMLWorkerHelper;
import org.jsoup.Jsoup;
import org.springframework.stereotype.Component;
import java.io.*;
/**
* @description pdf
* @date 2018/3/16 16:48$
*/
@Component
public class ExportPdfTest {
public void export() throws Exception {
System.out.println ("开始执行");
Document document = new Document(PageSize.A4);
//设置要导出的文件名
OutputStream outputStream = new FileOutputStream (new File("D:\\abc\\test.pdf"));
PdfWriter writer = PdfWriter.getInstance(document, outputStream);
document.open();
//获取字体文件目录
String fontDir = this.getClass().getClassLoader().getResource("font").getFile();
//注册字体文件
XMLWorkerFontProvider xmlWorkerFontProvider = new XMLWorkerFontProvider(fontDir);
//设置中文字体,本文举例使用的是仿宋
BaseFont baseFont = BaseFont.createFont("font/SIMFANG.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font font12 = new Font(baseFont, 12);
//页眉,是可以双层或更多,取决于放置的坐标
PdfContentByte cb = writer.getDirectContent();
//页眉左上
Phrase leftp1 = new Phrase("页眉左上", font12);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, leftp1, document.left(), document.top() + 13, 0);
//页眉左下
Phrase leftp2 = new Phrase("页眉左下:", font12);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, leftp2, document.left(), document.top(), 0);
//页眉右上
Phrase rightp1 = new Phrase("页眉右上:", font12);
float rightp1WidthPoint = baseFont.getWidthPoint(rightp1.getContent(), 12);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, rightp1, document.right() - rightp1WidthPoint, document.top() + 13, 0);
//页眉右下
Phrase rightp2 = new Phrase("页眉右下:", font12);
float rightp2WidthPoint = baseFont.getWidthPoint(rightp2.getContent(), 12);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, rightp2, document.right() - rightp2WidthPoint, document.top(), 0);
//下划线
PdfContentByte canvas = writer.getDirectContent();
CMYKColor magentaColor = new CMYKColor(1.f, 1.f, 1.f, 1.f);
canvas.setColorStroke(magentaColor);
canvas.moveTo(document.left(), document.top() - 4);
canvas.lineTo(document.right(), document.top() - 4);
canvas.closePathStroke();
//标题
Font h1 = new Font(baseFont, 20, Font.BOLD);//创建全文标题字体,参数分别是字体类别,字号,效果
Paragraph paragraphTitle = new Paragraph("标题测试", h1);//设置文本内容和要使用的字体
paragraphTitle.setAlignment(Element.ALIGN_CENTER);//设置居中
document.add(paragraphTitle);
//正文标题1
Font h3 = new Font(baseFont, 14, Font.BOLD);//创建标题字体
Paragraph paragraphH1 = new Paragraph("正文标题1", h3);
document.add(paragraphH1);
//正文1
Paragraph paragraphText1 = new Paragraph("你能做到最好,你能做到最好,你能做到最好,你能做到最好,你能做到最好,你能做到最好,你能做到最好。", font12);
document.add(paragraphText1);
//正文2html标签内容
String content = "<div class=\"overflow-hidden\"><div class=\"editContent\"><p><br>eah, you could be the greatest<br>你会成为最伟大的人<br>You can be the best<br>你能做到最好<br>You can be the King Kong banging on your chest<br>你能像金刚一样自信满满的敲打胸脯<br>You could beat the world<br>你可以征服全世界<br>You could beat the war<br>能够赢得一切战争<br>You could talk to God, go banging on his door<br>甚至能够与神对话 去敲打他的门<br>You can throw your hands up<br>你能自信的举起双手<br>You can be the clock<br>你可以与时间抗争<br>You can move a mountain<br>你有移山之力<br>You can break rocks<br>你能击碎岩石<br>You can be a master<br>你可以成为命运主宰<br>Don't wait for luck<br>无需等待运气垂青<br>Dedicate yourself and you can find yourself<br>放手一搏后你会恍然发现<br>Standing in the hall of fame<br>你已身处名人堂之中</p></div></div>";
//html转换成普通文字,方法如下:
org.jsoup.nodes.Document contentDoc = Jsoup.parseBodyFragment(content);
org.jsoup.nodes.Document.OutputSettings outputSettings = new org.jsoup.nodes.Document.OutputSettings();
outputSettings.syntax(org.jsoup.nodes.Document.OutputSettings.Syntax.xml);
contentDoc.outputSettings(outputSettings);
String parsedHtml = contentDoc.outerHtml();
//这儿的font-family不支持汉字{font-family:仿宋} 是不可以的。
InputStream cssIs = new ByteArrayInputStream ("* {font-family: fangsong;}".getBytes("UTF-8"));
//第四个参数是html中的css文件的输入流
//第五个参数是字体提供者,使用系统默认支持的字体时,可以不传。
XMLWorkerHelper.getInstance().parseXHtml(writer, document, new ByteArrayInputStream(parsedHtml.getBytes()), cssIs, xmlWorkerFontProvider);
//页脚
PdfContentByte cj = writer.getDirectContent();
Phrase leftp3 = new Phrase("页脚左侧", font12);
ColumnText.showTextAligned(cj, Element.ALIGN_LEFT, leftp3, document.left(), document.bottom(), 0);
Phrase rightp3 = new Phrase("页脚右侧", font12);
final float rightp3WidthPoint = baseFont.getWidthPoint(rightp3.getContent(), 12);
ColumnText.showTextAligned(cj, Element.ALIGN_LEFT, rightp3, document.right() - rightp3WidthPoint, document.bottom(), 0);
//关闭
document.close();
}}

View File

@ -0,0 +1,17 @@
package com.etl.spike.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.etl.spike.entity.Goods;
/**
* <p>
* sku
* </p>
*
* @author test
* @since 2024-07-10
*/
public interface IGoodsService extends IService< Goods > {
}

View File

@ -0,0 +1,17 @@
package com.etl.spike.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.etl.spike.entity.OrderItem;
/**
* <p>
*
* </p>
*
* @author test
* @since 2024-07-10
*/
public interface IOrderItemService extends IService< OrderItem > {
}

View File

@ -0,0 +1,18 @@
package com.etl.spike.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.etl.spike.entity.Order;
/**
* <p>
*
* </p>
*
* @author test
* @since 2024-07-10
*/
public interface IOrderService extends IService< Order > {
boolean orderGoOn();
}

View File

@ -0,0 +1,17 @@
package com.etl.spike.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.etl.spike.entity.TimesGoods;
/**
* <p>
*
* </p>
*
* @author test
* @since 2024-07-10
*/
public interface ITimesGoodsService extends IService< TimesGoods > {
}

View File

@ -0,0 +1,17 @@
package com.etl.spike.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.etl.spike.entity.Times;
/**
* <p>
*
* </p>
*
* @author test
* @since 2024-07-10
*/
public interface ITimesService extends IService< Times > {
}

View File

@ -0,0 +1,21 @@
package com.etl.spike.serviceImpl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.etl.spike.entity.Goods;
import com.etl.spike.mapper.GoodsMapper;
import com.etl.spike.service.IGoodsService;
import org.springframework.stereotype.Service;
/**
* <p>
* sku
* </p>
*
* @author test
* @since 2024-07-10
*/
@Service
public class GoodsServiceImpl extends ServiceImpl< GoodsMapper, Goods > implements IGoodsService {
}

View File

@ -0,0 +1,21 @@
package com.etl.spike.serviceImpl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.etl.spike.entity.OrderItem;
import com.etl.spike.mapper.OrderItemMapper;
import com.etl.spike.service.IOrderItemService;
import org.springframework.stereotype.Service;
/**
* <p>
*
* </p>
*
* @author test
* @since 2024-07-10
*/
@Service
public class OrderItemServiceImpl extends ServiceImpl < OrderItemMapper, OrderItem > implements IOrderItemService {
}

View File

@ -0,0 +1,28 @@
package com.etl.spike.serviceImpl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.etl.spike.entity.Order;
import com.etl.spike.mapper.OrderMapper;
import com.etl.spike.service.IOrderService;
import org.springframework.stereotype.Service;
/**
* <p>
*
* </p>
*
* @author test
* @since 2024-07-10
*/
@Service
public class OrderServiceImpl extends ServiceImpl< OrderMapper, Order > implements IOrderService {
/**
*
* @return
*/
@Override
public boolean orderGoOn(){
return false;
}
}

View File

@ -0,0 +1,21 @@
package com.etl.spike.serviceImpl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.etl.spike.entity.TimesGoods;
import com.etl.spike.mapper.TimesGoodsMapper;
import com.etl.spike.service.ITimesGoodsService;
import org.springframework.stereotype.Service;
/**
* <p>
*
* </p>
*
* @author test
* @since 2024-07-10
*/
@Service
public class TimesGoodsServiceImpl extends ServiceImpl< TimesGoodsMapper, TimesGoods > implements ITimesGoodsService {
}

View File

@ -0,0 +1,21 @@
package com.etl.spike.serviceImpl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.etl.spike.entity.Times;
import com.etl.spike.mapper.TimesMapper;
import com.etl.spike.service.ITimesService;
import org.springframework.stereotype.Service;
/**
* <p>
*
* </p>
*
* @author test
* @since 2024-07-10
*/
@Service
public class TimesServiceImpl extends ServiceImpl< TimesMapper, Times > implements ITimesService {
}

View File

@ -0,0 +1,22 @@
# 应用服务 WEB 访问端口
server.port=10002
spring.redis.host=47.101.130.221
spring.redis.port=6379
spring.redis.password=123456
mybatis-plus.type-aliases-package=com.etl.spike.entity
mybatis-plus.mapper-locations=classpath:mapper/*.xml
mybatis-plus.configuration.map-underscore-to-camel-case=true
logging.level.com.etl.**=debug
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://47.101.130.221:3306/spike?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=ays@123
spring.cloud.sentinel.transport.dashboard=localhost:8333
spring.cloud.sentinel.transport.port=localhost:8719
# ??????
management.endpoints.web.exposure.include= *
spring.main.allow-circular-references=true
redisson.addresses=redis://47.101.130.221:6379
redisson.password=123456

Binary file not shown.

View File

@ -0,0 +1,6 @@
<html>
<body>
<h1>hello word!!!</h1>
<p>this is a html page</p>
</body>
</html>

View File

@ -0,0 +1,13 @@
package com.etl.spike;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class EtlSpikeApplicationTests {
@Test
void contextLoads() {
}
}

View File

@ -12,6 +12,7 @@
<module>etl-common</module>
<module>etl-gateway</module>
<module>etl-cleaning</module>
<module>etl-spike</module>
</modules>
<properties>