集成redisson
parent
b40b5b908a
commit
b8ff0aefe2
File diff suppressed because one or more lines are too long
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -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
|
||||
|
|
|
@ -45,11 +45,25 @@
|
|||
<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.exam</groupId>
|
||||
<artifactId>exam-common</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<groupId>com.bwie</groupId>
|
||||
<artifactId>etl-common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
|
@ -57,6 +71,38 @@
|
|||
<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>
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package com.etl.spike;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan("com.etl.spike.entity")
|
||||
@MapperScan("com.etl.spike.mapper")
|
||||
@EnableScheduling
|
||||
@EnableDiscoveryClient
|
||||
public class EtlSpikeApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(EtlSpikeApplication.class, args);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -1,10 +1,16 @@
|
|||
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商品表 前端控制器
|
||||
|
@ -16,5 +22,20 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,24 @@
|
|||
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
|
||||
|
@ -16,5 +27,58 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@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 ();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 ();
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@ package com.etl.spike.controller;
|
|||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
|
@ -17,4 +16,6 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@RequestMapping("/times-goods")
|
||||
public class TimesGoodsController {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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()));
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 开启一个定时任务将mysql中的最近三天的场次,商品信息和库存存入redis
|
||||
*/
|
||||
@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 ());
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
||||
//正文2,html标签内容
|
||||
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();
|
||||
}}
|
|
@ -14,4 +14,5 @@ import com.etl.spike.entity.Order;
|
|||
*/
|
||||
public interface IOrderService extends IService< Order > {
|
||||
|
||||
boolean orderGoOn();
|
||||
}
|
||||
|
|
|
@ -17,5 +17,12 @@ import org.springframework.stereotype.Service;
|
|||
*/
|
||||
@Service
|
||||
public class OrderServiceImpl extends ServiceImpl< OrderMapper, Order > implements IOrderService {
|
||||
|
||||
/**
|
||||
* 参数校验无误后推送队列
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean orderGoOn(){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,3 +12,11 @@ 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.
|
@ -1,5 +0,0 @@
|
|||
<?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.bwie.shop.EntityMapper.GoodsMapper">
|
||||
|
||||
</mapper>
|
|
@ -1,5 +0,0 @@
|
|||
<?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.bwie.shop.EntityMapper.OrderItemMapper">
|
||||
|
||||
</mapper>
|
|
@ -1,5 +0,0 @@
|
|||
<?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.bwie.shop.EntityMapper.OrderMapper">
|
||||
|
||||
</mapper>
|
|
@ -1,5 +0,0 @@
|
|||
<?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.bwie.shop.EntityMapper.TimesGoodsMapper">
|
||||
|
||||
</mapper>
|
|
@ -1,5 +0,0 @@
|
|||
<?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.bwie.shop.EntityMapper.TimesMapper">
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue