yu_u66 1 týždeň pred
commit
d310a2fbe3

+ 33 - 0
.gitignore

@@ -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/

+ 110 - 0
pom.xml

@@ -0,0 +1,110 @@
+<?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.futu.course</groupId>
+    <artifactId>yzzsale</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <name>yzzsale</name>
+    <description>yzzsale</description>
+    <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.7.6</spring-boot.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.mybatis.spring.boot</groupId>
+            <artifactId>mybatis-spring-boot-starter</artifactId>
+            <version>2.3.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.kafka</groupId>
+            <artifactId>spring-kafka</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.mysql</groupId>
+            <artifactId>mysql-connector-j</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+        <dependency>
+            <groupId>redis.clients</groupId>
+            <artifactId>jedis</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-boot-starter</artifactId>
+            <version>3.5.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </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.futu.course.YzzsaleApplication</mainClass>
+                    <skip>true</skip>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>repackage</id>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 13 - 0
src/main/java/com/futu/course/YzzsaleApplication.java

@@ -0,0 +1,13 @@
+package com.futu.course;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class YzzsaleApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(YzzsaleApplication.class, args);
+    }
+
+}

+ 38 - 0
src/main/java/com/futu/course/controller/GoodsController.java

@@ -0,0 +1,38 @@
+package com.futu.course.controller;
+
+import com.futu.course.domain.Goods;
+import com.futu.course.dto.GoodsDto;
+import com.futu.course.service.GoodsService;
+import com.futu.course.utils.SnowflakeIdWorker;
+import com.futu.course.vo.ResultVo;
+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.RestController;
+
+import java.util.Date;
+
+@RestController
+@RequestMapping("goods")
+public class GoodsController {
+
+
+
+    @Autowired
+    private GoodsService goodsService;
+    @PostMapping("add")
+    public ResultVo add(@RequestBody GoodsDto dto)
+    {
+        SnowflakeIdWorker worker=new SnowflakeIdWorker(1,1);
+        Goods goods = new Goods();
+        goods.setGoodsName(dto.getGoodName());
+         goods.setId(worker.nextId());
+         goods.setGoodsImg(dto.getGoodsImg());
+         goods.setContent(dto.getContent());
+         goods.setCreatedTimee(new Date());
+         goods.setDescruptions(dto.getDesciption());
+        boolean b = goodsService.save(goods);
+        return b?ResultVo.success("添加成功",goods):ResultVo.fail(500,"添加失败");
+    }
+}

+ 45 - 0
src/main/java/com/futu/course/controller/SignController.java

@@ -0,0 +1,45 @@
+package com.futu.course.controller;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.futu.course.domain.SignDto;
+import com.futu.course.vo.ResultVo;
+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 javax.servlet.http.HttpServletRequest;
+import java.util.Map;
+import java.util.TreeMap;
+
+@RestController
+@RequestMapping("sign")
+public class SignController {
+
+    private static  final String APP_SECRET="123";
+    @PostMapping("getSign")
+    public ResultVo getSign(@RequestBody SignDto dto, HttpServletRequest request)
+    {
+        String reqId = request.getHeader("reqId");
+        String reqTime = request.getHeader("reqTime");
+        String appId = request.getHeader("appId");
+        TreeMap<String,String>map=new TreeMap<>();
+        map.put("reqId",reqId);
+        map.put("reqTime",reqTime);
+        map.put("appId",appId);
+        map.put("goodsId",dto.getGoodsId());
+        StringBuilder sb = new StringBuilder();
+        for (Map.Entry<String, String> entry : map.entrySet()) {
+            sb.append(entry.getKey()).append(entry.getValue()).append("&");
+        }
+        String sign = sb.substring(0, sb.length() - 1) + APP_SECRET;
+        if (!sign.equals(dto.getSign()))
+        {
+            return ResultVo.fail(1002,"失败");
+        }
+        return ResultVo.success("验签成功","商品名称");
+
+
+
+    }
+}

+ 101 - 0
src/main/java/com/futu/course/domain/Goods.java

@@ -0,0 +1,101 @@
+package com.futu.course.domain;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.io.Serializable;
+import java.util.Date;
+import lombok.Data;
+
+/**
+ * 
+ * @TableName goods
+ */
+@TableName(value ="goods")
+@Data
+public class Goods implements Serializable {
+    /**
+     * 
+     */
+    @TableId
+    private Long id;
+
+    /**
+     * 
+     */
+    private String goodsName;
+
+    /**
+     * 
+     */
+    private String descruptions;
+
+    /**
+     * 
+     */
+    private String goodsImg;
+
+    /**
+     * 
+     */
+    private String content;
+
+    /**
+     * 
+     */
+    private Date createdTimee;
+
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        }
+        if (that == null) {
+            return false;
+        }
+        if (getClass() != that.getClass()) {
+            return false;
+        }
+        Goods other = (Goods) that;
+        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
+            && (this.getGoodsName() == null ? other.getGoodsName() == null : this.getGoodsName().equals(other.getGoodsName()))
+            && (this.getDescruptions() == null ? other.getDescruptions() == null : this.getDescruptions().equals(other.getDescruptions()))
+            && (this.getGoodsImg() == null ? other.getGoodsImg() == null : this.getGoodsImg().equals(other.getGoodsImg()))
+            && (this.getContent() == null ? other.getContent() == null : this.getContent().equals(other.getContent()))
+            && (this.getCreatedTimee() == null ? other.getCreatedTimee() == null : this.getCreatedTimee().equals(other.getCreatedTimee()));
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
+        result = prime * result + ((getGoodsName() == null) ? 0 : getGoodsName().hashCode());
+        result = prime * result + ((getDescruptions() == null) ? 0 : getDescruptions().hashCode());
+        result = prime * result + ((getGoodsImg() == null) ? 0 : getGoodsImg().hashCode());
+        result = prime * result + ((getContent() == null) ? 0 : getContent().hashCode());
+        result = prime * result + ((getCreatedTimee() == null) ? 0 : getCreatedTimee().hashCode());
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append(getClass().getSimpleName());
+        sb.append(" [");
+        sb.append("Hash = ").append(hashCode());
+        sb.append(", id=").append(id);
+        sb.append(", goodsName=").append(goodsName);
+        sb.append(", descruptions=").append(descruptions);
+        sb.append(", goodsImg=").append(goodsImg);
+        sb.append(", content=").append(content);
+        sb.append(", createdTimee=").append(createdTimee);
+        sb.append(", serialVersionUID=").append(serialVersionUID);
+        sb.append("]");
+        return sb.toString();
+    }
+}

+ 9 - 0
src/main/java/com/futu/course/domain/SignDto.java

@@ -0,0 +1,9 @@
+package com.futu.course.domain;
+
+import lombok.Data;
+
+@Data
+public class SignDto {
+    private String goodsId;
+    private String sign;
+}

+ 11 - 0
src/main/java/com/futu/course/dto/GoodsDto.java

@@ -0,0 +1,11 @@
+package com.futu.course.dto;
+
+import lombok.Data;
+
+@Data
+public class GoodsDto {
+    private String goodName;
+    private String desciption;
+    private String goodsImg;
+    private String content;
+}

+ 41 - 0
src/main/java/com/futu/course/kafka/KafkaConsumerConfig.java

@@ -0,0 +1,41 @@
+package com.futu.course.kafka;
+
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.common.serialization.StringDeserializer;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
+import org.springframework.kafka.core.ConsumerFactory;
+import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@Configuration
+public class KafkaConsumerConfig {
+
+    @Value("${spring.kafka.bootstrap-servers}")
+    private String bootstrapServers;
+
+    // 消费者工厂配置
+    @Bean
+    public ConsumerFactory<String, String> consumerFactory() {
+        Map<String, Object> configProps = new HashMap<>();
+        configProps.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
+        configProps.put(ConsumerConfig.GROUP_ID_CONFIG, "my_group");
+        configProps.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
+        configProps.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
+        return new DefaultKafkaConsumerFactory<>(configProps);
+    }
+
+    // 消费者容器工厂配置(支持并发消费)
+    @Bean
+    public ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory() {
+        ConcurrentKafkaListenerContainerFactory<String, String> factory =
+            new ConcurrentKafkaListenerContainerFactory<>();
+        factory.setConsumerFactory(consumerFactory());
+        factory.setConcurrency(3);  // 并发线程数
+        return factory;
+    }
+}

+ 10 - 0
src/main/java/com/futu/course/kafka/Product.java

@@ -0,0 +1,10 @@
+package com.futu.course.kafka;
+
+import lombok.Data;
+
+@Data
+public class Product {
+    private String msgId;
+    private String msgType;
+    private String content;
+}

+ 33 - 0
src/main/java/com/futu/course/kafka/ProductProperties.java

@@ -0,0 +1,33 @@
+package com.futu.course.kafka;
+
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.common.serialization.StringSerializer;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.kafka.core.DefaultKafkaProducerFactory;
+import org.springframework.kafka.core.KafkaTemplate;
+import org.springframework.kafka.core.ProducerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@Configuration
+public class ProductProperties {
+    @Value("${spring.kafka.bootstrap-servers}")
+    private String bootstrapServers;
+
+    @Bean
+    public ProducerFactory<String,String>producerFactory(){
+        Map<String, Object>map=new HashMap<>();
+        map.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
+        map.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
+        map.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
+        return new DefaultKafkaProducerFactory<>(map);
+    }
+    @Bean
+    public KafkaTemplate kafkaTemplate()
+    {
+        return new KafkaTemplate<>(producerFactory());
+    }
+}

+ 20 - 0
src/main/java/com/futu/course/mapper/GoodsMapper.java

@@ -0,0 +1,20 @@
+package com.futu.course.mapper;
+
+import com.futu.course.domain.Goods;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+/**
+* @author yuu
+* @description 针对表【goods】的数据库操作Mapper
+* @createDate 2025-05-16 10:03:35
+* @Entity com.futu.course.domain.Goods
+*/
+public interface GoodsMapper extends BaseMapper<Goods> {
+
+}
+
+
+
+

+ 38 - 0
src/main/java/com/futu/course/orders/TestOrders.java

@@ -0,0 +1,38 @@
+package com.futu.course.orders;
+
+import com.futu.course.utils.DateUtils;
+import redis.clients.jedis.Jedis;
+
+import java.time.LocalDateTime;
+import java.util.Date;
+
+public class TestOrders {
+   private static final int PORT=6379;
+   private static final String HOST="localhost";
+   private static final Integer LENGTH=5;
+   private static final String  ORDER_NAME="order:cou";
+
+    public static void main(String[] args) {
+
+       String aaa=getSum("ord");
+       String aaa1=getSum("ord");
+        System.out.println("格式化订单号"+aaa);
+        System.out.println("格式化订单号"+aaa1);
+    }
+
+    private static String getSum(String ord) {
+        String timeNum = DateUtils.getDateTimeNum();
+        String day = DateUtils.getDay();
+        String month = DateUtils.getMonth();
+        String year = DateUtils.getYear();
+        StringBuilder sb=new StringBuilder();
+        String s = sb.append(year).append(month).append(day).toString();
+
+        Jedis jedis = new Jedis(HOST, PORT);
+
+        Long incr = jedis.incr(s);
+
+
+        return ord+s+String.valueOf(incr);
+    }
+}

+ 13 - 0
src/main/java/com/futu/course/service/GoodsService.java

@@ -0,0 +1,13 @@
+package com.futu.course.service;
+
+import com.futu.course.domain.Goods;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+* @author yuu
+* @description 针对表【goods】的数据库操作Service
+* @createDate 2025-05-16 10:03:35
+*/
+public interface GoodsService extends IService<Goods> {
+
+}

+ 22 - 0
src/main/java/com/futu/course/service/impl/GoodsServiceImpl.java

@@ -0,0 +1,22 @@
+package com.futu.course.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.futu.course.domain.Goods;
+import com.futu.course.service.GoodsService;
+import com.futu.course.mapper.GoodsMapper;
+import org.springframework.stereotype.Service;
+
+/**
+* @author yuu
+* @description 针对表【goods】的数据库操作Service实现
+* @createDate 2025-05-16 10:03:35
+*/
+@Service
+public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods>
+    implements GoodsService{
+
+}
+
+
+
+

+ 45 - 0
src/main/java/com/futu/course/task/KafkaTask.java

@@ -0,0 +1,45 @@
+package com.futu.course.task;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.futu.course.kafka.Product;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.kafka.annotation.KafkaListener;
+import org.springframework.kafka.core.KafkaTemplate;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+@EnableScheduling
+@Component
+public class KafkaTask {
+
+    @Autowired
+    private KafkaTemplate kafkaTemplate;
+
+
+    @Scheduled(cron = "0 * * * * *")
+    public void sendMsg() throws JsonProcessingException {
+        Product product = new Product();
+        product.setMsgId("12333");
+        product.setMsgType("类型");
+        product.setContent("内容哈哈哈哈");
+        ObjectMapper mapper = new ObjectMapper();
+        String value = mapper.writeValueAsString(product);
+
+        try {
+            kafkaTemplate.send("dome",value);
+            System.out.println("消息发送成功"+value);
+        }catch (Exception e)
+        {
+            System.out.println("消息发送失败"+e.getMessage());
+        }
+    }
+
+
+    @KafkaListener(topics = "dome")
+    public void getMsg(String msg)
+    {
+        System.out.println("接收到消息"+msg);
+    }
+}

+ 374 - 0
src/main/java/com/futu/course/utils/DateUtils.java

@@ -0,0 +1,374 @@
+/**
+ * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
+ */
+package com.futu.course.utils;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.time.DateFormatUtils;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * 日期工具类, 继承org.apache.commons.lang.time.DateUtils类
+ * @author jeeplus
+ * @version 2014-4-15
+ */
+public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
+
+	private static String[] parsePatterns = {
+		"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
+		"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
+		"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
+
+	/**
+	 * 得到当前日期字符串 格式(yyyy-MM-dd)
+	 */
+	public static String getDate() {
+		return getDate("yyyy-MM-dd");
+	}
+
+	/**
+	 * 得到当前日期字符串 格式(yyyy-MM-dd) pattern可以为:"yyyy-MM-dd" "HH:mm:ss" "E"
+	 */
+	public static String getDate(String pattern) {
+		return DateFormatUtils.format(new Date(), pattern);
+	}
+
+	/**
+	 * 得到日期字符串 默认格式(yyyy-MM-dd) pattern可以为:"yyyy-MM-dd" "HH:mm:ss" "E"
+	 */
+	public static String formatDate(Date date, Object... pattern) {
+		String formatDate = null;
+		if (pattern != null && pattern.length > 0) {
+			formatDate = DateFormatUtils.format(date, pattern[0].toString());
+		} else {
+			formatDate = DateFormatUtils.format(date, "yyyy-MM-dd");
+		}
+		return formatDate;
+	}
+
+	/**
+	 * 获取年月
+	 */
+	public static String getYearMonth(Date date) {
+
+		return formatDate(date,"yyyy")+formatDate(date,"MM");
+	}
+
+	/**
+	 * 得到日期时间字符串,转换格式(yyyy-MM-dd HH:mm:ss)
+	 */
+	public static String formatDateTime(Date date) {
+		return formatDate(date, "yyyy-MM-dd HH:mm:ss");
+	}
+
+	/**
+	 * 得到当前时间字符串 格式(HH:mm:ss)
+	 */
+	public static String getTime() {
+		return formatDate(new Date(), "HH:mm:ss");
+	}
+
+	/**
+	 * 得到当前日期和时间字符串 格式(yyyy-MM-dd HH:mm:ss)
+	 */
+	public static String getDateTime() {
+		return formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
+	}
+
+	public static String getDateTimeNum(){
+		String date=formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
+		date= StringUtils.replace(date,"-","");
+		date= StringUtils.replace(date,":","");
+		date= StringUtils.replace(date," ","");
+
+		return date;
+	}
+	public static String getYearMonthDayNum(){
+		String date=formatDate(new Date(), "yyyy-MM-dd");
+		date= StringUtils.replace(date,"-","");
+
+		return date;
+	}
+
+	/**
+	 * 得到当前年份字符串 格式(yyyy)
+	 */
+	public static String getYear() {
+		return formatDate(new Date(), "yyyy");
+	}
+
+	public static String getYear(Date date) {
+		return formatDate(date, "yyyy");
+	}
+
+	/**
+	 * 得到当前月份字符串 格式(MM)
+	 */
+	public static String getMonth() {
+		return formatDate(new Date(), "MM");
+	}
+
+	/**
+	 * 得到当天字符串 格式(dd)
+	 */
+	public static String getDay() {
+		return formatDate(new Date(), "dd");
+	}
+
+	/**
+	 * 得到当前星期字符串 格式(E)星期几
+	 */
+	public static String getWeek() {
+		return formatDate(new Date(), "E");
+	}
+
+	/**
+	 * 日期型字符串转化为日期 格式
+	 * { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm",
+	 *   "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm",
+	 *   "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm" }
+	 */
+	public static Date parseDate(Object str) {
+		if (str == null){
+			return null;
+		}
+		try {
+			return parseDate(str.toString(), parsePatterns);
+		} catch (ParseException e) {
+			return null;
+		}
+	}
+
+	/**
+	 * 获取过去的天数
+	 * @param date
+	 * @return
+	 */
+	public static long pastDays(Date date) {
+		long t = new Date().getTime()-date.getTime();
+		return t/(24*60*60*1000L);
+	}
+
+
+	/**
+	 * 之后多少天的时间
+	 * @param days
+	 * @return
+	 */
+	public static long getAfterDays(int days){
+		long t=new Date().getTime()+days*24*60*60*1000L;
+		return t;
+	}
+	public static Date getDateAfterDays(Date d,int days){
+		long t=d.getTime()+days*24*60*60*1000L;
+		Date afterTime=new Date(t);
+		return afterTime;
+	}
+	/**
+	 * 指定时间之后多少天的时间
+	 * @param days
+	 * @return
+	 */
+	public static long getAfterDays(Date d,int days){
+		long t=d.getTime()+days*24*60*60*1000L;
+		return t;
+	}
+
+	public static long diffDate(Date nowTime,Date extTime){
+	long time=	nowTime.getTime()-extTime.getTime();
+	return time;
+	}
+
+	/**
+	 * 之前多少天的时间
+	 * @param days
+	 * @return
+	 */
+	public static long getBeforeDays(int days){
+		long t=new Date().getTime()-days*24*60*60*1000L;
+		return t;
+	}
+
+	/**
+	 * 指定时间之前多少天的时间
+	 * @param days
+	 * @return
+	 */
+	public static long getBeforeDays(Date d,int days){
+		long t=d.getTime()-days*24*60*60*1000L;
+		return t;
+	}
+	public static Date getBeforeDaysDate(Date d,int days){
+		long t=d.getTime()-days*24*60*60*1000L;
+		Date beforeDays=new Date(t);
+		return beforeDays;
+	}
+	/**
+	 *
+	 * @param d
+	 * @param days
+	 * @return
+	 */
+	public static long getSpecificAfterDays(Date d,int days){
+		long t=d.getTime()+days*24*60*60*1000L;
+		return t;
+	}
+	/**
+	 * 获取过去的小时
+	 * @param date
+	 * @return
+	 */
+	public static long pastHour(Date date) {
+		long t = new Date().getTime()-date.getTime();
+		return t/(60*60*1000L);
+	}
+
+	/**
+	 * 获取过去的分钟
+	 * @param date
+	 * @return
+	 */
+	public static long pastMinutes(Date date) {
+		long t = new Date().getTime()-date.getTime();
+		return t/(60*1000L);
+	}
+
+	/**
+	 * 获取过去的分钟
+	 * @param date
+	 * @return
+	 */
+	public static long pastSecond(Date date) {
+		long t = new Date().getTime()-date.getTime();
+		return t/(1*1000L);
+	}
+
+	/**
+	 * 转换为时间(天,时:分:秒.毫秒)
+	 * @param timeMillis
+	 * @return
+	 */
+    public static String formatDateTime(long timeMillis){
+		long day = timeMillis/(24*60*60*1000L);
+		long hour = (timeMillis/(60*60*1000L)-day*24);
+		long min = ((timeMillis/(60*1000))-day*24*60-hour*60);
+		long s = (timeMillis/1000-day*24*60*60-hour*60*60-min*60);
+		long sss = (timeMillis-day*24*60*60*1000-hour*60*60*1000-min*60*1000-s*1000);
+		return (day>0?day+",":"")+hour+":"+min+":"+s+"."+sss;
+    }
+
+	/**
+	 * 时长
+	 * @param timeMillis
+	 * @return
+	 */
+	public static String formatDateTimeToString(long timeMillis){
+
+		long day = timeMillis/(24*60*60*1000L);
+		long hour = (timeMillis/(60*60*1000L)-day*24);
+		long min = ((timeMillis/(60*1000))-day*24*60-hour*60);
+		long s = (timeMillis/1000-day*24*60*60-hour*60*60-min*60);
+		long sss = (timeMillis-day*24*60*60*1000-hour*60*60*1000-min*60*1000-s*1000);
+		return (day>0?day+"天":"")+(hour>0?hour+"时":"")+(min>0?min+"分":"")+(s>0?s+"秒":"");
+	}
+
+	/**
+	 * 过去多少时间转换为时间(天,时:分:秒.毫秒)
+	 * @param timeMillis
+	 * @return
+	 */
+	public static String pastTime(long timeMillis){
+		long tempTimeMillis=timeMillis;
+		timeMillis=new Date().getTime()-timeMillis;
+		long day = timeMillis/(24*60*60*1000L);
+		long hour = (timeMillis/(60*60*1000L)-day*24);
+		long min = ((timeMillis/(60*1000L))-day*24*60-hour*60);
+		long s = (timeMillis/1000L-day*24*60*60-hour*60*60-min*60);
+		long sss = (timeMillis-day*24*60*60*1000-hour*60*60*1000-min*60*1000-s*1000L);
+		if(day>31){
+			return DateUtils.formateDate("yyyy-MM-dd",tempTimeMillis);
+		}
+		if(day>0){
+			return day+"天前";
+		}
+		if(hour>0){
+			return hour+"小时前";
+		}
+		if(min>0){
+			return min+"分钟前";
+		}
+		return "刚刚";
+	}
+	/**
+	 * 过去的时间
+
+	 * @return
+	 */
+	public static String pastTimeForDate(Date date){
+
+		long timeMillis=new Date().getTime()-date.getTime();
+		long day = timeMillis/(24*60*60*1000L);
+		long hour = (timeMillis/(60*60*1000)-day*24);
+		long min = ((timeMillis/(60*1000))-day*24*60-hour*60);
+		long s = (timeMillis/1000-day*24*60*60-hour*60*60-min*60);
+		long sss = (timeMillis-day*24*60*60*1000-hour*60*60*1000-min*60*1000-s*1000);
+		if(day>31){
+			return DateUtils.formatDate(date,"yyyy-MM-dd");
+		}
+		if(day>0){
+			return day+"天前";
+		}
+		if(hour>0){
+			return hour+"小时前";
+		}
+		if(min>0){
+			return min+"分钟前";
+		}
+		return "刚刚";
+	}
+
+	/**
+	 * 时长
+	 * @param timeMillis
+	 * @return
+	 */
+	public static String formatDateToHHMM(long timeMillis){
+		long day = timeMillis/(24*60*60*1000L);
+		long hour = (timeMillis/(60*60*1000));
+		long min = ((timeMillis/(60*1000))-day*24*60-hour*60);
+		long s = (timeMillis/1000-day*24*60*60-hour*60*60-min*60);
+		long sss = (timeMillis-day*24*60*60*1000-hour*60*60*1000-min*60*1000-s*1000);
+		return (hour>0?hour+"时":"0时")+(min>0?min+"分":"0分");
+	}
+    public static String formateDate(String dateFormat,long timeMillis){
+		SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
+		      Date date = new Date(timeMillis);
+		     return sdf.format(date);
+	}
+
+	/**
+	 * 获取两个日期之间的天数
+	 *
+	 * @param before
+	 * @param after
+	 * @return
+	 */
+	public static double getDistanceOfTwoDate(Date before, Date after) {
+		long beforeTime = before.getTime();
+		long afterTime = after.getTime();
+		return (afterTime - beforeTime) / (1000 * 60 * 60 * 24L);
+	}
+
+	/**
+	 * @param args
+	 * @throws ParseException
+	 */
+	public static void main(String[] args) throws ParseException {
+		long timelong=0;
+	System.out.println(	DateUtils.formatDateTime(timelong));
+	System.out.println(DateUtils.formatDateToHHMM(timelong));
+	}
+}

+ 73 - 0
src/main/java/com/futu/course/utils/SnowflakeIdWorker.java

@@ -0,0 +1,73 @@
+package com.futu.course.utils;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+public class SnowflakeIdWorker {
+    // 时间起始标记点,作为基准,一般取系统的最近时间(一旦确定不能变动)
+    private final long twepoch = 1288834974657L;
+    // 机器标识位数
+    private final long workerIdBits = 5L;
+    // 数据标识位数
+    private final long datacenterIdBits = 5L;
+    // 支持的最大机器标识数
+    private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
+    // 支持的最大数据标识数
+    private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
+    // 序列在id中占的位数
+    private final long sequenceBits = 12L;
+    // 机器ID向左移12位
+    private final long workerIdShift = sequenceBits;
+    // 数据标识符向左移17位(12+5)
+    private final long datacenterIdShift = sequenceBits + workerIdBits;
+    // 时间戳向左移22位(5+5+12)
+    private final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
+    private final long sequenceMask = -1L ^ (-1L << sequenceBits);
+    private long workerId;
+    private long datacenterId;
+    private long sequence = 0L;
+    private long lastTimestamp = -1L;
+    private final AtomicLong sequenceGenerator = new AtomicLong(0L);
+
+    public SnowflakeIdWorker(long workerId, long datacenterId) {
+        if (workerId > maxWorkerId || workerId < 0) {
+            throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
+        }
+        if (datacenterId > maxDatacenterId || datacenterId < 0) {
+            throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
+        }
+        this.workerId = workerId;
+        this.datacenterId = datacenterId;
+    }
+
+    public synchronized long nextId() {
+        long timestamp = timeGen();
+        if (timestamp < lastTimestamp) {
+            throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
+        }
+        if (lastTimestamp == timestamp) {
+            sequence = (sequence + 1) & sequenceMask;
+            if (sequence == 0) {
+                timestamp = tilNextMillis(lastTimestamp);
+            }
+        } else {
+            sequence = 0L;
+        }
+        lastTimestamp = timestamp;
+        return ((timestamp - twepoch) << timestampLeftShift) |
+                (datacenterId << datacenterIdShift) |
+                (workerId << workerIdShift) |
+                sequence;
+    }
+
+    protected long tilNextMillis(long lastTimestamp) {
+        long timestamp = timeGen();
+        while (timestamp <= lastTimestamp) {
+            timestamp = timeGen();
+        }
+        return timestamp;
+    }
+
+    protected long timeGen() {
+        return System.currentTimeMillis();
+    }
+}

+ 23 - 0
src/main/java/com/futu/course/vo/ResultVo.java

@@ -0,0 +1,23 @@
+package com.futu.course.vo;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class ResultVo<T> {
+    private int code;
+    private String msg;
+    private T data;
+
+    public static <T> ResultVo<T> success(String msg, T data) {
+        return new ResultVo<>(200, msg, data);
+    }
+
+
+    public static <T> ResultVo<T> fail(int code, String msg) {
+        return new ResultVo<>(code, msg, null);
+    }
+}

+ 21 - 0
src/main/resources/application.yml

@@ -0,0 +1,21 @@
+spring:
+  datasource:
+    driver-class-name: com.mysql.cj.jdbc.Driver
+    url: jdbc:mysql://localhost:3306/yuu?characterEncoding=utf8&serverTimezone=GMT%2B8
+    username: root
+    password: root
+  kafka:
+    bootstrap-servers: 192.168.88.88:9092
+    producer:
+      key-serializer: org.apache.kafka.common.serialization.StringSerializer
+      value-serializer: org.apache.kafka.common.serialization.StringSerializer
+      acks: all
+      retries: 3
+    consumer:
+      group-id: my_group
+      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
+      value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
+      auto-offset-reset: earliest
+      enable-auto-commit: false
+server:
+  port: 8003

+ 20 - 0
src/main/resources/mapper/GoodsMapper.xml

@@ -0,0 +1,20 @@
+<?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.futu.course.mapper.GoodsMapper">
+
+    <resultMap id="BaseResultMap" type="com.futu.course.domain.Goods">
+            <id property="id" column="id" jdbcType="BIGINT"/>
+            <result property="goodsName" column="goods_name" jdbcType="VARCHAR"/>
+            <result property="descruptions" column="descruptions" jdbcType="VARCHAR"/>
+            <result property="goodsImg" column="goods_img" jdbcType="VARCHAR"/>
+            <result property="content" column="content" jdbcType="VARCHAR"/>
+            <result property="createdTimee" column="created_timee" jdbcType="TIMESTAMP"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id,goods_name,descruptions,
+        goods_img,content,created_timee
+    </sql>
+</mapper>

+ 13 - 0
src/test/java/com/futu/course/YzzsaleApplicationTests.java

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