后端创建订单

news2024/11/15 8:57:25
package com.java1234.entity;

import io.jsonwebtoken.Claims;

/**
 * jwt验证信息
 * @author java1234_小锋
 * @site www.java1234.com
 * @company Java知识分享网
 * @create 2019-08-13 上午 10:00
 */
public class CheckResult {

    private int errCode;

    private boolean success;

    private Claims claims;

    public int getErrCode() {
        return errCode;
    }

    public void setErrCode(int errCode) {
        this.errCode = errCode;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public Claims getClaims() {
        return claims;
    }

    public void setClaims(Claims claims) {
        this.claims = claims;
    }

}

package com.java1234.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 订单主表
 * @author java1234_小锋
 * @site www.java1234.com
 * @company 南通小锋网络科技有限公司
 * @create 2022-01-12 10:13
 */
@TableName("t_order")
@Data
public class Order {

    private Integer id; // 编号

    private String orderNo; // 订单号

    private String userId; // openId微信用户ID

    @TableField(select = false)
    private WxUserInfo wxUserInfo; // 微信用户

    private BigDecimal totalPrice; // 总价

    private String address; // 收货地址

    private String consignee; // 收货人

    private String telNumber; // 联系电话

    @JsonSerialize(using=CustomDateTimeSerializer.class)
    private Date createDate; // 订单创建日期

    @JsonSerialize(using=CustomDateTimeSerializer.class)
    private Date payDate; // 订单支付日期

    private Integer status=1; // 订单状态 1 未支付 2 已经支付/待收货 3 退款/退货

    @TableField(select = false,exist = false)
    private OrderDetail[] goods; // 订单商品详情

}

package com.java1234.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.math.BigDecimal;

/**
 * 订单详细表
 * @author java1234_小锋
 * @site www.java1234.com
 * @company 南通小锋网络科技有限公司
 * @create 2022-01-12 10:19
 */
@TableName("t_order_detail")
@Data
public class OrderDetail {

    private Integer id; // 编号

    private Integer mId; // 订单主表Id

    private Integer goodsId; // 商品ID

    private Integer goodsNumber; // 商品购买数量

    private BigDecimal goodsPrice; // 商品单价

    private String goodsName; // 商品名称

    private String goodsPic; // 商品图片

}

/*
SQLyog Ultimate v11.33 (64 bit)
MySQL - 5.7.18-log 
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;

create table `t_order_detail` (
	`id` int (11),
	`mId` int (11),
	`goodsId` int (11),
	`goodsNumber` int (11),
	`goodsPrice` Decimal (10),
	`goodsName` varchar (300),
	`goodsPic` varchar (765)
); 
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('121','82','14','1','2599.00','Xiaomi Civi','9.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('122','83','14','2','2599.00','Xiaomi Civi','9.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('123','97','14','1','2599.00','Xiaomi Civi','9.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('124','98','14','2','2599.00','Xiaomi Civi','9.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('125','99','4','1','3799.00','Xiaomi 11','6.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('126','100','14','1','2599.00','Xiaomi Civi','9.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('127','101','14','1','2599.00','Xiaomi Civi','9.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('128','102','4','1','3799.00','Xiaomi 11','6.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('129','103','14','1','2599.00','Xiaomi Civi','9.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('130','104','14','1','2599.00','Xiaomi Civi','9.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('131','105','14','2','2599.00','Xiaomi Civi','9.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('132','105','4','1','3799.00','Xiaomi 11','6.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('133','105','16','2','1999.00','小米平板5','13.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('134','105','6','1','4499.00','Xiaomi 11 Pro','1.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('135','106','5','1','2299.00','Redmi K40 游戏增强版','11.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('136','106','14','2','2599.00','Xiaomi Civi','9.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('137','107','14','3','2599.00','Xiaomi Civi','9.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('138','107','1','2','10999.00','小米电视大师 82英寸','21.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('139','107','16','1','1999.00','小米平板5','13.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('140','108','14','2','2599.00','Xiaomi Civi','9.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('141','108','16','1','1999.00','小米平板5','13.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('142','108','11','1','2499.00','黑鲨4','7.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('143','109','14','1','2599.00','Xiaomi Civi','9.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('144','110','14','1','2599.00','Xiaomi Civi','9.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('145','111','14','1','2599.00','Xiaomi Civi','9.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('146','112','14','1','2599.00','Xiaomi Civi','9.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('147','113','14','1','2599.00','Xiaomi Civi','9.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('148','114','14','3','2599.00','Xiaomi Civi','9.png');
insert into `t_order_detail` (`id`, `mId`, `goodsId`, `goodsNumber`, `goodsPrice`, `goodsName`, `goodsPic`) values('149','114','9','2','2999.00','Xiaomi 10S','4.png');

/*
SQLyog Ultimate v11.33 (64 bit)
MySQL - 5.7.18-log 
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;

create table `t_order` (
	`id` int (11),
	`orderNo` varchar (300),
	`userId` varchar (600),
	`totalPrice` Decimal (10),
	`address` varchar (900),
	`consignee` varchar (60),
	`telNumber` varchar (60),
	`createDate` datetime ,
	`payDate` datetime ,
	`status` int (11)
); 
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('82','JAVA20220127032849000000201','o30ur5JpAsAUyGBkR0uW4IxvahR8','2599.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-27 15:28:49','2022-01-27 15:29:06','1');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('83','JAVA20220129103913000000494','o30ur5JpAsAUyGBkR0uW4IxvahR8','5198.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-29 10:39:13','2022-01-27 15:29:06','1');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('84','JAVA20220129103913000001494','o30ur5JpAsAUyGBkR0uW4IxvahR8','5198.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-29 10:39:13','2022-01-27 15:29:06','1');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('85','JAVA20220129103913000002494','o30ur5JpAsAUyGBkR0uW4IxvahR8','5198.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-29 10:39:13','2022-01-27 15:29:06','1');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('86','JAVA20220129103913000003494','o30ur5JpAsAUyGBkR0uW4IxvahR8','5198.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-29 10:39:13','2022-01-27 15:29:06','1');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('87','JAVA20220129103913000004494','o30ur5JpAsAUyGBkR0uW4IxvahR8','5198.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-29 10:39:13','2022-01-27 15:29:06','1');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('88','JAVA20220129103913000005494','o30ur5JpAsAUyGBkR0uW4IxvahR8','5198.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-29 10:39:13','2022-01-27 15:29:06','2');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('89','JAVA20220129103913000006494','o30ur5JpAsAUyGBkR0uW4IxvahR8','5198.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-29 10:39:13','2022-01-27 15:29:06','2');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('90','JAVA20220129103913000007494','o30ur5JpAsAUyGBkR0uW4IxvahR8','5198.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-29 10:39:13','2022-01-27 15:29:06','2');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('91','JAVA20220129103913000008494','o30ur5JpAsAUyGBkR0uW4IxvahR8','5198.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-29 10:39:13','2022-01-27 15:29:06','2');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('92','JAVA20220129103913000009494','o30ur5JpAsAUyGBkR0uW4IxvahR8','5198.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-29 10:39:13','2022-01-27 15:29:06','2');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('93','JAVA20220129103913000010494','o30ur5JpAsAUyGBkR0uW4IxvahR8','5198.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-29 10:39:13','2022-01-27 15:29:06','2');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('94','JAVA20220129103913000011494','o30ur5JpAsAUyGBkR0uW4IxvahR8','5198.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-29 10:39:13','2022-01-27 15:29:06','2');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('95','JAVA20220129103913000012494','o30ur5JpAsAUyGBkR0uW4IxvahR8','5198.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-29 10:39:13','2022-01-27 15:29:06','2');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('96','JAVA20220129103913000013494','o30ur5JpAsAUyGBkR0uW4IxvahR8','5198.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-29 10:39:13','2022-01-27 15:29:06','3');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('97','JAVA20220129035805000000052','o30ur5JpAsAUyGBkR0uW4IxvahR8','2599.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-29 15:58:05','2022-01-29 16:12:26','2');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('98','JAVA20220129035946000000595','o30ur5JpAsAUyGBkR0uW4IxvahR8','5198.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-29 15:59:47','2022-01-29 16:14:07','2');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('99','JAVA20220129040547000000824','o30ur5JpAsAUyGBkR0uW4IxvahR8','3799.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-29 16:05:48','2022-01-29 16:20:08','2');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('100','JAVA20220129040836000000654','o30ur5JpAsAUyGBkR0uW4IxvahR8','2599.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-29 16:08:37','2022-01-29 16:12:52','3');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('101','JAVA20220129041124000000758','o30ur5JpAsAUyGBkR0uW4IxvahR8','2599.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-29 16:11:25','2022-01-29 16:11:36','2');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('102','JAVA20220129043412000000133','o30ur5JpAsAUyGBkR0uW4IxvahR8','3799.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-01-29 16:34:12','2022-01-29 16:34:26','2');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('103','JAVA20220217071851000000421','o30ur5JpAsAUyGBkR0uW4IxvahR8','2599.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-02-17 19:18:51',NULL,'1');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('104','JAVA20220217072440000000734','o30ur5JpAsAUyGBkR0uW4IxvahR8','2599.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-02-17 19:24:41',NULL,'4');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('105','JAVA20220217072709000000080','o30ur5JpAsAUyGBkR0uW4IxvahR8','17494.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-02-17 19:27:09',NULL,'3');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('106','JAVA20220221080859000000097','o30ur5JpAsAUyGBkR0uW4IxvahR8','7497.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-02-21 08:08:59','2022-02-21 08:09:24','2');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('107','JAVA20220221082558000000449','o30ur5JpAsAUyGBkR0uW4IxvahR8','31794.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-02-21 08:25:58','2022-02-21 08:26:15','3');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('108','JAVA20220226112352000000844','o30ur5JpAsAUyGBkR0uW4IxvahR8','9696.00','北京市北京市西城区新街口街道楼','咯','458698866','2022-02-26 11:23:53','2022-02-26 11:24:03','2');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('109','JAVA20220226113103000000063','o30ur5JpAsAUyGBkR0uW4IxvahR8','2599.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-02-26 11:31:03',NULL,'1');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('110','JAVA20220226114127000000088','o30ur5JpAsAUyGBkR0uW4IxvahR8','2599.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-02-26 11:41:27','2022-02-26 11:41:43','2');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('111','JAVA20220226120649000000157','o30ur5JpAsAUyGBkR0uW4IxvahR8','2599.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-02-26 12:06:49','2022-02-26 12:07:03','2');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('112','JAVA20220226121701000000063','o30ur5JpAsAUyGBkR0uW4IxvahR8','2599.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-02-26 12:17:01',NULL,'1');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('113','JAVA20220226121703000000888','o30ur5JpAsAUyGBkR0uW4IxvahR8','2599.00','广东省广州市海珠区新港中路397号','张三','020-81167888','2022-02-26 12:17:04','2022-02-26 12:17:18','2');
insert into `t_order` (`id`, `orderNo`, `userId`, `totalPrice`, `address`, `consignee`, `telNumber`, `createDate`, `payDate`, `status`) values('114','JAVA20220226124930000000901','o30ur5JpAsAUyGBkR0uW4IxvahR8','13795.00','江苏省南通市通州区万科大都会11栋11-11室','小锋','18862857105','2022-02-26 12:49:31','2022-02-26 12:49:43','2');

package com.java1234.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 字符串工具类
 * @author 
 *
 */
public class StringUtil {

	/**
	 * 判断是否是空
	 * @param str
	 * @return
	 */
	public static boolean isEmpty(String str){
		if(str==null||"".equals(str.trim())){
			return true;
		}else{
			return false;
		}
	}
	
	/**
	 * 判断是否不是空
	 * @param str
	 * @return
	 */
	public static boolean isNotEmpty(String str){
		if((str!=null)&&!"".equals(str.trim())){
			return true;
		}else{
			return false;
		}
	}
	
	/**
	 * 格式化模糊查询
	 * @param str
	 * @return
	 */
	public static String formatLike(String str){
		if(isNotEmpty(str)){
			return "%"+str+"%";
		}else{
			return null;
		}
	}
	
	/**
	 * 过滤掉集合里的空格
	 * @param list
	 * @return
	 */
	public static List<String> filterWhite(List<String> list){
		List<String> resultList=new ArrayList<String>();
		for(String l:list){
			if(isNotEmpty(l)){
				resultList.add(l);
			}
		}
		return resultList;
	}
	
	/**
	 * 去除html标签
	 */
	public static String stripHtml(String content) { 
	    // <p>段落替换为换行 
	    content = content.replaceAll("<p .*?>", "\r\n"); 
	    // <br><br/>替换为换行 
	    content = content.replaceAll("<br\\s*/?>", "\r\n"); 
	    // 去掉其它的<>之间的东西 
	    content = content.replaceAll("\\<.*?>", ""); 
	    // 去掉空格 
	    content = content.replaceAll(" ", ""); 
	    return content;   
	}
	
	/**
	 * 生成六位随机数
	 * @return
	 */
	public static String genSixRandomNum(){
		Random random = new Random();
		String result="";
		for (int i=0;i<6;i++)
		{
			result+=random.nextInt(10);
		}
		return result;
	}

	/**
	 * 生成由[A-Z,0-9]生成的随机字符串
	 * @param length  欲生成的字符串长度
	 * @return
	 */
	public static String getRandomString(int length){
		Random random = new Random();

		StringBuffer sb = new StringBuffer();

		for(int i = 0; i < length; ++i){
			int number = random.nextInt(2);
			long result = 0;

			switch(number){
				case 0:
					result = Math.round(Math.random() * 25 + 65);
					sb.append(String.valueOf((char)result));
					break;
				case 1:

					sb.append(String.valueOf(new Random().nextInt(10)));
					break;
			}
		}
		return sb.toString();
	}


}

package com.java1234.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 日期工具类
 * @author Administrator
 *
 */
public class DateUtil {

	/**
	 * 日期对象转字符串
	 * @param date
	 * @param format
	 * @return
	 */
	public static String formatDate(Date date,String format){
		String result="";
		SimpleDateFormat sdf=new SimpleDateFormat(format);
		if(date!=null){
			result=sdf.format(date);
		}
		return result;
	}
	
	/**
	 * 字符串转日期对象
	 * @param str
	 * @param format
	 * @return
	 * @throws Exception
	 */
	public static Date formatString(String str,String format) throws Exception{
		if(StringUtil.isEmpty(str)){
			return null;
		}
		SimpleDateFormat sdf=new SimpleDateFormat(format);
		return sdf.parse(str);
	}
	
	public static String getCurrentDateStr(){
		Date date=new Date();
		SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddhhmmssSSSSSSSSS");
		return sdf.format(date);
	}
	
	public static String getCurrentDatePath()throws Exception{
		Date date=new Date();
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd/");
		return sdf.format(date);
	}
	
	public static void main(String[] args) {
		try {
			System.out.println(getCurrentDateStr());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

package com.java1234.constant;

/**
 * 系统级静态变量
 * @author java1234_小锋
 * @site www.java1234.com
 * @company Java知识分享网
 * @create 2019-08-13 上午 9:51
 */
public class SystemConstant {

    /**
     * token
     */
    public static final int JWT_ERRCODE_NULL = 4000;			//Token不存在
    public static final int JWT_ERRCODE_EXPIRE = 4001;			//Token过期
    public static final int JWT_ERRCODE_FAIL = 4002;			//验证不通过

    /**
     * JWT
     */
    public static final String JWT_SECERT = "8677df7fc3a34e26a61c034d5ec8245d";			//密匙
    public static final long JWT_TTL = 24*60 * 60 * 1000;									//token有效时间
}

package com.java1234.util;

import com.java1234.constant.SystemConstant;
import com.java1234.entity.CheckResult;
import io.jsonwebtoken.*;
import org.bouncycastle.util.encoders.Base64;

import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.util.Date;

/**
 * jwt加密和解密的工具类
 * @author java1234_小锋
 * @site www.java1234.com
 * @company Java知识分享网
 * @create 2019-08-13 上午 10:06
 */
public class JwtUtils {

    /**
     * 签发JWT
     * @param id
     * @param subject 可以是JSON数据 尽可能少
     * @param ttlMillis
     * @return
     */
    public static String createJWT(String id, String subject, long ttlMillis) {
        SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
        long nowMillis = System.currentTimeMillis();
        Date now = new Date(nowMillis);
        SecretKey secretKey = generalKey();
        JwtBuilder builder = Jwts.builder()
                .setId(id)
                .setSubject(subject)   // 主题
                .setIssuer("Java1234")     // 签发者
                .setIssuedAt(now)      // 签发时间
                .signWith(signatureAlgorithm, secretKey); // 签名算法以及密匙
        if (ttlMillis >= 0) {
            long expMillis = nowMillis + ttlMillis;
            Date expDate = new Date(expMillis);
            builder.setExpiration(expDate); // 过期时间
        }
        return builder.compact();
    }

    /**
     * 验证JWT
     * @param jwtStr
     * @return
     */
    public static CheckResult validateJWT(String jwtStr) {
        CheckResult checkResult = new CheckResult();
        Claims claims = null;
        try {
            claims = parseJWT(jwtStr);
            checkResult.setSuccess(true);
            checkResult.setClaims(claims);
        } catch (ExpiredJwtException e) {
            checkResult.setErrCode(SystemConstant.JWT_ERRCODE_EXPIRE);
            checkResult.setSuccess(false);
        } catch (SignatureException e) {
            checkResult.setErrCode(SystemConstant.JWT_ERRCODE_FAIL);
            checkResult.setSuccess(false);
        } catch (Exception e) {
            checkResult.setErrCode(SystemConstant.JWT_ERRCODE_FAIL);
            checkResult.setSuccess(false);
        }
        return checkResult;
    }

    /**
     * 生成加密Key
     * @return
     */
    public static SecretKey generalKey() {
        byte[] encodedKey = Base64.decode(SystemConstant.JWT_SECERT);
        SecretKey key = new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES");
        return key;
    }


    /**
     * 解析JWT字符串
     * @param jwt
     * @return
     * @throws Exception
     */
    public static Claims parseJWT(String jwt) throws Exception {
        SecretKey secretKey = generalKey();
        return Jwts.parser()
                .setSigningKey(secretKey)
                .parseClaimsJws(jwt)
                .getBody();
    }

    public static void main(String[] args) throws InterruptedException {
        //小明失效 10s
        String sc = createJWT("1","小明", 60 * 60 * 1000);
        System.out.println(sc);
        System.out.println(validateJWT(sc).getErrCode());
        System.out.println(validateJWT(sc).getClaims().getId());
        System.out.println(validateJWT(sc).getClaims().getSubject());
        //Thread.sleep(3000);
        System.out.println(validateJWT(sc).getClaims());
        Claims claims = validateJWT(sc).getClaims();
        String sc2 = createJWT(claims.getId(),claims.getSubject(), SystemConstant.JWT_TTL);
        System.out.println(sc2);
    }

}

package com.java1234.util;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.DefaultHostnameVerifier;
import org.apache.http.conn.util.PublicSuffixMatcher;
import org.apache.http.conn.util.PublicSuffixMatcherLoader;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Component;

import java.io.*;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * httpClient 工具类
 * @author java1234_小锋
 * @site www.java1234.com
 * @company Java知识分享网
 * @create 2019-02-10 下午 2:49
 */
@Component
public class HttpClientUtil {
	
	/**
	 * 默认参数设置
	 * setConnectTimeout:设置连接超时时间,单位毫秒。
	 * setConnectionRequestTimeout:设置从connect Manager获取Connection 超时时间,单位毫秒。
	 * setSocketTimeout:请求获取数据的超时时间,单位毫秒。访问一个接口,多少时间内无法返回数据,就直接放弃此次调用。 暂时定义15分钟
	 */
	private RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(600000).setConnectTimeout(600000).setConnectionRequestTimeout(600000).build();
	
	/**
	 * 静态内部类---作用:单例产生类的实例
	 * @author Administrator
	 *
	 */
	private static class LazyHolder {    
       private static final HttpClientUtil INSTANCE = new HttpClientUtil();    
       
    }  
	private HttpClientUtil(){}
	public static HttpClientUtil getInstance(){
		return LazyHolder.INSTANCE;    
	}
	
	/**
	 * 发送 post请求
	 * @param httpUrl 地址
	 */
	public String sendHttpPost(String httpUrl) {
		HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost  
		return sendHttpPost(httpPost);
	}
	
	/**
	 * 发送 post请求
	 * @param httpUrl 地址
	 * @param params 参数(格式:key1=value1&key2=value2)
	 */
	public String sendHttpPost(String httpUrl, String params) {
		HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost  
		try {
			//设置参数
			StringEntity stringEntity = new StringEntity(params, "UTF-8");
			stringEntity.setContentType("application/x-www-form-urlencoded");
			httpPost.setEntity(stringEntity);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sendHttpPost(httpPost);
	}
	
	/**
	 * 发送 post请求
	 * @param httpUrl 地址
	 * @param maps 参数
	 */
	public String sendHttpPost(String httpUrl, Map<String, String> maps) {
		HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost  
		// 创建参数队列  
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		for (String key : maps.keySet()) {
			nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));
		}
		try {
			httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sendHttpPost(httpPost);
	}
	
	/**
	 * 发送Post请求
	 * @param httpPost
	 * @return
	 */
	private String sendHttpPost(HttpPost httpPost) {
		CloseableHttpClient httpClient = null;
		CloseableHttpResponse response = null;
		HttpEntity entity = null;
		String responseContent = null;
		try {
			// 创建默认的httpClient实例
			httpClient = HttpClients.createDefault();
			httpPost.setConfig(requestConfig);
			// 执行请求
			long execStart = System.currentTimeMillis();
			response = httpClient.execute(httpPost);
			long execEnd = System.currentTimeMillis();
			System.out.println("=================执行post请求耗时:"+(execEnd-execStart)+"ms");
			long getStart = System.currentTimeMillis();
			entity = response.getEntity();
			responseContent = EntityUtils.toString(entity, "UTF-8");
			long getEnd = System.currentTimeMillis();
			System.out.println("=================获取响应结果耗时:"+(getEnd-getStart)+"ms");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				// 关闭连接,释放资源
				if (response != null) {
					response.close();
				}
				if (httpClient != null) {
					httpClient.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return responseContent;
	}

	/**
	 * 发送 get请求
	 * @param httpUrl
	 */
	public String sendHttpGet(String httpUrl) {
		HttpGet httpGet = new HttpGet(httpUrl);// 创建get请求
		return sendHttpGet(httpGet);
	}
	
	/**
	 * 发送 get请求Https
	 * @param httpUrl
	 */
	public String sendHttpsGet(String httpUrl) {
		HttpGet httpGet = new HttpGet(httpUrl);// 创建get请求
		return sendHttpsGet(httpGet);
	}
	
	/**
	 * 发送Get请求
	 * @param httpGet
	 * @return
	 */
	private String sendHttpGet(HttpGet httpGet) {
		CloseableHttpClient httpClient = null;
		CloseableHttpResponse response = null;
		HttpEntity entity = null;
		String responseContent = null;
		try {
			// 创建默认的httpClient实例.

			
			httpClient = HttpClients.createDefault();

			httpGet.setConfig(requestConfig);
			// 执行请求
			response = httpClient.execute(httpGet);
			entity = response.getEntity();
			responseContent = EntityUtils.toString(entity, "UTF-8");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				// 关闭连接,释放资源
				if (response != null) {
					response.close();
				}
				if (httpClient != null) {
					httpClient.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return responseContent;
	}
	
	/**
	 * 发送Get请求Https
	 * @param httpGet
	 * @return
	 */
	private String sendHttpsGet(HttpGet httpGet) {
		CloseableHttpClient httpClient = null;
		CloseableHttpResponse response = null;
		HttpEntity entity = null;
		String responseContent = null;
		try {
			// 创建默认的httpClient实例.
			PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader.load(new URL(httpGet.getURI().toString()));
			DefaultHostnameVerifier hostnameVerifier = new DefaultHostnameVerifier(publicSuffixMatcher);
			httpClient = HttpClients.custom().setSSLHostnameVerifier(hostnameVerifier).build();
			httpGet.setConfig(requestConfig);
			// 执行请求
			response = httpClient.execute(httpGet);
			entity = response.getEntity();
			responseContent = EntityUtils.toString(entity, "UTF-8");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				// 关闭连接,释放资源
				if (response != null) {
					response.close();
				}
				if (httpClient != null) {
					httpClient.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return responseContent;
	}

	/**
	 * 发送xml数据
	 * @param url
	 * @param xmlData
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static HttpResponse sendXMLDataByPost(String url, String xmlData)
			throws ClientProtocolException, IOException {
		HttpClient httpClient = HttpClients.createDefault();
		HttpPost httppost = new HttpPost(url);
		StringEntity entity = new StringEntity(xmlData);
		httppost.setEntity(entity);
		httppost.setHeader("Content-Type", "text/xml;charset=UTF-8");
		HttpResponse response = httpClient.execute(httppost);
		return response;
	}

	/**
	 * 获得响应HTTP实体内容
	 *
	 * @param response
	 * @return
	 * @throws IOException
	 * @throws UnsupportedEncodingException
	 */
	public static String getHttpEntityContent(HttpResponse response) throws IOException, UnsupportedEncodingException {
		HttpEntity entity = response.getEntity();
		if (entity != null) {
			InputStream is = entity.getContent();
			BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
			String line = br.readLine();
			StringBuilder sb = new StringBuilder();
			while (line != null) {
				sb.append(line + "\n");
				line = br.readLine();
			}
			return sb.toString();
		}
		return "";
	}


}

package com.java1234.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.java1234.entity.BigType;
import com.java1234.entity.WxUserInfo;

/**
 * 微信用户Mapper接口
 * @author java1234_小锋
 * @site www.java1234.com
 * @company 南通小锋网络科技有限公司
 * @create 2022-02-23 22:00
 */
public interface WxUserInfoMapper extends BaseMapper<WxUserInfo> {
}

package com.java1234.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.java1234.entity.Order;

/**
 * 订单Mapper接口
 * @author java1234_小锋
 * @site www.java1234.com
 * @company 南通小锋网络科技有限公司
 * @create 2022-02-23 22:00
 */
public interface OrderMapper extends BaseMapper<Order> {
}

package com.java1234.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.java1234.entity.OrderDetail;

/**
 * 订单详情Mapper接口
 * @author java1234_小锋
 * @site www.java1234.com
 * @company 南通小锋网络科技有限公司
 * @create 2022-02-23 22:00
 */
public interface OrderDetailMapper extends BaseMapper<OrderDetail> {
}

package com.java1234.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.java1234.entity.WxUserInfo;

/**
 * 微信用户Service接口
 * @author java1234_小锋
 * @site www.java1234.com
 * @company 南通小锋网络科技有限公司
 * @create 2022-02-23 22:01
 */
public interface IWxUserInfoService extends IService<WxUserInfo> {
}

package com.java1234.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.java1234.entity.Order;

/**
 * 订单Service接口
 * @author java1234_小锋
 * @site www.java1234.com
 * @company 南通小锋网络科技有限公司
 * @create 2022-02-23 22:01
 */
public interface IOrderService extends IService<Order> {
}

package com.java1234.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.java1234.entity.OrderDetail;

/**
 * 订单详情Service接口
 * @author java1234_小锋
 * @site www.java1234.com
 * @company 南通小锋网络科技有限公司
 * @create 2022-02-23 22:01
 */
public interface IOrderDetailService extends IService<OrderDetail> {
}

package com.java1234.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.java1234.entity.OrderDetail;
import com.java1234.mapper.OrderDetailMapper;
import com.java1234.service.IOrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 订单详情Service实现类
 * @author java1234_小锋
 * @site www.java1234.com
 * @company 南通小锋网络科技有限公司
 * @create 2022-02-23 22:02
 */
@Service("orderDetailService")
public class IOrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper,OrderDetail> implements IOrderDetailService {

    @Autowired
    private OrderDetailMapper orderDetailMapper;
}

package com.java1234.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.java1234.entity.Order;
import com.java1234.mapper.OrderMapper;
import com.java1234.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 订单Service实现类
 * @author java1234_小锋
 * @site www.java1234.com
 * @company 南通小锋网络科技有限公司
 * @create 2022-02-23 22:02
 */
@Service("orderService")
public class IOrderServiceImpl extends ServiceImpl<OrderMapper,Order> implements IOrderService {

    @Autowired
    private OrderMapper orderMapper;
}

package com.java1234.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.java1234.entity.WxUserInfo;
import com.java1234.mapper.WxUserInfoMapper;
import com.java1234.service.IWxUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 微信用户Service实现类
 * @author java1234_小锋
 * @site www.java1234.com
 * @company 南通小锋网络科技有限公司
 * @create 2022-02-23 22:02
 */
@Service("wxUserInfoService")
public class IWxUserInfoServiceImpl extends ServiceImpl<WxUserInfoMapper,WxUserInfo> implements IWxUserInfoService {

    @Autowired
    private WxUserInfoMapper wxUserInfoMapper;
}

package com.java1234.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.java1234.constant.SystemConstant;
import com.java1234.entity.R;
import com.java1234.entity.WxUserInfo;
import com.java1234.properties.WeixinProperties;
import com.java1234.service.IWxUserInfoService;
import com.java1234.util.HttpClientUtil;
import com.java1234.util.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
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;
import java.util.HashMap;
import java.util.Map;

/**
 * 微信用户Controller
 * @author java1234_小锋
 * @site www.java1234.com
 * @company 南通小锋网络科技有限公司
 * @create 2022-04-02 9:12
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private WeixinProperties weixinProperties;

    @Autowired
    private HttpClientUtil httpClientUtil;

    @Autowired
    private IWxUserInfoService wxUserInfoService;


    /**
     * 微信用户登录
     * @return
     */
    @RequestMapping("/wxlogin")
    public R wxLogin(@RequestBody WxUserInfo wxUserInfo){
        System.out.println(wxUserInfo.getCode());
        String jscode2sessionUrl=weixinProperties.getJscode2sessionUrl()+"?appid="+weixinProperties.getAppid()+"&secret="+weixinProperties.getSecret()+"&js_code="+wxUserInfo.getCode()+"&grant_type=authorization_code";
        System.out.println(jscode2sessionUrl);
        String result = httpClientUtil.sendHttpGet(jscode2sessionUrl);
        System.out.println(result);
        JSONObject jsonObject= JSON.parseObject(result);
        String openid = jsonObject.get("openid").toString();
        System.out.println(openid);
        // 插入用户到数据库  假如说 用户不存在 我们插入用户  如果用户存在 我们更新用户
        WxUserInfo resultWxUserInfo = wxUserInfoService.getOne(new QueryWrapper<WxUserInfo>().eq("openid", openid));
        if(resultWxUserInfo==null){
            System.out.println("不存在 插入用户");
            wxUserInfo.setOpenid(openid);
            wxUserInfo.setRegisterDate(new Date());
            wxUserInfo.setLastLoginDate(new Date());
            wxUserInfoService.save(wxUserInfo);
        }else{
            System.out.println("存在 更新用户");
            resultWxUserInfo.setNickName(wxUserInfo.getNickName());
            resultWxUserInfo.setAvatarUrl(wxUserInfo.getAvatarUrl());
            resultWxUserInfo.setLastLoginDate(new Date());
            wxUserInfoService.updateById(resultWxUserInfo);
        }
        // 利用jwt生成token返回到前端
        String token = JwtUtils.createJWT(openid, wxUserInfo.getNickName(), SystemConstant.JWT_TTL);
        Map<String,Object> resultMap=new HashMap<>();
        resultMap.put("token",token);
        return R.ok(resultMap);
    }
}

package com.java1234.controller;

import com.java1234.constant.SystemConstant;
import com.java1234.entity.Order;
import com.java1234.entity.OrderDetail;
import com.java1234.entity.R;
import com.java1234.service.IOrderDetailService;
import com.java1234.service.IOrderService;
import com.java1234.util.DateUtil;
import com.java1234.util.JwtUtils;
import io.jsonwebtoken.Claims;
import javafx.scene.input.TouchEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 订单Controller控制器
 * @author java1234_小锋
 * @site www.java1234.com
 * @company 南通小锋网络科技有限公司
 * @create 2022-04-05 9:26
 */
@RestController
@RequestMapping("/my/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @Autowired
    private IOrderDetailService orderDetailService;

    /**
     * 创建订单,返回订单号
     * @param token
     * @return
     */
    @RequestMapping("/create")
    @Transactional
    public R create(@RequestBody Order order, @RequestHeader(value = "token")String token){
        // 通过token获取openid
        System.out.println("token="+token);
        System.out.println("order="+order);
        // 添加订单到数据库
        Claims claims = JwtUtils.validateJWT(token).getClaims();
        if(claims!=null){
            System.out.println("openid="+claims.getId());
            order.setUserId(claims.getId());
        }
        order.setOrderNo("JAVA"+DateUtil.getCurrentDateStr());
        order.setCreateDate(new Date());

        OrderDetail[] goods = order.getGoods();
        orderService.save(order);
        // 添加订单详情到数据库
        for(int i=0;i<goods.length;i++){
            OrderDetail orderDetail=goods[i];
            orderDetail.setMId(order.getId());
            orderDetailService.save(orderDetail);
        }
        Map<String,Object> resultMap=new HashMap<>();
        resultMap.put("orderNo",order.getOrderNo());
        return R.ok(resultMap);
    }
}

requestUtil.js封装 对于/my/请求,header里面加token

//定义请求根路径baseUrl
const baseUrl="http://localhost:8080";

//同时发送异步代码的次数
let ajaxTimes=0;

/**
 * 返回请求根路径baseUrl
 */
export const getBaseUrl=()=>{
    return baseUrl;
}

/**
 * wx login 封装
 * @param {*} params 
 */
export const getWxLogin=()=>{
    return new Promise((resolve,reject)=>{
        wx.login({
         timeout: 5000,
          success: (res) => {
            resolve(res)
          },
          fail:(err)=>{
              reject(err)
          }
        })
    });
}

/**
 * promise形式的 小程序微信支付
 * 
 */
export const requestPay=(pay)=>{
    return new Promise((resolve,reject)=>{
        wx.requestPayment({
          ...pay,
          success:(res)=>{
              resolve(res)
          },
          fail:(err)=>{
              reject(err)
          }
        })
    });
}
/**
 * wx getUserProfile封装
 * @param {*} params 
 */
export const getUserProfile=()=>{
        return new Promise((resolve,reject)=>{
            wx.getUserProfile({
              desc: '获取用户信息',
              success:(res)=>{
                  resolve(res)
              },
              fail:(err)=>{
                  reject(err)
              }
            })
        });
}

/**
 * 后端请求工具类
 * @param {*} params 
 */
export const requestUtil=(params)=>{

    var start=new Date().getTime();
    console.log("ajaxTimes="+ajaxTimes)
    
    ajaxTimes++;

    //显示加载效果
    wx.showLoading({
      title: '加载中',
      mask:true
    })
    //模拟网络延迟加载
    while(true) if(new Date().getTime()-start > 1 * 100)break;

    return new Promise((resolve,reject)=>{
        wx.request({
          ...params,
          url:baseUrl+params.url,
          success:(result)=>{
              resolve(result.data)
          },
          fail:(err)=>{
              reject(err)
          },
          complete:()=>{
              ajaxTimes--;
              if(ajaxTimes==0){
                  //关闭正在等待的图标
                  wx.hideLoading();
              }
          }
        })
    });
}

//定义请求根路径baseUrl
const baseUrl="http://localhost:8080";

//同时发送异步代码的次数
let ajaxTimes=0;

/**
 * 返回请求根路径baseUrl
 */
export const getBaseUrl=()=>{
    return baseUrl;
}

/**
 * wx login 封装
 * @param {*} params 
 */
export const getWxLogin=()=>{
    return new Promise((resolve,reject)=>{
        wx.login({
         timeout: 5000,
          success: (res) => {
            resolve(res)
          },
          fail:(err)=>{
              reject(err)
          }
        })
    });
}

/**
 * promise形式的 小程序微信支付
 * 
 */
export const requestPay=(pay)=>{
    return new Promise((resolve,reject)=>{
        wx.requestPayment({
          ...pay,
          success:(res)=>{
              resolve(res)
          },
          fail:(err)=>{
              reject(err)
          }
        })
    });
}
/**
 * wx getUserProfile封装
 * @param {*} params 
 */
export const getUserProfile=()=>{
        return new Promise((resolve,reject)=>{
            wx.getUserProfile({
              desc: '获取用户信息',
              success:(res)=>{
                  resolve(res)
              },
              fail:(err)=>{
                  reject(err)
              }
            })
        });
}

/**
 * 后端请求工具类
 * @param {*} params 
 */
export const requestUtil=(params)=>{

    var start=new Date().getTime();
    console.log("ajaxTimes="+ajaxTimes)
    
    ajaxTimes++;

    //显示加载效果
    wx.showLoading({
      title: '加载中',
      mask:true
    })
    //模拟网络延迟加载
    while(true) if(new Date().getTime()-start > 1 * 100)break;

    return new Promise((resolve,reject)=>{
        wx.request({
          ...params,
          header,
          url:baseUrl+params.url,
          success:(result)=>{
              resolve(result.data)
          },
          fail:(err)=>{
              reject(err)
          },
          complete:()=>{
              ajaxTimes--;
              if(ajaxTimes==0){
                  //关闭正在等待的图标
                  wx.hideLoading();
              }
          }
        })
    });
}

在这里插入图片描述
前端


  /**
   * 创建订单
   */
  async createOrder(){

    const totalPrice=this.data.totalPrice; // 请求体 总价
    const address=this.data.address.provinceName+this.data.address.cityName+this.data.address.countyName+this.data.address.detailInfo; // 请求体  收货地址
    const consignee=this.data.address.userName; // 请求体 收货人
    const telNumber=this.data.address.telNumber; // 请求体 联系电话
    let goods=[];
    this.data.cart.forEach(v=>goods.push({
      goodsId:v.id,
      goodsNumber:v.num,
      goodsPrice:v.price,
      goodsName:v.name,
      goodsPic:v.proPic
    }))
    const orderParam={
      totalPrice,
      address,
      consignee,
      telNumber,
      goods
    }
    const res=await requestUtil({url:"/my/order/create",method:"POST",data:orderParam})
    console.log(res.orderNo);
  },

后端:(加下事务)

    /**
     * 创建订单,返回订单号
     * @param order
     * @param token
     * @return
     */
    @RequestMapping("/create")
    @Transactional
    public R create(@RequestBody Order order, @RequestHeader(value="token") String token){
        System.out.println("token:"+token);
        // 通过token获取openid
        Claims claims = JwtUtils.validateJWT(token).getClaims();
        if(claims!=null){
            System.out.println("openid="+claims.getId());
            order.setUserId(claims.getId());
        }
        order.setOrderNo("JAVA"+DateUtil.getCurrentDateStr());
        order.setCreateDate(new Date());

        OrderDetail[] goods = order.getGoods();

        // 添加订单到数据库
        orderService.save(order);
        // 添加订单详情到数据库
        for(int i=0;i<goods.length;i++){
            OrderDetail orderDetail=goods[i];
            orderDetail.setMId(order.getId());
            orderDetailService.save(orderDetail);
        }
        Map<String,Object> resultMap=new HashMap<>();
        resultMap.put("orderNo",order.getOrderNo());
        return R.ok(resultMap);
    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1439127.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

登录+JS逆向进阶【过咪咕登录】(附带源码)

JS渗透之咪咕登录 每篇前言&#xff1a;咪咕登录参数对比 captcha参数enpassword参数搜索enpassword参数搜索J_RsaPsd参数setPublic函数encrypt加密函数运行时可能会遇到的问题此部分改写的最终形态JS代码&#xff1a;运行结果python编写脚本运行此JS代码&#xff1a;运行结果&…

Powershell Install 一键部署Openssl+certificate证书创建

前言 Openssl 是一个方便的实用程序,用于创建自签名证书。您可以在所有操作系统(如 Windows、MAC 和 Linux 版本)上使用 OpenSSL。 Windows openssl 下载 前提条件 开启wmi,配置网卡,参考 自签名证书 创建我们自己的根 CA 证书和 CA 私钥(我们自己充当 CA)创建服务器…

2024.2.6

1.现有无序序列数组为23,24,12,5,33,5347&#xff0c;请使用以下排序实现编程 函数1:请使用冒泡排序实现升序排序 函数2:请使用简单选择排序实现升序排序 函数3:请使用快速排序实现升序排序 函数4:请使用插入排序实现升序排序 #include<stdio.h> #include<string.h&g…

详述FlinkSql Join操作

FlinkSql 的 Join Flink 官网将其分为了 Joins 和 Window Joins两个大类&#xff0c;其中里面又分了很多 Join 方式 参考文档&#xff1a; Joins | Apache Flink Window JOIN | Apache Flink Joins 官网介绍共有6种方式&#xff1a; Regular Join&#xff1a;流与流的 Joi…

postman执行批量测试

1.背景 有许多的人常常需要使用第三方系统进行重复的数据查询&#xff0c;本文介绍使用PostMan的方式对数据进行批量的查询&#xff0c;减少重复的劳动。 2.工具下载 3.初入门 一、如图示进行点击&#xff0c;创建collection 二、输入对应的名称 三、创建Request并进行查…

Leetcode3020. 子集中元素的最大数量

Every day a Leetcode 题目来源&#xff1a;3020. 子集中元素的最大数量 解法1&#xff1a;哈希 枚举 用一个哈希表统计数组 nums 中的元素及其出现次数。 暴力枚举数组中的数&#xff0c;作为 x&#xff0c;然后不断看 x2,x4,⋯ 在数组中的个数。直到个数不足 2 个为止&a…

ChatGPT高效提问—prompt常见用法(续篇三)

ChatGPT高效提问—prompt常见用法&#xff08;续篇三&#xff09; 1.1 多选项 ​ 多选项技术为模型提供了一个清晰的问题或任务&#xff0c;并附带一组预先定义的潜在答案。这种方法在生成仅限于特定选项集的文本方面表现出色&#xff0c;适用于问答、文本补全和其他任务。利…

win10系统连接WiFi,输入正确密码,但还是提示错误

情况 电信宽带 mac和小米手机都可以连上wifi dell上的windows输入正确的密码还是提示错误 解决办法 根据路由器上的终端配置进入网页进行配置&#xff0c;我的是192.168.1.1&#xff0c;账户:useradmin 修改无线网络设置中的加密方式&#xff0c;由Mixed WPA2/WPA-PSK改为W…

【社交电商】带直播电商功能,可以DIY前端,可以H5和小程序一般商城常用功能齐全

第一次接触这个系统&#xff0c;感觉和微擎有点像。也是一个主体&#xff0c;也很多插件的那种。 测试了下。安装成功了&#xff0c;站长亲测没有问题&#xff0c;一切都挺完善的&#xff0c;不过系统比较庞大&#xff0c;可能新手熟悉起来要一定的过程。 站长整理了一份简要…

WordPress突然后台无法管理问题

登录WordPress后台管理评论&#xff0c;发现点击编辑、回复均无反应。 尝试清除缓存、关闭CF连接均无效。 查看插件时发现关闭wp-china-yes插件可以解决问题。 后来又测试了下发现加速管理后台这项&#xff0c;在启用时会发生点击无效问题&#xff0c;禁用就好了&#xff0c;不…

Airtest实现在手机界面快速批量采集数据

Airtest实现在手机界面快速批量采集数据 一、问题 Airtest使用的poco方法比较慢,寻找差不多一周,看完这篇文章能节省一周时间,希望帮到大家。二、解决思路 使用Airtest图像识别,这样就会速度上提升效率。 三、解决办法 使用页面规律,要找到每条数据的附近规律(一般是图…

简单说网络:TCP+UDP

TCP和UPD: (1)都工作在传输层 (2)目的都是在程序之中传输数据 (3)数据可以是文本、视频或者图片(对TCP和UDP来说都是一堆二进制数没有太大区别) 一、区别:一个基于连接一个基于非连接 将人与人之间的通信比喻为进程和进程之前的通信:基本上有两种方式(1)写信;(2)打电话;这…

【数据结构】链表OJ面试题2《分割小于x并排序链表、回文结构、相交链表》+解析

1.前言 前五题在这http://t.csdnimg.cn/UeggB 休息一天&#xff0c;今天继续刷题&#xff01; 2.OJ题目训练 1. 编写代码&#xff0c;以给定值x为基准将链表分割成两部分&#xff0c;所有小于x的结点排在大于或等于x的结点之前 。链表分割_牛客题霸_牛客网 思路 既然涉及…

naiveui 上传图片遇到的坑 Upload

我在开发图片上传功能, 需要手动触发上传 但是我调用它内部自定义submit方法, 结果接口一直在报错400 我反反复复的测试了好就, 确定了就是我前端的问题,因为之前一直在做后端的错误排查, 以为是编译问题(因为之前也出现过这个问题) 好 , 我把其中一个参数类型改为String类型, …

NC6X单点登录设计文档说明

前言 因为业务场景需要&#xff0c;第三方系统有些工作需要经常到NC系统里做&#xff0c;如果每次去NC系统做业务单据&#xff0c;都需要反复登录&#xff0c;导致客户使用体验不是很好&#xff0c;所以需要开发实现从第三方系统单点登录到NC系统&#xff0c;提高客户满意度。 …

电力负荷预测 | 基于GRU门控循环单元的深度学习电力负荷预测,含预测未来(Python)

文章目录 效果一览文章概述源码设计参考资料效果一览 文章概述 电力负荷预测 | 基于GRU门控循环单元的深度学习电力负荷预测,含预测未来(Python&

开源!免费!Hugging Face推出GPT商城

Hugging Face发布开源AI助手制造工具&#xff0c;与OpenAI的定制GPT形成竞争 Hugging Face今年1月31日推出一款开源AI代码库——Hugging Chat Assistants&#xff0c;允许用户轻松创建特定功能的定制AI聊天机器人。 不同于OpenAI的ChatGPT商城需要每月20美金成为会员才能使用…

VBA技术资料MF116:测试操作系统是否为64位

我给VBA的定义&#xff1a;VBA是个人小型自动化处理的有效工具。利用好了&#xff0c;可以大大提高自己的工作效率&#xff0c;而且可以提高数据的准确度。我的教程一共九套&#xff0c;分为初级、中级、高级三大部分。是对VBA的系统讲解&#xff0c;从简单的入门&#xff0c;到…

OLED调试简介

文章目录 一、介绍调试方法介绍OLED简介硬件电路OLED驱动函数 二、操作连接线路使用驱动函数显示内容 OLED.c的内容 一、介绍 调试方法介绍 OLED简介 硬件电路 OLED驱动函数 二、操作 连接线路 因为这两个引脚不做配置是浮空状态&#xff0c;在这里直接用电源给OLED供电 使…

第三模块 面向对象网络并发编程

第三模块 面向对象&网络&并发编程 面向对象基础1. 初识面向对象1.1 对象和self1.2 常见成员1.3 应用示例 2. 三大特性2.1 封装2.2 继承练习题2.3 多态 3. 扩展&#xff1a;再看数据类型总结作业 从今天开始&#xff0c;我们将进入系列课程第3个模块的的学习&#xff0c…