diff --git a/pom.xml b/pom.xml
index 215778af1a841a8974636ebfcbaa9f0f16803c35..c59a31ca94cfef3e7881a8dcda938574062ebe00 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,6 +17,14 @@
17
+
+ com.alipay.sdk
+ alipay-easysdk
+ 2.2.3
+
+
+
+
org.springframework.boot
spring-boot-starter-data-redis
diff --git a/src/main/java/com/online/edu/config/AlipayConfig.java b/src/main/java/com/online/edu/config/AlipayConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..41537a4a253c8d8fa3729f050eecf7ca63d430c6
--- /dev/null
+++ b/src/main/java/com/online/edu/config/AlipayConfig.java
@@ -0,0 +1,36 @@
+package com.online.edu.config;
+
+import com.alipay.easysdk.factory.Factory;
+import com.alipay.easysdk.kernel.Config;
+import org.springframework.stereotype.Component;
+
+@Component
+public class AlipayConfig {
+ static {
+ Factory.setOptions(getOptions());
+ }
+
+ private static Config getOptions() {
+ Config config = new Config();
+
+ config.protocol = "https";
+
+ // 沙箱环境修改为 openapi.alipaydev.com
+ config.gatewayHost = "openapi-sandbox.dl.alipaydev.com";
+
+ config.signType = "RSA2";
+
+ config.appId = "9021000122682309";
+
+ // 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
+ config.merchantPrivateKey ="MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCZnas0p9C7kXBonkSJTNK5e5rECUQHS3s1YnAUbxaxEKQ/k6vSShNYKhum2N5jXKc4sxFpwqRWrnmT9/a9/cc+pB7XCOZ2dJR7r6pFGCKpbi7bz+/eAVi2J+Zr+2a5fXcbuStYnkFBUPw5ad+UoGtnl/38VEiBHaY57catW3x5GTNiEwmDBXUga6GBrEcTdxhuYX5oe7URR0V4qXC5nKTw+iuyDik5Yqp+4UpXbDv1NEyxRDge1KEtr7YgIe8lF1K9sK3TKeuyQRueMx/I/sddliXpFa+7BlUqDBVhzcyQYYei5eo6k/OkR0GdDMS0bFoJlgIB/4Y1QrlBi62JFlWdAgMBAAECggEBAIOi+PNGWzhgiVMdTN3bVzhbE2SqDAG0TQCSOjlIeMmC2T0h7jtl/u2uJ8PyU6AR5bpQuLtIcEtXeBe0hVyJ/BNR0Ju0pMkdXaAgCGjtJcbLBJyYs5Qq0zpFNs+Rv5V0Tn0TUHHAK2stWvZYI5/ZWDCNrrhsATWjkq5Rc89adm/ONKy8INzggGlr7EoNL9tjP9Vg39MxBfvFP8HC+MFlNOEw+OCxmyaFk9djTFcPTD3tVBkyKZcCjhhSREZrlUstWfGUXhyuMNoJZ38kKJoyCrug7p+U50mNYeLXRl9OoBU+F2IwsUa72VqKN0rcudVcFKNQt79h+IVKldjndSwA1oECgYEAyeZzuiyKc/gA5o8ShdOv08e7g/t5LciXBEaMb4mhACV3zq6SNfFtv4V+8xYpVUNqEnDejMAM2Dgb/iUEcKkCN5V8RGooSll0vFH/jdnN46meJUV4OFplwjUrMWSz2lhxbtpyeMbR6fdgJ2OBYqQb4DTmNwsNXh+B43022GWQi0cCgYEAwscbFzXMtBgF+1JSA99FnMoXXhvUdwi/J1hRit4o6E2ZAAO6ZrMFbT+7vdOWeBDHqmUgqSPwmuNXfYVToYkNf1+3L0bRI9ywpnFYSzIF+0V+J7rKzN0a5+yYWgoiQ3MrQxVu1R6oEp4CAcTCEADAmoIZt1hE5rPcbSm4+vnZgfsCgYAWRgQyX8OOc6e1x8blWKsnE/vN3apKsLxoTlgj3e0TFQ8YkA21QcM3w8RzkNhSfbNwAV+r62v/VoFQEklhHGQQOb+R1JxJR4EnXWxx+7tJCGdX+Uf//4kGWdNACboFtogdEKBcTqLNyuqircmSVkR1AaD8JY39+j/cFu48BUhi9QKBgDbvWSCut9GDhQxhJ2iYLFYQWY7dYotAGEnMixMTnY4HdMOgSY51p24sr5LWfnXWpbnVU+TgkhfdTuvEEtZYhUoLgOsAmjP3JouLJE/xB+barr4d3Nzy74fCHyYl/Yvwi58cCGprfxPhJMfC6skArVHmp8IiTyySRfUz80w187bJAoGAbbjYLPjeaP+4ZZt0/Rf7oDRpX69GzbDo5PWGc6A1BbK21/aXoom8yJDZG1DHYX0tLcQ8QwcwcMmLRITg0HQ/1mF5RQcTaYDBurP+uc88a9t683ItTZcWuXBexA32I61o0fbWYqMNBYsC8gQxI6j+npUUe+x5soBQhQb16Vj70r0=";
+
+ //注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
+ config.alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuHXKkCpzlrER7wZqPE3hkqB9fYZ9neEgwldrkqcNg8ds6PGTjkpZJKdWBzz89i19Dfqoa2TffVyC2Rz5lYMoeN3WE/KsfySa4zHsKqzEm08ndO8O46xJb/2VbIxsc9cvRH5GEQiHxzWIAZpBEolZgETQyCBrGlcjMyhjG5+XQ22P2Iye/+6qMwQnnz95E6GnZH9hr6Z/Tcc1+PBNJMhGotJrOfnTYabu0KOHIxE0p4G8vRC5TKXEWHj9MeV49piTR5WO8W6LUBQq7Vn1XZ7+ZDuOdYQ4xQXuMAhxnX6HW17d6eJNn4Ir8g6BFt/0jnXoOT4x19mbXq39IUArg6NcUQIDAQAB";
+
+ //可设置异步通知接收服务地址(可选)
+ config.notifyUrl = "";
+
+ return config;
+ }
+}
diff --git a/src/main/java/com/online/edu/controller/order/CourseElectionController.java b/src/main/java/com/online/edu/controller/order/CourseElectionController.java
index 71242d5743a07b4881fb4dd47d04651b9053414d..02476d400fe8906d5dba59ba14a66b196509038b 100644
--- a/src/main/java/com/online/edu/controller/order/CourseElectionController.java
+++ b/src/main/java/com/online/edu/controller/order/CourseElectionController.java
@@ -3,13 +3,21 @@ package com.online.edu.controller.order;
import com.online.edu.common.CommonResult;
import com.online.edu.entity.order.CourseElection;
+import com.online.edu.entity.order.vo.CourseElectionVO;
import com.online.edu.service.order.CourseElectionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
+import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+
+import static com.online.edu.utils.OrderSerialNumberUtil.getSerialNumber;
+
@Tag(name = "选课控制")
@RestController
@RequestMapping("/course/election")
@@ -21,8 +29,9 @@ public class CourseElectionController {
@Operation(description = "添加选课记录")
@PostMapping("/add")
- public CommonResult addCourse(@RequestBody @Valid CourseElection courseElection) {
+ public CommonResult addCourse(@RequestBody @Valid CourseElectionVO courseElectionvo) {
//TODO:建立VO
+ CourseElection courseElection=new CourseElection(courseElectionvo.getId(),getSerialNumber(),courseElectionvo.getCourseId(),courseElectionvo.getCourseName(),courseElectionvo.getTeacherName(),courseElectionvo.getStudentId(),courseElectionvo.getStudentName(),courseElectionvo.getPrice(), 0,0,new Date(),new Date());
boolean success = courseElectionService.save(courseElection);
if (success) {
return CommonResult.success(courseElection);
@@ -31,6 +40,40 @@ public class CourseElectionController {
}
}
+ /**
+ * 根据id查询选课结果
+ */
+ @GetMapping("/selectbyid")
+ public CommonResult> selectCoursebyid(@RequestBody Long studentid ){
+ List courselist=courseElectionService.getById(studentid);
+ for(CourseElection e:courselist){
+ System.out.println(e);
+ if(e.getStatus() == 0 && e.getPrice().compareTo(BigDecimal.ZERO) != 0 ){
+ courselist.remove(e);
+ }
+ }
+ return CommonResult.success(courselist);
+ }
+
+ /**
+ * 根据课程id查询选课结果
+ */
+
+ @GetMapping("/selectbycourse")
+ public CommonResult> selectCoursebycourse(@RequestBody Long courseid ){
+ List courselist=courseElectionService.getByCourse(courseid);
+ if(courselist.isEmpty()){
+ return CommonResult.error(400,"查询失败");
+ }
+ for(CourseElection e:courselist){
+ if(e.getStatus() == 0 && e.getPrice().compareTo(BigDecimal.ZERO) != 0 ){
+ courselist.remove(e);
+ }
+ }
+ return CommonResult.success(courselist);
+ }
+
+
}
diff --git a/src/main/java/com/online/edu/controller/order/CourseOrderController.java b/src/main/java/com/online/edu/controller/order/CourseOrderController.java
index c3d6a1ae19fdb8e5d92c4b2d1251a61658b6278e..00c461e3a8cc46c1c2681dba03f20bb7f629739c 100644
--- a/src/main/java/com/online/edu/controller/order/CourseOrderController.java
+++ b/src/main/java/com/online/edu/controller/order/CourseOrderController.java
@@ -4,14 +4,19 @@ package com.online.edu.controller.order;
import com.online.edu.common.CommonResult;
import com.online.edu.entity.order.CourseElection;
import com.online.edu.entity.order.CourseOrder;
+import com.online.edu.entity.order.vo.CourseOrderVO;
import com.online.edu.service.order.CourseElectionService;
import com.online.edu.service.order.CourseOrderService;
+import com.online.edu.service.order.impl.AlipayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
+import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
+import java.math.BigDecimal;
+
@Tag(name = "订单控制")
@RestController
@RequestMapping("/course/order")
@@ -24,10 +29,14 @@ public class CourseOrderController {
@Autowired
private CourseOrderService courseOrderService;
+ @Autowired
+ private AlipayService alipayService;
+
@Operation(description = "添加订单")
@PostMapping("/add")
- public CommonResult add(@RequestBody @Valid CourseOrder courseOrder) {
+ public CommonResult add(@RequestBody @Valid CourseOrderVO courseOrderVO) {
//TODO:建立VO
+ CourseOrder courseOrder=new CourseOrder(courseOrderVO.getId(), courseOrderVO.getSerialNumber(), courseOrderVO.getPrice(), courseOrderVO.getAttr());
boolean success = courseOrderService.save(courseOrder);
if (success) {
return CommonResult.success(courseOrder);
@@ -36,6 +45,30 @@ public class CourseOrderController {
}
}
+ /**
+ * 支付
+ */
+
+ @GetMapping("/topay")
+ @ResponseBody
+ public CommonResult toPay(@RequestBody @Valid CourseOrderVO courseOrderVO) throws Exception {
+ String subject=courseOrderVO.getCoursename();
+ String serialNumber=courseOrderVO.getSerialNumber();
+ BigDecimal money=courseOrderVO.getPrice();
+ String form = alipayService.toPay(subject, serialNumber, money);
+ return CommonResult.success(form);
+ }
+
+ /**
+ * 根据订单号查询支付结果
+ */
+
+ @GetMapping("/query")
+ @ResponseBody
+ public Object queryTradeStatus(@NotNull String serialNumber) throws Exception {
+ Object result = alipayService.queryTradeStatus(serialNumber);
+ return result;
+ }
}
diff --git a/src/main/java/com/online/edu/entity/order/CourseElection.java b/src/main/java/com/online/edu/entity/order/CourseElection.java
index 22f6d6fa5edb712fa8e4ab3be77cf7a8c77ad45d..a616b57ec3c018ec914e54f3c3e33bbb6e7c2e97 100644
--- a/src/main/java/com/online/edu/entity/order/CourseElection.java
+++ b/src/main/java/com/online/edu/entity/order/CourseElection.java
@@ -64,4 +64,19 @@ public class CourseElection implements Serializable {
* 更新时间
*/
private Date updatedAt;
+
+ public CourseElection(Long id,String serialNumber,Long courseId,String courseName,String teacherName,Long studentId,String studentName,BigDecimal price,Integer status,Integer isDeleted,Date createdAt,Date updatedAt){
+ this.id=id;
+ this.serialNumber=serialNumber;
+ this.courseId=courseId;
+ this.courseName=courseName;
+ this.teacherName=teacherName;
+ this.studentId=studentId;
+ this.studentName=studentName;
+ this.price=price;
+ this.status=status;
+ this.isDeleted=isDeleted;
+ this.createdAt=createdAt;
+ this.updatedAt=updatedAt;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/online/edu/entity/order/CourseOrder.java b/src/main/java/com/online/edu/entity/order/CourseOrder.java
index feaeb4d8ded3c64e90d4a67683cbc36b026d44c8..47bd901763c5e3d26a9b63b5ead8b5936a2a6324 100644
--- a/src/main/java/com/online/edu/entity/order/CourseOrder.java
+++ b/src/main/java/com/online/edu/entity/order/CourseOrder.java
@@ -54,4 +54,16 @@ public class CourseOrder implements Serializable {
* 更新时间
*/
private Date updatedAt;
+ public CourseOrder(Long id, String serialNumber, BigDecimal price, String attr){
+ this.id=id;
+ this.serialNumber=serialNumber;
+ this.payedat=new Date();
+ this.price=price;
+ this.transactionId="";
+ this.tradeState="Not_Finished";
+ this.attr=attr;
+ this.isDeleted=0;
+ this.createdAt=new Date();
+ this.updatedAt=new Date();
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/online/edu/entity/order/vo/CourseElectionVO.java b/src/main/java/com/online/edu/entity/order/vo/CourseElectionVO.java
new file mode 100644
index 0000000000000000000000000000000000000000..030836963ba5768f57e4c501887e3a3f95effdd7
--- /dev/null
+++ b/src/main/java/com/online/edu/entity/order/vo/CourseElectionVO.java
@@ -0,0 +1,48 @@
+package com.online.edu.entity.order.vo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * 选课
+ *
+ * @TableName course_election
+ */
+@Data
+public class CourseElectionVO implements Serializable {
+ private static final long serialVersionUID = 1L;
+ /**
+ *
+ */
+ @TableId(value = "id", type = IdType.ASSIGN_ID)
+ private Long id;
+ /**
+ * 课程id
+ */
+ private Long courseId;
+ /**
+ * 课程名称
+ */
+ private String courseName;
+ /**
+ * 教师名称
+ */
+ private String teacherName;
+ /**
+ * 学生id
+ */
+ private Long studentId;
+ /**
+ * 学生昵称
+ */
+ private String studentName;
+ /**
+ * 订单金额(分)
+ */
+ private BigDecimal price;
+}
diff --git a/src/main/java/com/online/edu/entity/order/vo/CourseOrderVO.java b/src/main/java/com/online/edu/entity/order/vo/CourseOrderVO.java
new file mode 100644
index 0000000000000000000000000000000000000000..d5981bfc4c5bad8446aedb14f546571fab90cc82
--- /dev/null
+++ b/src/main/java/com/online/edu/entity/order/vo/CourseOrderVO.java
@@ -0,0 +1,29 @@
+package com.online.edu.entity.order.vo;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class CourseOrderVO {
+ /**
+ *
+ */
+ private Long id;
+ /**
+ * 订单号
+ */
+ private String serialNumber;
+ /**
+ * 支付金额(分)
+ */
+ private BigDecimal price;
+ /**
+ * 其他属性
+ */
+ private String attr;
+ /**
+ * 课程名
+ */
+ private String coursename;
+}
diff --git a/src/main/java/com/online/edu/mapper/order/CourseElectionMapper.java b/src/main/java/com/online/edu/mapper/order/CourseElectionMapper.java
index e576ff2d68cd413fdf02147f408484943d62cf89..e74b2871e00c6bc4eb96bd549ddf1899715a9736 100644
--- a/src/main/java/com/online/edu/mapper/order/CourseElectionMapper.java
+++ b/src/main/java/com/online/edu/mapper/order/CourseElectionMapper.java
@@ -2,6 +2,10 @@ package com.online.edu.mapper.order;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.online.edu.entity.order.CourseElection;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.Date;
+import java.util.List;
/**
* @author Nvnqs
@@ -10,6 +14,13 @@ import com.online.edu.entity.order.CourseElection;
* @Entity com.online.edu.entity.order.CourseElection
*/
public interface CourseElectionMapper extends BaseMapper {
+ int insertAll(CourseElection courseElection);
+
+ List getById(@Param("studentId") Long studentId);
+
+ List getByCourse(@Param("courseId") Long courseId);
+
+ int updateById(@Param("serialNumber") String serialNumber, @Param("status") Integer status ,@Param("updateAt") Date updateAt);
}
diff --git a/src/main/java/com/online/edu/mapper/order/CourseOrderMapper.java b/src/main/java/com/online/edu/mapper/order/CourseOrderMapper.java
index 1398bcf053ca95f82add0efa686ab53316196055..487d2fa13dba0f33e38abd41580cfd63eefc5d9b 100644
--- a/src/main/java/com/online/edu/mapper/order/CourseOrderMapper.java
+++ b/src/main/java/com/online/edu/mapper/order/CourseOrderMapper.java
@@ -1,7 +1,11 @@
package com.online.edu.mapper.order;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.online.edu.entity.order.CourseElection;
import com.online.edu.entity.order.CourseOrder;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.Date;
/**
* @author Nvnqs
@@ -10,7 +14,9 @@ import com.online.edu.entity.order.CourseOrder;
* @Entity com.online.edu.entity.order.CourseOrder
*/
public interface CourseOrderMapper extends BaseMapper {
+ int insertAll(CourseOrder courseOrder);
+ int updateById(@Param("serialNumber") String serialNumber, @Param("tradeState") String tradeState, @Param("updateAt") Date updateAt);
}
diff --git a/src/main/java/com/online/edu/service/order/CourseElectionService.java b/src/main/java/com/online/edu/service/order/CourseElectionService.java
index 7de1108b46f1557d8652dbc5813dcfbea6479d39..09d37ad773fd759db42c9237d3e4fbf36a9b63bb 100644
--- a/src/main/java/com/online/edu/service/order/CourseElectionService.java
+++ b/src/main/java/com/online/edu/service/order/CourseElectionService.java
@@ -3,6 +3,8 @@ package com.online.edu.service.order;
import com.baomidou.mybatisplus.extension.service.IService;
import com.online.edu.entity.order.CourseElection;
+import java.util.List;
+
/**
* @author Nvnqs
* @description 针对表【course_election(选课)】的数据库操作Service
@@ -10,4 +12,9 @@ import com.online.edu.entity.order.CourseElection;
*/
public interface CourseElectionService extends IService {
+ boolean save(CourseElection courseElection);
+
+ List getById(Long studentid);
+
+ List getByCourse(Long courseid);
}
diff --git a/src/main/java/com/online/edu/service/order/CourseOrderService.java b/src/main/java/com/online/edu/service/order/CourseOrderService.java
index 68d18d05fd6c575b9bfb7d013a8948a1742f7a86..745e7236ffba9ba777f0b4714e6a2905ace53fb0 100644
--- a/src/main/java/com/online/edu/service/order/CourseOrderService.java
+++ b/src/main/java/com/online/edu/service/order/CourseOrderService.java
@@ -1,6 +1,7 @@
package com.online.edu.service.order;
import com.baomidou.mybatisplus.extension.service.IService;
+import com.online.edu.entity.order.CourseElection;
import com.online.edu.entity.order.CourseOrder;
/**
@@ -9,5 +10,5 @@ import com.online.edu.entity.order.CourseOrder;
* @createDate 2023-06-04 17:20:56
*/
public interface CourseOrderService extends IService {
-
+ boolean save(CourseOrder courseOrder);
}
diff --git a/src/main/java/com/online/edu/service/order/impl/AlipayService.java b/src/main/java/com/online/edu/service/order/impl/AlipayService.java
new file mode 100644
index 0000000000000000000000000000000000000000..5a4c2e7368220c5695b84c1eb9acb7e38bd9e2ad
--- /dev/null
+++ b/src/main/java/com/online/edu/service/order/impl/AlipayService.java
@@ -0,0 +1,81 @@
+package com.online.edu.service.order.impl;
+
+
+import com.alibaba.fastjson2.JSON;
+import com.alipay.easysdk.factory.Factory;
+import com.alipay.easysdk.kernel.util.ResponseChecker;
+import com.alipay.easysdk.payment.common.models.AlipayTradeQueryResponse;
+import com.alipay.easysdk.payment.page.models.AlipayTradePagePayResponse;
+import com.online.edu.common.CommonResult;
+import com.online.edu.entity.order.CourseElection;
+import com.online.edu.entity.order.CourseOrder;
+import com.online.edu.mapper.order.CourseElectionMapper;
+import com.online.edu.mapper.order.CourseOrderMapper;
+import com.online.edu.utils.JSONUtils;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.util.*;
+
+/**
+ * 支付服务
+ */
+
+@Service
+public class AlipayService {
+ @Autowired
+ CourseOrderMapper courseOrderMapper;
+
+ @Autowired
+ CourseElectionMapper courseElectionMapper;
+
+ /**
+ * 生成支付表单
+ * @param subject
+ * @param money
+ * @return
+ * @throws Exception
+ */
+ public String toPay(String subject,String serialNumber, BigDecimal money) throws Exception {
+ AlipayTradePagePayResponse pay = Factory.Payment.Page().pay(subject, serialNumber,
+ String.valueOf(money), "http://localhost:8080");
+ String payForm = null;
+ if (ResponseChecker.success(pay)) {
+ payForm = pay.getBody();
+ }
+ return payForm;
+ }
+
+
+ /**
+ * 查询交易状态
+ * @param outTradeNo 订单号 out_trade_no
+ * @return
+ * @throws Exception
+ */
+
+ public Object queryTradeStatus(String outTradeNo) throws Exception {
+ AlipayTradeQueryResponse query = Factory.Payment.Common().query(outTradeNo);
+ Map map = JSONUtils.jsonToMap(query.getHttpBody());
+ Map, ?> resultMap = JSON.parseObject(map.get("alipay_trade_query_response").toString());
+ Object trade_status = resultMap.get("trade_status");
+ if ("TRADE_SUCCESS".equals(trade_status) || "TRADE_FINISHED".equals(trade_status)) {
+ courseOrderMapper.updateById(outTradeNo,"Trade_Finished",new Date());
+ courseElectionMapper.updateById(outTradeNo, 1,new Date());
+ } else {
+ return CommonResult.error(400,"支付失败");
+ }
+ // 返回交易结果, 是否交易成功需要根据该对象中的 trade_status 来确定
+ // trade_status 的枚举值如下, 请见 https://opendocs.alipay.com/apis/api_1/alipay.trade.query
+ // WAIT_BUYER_PAY(交易创建,等待买家付款)
+ // TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)
+ // TRADE_SUCCESS(交易支付成功)
+ // TRADE_FINISHED(交易结束,不可退款)
+ // 当 trade_status 等于 TRADE_SUCCESS 或 TRADE_FINISHED 时, 表示支付成功
+ return map.get("alipay_trade_query_response");
+ }
+
+}
diff --git a/src/main/java/com/online/edu/service/order/impl/CourseElectionServiceImpl.java b/src/main/java/com/online/edu/service/order/impl/CourseElectionServiceImpl.java
index d9c4dbc2119db06e7885be50751425d413447f98..e245c633f96c4f1595add0624577beaa54c4f9d6 100644
--- a/src/main/java/com/online/edu/service/order/impl/CourseElectionServiceImpl.java
+++ b/src/main/java/com/online/edu/service/order/impl/CourseElectionServiceImpl.java
@@ -4,8 +4,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.online.edu.entity.order.CourseElection;
import com.online.edu.mapper.order.CourseElectionMapper;
import com.online.edu.service.order.CourseElectionService;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import java.util.List;
+
/**
* @author Nvnqs
* @description 针对表【course_election(选课)】的数据库操作Service实现
@@ -14,6 +17,21 @@ import org.springframework.stereotype.Service;
@Service
public class CourseElectionServiceImpl extends ServiceImpl
implements CourseElectionService {
+ @Autowired
+ CourseElectionMapper courseElectionMapper;
+
+ @Override
+ public boolean save(CourseElection courseElection){
+ int i=courseElectionMapper.insertAll(courseElection);
+ System.out.println(i);
+ return i != 0;
+ }
+
+ @Override
+ public List getById(Long studentid){ return courseElectionMapper.getById(studentid);}
+
+ @Override
+ public List getByCourse(Long courseid){ return courseElectionMapper.getById(courseid);}
}
diff --git a/src/main/java/com/online/edu/service/order/impl/CourseOrderServiceImpl.java b/src/main/java/com/online/edu/service/order/impl/CourseOrderServiceImpl.java
index ceaa2aa54bc1297c8fef5594f87f0fb63b18cfa6..932eed9cc550ebae0d1db54087fc89cf46bab0da 100644
--- a/src/main/java/com/online/edu/service/order/impl/CourseOrderServiceImpl.java
+++ b/src/main/java/com/online/edu/service/order/impl/CourseOrderServiceImpl.java
@@ -1,9 +1,12 @@
package com.online.edu.service.order.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.online.edu.entity.order.CourseElection;
import com.online.edu.entity.order.CourseOrder;
+import com.online.edu.mapper.order.CourseElectionMapper;
import com.online.edu.mapper.order.CourseOrderMapper;
import com.online.edu.service.order.CourseOrderService;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
@@ -14,7 +17,13 @@ import org.springframework.stereotype.Service;
@Service
public class CourseOrderServiceImpl extends ServiceImpl
implements CourseOrderService {
+ @Autowired
+ CourseOrderMapper courseOrderMapper;
+ @Override
+ public boolean save(CourseOrder courseOrder){
+ return courseOrderMapper.insertAll(courseOrder) != 0;
+ }
}
diff --git a/src/main/java/com/online/edu/utils/JSONUtils.java b/src/main/java/com/online/edu/utils/JSONUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..3652ef100ced194edde01ceeb43f524593b7f445
--- /dev/null
+++ b/src/main/java/com/online/edu/utils/JSONUtils.java
@@ -0,0 +1,16 @@
+package com.online.edu.utils;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Map;
+
+public class JSONUtils {
+
+ private static final ObjectMapper mapper = new ObjectMapper();
+
+ public static Map jsonToMap(String jsonStr) throws JsonProcessingException {
+ Map map = mapper.readValue(jsonStr, Map.class);
+ return map;
+ }
+}
diff --git a/src/main/resources/mapper/CourseElectionMapper.xml b/src/main/resources/mapper/CourseElectionMapper.xml
index c0b475618f35c761f4bef7891bdd5ebb1d1a0225..4db8c3b79bfdd7fc83c9799667f995fddcb1c580 100644
--- a/src/main/resources/mapper/CourseElectionMapper.xml
+++ b/src/main/resources/mapper/CourseElectionMapper.xml
@@ -19,5 +19,27 @@
+
+ insert into online_edu.course_election
+ (id, serial_number, course_id, course_name, teacher_name, student_id, student_name, price, status, is_deleted, created_at, updated_at)
+ values (#{id}, #{serialNumber}, #{courseId}, #{courseName}, #{teacherName}, #{studentId}, #{studentName}, #{status}, #{price}, #{isDeleted}, #{createdAt}, #{updatedAt})
+
+
+
+
+
+
+ update online_edu.course_election
+ set trade_state = #{status, jdbcType=TINYINT}, updated_at = #{updatedAt, jdbcType=TIMESTAMP}
+ where serialNumber=#{serialNumber}
+
diff --git a/src/main/resources/mapper/CourseOrderMapper.xml b/src/main/resources/mapper/CourseOrderMapper.xml
index 21dbadd710afa4d7befdfdc4a171a3d30cac88a7..ce52da7bd992b7b3732663a2a04550ab9330a214 100644
--- a/src/main/resources/mapper/CourseOrderMapper.xml
+++ b/src/main/resources/mapper/CourseOrderMapper.xml
@@ -17,5 +17,17 @@
+
+ insert into online_edu.course_order
+ (id, serial_number, payedAt, price, transaction_id, trade_state, attr, is_deleted, created_at, updated_at)
+ values
+ (#{id}, #{serialNumber}, #{payedat}, #{price}, #{transactionId,jdbcType=VARCHAR}, #{tradeState}, #{attr}, #{isDeleted}, #{createdAt}, #{updatedAt})
+
+
+
+ update online_edu.course_order
+ set trade_state = #{tradeState, jdbcType=CHAR}, updated_at = #{updatedAt, jdbcType=TIMESTAMP}
+ where serialNumber=#{serialNumber}
+