├── README.md ├── demo-support-launcher ├── src │ └── main │ │ ├── webapp │ │ ├── index.jsp │ │ └── WEB-INF │ │ │ └── web.xml │ │ ├── resources │ │ ├── properties │ │ │ ├── mysql.properties │ │ │ └── redis.properties │ │ ├── log4j2.xml │ │ ├── spring-servlet.xml │ │ ├── spring │ │ │ ├── spring-provider.xml │ │ │ ├── spring-redis.xml │ │ │ └── spring-datasource.xml │ │ └── spring-context.xml │ │ └── java │ │ └── com │ │ └── demo │ │ └── support │ │ └── export │ │ └── impl │ │ ├── ProductExportServiceImpl.java │ │ ├── SettlementExportServiceImpl.java │ │ └── ActivityExportServiceImpl.java └── pom.xml ├── demo-support-export ├── src │ └── main │ │ └── java │ │ └── com │ │ └── demo │ │ └── support │ │ ├── constant │ │ └── ResultCodeConstant.java │ │ ├── export │ │ ├── ProductExportService.java │ │ ├── SettlementExportService.java │ │ └── ActivityExportService.java │ │ └── dto │ │ ├── SettlementDataRequestDTO.java │ │ ├── SettlementDataDTO.java │ │ ├── Result.java │ │ ├── SettlementOrderDTO.java │ │ ├── ProductInfoDTO.java │ │ └── SeckillActivityDTO.java └── pom.xml ├── .gitignore ├── demo-support-service ├── src │ └── main │ │ └── java │ │ └── com │ │ └── demo │ │ └── support │ │ ├── ProductService.java │ │ ├── SettlementService.java │ │ ├── ActivityService.java │ │ ├── impl │ │ ├── ProductServiceImpl.java │ │ ├── ActivityServiceImpl.java │ │ └── SettlementServiceImpl.java │ │ └── tools │ │ └── RedisTools.java └── pom.xml ├── demo-support-dao ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── demo │ │ │ └── support │ │ │ ├── mapper │ │ │ ├── OrderRecordMapper.java │ │ │ ├── ProductInfoMapper.java │ │ │ └── ActivityMapper.java │ │ │ └── dao │ │ │ ├── ProductInfo.java │ │ │ ├── OrderRecord.java │ │ │ └── ActivityInfo.java │ │ └── resources │ │ └── mapper │ │ ├── ProductInfoMapper.xml │ │ ├── OrderRecordMapper.xml │ │ └── ActivityMapper.xml └── pom.xml ├── demo-support-common ├── src │ └── main │ │ └── java │ │ └── com │ │ └── demo │ │ └── support │ │ └── exception │ │ └── BizException.java └── pom.xml └── pom.xml /README.md: -------------------------------------------------------------------------------- 1 | # demo-support -------------------------------------------------------------------------------- /demo-support-launcher/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /demo-support-launcher/src/main/resources/properties/mysql.properties: -------------------------------------------------------------------------------- 1 | #数据库连接配置 2 | mysql.url=jdbc:mysql://localhost:3306/seckill?useUnicode=true&characterEncoding=UTF-8&connectTimeout=2000&socketTimeout=5000 3 | username=root 4 | password=Root_123 -------------------------------------------------------------------------------- /demo-support-export/src/main/java/com/demo/support/constant/ResultCodeConstant.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.constant; 2 | 3 | public class ResultCodeConstant { 4 | public static String SUCCESS="000000"; //成功 5 | 6 | public static String SYSTEM_EXCEPTION="999999"; //成功 7 | 8 | 9 | } 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | *.iml 23 | .idea/ 24 | target 25 | 26 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 27 | hs_err_pid* 28 | -------------------------------------------------------------------------------- /demo-support-service/src/main/java/com/demo/support/ProductService.java: -------------------------------------------------------------------------------- 1 | package com.demo.support; 2 | 3 | import com.demo.support.dto.ProductInfoDTO; 4 | import com.demo.support.dto.Result; 5 | 6 | public interface ProductService { 7 | 8 | /** 9 | * 创建商品 10 | * @param productInfoDTO 11 | * @return 12 | */ 13 | Result createProduct(ProductInfoDTO productInfoDTO); 14 | 15 | 16 | /** 17 | * 查询商品 18 | * @param productId 19 | * @return 20 | */ 21 | Result queryProduct(String productId); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /demo-support-service/src/main/java/com/demo/support/SettlementService.java: -------------------------------------------------------------------------------- 1 | package com.demo.support; 2 | 3 | import com.demo.support.dto.Result; 4 | import com.demo.support.dto.SettlementDataDTO; 5 | import com.demo.support.dto.SettlementDataRequestDTO; 6 | import com.demo.support.dto.SettlementOrderDTO; 7 | 8 | public interface SettlementService { 9 | 10 | /** 11 | * 下单 12 | * @param orderDTO 13 | * @return 订单号 14 | */ 15 | String submitOrder(SettlementOrderDTO orderDTO); 16 | 17 | 18 | SettlementDataDTO settlementData(SettlementDataRequestDTO requestDTO); 19 | } 20 | -------------------------------------------------------------------------------- /demo-support-export/src/main/java/com/demo/support/export/ProductExportService.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.export; 2 | 3 | import com.demo.support.dto.ProductInfoDTO; 4 | import com.demo.support.dto.Result; 5 | 6 | public interface ProductExportService { 7 | 8 | /** 9 | * 创建商品 10 | * @param productInfoDTO 11 | * @return 12 | */ 13 | Result createProduct(ProductInfoDTO productInfoDTO); 14 | 15 | 16 | /** 17 | * 查询商品 18 | * @param productId 19 | * @return 20 | */ 21 | Result queryProduct(String productId); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /demo-support-export/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.demo 8 | demo-support-export 9 | 1.0.0-SNAPSHOT 10 | 11 | 12 | 8 13 | 8 14 | 15 | 16 | -------------------------------------------------------------------------------- /demo-support-launcher/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /demo-support-export/src/main/java/com/demo/support/export/SettlementExportService.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.export; 2 | 3 | import com.demo.support.dto.*; 4 | 5 | public interface SettlementExportService { 6 | 7 | /** 8 | * 结算页初始化所需数据 9 | * 主要返回结算页所需的结算元素,包括用户地址,支付方式、配送时效、虚拟资产、价格相关数据(商品金额、抵扣金额等等) 10 | * @return 11 | */ 12 | Result settlementData(SettlementDataRequestDTO requestDTO); 13 | 14 | /** 15 | * 下单 16 | * @param orderDTO 17 | * @return 订单号 18 | */ 19 | Result submitOrder(SettlementOrderDTO orderDTO); 20 | 21 | /** 22 | * 获取支付页URL 23 | */ 24 | Result getPayPageUrl(String orderId); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /demo-support-dao/src/main/java/com/demo/support/mapper/OrderRecordMapper.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.mapper; 2 | 3 | import com.demo.support.dao.OrderRecord; 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | public interface OrderRecordMapper { 7 | 8 | /** 9 | * 创建订单 10 | * @param orderRecord 11 | * @return 12 | */ 13 | int insert(OrderRecord orderRecord); 14 | 15 | /** 16 | * 查询活动 17 | * @param 18 | * @return 19 | */ 20 | OrderRecord selectByOrderId(String orderId); 21 | 22 | /** 23 | * 更新状态 24 | * @param 25 | * @return 26 | */ 27 | int updateOrderStatus(@Param("orderId") String orderId,@Param("orderStatus") Integer orderStatus); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /demo-support-launcher/src/main/resources/properties/redis.properties: -------------------------------------------------------------------------------- 1 | #最大活动对象数 2 | redis.pool.maxTotal=1000 3 | #最大能够保持idel状态的对象数 4 | redis.pool.maxIdle=100 5 | #最小能够保持idel状态的对象数 6 | redis.pool.minIdle=50 7 | #当池内没有返回对象时,最大等待时间(毫秒) 8 | redis.pool.maxWaitMillis=1000 9 | #当调用borrow Object方法时,是否进行有效性检查 10 | redis.pool.testOnBorrow=true 11 | #当调用return Object方法时,是否进行有效性检查 12 | redis.pool.testOnReturn=true 13 | #“空闲链接”检测线程,检测的周期,毫秒数。如果为负值,表示不运行“检测线程”。默认为-1. 14 | redis.pool.timeBetweenEvictionRunsMillis=30000 15 | #向调用者输出“链接”对象时,是否检测它的空闲超时; 16 | redis.pool.testWhileIdle=true 17 | # 对于“空闲链接”检测线程而言,每次检测的链接资源的个数。默认为3. 18 | redis.pool.numTestsPerEvictionRun=50 19 | #redis服务器的IP 20 | redis.ip=127.0.0.1 21 | #redis服务器的Port 22 | redis.port=6379 23 | #单位秒 当客户端闲置多长时间后关闭连接,如果指定为0,表示关闭该功能 24 | redis.timeout=30 -------------------------------------------------------------------------------- /demo-support-common/src/main/java/com/demo/support/exception/BizException.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.exception; 2 | 3 | public class BizException extends Exception{ 4 | 5 | private String errorCode; 6 | 7 | public BizException(String errorCode, String message) { 8 | super(message); 9 | this.errorCode = errorCode; 10 | } 11 | 12 | public BizException(String errorCode, String message, Throwable cause) { 13 | super(message, cause); 14 | this.errorCode = errorCode; 15 | } 16 | 17 | public BizException(String message) { 18 | super(message); 19 | } 20 | 21 | public String getErrorCode() { 22 | return this.errorCode; 23 | } 24 | 25 | public void setErrorCode(String errorCode) { 26 | this.errorCode = errorCode; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /demo-support-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.demo 8 | demo-support 9 | 1.0.0-SNAPSHOT 10 | 11 | com.demo 12 | demo-support-common 13 | 1.0.0-SNAPSHOT 14 | 15 | 16 | 8 17 | 8 18 | 19 | 20 | -------------------------------------------------------------------------------- /demo-support-dao/src/main/java/com/demo/support/mapper/ProductInfoMapper.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.mapper; 2 | 3 | import com.demo.support.dao.ProductInfo; 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | public interface ProductInfoMapper { 7 | 8 | /** 9 | * 创建商品 10 | * @param productInfo 11 | * @return 12 | */ 13 | int insert(ProductInfo productInfo); 14 | 15 | /** 16 | * 查询商品 17 | * @param id 18 | * @return 19 | */ 20 | ProductInfo selectById(Long id); 21 | 22 | /** 23 | * 查询商品 24 | * @param productId 25 | * @return 26 | */ 27 | ProductInfo selectByProductId(@Param("productId") String productId); 28 | 29 | /** 30 | * 更新商品标签 1:正常商品,2:秒杀商品 3:预约商品 31 | * @param productId 32 | * @return 33 | */ 34 | int updateTag(@Param("productId") String productId,@Param("tag") Integer tag); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /demo-support-export/src/main/java/com/demo/support/dto/SettlementDataRequestDTO.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.dto; 2 | 3 | import java.io.Serializable; 4 | import java.math.BigDecimal; 5 | 6 | public class SettlementDataRequestDTO implements Serializable { 7 | 8 | private String userId; 9 | private Integer buyNum; 10 | private String productId; 11 | 12 | public String getUserId() { 13 | return userId; 14 | } 15 | 16 | public void setUserId(String userId) { 17 | this.userId = userId; 18 | } 19 | 20 | public Integer getBuyNum() { 21 | return buyNum; 22 | } 23 | 24 | public void setBuyNum(Integer buyNum) { 25 | this.buyNum = buyNum; 26 | } 27 | 28 | public String getProductId() { 29 | return productId; 30 | } 31 | 32 | public void setProductId(String productId) { 33 | this.productId = productId; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /demo-support-launcher/src/main/java/com/demo/support/export/impl/ProductExportServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.export.impl; 2 | 3 | import com.demo.support.ProductService; 4 | import com.demo.support.dto.ProductInfoDTO; 5 | import com.demo.support.dto.Result; 6 | import com.demo.support.export.ProductExportService; 7 | import org.apache.logging.log4j.LogManager; 8 | import org.apache.logging.log4j.Logger; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | 11 | public class ProductExportServiceImpl implements ProductExportService { 12 | 13 | Logger logger = LogManager.getLogger(ProductExportServiceImpl.class); 14 | 15 | @Autowired 16 | ProductService productService; 17 | 18 | @Override 19 | public Result createProduct(ProductInfoDTO productInfoDTO) { 20 | return null; 21 | } 22 | 23 | @Override 24 | public Result queryProduct(String productId) { 25 | return productService.queryProduct(productId); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /demo-support-dao/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.demo 8 | demo-support 9 | 1.0.0-SNAPSHOT 10 | 11 | com.demo 12 | demo-support-dao 13 | 1.0.0-SNAPSHOT 14 | 15 | 16 | 8 17 | 8 18 | 19 | 20 | 21 | 22 | org.mybatis 23 | mybatis 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /demo-support-launcher/src/main/resources/spring-servlet.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /demo-support-export/src/main/java/com/demo/support/dto/SettlementDataDTO.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.dto; 2 | 3 | import java.io.Serializable; 4 | import java.math.BigDecimal; 5 | 6 | public class SettlementDataDTO implements Serializable { 7 | 8 | private Integer payType; 9 | private BigDecimal totalPrice; 10 | private String address; 11 | private String assets; 12 | 13 | public Integer getPayType() { 14 | return payType; 15 | } 16 | 17 | public void setPayType(Integer payType) { 18 | this.payType = payType; 19 | } 20 | 21 | public BigDecimal getTotalPrice() { 22 | return totalPrice; 23 | } 24 | 25 | public void setTotalPrice(BigDecimal totalPrice) { 26 | this.totalPrice = totalPrice; 27 | } 28 | 29 | public String getAddress() { 30 | return address; 31 | } 32 | 33 | public void setAddress(String address) { 34 | this.address = address; 35 | } 36 | 37 | public String getAssets() { 38 | return assets; 39 | } 40 | 41 | public void setAssets(String assets) { 42 | this.assets = assets; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /demo-support-export/src/main/java/com/demo/support/dto/Result.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.dto; 2 | 3 | import com.demo.support.constant.ResultCodeConstant; 4 | 5 | import java.io.Serializable; 6 | 7 | public class Result implements Serializable { 8 | 9 | private String code; 10 | private String message; 11 | private T data; 12 | 13 | public Result() { 14 | } 15 | 16 | public Result(T data) { 17 | this.data = data; 18 | this.code = ResultCodeConstant.SUCCESS; 19 | } 20 | 21 | public Result(String code, String message, T data) { 22 | this.code = code; 23 | this.message = message; 24 | this.data = data; 25 | } 26 | 27 | public String getCode() { 28 | return code; 29 | } 30 | 31 | public void setCode(String code) { 32 | this.code = code; 33 | } 34 | 35 | public String getMessage() { 36 | return message; 37 | } 38 | 39 | public void setMessage(String message) { 40 | this.message = message; 41 | } 42 | 43 | public T getData() { 44 | return data; 45 | } 46 | 47 | public void setData(T data) { 48 | this.data = data; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /demo-support-dao/src/main/java/com/demo/support/mapper/ActivityMapper.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.mapper; 2 | 3 | import com.demo.support.dao.ActivityInfo; 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | public interface ActivityMapper { 7 | 8 | /** 9 | * 创建活动 10 | * @param activityInfo 11 | * @return 12 | */ 13 | int insert(ActivityInfo activityInfo); 14 | 15 | /** 16 | * 查询活动 17 | * @param id 18 | * @return 19 | */ 20 | ActivityInfo selectById(Long id); 21 | 22 | /** 23 | * 查询活动(最近的一场) 24 | * @param productId 25 | * @return 26 | */ 27 | ActivityInfo selectByProductId(@Param("productId") String productId); 28 | 29 | /** 30 | * 查询活动(按条件) 31 | * @param productId 32 | * @return 33 | */ 34 | ActivityInfo selectByCondition(@Param("productId") String productId,@Param("status") Integer status); 35 | 36 | /** 37 | * 更新活动状态 38 | * @param 39 | * @return 40 | */ 41 | int updateStatus(@Param("id") Long id,@Param("status") Integer status); 42 | 43 | /** 44 | * 更新库存 45 | * @param 46 | * @return 47 | */ 48 | int updateStockNum(@Param("id") Long id,@Param("buyNum") Integer buyNum); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /demo-support-export/src/main/java/com/demo/support/export/ActivityExportService.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.export; 2 | 3 | import com.demo.support.dto.Result; 4 | import com.demo.support.dto.SeckillActivityDTO; 5 | 6 | public interface ActivityExportService { 7 | 8 | /** 9 | * 查询活动库存 10 | * @param productId 11 | * @return 12 | */ 13 | Result queryStore(String productId); 14 | 15 | /** 16 | * 创建活动 17 | * @param activityDTO 18 | * @return 19 | */ 20 | Result createActivity(SeckillActivityDTO activityDTO); 21 | 22 | 23 | /** 24 | * 查询活动(查询活动最近的一场) 25 | * @param productId 26 | * @return 27 | */ 28 | Result queryActivity(String productId); 29 | 30 | /** 31 | * 查询活动 32 | * @param productId 33 | * @return 34 | */ 35 | Result queryActivityByCondition(String productId,Integer status); 36 | 37 | /** 38 | * 活动开始 39 | * @param productId 40 | * @return 41 | */ 42 | Result startActivity(String productId); 43 | 44 | /** 45 | * 活动关闭 46 | * @param productId 47 | * @return 48 | */ 49 | Result endActivity(String productId); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /demo-support-export/src/main/java/com/demo/support/dto/SettlementOrderDTO.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.dto; 2 | 3 | import java.io.Serializable; 4 | 5 | public class SettlementOrderDTO implements Serializable { 6 | 7 | private Integer payType; 8 | private String productId; 9 | private Integer buyNum; 10 | private String address; 11 | private String userId; 12 | 13 | public Integer getPayType() { 14 | return payType; 15 | } 16 | 17 | public void setPayType(Integer payType) { 18 | this.payType = payType; 19 | } 20 | 21 | public String getProductId() { 22 | return productId; 23 | } 24 | 25 | public void setProductId(String productId) { 26 | this.productId = productId; 27 | } 28 | 29 | public Integer getBuyNum() { 30 | return buyNum; 31 | } 32 | 33 | public void setBuyNum(Integer buyNum) { 34 | this.buyNum = buyNum; 35 | } 36 | 37 | public String getAddress() { 38 | return address; 39 | } 40 | 41 | public void setAddress(String address) { 42 | this.address = address; 43 | } 44 | 45 | public String getUserId() { 46 | return userId; 47 | } 48 | 49 | public void setUserId(String userId) { 50 | this.userId = userId; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /demo-support-service/src/main/java/com/demo/support/ActivityService.java: -------------------------------------------------------------------------------- 1 | package com.demo.support; 2 | 3 | import com.demo.support.dao.ActivityInfo; 4 | import com.demo.support.dto.Result; 5 | import com.demo.support.exception.BizException; 6 | 7 | /** 8 | * @Description: 9 | * @Author: wangzhangfei5 10 | * @Date: 2021/5/8 11 | * @Version: 1.0.0 12 | */ 13 | public interface ActivityService { 14 | /** 15 | * 创建活动 16 | * @param activityInfo 17 | * @return 18 | */ 19 | int createActivity(ActivityInfo activityInfo) throws BizException; 20 | 21 | /** 22 | * 查询活动 23 | * @param productId 24 | * @return 25 | */ 26 | ActivityInfo queryActivityById(String productId); 27 | 28 | /** 29 | * 查询活动 30 | * @param productId 31 | * @return 32 | */ 33 | ActivityInfo queryActivityByCondition(String productId,Integer status); 34 | 35 | /** 36 | * 活动开始 37 | * @param productId 38 | * @return 39 | */ 40 | Integer startActivity(String productId) throws BizException; 41 | 42 | /** 43 | * 活动关闭 44 | * @param productId 45 | * @return 46 | */ 47 | Integer endActivity(String productId) throws BizException; 48 | 49 | /** 50 | * 活动库存查询 51 | * @param productId 52 | * @return 53 | */ 54 | Integer queryStore(String productId); 55 | } 56 | -------------------------------------------------------------------------------- /demo-support-service/src/main/java/com/demo/support/impl/ProductServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.impl; 2 | 3 | import com.demo.support.ProductService; 4 | import com.demo.support.dao.ProductInfo; 5 | import com.demo.support.dto.ProductInfoDTO; 6 | import com.demo.support.dto.Result; 7 | import com.demo.support.mapper.ProductInfoMapper; 8 | import org.springframework.beans.BeanUtils; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Service; 11 | 12 | /** 13 | * @Description: 14 | * @Author: wangzhangfei5 15 | * @Date: 2021/5/10 16 | * @Version: 1.0.0 17 | */ 18 | @Service 19 | public class ProductServiceImpl implements ProductService { 20 | 21 | @Autowired 22 | ProductInfoMapper productInfoMapper; 23 | 24 | @Override 25 | public Result createProduct(ProductInfoDTO productInfoDTO) { 26 | ProductInfo productInfo = new ProductInfo(); 27 | BeanUtils.copyProperties(productInfoDTO,productInfo); 28 | int count = productInfoMapper.insert(productInfo); 29 | BeanUtils.copyProperties(productInfoDTO,productInfo); 30 | return new Result<>(count); 31 | } 32 | 33 | @Override 34 | public Result queryProduct(String productId) { 35 | ProductInfo productInfo = productInfoMapper.selectByProductId(productId); 36 | ProductInfoDTO infoDTO = new ProductInfoDTO(); 37 | BeanUtils.copyProperties(productInfo,infoDTO); 38 | return new Result<>(infoDTO); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /demo-support-launcher/src/main/resources/spring/spring-provider.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /demo-support-launcher/src/main/resources/spring-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | classpath:properties/*.properties 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /demo-support-export/src/main/java/com/demo/support/dto/ProductInfoDTO.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.dto; 2 | 3 | import java.io.Serializable; 4 | import java.math.BigDecimal; 5 | import java.util.Date; 6 | 7 | public class ProductInfoDTO implements Serializable { 8 | 9 | private long id; 10 | private String productId; 11 | private String productName; 12 | private String pictureUrl; 13 | private BigDecimal productPrice; 14 | private Integer tag; 15 | 16 | public long getId() { 17 | return id; 18 | } 19 | 20 | public void setId(long id) { 21 | this.id = id; 22 | } 23 | 24 | public String getProductId() { 25 | return productId; 26 | } 27 | 28 | public void setProductId(String productId) { 29 | this.productId = productId; 30 | } 31 | 32 | public String getProductName() { 33 | return productName; 34 | } 35 | 36 | public void setProductName(String productName) { 37 | this.productName = productName; 38 | } 39 | 40 | public String getPictureUrl() { 41 | return pictureUrl; 42 | } 43 | 44 | public void setPictureUrl(String pictureUrl) { 45 | this.pictureUrl = pictureUrl; 46 | } 47 | 48 | public BigDecimal getProductPrice() { 49 | return productPrice; 50 | } 51 | 52 | public void setProductPrice(BigDecimal productPrice) { 53 | this.productPrice = productPrice; 54 | } 55 | 56 | public Integer getTag() { 57 | return tag; 58 | } 59 | 60 | public void setTag(Integer tag) { 61 | this.tag = tag; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /demo-support-dao/src/main/java/com/demo/support/dao/ProductInfo.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.dao; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.Date; 5 | 6 | /** 7 | * @Description: 8 | * @Author: wangzhangfei5 9 | * @Date: 2021/5/8 10 | * @Version: 1.0.0 11 | */ 12 | public class ProductInfo { 13 | 14 | private long id; 15 | private String productId; 16 | private String productName; 17 | private String pictureUrl; 18 | private BigDecimal productPrice; 19 | private Integer tag; 20 | 21 | public long getId() { 22 | return id; 23 | } 24 | 25 | public void setId(long id) { 26 | this.id = id; 27 | } 28 | 29 | public String getProductId() { 30 | return productId; 31 | } 32 | 33 | public void setProductId(String productId) { 34 | this.productId = productId; 35 | } 36 | 37 | public String getProductName() { 38 | return productName; 39 | } 40 | 41 | public void setProductName(String productName) { 42 | this.productName = productName; 43 | } 44 | 45 | public String getPictureUrl() { 46 | return pictureUrl; 47 | } 48 | 49 | public void setPictureUrl(String pictureUrl) { 50 | this.pictureUrl = pictureUrl; 51 | } 52 | 53 | public BigDecimal getProductPrice() { 54 | return productPrice; 55 | } 56 | 57 | public void setProductPrice(BigDecimal productPrice) { 58 | this.productPrice = productPrice; 59 | } 60 | 61 | public Integer getTag() { 62 | return tag; 63 | } 64 | 65 | public void setTag(Integer tag) { 66 | this.tag = tag; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /demo-support-launcher/src/main/resources/spring/spring-redis.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /demo-support-dao/src/main/resources/mapper/ProductInfoMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | id, product_name,product_id,picture_url,product_price,tag 15 | 16 | 17 | 18 | insert into product_info( 19 | product_name,product_id,picture_url,product_price,tag) 20 | values (#{productName},#{productId},#{pictureUrl},#{productPrice},#{tag}) 21 | 22 | 23 | 29 | 30 | 36 | 37 | 38 | update product_info 39 | set tag = #{tag} 40 | where product_id = #{productId} 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /demo-support-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.demo 8 | demo-support 9 | 1.0.0-SNAPSHOT 10 | 11 | 12 | com.demo 13 | demo-support-service 14 | 1.0.0-SNAPSHOT 15 | 16 | 17 | 18 | org.springframework 19 | spring-context 20 | 21 | 22 | 23 | org.apache.logging.log4j 24 | log4j-api 25 | 26 | 27 | org.apache.logging.log4j 28 | log4j-core 29 | 30 | 31 | 32 | redis.clients 33 | jedis 34 | 35 | 36 | 37 | demo-support-dao 38 | com.demo 39 | 1.0.0-SNAPSHOT 40 | 41 | 42 | 43 | demo-support-export 44 | com.demo 45 | 1.0.0-SNAPSHOT 46 | 47 | 48 | com.demo 49 | demo-support-common 50 | 1.0.0-SNAPSHOT 51 | compile 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /demo-support-dao/src/main/resources/mapper/OrderRecordMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | id, order_id,product_id,user_id,buy_num,order_price,address,pay_type,order_time,order_status 21 | 22 | 23 | 24 | insert into order_record( 25 | order_id,product_id,user_id,buy_num,order_price,address,pay_type,order_time,order_status) 26 | values (#{orderId},#{productId},#{userId},#{buyNum},#{orderPrice},#{address},#{payType},#{orderTime},#{orderStatus}) 27 | 28 | 29 | 35 | 36 | 37 | update order_record 38 | set 39 | order_status = #{orderStatus} 40 | where 41 | order_id = #{orderId} 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /demo-support-launcher/src/main/java/com/demo/support/export/impl/SettlementExportServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.export.impl; 2 | 3 | import com.demo.support.ActivityService; 4 | import com.demo.support.SettlementService; 5 | import com.demo.support.dao.OrderRecord; 6 | import com.demo.support.dto.Result; 7 | import com.demo.support.dto.SettlementDataDTO; 8 | import com.demo.support.dto.SettlementDataRequestDTO; 9 | import com.demo.support.dto.SettlementOrderDTO; 10 | import com.demo.support.export.SettlementExportService; 11 | import com.demo.support.mapper.OrderRecordMapper; 12 | import org.apache.logging.log4j.LogManager; 13 | import org.apache.logging.log4j.Logger; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | 16 | public class SettlementExportServiceImpl implements SettlementExportService { 17 | 18 | Logger logger = LogManager.getLogger(SettlementExportServiceImpl.class); 19 | 20 | @Autowired 21 | ActivityService activityService; 22 | 23 | @Autowired 24 | SettlementService settlementService; 25 | 26 | @Autowired 27 | OrderRecordMapper orderRecordMapper; 28 | 29 | @Override 30 | public Result settlementData(SettlementDataRequestDTO requestDTO) { 31 | SettlementDataDTO dataDTO = settlementService.settlementData(requestDTO); 32 | return new Result<>(dataDTO); 33 | } 34 | 35 | @Override 36 | public Result submitOrder(SettlementOrderDTO orderDTO) { 37 | try{ 38 | String orderId = settlementService.submitOrder(orderDTO); 39 | 40 | return new Result<>(orderId); 41 | }catch (Exception e){ 42 | logger.error("提单异常",e); 43 | } 44 | return new Result<>(null); 45 | } 46 | 47 | @Override 48 | public Result getPayPageUrl(String orderId) { 49 | OrderRecord orderRecord = orderRecordMapper.selectByOrderId(orderId); 50 | String payPageUrl = "http://localhost:8080/mock/payPage?orderId="+orderId+"&orderPrice="+orderRecord.getOrderPrice().toPlainString(); 51 | return new Result<>(payPageUrl); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /demo-support-launcher/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | log4jConfiguration 10 | classpath:log4j2.xml 11 | 12 | 13 | 14 | contextConfigLocation 15 | classpath:/spring-context.xml 16 | 17 | 18 | 19 | org.springframework.web.context.ContextLoaderListener 20 | 21 | 22 | org.springframework.web.util.IntrospectorCleanupListener 23 | 24 | 25 | 26 | dispatcherServlet 27 | org.springframework.web.servlet.DispatcherServlet 28 | 29 | contextConfigLocation 30 | classpath:/spring-servlet.xml 31 | 32 | 1 33 | 34 | 35 | 36 | dispatcherServlet 37 | / 38 | 39 | 40 | 41 | jsp 42 | *.jsp 43 | 44 | 45 | jsp 46 | *.jspx 47 | 48 | 49 | 50 | characterEncodingFilter 51 | org.springframework.web.filter.CharacterEncodingFilter 52 | 53 | encoding 54 | UTF-8 55 | 56 | 57 | ignore 58 | true 59 | 60 | 61 | 62 | characterEncodingFilter 63 | /* 64 | 65 | 66 | 67 | index.jsp 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /demo-support-dao/src/main/java/com/demo/support/dao/OrderRecord.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.dao; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.Date; 5 | 6 | /** 7 | * @Description: 8 | * @Author: wangzhangfei5 9 | * @Date: 2021/5/8 10 | * @Version: 1.0.0 11 | */ 12 | public class OrderRecord { 13 | 14 | private long id; 15 | private String orderId; 16 | private String productId; 17 | private String userId; 18 | private Integer buyNum; 19 | private BigDecimal orderPrice; 20 | private String address; 21 | private Integer payType; 22 | private Date orderTime; 23 | private Integer orderStatus; //订单状态 0:初始化,1:成功待支付,2:完成,3:处理中,4:失败,5:订单取消 24 | 25 | public long getId() { 26 | return id; 27 | } 28 | 29 | public void setId(long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getProductId() { 34 | return productId; 35 | } 36 | 37 | public void setProductId(String productId) { 38 | this.productId = productId; 39 | } 40 | 41 | public String getUserId() { 42 | return userId; 43 | } 44 | 45 | public void setUserId(String userId) { 46 | this.userId = userId; 47 | } 48 | 49 | public Integer getBuyNum() { 50 | return buyNum; 51 | } 52 | 53 | public void setBuyNum(Integer buyNum) { 54 | this.buyNum = buyNum; 55 | } 56 | 57 | public BigDecimal getOrderPrice() { 58 | return orderPrice; 59 | } 60 | 61 | public void setOrderPrice(BigDecimal orderPrice) { 62 | this.orderPrice = orderPrice; 63 | } 64 | 65 | public String getAddress() { 66 | return address; 67 | } 68 | 69 | public void setAddress(String address) { 70 | this.address = address; 71 | } 72 | 73 | public Integer getPayType() { 74 | return payType; 75 | } 76 | 77 | public void setPayType(Integer payType) { 78 | this.payType = payType; 79 | } 80 | 81 | public Date getOrderTime() { 82 | return orderTime; 83 | } 84 | 85 | public void setOrderTime(Date orderTime) { 86 | this.orderTime = orderTime; 87 | } 88 | 89 | public Integer getOrderStatus() { 90 | return orderStatus; 91 | } 92 | 93 | public void setOrderStatus(Integer orderStatus) { 94 | this.orderStatus = orderStatus; 95 | } 96 | 97 | public String getOrderId() { 98 | return orderId; 99 | } 100 | 101 | public void setOrderId(String orderId) { 102 | this.orderId = orderId; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /demo-support-launcher/src/main/resources/spring/spring-datasource.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /demo-support-dao/src/main/java/com/demo/support/dao/ActivityInfo.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.dao; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.Date; 5 | 6 | /** 7 | * @Description: 8 | * @Author: wangzhangfei5 9 | * @Date: 2021/5/8 10 | * @Version: 1.0.0 11 | */ 12 | public class ActivityInfo { 13 | 14 | private long id; 15 | private String activityName; 16 | private String productId; 17 | private Date activityStart; 18 | private Date activityEnd; 19 | private Integer limitNum; 20 | private Integer stockNum; 21 | private Integer status;//0:未开始 1:已开始 2:已结束 22 | private String activityPictureUrl; 23 | private BigDecimal activityPrice; 24 | 25 | public long getId() { 26 | return id; 27 | } 28 | 29 | public void setId(long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getActivityName() { 34 | return activityName; 35 | } 36 | 37 | public void setActivityName(String activityName) { 38 | this.activityName = activityName; 39 | } 40 | 41 | public String getProductId() { 42 | return productId; 43 | } 44 | 45 | public void setProductId(String productId) { 46 | this.productId = productId; 47 | } 48 | 49 | public Date getActivityStart() { 50 | return activityStart; 51 | } 52 | 53 | public void setActivityStart(Date activityStart) { 54 | this.activityStart = activityStart; 55 | } 56 | 57 | public Date getActivityEnd() { 58 | return activityEnd; 59 | } 60 | 61 | public void setActivityEnd(Date activityEnd) { 62 | this.activityEnd = activityEnd; 63 | } 64 | 65 | public Integer getLimitNum() { 66 | return limitNum; 67 | } 68 | 69 | public void setLimitNum(Integer limitNum) { 70 | this.limitNum = limitNum; 71 | } 72 | 73 | public Integer getStockNum() { 74 | return stockNum; 75 | } 76 | 77 | public void setStockNum(Integer stockNum) { 78 | this.stockNum = stockNum; 79 | } 80 | 81 | public Integer getStatus() { 82 | return status; 83 | } 84 | 85 | public void setStatus(Integer status) { 86 | this.status = status; 87 | } 88 | 89 | public String getActivityPictureUrl() { 90 | return activityPictureUrl; 91 | } 92 | 93 | public void setActivityPictureUrl(String activityPictureUrl) { 94 | this.activityPictureUrl = activityPictureUrl; 95 | } 96 | 97 | public BigDecimal getActivityPrice() { 98 | return activityPrice; 99 | } 100 | 101 | public void setActivityPrice(BigDecimal activityPrice) { 102 | this.activityPrice = activityPrice; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /demo-support-export/src/main/java/com/demo/support/dto/SeckillActivityDTO.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.dto; 2 | 3 | import java.io.Serializable; 4 | import java.math.BigDecimal; 5 | import java.util.Date; 6 | 7 | public class SeckillActivityDTO implements Serializable { 8 | 9 | private long id; 10 | private String activityName; 11 | private String productId; 12 | private Date activityStart; 13 | private Date activityEnd; 14 | private Integer limitNum; 15 | private Integer stockNum; 16 | private String activityPictureUrl; 17 | private BigDecimal activityPrice; 18 | private Integer status; 19 | 20 | public Long getId() { 21 | return id; 22 | } 23 | 24 | public void setId(Long id) { 25 | this.id = id; 26 | } 27 | 28 | public String getActivityName() { 29 | return activityName; 30 | } 31 | 32 | public void setActivityName(String activityName) { 33 | this.activityName = activityName; 34 | } 35 | 36 | public void setId(long id) { 37 | this.id = id; 38 | } 39 | 40 | public String getProductId() { 41 | return productId; 42 | } 43 | 44 | public void setProductId(String productId) { 45 | this.productId = productId; 46 | } 47 | 48 | public Date getActivityStart() { 49 | return activityStart; 50 | } 51 | 52 | public void setActivityStart(Date activityStart) { 53 | this.activityStart = activityStart; 54 | } 55 | 56 | public Date getActivityEnd() { 57 | return activityEnd; 58 | } 59 | 60 | public void setActivityEnd(Date activityEnd) { 61 | this.activityEnd = activityEnd; 62 | } 63 | 64 | public Integer getLimitNum() { 65 | return limitNum; 66 | } 67 | 68 | public void setLimitNum(Integer limitNum) { 69 | this.limitNum = limitNum; 70 | } 71 | 72 | public Integer getStockNum() { 73 | return stockNum; 74 | } 75 | 76 | public void setStockNum(Integer stockNum) { 77 | this.stockNum = stockNum; 78 | } 79 | 80 | public String getActivityPictureUrl() { 81 | return activityPictureUrl; 82 | } 83 | 84 | public void setActivityPictureUrl(String activityPictureUrl) { 85 | this.activityPictureUrl = activityPictureUrl; 86 | } 87 | 88 | public BigDecimal getActivityPrice() { 89 | return activityPrice; 90 | } 91 | 92 | public void setActivityPrice(BigDecimal activityPrice) { 93 | this.activityPrice = activityPrice; 94 | } 95 | 96 | public Integer getStatus() { 97 | return status; 98 | } 99 | 100 | public void setStatus(Integer status) { 101 | this.status = status; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /demo-support-service/src/main/java/com/demo/support/tools/RedisTools.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.tools; 2 | 3 | 4 | import org.apache.logging.log4j.LogManager; 5 | import org.apache.logging.log4j.Logger; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Component; 8 | import redis.clients.jedis.Jedis; 9 | import redis.clients.jedis.JedisPool; 10 | 11 | import javax.annotation.PostConstruct; 12 | 13 | @Component 14 | public class RedisTools { 15 | 16 | @Autowired 17 | JedisPool jedisPool; 18 | 19 | Logger logger = LogManager.getLogger(RedisTools.class); 20 | 21 | /** 22 | * lua逻辑:首先判断活动库存是否存在,以及库存余量是否够本次购买数量,如果不够,则返回0,如果够则完成扣减并返回1 23 | * 两个入参,KEYS[1] : 活动库存的key 24 | * KEYS[2] : 活动库存的扣减数量 25 | */ 26 | private String STORE_DEDUCTION_SCRIPT_LUA = 27 | "local c_s = redis.call('get', KEYS[1])\n" + 28 | "if not c_s or tonumber(c_s) < tonumber(KEYS[2]) then\n" + 29 | "return 0\n" + 30 | "end\n" + 31 | "redis.call('decrby',KEYS[1], KEYS[2])\n" + 32 | "return 1"; 33 | 34 | /** 35 | * 在系统启动时,将脚本预加载到Redis中,并返回一个加密的字符串,下次只要传该加密窜,即可执行对应脚本,减少了Redis的预编译 36 | */ 37 | private String STORE_DEDUCTION_SCRIPT_SHA1 = ""; 38 | 39 | @PostConstruct 40 | public void init(){ 41 | try (Jedis jedis = jedisPool.getResource()) { 42 | String sha1 = jedis.scriptLoad(STORE_DEDUCTION_SCRIPT_LUA); 43 | logger.error("生成的sha1:" + sha1); 44 | STORE_DEDUCTION_SCRIPT_SHA1 = sha1; 45 | } 46 | } 47 | 48 | /** 49 | * 调用Lua脚本,不需要每次都传入Lua脚本,只需要传入预编译返回的sha1即可 50 | * String-evalsha 51 | * @param key 52 | */ 53 | public Long evalsha(String key,String buyNum){ 54 | try (Jedis jedis = jedisPool.getResource()) { 55 | Object obj = jedis.evalsha(STORE_DEDUCTION_SCRIPT_SHA1,2,key,buyNum); 56 | //脚本中返回的结果是0或1,表示失败或者成功 57 | return (Long)obj; 58 | } 59 | } 60 | 61 | /** 62 | * String-设置缓存 63 | * @param key 64 | * @param value 65 | */ 66 | public void set(String key,String value){ 67 | try (Jedis jedis = jedisPool.getResource()) { 68 | jedis.set(key, value); 69 | } 70 | } 71 | 72 | /** 73 | * String-查询 74 | * @param key 75 | */ 76 | public String get(String key){ 77 | try (Jedis jedis = jedisPool.getResource()) { 78 | return jedis.get(key); 79 | } 80 | } 81 | 82 | /** 83 | * String-设置缓存 84 | * 带失效时间 85 | * @param key 86 | * @param value 87 | */ 88 | public void set(String key,String value,int expireTime){ 89 | try (Jedis jedis = jedisPool.getResource()) { 90 | jedis.set(key, value); 91 | jedis.expire(key,expireTime); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /demo-support-dao/src/main/resources/mapper/ActivityMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | id, activity_name,product_id,activity_start,activity_end,limit_num,stock_num,status,activity_picture_url,activity_price 20 | 21 | 22 | 23 | insert into seckill_activity( 24 | activity_name,product_id,activity_start,activity_end,limit_num,stock_num,status,activity_picture_url,activity_price) 25 | values (#{activityName},#{productId},#{activityStart},#{activityEnd}, 26 | #{limitNum},#{stockNum},#{status},#{activityPictureUrl},#{activityPrice}) 27 | 28 | 29 | 35 | 36 | 45 | 46 | 57 | 58 | 59 | update seckill_activity 60 | set status = #{status} 61 | where id = #{id} 62 | 63 | 64 | 65 | update seckill_activity 66 | set stock_num = stock_num - #{buyNum} 67 | where id = #{id} 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /demo-support-service/src/main/java/com/demo/support/impl/ActivityServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.impl; 2 | 3 | import com.demo.support.dao.ActivityInfo; 4 | import com.demo.support.ActivityService; 5 | import com.demo.support.exception.BizException; 6 | import com.demo.support.mapper.ActivityMapper; 7 | import com.demo.support.mapper.ProductInfoMapper; 8 | import com.demo.support.tools.RedisTools; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Service; 11 | 12 | import java.util.Date; 13 | 14 | /** 15 | * @Description: 16 | * @Author: wangzhangfei5 17 | * @Date: 2021/5/10 18 | * @Version: 1.0.0 19 | */ 20 | @Service 21 | public class ActivityServiceImpl implements ActivityService { 22 | 23 | @Autowired 24 | ActivityMapper activityMapper; 25 | @Autowired 26 | ProductInfoMapper productInfoMapper; 27 | @Autowired 28 | RedisTools redisTools; 29 | 30 | @Override 31 | public int createActivity(ActivityInfo activityInfo) throws BizException { 32 | ActivityInfo existRecord = activityMapper.selectByCondition(activityInfo.getProductId(),null); 33 | if(existRecord!=null && (existRecord.getStatus()==1 || existRecord.getStatus()==0)){ 34 | throw new BizException("活动已存在"); 35 | } 36 | activityInfo.setStatus(0); 37 | return activityMapper.insert(activityInfo); 38 | } 39 | 40 | @Override 41 | public ActivityInfo queryActivityById(String productId) { 42 | return activityMapper.selectByProductId(productId); 43 | } 44 | 45 | @Override 46 | public ActivityInfo queryActivityByCondition(String productId,Integer status) { 47 | return activityMapper.selectByCondition(productId,status); 48 | } 49 | 50 | @Override 51 | public Integer startActivity(String productId) throws BizException { 52 | //查询未开始的 53 | ActivityInfo activityInfo = activityMapper.selectByCondition(productId,0); 54 | //判断时间是否在有效期内 55 | Date now = new Date(); 56 | if(now.before(activityInfo.getActivityStart())){ 57 | throw new BizException("活动尚未开始束"); 58 | } 59 | if(now.after(activityInfo.getActivityEnd())){ 60 | throw new BizException("活动已结束"); 61 | } 62 | //更改活动为开始状态 63 | activityMapper.updateStatus(activityInfo.getId(),1); 64 | //更改商品标识为秒杀 65 | productInfoMapper.updateTag(productId,2); 66 | 67 | //将库存放入Redis 68 | redisTools.set("store_"+productId,String.valueOf(activityInfo.getStockNum())); 69 | 70 | return 1; 71 | } 72 | 73 | @Override 74 | public Integer endActivity(String productId) throws BizException { 75 | //查询进行中的 76 | ActivityInfo activityInfo = activityMapper.selectByCondition(productId,1); 77 | //更改活动为结束状态 78 | activityMapper.updateStatus(activityInfo.getId(),2); 79 | //更改商品标识为普通 80 | productInfoMapper.updateTag(productId,1); 81 | return 1; 82 | } 83 | 84 | @Override 85 | public Integer queryStore(String productId) { 86 | //查询进行中的 87 | ActivityInfo activityInfo = activityMapper.selectByCondition(productId,1); 88 | return activityInfo.getStockNum(); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /demo-support-launcher/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.demo 8 | demo-support 9 | 1.0.0-SNAPSHOT 10 | 11 | 12 | com.demo 13 | demo-support-launcher 14 | 1.0.0-SNAPSHOT 15 | 16 | war 17 | 18 | 19 | 20 | 21 | 22 | org.springframework 23 | spring-beans 24 | 25 | 26 | org.springframework 27 | spring-aop 28 | 29 | 30 | org.springframework 31 | spring-expression 32 | 33 | 34 | org.springframework 35 | spring-core 36 | 37 | 38 | org.springframework 39 | spring-web 40 | 41 | 42 | org.springframework 43 | spring-webmvc 44 | 45 | 46 | org.aspectj 47 | aspectjrt 48 | 49 | 50 | 51 | 52 | 53 | mysql 54 | mysql-connector-java 55 | 56 | 57 | com.alibaba 58 | druid 59 | 60 | 61 | org.mybatis 62 | mybatis-spring 63 | 64 | 65 | org.springframework 66 | spring-jdbc 67 | 68 | 69 | spring-tx 70 | org.springframework 71 | 72 | 73 | 74 | 75 | org.apache.dubbo 76 | dubbo 77 | 78 | 79 | 80 | 81 | 82 | javax.servlet 83 | javax.servlet-api 84 | 85 | 86 | 87 | com.demo 88 | demo-support-service 89 | 1.0.0-SNAPSHOT 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /demo-support-service/src/main/java/com/demo/support/impl/SettlementServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.impl; 2 | 3 | import com.demo.support.SettlementService; 4 | import com.demo.support.dao.ActivityInfo; 5 | import com.demo.support.dao.OrderRecord; 6 | import com.demo.support.dao.ProductInfo; 7 | import com.demo.support.dto.Result; 8 | import com.demo.support.dto.SettlementDataDTO; 9 | import com.demo.support.dto.SettlementDataRequestDTO; 10 | import com.demo.support.dto.SettlementOrderDTO; 11 | import com.demo.support.mapper.ActivityMapper; 12 | import com.demo.support.mapper.OrderRecordMapper; 13 | import com.demo.support.mapper.ProductInfoMapper; 14 | import com.demo.support.tools.RedisTools; 15 | import org.apache.logging.log4j.LogManager; 16 | import org.apache.logging.log4j.Logger; 17 | import org.springframework.beans.factory.annotation.Autowired; 18 | import org.springframework.stereotype.Service; 19 | 20 | import java.math.BigDecimal; 21 | import java.util.Date; 22 | import java.util.Random; 23 | 24 | /** 25 | * @Description: 26 | * @Author: wangzhangfei5 27 | * @Date: 2021/5/10 28 | * @Version: 1.0.0 29 | */ 30 | @Service 31 | public class SettlementServiceImpl implements SettlementService { 32 | 33 | Logger logger = LogManager.getLogger(SettlementServiceImpl.class); 34 | 35 | @Autowired 36 | OrderRecordMapper orderRecordMapper; 37 | 38 | @Autowired 39 | ActivityMapper activityMapper; 40 | 41 | @Autowired 42 | ProductInfoMapper productInfoMapper; 43 | 44 | @Autowired 45 | RedisTools redisTools; 46 | 47 | @Override 48 | public String submitOrder(SettlementOrderDTO orderDTO) { 49 | //1.校验商品标识 50 | 51 | //2.限购 52 | Long count = redisTools.evalsha("store_"+orderDTO.getProductId(),String.valueOf(orderDTO.getBuyNum())); 53 | logger.error(orderDTO.getUserId()+"限购结果:"+count); 54 | if(count==null || count<=0){ 55 | return null; 56 | } 57 | 58 | //3.下单-初始化 59 | Random random = new Random(10000); 60 | String orderId = String.valueOf(System.currentTimeMillis())+random.nextInt(); 61 | OrderRecord orderRecord = new OrderRecord(); 62 | 63 | ActivityInfo activityInfo = activityMapper.selectByProductId(orderDTO.getProductId()); 64 | 65 | orderRecord.setOrderId(orderId); 66 | BigDecimal orderPrice = activityInfo.getActivityPrice().multiply(new BigDecimal(orderDTO.getBuyNum())); 67 | orderRecord.setOrderPrice(orderPrice); 68 | orderRecord.setOrderStatus(0); 69 | orderRecord.setAddress(orderDTO.getAddress()); 70 | orderRecord.setPayType(orderDTO.getPayType()); 71 | orderRecord.setProductId(orderDTO.getProductId()); 72 | orderRecord.setUserId(orderDTO.getUserId()); 73 | orderRecord.setOrderTime(new Date()); 74 | orderRecord.setBuyNum(orderDTO.getBuyNum()); 75 | 76 | orderRecordMapper.insert(orderRecord); 77 | 78 | //3.预占库存 79 | activityMapper.updateStockNum(activityInfo.getId(),orderDTO.getBuyNum()); 80 | 81 | //4.更新订单-下单成功待支付 82 | orderRecordMapper.updateOrderStatus(orderId,1); 83 | 84 | return orderId; 85 | } 86 | 87 | @Override 88 | public SettlementDataDTO settlementData(SettlementDataRequestDTO requestDTO) { 89 | ActivityInfo activityInfo = activityMapper.selectByProductId(requestDTO.getProductId()); 90 | 91 | SettlementDataDTO dataDTO = new SettlementDataDTO(); 92 | 93 | dataDTO.setAssets(""); 94 | dataDTO.setPayType(1);//在线支付 95 | dataDTO.setTotalPrice(activityInfo.getActivityPrice().multiply(new BigDecimal(requestDTO.getBuyNum()))); 96 | dataDTO.setAddress("北京朝阳区"); 97 | 98 | return dataDTO; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /demo-support-launcher/src/main/java/com/demo/support/export/impl/ActivityExportServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.demo.support.export.impl; 2 | 3 | import com.demo.support.ActivityService; 4 | import com.demo.support.constant.ResultCodeConstant; 5 | import com.demo.support.dao.ActivityInfo; 6 | import com.demo.support.dto.Result; 7 | import com.demo.support.dto.SeckillActivityDTO; 8 | import com.demo.support.exception.BizException; 9 | import com.demo.support.export.ActivityExportService; 10 | import org.apache.logging.log4j.LogManager; 11 | import org.apache.logging.log4j.Logger; 12 | import org.springframework.beans.BeanUtils; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | 15 | public class ActivityExportServiceImpl implements ActivityExportService { 16 | 17 | Logger logger = LogManager.getLogger(ActivityExportServiceImpl.class); 18 | 19 | @Autowired 20 | ActivityService activityService; 21 | 22 | 23 | @Override 24 | public Result queryStore(String productId) { 25 | try{ 26 | Integer count = activityService.queryStore(productId); 27 | return new Result<>(count); 28 | }catch (Exception e){ 29 | logger.error("发生异常了",e); 30 | } 31 | return new Result<>(ResultCodeConstant.SYSTEM_EXCEPTION,"系统异常",null); 32 | } 33 | 34 | @Override 35 | public Result createActivity(SeckillActivityDTO activityDTO) { 36 | try{ 37 | ActivityInfo activityInfo = new ActivityInfo(); 38 | 39 | BeanUtils.copyProperties(activityDTO,activityInfo); 40 | 41 | int count = activityService.createActivity(activityInfo); 42 | 43 | return new Result<>(count); 44 | }catch (BizException e){ 45 | logger.error("发生异常了",e); 46 | return new Result<>(ResultCodeConstant.SYSTEM_EXCEPTION,e.getMessage(),null); 47 | }catch (Exception e){ 48 | logger.error("发生异常了",e); 49 | } 50 | return new Result<>(ResultCodeConstant.SYSTEM_EXCEPTION,"系统异常",null); 51 | } 52 | 53 | @Override 54 | public Result queryActivity(String productId) { 55 | ActivityInfo activityInfo = activityService.queryActivityById(productId); 56 | 57 | SeckillActivityDTO activityDTO = new SeckillActivityDTO(); 58 | 59 | BeanUtils.copyProperties(activityInfo,activityDTO); 60 | 61 | return new Result<>(activityDTO); 62 | } 63 | 64 | @Override 65 | public Result queryActivityByCondition(String productId, Integer status) { 66 | ActivityInfo activityInfo = activityService.queryActivityByCondition(productId,status); 67 | if(activityInfo == null){ 68 | return new Result<>(null); 69 | } 70 | 71 | SeckillActivityDTO activityDTO = new SeckillActivityDTO(); 72 | 73 | BeanUtils.copyProperties(activityInfo,activityDTO); 74 | 75 | return new Result<>(activityDTO); 76 | } 77 | 78 | @Override 79 | public Result startActivity(String productId) { 80 | Integer count = 0; 81 | try{ 82 | count = activityService.startActivity(productId); 83 | }catch (BizException e){ 84 | return new Result<>(ResultCodeConstant.SYSTEM_EXCEPTION,e.getErrorCode(),count); 85 | }catch (Exception e){ 86 | return new Result<>(ResultCodeConstant.SYSTEM_EXCEPTION,"系统异常",null); 87 | } 88 | return new Result<>(count); 89 | } 90 | 91 | @Override 92 | public Result endActivity(String productId) { 93 | Integer count = 0; 94 | try{ 95 | count = activityService.endActivity(productId); 96 | }catch (BizException e){ 97 | return new Result<>(ResultCodeConstant.SYSTEM_EXCEPTION,e.getErrorCode(),count); 98 | }catch (Exception e){ 99 | return new Result<>(ResultCodeConstant.SYSTEM_EXCEPTION,"系统异常",null); 100 | } 101 | return new Result<>(count); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 4.0.0 6 | 7 | com.demo 8 | demo-support 9 | 1.0.0-SNAPSHOT 10 | 11 | 12 | demo-support-export 13 | demo-support-launcher 14 | demo-support-common 15 | demo-support-dao 16 | demo-support-service 17 | 18 | 19 | pom 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 1.8 25 | 4.3.25.RELEASE 26 | 27 | 5.1.30 28 | 1.1.12 29 | 30 | 3.4.6 31 | 1.3.2 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.springframework 40 | spring-beans 41 | ${spring.version} 42 | 43 | 44 | org.springframework 45 | spring-aop 46 | ${spring.version} 47 | 48 | 49 | org.springframework 50 | spring-expression 51 | ${spring.version} 52 | 53 | 54 | org.springframework 55 | spring-core 56 | ${spring.version} 57 | 58 | 59 | org.springframework 60 | spring-web 61 | ${spring.version} 62 | 63 | 64 | org.springframework 65 | spring-webmvc 66 | ${spring.version} 67 | 68 | 69 | org.springframework 70 | spring-context 71 | ${spring.version} 72 | 73 | 74 | org.aspectj 75 | aspectjweaver 76 | 1.8.13 77 | 78 | 79 | org.aspectj 80 | aspectjrt 81 | 1.7.2 82 | 83 | 84 | 85 | 86 | mysql 87 | mysql-connector-java 88 | ${mysql.jdbc.version} 89 | 90 | 91 | com.alibaba 92 | druid 93 | ${druid.version} 94 | 95 | 96 | org.mybatis 97 | mybatis 98 | ${mybatis.version} 99 | 100 | 101 | org.mybatis 102 | mybatis-spring 103 | ${mybatis.spring.version} 104 | 105 | 106 | org.springframework 107 | spring-jdbc 108 | ${spring.version} 109 | 110 | 111 | spring-tx 112 | org.springframework 113 | ${spring.version} 114 | 115 | 116 | 117 | 118 | javax.servlet 119 | javax.servlet-api 120 | 3.1.0 121 | provided 122 | 123 | 124 | 125 | 126 | org.apache.logging.log4j 127 | log4j-core 128 | 2.12.1 129 | 130 | 131 | 132 | org.apache.logging.log4j 133 | log4j-api 134 | 2.12.1 135 | 136 | 137 | 138 | 139 | org.apache.dubbo 140 | dubbo 141 | 2.7.11 142 | 143 | 144 | 145 | 146 | 147 | redis.clients 148 | jedis 149 | 3.3.0 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | src/main/resources 160 | 161 | 162 | 163 | 164 | 165 | maven-clean-plugin 166 | 3.1.0 167 | 168 | 169 | 170 | maven-resources-plugin 171 | 3.0.2 172 | 173 | 174 | maven-compiler-plugin 175 | 3.8.0 176 | 177 | 178 | maven-surefire-plugin 179 | 2.22.1 180 | 181 | 182 | maven-war-plugin 183 | 3.2.2 184 | 185 | 186 | maven-install-plugin 187 | 2.5.2 188 | 189 | 190 | 191 | 192 | 193 | --------------------------------------------------------------------------------