From bade3bd2cebb2126ba4936397013b05fa8d930a0 Mon Sep 17 00:00:00 2001 From: TTX Date: Sat, 17 Jun 2023 15:20:05 +0800 Subject: [PATCH 1/7] xiugai --- pom.xml | 8 ++ .../com/online/edu/config/AlipayConfig.java | 36 +++++++++ .../order/CourseElectionController.java | 45 ++++++++++- .../order/CourseOrderController.java | 35 +++++++- .../edu/entity/order/CourseElection.java | 15 ++++ .../online/edu/entity/order/CourseOrder.java | 12 +++ .../edu/entity/order/vo/CourseElectionVO.java | 48 +++++++++++ .../edu/entity/order/vo/CourseOrderVO.java | 29 +++++++ .../mapper/order/CourseElectionMapper.java | 11 +++ .../edu/mapper/order/CourseOrderMapper.java | 6 ++ .../service/order/CourseElectionService.java | 7 ++ .../edu/service/order/CourseOrderService.java | 3 +- .../edu/service/order/impl/AlipayService.java | 81 +++++++++++++++++++ .../order/impl/CourseElectionServiceImpl.java | 18 +++++ .../order/impl/CourseOrderServiceImpl.java | 9 +++ .../java/com/online/edu/utils/JSONUtils.java | 16 ++++ .../resources/mapper/CourseElectionMapper.xml | 22 +++++ .../resources/mapper/CourseOrderMapper.xml | 12 +++ 18 files changed, 410 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/online/edu/config/AlipayConfig.java create mode 100644 src/main/java/com/online/edu/entity/order/vo/CourseElectionVO.java create mode 100644 src/main/java/com/online/edu/entity/order/vo/CourseOrderVO.java create mode 100644 src/main/java/com/online/edu/service/order/impl/AlipayService.java create mode 100644 src/main/java/com/online/edu/utils/JSONUtils.java diff --git a/pom.xml b/pom.xml index 215778a..c59a31c 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 0000000..f5f1c57 --- /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/gateway.do"; + + 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 71242d5..02476d4 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 c3d6a1a..b613c5c 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 String 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 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 22f6d6f..a616b57 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 feaeb4d..47bd901 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 0000000..0308369 --- /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 0000000..d5981bf --- /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 e576ff2..e74b287 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 1398bcf..487d2fa 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 7de1108..09d37ad 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 68d18d0..745e723 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 0000000..6770a11 --- /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:28080"); + 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 d9c4dbc..e245c63 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 ceaa2aa..932eed9 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 0000000..3652ef1 --- /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 c0b4756..4db8c3b 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 21dbadd..ce52da7 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} + -- Gitee From 81325ec7c48c4b6f2e75b598861be4c30085a30a Mon Sep 17 00:00:00 2001 From: nvnqsr Date: Sat, 17 Jun 2023 15:25:49 +0800 Subject: [PATCH 2/7] update UserInfo.java --- src/main/java/com/online/edu/entity/rbac/UserInfo.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/com/online/edu/entity/rbac/UserInfo.java b/src/main/java/com/online/edu/entity/rbac/UserInfo.java index e3fc23e..e9f5bce 100644 --- a/src/main/java/com/online/edu/entity/rbac/UserInfo.java +++ b/src/main/java/com/online/edu/entity/rbac/UserInfo.java @@ -74,9 +74,6 @@ public class UserInfo implements Serializable { @Schema(description = "姓名") private String displayName; - - private String openid; - private String phone; private String email; -- Gitee From 95498d71674709bf0a4481ea982d40f87182219a Mon Sep 17 00:00:00 2001 From: TTX Date: Mon, 19 Jun 2023 17:13:36 +0800 Subject: [PATCH 3/7] ttx --- src/main/java/com/online/edu/config/AlipayConfig.java | 2 +- .../online/edu/controller/order/CourseOrderController.java | 4 ++-- .../java/com/online/edu/service/order/impl/AlipayService.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/online/edu/config/AlipayConfig.java b/src/main/java/com/online/edu/config/AlipayConfig.java index f5f1c57..41537a4 100644 --- a/src/main/java/com/online/edu/config/AlipayConfig.java +++ b/src/main/java/com/online/edu/config/AlipayConfig.java @@ -16,7 +16,7 @@ public class AlipayConfig { config.protocol = "https"; // 沙箱环境修改为 openapi.alipaydev.com - config.gatewayHost = "openapi-sandbox.dl.alipaydev.com/gateway.do"; + config.gatewayHost = "openapi-sandbox.dl.alipaydev.com"; config.signType = "RSA2"; 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 b613c5c..00c461e 100644 --- a/src/main/java/com/online/edu/controller/order/CourseOrderController.java +++ b/src/main/java/com/online/edu/controller/order/CourseOrderController.java @@ -51,12 +51,12 @@ public class CourseOrderController { @GetMapping("/topay") @ResponseBody - public String toPay(@RequestBody @Valid CourseOrderVO courseOrderVO) throws Exception { + 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 form; + return CommonResult.success(form); } /** 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 index 6770a11..5a4c2e7 100644 --- a/src/main/java/com/online/edu/service/order/impl/AlipayService.java +++ b/src/main/java/com/online/edu/service/order/impl/AlipayService.java @@ -41,7 +41,7 @@ public class AlipayService { */ public String toPay(String subject,String serialNumber, BigDecimal money) throws Exception { AlipayTradePagePayResponse pay = Factory.Payment.Page().pay(subject, serialNumber, - String.valueOf(money), "http://localhost:28080"); + String.valueOf(money), "http://localhost:8080"); String payForm = null; if (ResponseChecker.success(pay)) { payForm = pay.getBody(); -- Gitee From 198e4296c4ab1ac64382c646171c3d0542a408e4 Mon Sep 17 00:00:00 2001 From: nvnqsr Date: Tue, 20 Jun 2023 15:55:44 +0800 Subject: [PATCH 4/7] update course and comment --- pom.xml | 6 +- .../online/edu/config/MySecurityConfig.java | 6 +- .../controller/course/CommentController.java | 4 +- .../course/CourseInfoController.java | 47 +++++- .../order/CourseElectionController.java | 14 +- .../order/CourseOrderController.java | 38 ++--- .../edu/controller/rbac/UserController.java | 47 +++++- .../controller/resource/FileController.java | 15 ++ .../edu/controller/stat/StatController.java | 36 ++++ .../userInfo/TeacherController.java | 154 ++++++++++++++++++ .../verification/KaptchaController.java | 4 +- .../online/edu/entity/course/CourseInfo.java | 6 + .../online/edu/entity/course/CourseType.java | 31 ++++ .../edu/entity/course/vo/CourseBasicInfo.java | 34 ++++ .../edu/entity/course/vo/CourseInfoVO.java | 100 ++++++++++++ .../edu/entity/course/vo/CourseUpdateVO.java | 6 +- .../edu/entity/course/vo/NewCourseVO.java | 6 +- .../edu/entity/order/CourseElection.java | 20 +-- .../online/edu/entity/order/CourseOrder.java | 18 +- .../edu/entity/order/vo/CourseElectionVO.java | 37 +---- .../edu/entity/order/vo/CourseOrderVO.java | 7 +- .../edu/entity/rbac/UserRoleRelation.java | 1 - .../edu/entity/rbac/vo/UserLoginVO.java | 8 +- .../edu/entity/stat/vo/TeacherStatVO.java | 27 +++ .../edu/entity/userInfo/TeacherInfo.java | 49 +++++- .../entity/userInfo/vo/NewTeacherInfo.java | 52 ++++++ .../entity/userInfo/vo/TeacherQueryVO.java | 47 ++++++ .../edu/mapper/course/CourseInfoMapper.java | 7 +- .../edu/mapper/course/CourseTypeMapper.java | 18 ++ .../online/edu/mapper/rbac/UserMapper.java | 2 + .../online/edu/mapper/stat/StatMapper.java | 7 + .../mapper/userInfo/TeacherInfoMapper.java | 24 +++ .../edu/service/course/CourseInfoService.java | 11 +- .../edu/service/course/CourseTypeService.java | 13 ++ .../course/impl/CourseInfoServiceImpl.java | 36 +++- .../course/impl/CourseTypeServiceImpl.java | 22 +++ .../service/order/CourseElectionService.java | 2 +- .../edu/service/order/CourseOrderService.java | 2 + .../edu/service/order/impl/AlipayService.java | 7 +- .../order/impl/CourseElectionServiceImpl.java | 2 +- .../order/impl/CourseOrderServiceImpl.java | 8 +- .../online/edu/service/rbac/AuthService.java | 23 ++- .../online/edu/service/rbac/UserService.java | 6 + .../service/rbac/impl/AuthServiceImpl.java | 59 +++++-- .../service/rbac/impl/UserServiceImpl.java | 5 + .../edu/service/resource/OSSFileService.java | 4 + .../resource/impl/OSSFileServiceImpl.java | 37 ++++- .../online/edu/service/stat/StatService.java | 9 + .../service/stat/impl/StatServiceImpl.java | 53 ++++++ .../service/userInfo/TeacherInfoService.java | 8 + .../userInfo/impl/TeacherInfoServiceImpl.java | 18 ++ .../com/online/edu/utils/FileTypeUtils.java | 11 ++ .../resources/mapper/CourseInfoMapper.xml | 5 + .../resources/mapper/CourseTypeMapper.xml | 15 ++ src/main/resources/mapper/StatMapper.xml | 8 + .../resources/mapper/TeacherInfoMapper.xml | 25 ++- src/main/resources/mapper/UserMapper.xml | 5 + .../mapper/UserRoleRelationMapper.xml | 2 +- 58 files changed, 1110 insertions(+), 164 deletions(-) create mode 100644 src/main/java/com/online/edu/controller/stat/StatController.java create mode 100644 src/main/java/com/online/edu/controller/userInfo/TeacherController.java create mode 100644 src/main/java/com/online/edu/entity/course/CourseType.java create mode 100644 src/main/java/com/online/edu/entity/course/vo/CourseBasicInfo.java create mode 100644 src/main/java/com/online/edu/entity/course/vo/CourseInfoVO.java create mode 100644 src/main/java/com/online/edu/entity/stat/vo/TeacherStatVO.java create mode 100644 src/main/java/com/online/edu/entity/userInfo/vo/NewTeacherInfo.java create mode 100644 src/main/java/com/online/edu/entity/userInfo/vo/TeacherQueryVO.java create mode 100644 src/main/java/com/online/edu/mapper/course/CourseTypeMapper.java create mode 100644 src/main/java/com/online/edu/mapper/stat/StatMapper.java create mode 100644 src/main/java/com/online/edu/service/course/CourseTypeService.java create mode 100644 src/main/java/com/online/edu/service/course/impl/CourseTypeServiceImpl.java create mode 100644 src/main/java/com/online/edu/service/stat/StatService.java create mode 100644 src/main/java/com/online/edu/service/stat/impl/StatServiceImpl.java create mode 100644 src/main/resources/mapper/CourseTypeMapper.xml create mode 100644 src/main/resources/mapper/StatMapper.xml diff --git a/pom.xml b/pom.xml index 1e5beb4..d2072e4 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,11 @@ 2.2.3 - + + javax.xml.bind + jaxb-api + 2.3.1 + org.springframework.boot diff --git a/src/main/java/com/online/edu/config/MySecurityConfig.java b/src/main/java/com/online/edu/config/MySecurityConfig.java index 33068ef..871a978 100644 --- a/src/main/java/com/online/edu/config/MySecurityConfig.java +++ b/src/main/java/com/online/edu/config/MySecurityConfig.java @@ -77,13 +77,13 @@ public class MySecurityConfig extends SecurityConfigurerAdapter deleteComment(@RequestParam @Valid @Schema(description = "课程ID") String commentId) { + public CommonResult deleteComment(@RequestParam @Valid @Schema(description = "评论ID") String commentId) { boolean result = commentService.setIsDeleted(commentId,1); if (result) { @@ -65,7 +65,7 @@ public class CommentController { if (result != null) { return CommonResult.success(result); } else { - return CommonResult.error(400, "删除失败"); + return CommonResult.error(400, "更新评论失败"); } } } diff --git a/src/main/java/com/online/edu/controller/course/CourseInfoController.java b/src/main/java/com/online/edu/controller/course/CourseInfoController.java index 28f1bdc..67bf0c4 100644 --- a/src/main/java/com/online/edu/controller/course/CourseInfoController.java +++ b/src/main/java/com/online/edu/controller/course/CourseInfoController.java @@ -4,18 +4,22 @@ package com.online.edu.controller.course; import com.online.edu.common.CommonResult; import com.online.edu.common.PageResult; import com.online.edu.entity.course.CourseInfo; -import com.online.edu.entity.course.vo.CourseQueryVO; -import com.online.edu.entity.course.vo.CourseUpdateVO; -import com.online.edu.entity.course.vo.NewCourseVO; +import com.online.edu.entity.course.CourseType; +import com.online.edu.entity.course.vo.*; import com.online.edu.service.course.CourseInfoService; +import com.online.edu.service.course.CourseTypeService; import com.online.edu.service.order.CourseElectionService; +import com.online.edu.service.rbac.UserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.*; +import java.util.List; + @Tag(name = "课程信息控制") @RestController @RequestMapping("/course/info") @@ -23,9 +27,16 @@ import org.springframework.web.bind.annotation.*; public class CourseInfoController { @Autowired private CourseInfoService courseInfoService; + + @Autowired + private CourseTypeService typeService; + @Autowired private CourseElectionService courseElectionService; + @Autowired + private UserService userService; + @Operation(description = "添加课程") @PostMapping("/add") public CommonResult addCourse(@RequestBody @Valid NewCourseVO newCourseVO) { @@ -49,8 +60,24 @@ public class CourseInfoController { @Operation(description = "获取课程信息") @PostMapping("/query") - public CommonResult > queryCourse(@RequestBody @Valid CourseQueryVO courseQueryVO) { + public CommonResult > queryCourse(@RequestBody @Valid CourseQueryVO courseQueryVO) { PageResult courseInfo= courseInfoService.query(courseQueryVO); + if (courseInfo != null) { + return CommonResult.success(courseInfoService.convertToVO(courseInfo)); + } else { + return CommonResult.error(400, "查询失败"); + } + } + + @Operation(description = "获取课程基本信息") + @GetMapping("/list/base") + public CommonResult > listBase(Authentication authentication) { + String username = authentication.getName(); + if(username == null){ + return CommonResult.error(401, "未登录"); + } + String teacherId = userService.getUserByUsername(username).getId(); + List courseInfo= courseInfoService.listAll(teacherId); if (courseInfo != null) { return CommonResult.success(courseInfo); } else { @@ -58,6 +85,7 @@ public class CourseInfoController { } } + @Operation(description = "更新课程信息") @PostMapping("/update") public CommonResult updateCourse(@RequestBody @Valid CourseUpdateVO courseUpdateVO) { @@ -95,6 +123,17 @@ public class CourseInfoController { } } + @Operation(description = "获取课程类型列表") + @GetMapping("/type") + public CommonResult> getCourseType() { + List types= typeService.list(); + if (types != null) { + return CommonResult.success(types); + } else { + return CommonResult.error(400, "查询失败"); + } + } + } 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 02476d4..ecf5f88 100644 --- a/src/main/java/com/online/edu/controller/order/CourseElectionController.java +++ b/src/main/java/com/online/edu/controller/order/CourseElectionController.java @@ -8,16 +8,13 @@ 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.ArrayList; import java.util.List; -import static com.online.edu.utils.OrderSerialNumberUtil.getSerialNumber; - @Tag(name = "选课控制") @RestController @RequestMapping("/course/election") @@ -30,8 +27,8 @@ public class CourseElectionController { @Operation(description = "添加选课记录") @PostMapping("/add") 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()); + CourseElection courseElection = courseElectionvo.buildCourseElection(); + boolean success = courseElectionService.save(courseElection); if (success) { return CommonResult.success(courseElection); @@ -44,8 +41,9 @@ public class CourseElectionController { * 根据id查询选课结果 */ @GetMapping("/selectbyid") - public CommonResult> selectCoursebyid(@RequestBody Long studentid ){ - List courselist=courseElectionService.getById(studentid); + public CommonResult> selectCoursebyid(@RequestBody String studentid ){ + List courselist= new ArrayList<>(); + courselist.add(courseElectionService.getById(studentid)); for(CourseElection e:courselist){ System.out.println(e); if(e.getStatus() == 0 && e.getPrice().compareTo(BigDecimal.ZERO) != 0 ){ 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 b613c5c..eddb706 100644 --- a/src/main/java/com/online/edu/controller/order/CourseOrderController.java +++ b/src/main/java/com/online/edu/controller/order/CourseOrderController.java @@ -4,11 +4,11 @@ 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.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; @@ -33,10 +33,11 @@ public class CourseOrderController { private AlipayService alipayService; @Operation(description = "添加订单") - @PostMapping("/add") - public CommonResult add(@RequestBody @Valid CourseOrderVO courseOrderVO) { - //TODO:建立VO - CourseOrder courseOrder=new CourseOrder(courseOrderVO.getId(), courseOrderVO.getSerialNumber(), courseOrderVO.getPrice(), courseOrderVO.getAttr()); + @GetMapping("/create") + public CommonResult add(@RequestParam @NotNull @Schema(description = "选课ID") String electionId) { + CourseElection election = courseElectionService.getById(electionId); + CourseOrder courseOrder=courseOrderService.buildCourseOrder(election); + boolean success = courseOrderService.save(courseOrder); if (success) { return CommonResult.success(courseOrder); @@ -45,29 +46,22 @@ public class CourseOrderController { } } - /** - * 支付 - */ + @Operation(description = "支付") @GetMapping("/topay") - @ResponseBody - public String 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 form; - } + public String toPay(@RequestParam @Valid String orderId) throws Exception { + CourseOrder courseOrder=courseOrderService.getById(orderId); - /** - * 根据订单号查询支付结果 - */ + String subject=courseOrder.getSerialNumber(); + String serialNumber=courseOrder.getSerialNumber(); + BigDecimal money=courseOrder.getPrice(); + return alipayService.toPay(subject, serialNumber, money); + } @GetMapping("/query") - @ResponseBody + @Operation(description = "根据订单号查询支付结果") public Object queryTradeStatus(@NotNull String serialNumber) throws Exception { - Object result = alipayService.queryTradeStatus(serialNumber); - return result; + return alipayService.queryTradeStatus(serialNumber); } } diff --git a/src/main/java/com/online/edu/controller/rbac/UserController.java b/src/main/java/com/online/edu/controller/rbac/UserController.java index d376b43..d1d20f0 100644 --- a/src/main/java/com/online/edu/controller/rbac/UserController.java +++ b/src/main/java/com/online/edu/controller/rbac/UserController.java @@ -12,6 +12,8 @@ import com.online.edu.service.rbac.UserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.security.PermitAll; +import jakarta.servlet.http.HttpSession; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import org.springframework.beans.factory.annotation.Autowired; @@ -21,7 +23,6 @@ import org.springframework.security.core.annotation.CurrentSecurityContext; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; -import javax.servlet.http.HttpSession; import java.util.List; import java.util.Set; @@ -49,7 +50,6 @@ public class UserController { @Operation(description = "查看用户列表") @GetMapping("/list") - @PreAuthorize("hasAuthority('test')") public CommonResult> list(@RequestParam(required = false) @Valid @Schema(description = "待查看状态id") List targetStatus) { List result; @@ -110,10 +110,33 @@ public class UserController { @Operation(description = "登录") @PostMapping("/login") - public CommonResult login(@RequestBody @Valid UserLoginVO userLoginVO, @RequestParam("code") String code, HttpSession session, Model model) { - return CommonResult.success(authService.login(userLoginVO, code, session, model)); + @PermitAll + public CommonResult login(@RequestBody @Valid UserLoginVO userLoginVO, HttpSession session, Model model) { + String token = authService.login(userLoginVO, session, model); + if(token != null) { + return CommonResult.success(token); + } + else { + return CommonResult.error(401,"登录失败"); + } + } + + + @Operation(description = "管理员登录") + @PostMapping("/admin/login") + @PermitAll + public CommonResult adminLogin(@RequestBody @Valid UserLoginVO userLoginVO, HttpSession session, Model model) { + String token = authService.adminLogin(userLoginVO, session, model); + if(token != null) { + return CommonResult.success(token); + } + else { + return CommonResult.error(401,"登录失败"); + } } + + @Operation(description = "更新用户显示名") @PostMapping("/update/display") public CommonResult updateDisplayName(@RequestParam @NotNull @@ -142,13 +165,15 @@ public class UserController { } } - @Operation(description = "更新用户状态") + @Operation(description = "更新用户密码") @PostMapping("/update/password") public CommonResult updatePassword(@RequestParam @NotNull @Schema(description = "新密码") String newPassword, @RequestParam @NotNull - @Schema(description = "用户名") String username) { - boolean result = authService.updatePassword(newPassword, username); + @Schema(description = "原密码") String oldPassword, + Authentication authentication) { + String username = authentication.getName(); + boolean result = authService.updatePassword(newPassword,oldPassword, username); if (result) { return CommonResult.success(username + "的密码已经更新"); } else { @@ -203,6 +228,14 @@ public class UserController { } } + @Operation(description = "登出") + @PostMapping("/logout") + @PermitAll + public CommonResult logout(@CurrentSecurityContext(expression = "authentication") + Authentication authentication) { + return CommonResult.success(authentication.getName()); + } + } diff --git a/src/main/java/com/online/edu/controller/resource/FileController.java b/src/main/java/com/online/edu/controller/resource/FileController.java index 6aaa0fc..053a88b 100644 --- a/src/main/java/com/online/edu/controller/resource/FileController.java +++ b/src/main/java/com/online/edu/controller/resource/FileController.java @@ -49,6 +49,21 @@ public class FileController { } } + @Operation(description = "上传图片文件") + @PostMapping("/upload/picture") + public CommonResult uploadPicture(@RequestParam("file") MultipartFile file, Authentication authentication) throws Exception { + String userId = userService.getUserByUsername(authentication.getName()).getId(); + if(file == null){ + return CommonResult.error(400, "添加失败"); + } + OSSFile result = ossFileService.uploadPicture(file, userId); + if (result != null) { + return CommonResult.success(result); + } else { + return CommonResult.error(400, "添加失败"); + } + } + @Operation(description = "获取上传凭证") @PostMapping("/get/token") public CommonResult> getToken(@RequestParam("file") MultipartFile file) { diff --git a/src/main/java/com/online/edu/controller/stat/StatController.java b/src/main/java/com/online/edu/controller/stat/StatController.java new file mode 100644 index 0000000..048020a --- /dev/null +++ b/src/main/java/com/online/edu/controller/stat/StatController.java @@ -0,0 +1,36 @@ +package com.online.edu.controller.stat; + +import com.online.edu.common.CommonResult; +import com.online.edu.entity.stat.vo.TeacherStatVO; +import com.online.edu.service.rbac.UserService; +import com.online.edu.service.stat.StatService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.Authentication; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "统计数据") +@RestController +@RequestMapping("/api/stat") +@CrossOrigin(value = "*") +public class StatController { + + @Autowired + StatService statService; + @Autowired + UserService userService; + @Operation(description = "获取教师统计数据") + @GetMapping("/teacher") + public CommonResult getTeacher(Authentication authentication) { + String username = authentication.getName(); + if(username == null){ + return CommonResult.error(401, "未登录"); + } + String teacherId = userService.getUserByUsername(username).getId(); + return CommonResult.success(statService.getTeacherStat(teacherId)); + } +} diff --git a/src/main/java/com/online/edu/controller/userInfo/TeacherController.java b/src/main/java/com/online/edu/controller/userInfo/TeacherController.java new file mode 100644 index 0000000..af19b5c --- /dev/null +++ b/src/main/java/com/online/edu/controller/userInfo/TeacherController.java @@ -0,0 +1,154 @@ +package com.online.edu.controller.userInfo; + + +import com.online.edu.common.CommonResult; +import com.online.edu.common.PageResult; +import com.online.edu.entity.rbac.vo.UserLoginVO; +import com.online.edu.entity.userInfo.TeacherInfo; +import com.online.edu.entity.userInfo.vo.NewTeacherInfo; +import com.online.edu.entity.userInfo.vo.TeacherQueryVO; +import com.online.edu.service.rbac.AuthService; +import com.online.edu.service.rbac.UserService; +import com.online.edu.service.userInfo.TeacherInfoService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.security.PermitAll; +import jakarta.servlet.http.HttpSession; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.Authentication; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.*; + +@Tag(name = "教师用户") +@RestController +@RequestMapping("/api/teacher") +@CrossOrigin(value = "*") +public class TeacherController { + @Autowired + private UserService userService; + + @Autowired + private AuthService authService; + + @Autowired + private TeacherInfoService teacherInfoService; + + @Operation(description = "申请教师用户") + @PostMapping("/user/apply") + public CommonResult addTeacher(@RequestBody @Valid NewTeacherInfo newTeacherInfo, + Authentication authentication) { + String username = authentication.getName(); + if(username == null){ + return CommonResult.error(401, "未登录"); + } + String id = userService.getUserByUsername(username).getId(); + if (teacherInfoService.getById(id) != null) { + return CommonResult.error(400, "当前用户已经是教师"); + } + TeacherInfo info = newTeacherInfo.bulidTeacherInfo(id); + boolean result = teacherInfoService.save(info); + if (result) { + return CommonResult.success(info); + } else { + return CommonResult.error(400, "添加失败"); + } + } + + @Operation(description = "审核教师用户") + @GetMapping("/audit") + public CommonResult auditTeacher(@RequestParam @NotNull @Schema(description = "教师ID") String teacherId, + @RequestParam @NotNull @Schema(description = "教师状态") Integer status) { + + + if(status < 0 || status > 2){ + return CommonResult.error(400, "状态错误"); + } + else if(status == 1){ + userService.addUserRole(teacherId,"1"); + } + else { + userService.delUserRole(teacherId,"1"); + } + boolean result = teacherInfoService.updateTeacherStatus(teacherId,status); + if (result) { + return CommonResult.success(teacherInfoService.getById(teacherId)); + } else { + return CommonResult.error(400, "审核失败"); + } + } + + + @Operation(description = "删除教师用户") + @GetMapping("/delete") + public CommonResult deleteTeacher(@RequestParam @NotNull @Schema(description = "教师ID") String teacherId, + @RequestParam @NotNull @Schema(description = "删除状态") Integer isDeleted) { + if(isDeleted == 1){ + userService.delUserRole(teacherId,"1"); + } + boolean result = teacherInfoService.updateIsDeleted(teacherId,isDeleted); + if (result) { + return CommonResult.success(teacherInfoService.getById(teacherId)); + } else { + return CommonResult.error(400, "删除失败"); + } + } + + + @Operation(description = "获取教师信息") + @GetMapping("/user/get") + public CommonResult getTeacher(@RequestParam @NotNull @Schema(description = "教师ID") String teacherId) { + TeacherInfo result = teacherInfoService.getById(teacherId); + if (result != null) { + return CommonResult.success(result); + } else { + return CommonResult.error(400, "删除失败"); + } + } + + @Operation(description = "获取教师信息") + @GetMapping("/user/get/self") + public CommonResult getTeacher(Authentication authentication) { + String username = authentication.getName(); + if(username == null){ + return CommonResult.error(401, "未登录"); + } + String teacherId = userService.getUserByUsername(username).getId(); + TeacherInfo result = teacherInfoService.getById(teacherId); + if (result != null) { + return CommonResult.success(result); + } else { + return CommonResult.error(400, "获取教师信息失败"); + } + } + + @Operation(description = "查询教师信息") + @PostMapping("/query") + public CommonResult> queryTeacher(@RequestBody @Valid TeacherQueryVO teacherQueryVO) { + PageResult result = teacherInfoService.query(teacherQueryVO); + if (result != null) { + return CommonResult.success(result); + } else { + return CommonResult.error(400, "删除失败"); + } + } + + @Operation(description = "教师登录") + @PostMapping("/user/login") + @PermitAll + public CommonResult teacherLogin(@RequestBody @Valid UserLoginVO userLoginVO, HttpSession session, Model model) { + String token = authService.teacherLogin(userLoginVO, session, model); + if(token != null) { + return CommonResult.success(token); + } + else { + return CommonResult.error(401,"登录失败"); + } + } + + +} + + diff --git a/src/main/java/com/online/edu/controller/verification/KaptchaController.java b/src/main/java/com/online/edu/controller/verification/KaptchaController.java index 261b6a8..5dba050 100644 --- a/src/main/java/com/online/edu/controller/verification/KaptchaController.java +++ b/src/main/java/com/online/edu/controller/verification/KaptchaController.java @@ -2,6 +2,8 @@ package com.online.edu.controller.verification; import com.google.code.kaptcha.Producer; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -11,8 +13,6 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.imageio.ImageIO; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.OutputStream; diff --git a/src/main/java/com/online/edu/entity/course/CourseInfo.java b/src/main/java/com/online/edu/entity/course/CourseInfo.java index 58ab4b1..3eae521 100644 --- a/src/main/java/com/online/edu/entity/course/CourseInfo.java +++ b/src/main/java/com/online/edu/entity/course/CourseInfo.java @@ -41,6 +41,12 @@ public class CourseInfo implements Serializable { * 封面链接 */ private String cover; + + /** + * 描述 + */ + private String description; + /** * 价格 */ diff --git a/src/main/java/com/online/edu/entity/course/CourseType.java b/src/main/java/com/online/edu/entity/course/CourseType.java new file mode 100644 index 0000000..9502899 --- /dev/null +++ b/src/main/java/com/online/edu/entity/course/CourseType.java @@ -0,0 +1,31 @@ +package com.online.edu.entity.course; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; + +/** + * 课程类型 + * @TableName course_type + */ +@TableName(value ="course_type") +@Data +public class CourseType implements Serializable { + /** + * 类型ID + */ + @TableId(type = IdType.AUTO) + private Integer id; + + /** + * 课程类型 + */ + private String courseType; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/course/vo/CourseBasicInfo.java b/src/main/java/com/online/edu/entity/course/vo/CourseBasicInfo.java new file mode 100644 index 0000000..5463815 --- /dev/null +++ b/src/main/java/com/online/edu/entity/course/vo/CourseBasicInfo.java @@ -0,0 +1,34 @@ +package com.online.edu.entity.course.vo; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serial; +import java.io.Serializable; + +/** + * 课程信息 + * + * @TableName course_info + */ +@Data +@Accessors(chain = true) +public class CourseBasicInfo implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + /** + * 课程id + */ + @TableId(value = "id", type = IdType.ASSIGN_ID) + @Schema(nullable = true,defaultValue = "") + private String id; + + /** + * 标题 + */ + private String title; + +} \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/course/vo/CourseInfoVO.java b/src/main/java/com/online/edu/entity/course/vo/CourseInfoVO.java new file mode 100644 index 0000000..c9c6dd5 --- /dev/null +++ b/src/main/java/com/online/edu/entity/course/vo/CourseInfoVO.java @@ -0,0 +1,100 @@ +package com.online.edu.entity.course.vo; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.online.edu.entity.course.CourseInfo; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serial; +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * 课程信息 + * + * @TableName course_info + */ +@Data +@Accessors(chain = true) +public class CourseInfoVO implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + /** + * 课程id + */ + @TableId(value = "id", type = IdType.ASSIGN_ID) + @Schema(nullable = true,defaultValue = "") + private String id; + /** + * 教师id + */ + private String teacherId; + /** + * 教师姓名 + */ + private String teacherName; + + /** + * 教师描述 + */ + private String teacherDescription; + + /** + * 教师头像 + */ + private String teacherAvatar; + /** + * 课程类型 + */ + private Integer typeId; + + /** + * 课程类型名称 + */ + private String typeName; + /** + * 标题 + */ + private String title; + /** + * 封面链接 + */ + private String cover; + /** + * 描述 + */ + private String description; + /** + * 价格 + */ + private BigDecimal price; + /** + * 课程状态 0:未上线,1:私有开课中,2:公开开课中,3:结课 + */ + private Integer status; + /** + * 是否删除 + */ + private Integer isDeleted; + /** + * 创建时间 + */ + private Date createdAt; + /** + * 更新时间 + */ + private Date updatedAt; + + public static CourseInfoVO build(CourseInfo courseInfo,String teacherName, String teacherDescription, + String teacherAvatar, String typeName) { + return new CourseInfoVO().setId(courseInfo.getId()).setTeacherId(courseInfo.getTeacherId()) + .setTeacherName(teacherName).setTeacherDescription(teacherDescription).setTeacherAvatar(teacherAvatar) + .setTitle(courseInfo.getTitle()).setTypeId(courseInfo.getTypeId()).setTypeName(typeName) + .setPrice(courseInfo.getPrice()).setCover(courseInfo.getCover()).setPrice(courseInfo.getPrice()) + .setCreatedAt(courseInfo.getCreatedAt()).setUpdatedAt(courseInfo.getUpdatedAt()).setStatus(courseInfo.getStatus()) + .setDescription(courseInfo.getDescription()).setIsDeleted(courseInfo.getIsDeleted()); + } +} \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/course/vo/CourseUpdateVO.java b/src/main/java/com/online/edu/entity/course/vo/CourseUpdateVO.java index e0f024f..b3025e3 100644 --- a/src/main/java/com/online/edu/entity/course/vo/CourseUpdateVO.java +++ b/src/main/java/com/online/edu/entity/course/vo/CourseUpdateVO.java @@ -37,6 +37,10 @@ public class CourseUpdateVO implements Serializable { * 封面链接 */ private String cover; + /** + * 描述 + */ + private String description; /** * 价格 */ @@ -51,6 +55,6 @@ public class CourseUpdateVO implements Serializable { private Integer isDeleted; public CourseInfo buildCourseInfo(){ return new CourseInfo().setId(id).setTypeId(typeId).setTitle(title) - .setCover(cover).setPrice(price).setStatus(status).setIsDeleted(isDeleted); + .setCover(cover).setDescription(description).setPrice(price).setStatus(status).setIsDeleted(isDeleted); } } \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/course/vo/NewCourseVO.java b/src/main/java/com/online/edu/entity/course/vo/NewCourseVO.java index 0303f20..55efd43 100644 --- a/src/main/java/com/online/edu/entity/course/vo/NewCourseVO.java +++ b/src/main/java/com/online/edu/entity/course/vo/NewCourseVO.java @@ -28,6 +28,10 @@ public class NewCourseVO implements Serializable { * 封面链接 */ private String cover; + /** + * 描述 + */ + private String description; /** * 价格 */ @@ -35,6 +39,6 @@ public class NewCourseVO implements Serializable { public CourseInfo buildCourseInfo(){ return new CourseInfo().setTeacherId(teacherId).setTypeId(typeId).setTitle(title) - .setCover(cover).setPrice(price).setStatus(0).setIsDeleted(0); + .setCover(cover).setPrice(price).setDescription(description).setStatus(0).setIsDeleted(0); } } \ No newline at end of file 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 59d8e2c..395badf 100644 --- a/src/main/java/com/online/edu/entity/order/CourseElection.java +++ b/src/main/java/com/online/edu/entity/order/CourseElection.java @@ -2,7 +2,10 @@ package com.online.edu.entity.order; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; import java.io.Serializable; import java.math.BigDecimal; @@ -14,6 +17,9 @@ import java.util.Date; * @TableName course_election */ @Data +@AllArgsConstructor +@NoArgsConstructor +@Accessors(chain = true) public class CourseElection implements Serializable { private static final long serialVersionUID = 1L; /** @@ -66,18 +72,4 @@ 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 923030d..86d51a1 100644 --- a/src/main/java/com/online/edu/entity/order/CourseOrder.java +++ b/src/main/java/com/online/edu/entity/order/CourseOrder.java @@ -2,7 +2,10 @@ package com.online.edu.entity.order; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; import java.io.Serializable; import java.math.BigDecimal; @@ -14,6 +17,9 @@ import java.util.Date; * @TableName course_order */ @Data +@AllArgsConstructor +@NoArgsConstructor +@Accessors(chain = true) public class CourseOrder implements Serializable { private static final long serialVersionUID = 1L; /** @@ -57,16 +63,4 @@ 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 index 0308369..e2d01fa 100644 --- a/src/main/java/com/online/edu/entity/order/vo/CourseElectionVO.java +++ b/src/main/java/com/online/edu/entity/order/vo/CourseElectionVO.java @@ -1,12 +1,9 @@ package com.online.edu.entity.order.vo; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; +import com.online.edu.entity.order.CourseElection; import lombok.Data; import java.io.Serializable; -import java.math.BigDecimal; -import java.util.Date; /** * 选课 @@ -15,34 +12,18 @@ import java.util.Date; */ @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; + private String courseId; /** * 学生id */ - private Long studentId; - /** - * 学生昵称 - */ - private String studentName; - /** - * 订单金额(分) - */ - private BigDecimal price; + private String studentId; + + + public CourseElection buildCourseElection() { + return new CourseElection().setCourseId(courseId).setStudentId(studentId); + } } 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 index d5981bf..840b5dd 100644 --- a/src/main/java/com/online/edu/entity/order/vo/CourseOrderVO.java +++ b/src/main/java/com/online/edu/entity/order/vo/CourseOrderVO.java @@ -9,7 +9,7 @@ public class CourseOrderVO { /** * */ - private Long id; + private String id; /** * 订单号 */ @@ -22,8 +22,5 @@ public class CourseOrderVO { * 其他属性 */ private String attr; - /** - * 课程名 - */ - private String coursename; + } diff --git a/src/main/java/com/online/edu/entity/rbac/UserRoleRelation.java b/src/main/java/com/online/edu/entity/rbac/UserRoleRelation.java index 539f9b2..8cc35e3 100644 --- a/src/main/java/com/online/edu/entity/rbac/UserRoleRelation.java +++ b/src/main/java/com/online/edu/entity/rbac/UserRoleRelation.java @@ -28,7 +28,6 @@ public class UserRoleRelation implements Serializable { @NotNull(message = "[关联ID]不能为空") @Schema(description = "关联ID") @TableId(value = "id", type = IdType.ASSIGN_ID) - private String id; /** * 用户ID diff --git a/src/main/java/com/online/edu/entity/rbac/vo/UserLoginVO.java b/src/main/java/com/online/edu/entity/rbac/vo/UserLoginVO.java index 7574fdf..c1fcc09 100644 --- a/src/main/java/com/online/edu/entity/rbac/vo/UserLoginVO.java +++ b/src/main/java/com/online/edu/entity/rbac/vo/UserLoginVO.java @@ -28,6 +28,12 @@ public class UserLoginVO { */ @NotBlank(message = "[密码]不能为空") @Size(max = 100, message = "编码长度不能超过100") - @Schema(description = "密码,为加密格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "password") + @Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "password") private String password; + + /** + * 验证码 + */ + @Schema(description = "验证码", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "1234") + private String code; } diff --git a/src/main/java/com/online/edu/entity/stat/vo/TeacherStatVO.java b/src/main/java/com/online/edu/entity/stat/vo/TeacherStatVO.java new file mode 100644 index 0000000..0d8bc64 --- /dev/null +++ b/src/main/java/com/online/edu/entity/stat/vo/TeacherStatVO.java @@ -0,0 +1,27 @@ +package com.online.edu.entity.stat.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +@Data +public class TeacherStatVO implements Serializable { + @Schema(description = "已上架课程数量") + private Integer courseCount; + + @Schema(description = "已上架课程章节数量") + private Integer sectionCount; + + @Schema(description = "评论数量") + private Integer commentCount; + + + @Schema(description = "加入时间") + private Date joinDateTime; + + @Schema(description = "加入时长") + private Integer joinDaysCount; + +} diff --git a/src/main/java/com/online/edu/entity/userInfo/TeacherInfo.java b/src/main/java/com/online/edu/entity/userInfo/TeacherInfo.java index 3792fa2..9c55a6e 100644 --- a/src/main/java/com/online/edu/entity/userInfo/TeacherInfo.java +++ b/src/main/java/com/online/edu/entity/userInfo/TeacherInfo.java @@ -1,33 +1,68 @@ package com.online.edu.entity.userInfo; -import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; +import lombok.experimental.Accessors; -import java.io.Serial; import java.io.Serializable; +import java.util.Date; /** * 教师信息 - * * @TableName teacher_info */ +@TableName(value ="teacher_info") @Data +@Accessors(chain = true) public class TeacherInfo implements Serializable { - @Serial - private static final long serialVersionUID = 1L; /** * 教师id */ - @TableId(value = "id", type = IdType.ASSIGN_ID) - + @TableId private String teacherId; + + /** + * 教师头像 + */ + private String teacherAvatar; + /** * 教师姓名 */ private String teacherName; + /** * 教师描述 */ private String teacherDescription; + + /** + * 教师邮箱 + */ + private String teacherEmail; + + /** + * 教师状态:0禁用,1已审核,2待审核 + */ + private Integer status; + + /** + * 已删除 + */ + private Integer isDeleted; + + /** + * 创建时间 + */ + private Date createdAt; + + /** + * 更新时间 + */ + private Date updatedAt; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/userInfo/vo/NewTeacherInfo.java b/src/main/java/com/online/edu/entity/userInfo/vo/NewTeacherInfo.java new file mode 100644 index 0000000..ec72dc7 --- /dev/null +++ b/src/main/java/com/online/edu/entity/userInfo/vo/NewTeacherInfo.java @@ -0,0 +1,52 @@ +package com.online.edu.entity.userInfo.vo; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.online.edu.entity.userInfo.TeacherInfo; +import lombok.Data; + +import java.io.Serializable; + +/** + * 教师信息 + * @TableName teacher_info + */ +@TableName(value ="teacher_info") +@Data +public class NewTeacherInfo implements Serializable { + + + /** + * 教师头像 + */ + private String teacherAvatar; + + /** + * 教师姓名 + */ + private String teacherName; + + /** + * 教师描述 + */ + private String teacherDescription; + + /** + * 教师邮箱 + */ + private String teacherEmail; + + public TeacherInfo bulidTeacherInfo(String userId){ + if(userId == null){ + return null; + } + TeacherInfo result = new TeacherInfo(); + result.setTeacherId(userId); + result.setTeacherEmail(teacherEmail); + result.setTeacherAvatar(teacherAvatar); + result.setTeacherName(teacherDescription); + result.setTeacherName(teacherName); + result.setIsDeleted(0); + result.setStatus(2); + return result; + } +} \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/userInfo/vo/TeacherQueryVO.java b/src/main/java/com/online/edu/entity/userInfo/vo/TeacherQueryVO.java new file mode 100644 index 0000000..72161e2 --- /dev/null +++ b/src/main/java/com/online/edu/entity/userInfo/vo/TeacherQueryVO.java @@ -0,0 +1,47 @@ +package com.online.edu.entity.userInfo.vo; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.online.edu.common.PageParam; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.util.Date; + +/** + * 教师信息 + * @TableName teacher_info + */ +@TableName(value ="teacher_info") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class TeacherQueryVO extends PageParam { + + /** + * 教师姓名 + */ + private String teacherName; + + + /** + * 教师状态:0禁用,1已审核,2待审核 + */ + private Integer status; + + /** + * 已删除 + */ + private Integer isDeleted; + + /** + * 创建时间 + */ + private Date oldDate; + + /** + * 更新时间 + */ + private Date newDate; + +} \ No newline at end of file diff --git a/src/main/java/com/online/edu/mapper/course/CourseInfoMapper.java b/src/main/java/com/online/edu/mapper/course/CourseInfoMapper.java index 2d60bde..a10c55b 100644 --- a/src/main/java/com/online/edu/mapper/course/CourseInfoMapper.java +++ b/src/main/java/com/online/edu/mapper/course/CourseInfoMapper.java @@ -1,5 +1,4 @@ package com.online.edu.mapper.course; -import org.apache.ibatis.annotations.Param; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; @@ -7,7 +6,11 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.online.edu.common.PageParam; import com.online.edu.common.PageResult; import com.online.edu.entity.course.CourseInfo; +import com.online.edu.entity.course.vo.CourseBasicInfo; import com.online.edu.entity.course.vo.CourseQueryVO; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * @author Nvnqs @@ -33,6 +36,8 @@ public interface CourseInfoMapper extends BaseMapper { } int updateIsDeletedById(@Param("isDeleted") Integer isDeleted, @Param("id") String id); + + List listAll(@Param("teacherId") String teacherId); } diff --git a/src/main/java/com/online/edu/mapper/course/CourseTypeMapper.java b/src/main/java/com/online/edu/mapper/course/CourseTypeMapper.java new file mode 100644 index 0000000..e5fadd4 --- /dev/null +++ b/src/main/java/com/online/edu/mapper/course/CourseTypeMapper.java @@ -0,0 +1,18 @@ +package com.online.edu.mapper.course; + +import com.online.edu.entity.course.CourseType; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** +* @author Nvnqs +* @description 针对表【course_type(课程类型)】的数据库操作Mapper +* @createDate 2023-06-17 19:44:29 +* @Entity com.online.edu.entity.course.CourseType +*/ +public interface CourseTypeMapper extends BaseMapper { + +} + + + + diff --git a/src/main/java/com/online/edu/mapper/rbac/UserMapper.java b/src/main/java/com/online/edu/mapper/rbac/UserMapper.java index 907d58e..20ff114 100644 --- a/src/main/java/com/online/edu/mapper/rbac/UserMapper.java +++ b/src/main/java/com/online/edu/mapper/rbac/UserMapper.java @@ -42,4 +42,6 @@ public interface UserMapper { int delById(@Param("id") String id); Set getMenu(@Param("username") String username); + + String getAvatarById(@Param("id") String id); } diff --git a/src/main/java/com/online/edu/mapper/stat/StatMapper.java b/src/main/java/com/online/edu/mapper/stat/StatMapper.java new file mode 100644 index 0000000..da83bba --- /dev/null +++ b/src/main/java/com/online/edu/mapper/stat/StatMapper.java @@ -0,0 +1,7 @@ +package com.online.edu.mapper.stat; + +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface StatMapper { +} diff --git a/src/main/java/com/online/edu/mapper/userInfo/TeacherInfoMapper.java b/src/main/java/com/online/edu/mapper/userInfo/TeacherInfoMapper.java index f81c4ef..8d787bb 100644 --- a/src/main/java/com/online/edu/mapper/userInfo/TeacherInfoMapper.java +++ b/src/main/java/com/online/edu/mapper/userInfo/TeacherInfoMapper.java @@ -1,7 +1,12 @@ package com.online.edu.mapper.userInfo; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.online.edu.common.PageParam; +import com.online.edu.common.PageResult; import com.online.edu.entity.userInfo.TeacherInfo; +import com.online.edu.entity.userInfo.vo.TeacherQueryVO; import org.apache.ibatis.annotations.Param; /** @@ -12,6 +17,25 @@ import org.apache.ibatis.annotations.Param; */ public interface TeacherInfoMapper extends BaseMapper { int countByTeacherId(@Param("teacherId") String teacherId); + + int updateStatusByTeacherId(@Param("status") Integer status, @Param("teacherId") String teacherId); + + int updateIsDeletedByTeacherId(@Param("isDeleted") Integer isDeleted, @Param("teacherId") String teacherId); + + default PageResult selectPage(TeacherQueryVO queryVO) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper() + .like(queryVO.getTeacherName() != null, TeacherInfo::getTeacherName, queryVO.getTeacherName()) + .between(queryVO.getOldDate() != null && queryVO.getNewDate() != null, TeacherInfo::getCreatedAt, queryVO.getOldDate(), queryVO.getNewDate()) + .eq(queryVO.getIsDeleted() != null, TeacherInfo::getIsDeleted, queryVO.getIsDeleted()) + .eq(queryVO.getIsDeleted() == null, TeacherInfo::getIsDeleted, 0) + .eq(queryVO.getStatus() != null, TeacherInfo::getStatus, queryVO.getStatus()) + .eq(queryVO.getStatus() == null, TeacherInfo::getStatus, 1) + .orderByDesc(TeacherInfo::getTeacherId); + IPage mpPage = PageParam.buildPage(queryVO); + selectPage(mpPage, wrapper); + // 转换返回 + return new PageResult<>(mpPage.getRecords(), mpPage.getTotal()); + } } diff --git a/src/main/java/com/online/edu/service/course/CourseInfoService.java b/src/main/java/com/online/edu/service/course/CourseInfoService.java index 26426aa..bccfa83 100644 --- a/src/main/java/com/online/edu/service/course/CourseInfoService.java +++ b/src/main/java/com/online/edu/service/course/CourseInfoService.java @@ -3,9 +3,9 @@ package com.online.edu.service.course; import com.baomidou.mybatisplus.extension.service.IService; import com.online.edu.common.PageResult; import com.online.edu.entity.course.CourseInfo; -import com.online.edu.entity.course.vo.CourseQueryVO; -import com.online.edu.entity.course.vo.CourseUpdateVO; -import com.online.edu.entity.course.vo.NewCourseVO; +import com.online.edu.entity.course.vo.*; + +import java.util.List; /** * @author Nvnqs @@ -22,6 +22,11 @@ public interface CourseInfoService extends IService { PageResult query(CourseQueryVO courseQueryVO); + + PageResult convertToVO(PageResult courseInfoPageResult); + boolean setIsDeleted(String courseId, Integer isDeleted); + List listAll(String teacherId); + } diff --git a/src/main/java/com/online/edu/service/course/CourseTypeService.java b/src/main/java/com/online/edu/service/course/CourseTypeService.java new file mode 100644 index 0000000..724434a --- /dev/null +++ b/src/main/java/com/online/edu/service/course/CourseTypeService.java @@ -0,0 +1,13 @@ +package com.online.edu.service.course; + +import com.online.edu.entity.course.CourseType; +import com.baomidou.mybatisplus.extension.service.IService; + +/** +* @author Nvnqs +* @description 针对表【course_type(课程类型)】的数据库操作Service +* @createDate 2023-06-17 19:44:29 +*/ +public interface CourseTypeService extends IService { + +} diff --git a/src/main/java/com/online/edu/service/course/impl/CourseInfoServiceImpl.java b/src/main/java/com/online/edu/service/course/impl/CourseInfoServiceImpl.java index 984b724..d62bfd8 100644 --- a/src/main/java/com/online/edu/service/course/impl/CourseInfoServiceImpl.java +++ b/src/main/java/com/online/edu/service/course/impl/CourseInfoServiceImpl.java @@ -3,25 +3,34 @@ package com.online.edu.service.course.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.online.edu.common.PageResult; import com.online.edu.entity.course.CourseInfo; -import com.online.edu.entity.course.vo.CourseQueryVO; -import com.online.edu.entity.course.vo.CourseUpdateVO; -import com.online.edu.entity.course.vo.NewCourseVO; +import com.online.edu.entity.course.CourseType; +import com.online.edu.entity.course.vo.*; +import com.online.edu.entity.userInfo.TeacherInfo; import com.online.edu.mapper.course.CourseInfoMapper; import com.online.edu.service.course.CourseInfoService; +import com.online.edu.service.course.CourseTypeService; +import com.online.edu.service.rbac.UserService; import com.online.edu.service.userInfo.TeacherInfoService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + /** * @author Nvnqs - * @description 针对表【course_info(课程信息)】的数据库操作Service实现 - * @createDate 2023-06-04 17:20:56 + */ @Service public class CourseInfoServiceImpl extends ServiceImpl implements CourseInfoService { @Autowired TeacherInfoService teacherInfoService; + @Autowired + UserService userService; + @Autowired + CourseTypeService courseTypeService; + @Override public CourseInfo addCourse(NewCourseVO newCourseVO) { CourseInfo courseInfo= newCourseVO.buildCourseInfo(); @@ -57,10 +66,27 @@ public class CourseInfoServiceImpl extends ServiceImpl convertToVO(PageResult courseInfoPageResult) { + List courses = new ArrayList<>(); + for(CourseInfo info: courseInfoPageResult.getList()){ + TeacherInfo teacherInfo = teacherInfoService.lambdaQuery().eq(TeacherInfo::getTeacherId,info.getTeacherId()).one(); + CourseType type = courseTypeService.getById(info.getTypeId()); + courses.add(CourseInfoVO.build(info,teacherInfo.getTeacherName(),teacherInfo.getTeacherDescription(), + teacherInfo.getTeacherAvatar(),type==null?"0":type.getCourseType())); + } + return new PageResult<>(courses, courseInfoPageResult.getTotal()); + } + @Override public boolean setIsDeleted(String courseId, Integer isDeleted) { return baseMapper.updateIsDeletedById(isDeleted,courseId) > 0; } + + @Override + public List listAll(String teacherId) { + return baseMapper.listAll(teacherId); + } } diff --git a/src/main/java/com/online/edu/service/course/impl/CourseTypeServiceImpl.java b/src/main/java/com/online/edu/service/course/impl/CourseTypeServiceImpl.java new file mode 100644 index 0000000..daa90e3 --- /dev/null +++ b/src/main/java/com/online/edu/service/course/impl/CourseTypeServiceImpl.java @@ -0,0 +1,22 @@ +package com.online.edu.service.course.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.online.edu.entity.course.CourseType; +import com.online.edu.service.course.CourseTypeService; +import com.online.edu.mapper.course.CourseTypeMapper; +import org.springframework.stereotype.Service; + +/** +* @author Nvnqs +* @description 针对表【course_type(课程类型)】的数据库操作Service实现 +* @createDate 2023-06-17 19:44:29 +*/ +@Service +public class CourseTypeServiceImpl extends ServiceImpl + implements CourseTypeService{ + +} + + + + 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 09d37ad..e1d904a 100644 --- a/src/main/java/com/online/edu/service/order/CourseElectionService.java +++ b/src/main/java/com/online/edu/service/order/CourseElectionService.java @@ -12,7 +12,7 @@ import java.util.List; */ public interface CourseElectionService extends IService { - boolean save(CourseElection courseElection); + boolean electCourse(CourseElection courseElection); List getById(Long studentid); 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 745e723..72becd1 100644 --- a/src/main/java/com/online/edu/service/order/CourseOrderService.java +++ b/src/main/java/com/online/edu/service/order/CourseOrderService.java @@ -11,4 +11,6 @@ import com.online.edu.entity.order.CourseOrder; */ public interface CourseOrderService extends IService { boolean save(CourseOrder courseOrder); + + CourseOrder buildCourseOrder(CourseElection courseElection); } 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 index 6770a11..cf2f4bc 100644 --- a/src/main/java/com/online/edu/service/order/impl/AlipayService.java +++ b/src/main/java/com/online/edu/service/order/impl/AlipayService.java @@ -7,18 +7,15 @@ 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.*; +import java.util.Date; +import java.util.Map; /** * 支付服务 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 e245c63..dd3e49f 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 @@ -21,7 +21,7 @@ public class CourseElectionServiceImpl extends ServiceImpl getMenu(String username); + String getAvatarUrl(String userId); + + } \ No newline at end of file diff --git a/src/main/java/com/online/edu/service/rbac/impl/AuthServiceImpl.java b/src/main/java/com/online/edu/service/rbac/impl/AuthServiceImpl.java index 00245c7..f23999b 100644 --- a/src/main/java/com/online/edu/service/rbac/impl/AuthServiceImpl.java +++ b/src/main/java/com/online/edu/service/rbac/impl/AuthServiceImpl.java @@ -2,14 +2,16 @@ package com.online.edu.service.rbac.impl; import com.online.edu.common.AppException; import com.online.edu.entity.rbac.UserInfo; +import com.online.edu.entity.rbac.UserInfoDAO; import com.online.edu.entity.rbac.UserRoleRelation; import com.online.edu.entity.rbac.vo.NewUserVO; import com.online.edu.entity.rbac.vo.UserLoginVO; import com.online.edu.mapper.rbac.UserMapper; import com.online.edu.mapper.rbac.UserRoleRelationMapper; import com.online.edu.service.rbac.AuthService; +import com.online.edu.service.userInfo.TeacherInfoService; import com.online.edu.utils.JwtTokenUtil; -import org.apache.commons.lang3.StringUtils; +import jakarta.servlet.http.HttpSession; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.authentication.BadCredentialsException; @@ -22,7 +24,6 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.ui.Model; -import javax.servlet.http.HttpSession; @Service public class AuthServiceImpl implements AuthService { @@ -34,6 +35,9 @@ public class AuthServiceImpl implements AuthService { @Autowired PasswordEncoder passwordEncoder; + @Autowired + TeacherInfoService trainingInfoService; + @Autowired UserDetailsService userDetailsService; @@ -71,15 +75,13 @@ public class AuthServiceImpl implements AuthService { } @Override - public String login(UserLoginVO userLoginVO, - String code, HttpSession session, Model model) { - - // 检查验证码 - String kaptcha = (String) session.getAttribute("kaptcha"); - if (StringUtils.isBlank(kaptcha) || StringUtils.isBlank(code) || !kaptcha.equalsIgnoreCase(code)) { - model.addAttribute("codeMsg", "验证码不正确!"); - return "/rbac/user/login"; - } + public String login(UserLoginVO userLoginVO, HttpSession session, Model model) { +// // 检查验证码 +// String kaptcha = (String) session.getAttribute("kaptcha"); +// if (StringUtils.isBlank(kaptcha) || StringUtils.isBlank(userLoginVO.getCode()) || !kaptcha.equalsIgnoreCase(userLoginVO.getCode())) { +// model.addAttribute("codeMsg", "验证码不正确!"); +// return null; +// } try { UserDetails userDetails = userDetailsService.loadUserByUsername(userLoginVO.getUsername()); @@ -98,10 +100,43 @@ public class AuthServiceImpl implements AuthService { } + @Override + public String teacherLogin(UserLoginVO userLoginVO, HttpSession session, Model model) { + UserInfoDAO userInfo = userMapper.getUserByUsername(userLoginVO.getUsername()); + if(userInfo == null){ + return null; + } + String id = userInfo.getId(); + if(!trainingInfoService.checkTeacher(id)){ + return null; + } + else{ + return login(userLoginVO, session, model); + } + } @Override - public boolean updatePassword(String newPassword, String username) { + public String adminLogin(UserLoginVO userLoginVO, HttpSession session, Model model) { + UserInfoDAO userInfo = userMapper.getUserByUsername(userLoginVO.getUsername()); + if(userInfo == null){ + return null; + } + String id = userInfo.getId(); + if(userRoleRelationMapper.getByUserIdAndRoleId(id,"4") == 0){ + return null; + } + else{ + return login(userLoginVO, session, model); + } + } + + @Override + public boolean updatePassword(String newPassword, String oldPassword, String username) { + String origin = userMapper.getUserByUsername(username).getPassword(); + if(origin == null || !passwordEncoder.matches(oldPassword,origin)){ + return false; + } return userMapper.updatePasswordByUsername(passwordEncoder.encode(newPassword), username) > 0; } diff --git a/src/main/java/com/online/edu/service/rbac/impl/UserServiceImpl.java b/src/main/java/com/online/edu/service/rbac/impl/UserServiceImpl.java index 13c4326..e963538 100644 --- a/src/main/java/com/online/edu/service/rbac/impl/UserServiceImpl.java +++ b/src/main/java/com/online/edu/service/rbac/impl/UserServiceImpl.java @@ -98,5 +98,10 @@ public class UserServiceImpl implements UserService { return userMapper.getMenu(username); } + @Override + public String getAvatarUrl(String userId) { + return userMapper.getAvatarById(userId); + } + } diff --git a/src/main/java/com/online/edu/service/resource/OSSFileService.java b/src/main/java/com/online/edu/service/resource/OSSFileService.java index a5cd159..47a79a0 100644 --- a/src/main/java/com/online/edu/service/resource/OSSFileService.java +++ b/src/main/java/com/online/edu/service/resource/OSSFileService.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.online.edu.common.PageResult; import com.online.edu.entity.resource.OSSFile; import com.online.edu.entity.resource.vo.FileQueryVO; +import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -31,4 +32,7 @@ public interface OSSFileService extends IService { OSSFile recovery(String fileId); PageResult query(FileQueryVO fileQueryVO); + + OSSFile uploadPicture(MultipartFile file, String uploaderId) throws Exception; + } diff --git a/src/main/java/com/online/edu/service/resource/impl/OSSFileServiceImpl.java b/src/main/java/com/online/edu/service/resource/impl/OSSFileServiceImpl.java index a86d68f..9a82200 100644 --- a/src/main/java/com/online/edu/service/resource/impl/OSSFileServiceImpl.java +++ b/src/main/java/com/online/edu/service/resource/impl/OSSFileServiceImpl.java @@ -1,5 +1,6 @@ package com.online.edu.service.resource.impl; +import cn.hutool.core.io.FileTypeUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.online.edu.common.PageResult; import com.online.edu.entity.resource.OSSFile; @@ -11,7 +12,9 @@ import com.online.edu.utils.FileTypeUtils; import com.online.edu.utils.S3FileClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; +import java.io.ByteArrayInputStream; import java.io.Serializable; import java.util.List; @@ -29,14 +32,14 @@ public class OSSFileServiceImpl extends ServiceImpl S3FileClient s3FileClient; private String generatePath(String name, String type){ - if(type.startsWith("video")){ - return "videos/upload/"+name+ FileSerialNumberUtil.getSerialNumber(); - } else if (type.startsWith("image")) { - return "images/upload/"+name+ FileSerialNumberUtil.getSerialNumber(); - }else if (name.endsWith("pdf")) { - return "docs/upload/"+name+ FileSerialNumberUtil.getSerialNumber(); + if(FileTypeUtils.isVideo(type)){ + return "videos/upload/"+ FileSerialNumberUtil.getSerialNumber()+'.'+type; + } else if (FileTypeUtils.isPicture(type)) { + return "images/upload/"+ FileSerialNumberUtil.getSerialNumber()+'.'+type; + }else if (FileTypeUtils.isDoc(type)) { + return "docs/upload/"+ FileSerialNumberUtil.getSerialNumber()+'.'+type; } - return "files/upload/"+name+ FileSerialNumberUtil.getSerialNumber(); + return "files/upload/"+ FileSerialNumberUtil.getSerialNumber()+'.'+type; } @Override @@ -56,9 +59,10 @@ public class OSSFileServiceImpl extends ServiceImpl @Override public OSSFile upload(byte[] content, String name,String uploaderId) throws Exception { - String type = FileTypeUtils.getMineType(content, name); + String type = FileTypeUtil.getType(new ByteArrayInputStream(content), name); + String contentType = FileTypeUtils.getMineType(content, name); String path = generatePath(name, type); - return upload(content,name,path,type,uploaderId); + return upload(content,name,path,contentType,uploaderId); } @Override @@ -104,6 +108,21 @@ public class OSSFileServiceImpl extends ServiceImpl public PageResult query(FileQueryVO fileQueryVO) { return baseMapper.selectPage(fileQueryVO); } + + @Override + public OSSFile uploadPicture(MultipartFile file, String uploaderId) throws Exception { + // 图片大小限制在 2MB + if (file.getSize() > 2097152L) { + return null; + } + String type = FileTypeUtil.getType(file.getInputStream()); + if(!FileTypeUtils.isPicture(type)){ + return null; + } + return upload(file.getBytes(), file.getOriginalFilename(), uploaderId); + } + + } diff --git a/src/main/java/com/online/edu/service/stat/StatService.java b/src/main/java/com/online/edu/service/stat/StatService.java new file mode 100644 index 0000000..e8c485a --- /dev/null +++ b/src/main/java/com/online/edu/service/stat/StatService.java @@ -0,0 +1,9 @@ +package com.online.edu.service.stat; + + +import com.online.edu.entity.stat.vo.TeacherStatVO; + +public interface StatService { + + TeacherStatVO getTeacherStat(String teacherId); +} diff --git a/src/main/java/com/online/edu/service/stat/impl/StatServiceImpl.java b/src/main/java/com/online/edu/service/stat/impl/StatServiceImpl.java new file mode 100644 index 0000000..d08ec5d --- /dev/null +++ b/src/main/java/com/online/edu/service/stat/impl/StatServiceImpl.java @@ -0,0 +1,53 @@ +package com.online.edu.service.stat.impl; + +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; +import com.online.edu.entity.course.Comment; +import com.online.edu.entity.course.CourseInfo; +import com.online.edu.entity.resource.CourseSection; +import com.online.edu.entity.stat.vo.TeacherStatVO; +import com.online.edu.service.course.CommentService; +import com.online.edu.service.course.CourseInfoService; +import com.online.edu.service.rbac.UserService; +import com.online.edu.service.resource.CourseSectionService; +import com.online.edu.service.stat.StatService; +import com.online.edu.service.userInfo.TeacherInfoService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; + +@Service + +public class StatServiceImpl implements StatService { + + @Autowired + UserService userService; + + @Autowired + CourseInfoService courseInfoService; + + + @Autowired + CourseSectionService courseSectionService; + + @Autowired + CommentService commentService; + @Autowired + TeacherInfoService teacherInfoService; + + @Override + public TeacherStatVO getTeacherStat(String teacherId) { + TeacherStatVO statVO = new TeacherStatVO(); + List courses = courseInfoService.lambdaQuery().eq(CourseInfo::getTeacherId,teacherId).list(); + statVO.setCourseCount(courses.size()); + statVO.setSectionCount(Math.toIntExact(courseSectionService.lambdaQuery().in(CourseSection::getCourseId, courses).count())); + statVO.setCommentCount(Math.toIntExact(commentService.lambdaQuery().in(Comment::getCourseId, courses).count())); + Date join = teacherInfoService.getById(teacherId).getCreatedAt(); + statVO.setJoinDateTime(join); + Date now = new Date(); + statVO.setJoinDaysCount((int) DateUtil.between(join,now, DateUnit.DAY)); + return statVO; + } +} diff --git a/src/main/java/com/online/edu/service/userInfo/TeacherInfoService.java b/src/main/java/com/online/edu/service/userInfo/TeacherInfoService.java index bf6bf1c..aad58e8 100644 --- a/src/main/java/com/online/edu/service/userInfo/TeacherInfoService.java +++ b/src/main/java/com/online/edu/service/userInfo/TeacherInfoService.java @@ -1,7 +1,9 @@ package com.online.edu.service.userInfo; import com.baomidou.mybatisplus.extension.service.IService; +import com.online.edu.common.PageResult; import com.online.edu.entity.userInfo.TeacherInfo; +import com.online.edu.entity.userInfo.vo.TeacherQueryVO; /** * @author Nvnqs @@ -11,4 +13,10 @@ import com.online.edu.entity.userInfo.TeacherInfo; public interface TeacherInfoService extends IService { boolean checkTeacher( String teacherId); + boolean updateTeacherStatus(String teacherId, Integer status); + + boolean updateIsDeleted(String teacherId, Integer isDeleted); + + PageResult query(TeacherQueryVO teacherQueryVO); + } diff --git a/src/main/java/com/online/edu/service/userInfo/impl/TeacherInfoServiceImpl.java b/src/main/java/com/online/edu/service/userInfo/impl/TeacherInfoServiceImpl.java index 4740c11..cd97070 100644 --- a/src/main/java/com/online/edu/service/userInfo/impl/TeacherInfoServiceImpl.java +++ b/src/main/java/com/online/edu/service/userInfo/impl/TeacherInfoServiceImpl.java @@ -1,7 +1,9 @@ package com.online.edu.service.userInfo.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.online.edu.common.PageResult; import com.online.edu.entity.userInfo.TeacherInfo; +import com.online.edu.entity.userInfo.vo.TeacherQueryVO; import com.online.edu.mapper.userInfo.TeacherInfoMapper; import com.online.edu.service.userInfo.TeacherInfoService; import org.springframework.stereotype.Service; @@ -19,6 +21,22 @@ public class TeacherInfoServiceImpl extends ServiceImpl 0; + } + + @Override + public boolean updateIsDeleted(String teacherId, Integer isDeleted) { + return baseMapper.updateIsDeletedByTeacherId(isDeleted,teacherId) > 0; + } + + @Override + public PageResult query(TeacherQueryVO teacherQueryVO) { + return baseMapper.selectPage(teacherQueryVO); + + } } diff --git a/src/main/java/com/online/edu/utils/FileTypeUtils.java b/src/main/java/com/online/edu/utils/FileTypeUtils.java index d655fca..b05eace 100644 --- a/src/main/java/com/online/edu/utils/FileTypeUtils.java +++ b/src/main/java/com/online/edu/utils/FileTypeUtils.java @@ -22,4 +22,15 @@ public class FileTypeUtils { return TIKA.get().detect(data, name); } + public static boolean isVideo(String type) { + return "mkv".equals(type)||"mp4".equals(type)||"avi".equals(type)||"flv".equals(type); + } + + public static boolean isDoc(String type) { + return "doc".equals(type)||"pdf".equals(type)||"docx".equals(type)||"ppt".equals(type)||"pptx".equals(type)||"xls".equals(type)||"xlsx".equals(type); + } + + public static boolean isPicture(String type) { + return "jpg".equals(type)||"jpeg".equals(type)||"webp".equals(type)||"png".equals(type)||"svg".equals(type)||"gif".equals(type); + } } diff --git a/src/main/resources/mapper/CourseInfoMapper.xml b/src/main/resources/mapper/CourseInfoMapper.xml index 0c14080..cfc96ed 100644 --- a/src/main/resources/mapper/CourseInfoMapper.xml +++ b/src/main/resources/mapper/CourseInfoMapper.xml @@ -21,6 +21,11 @@ set is_deleted = #{isDeleted,jdbcType=NUMERIC} where id = #{id,jdbcType=VARCHAR} + diff --git a/src/main/resources/mapper/CourseTypeMapper.xml b/src/main/resources/mapper/CourseTypeMapper.xml new file mode 100644 index 0000000..8d00727 --- /dev/null +++ b/src/main/resources/mapper/CourseTypeMapper.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + id,course_type + + diff --git a/src/main/resources/mapper/StatMapper.xml b/src/main/resources/mapper/StatMapper.xml new file mode 100644 index 0000000..b42335d --- /dev/null +++ b/src/main/resources/mapper/StatMapper.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/src/main/resources/mapper/TeacherInfoMapper.xml b/src/main/resources/mapper/TeacherInfoMapper.xml index 03d0403..d153219 100644 --- a/src/main/resources/mapper/TeacherInfoMapper.xml +++ b/src/main/resources/mapper/TeacherInfoMapper.xml @@ -5,15 +5,34 @@ - - - + + + + + + + + + + + + update teacher_info + set status = #{status,jdbcType=NUMERIC} + where teacher_id = #{teacherId,jdbcType=VARCHAR} + + + update teacher_info + set is_deleted = #{isDeleted,jdbcType=NUMERIC} + where teacher_id = #{teacherId,jdbcType=VARCHAR} + + + diff --git a/src/main/resources/mapper/UserMapper.xml b/src/main/resources/mapper/UserMapper.xml index 5fc285a..b3f7d12 100644 --- a/src/main/resources/mapper/UserMapper.xml +++ b/src/main/resources/mapper/UserMapper.xml @@ -131,4 +131,9 @@ in (select id from user_info where username = #{username}))) + diff --git a/src/main/resources/mapper/UserRoleRelationMapper.xml b/src/main/resources/mapper/UserRoleRelationMapper.xml index ae218c3..e943e4c 100644 --- a/src/main/resources/mapper/UserRoleRelationMapper.xml +++ b/src/main/resources/mapper/UserRoleRelationMapper.xml @@ -33,7 +33,7 @@ insert ignore into online_edu.user_role_relation (id, user_id, role_id) - values (#{id}, #{userId,jdbcType=NUMERIC}, #{roleId,jdbcType=NUMERIC}) + values (#{id}, #{userId}, #{roleId}) -- Gitee From 7c15e0d50badb379eb3ca9708dbfd308ca520530 Mon Sep 17 00:00:00 2001 From: nvnqsr Date: Thu, 22 Jun 2023 19:55:26 +0800 Subject: [PATCH 5/7] update --- .../online/edu/config/MySecurityConfig.java | 2 +- .../course/CourseInfoController.java | 48 +++++- .../order/CourseOrderController.java | 4 +- .../edu/controller/rbac/UserController.java | 149 ++++++++++++++---- .../controller/resource/FileController.java | 22 ++- .../userInfo/SocialUserController.java | 84 ---------- .../userInfo/TeacherController.java | 15 +- .../online/edu/entity/course/CourseType.java | 8 +- .../entity/course/vo/CourseTypeQueryVO.java | 21 +++ .../online/edu/entity/message/Message.java | 6 +- .../edu/entity/message/MessageTemplate.java | 6 +- .../entity/message/SystemNotifyMessage.java | 76 --------- .../entity/message/vo/MessageGroupSendVO.java | 43 +++++ .../edu/entity/message/vo/MessageSendVO.java | 44 ++++++ .../com/online/edu/entity/rbac/UserInfo.java | 3 +- .../online/edu/entity/rbac/UserInfoDAO.java | 12 ++ .../online/edu/entity/rbac/vo/NewUserVO.java | 28 +++- .../edu/entity/rbac/vo/UserBasicInfoVO.java | 1 + .../online/edu/entity/rbac/vo/UserInfoVO.java | 1 + .../edu/entity/rbac/vo/UserQueryVO.java | 61 +++++++ .../edu/entity/rbac/vo/UserUpdateVO.java | 42 +++++ .../edu/entity/userInfo/vo/RegisterVO.java | 7 +- .../edu/mapper/course/CourseTypeMapper.java | 31 +++- .../message/SystemNotifyMessageMapper.java | 18 --- .../online/edu/mapper/rbac/UserMapper.java | 43 ++++- .../edu/mapper/userInfo/SocialUserMapper.java | 19 --- .../edu/service/course/CourseTypeService.java | 19 ++- .../course/impl/CourseTypeServiceImpl.java | 28 +++- .../message/SystemNotifyMessageService.java | 13 -- .../impl/SystemNotifyMessageServiceImpl.java | 22 --- .../online/edu/service/rbac/AuthService.java | 18 ++- .../edu/service/rbac/RoleInfoService.java | 2 + .../online/edu/service/rbac/UserService.java | 24 ++- .../service/rbac/impl/AuthServiceImpl.java | 55 ++++++- .../rbac/impl/RoleInfoServiceImpl.java | 8 + .../service/rbac/impl/UserServiceImpl.java | 41 ++++- .../service/userInfo/SocialUserService.java | 14 -- .../userInfo/impl/SocialUserServiceImpl.java | 22 --- src/main/resources/application.yml | 3 + .../resources/mapper/CourseTypeMapper.xml | 15 +- .../resources/mapper/SocialUserMapper.xml | 16 -- .../mapper/SystemNotifyMessageMapper.xml | 22 --- src/main/resources/mapper/UserMapper.xml | 69 +++++--- 43 files changed, 750 insertions(+), 435 deletions(-) delete mode 100644 src/main/java/com/online/edu/controller/userInfo/SocialUserController.java create mode 100644 src/main/java/com/online/edu/entity/course/vo/CourseTypeQueryVO.java delete mode 100644 src/main/java/com/online/edu/entity/message/SystemNotifyMessage.java create mode 100644 src/main/java/com/online/edu/entity/message/vo/MessageGroupSendVO.java create mode 100644 src/main/java/com/online/edu/entity/message/vo/MessageSendVO.java create mode 100644 src/main/java/com/online/edu/entity/rbac/vo/UserQueryVO.java create mode 100644 src/main/java/com/online/edu/entity/rbac/vo/UserUpdateVO.java delete mode 100644 src/main/java/com/online/edu/mapper/message/SystemNotifyMessageMapper.java delete mode 100644 src/main/java/com/online/edu/mapper/userInfo/SocialUserMapper.java delete mode 100644 src/main/java/com/online/edu/service/message/SystemNotifyMessageService.java delete mode 100644 src/main/java/com/online/edu/service/message/impl/SystemNotifyMessageServiceImpl.java delete mode 100644 src/main/java/com/online/edu/service/userInfo/SocialUserService.java delete mode 100644 src/main/java/com/online/edu/service/userInfo/impl/SocialUserServiceImpl.java delete mode 100644 src/main/resources/mapper/SocialUserMapper.xml delete mode 100644 src/main/resources/mapper/SystemNotifyMessageMapper.xml diff --git a/src/main/java/com/online/edu/config/MySecurityConfig.java b/src/main/java/com/online/edu/config/MySecurityConfig.java index 871a978..eb08e06 100644 --- a/src/main/java/com/online/edu/config/MySecurityConfig.java +++ b/src/main/java/com/online/edu/config/MySecurityConfig.java @@ -163,7 +163,7 @@ public class MySecurityConfig extends SecurityConfigurerAdapter { //先获取用户 UserInfoDAO user = userService.getUserByUsername(username); - if (user != null && user.getStatus().equals("正常")) { + if (user != null && "1".equals(user.getStatus())) { List permissionList = userService.getUserPermission(user.getId()); return new MyUserDetails(user, permissionList); } diff --git a/src/main/java/com/online/edu/controller/course/CourseInfoController.java b/src/main/java/com/online/edu/controller/course/CourseInfoController.java index 67bf0c4..344bf95 100644 --- a/src/main/java/com/online/edu/controller/course/CourseInfoController.java +++ b/src/main/java/com/online/edu/controller/course/CourseInfoController.java @@ -126,7 +126,7 @@ public class CourseInfoController { @Operation(description = "获取课程类型列表") @GetMapping("/type") public CommonResult> getCourseType() { - List types= typeService.list(); + List types = typeService.list(); if (types != null) { return CommonResult.success(types); } else { @@ -134,6 +134,52 @@ public class CourseInfoController { } } + @Operation(description = "查询课程类型列表") + @PostMapping("/type/query") + public CommonResult> queryCourseType(@RequestBody @Valid CourseTypeQueryVO queryVO) { + PageResult types = typeService.query(queryVO); + if (types != null) { + return CommonResult.success(types); + } else { + return CommonResult.error(400, "查询失败"); + } + } + + @Operation(description = "新增课程类型") + @PostMapping("/type/add") + public CommonResult addCourseType(@RequestBody @Valid CourseType courseType) { + boolean result = typeService.addCourseType(courseType); + if (result) { + return CommonResult.success(courseType); + } else { + return CommonResult.error(400, "查询失败"); + } + } + + @Operation(description = "更新课程类型") + @PostMapping("/type/update") + public CommonResult updateCourseType(@RequestBody @Valid CourseType courseType) { + boolean result = typeService.updateCourseType(courseType); + + if (result) { + return CommonResult.success(courseType); + } else { + return CommonResult.error(400, "查询失败"); + } + } + + @Operation(description = "删除课程类型") + @DeleteMapping("/type/delete") + public CommonResult deleteCourseType(@RequestParam @Valid @Schema(name = "类型ID") String id) { + boolean result = typeService.removeById(id); + if (result) { + return CommonResult.success(id + "已删除"); + } else { + return CommonResult.error(400, "查询失败"); + } + } + + } 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 0b38225..4d98485 100644 --- a/src/main/java/com/online/edu/controller/order/CourseOrderController.java +++ b/src/main/java/com/online/edu/controller/order/CourseOrderController.java @@ -55,8 +55,8 @@ public class CourseOrderController { @GetMapping("/topay") @ResponseBody public CommonResult toPay(@RequestBody @Valid CourseOrderVO courseOrderVO) throws Exception { - String subject=courseOrderVO.getCoursename(); - String serialNumber=courseOrderVO.getSerialNumber(); + String subject = "购买课程"; + String serialNumber = courseOrderVO.getSerialNumber(); BigDecimal money=courseOrderVO.getPrice(); String form = alipayService.toPay(subject, serialNumber, money); return CommonResult.success(form); diff --git a/src/main/java/com/online/edu/controller/rbac/UserController.java b/src/main/java/com/online/edu/controller/rbac/UserController.java index d1d20f0..f4da683 100644 --- a/src/main/java/com/online/edu/controller/rbac/UserController.java +++ b/src/main/java/com/online/edu/controller/rbac/UserController.java @@ -2,12 +2,13 @@ package com.online.edu.controller.rbac; import com.online.edu.common.CommonResult; +import com.online.edu.common.PageResult; +import com.online.edu.entity.rbac.UserInfo; import com.online.edu.entity.rbac.UserInfoDAO; -import com.online.edu.entity.rbac.vo.NewUserVO; -import com.online.edu.entity.rbac.vo.PermissionMenuVO; -import com.online.edu.entity.rbac.vo.UserInfoVO; -import com.online.edu.entity.rbac.vo.UserLoginVO; +import com.online.edu.entity.rbac.vo.*; +import com.online.edu.entity.userInfo.vo.RegisterVO; import com.online.edu.service.rbac.AuthService; +import com.online.edu.service.rbac.RoleInfoService; import com.online.edu.service.rbac.UserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Schema; @@ -16,8 +17,8 @@ import jakarta.annotation.security.PermitAll; import jakarta.servlet.http.HttpSession; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; +import org.hibernate.validator.constraints.Length; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.core.Authentication; import org.springframework.security.core.annotation.CurrentSecurityContext; import org.springframework.ui.Model; @@ -36,7 +37,10 @@ public class UserController { @Autowired private AuthService authService; - @Operation(description = "新建用户") + @Autowired + private RoleInfoService roleInfoService; + + @Operation(description = "管理员新建用户") @PostMapping("/add") public CommonResult addUser(@RequestBody @Valid NewUserVO newUserVO) { @@ -48,6 +52,20 @@ public class UserController { } } + + @Operation(description = "注册用户") + @PostMapping("/register") + @PermitAll + public CommonResult register(@RequestBody @Valid RegisterVO registerVO) { + + boolean success = authService.addUser(registerVO); + if (success) { + return CommonResult.success(registerVO); + } else { + return CommonResult.error(400, "添加失败"); + } + } + @Operation(description = "查看用户列表") @GetMapping("/list") public CommonResult> list(@RequestParam(required = false) @Valid @@ -69,13 +87,13 @@ public class UserController { @Operation(description = "查看用户信息") @GetMapping("/get") - @PreAuthorize("hasAuthority('test')") public CommonResult get(@RequestParam(required = false) @Valid @Schema(description = "待查看用户名") String username) { - UserInfoDAO result = userService.getUserByUsername(username); if (result != null) { + result.setPassword(null); + result.setRoles(roleInfoService.getRoleIdByUser(result.getId())); return CommonResult.success(result); } else { return CommonResult.error(400, "查看用户信息失败"); @@ -88,7 +106,24 @@ public class UserController { public CommonResult getSelf(@CurrentSecurityContext(expression = "authentication") Authentication authentication) { UserInfoDAO result = userService.getUserByUsername(authentication.getName()); + + if (result != null) { + result.setPassword(null); + return CommonResult.success(result); + } else { + return CommonResult.error(400, "查看自身信息失败"); + } + } + + @Operation(description = "查看自身信息") + @GetMapping("/info") + + public CommonResult info(@CurrentSecurityContext(expression = "authentication") + Authentication authentication) { + UserInfoDAO result = userService.getUserByUsername(authentication.getName()); + if (result != null) { + result.setPassword(null); return CommonResult.success(result); } else { return CommonResult.error(400, "查看自身信息失败"); @@ -96,7 +131,7 @@ public class UserController { } @Operation(description = "删除用户") - @GetMapping("/delete") + @PostMapping("/delete") public CommonResult delete(@RequestParam @Valid @Schema(description = "待删除用户名") String username) { boolean result = userService.delUser(username); @@ -108,15 +143,27 @@ public class UserController { } } + @Operation(description = "恢复用户") + @PostMapping("/recover") + public CommonResult recover(@RequestParam @Valid + @Schema(description = "待恢复用户名") String username) { + boolean result = userService.recoverUser(username); + + if (result) { + return CommonResult.success(username + "已经恢复用户"); + } else { + return CommonResult.error(400, username + "恢复用户失败"); + } + } + @Operation(description = "登录") @PostMapping("/login") @PermitAll public CommonResult login(@RequestBody @Valid UserLoginVO userLoginVO, HttpSession session, Model model) { String token = authService.login(userLoginVO, session, model); - if(token != null) { + if (token != null) { return CommonResult.success(token); - } - else { + } else { return CommonResult.error(401,"登录失败"); } } @@ -129,51 +176,62 @@ public class UserController { String token = authService.adminLogin(userLoginVO, session, model); if(token != null) { return CommonResult.success(token); - } - else { - return CommonResult.error(401,"登录失败"); + } else { + return CommonResult.error(401, "登录失败"); } } - @Operation(description = "更新用户显示名") - @PostMapping("/update/display") - public CommonResult updateDisplayName(@RequestParam @NotNull - @Schema(description = "新显示名") String displayName, - @RequestParam @NotNull - @Schema(description = "用户名") String username) { - boolean result = userService.updateDisplayName(displayName, username); + @PostMapping("/update") + public CommonResult updateDisplayName(@RequestBody @Valid + @Schema(description = "更新数据") UserUpdateVO userUpdateVO, + Authentication authentication) { + if (!authentication.getName().equals(userUpdateVO.getUsername())) { + return CommonResult.error(403, "更新失败"); + } + UserInfoDAO result = userService.update(userUpdateVO); + if (result != null) { + return CommonResult.success(result); + } else { + return CommonResult.error(400, "更新失败"); + } + } + + @Operation(description = "更新用户状态: 启用") + @PostMapping("/enable") + public CommonResult enable(@RequestParam @NotNull + @Schema(description = "用户名") String username) { + boolean result = userService.updateStatus(1, username); if (result) { - return CommonResult.success(username + "更新为" + displayName); + return CommonResult.success(username + "更新为" + 1); } else { return CommonResult.error(400, "更新失败"); } } - @Operation(description = "更新用户状态") - @PostMapping("/update/status") - public CommonResult updateStatus(@RequestParam @NotNull - @Schema(description = "新状态", allowableValues = {"1", "2", "3"}) int newStatus, - @RequestParam @NotNull - @Schema(description = "用户名") String username) { - boolean result = userService.updateStatus(newStatus, username); + @Operation(description = "更新用户状态: 禁用") + @PostMapping("/disable") + public CommonResult disable(@RequestParam @NotNull + @Schema(description = "用户名") String username) { + boolean result = userService.updateStatus(0, username); if (result) { - return CommonResult.success(username + "更新为" + newStatus); + return CommonResult.success(username + "更新为" + 0); } else { return CommonResult.error(400, "更新失败"); } } + @Operation(description = "更新用户密码") @PostMapping("/update/password") public CommonResult updatePassword(@RequestParam @NotNull - @Schema(description = "新密码") String newPassword, + @Schema(description = "新密码") @Length(min = 6) String newPassword, @RequestParam @NotNull @Schema(description = "原密码") String oldPassword, Authentication authentication) { String username = authentication.getName(); - boolean result = authService.updatePassword(newPassword,oldPassword, username); + boolean result = authService.updatePassword(newPassword, oldPassword, username); if (result) { return CommonResult.success(username + "的密码已经更新"); } else { @@ -182,6 +240,20 @@ public class UserController { } + @Operation(description = "强制更新用户密码") + @PostMapping("/update/password/admin") + public CommonResult forceUpdatePassword(@RequestParam @NotNull + @Schema(description = "新密码") @Length(min = 6) String newPassword, + @RequestParam @NotNull + @Schema(description = "用户名") String username) { + boolean result = authService.updatePassword(newPassword, username); + if (result) { + return CommonResult.success(username + "的密码已经更新"); + } else { + return CommonResult.error(400, "更新失败"); + } + } + @Operation(description = "添加用户角色") @PostMapping("/addRole") public CommonResult addUserRole(@RequestParam @NotNull @@ -211,6 +283,17 @@ public class UserController { } } + @Operation(description = "查询用户信息") + @PostMapping("/query") + public CommonResult> queryUser(@RequestBody @Valid UserQueryVO userQueryVO) { + PageResult result = userService.query(userQueryVO); + if (result != null) { + return CommonResult.success(result); + } else { + return CommonResult.error(400, "删除失败"); + } + } + @Operation(description = "获取当前用户菜单") @PostMapping("/getMenu") diff --git a/src/main/java/com/online/edu/controller/resource/FileController.java b/src/main/java/com/online/edu/controller/resource/FileController.java index 053a88b..8114fbb 100644 --- a/src/main/java/com/online/edu/controller/resource/FileController.java +++ b/src/main/java/com/online/edu/controller/resource/FileController.java @@ -64,13 +64,31 @@ public class FileController { } } + @Operation(description = "更新用户头像") + @PostMapping("/update/avatar") + public CommonResult updateAvatar(@RequestParam("file") MultipartFile file, Authentication authentication) throws Exception { + String userId = userService.getUserByUsername(authentication.getName()).getId(); + if (file == null) { + return CommonResult.error(400, "添加失败"); + } + OSSFile result = ossFileService.uploadPicture(file, userId); + if (result != null) { + String url = "http://" + result.getPath(); + url = userService.updateAvatarUrl(url, userId); + return CommonResult.success(url); + } else { + return CommonResult.error(400, "添加失败"); + } + + } + @Operation(description = "获取上传凭证") @PostMapping("/get/token") - public CommonResult> getToken(@RequestParam("file") MultipartFile file) { + public CommonResult> getToken(@RequestParam("file") MultipartFile file) { String fileName = file.getOriginalFilename(); String token = ossFileService.getToken(fileName); if (token != null) { - return CommonResult.success("token",token); + return CommonResult.success("token", token); } else { return CommonResult.error(400, "添加失败"); } diff --git a/src/main/java/com/online/edu/controller/userInfo/SocialUserController.java b/src/main/java/com/online/edu/controller/userInfo/SocialUserController.java deleted file mode 100644 index 7c451c4..0000000 --- a/src/main/java/com/online/edu/controller/userInfo/SocialUserController.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.online.edu.controller.userInfo; - - -import com.online.edu.common.CommonResult; -import com.online.edu.entity.rbac.UserInfoDAO; -import com.online.edu.entity.rbac.vo.NewUserVO; -import com.online.edu.entity.rbac.vo.UserInfoVO; -import com.online.edu.service.rbac.AuthService; -import com.online.edu.service.rbac.UserService; -import com.online.edu.service.userInfo.SocialUserService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.validation.Valid; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@Tag(name = "社交用户") -@RestController -@RequestMapping("/rbac/social") -@CrossOrigin(value = "*") -public class SocialUserController { - @Autowired - private UserService userService; - @Autowired - private AuthService authService; - - @Autowired - private SocialUserService socialUserService; - - @Operation(description = "新建社交用户") - @PostMapping("/add") - public CommonResult addSocialUser(@RequestBody @Valid NewUserVO newUserVO) { - - boolean success = authService.addUser(newUserVO); - if (success) { - return CommonResult.success(newUserVO); - } else { - return CommonResult.error(400, "添加失败"); - } - } - - @Operation(description = "查看用户列表") - @GetMapping("/list") - @PreAuthorize("hasAuthority('test')") - public CommonResult> list(@RequestParam(required = false) @Valid - @Schema(description = "待查看状态id") List targetStatus) { - List result; - if (targetStatus != null) { - result = userService.getAllByStatusIn(targetStatus); - } else { - result = userService.getAllUnionRole(); - } - - if (result != null) { - return CommonResult.success(result); - } else { - return CommonResult.error(400, "查看用户列表失败"); - } - } - - - @Operation(description = "查看用户信息") - @GetMapping("/get") - @PreAuthorize("hasAuthority('test')") - public CommonResult get(@RequestParam(required = false) @Valid - @Schema(description = "待查看用户名") String username) { - - - UserInfoDAO result = userService.getUserByUsername(username); - if (result != null) { - return CommonResult.success(result); - } else { - return CommonResult.error(400, "查看用户信息失败"); - } - } - - -} - - diff --git a/src/main/java/com/online/edu/controller/userInfo/TeacherController.java b/src/main/java/com/online/edu/controller/userInfo/TeacherController.java index af19b5c..5d3a104 100644 --- a/src/main/java/com/online/edu/controller/userInfo/TeacherController.java +++ b/src/main/java/com/online/edu/controller/userInfo/TeacherController.java @@ -57,8 +57,19 @@ public class TeacherController { } } + @Operation(description = "更新教师用户") + @PostMapping("/update") + public CommonResult updateTeacher(@RequestBody @Valid TeacherInfo teacherInfo) { + boolean result = teacherInfoService.updateById(teacherInfo); + if (result) { + return CommonResult.success(teacherInfo); + } else { + return CommonResult.error(400, "添加失败"); + } + } + @Operation(description = "审核教师用户") - @GetMapping("/audit") + @PostMapping("/audit") public CommonResult auditTeacher(@RequestParam @NotNull @Schema(description = "教师ID") String teacherId, @RequestParam @NotNull @Schema(description = "教师状态") Integer status) { @@ -82,7 +93,7 @@ public class TeacherController { @Operation(description = "删除教师用户") - @GetMapping("/delete") + @PostMapping("/delete") public CommonResult deleteTeacher(@RequestParam @NotNull @Schema(description = "教师ID") String teacherId, @RequestParam @NotNull @Schema(description = "删除状态") Integer isDeleted) { if(isDeleted == 1){ diff --git a/src/main/java/com/online/edu/entity/course/CourseType.java b/src/main/java/com/online/edu/entity/course/CourseType.java index 9502899..a8f6f9f 100644 --- a/src/main/java/com/online/edu/entity/course/CourseType.java +++ b/src/main/java/com/online/edu/entity/course/CourseType.java @@ -1,7 +1,6 @@ package com.online.edu.entity.course; import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @@ -26,6 +25,9 @@ public class CourseType implements Serializable { */ private String courseType; - @TableField(exist = false) - private static final long serialVersionUID = 1L; + /** + * 已删除 + */ + private Integer isDeleted; + } \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/course/vo/CourseTypeQueryVO.java b/src/main/java/com/online/edu/entity/course/vo/CourseTypeQueryVO.java new file mode 100644 index 0000000..a88d109 --- /dev/null +++ b/src/main/java/com/online/edu/entity/course/vo/CourseTypeQueryVO.java @@ -0,0 +1,21 @@ +package com.online.edu.entity.course.vo; + +import com.online.edu.common.PageParam; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +@EqualsAndHashCode(callSuper = true) +@Data +@Accessors(chain = true) +@ToString(callSuper = true) +public class CourseTypeQueryVO extends PageParam implements Serializable { + /** + * 课程类型 + */ + private String courseType; + +} \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/message/Message.java b/src/main/java/com/online/edu/entity/message/Message.java index adf4d9c..2991ae9 100644 --- a/src/main/java/com/online/edu/entity/message/Message.java +++ b/src/main/java/com/online/edu/entity/message/Message.java @@ -19,7 +19,7 @@ public class Message implements Serializable { * 消息ID */ @TableId - private Long id; + private String id; /** * 消息标题 @@ -34,12 +34,12 @@ public class Message implements Serializable { /** * 发送者id */ - private Long senderId; + private String senderId; /** * 接收者ID */ - private Long receiverId; + private String receiverId; /** * 是否发送{0:未发送,1:已发送} diff --git a/src/main/java/com/online/edu/entity/message/MessageTemplate.java b/src/main/java/com/online/edu/entity/message/MessageTemplate.java index cbedfe0..cf651c9 100644 --- a/src/main/java/com/online/edu/entity/message/MessageTemplate.java +++ b/src/main/java/com/online/edu/entity/message/MessageTemplate.java @@ -1,12 +1,12 @@ package com.online.edu.entity.message; -import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + import java.io.Serializable; import java.util.Date; -import lombok.Data; /** * 站内信模板表 @@ -19,7 +19,7 @@ public class MessageTemplate implements Serializable { * 主键 */ @TableId - private Long id; + private String id; /** * 模板名称 diff --git a/src/main/java/com/online/edu/entity/message/SystemNotifyMessage.java b/src/main/java/com/online/edu/entity/message/SystemNotifyMessage.java deleted file mode 100644 index fce048d..0000000 --- a/src/main/java/com/online/edu/entity/message/SystemNotifyMessage.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.online.edu.entity.message; - -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import java.io.Serializable; -import java.util.Date; -import lombok.Data; - -/** - * 站内信消息表 - * @TableName system_notify_message - */ -@TableName(value ="system_notify_message") -@Data -public class SystemNotifyMessage implements Serializable { - /** - * 用户ID - */ - @TableId - private Long id; - - /** - * 用户id - */ - private Long userId; - - /** - * 模版编号 - */ - private Long templateId; - - /** - * 模版发送人名称 - */ - private String templateNickname; - - /** - * 模版内容 - */ - private String templateContent; - - /** - * 模版类型 - */ - private Integer templateType; - - /** - * 模版参数 - */ - private String templateParams; - - /** - * 是否已读 - */ - private Integer readStatus; - - /** - * 创建时间 - */ - private Date createTime; - - /** - * 更新时间 - */ - private Date updateTime; - - /** - * 是否删除 - */ - private Integer deleted; - - @TableField(exist = false) - private static final long serialVersionUID = 1L; -} \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/message/vo/MessageGroupSendVO.java b/src/main/java/com/online/edu/entity/message/vo/MessageGroupSendVO.java new file mode 100644 index 0000000..7ad9d66 --- /dev/null +++ b/src/main/java/com/online/edu/entity/message/vo/MessageGroupSendVO.java @@ -0,0 +1,43 @@ +package com.online.edu.entity.message.vo; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; + +/** + * 消息表 + * + * @TableName message + */ +@TableName(value = "message") +@Data +public class MessageGroupSendVO implements Serializable { + /** + * 消息ID + */ + @TableId + private String id; + + /** + * 消息标题 + */ + private String messageTitle; + + /** + * 消息内容 + */ + private String messageBody; + + /** + * 发送者id + */ + private String senderId; + + /** + * 接收者用户角色 + */ + private String roleId; + +} \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/message/vo/MessageSendVO.java b/src/main/java/com/online/edu/entity/message/vo/MessageSendVO.java new file mode 100644 index 0000000..9b38ff5 --- /dev/null +++ b/src/main/java/com/online/edu/entity/message/vo/MessageSendVO.java @@ -0,0 +1,44 @@ +package com.online.edu.entity.message.vo; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * 消息表 + * + * @TableName message + */ +@TableName(value = "message") +@Data +public class MessageSendVO implements Serializable { + /** + * 消息ID + */ + @TableId + private String id; + + /** + * 消息标题 + */ + private String messageTitle; + + /** + * 消息内容 + */ + private String messageBody; + + /** + * 发送者id + */ + private String senderId; + + /** + * 接收者用户名 + */ + private List receivers; + +} \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/rbac/UserInfo.java b/src/main/java/com/online/edu/entity/rbac/UserInfo.java index e9f5bce..df9be36 100644 --- a/src/main/java/com/online/edu/entity/rbac/UserInfo.java +++ b/src/main/java/com/online/edu/entity/rbac/UserInfo.java @@ -30,8 +30,7 @@ public class UserInfo implements Serializable { */ @NotNull(message = "[用户ID]不能为空") @Schema(description = "用户ID") - @TableId(value = "id", type = IdType.ASSIGN_ID) - + @TableId(type = IdType.INPUT) private String id; /** * 创建时间 diff --git a/src/main/java/com/online/edu/entity/rbac/UserInfoDAO.java b/src/main/java/com/online/edu/entity/rbac/UserInfoDAO.java index 066b6a9..23c1f83 100644 --- a/src/main/java/com/online/edu/entity/rbac/UserInfoDAO.java +++ b/src/main/java/com/online/edu/entity/rbac/UserInfoDAO.java @@ -10,6 +10,8 @@ import lombok.NoArgsConstructor; import lombok.experimental.Accessors; import org.hibernate.validator.constraints.Length; +import java.util.List; + @Data @AllArgsConstructor @NoArgsConstructor @@ -55,4 +57,14 @@ public class UserInfoDAO { @NotNull(message = "[用户状态]不能为空") @Schema(description = "用户状态") private String status; + + private String phone; + + private String email; + + private String avatar; + + private List roles; + + } diff --git a/src/main/java/com/online/edu/entity/rbac/vo/NewUserVO.java b/src/main/java/com/online/edu/entity/rbac/vo/NewUserVO.java index e2bf234..819366c 100644 --- a/src/main/java/com/online/edu/entity/rbac/vo/NewUserVO.java +++ b/src/main/java/com/online/edu/entity/rbac/vo/NewUserVO.java @@ -18,11 +18,11 @@ import java.util.List; public class NewUserVO { /** - * 用户名,为学/工号 + * 用户名 */ @NotBlank(message = "[用户名]不能为空") @Size(max = 50, message = "编码长度不能超过50") - @Schema(description = "用户名,默认为学/工号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2200000000") + @Schema(description = "用户名", requiredMode = Schema.RequiredMode.REQUIRED, example = "2200000000") private String username; /** @@ -47,12 +47,26 @@ public class NewUserVO { @NotNull(message = "[角色]不能为空") @Size(max = 10) @Schema(description = "角色", requiredMode = Schema.RequiredMode.REQUIRED, example = "['1']") - private List role; + private List roles; /** - * 用户状态 + * 头像 */ - @NotNull(message = "[用户状态]不能为空") - @Schema(description = "用户状态", example = "1") - private Integer status; + @NotNull(message = "[头像]不能为空") + @Schema(description = "头像") + private String avatar; + + /** + * 电话 + */ + @NotNull(message = "[电话]不能为空") + @Schema(description = "电话") + private String phone; + + /** + * 邮箱 + */ + @Schema(description = "邮箱") + private String email; + } \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/rbac/vo/UserBasicInfoVO.java b/src/main/java/com/online/edu/entity/rbac/vo/UserBasicInfoVO.java index 5cd82dc..4aeee9a 100644 --- a/src/main/java/com/online/edu/entity/rbac/vo/UserBasicInfoVO.java +++ b/src/main/java/com/online/edu/entity/rbac/vo/UserBasicInfoVO.java @@ -27,6 +27,7 @@ public class UserBasicInfoVO { @Schema(description = "姓名", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") private String displayName; + private String avatar; private String phone; diff --git a/src/main/java/com/online/edu/entity/rbac/vo/UserInfoVO.java b/src/main/java/com/online/edu/entity/rbac/vo/UserInfoVO.java index 48ba8a3..a20ac0c 100644 --- a/src/main/java/com/online/edu/entity/rbac/vo/UserInfoVO.java +++ b/src/main/java/com/online/edu/entity/rbac/vo/UserInfoVO.java @@ -61,6 +61,7 @@ public class UserInfoVO { private String email; + private String avatar; public UserInfoVO(UserInfoDAO userInfoDAO, List roles) { this.id = userInfoDAO.getId(); diff --git a/src/main/java/com/online/edu/entity/rbac/vo/UserQueryVO.java b/src/main/java/com/online/edu/entity/rbac/vo/UserQueryVO.java new file mode 100644 index 0000000..70b378b --- /dev/null +++ b/src/main/java/com/online/edu/entity/rbac/vo/UserQueryVO.java @@ -0,0 +1,61 @@ +package com.online.edu.entity.rbac.vo; + +import com.online.edu.common.PageParam; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.hibernate.validator.constraints.Range; + +import java.util.Date; + + +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class UserQueryVO extends PageParam { + + + /** + * 用户名 + */ + private String username; + + /** + * 显示名 + */ + private String displayName; + + + /** + * 电话号 + */ + private String phone; + + /** + * 邮箱 + */ + private String email; + + /** + * 已删除 + */ + @Range(min = 0, max = 1) + private Integer isDeleted; + + /** + * 状态 + */ + @Range(min = 0, max = 1) + private Integer status; + + /** + * 创建时间 + */ + private Date oldDate; + + /** + * 更新时间 + */ + private Date newDate; + +} \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/rbac/vo/UserUpdateVO.java b/src/main/java/com/online/edu/entity/rbac/vo/UserUpdateVO.java new file mode 100644 index 0000000..a2427a2 --- /dev/null +++ b/src/main/java/com/online/edu/entity/rbac/vo/UserUpdateVO.java @@ -0,0 +1,42 @@ +package com.online.edu.entity.rbac.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Accessors(chain = true) +public class UserUpdateVO { + + /** + * 用户ID + */ + @NotNull(message = "[用户ID]不能为空") + @Schema(description = "用户ID") + private String id; + + /** + * 用户ID + */ + @NotNull(message = "[用户名]不能为空") + @Schema(description = "用户名") + private String username; + + /** + * 姓名 + */ + @NotNull(message = "[姓名]不能为空") + @Schema(description = "姓名", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") + private String displayName; + + private String phone; + + private String email; + + +} diff --git a/src/main/java/com/online/edu/entity/userInfo/vo/RegisterVO.java b/src/main/java/com/online/edu/entity/userInfo/vo/RegisterVO.java index 8bb75d9..774af7e 100644 --- a/src/main/java/com/online/edu/entity/userInfo/vo/RegisterVO.java +++ b/src/main/java/com/online/edu/entity/userInfo/vo/RegisterVO.java @@ -1,23 +1,26 @@ package com.online.edu.entity.userInfo.vo; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotEmpty; import lombok.Data; @Data public class RegisterVO { //注册对象 @Schema(description = "用户名") + @NotEmpty private String username; @Schema(description = "显示名") + @NotEmpty private String displayName; @Schema(description = "手机号") + @NotEmpty private String mobile; @Schema(description = "密码") + @NotEmpty private String password; - @Schema(description = "验证码") - private String code; } diff --git a/src/main/java/com/online/edu/mapper/course/CourseTypeMapper.java b/src/main/java/com/online/edu/mapper/course/CourseTypeMapper.java index e5fadd4..5664fbb 100644 --- a/src/main/java/com/online/edu/mapper/course/CourseTypeMapper.java +++ b/src/main/java/com/online/edu/mapper/course/CourseTypeMapper.java @@ -1,16 +1,35 @@ package com.online.edu.mapper.course; -import com.online.edu.entity.course.CourseType; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.online.edu.common.PageParam; +import com.online.edu.common.PageResult; +import com.online.edu.entity.course.CourseType; +import com.online.edu.entity.course.vo.CourseTypeQueryVO; /** -* @author Nvnqs -* @description 针对表【course_type(课程类型)】的数据库操作Mapper -* @createDate 2023-06-17 19:44:29 -* @Entity com.online.edu.entity.course.CourseType -*/ + * @author Nvnqs + * @description 针对表【course_type(课程类型)】的数据库操作Mapper + * @createDate 2023-06-17 19:44:29 + * @Entity com.online.edu.entity.course.CourseType + */ public interface CourseTypeMapper extends BaseMapper { + default PageResult selectPage(CourseTypeQueryVO queryVO) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper() + .like(queryVO.getCourseType() != null, CourseType::getCourseType, queryVO.getCourseType()) + .orderByDesc(CourseType::getId); + IPage mpPage = PageParam.buildPage(queryVO); + selectPage(mpPage, wrapper); + // 转换返回 + return new PageResult<>(mpPage.getRecords(), mpPage.getTotal()); + } + + + int addAll(CourseType courseType); + + int updateCourseType(CourseType courseType); } diff --git a/src/main/java/com/online/edu/mapper/message/SystemNotifyMessageMapper.java b/src/main/java/com/online/edu/mapper/message/SystemNotifyMessageMapper.java deleted file mode 100644 index e3b24f0..0000000 --- a/src/main/java/com/online/edu/mapper/message/SystemNotifyMessageMapper.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.online.edu.mapper.message; - -import com.online.edu.entity.message.SystemNotifyMessage; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -/** -* @author Nvnqs -* @description 针对表【system_notify_message(站内信消息表)】的数据库操作Mapper -* @createDate 2023-06-17 14:32:31 -* @Entity com.online.edu.entity.message.SystemNotifyMessage -*/ -public interface SystemNotifyMessageMapper extends BaseMapper { - -} - - - - diff --git a/src/main/java/com/online/edu/mapper/rbac/UserMapper.java b/src/main/java/com/online/edu/mapper/rbac/UserMapper.java index 20ff114..9fb016f 100644 --- a/src/main/java/com/online/edu/mapper/rbac/UserMapper.java +++ b/src/main/java/com/online/edu/mapper/rbac/UserMapper.java @@ -1,12 +1,17 @@ package com.online.edu.mapper.rbac; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.online.edu.common.PageParam; +import com.online.edu.common.PageResult; import com.online.edu.entity.rbac.UserInfo; import com.online.edu.entity.rbac.UserInfoDAO; import com.online.edu.entity.rbac.vo.PermissionMenuVO; import com.online.edu.entity.rbac.vo.PermissionVO; -import com.online.edu.entity.rbac.vo.UserInfoVO; -import jakarta.validation.constraints.NotNull; +import com.online.edu.entity.rbac.vo.UserQueryVO; +import com.online.edu.entity.rbac.vo.UserUpdateVO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -15,7 +20,7 @@ import java.util.List; import java.util.Set; @Mapper -public interface UserMapper { +public interface UserMapper extends BaseMapper { UserInfoDAO getUserByUsername(String username); List getAllByStatusInWithoutPassword(@Param("statusList") Collection statusList); @@ -30,18 +35,46 @@ public interface UserMapper { int updateDisplayNameByUsername(@Param("displayName") String displayName, @Param("username") String username); + int updateEmailAndPhoneAndDisplayNameById(UserUpdateVO userUpdateVO); + int updatePasswordByUsername(@Param("password") String password, @Param("username") String username); int updateStatusByUsername(@Param("status") Integer status, @Param("username") String username); - List getAllByRole(@Param("role_id") String roleId); + List getAllByRole(@Param("role_id") String roleId); - @NotNull(message = "[用户ID]不能为空") String getIdByUsername(@Param("username") String username); + String getIdByUsername(@Param("username") String username); int delById(@Param("id") String id); + + int delLogicById(@Param("id") String id); + + int recoverById(@Param("id") String id); + Set getMenu(@Param("username") String username); String getAvatarById(@Param("id") String id); + + int updateAvatarById(@Param("avatar") String avatar, @Param("id") String id); + + default PageResult selectPage(UserQueryVO queryVO) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper() + .like(queryVO.getUsername() != null, UserInfo::getUsername, queryVO.getUsername()) + .like(queryVO.getDisplayName() != null, UserInfo::getDisplayName, queryVO.getDisplayName()) + .like(queryVO.getPhone() != null, UserInfo::getPhone, queryVO.getPhone()) + .like(queryVO.getEmail() != null, UserInfo::getEmail, queryVO.getEmail()) + .between(queryVO.getOldDate() != null && queryVO.getNewDate() != null, UserInfo::getCreatedAt, queryVO.getOldDate(), queryVO.getNewDate()) + .eq(queryVO.getStatus() != null, UserInfo::getStatus, queryVO.getStatus()) + .eq(queryVO.getStatus() == null, UserInfo::getStatus, 1) + .eq(queryVO.getIsDeleted() != null, UserInfo::getIsDeleted, queryVO.getIsDeleted()) + .eq(queryVO.getIsDeleted() == null, UserInfo::getIsDeleted, 0) + + .orderByDesc(UserInfo::getId); + IPage mpPage = PageParam.buildPage(queryVO); + selectPage(mpPage, wrapper); + // 转换返回 + return new PageResult<>(mpPage.getRecords(), mpPage.getTotal()); + } } diff --git a/src/main/java/com/online/edu/mapper/userInfo/SocialUserMapper.java b/src/main/java/com/online/edu/mapper/userInfo/SocialUserMapper.java deleted file mode 100644 index 5d4b0a7..0000000 --- a/src/main/java/com/online/edu/mapper/userInfo/SocialUserMapper.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.online.edu.mapper.userInfo; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.online.edu.entity.userInfo.SocialUser; - -/** - * @author Nvnqs - * @description 针对表【social_user(第三方登录用户)】的数据库操作Mapper - * @createDate 2023-06-04 17:20:56 - * @Entity com.online.edu.entity.userInfo.SocialUser - */ -public interface SocialUserMapper extends BaseMapper { - - -} - - - - diff --git a/src/main/java/com/online/edu/service/course/CourseTypeService.java b/src/main/java/com/online/edu/service/course/CourseTypeService.java index 724434a..6aef84f 100644 --- a/src/main/java/com/online/edu/service/course/CourseTypeService.java +++ b/src/main/java/com/online/edu/service/course/CourseTypeService.java @@ -1,13 +1,22 @@ package com.online.edu.service.course; -import com.online.edu.entity.course.CourseType; import com.baomidou.mybatisplus.extension.service.IService; +import com.online.edu.common.PageResult; +import com.online.edu.entity.course.CourseType; +import com.online.edu.entity.course.vo.CourseTypeQueryVO; /** -* @author Nvnqs -* @description 针对表【course_type(课程类型)】的数据库操作Service -* @createDate 2023-06-17 19:44:29 -*/ + * @author Nvnqs + * @description 针对表【course_type(课程类型)】的数据库操作Service + * @createDate 2023-06-17 19:44:29 + */ public interface CourseTypeService extends IService { + + boolean addCourseType(CourseType courseType); + + boolean updateCourseType(CourseType courseType); + + PageResult query(CourseTypeQueryVO query); + } diff --git a/src/main/java/com/online/edu/service/course/impl/CourseTypeServiceImpl.java b/src/main/java/com/online/edu/service/course/impl/CourseTypeServiceImpl.java index daa90e3..280240b 100644 --- a/src/main/java/com/online/edu/service/course/impl/CourseTypeServiceImpl.java +++ b/src/main/java/com/online/edu/service/course/impl/CourseTypeServiceImpl.java @@ -1,20 +1,36 @@ package com.online.edu.service.course.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.online.edu.common.PageResult; import com.online.edu.entity.course.CourseType; -import com.online.edu.service.course.CourseTypeService; +import com.online.edu.entity.course.vo.CourseTypeQueryVO; import com.online.edu.mapper.course.CourseTypeMapper; +import com.online.edu.service.course.CourseTypeService; import org.springframework.stereotype.Service; /** -* @author Nvnqs -* @description 针对表【course_type(课程类型)】的数据库操作Service实现 -* @createDate 2023-06-17 19:44:29 -*/ + * @author Nvnqs + * @description 针对表【course_type(课程类型)】的数据库操作Service实现 + * @createDate 2023-06-17 19:44:29 + */ @Service public class CourseTypeServiceImpl extends ServiceImpl - implements CourseTypeService{ + implements CourseTypeService { + + @Override + public boolean addCourseType(CourseType courseType) { + return baseMapper.addAll(courseType) > 0; + } + + @Override + public boolean updateCourseType(CourseType courseType) { + return baseMapper.updateCourseType(courseType) > 0; + } + @Override + public PageResult query(CourseTypeQueryVO query) { + return baseMapper.selectPage(query); + } } diff --git a/src/main/java/com/online/edu/service/message/SystemNotifyMessageService.java b/src/main/java/com/online/edu/service/message/SystemNotifyMessageService.java deleted file mode 100644 index 9f0d7ca..0000000 --- a/src/main/java/com/online/edu/service/message/SystemNotifyMessageService.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.online.edu.service.message; - -import com.baomidou.mybatisplus.extension.service.IService; -import com.online.edu.entity.message.SystemNotifyMessage; - -/** - * @author Nvnqs - * @description 针对表【system_notify_message(站内信消息表)】的数据库操作Service - * @createDate 2023-06-04 17:20:56 - */ -public interface SystemNotifyMessageService extends IService { - -} diff --git a/src/main/java/com/online/edu/service/message/impl/SystemNotifyMessageServiceImpl.java b/src/main/java/com/online/edu/service/message/impl/SystemNotifyMessageServiceImpl.java deleted file mode 100644 index c245a9b..0000000 --- a/src/main/java/com/online/edu/service/message/impl/SystemNotifyMessageServiceImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.online.edu.service.message.impl; - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.online.edu.entity.message.SystemNotifyMessage; -import com.online.edu.mapper.message.SystemNotifyMessageMapper; -import com.online.edu.service.message.SystemNotifyMessageService; -import org.springframework.stereotype.Service; - -/** - * @author Nvnqs - * @description 针对表【system_notify_message(站内信消息表)】的数据库操作Service实现 - * @createDate 2023-06-04 17:20:56 - */ -@Service -public class SystemNotifyMessageServiceImpl extends ServiceImpl - implements SystemNotifyMessageService { - -} - - - - diff --git a/src/main/java/com/online/edu/service/rbac/AuthService.java b/src/main/java/com/online/edu/service/rbac/AuthService.java index 6b6c6c1..fceff3f 100644 --- a/src/main/java/com/online/edu/service/rbac/AuthService.java +++ b/src/main/java/com/online/edu/service/rbac/AuthService.java @@ -3,15 +3,18 @@ package com.online.edu.service.rbac; import com.online.edu.entity.rbac.vo.NewUserVO; import com.online.edu.entity.rbac.vo.UserLoginVO; -import org.springframework.ui.Model; - +import com.online.edu.entity.userInfo.vo.RegisterVO; import jakarta.servlet.http.HttpSession; +import org.springframework.ui.Model; public interface AuthService { boolean addUser(NewUserVO newUserVO); + + boolean addUser(RegisterVO registerVO); + /** * 登录 * @@ -45,5 +48,14 @@ public interface AuthService { * @param username 用户名 * @return 是否成功 */ - boolean updatePassword(String newPassword, String oldPassword,String username); + boolean updatePassword(String newPassword, String oldPassword, String username); + + /** + * 强制修改用户密码 + * + * @param newPassword 新密码 + * @param username 用户名 + * @return 是否成功 + */ + boolean updatePassword(String newPassword, String username); } \ No newline at end of file diff --git a/src/main/java/com/online/edu/service/rbac/RoleInfoService.java b/src/main/java/com/online/edu/service/rbac/RoleInfoService.java index e1a3f49..9fef230 100644 --- a/src/main/java/com/online/edu/service/rbac/RoleInfoService.java +++ b/src/main/java/com/online/edu/service/rbac/RoleInfoService.java @@ -27,4 +27,6 @@ public interface RoleInfoService { List listRole(); List getRoleByUser(String userId); + + List getRoleIdByUser(String userId); } diff --git a/src/main/java/com/online/edu/service/rbac/UserService.java b/src/main/java/com/online/edu/service/rbac/UserService.java index 0be2c03..a23a813 100644 --- a/src/main/java/com/online/edu/service/rbac/UserService.java +++ b/src/main/java/com/online/edu/service/rbac/UserService.java @@ -1,10 +1,11 @@ package com.online.edu.service.rbac; +import com.baomidou.mybatisplus.extension.service.IService; +import com.online.edu.common.PageResult; +import com.online.edu.entity.rbac.UserInfo; import com.online.edu.entity.rbac.UserInfoDAO; -import com.online.edu.entity.rbac.vo.PermissionMenuVO; -import com.online.edu.entity.rbac.vo.PermissionVO; -import com.online.edu.entity.rbac.vo.UserInfoVO; +import com.online.edu.entity.rbac.vo.*; import java.util.Collection; import java.util.List; @@ -14,7 +15,7 @@ import java.util.Set; /** * @author Nvnqs */ -public interface UserService { +public interface UserService extends IService { /** * 获取用户信息 * @@ -39,9 +40,17 @@ public interface UserService { * @param username 用户名 * @return 是否成功 */ - boolean updateDisplayName(String displayName, String username); + boolean update(String displayName, String username); + /** + * 更新用户信息 + * + * @param userUpdateVO 更新信息 + * @return 更新结果 + */ + UserInfoDAO update(UserUpdateVO userUpdateVO); + /** * 修改用户状态 * @@ -56,9 +65,12 @@ public interface UserService { boolean delUserRole(String userId, String roleId); + PageResult query(UserQueryVO userQueryVO); boolean delUser(String username); + boolean recoverUser(String username); + List getAllByStatusIn(Collection statusList); List getAllUnionRole(); @@ -69,5 +81,5 @@ public interface UserService { String getAvatarUrl(String userId); - + String updateAvatarUrl(String url, String userId); } \ No newline at end of file diff --git a/src/main/java/com/online/edu/service/rbac/impl/AuthServiceImpl.java b/src/main/java/com/online/edu/service/rbac/impl/AuthServiceImpl.java index f23999b..15cd4ea 100644 --- a/src/main/java/com/online/edu/service/rbac/impl/AuthServiceImpl.java +++ b/src/main/java/com/online/edu/service/rbac/impl/AuthServiceImpl.java @@ -1,11 +1,13 @@ package com.online.edu.service.rbac.impl; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.online.edu.common.AppException; import com.online.edu.entity.rbac.UserInfo; import com.online.edu.entity.rbac.UserInfoDAO; import com.online.edu.entity.rbac.UserRoleRelation; import com.online.edu.entity.rbac.vo.NewUserVO; import com.online.edu.entity.rbac.vo.UserLoginVO; +import com.online.edu.entity.userInfo.vo.RegisterVO; import com.online.edu.mapper.rbac.UserMapper; import com.online.edu.mapper.rbac.UserRoleRelationMapper; import com.online.edu.service.rbac.AuthService; @@ -52,14 +54,19 @@ public class AuthServiceImpl implements AuthService { newUserVO.setPassword(defaultPassword); } UserInfo user = new UserInfo(); - user.setUsername(newUserVO.getUsername()) + Long id = IdWorker.getId(user); + + user.setId(String.valueOf(id)).setUsername(newUserVO.getUsername()) .setPassword(passwordEncoder.encode(newUserVO.getPassword())) .setDisplayName(newUserVO.getDisplayName()) - .setStatus(newUserVO.getStatus()); + .setStatus(1) + .setPhone(newUserVO.getPhone()) + .setAvatar(newUserVO.getAvatar()) + .setEmail(newUserVO.getEmail()); if (userMapper.addUser(user) == 0) { return false; } else { - for (String roleId : newUserVO.getRole()) { + for (String roleId : newUserVO.getRoles()) { if (userRoleRelationMapper.addAll(new UserRoleRelation().setUserId( userMapper.getIdByUsername(newUserVO.getUsername()) @@ -74,6 +81,34 @@ public class AuthServiceImpl implements AuthService { } } + @Override + public boolean addUser(RegisterVO registerVO) { + if (registerVO.getPassword() == null || registerVO.getPassword().length() == 0) { + registerVO.setPassword(defaultPassword); + } + UserInfo user = new UserInfo(); + Long id = IdWorker.getId(user); + + user.setId(String.valueOf(id)).setUsername(registerVO.getUsername()) + .setPassword(passwordEncoder.encode(registerVO.getPassword())) + .setDisplayName(registerVO.getDisplayName()) + .setPhone(registerVO.getMobile()) + .setStatus(1); + if (userMapper.addUser(user) == 0) { + return false; + } else { + if (userRoleRelationMapper.addAll(new UserRoleRelation().setUserId( + userMapper.getIdByUsername(registerVO.getUsername()) + ).setRoleId("1")) == 0) { + String userId = userMapper.getIdByUsername(registerVO.getUsername()); + userRoleRelationMapper.delByUserId(userId); + userMapper.delById(userId); + return false; + } + } + return true; + } + @Override public String login(UserLoginVO userLoginVO, HttpSession session, Model model) { // // 检查验证码 @@ -133,8 +168,20 @@ public class AuthServiceImpl implements AuthService { @Override public boolean updatePassword(String newPassword, String oldPassword, String username) { + if (newPassword.length() < 6) { + return false; + } String origin = userMapper.getUserByUsername(username).getPassword(); - if(origin == null || !passwordEncoder.matches(oldPassword,origin)){ + if (origin == null || !passwordEncoder.matches(oldPassword, origin)) { + return false; + } + return userMapper.updatePasswordByUsername(passwordEncoder.encode(newPassword), username) > 0; + + } + + @Override + public boolean updatePassword(String newPassword, String username) { + if (newPassword.length() < 6) { return false; } return userMapper.updatePasswordByUsername(passwordEncoder.encode(newPassword), username) > 0; diff --git a/src/main/java/com/online/edu/service/rbac/impl/RoleInfoServiceImpl.java b/src/main/java/com/online/edu/service/rbac/impl/RoleInfoServiceImpl.java index 7ca59a4..3121142 100644 --- a/src/main/java/com/online/edu/service/rbac/impl/RoleInfoServiceImpl.java +++ b/src/main/java/com/online/edu/service/rbac/impl/RoleInfoServiceImpl.java @@ -122,6 +122,14 @@ public class RoleInfoServiceImpl return result; } + @Override + public List getRoleIdByUser(String userId) { + List roles = getRoleByUser(userId); + List result = new ArrayList<>(); + roles.forEach(role -> result.add(role.getId())); + return result; + } + } diff --git a/src/main/java/com/online/edu/service/rbac/impl/UserServiceImpl.java b/src/main/java/com/online/edu/service/rbac/impl/UserServiceImpl.java index e963538..13f4ddf 100644 --- a/src/main/java/com/online/edu/service/rbac/impl/UserServiceImpl.java +++ b/src/main/java/com/online/edu/service/rbac/impl/UserServiceImpl.java @@ -1,11 +1,12 @@ package com.online.edu.service.rbac.impl; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.online.edu.common.PageResult; +import com.online.edu.entity.rbac.UserInfo; import com.online.edu.entity.rbac.UserInfoDAO; import com.online.edu.entity.rbac.UserRoleRelation; -import com.online.edu.entity.rbac.vo.PermissionMenuVO; -import com.online.edu.entity.rbac.vo.PermissionVO; -import com.online.edu.entity.rbac.vo.UserInfoVO; +import com.online.edu.entity.rbac.vo.*; import com.online.edu.mapper.rbac.UserMapper; import com.online.edu.mapper.rbac.UserRoleRelationMapper; import com.online.edu.service.rbac.RoleInfoService; @@ -19,7 +20,7 @@ import java.util.List; import java.util.Set; @Service -public class UserServiceImpl implements UserService { +public class UserServiceImpl extends ServiceImpl implements UserService { @Autowired UserMapper userMapper; @@ -40,10 +41,17 @@ public class UserServiceImpl implements UserService { @Override - public boolean updateDisplayName(String displayName, String username) { + public boolean update(String displayName, String username) { return userMapper.updateDisplayNameByUsername(displayName, username) != 0; } + @Override + public UserInfoDAO update(UserUpdateVO userUpdateVO) { + userMapper.updateEmailAndPhoneAndDisplayNameById(userUpdateVO); + + return userMapper.getUserByUsername(userUpdateVO.getUsername()); + } + @Override public boolean updateStatus(int newStatus, String username) { @@ -65,12 +73,22 @@ public class UserServiceImpl implements UserService { return userRoleRelationMapper.delByUserIdAndRoleId(userId, roleId) > 0; } + @Override + public PageResult query(UserQueryVO userQueryVO) { + return baseMapper.selectPage(userQueryVO); + } + @Override public boolean delUser(String username) { String userId = userMapper.getIdByUsername(username); - userRoleRelationMapper.delByUserId(userId); - return userMapper.delById(userId) > 0; + return userMapper.delLogicById(userId) > 0; + } + + @Override + public boolean recoverUser(String username) { + String userId = userMapper.getIdByUsername(username); + return userMapper.recoverById(userId) > 0; } @Override @@ -103,5 +121,14 @@ public class UserServiceImpl implements UserService { return userMapper.getAvatarById(userId); } + @Override + public String updateAvatarUrl(String url, String userId) { + if (userMapper.updateAvatarById(url, userId) > 0) { + return url; + } else { + return getAvatarUrl(userId); + } + } + } diff --git a/src/main/java/com/online/edu/service/userInfo/SocialUserService.java b/src/main/java/com/online/edu/service/userInfo/SocialUserService.java deleted file mode 100644 index 3a0a1a9..0000000 --- a/src/main/java/com/online/edu/service/userInfo/SocialUserService.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.online.edu.service.userInfo; - -import com.baomidou.mybatisplus.extension.service.IService; -import com.online.edu.entity.userInfo.SocialUser; - -/** - * @author Nvnqs - * @description 针对表【social_user(第三方登录用户)】的数据库操作Service - * @createDate 2023-06-04 17:20:56 - */ -public interface SocialUserService extends IService { - - -} diff --git a/src/main/java/com/online/edu/service/userInfo/impl/SocialUserServiceImpl.java b/src/main/java/com/online/edu/service/userInfo/impl/SocialUserServiceImpl.java deleted file mode 100644 index e604c7b..0000000 --- a/src/main/java/com/online/edu/service/userInfo/impl/SocialUserServiceImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.online.edu.service.userInfo.impl; - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.online.edu.entity.userInfo.SocialUser; -import com.online.edu.mapper.userInfo.SocialUserMapper; -import com.online.edu.service.userInfo.SocialUserService; -import org.springframework.stereotype.Service; - -/** - * @author Nvnqs - * @description 针对表【social_user(第三方登录用户)】的数据库操作Service实现 - * @createDate 2023-06-04 17:20:56 - */ -@Service -public class SocialUserServiceImpl extends ServiceImpl - implements SocialUserService { - -} - - - - diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index eff6693..673da14 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -20,6 +20,9 @@ spring: host: localhost database: 0 port: 6379 + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 mybatis: diff --git a/src/main/resources/mapper/CourseTypeMapper.xml b/src/main/resources/mapper/CourseTypeMapper.xml index 8d00727..73e7d06 100644 --- a/src/main/resources/mapper/CourseTypeMapper.xml +++ b/src/main/resources/mapper/CourseTypeMapper.xml @@ -5,11 +5,22 @@ - - + + id,course_type + + insert into course_type + (course_type, is_deleted) + values (#{courseType,jdbcType=VARCHAR}, 0) + + + + update course_type + set course_type = #{courseType,jdbcType=VARCHAR} + where id = #{id} + diff --git a/src/main/resources/mapper/SocialUserMapper.xml b/src/main/resources/mapper/SocialUserMapper.xml deleted file mode 100644 index 903eeeb..0000000 --- a/src/main/resources/mapper/SocialUserMapper.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - diff --git a/src/main/resources/mapper/SystemNotifyMessageMapper.xml b/src/main/resources/mapper/SystemNotifyMessageMapper.xml deleted file mode 100644 index bbd88d0..0000000 --- a/src/main/resources/mapper/SystemNotifyMessageMapper.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/resources/mapper/UserMapper.xml b/src/main/resources/mapper/UserMapper.xml index b3f7d12..eb9e566 100644 --- a/src/main/resources/mapper/UserMapper.xml +++ b/src/main/resources/mapper/UserMapper.xml @@ -33,22 +33,21 @@ - - - - - - - - - + SELECT id, + username, + status, + display_name, + password, + avatar, + phone, + email FROM online_edu.user_info where username = #{username} limit 1; - + SELECT id, username, status, display_name, avatar, phone, email FROM online_edu.user_info @@ -60,12 +59,12 @@ INNER JOIN online_edu.permission p ON rp.permission_id = p.id WHERE ur.user_id = #{id}; - - insert ignore into online_edu.user_info - (username, password, status, - display_name) - values (#{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{status}, - #{displayName,jdbcType=VARCHAR}) + + insert into online_edu.user_info + (id, username, password, status, + display_name, avatar, phone, email, is_deleted) + values (#{id}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{status}, + #{displayName,jdbcType=VARCHAR}, #{avatar}, #{phone}, #{email}, 0) @@ -83,9 +82,9 @@ set status = #{status} where username = #{username,jdbcType=VARCHAR} - - SELECT id,username, status, display_name + SELECT id,username, status, display_name, avatar, phone, email FROM online_edu.user_info where status in @@ -94,9 +93,9 @@ - - SELECT ui.id, ui.username, ui.status, ui.display_name + SELECT ui.id, ui.username, ui.status, ui.display_name, ui.avatar, ui.phone, ui.email FROM online_edu.user_info ui LEFT JOIN online_edu.user_role_relation urr ON ui.id = urr.user_id LEFT JOIN online_edu.role_info ri ON urr.role_id = ri.id @@ -110,10 +109,15 @@ delete from online_edu.user_info + where id = #{id} + + + update online_edu.user_info + set is_deleted = 1 where id = #{id,jdbcType=NUMERIC} - + SELECT id, username, status, display_name, avatar, phone, email FROM online_edu.user_info where username = #{username,jdbcType=VARCHAR} @@ -136,4 +140,21 @@ from user_info where id = #{id,jdbcType=VARCHAR} + + update user_info + set avatar = #{avatar,jdbcType=VARCHAR} + where id = #{id,jdbcType=VARCHAR} + + + update user_info + set email = #{email,jdbcType=VARCHAR}, + phone = #{phone,jdbcType=VARCHAR}, + display_name = #{displayName,jdbcType=VARCHAR} + where id = #{id,jdbcType=VARCHAR} + + + update online_edu.user_info + set is_deleted = 0 + where id = #{id,jdbcType=NUMERIC} + -- Gitee From 975e9110f3adb5dd0d8c7afa60dd786bed48c39c Mon Sep 17 00:00:00 2001 From: nvnqsr Date: Sun, 25 Jun 2023 13:08:28 +0800 Subject: [PATCH 6/7] update pre final --- .../java/com/online/edu/common/PageParam.java | 4 +- .../edu/common/VerifyCodeException.java | 11 --- .../com/online/edu/config/AlipayConfig.java | 8 +- .../controller/banner/BannerController.java | 95 ++++++++++++++++++ .../course/CourseInfoController.java | 12 ++- .../controller/message/MessageController.java | 85 +++++++++++++--- .../message/MessageTemplateController.java | 38 -------- .../order/CourseElectionController.java | 87 ++++++++++------- .../order/CourseOrderController.java | 79 +++++++++++---- .../edu/controller/rbac/UserController.java | 14 +++ .../resource/CourseSectionController.java | 1 - .../resource/ResourceController.java | 39 +++++++- .../edu/controller/stat/StatController.java | 18 +++- .../Banner.java} | 81 +++++++--------- .../edu/entity/banner/vo/BannerQueryVO.java | 25 +++++ .../online/edu/entity/banner/vo/BannerVO.java | 54 +++++++++++ .../com/online/edu/entity/course/Comment.java | 17 ++++ .../online/edu/entity/course/CourseInfo.java | 2 +- .../edu/entity/course/vo/CommentQueryVO.java | 12 +++ .../edu/entity/course/vo/CourseInfoVO.java | 14 ++- .../edu/entity/course/vo/NewCommentVO.java | 12 ++- .../online/edu/entity/message/Message.java | 2 + .../entity/message/vo/MessageGroupSendVO.java | 43 --------- .../edu/entity/message/vo/MessageSendVO.java | 24 +++-- .../edu/entity/message/vo/MessageVO.java | 96 +++++++++++++++++++ .../order/vo/CourseElectionQueryVO.java | 45 +++++++++ .../edu/entity/order/vo/CourseElectionVO.java | 29 ------ .../entity/order/vo/CourseOrderListVO.java | 86 +++++++++++++++++ .../edu/entity/order/vo/CourseOrderVO.java | 4 - .../edu/entity/resource/LiveResourceVO.java | 7 +- .../online/edu/entity/resource/Resource.java | 1 - .../edu/entity/resource/StaticResource.java | 7 +- .../edu/entity/resource/StaticResourceVO.java | 19 ++-- .../edu/entity/resource/VideoResourceVO.java | 3 +- .../edu/entity/stat/vo/AdminStatVO.java | 52 ++++++++++ .../edu/entity/userInfo/SocialUser.java | 41 -------- .../entity/verification/BaseVerifyCode.java | 30 ------ .../entity/verification/ImageVerifyCode.java | 30 ------ .../edu/mapper/banner/BannerMapper.java | 35 +++++++ .../edu/mapper/course/CommentMapper.java | 3 +- .../edu/mapper/course/CourseInfoMapper.java | 3 + .../edu/mapper/message/MessageMapper.java | 18 ++-- .../mapper/message/MessageTemplateMapper.java | 18 ---- .../mapper/order/CourseElectionMapper.java | 29 +++++- .../edu/mapper/order/CourseOrderMapper.java | 8 +- .../online/edu/mapper/rbac/UserMapper.java | 1 + .../mapper/rbac/UserRoleRelationMapper.java | 3 + .../edu/service/banner/BannerService.java | 24 +++++ .../banner/impl/BannerServiceImpl.java | 60 ++++++++++++ .../edu/service/course/CourseInfoService.java | 6 ++ .../course/impl/CommentServiceImpl.java | 21 +++- .../course/impl/CourseInfoServiceImpl.java | 70 ++++++++++++-- .../edu/service/message/MessageService.java | 15 +++ .../message/MessageTemplateService.java | 13 --- .../message/impl/MessageServiceImpl.java | 50 ++++++++++ .../impl/MessageTemplateServiceImpl.java | 22 ----- .../service/order/CourseElectionService.java | 8 +- .../edu/service/order/CourseOrderService.java | 9 +- .../edu/service/order/impl/AlipayService.java | 18 ++-- .../order/impl/CourseElectionServiceImpl.java | 58 +++++++++-- .../order/impl/CourseOrderServiceImpl.java | 34 +++++-- .../online/edu/service/rbac/UserService.java | 2 + .../service/rbac/impl/AuthServiceImpl.java | 5 +- .../service/rbac/impl/UserServiceImpl.java | 12 +++ .../edu/service/resource/ResourceService.java | 5 + .../edu/service/resource/VideoService.java | 17 +++- .../resource/impl/ResourceServiceImpl.java | 10 ++ .../resource/impl/VideoServiceImpl.java | 3 +- .../online/edu/service/stat/StatService.java | 3 + .../service/stat/impl/StatServiceImpl.java | 44 ++++++++- .../com/online/edu/utils/ValidationUtils.java | 4 +- src/main/resources/application.yml | 2 +- src/main/resources/mapper/BannerMapper.xml | 23 +++++ .../resources/mapper/CourseElectionMapper.xml | 4 +- .../resources/mapper/CourseInfoMapper.xml | 9 +- .../resources/mapper/CourseOrderMapper.xml | 17 +++- src/main/resources/mapper/MessageMapper.xml | 39 ++++++-- .../mapper/MessageTemplateMapper.xml | 22 ----- .../resources/mapper/StaticResourceMapper.xml | 3 +- src/main/resources/mapper/UserMapper.xml | 1 + .../mapper/UserRoleRelationMapper.xml | 5 + 81 files changed, 1423 insertions(+), 560 deletions(-) delete mode 100644 src/main/java/com/online/edu/common/VerifyCodeException.java create mode 100644 src/main/java/com/online/edu/controller/banner/BannerController.java delete mode 100644 src/main/java/com/online/edu/controller/message/MessageTemplateController.java rename src/main/java/com/online/edu/entity/{message/MessageTemplate.java => banner/Banner.java} (36%) create mode 100644 src/main/java/com/online/edu/entity/banner/vo/BannerQueryVO.java create mode 100644 src/main/java/com/online/edu/entity/banner/vo/BannerVO.java delete mode 100644 src/main/java/com/online/edu/entity/message/vo/MessageGroupSendVO.java create mode 100644 src/main/java/com/online/edu/entity/message/vo/MessageVO.java create mode 100644 src/main/java/com/online/edu/entity/order/vo/CourseElectionQueryVO.java delete mode 100644 src/main/java/com/online/edu/entity/order/vo/CourseElectionVO.java create mode 100644 src/main/java/com/online/edu/entity/order/vo/CourseOrderListVO.java create mode 100644 src/main/java/com/online/edu/entity/stat/vo/AdminStatVO.java delete mode 100644 src/main/java/com/online/edu/entity/userInfo/SocialUser.java delete mode 100644 src/main/java/com/online/edu/entity/verification/BaseVerifyCode.java delete mode 100644 src/main/java/com/online/edu/entity/verification/ImageVerifyCode.java create mode 100644 src/main/java/com/online/edu/mapper/banner/BannerMapper.java delete mode 100644 src/main/java/com/online/edu/mapper/message/MessageTemplateMapper.java create mode 100644 src/main/java/com/online/edu/service/banner/BannerService.java create mode 100644 src/main/java/com/online/edu/service/banner/impl/BannerServiceImpl.java delete mode 100644 src/main/java/com/online/edu/service/message/MessageTemplateService.java delete mode 100644 src/main/java/com/online/edu/service/message/impl/MessageTemplateServiceImpl.java create mode 100644 src/main/resources/mapper/BannerMapper.xml delete mode 100644 src/main/resources/mapper/MessageTemplateMapper.xml diff --git a/src/main/java/com/online/edu/common/PageParam.java b/src/main/java/com/online/edu/common/PageParam.java index 34cc0cc..e906eca 100644 --- a/src/main/java/com/online/edu/common/PageParam.java +++ b/src/main/java/com/online/edu/common/PageParam.java @@ -23,7 +23,7 @@ public class PageParam implements Serializable { @Schema(description = "页码,从 1 开始", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @NotNull(message = "页码不能为空") @Min(value = 1, message = "页码最小值为 1") - private Integer pageNo = PAGE_NO; + private Integer current = PAGE_NO; @Schema(description = "每页条数,最大值为 100", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") @NotNull(message = "每页条数不能为空") @@ -38,7 +38,7 @@ public class PageParam implements Serializable { public static Page buildPage(PageParam pageParam, Collection sortingFields) { // 页码 + 数量 - Page page = new Page<>(pageParam.getPageNo(), pageParam.getPageSize()); + Page page = new Page<>(pageParam.getCurrent(), pageParam.getPageSize()); // 排序字段 if (!CollectionUtil.isEmpty(sortingFields)) { page.addOrder(sortingFields.stream().map(sortingField -> SortingField.ORDER_ASC.equals(sortingField.getOrder()) ? diff --git a/src/main/java/com/online/edu/common/VerifyCodeException.java b/src/main/java/com/online/edu/common/VerifyCodeException.java deleted file mode 100644 index 39666fb..0000000 --- a/src/main/java/com/online/edu/common/VerifyCodeException.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.online.edu.common; - - -import org.springframework.security.core.AuthenticationException; - -public class VerifyCodeException extends AuthenticationException { - - public VerifyCodeException(String detail) { - super(detail); - } -} diff --git a/src/main/java/com/online/edu/config/AlipayConfig.java b/src/main/java/com/online/edu/config/AlipayConfig.java index 41537a4..82f49d1 100644 --- a/src/main/java/com/online/edu/config/AlipayConfig.java +++ b/src/main/java/com/online/edu/config/AlipayConfig.java @@ -20,14 +20,12 @@ public class AlipayConfig { config.signType = "RSA2"; - config.appId = "9021000122682309"; + config.appId = "2021000122667727"; // 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中 - 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.merchantPrivateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC328PNsJULeV9L5P1vjgDPW3y9PgkDIXddDMgYbBWAu3GK40SZnmN+GAzGuobuAU6Um28aq4v4j4kLdilb6IdkLj/dEjhXSfJL9RmKOFyV2AevpFAcqhKG4z01DQhJ+KFTxFTxi5SlzfP/N3iXiu98Ju+1jHZK7CnX1AKo4GQeCVpGM7fEU3idhRIfMIJVEphNXxyCY2HU6P8QHKVzSTfYgttR+Snugup+mPk/BzNgkwu7BwnqBdRDA7qoc+4c43/knMZ3M/0y59DSZas1fYxYhzgOUbKfgL/LzvrJRxGMrCQMD4QW0LYNd/qgAMC9wDNsP8azjBp2v7iWSpMoA0GhAgMBAAECggEAaiVKadnkcndj+SD+4ASPmycqYOcLtO8BRos2ikL8NxIAfzquRDIZJpcj6SeO9qFyiIEkJ7WaXaogaKmTPyiD4eaBoFQAiwR6Cjg6wn2/lhLefRzT03issYtHrvUTMAGGwiG7GKiI7SB2GYYg7PydPoQMKDgrox2tGpmf33eM1Xl85/ncU3ri1BY4Zqd+jXOWkog5PhLVfeljxPkZ8J2CbmJXqfuZpfTavQHO7C5gdN7XMP1r6UzBtw7318Tv4lSBjp4LiosNDhtCUxEBSx/+rjELE7PZCMBsq/ZxR8gfpcTvCsKA0VBiJn67Yh4q+2XJA9VVecUbSTVSO3xs3mbhAQKBgQDxKwPk5mpbFyeRSXI2rpzEm1kZQNgdeYjegrsghA2CVm9R0QvJN8dmn2wG8rYRiKzva4btsKr0JOfXx6itf4qW6rwVfqUOMmOtlHxe8VxUUgRrBhSX1kyTdQhVzN4m/AC4ah2aFHzrlY3Fe6Uxf5bCJDHooeRUvQdOYXztmifE2QKBgQDDKnWX1K/i1GJYLbrLyu2jzfY8X3n52B8wV32Cz9evsKYFiVlktXGLRlcqxIAHtFdfrKaymepZa6SmIKj900Gppt/kTsRqRYAoBDcNBCscs/ClUvFtoBVdUo9YDfcIupaMaM1Tgaf2zp9cyQhbWadleHTBr0lkd95/eSZAnNpGCQKBgQDBUoEJoacKJBKExYJ30Rs8A2e19aQIZJ9R9yv4EcMegxkzVccD4uHGIu+e1jsa7RvrxJ9htCgmE9uBvrw5cC7xcXOaK242ZjA/OfNEzGf988002afyW0gBQGSRGuvOBl6xdecK13eYBcei0c4HUsbQE+GqIPR+9RSBQWa6tMNCaQKBgFGD8XvKJPCb/ruP1h56kslBJGDRDBRTtasuT8kMYK0MHjvfw0uyEUu3xH6jdkpBg+D9Lt8YNG7G7A1LROpHi3x9q7QjRhyRDNcp84hnPk6Nxax3uUktfN7utdp0csLdlDXvLBt94xbN9Hf/q5LkHmveZP3k5cWl33PkuRpxqSVpAoGACFT9q+i2M7kjZzw26JN5XOMwsSdp6hH11vN7zRr8WbZPqm0mq5toPsNPZIsJFN6UsR6NQk8iBBBj6vWJLWv6vGiQICr0/OiBF5P1GwMnshMM9iodH63aWYMNc9BuMkdAA0AG4nGxVZzlbLXlPSXl93q4U6psQJ7UOJLM48qWmRM="; //注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可 - config.alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuHXKkCpzlrER7wZqPE3hkqB9fYZ9neEgwldrkqcNg8ds6PGTjkpZJKdWBzz89i19Dfqoa2TffVyC2Rz5lYMoeN3WE/KsfySa4zHsKqzEm08ndO8O46xJb/2VbIxsc9cvRH5GEQiHxzWIAZpBEolZgETQyCBrGlcjMyhjG5+XQ22P2Iye/+6qMwQnnz95E6GnZH9hr6Z/Tcc1+PBNJMhGotJrOfnTYabu0KOHIxE0p4G8vRC5TKXEWHj9MeV49piTR5WO8W6LUBQq7Vn1XZ7+ZDuOdYQ4xQXuMAhxnX6HW17d6eJNn4Ir8g6BFt/0jnXoOT4x19mbXq39IUArg6NcUQIDAQAB"; - + config.alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2+PaztqivMGAAEm3+tDyVkfJEwQV2Sf7E9nzBvx2dUOgBxJzN/jjoGNyXvMqyC0AW9sUdAWEWgbZ4ktGgp+l05KdoochkWdirXqipoevWrv5n84OmT3R8YxtcoO3AZivJ3jRTLQPLMLAf9BUDBCO1zYaoNwzka1AfXJTIAzIiCYmbiBHlLJWtk/r69Niv61FloCcLk40IZlE6SdVkQZXaRzmRrYn00A/bBS6qmTJCjadnSce4DR+n1XJZhCK1eGB4cBVgP4pxDAAW5hHfU+5YloOfyPb1oP7L3vL/NiyAisC1Uy86kB+t4lVcrlJKdln+eV3ctQmCuLQLEMUctbVoQIDAQAB"; //可设置异步通知接收服务地址(可选) config.notifyUrl = ""; diff --git a/src/main/java/com/online/edu/controller/banner/BannerController.java b/src/main/java/com/online/edu/controller/banner/BannerController.java new file mode 100644 index 0000000..40540e2 --- /dev/null +++ b/src/main/java/com/online/edu/controller/banner/BannerController.java @@ -0,0 +1,95 @@ +package com.online.edu.controller.banner; + +import com.online.edu.common.CommonResult; +import com.online.edu.common.PageResult; +import com.online.edu.entity.banner.Banner; +import com.online.edu.entity.banner.vo.BannerQueryVO; +import com.online.edu.entity.banner.vo.BannerVO; +import com.online.edu.service.banner.BannerService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import jakarta.validation.constraints.Min; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.io.IOException; +import java.util.List; + +/** + * Banner控制器 + */ +@RestController("AdminHmBannerController") +@RequestMapping("/api/admin/banner") +@Tag(name = "Banner控制器") +@CrossOrigin(value = "*") + +public class BannerController { + + @Autowired + private BannerService bannerService; + + @PostMapping("/list") + @Operation(description = "搜索Banner") + public CommonResult> query(@RequestBody @Valid BannerQueryVO queryVO) { + PageResult result = bannerService.query(queryVO); + if (result != null) { + return CommonResult.success(result); + } else { + return CommonResult.error(400, "搜索失败"); + } + } + + @PostMapping("/create") + @Operation(description = "创建Banner") + public CommonResult create(@RequestBody @Valid BannerVO vo) throws IOException { + Banner banner = vo.build(); + boolean result = bannerService.save(banner); + if (result) { + return CommonResult.success(banner); + } else { + return CommonResult.error(400, "创建Banner失败"); + } + } + + @PostMapping("/update") + @Operation(description = "修改Banner信息") + public CommonResult updateProfile(@RequestBody @Valid BannerVO vo) throws IOException { + Banner banner = vo.build(); + boolean result = bannerService.updateById(banner); + if (result) { + return CommonResult.success(banner); + } else { + return CommonResult.error(400, "创建Banner失败"); + } + } + + + @PostMapping("/disable/{bannerId}") + @Operation(description = "禁用Banner") + public CommonResult disable(@PathVariable("bannerId") @Min(1) Integer bannerId) { + return CommonResult.success(bannerService.disable(bannerId)); + + } + + @PostMapping("/enable/{bannerId}") + @Operation(description = "启用Banner") + public CommonResult enable(@PathVariable("bannerId") @Min(1) Integer bannerId) { + return CommonResult.success(bannerService.enable(bannerId)); + + } + + @PostMapping("/delete/{bannerId}") + @Operation(description = "删除Banner") + public CommonResult delete(@PathVariable("bannerId") @Min(1) Integer bannerId) { + return CommonResult.success(bannerService.delete(bannerId)); + + } + + @GetMapping("/get") + @Operation(description = "获取所有banner") + public CommonResult> getBanners() { + return CommonResult.success(bannerService.get()); + } + +} diff --git a/src/main/java/com/online/edu/controller/course/CourseInfoController.java b/src/main/java/com/online/edu/controller/course/CourseInfoController.java index 344bf95..957743d 100644 --- a/src/main/java/com/online/edu/controller/course/CourseInfoController.java +++ b/src/main/java/com/online/edu/controller/course/CourseInfoController.java @@ -13,6 +13,7 @@ import com.online.edu.service.rbac.UserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.security.PermitAll; import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.Authentication; @@ -47,12 +48,14 @@ public class CourseInfoController { return CommonResult.error(400, "添加失败"); } } + @Operation(description = "获取课程信息") @GetMapping("/get") - public CommonResult getCourse(@RequestParam @Valid @Schema(description = "课程ID") String courseId) { - CourseInfo courseInfo= courseInfoService.getById(courseId); + public CommonResult getCourse(@RequestParam @Valid @Schema(description = "课程ID") String courseId) { + CourseInfo courseInfo = courseInfoService.getById(courseId); + if (courseInfo != null) { - return CommonResult.success(courseInfo); + return CommonResult.success(courseInfoService.convertToVO(courseInfo)); } else { return CommonResult.error(400, "查询失败"); } @@ -94,7 +97,7 @@ public class CourseInfoController { if (result != null) { return CommonResult.success(result); } else { - return CommonResult.error(400, "更新失败"); + return CommonResult.error(400, "课程信息没有更新"); } } @@ -125,6 +128,7 @@ public class CourseInfoController { @Operation(description = "获取课程类型列表") @GetMapping("/type") + @PermitAll public CommonResult> getCourseType() { List types = typeService.list(); if (types != null) { diff --git a/src/main/java/com/online/edu/controller/message/MessageController.java b/src/main/java/com/online/edu/controller/message/MessageController.java index 88513e7..345b83d 100644 --- a/src/main/java/com/online/edu/controller/message/MessageController.java +++ b/src/main/java/com/online/edu/controller/message/MessageController.java @@ -2,15 +2,18 @@ package com.online.edu.controller.message; import com.online.edu.common.CommonResult; -import com.online.edu.entity.message.Message; +import com.online.edu.entity.message.vo.MessageVO; import com.online.edu.service.message.MessageService; -import com.online.edu.service.order.CourseElectionService; +import com.online.edu.service.rbac.UserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.*; +import java.util.HashMap; +import java.util.List; + @Tag(name = "消息控制") @RestController @RequestMapping("/message") @@ -18,19 +21,77 @@ import org.springframework.web.bind.annotation.*; public class MessageController { @Autowired private MessageService messageService; + @Autowired - private CourseElectionService courseElectionService; + private UserService userService; - @Operation(description = "添加消息") - @PostMapping("/add") - public CommonResult addCourse(@RequestBody @Valid Message message) { - //TODO:建立VO - boolean success = messageService.save(message); + @Operation(description = "查看消息") + @GetMapping("/list") + public CommonResult> list(Authentication authentication) { + String username = authentication.getName(); + if (username == null) { + return CommonResult.error(401, "未登录"); + } + String userId = userService.getUserByUsername(username).getId(); + List messages = messageService.listRecieved(userId); + if (messages != null) { + return CommonResult.success(messages); + } + return CommonResult.error(400, "查看消息失败"); + } + + @Operation(description = "检查是否有未读消息") + @GetMapping("/check") + public CommonResult> checkCount(Authentication authentication) { + String username = authentication.getName(); + if (username == null) { + return CommonResult.error(401, "未登录"); + } + String userId = userService.getUserByUsername(username).getId(); + Long messages = messageService.countUnread(userId); + if (messages != null) { + return CommonResult.success("count", messages); + } + return CommonResult.error(400, "查看消息失败"); + } + + @Operation(description = "标记消息为已读") + @GetMapping("/read") + public CommonResult markAsRead(Authentication authentication) { + String username = authentication.getName(); + if (username == null) { + return CommonResult.error(401, "未登录"); + } + String userId = userService.getUserByUsername(username).getId(); + Long messages = messageService.markAsRead(userId); + return CommonResult.success("标记为已读"); + } + + @Operation(description = "删除单条消息") + @DeleteMapping("/delete/{id}") + public CommonResult delete(@PathVariable("id") String id, Authentication authentication) { + String username = authentication.getName(); + if (username == null) { + return CommonResult.error(401, "未登录"); + } + String userId = userService.getUserByUsername(username).getId(); + boolean success = messageService.delete(id, userId); if (success) { - return CommonResult.success(message); - } else { - return CommonResult.error(400, "添加失败"); + return CommonResult.success("已移除" + id); + } + return CommonResult.error(400, "移除失败"); + } + + @Operation(description = "清空所有消息") + @DeleteMapping("/clear") + public CommonResult clear(Authentication authentication) { + String username = authentication.getName(); + if (username == null) { + return CommonResult.error(401, "未登录"); } + String userId = userService.getUserByUsername(username).getId(); + boolean messages = messageService.clear(userId); + return CommonResult.success("标记为已读"); } } diff --git a/src/main/java/com/online/edu/controller/message/MessageTemplateController.java b/src/main/java/com/online/edu/controller/message/MessageTemplateController.java deleted file mode 100644 index 01ce006..0000000 --- a/src/main/java/com/online/edu/controller/message/MessageTemplateController.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.online.edu.controller.message; - - -import com.online.edu.common.CommonResult; -import com.online.edu.entity.message.MessageTemplate; -import com.online.edu.service.message.MessageTemplateService; -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 org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -@Tag(name = "消息模板控制") -@RestController -@RequestMapping("/admin/messageTemplate") -@CrossOrigin(value = "*") -public class MessageTemplateController { - @Autowired - private MessageTemplateService messageTemplateService; - @Autowired - private CourseElectionService courseElectionService; - - @Operation(description = "添加消息模板") - @PostMapping("/add") - public CommonResult addCourse(@RequestBody @Valid MessageTemplate messageTemplate) { - //TODO:建立VO - boolean success = messageTemplateService.save(messageTemplate); - if (success) { - return CommonResult.success(messageTemplate); - } else { - return CommonResult.error(400, "添加失败"); - } - } - -} - - 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 ecf5f88..0163312 100644 --- a/src/main/java/com/online/edu/controller/order/CourseElectionController.java +++ b/src/main/java/com/online/edu/controller/order/CourseElectionController.java @@ -3,18 +3,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.vo.CourseElectionVO; +import com.online.edu.entity.order.CourseOrder; import com.online.edu.service.order.CourseElectionService; +import com.online.edu.service.order.CourseOrderService; +import com.online.edu.service.order.impl.AlipayService; +import com.online.edu.service.rbac.UserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import jakarta.validation.constraints.NotEmpty; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.List; - @Tag(name = "选课控制") @RestController @RequestMapping("/course/election") @@ -24,51 +25,63 @@ public class CourseElectionController { @Autowired private CourseElectionService courseElectionService; + @Autowired + private AlipayService alipayService; + + @Autowired + private UserService userService; + + @Autowired + private CourseOrderService courseOrderService; + @Operation(description = "添加选课记录") - @PostMapping("/add") - public CommonResult addCourse(@RequestBody @Valid CourseElectionVO courseElectionvo) { - CourseElection courseElection = courseElectionvo.buildCourseElection(); + @PostMapping("/election") + public CommonResult electCourse(@RequestParam @NotEmpty String courseId, Authentication authentication) { + String username = authentication.getName(); + if (username == null) { + return CommonResult.error(401, "未登录"); + } + String studentId = userService.getUserByUsername(username).getId(); + + CourseElection courseElection = courseElectionService.lambdaQuery().eq(CourseElection::getCourseId, courseId) + .eq(CourseElection::getStudentId, studentId).one(); + if (courseElection != null) { + if (courseElection.getStatus() == 0) { + return CommonResult.success(courseOrderService.lambdaQuery() + .eq(CourseOrder::getSerialNumber, courseElection.getSerialNumber()).one()); + } else { + return CommonResult.error(400, "已经完成支付"); + } + } - boolean success = courseElectionService.save(courseElection); - if (success) { - return CommonResult.success(courseElection); + CourseOrder result = courseElectionService.electCourse(courseId, studentId); + if (result != null) { + return CommonResult.success(result); } else { return CommonResult.error(400, "添加失败"); } } - /** - * 根据id查询选课结果 - */ - @GetMapping("/selectbyid") - public CommonResult> selectCoursebyid(@RequestBody String studentid ){ - List courselist= new ArrayList<>(); - courselist.add(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查询选课结果 + * 根据课程id与学生id查询选课结果 */ - @GetMapping("/selectbycourse") - public CommonResult> selectCoursebycourse(@RequestBody Long courseid ){ - List courselist=courseElectionService.getByCourse(courseid); - if(courselist.isEmpty()){ - return CommonResult.error(400,"查询失败"); + @GetMapping("/inCourse") + public CommonResult check(@RequestParam @Valid String courseId, Authentication authentication) throws Exception { + String username = authentication.getName(); + if (username == null) { + return CommonResult.error(401, "未登录"); } - for(CourseElection e:courselist){ - if(e.getStatus() == 0 && e.getPrice().compareTo(BigDecimal.ZERO) != 0 ){ - courselist.remove(e); - } + String studentId = userService.getUserByUsername(username).getId(); + CourseElection election = courseElectionService.lambdaQuery().eq(CourseElection::getCourseId, courseId) + .eq(CourseElection::getStudentId, studentId).one(); + if (election == null) { + return CommonResult.success(false); } - return CommonResult.success(courselist); + alipayService.queryTradeStatus(election.getSerialNumber()); + + return CommonResult.success(election.getStatus() == 1); } 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 4d98485..445812f 100644 --- a/src/main/java/com/online/edu/controller/order/CourseOrderController.java +++ b/src/main/java/com/online/edu/controller/order/CourseOrderController.java @@ -2,21 +2,26 @@ package com.online.edu.controller.order; import com.online.edu.common.CommonResult; +import com.online.edu.common.PageResult; import com.online.edu.entity.order.CourseElection; import com.online.edu.entity.order.CourseOrder; +import com.online.edu.entity.order.vo.CourseElectionQueryVO; +import com.online.edu.entity.order.vo.CourseOrderListVO; 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 com.online.edu.service.rbac.UserService; import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Schema; 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.security.core.Authentication; import org.springframework.web.bind.annotation.*; import java.math.BigDecimal; +import java.util.List; @Tag(name = "订单控制") @RestController @@ -24,49 +29,83 @@ import java.math.BigDecimal; @CrossOrigin(value = "*") public class CourseOrderController { + @Autowired private CourseElectionService courseElectionService; @Autowired - private CourseOrderService courseOrderService; + private AlipayService alipayService; @Autowired - private AlipayService alipayService; + private UserService userService; - @Operation(description = "添加订单") - @GetMapping("/create") - public CommonResult add(@RequestParam @NotNull @Schema(description = "选课ID") String electionId) { - CourseElection election = courseElectionService.getById(electionId); - CourseOrder courseOrder=courseOrderService.buildCourseOrder(election); - boolean success = courseOrderService.save(courseOrder); - if (success) { - return CommonResult.success(courseOrder); - } else { - return CommonResult.error(400, "添加失败"); - } - } + @Autowired + private CourseOrderService courseOrderService; /** * 支付 */ @Operation(description = "支付") - @GetMapping("/topay") - @ResponseBody + @PostMapping("/topay") public CommonResult toPay(@RequestBody @Valid CourseOrderVO courseOrderVO) throws Exception { - String subject = "购买课程"; + String subject = "course"; String serialNumber = courseOrderVO.getSerialNumber(); - BigDecimal money=courseOrderVO.getPrice(); + BigDecimal money = courseOrderService.lambdaQuery() + .eq(CourseOrder::getSerialNumber, courseOrderVO.getSerialNumber()).one().getPrice(); String form = alipayService.toPay(subject, serialNumber, money); return CommonResult.success(form); } + + /** + * 根据id查询结果 + */ + @GetMapping("/selectbyid") + public CommonResult> selectCoursebyid(Authentication authentication) { + + String username = authentication.getName(); + if (username == null) { + return CommonResult.error(401, "未登录"); + } + String studentId = userService.getUserByUsername(username).getId(); + + List elections = courseElectionService.lambdaQuery() + .eq(CourseElection::getStudentId, studentId).list(); + if (elections != null) { + + + return CommonResult.success(courseOrderService.buildVO(elections)); + } else { + return CommonResult.error(400, "查询失败"); + } + } + + /** + * 查询全部结果 + */ + + @PostMapping("/list") + public CommonResult> query(@RequestBody @Valid CourseElectionQueryVO queryVO) { + PageResult courses = courseOrderService.query(queryVO); + List elections = courses.getList(); + if (elections != null) { + List result = courseOrderService.buildVO(elections); + + return CommonResult.success(new PageResult<>(result, courses.getTotal())); + } else { + return CommonResult.error(400, "查询失败"); + } + + } + + /** * 根据订单号查询支付结果 */ - @GetMapping("/query") + @PostMapping("/query") @Operation(description = "根据订单号查询支付结果") public Object queryTradeStatus(@NotNull String serialNumber) throws Exception { return alipayService.queryTradeStatus(serialNumber); diff --git a/src/main/java/com/online/edu/controller/rbac/UserController.java b/src/main/java/com/online/edu/controller/rbac/UserController.java index f4da683..8f2dbfd 100644 --- a/src/main/java/com/online/edu/controller/rbac/UserController.java +++ b/src/main/java/com/online/edu/controller/rbac/UserController.java @@ -85,6 +85,20 @@ public class UserController { } + @Operation(description = "查看用户信息") + @GetMapping("/getById") + public CommonResult getById(@RequestParam @Valid + @Schema(description = "待查看用户Id") String userId) { + + UserInfo result = userService.getById(userId); + if (result != null) { + result.setPassword(null); + return CommonResult.success(result); + } else { + return CommonResult.error(400, "查看用户信息失败"); + } + } + @Operation(description = "查看用户信息") @GetMapping("/get") public CommonResult get(@RequestParam(required = false) @Valid diff --git a/src/main/java/com/online/edu/controller/resource/CourseSectionController.java b/src/main/java/com/online/edu/controller/resource/CourseSectionController.java index 013ffe9..c905593 100644 --- a/src/main/java/com/online/edu/controller/resource/CourseSectionController.java +++ b/src/main/java/com/online/edu/controller/resource/CourseSectionController.java @@ -30,7 +30,6 @@ public class CourseSectionController { @Operation(description = "添加课程章节") @PostMapping("/add") public CommonResult> addCourseSection(@RequestBody @Valid CourseSection section) { - //TODO:建立VO boolean success = courseSectionService.save(section); if (success) { return CommonResult.success(courseSectionService.listByCourseId(section.getCourseId(),null)); diff --git a/src/main/java/com/online/edu/controller/resource/ResourceController.java b/src/main/java/com/online/edu/controller/resource/ResourceController.java index 38d6eb3..3c94200 100644 --- a/src/main/java/com/online/edu/controller/resource/ResourceController.java +++ b/src/main/java/com/online/edu/controller/resource/ResourceController.java @@ -36,7 +36,6 @@ public class ResourceController { @Operation(description = "添加静态资源") @PostMapping("/add/static") public CommonResult addStatic(@RequestBody @Valid StaticResource resource) { - //TODO:建立VO boolean success = resourceService.addStatic(resource); if (success) { return CommonResult.success(resource); @@ -45,11 +44,33 @@ public class ResourceController { } } + @Operation(description = "更新静态资源") + @PostMapping("/update/static") + public CommonResult updateStatic(@RequestBody @Valid StaticResource resource) { + boolean success = resourceService.updateStatic(resource); + if (success) { + return CommonResult.success(resource); + } else { + return CommonResult.error(400, "更新失败"); + } + } + + + @Operation(description = "删除静态资源") + @DeleteMapping("/del/static") + public CommonResult delStatic(@RequestParam @Valid String resourceId) { + boolean success = resourceService.delStatic(resourceId); + if (success) { + return CommonResult.success(resourceId); + } else { + return CommonResult.error(400, "删除失败"); + } + } + @Operation(description = "添加直播资源") @PostMapping("/add/live") public CommonResult addLive(@RequestBody @Valid LiveResource resource) { - //TODO:建立VO boolean success = resourceService.addLive(resource); if (success) { return CommonResult.success(resource); @@ -61,7 +82,6 @@ public class ResourceController { @Operation(description = "添加作业资源") @PostMapping("/add/homework") public CommonResult addHomework(@RequestBody @Valid HomeworkResource resource) { - //TODO:建立VO boolean success = resourceService.addHomework(resource); if (success) { return CommonResult.success(resource); @@ -73,9 +93,18 @@ public class ResourceController { @Operation(description = "显示章节资源") @GetMapping("/list") - public CommonResult> list(@RequestParam @Schema(description = "对应课程章节",requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull String sectionId) { + public CommonResult> list(@RequestParam @Schema(description = "对应课程章节", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull String sectionId) { + return CommonResult.success(resourceService.getResourcesBySectionId(sectionId)); + } + + + @Operation(description = "删除静态资源") + @GetMapping("/delete/static") + public CommonResult> deleteStatic(@RequestParam @Schema(description = "资源Id", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull String sectionId) { return CommonResult.success(resourceService.getResourcesBySectionId(sectionId)); } + } diff --git a/src/main/java/com/online/edu/controller/stat/StatController.java b/src/main/java/com/online/edu/controller/stat/StatController.java index 048020a..fdb393a 100644 --- a/src/main/java/com/online/edu/controller/stat/StatController.java +++ b/src/main/java/com/online/edu/controller/stat/StatController.java @@ -1,6 +1,7 @@ package com.online.edu.controller.stat; import com.online.edu.common.CommonResult; +import com.online.edu.entity.stat.vo.AdminStatVO; import com.online.edu.entity.stat.vo.TeacherStatVO; import com.online.edu.service.rbac.UserService; import com.online.edu.service.stat.StatService; @@ -23,14 +24,29 @@ public class StatController { StatService statService; @Autowired UserService userService; + @Operation(description = "获取教师统计数据") @GetMapping("/teacher") public CommonResult getTeacher(Authentication authentication) { String username = authentication.getName(); - if(username == null){ + if (username == null) { return CommonResult.error(401, "未登录"); } String teacherId = userService.getUserByUsername(username).getId(); return CommonResult.success(statService.getTeacherStat(teacherId)); } + + + @Operation(description = "获取管理员统计数据") + @GetMapping("/admin") + public CommonResult getAdmin(Authentication authentication) { + String username = authentication.getName(); + if (username == null) { + return CommonResult.error(401, "未登录"); + } + String userId = userService.getUserByUsername(username).getId(); + return CommonResult.success(statService.getAdminStat(userId)); + } + + } diff --git a/src/main/java/com/online/edu/entity/message/MessageTemplate.java b/src/main/java/com/online/edu/entity/banner/Banner.java similarity index 36% rename from src/main/java/com/online/edu/entity/message/MessageTemplate.java rename to src/main/java/com/online/edu/entity/banner/Banner.java index cf651c9..a4d2c5e 100644 --- a/src/main/java/com/online/edu/entity/message/MessageTemplate.java +++ b/src/main/java/com/online/edu/entity/banner/Banner.java @@ -1,76 +1,65 @@ -package com.online.edu.entity.message; +package com.online.edu.entity.banner; +import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotEmpty; import lombok.Data; +import lombok.experimental.Accessors; +import org.hibernate.validator.constraints.Length; import java.io.Serializable; import java.util.Date; /** - * 站内信模板表 - * @TableName message_template + * banner表 + * + * @TableName banner */ -@TableName(value ="message_template") +@TableName(value = "banner") +@Accessors(chain = true) @Data -public class MessageTemplate implements Serializable { - /** - * 主键 - */ - @TableId - private String id; - +public class Banner implements Serializable { + @TableField(exist = false) + private static final long serialVersionUID = 1L; /** - * 模板名称 + * ID */ - private String name; - + @TableId(type = IdType.AUTO) + @Min(1) + private Integer id; /** - * 发送人名称 + * 标题 */ - private String nickname; - + @Length(max = 63, message = "标题长度不能超过63个字符") + @NotEmpty + private String title; /** - * 模版内容 + * 图片地址 */ - private String content; - + @NotEmpty + private String imageUrl; /** - * 类型 + * 链接地址 */ - private Integer type; - + private String linkUrl; /** - * 参数数组 + * 排序 */ - private String params; - + @Min(0) + private Integer sort; /** - * 状态 + * 是否可用 */ - private Integer status; - - /** - * 备注 - */ - private String remark; - - /** - * 创建时间 - */ - private Date createdAt; - + private Boolean enable; /** * 更新时间 */ - private Date updatedAt; - + private Date updateTime; /** - * 是否删除 + * 创建时间 */ - private Integer deleted; - - @TableField(exist = false) - private static final long serialVersionUID = 1L; + private Date createTime; } \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/banner/vo/BannerQueryVO.java b/src/main/java/com/online/edu/entity/banner/vo/BannerQueryVO.java new file mode 100644 index 0000000..b2f6bbe --- /dev/null +++ b/src/main/java/com/online/edu/entity/banner/vo/BannerQueryVO.java @@ -0,0 +1,25 @@ +package com.online.edu.entity.banner.vo; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.online.edu.common.PageParam; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@TableName(value = "banner") +@Data +public class BannerQueryVO extends PageParam { + + /** + * 标题 + */ + private String title; + + /** + * 是否可用 + */ + private Boolean enable; + +} \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/banner/vo/BannerVO.java b/src/main/java/com/online/edu/entity/banner/vo/BannerVO.java new file mode 100644 index 0000000..adad62f --- /dev/null +++ b/src/main/java/com/online/edu/entity/banner/vo/BannerVO.java @@ -0,0 +1,54 @@ +package com.online.edu.entity.banner.vo; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.online.edu.entity.banner.Banner; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotEmpty; +import lombok.Data; + +import java.io.Serializable; + +@TableName(value = "banner") +@Data +public class BannerVO implements Serializable { + @TableField(exist = false) + private static final long serialVersionUID = 1L; + /** + * ID + */ + @TableId(type = IdType.AUTO) + @Min(1) + private Integer id; + /** + * 标题 + */ + @NotEmpty + private String title; + /** + * 图片地址 + */ + @NotEmpty + private String imageUrl; + /** + * 链接地址 + */ + private String linkUrl; + /** + * 排序 + */ + @Min(0) + private Integer sort; + /** + * 是否可用 + */ + + private Boolean enable; + + public Banner build() { + return new Banner().setId(id).setTitle(title).setImageUrl(imageUrl) + .setLinkUrl(linkUrl).setSort(sort).setEnable(enable); + } +} \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/course/Comment.java b/src/main/java/com/online/edu/entity/course/Comment.java index 91266ca..08c5aca 100644 --- a/src/main/java/com/online/edu/entity/course/Comment.java +++ b/src/main/java/com/online/edu/entity/course/Comment.java @@ -30,6 +30,22 @@ public class Comment implements Serializable { * 学生id */ private String studentId; + /** + * 学生头像 + */ + private String memberAvatar; + + /** + * 学生姓名 + */ + private String memberName; + + + /** + * 评分 + */ + private Integer mark; + /** * 内容 */ @@ -46,4 +62,5 @@ public class Comment implements Serializable { * 更新时间 */ private Date updatedAt; + } \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/course/CourseInfo.java b/src/main/java/com/online/edu/entity/course/CourseInfo.java index 3eae521..cbc2d06 100644 --- a/src/main/java/com/online/edu/entity/course/CourseInfo.java +++ b/src/main/java/com/online/edu/entity/course/CourseInfo.java @@ -52,7 +52,7 @@ public class CourseInfo implements Serializable { */ private BigDecimal price; /** - * 课程状态 0:未上线,1:私有开课中,2:公开开课中,3:结课 + * 课程状态 */ private Integer status; /** diff --git a/src/main/java/com/online/edu/entity/course/vo/CommentQueryVO.java b/src/main/java/com/online/edu/entity/course/vo/CommentQueryVO.java index e8a7be0..9c3c70a 100644 --- a/src/main/java/com/online/edu/entity/course/vo/CommentQueryVO.java +++ b/src/main/java/com/online/edu/entity/course/vo/CommentQueryVO.java @@ -8,6 +8,7 @@ import lombok.experimental.Accessors; import java.io.Serializable; import java.util.Date; +import java.util.List; /** * 评论 @@ -20,10 +21,21 @@ import java.util.Date; @ToString(callSuper = true) public class CommentQueryVO extends PageParam implements Serializable { + /** + * 教师id + */ + private String teacherId; + /** * 课程id */ private String courseId; + + /** + * 课程id + */ + private List courses; + /** * 学生id */ diff --git a/src/main/java/com/online/edu/entity/course/vo/CourseInfoVO.java b/src/main/java/com/online/edu/entity/course/vo/CourseInfoVO.java index c9c6dd5..6a9824c 100644 --- a/src/main/java/com/online/edu/entity/course/vo/CourseInfoVO.java +++ b/src/main/java/com/online/edu/entity/course/vo/CourseInfoVO.java @@ -67,12 +67,18 @@ public class CourseInfoVO implements Serializable { * 描述 */ private String description; + + /** + * 课程状态 0:未上线,1:私有开课中,2:公开开课中,3:结课 + */ + private Integer resourceCount; + /** * 价格 */ private BigDecimal price; /** - * 课程状态 0:未上线,1:私有开课中,2:公开开课中,3:结课 + * 课程状态 */ private Integer status; /** @@ -88,13 +94,13 @@ public class CourseInfoVO implements Serializable { */ private Date updatedAt; - public static CourseInfoVO build(CourseInfo courseInfo,String teacherName, String teacherDescription, - String teacherAvatar, String typeName) { + public static CourseInfoVO build(CourseInfo courseInfo, String teacherName, String teacherDescription, + String teacherAvatar, String typeName, Integer resourceCount) { return new CourseInfoVO().setId(courseInfo.getId()).setTeacherId(courseInfo.getTeacherId()) .setTeacherName(teacherName).setTeacherDescription(teacherDescription).setTeacherAvatar(teacherAvatar) .setTitle(courseInfo.getTitle()).setTypeId(courseInfo.getTypeId()).setTypeName(typeName) .setPrice(courseInfo.getPrice()).setCover(courseInfo.getCover()).setPrice(courseInfo.getPrice()) .setCreatedAt(courseInfo.getCreatedAt()).setUpdatedAt(courseInfo.getUpdatedAt()).setStatus(courseInfo.getStatus()) - .setDescription(courseInfo.getDescription()).setIsDeleted(courseInfo.getIsDeleted()); + .setDescription(courseInfo.getDescription()).setIsDeleted(courseInfo.getIsDeleted()).setResourceCount(resourceCount == null ? 0 : resourceCount); } } \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/course/vo/NewCommentVO.java b/src/main/java/com/online/edu/entity/course/vo/NewCommentVO.java index ec5fad0..3742bc5 100644 --- a/src/main/java/com/online/edu/entity/course/vo/NewCommentVO.java +++ b/src/main/java/com/online/edu/entity/course/vo/NewCommentVO.java @@ -1,6 +1,7 @@ package com.online.edu.entity.course.vo; import com.online.edu.entity.course.Comment; +import com.online.edu.entity.rbac.UserInfo; import lombok.Data; import java.io.Serializable; @@ -20,12 +21,19 @@ public class NewCommentVO implements Serializable { * 学生id */ private String studentId; + + /** + * 评分 + */ + private Integer mark; + /** * 内容 */ private String content; - public Comment buildComment(){ - return new Comment().setContent(content).setStudentId(studentId).setCourseId(courseId).setIsDeleted(0); + public Comment buildComment(UserInfo userInfo) { + return new Comment().setContent(content).setStudentId(studentId).setCourseId(courseId).setMark(mark).setIsDeleted(0) + .setMemberAvatar(userInfo.getAvatar()).setMemberName(userInfo.getDisplayName()); } } \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/message/Message.java b/src/main/java/com/online/edu/entity/message/Message.java index 2991ae9..7b910e1 100644 --- a/src/main/java/com/online/edu/entity/message/Message.java +++ b/src/main/java/com/online/edu/entity/message/Message.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; +import lombok.experimental.Accessors; import java.io.Serializable; import java.util.Date; @@ -14,6 +15,7 @@ import java.util.Date; */ @TableName(value ="message") @Data +@Accessors(chain = true) public class Message implements Serializable { /** * 消息ID diff --git a/src/main/java/com/online/edu/entity/message/vo/MessageGroupSendVO.java b/src/main/java/com/online/edu/entity/message/vo/MessageGroupSendVO.java deleted file mode 100644 index 7ad9d66..0000000 --- a/src/main/java/com/online/edu/entity/message/vo/MessageGroupSendVO.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.online.edu.entity.message.vo; - -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; - -import java.io.Serializable; - -/** - * 消息表 - * - * @TableName message - */ -@TableName(value = "message") -@Data -public class MessageGroupSendVO implements Serializable { - /** - * 消息ID - */ - @TableId - private String id; - - /** - * 消息标题 - */ - private String messageTitle; - - /** - * 消息内容 - */ - private String messageBody; - - /** - * 发送者id - */ - private String senderId; - - /** - * 接收者用户角色 - */ - private String roleId; - -} \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/message/vo/MessageSendVO.java b/src/main/java/com/online/edu/entity/message/vo/MessageSendVO.java index 9b38ff5..e0e9e92 100644 --- a/src/main/java/com/online/edu/entity/message/vo/MessageSendVO.java +++ b/src/main/java/com/online/edu/entity/message/vo/MessageSendVO.java @@ -1,25 +1,22 @@ package com.online.edu.entity.message.vo; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; +import com.online.edu.entity.message.Message; import lombok.Data; +import lombok.experimental.Accessors; import java.io.Serializable; +import java.util.ArrayList; +import java.util.Date; import java.util.List; /** * 消息表 * - * @TableName message */ -@TableName(value = "message") @Data +@Accessors(chain = true) public class MessageSendVO implements Serializable { - /** - * 消息ID - */ - @TableId - private String id; + /** * 消息标题 @@ -41,4 +38,13 @@ public class MessageSendVO implements Serializable { */ private List receivers; + public List build() { + List result = new ArrayList<>(); + receivers.forEach(receiver -> { + result.add(new Message().setSenderId(senderId).setReceiverId(receiver).setMessageBody(messageBody) + .setMessageTitle(messageTitle).setDeleted(0).setSendStatus(1).setReadStatus(0) + .setUpdatedAt(new Date()).setCreatedAt(new Date())); + }); + return result; + } } \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/message/vo/MessageVO.java b/src/main/java/com/online/edu/entity/message/vo/MessageVO.java new file mode 100644 index 0000000..95fc720 --- /dev/null +++ b/src/main/java/com/online/edu/entity/message/vo/MessageVO.java @@ -0,0 +1,96 @@ +package com.online.edu.entity.message.vo; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.online.edu.entity.message.Message; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.util.Date; + +/** + * 消息 + */ +@TableName(value = "message") +@Data +@Accessors(chain = true) +public class MessageVO implements Serializable { + /** + * 消息ID + */ + @TableId + private String id; + + /** + * 消息标题 + */ + private String messageTitle; + + /** + * 消息内容 + */ + private String messageBody; + + /** + * 发送者id + */ + private String senderId; + + /** + * 发送者id + */ + private String senderName; + + /** + * 接收者ID + */ + private String receiverId; + + /** + * 是否发送{0:未发送,1:已发送} + */ + private Integer sendStatus; + + /** + * 是否已读{0:未读,1:已读} + */ + private Integer readStatus; + + /** + * 是否删除{0:未删除,1:已删除} + */ + private Integer deleted; + + /** + * 创建时间 + */ + private Date createdAt; + + /** + * 更新时间 + */ + private Date updatedAt; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; + + public MessageVO(Message message, String senderName) { + id = message.getId(); + + messageTitle = message.getMessageTitle(); + messageBody = message.getMessageBody(); + + senderId = message.getSenderId(); + this.senderName = senderName; + receiverId = message.getReceiverId(); + + sendStatus = message.getSendStatus(); + readStatus = message.getReadStatus(); + deleted = message.getDeleted(); + createdAt = message.getCreatedAt(); + updatedAt = message.getUpdatedAt(); + + } +} \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/order/vo/CourseElectionQueryVO.java b/src/main/java/com/online/edu/entity/order/vo/CourseElectionQueryVO.java new file mode 100644 index 0000000..bd5e1ee --- /dev/null +++ b/src/main/java/com/online/edu/entity/order/vo/CourseElectionQueryVO.java @@ -0,0 +1,45 @@ +package com.online.edu.entity.order.vo; + +import com.online.edu.common.PageParam; +import lombok.*; +import lombok.experimental.Accessors; + +import java.util.Date; + +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Data +@AllArgsConstructor +@NoArgsConstructor +@Accessors(chain = true) +public class CourseElectionQueryVO extends PageParam { + + /** + * 订单号 + */ + private String serialNumber; + + + /** + * 学生昵称 + */ + private String studentName; + + /** + * 订单状态(0:未支付 1:已支付) + */ + private Integer status; + /** + * 逻辑删除 1(true)已删除, 0(false)未删除 + */ + private Integer isDeleted; + /** + * 最早创建时间 + */ + private Date oldDate; + /** + * 最晚创建时间 + */ + private Date newDate; + +} \ 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 deleted file mode 100644 index e2d01fa..0000000 --- a/src/main/java/com/online/edu/entity/order/vo/CourseElectionVO.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.online.edu.entity.order.vo; - -import com.online.edu.entity.order.CourseElection; -import lombok.Data; - -import java.io.Serializable; - -/** - * 选课 - * - * @TableName course_election - */ -@Data -public class CourseElectionVO implements Serializable { - - /** - * 课程id - */ - private String courseId; - /** - * 学生id - */ - private String studentId; - - - public CourseElection buildCourseElection() { - return new CourseElection().setCourseId(courseId).setStudentId(studentId); - } -} diff --git a/src/main/java/com/online/edu/entity/order/vo/CourseOrderListVO.java b/src/main/java/com/online/edu/entity/order/vo/CourseOrderListVO.java new file mode 100644 index 0000000..23d2af3 --- /dev/null +++ b/src/main/java/com/online/edu/entity/order/vo/CourseOrderListVO.java @@ -0,0 +1,86 @@ +package com.online.edu.entity.order.vo; + +import com.online.edu.entity.order.CourseElection; +import com.online.edu.entity.order.CourseOrder; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +@Data +public class CourseOrderListVO { + /** + * 订单号 + */ + private String serialNumber; + + /** + * 课程id + */ + private String courseId; + /** + * 课程名称 + */ + private String courseName; + /** + * 教师名称 + */ + private String teacherName; + /** + * 学生id + */ + private String studentId; + /** + * 学生昵称 + */ + private String studentName; + + /** + * 支付完成时间 + */ + private Date payedat; + /** + * 支付金额(分) + */ + private BigDecimal price; + /** + * 交易流水号 + */ + private String transactionId; + /** + * 交易状态 + */ + private String tradeState; + + /** + * 逻辑删除 1(true)已删除, 0(false)未删除 + */ + private Integer isDeleted; + /** + * 创建时间 + */ + private Date createdAt; + /** + * 更新时间 + */ + private Date updatedAt; + + public CourseOrderListVO(CourseOrder order, CourseElection election) { + serialNumber = order.getSerialNumber(); + courseId = election.getCourseId(); + courseName = election.getCourseName(); + teacherName = election.getTeacherName(); + studentId = election.getStudentId(); + studentName = election.getStudentName(); + payedat = order.getPayedat(); + price = order.getPrice(); + + transactionId = order.getTransactionId(); + tradeState = order.getTradeState(); + isDeleted = order.getIsDeleted(); + + createdAt = order.getCreatedAt(); + updatedAt = order.getUpdatedAt(); + + } +} 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 index 840b5dd..4a0fae9 100644 --- a/src/main/java/com/online/edu/entity/order/vo/CourseOrderVO.java +++ b/src/main/java/com/online/edu/entity/order/vo/CourseOrderVO.java @@ -6,10 +6,6 @@ import java.math.BigDecimal; @Data public class CourseOrderVO { - /** - * - */ - private String id; /** * 订单号 */ diff --git a/src/main/java/com/online/edu/entity/resource/LiveResourceVO.java b/src/main/java/com/online/edu/entity/resource/LiveResourceVO.java index 8b2640c..705134d 100644 --- a/src/main/java/com/online/edu/entity/resource/LiveResourceVO.java +++ b/src/main/java/com/online/edu/entity/resource/LiveResourceVO.java @@ -35,10 +35,13 @@ public class LiveResourceVO implements Resource { @Override public String getAccess() { - return roomId; + Date now = new Date(); + if (now.after(getStartTime()) && now.before(getEndTime())) { + return roomId; + } + return null; } - @Override public String getCover() { return cover; } diff --git a/src/main/java/com/online/edu/entity/resource/Resource.java b/src/main/java/com/online/edu/entity/resource/Resource.java index f13b28a..641c0b4 100644 --- a/src/main/java/com/online/edu/entity/resource/Resource.java +++ b/src/main/java/com/online/edu/entity/resource/Resource.java @@ -5,7 +5,6 @@ public interface Resource { public String getAccess(); - public String getCover(); public Integer getSort(); diff --git a/src/main/java/com/online/edu/entity/resource/StaticResource.java b/src/main/java/com/online/edu/entity/resource/StaticResource.java index 91aafd6..ea219c5 100644 --- a/src/main/java/com/online/edu/entity/resource/StaticResource.java +++ b/src/main/java/com/online/edu/entity/resource/StaticResource.java @@ -32,11 +32,6 @@ public class StaticResource implements Serializable { */ private String name; - /** - * 封面 - */ - private String cover; - /** * oss文件Id */ @@ -56,7 +51,7 @@ public class StaticResource implements Serializable { /** * 可以在线访问 */ - private Integer isAccessable; + private Integer isAccessible; @TableField(exist = false) private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/online/edu/entity/resource/StaticResourceVO.java b/src/main/java/com/online/edu/entity/resource/StaticResourceVO.java index 4160c6e..2d5a7ba 100644 --- a/src/main/java/com/online/edu/entity/resource/StaticResourceVO.java +++ b/src/main/java/com/online/edu/entity/resource/StaticResourceVO.java @@ -1,5 +1,6 @@ package com.online.edu.entity.resource; +import com.online.edu.service.resource.VideoService; import lombok.*; import lombok.experimental.Accessors; @@ -14,28 +15,28 @@ public class StaticResourceVO implements Resource { private String name; - private String cover; - @Getter(AccessLevel.PROTECTED) private OSSFile file; private Integer sort; - private Boolean isAccessible; + private Integer isAccessible; - public OSSFile getDownload() { - return file; + public static StaticResourceVO convert(StaticResource staticResource, OSSFile file) { + return new StaticResourceVO(staticResource.getId(), staticResource.getName(), file, staticResource.getSort(), staticResource.getIsAccessible()); } - public static StaticResourceVO convert(StaticResource staticResource,OSSFile file){ - return new StaticResourceVO(staticResource.getId(), staticResource.getName(), - staticResource.getCover(),file,staticResource.getSort(),staticResource.getIsAccessable()==1); + public String getDownload() { + return file.getPath(); } @Override public String getAccess() { - return getIsAccessible() ? file.getName() : ""; + if (getIsAccessible() == 0) { + return ""; + } + return getFile().getType().startsWith("video") ? VideoService.getVideoPath(getFile()) : getFile().getPath(); } @Override diff --git a/src/main/java/com/online/edu/entity/resource/VideoResourceVO.java b/src/main/java/com/online/edu/entity/resource/VideoResourceVO.java index ad19a77..c557510 100644 --- a/src/main/java/com/online/edu/entity/resource/VideoResourceVO.java +++ b/src/main/java/com/online/edu/entity/resource/VideoResourceVO.java @@ -1,5 +1,6 @@ package com.online.edu.entity.resource; +import com.online.edu.service.resource.VideoService; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; @@ -18,7 +19,7 @@ public class VideoResourceVO extends StaticResourceVO { @Override public String getAccess() { - return getFile().getName(); + return VideoService.getVideoPath(getFile()); } public LinkedHashMap generateResolutionUrls() { diff --git a/src/main/java/com/online/edu/entity/stat/vo/AdminStatVO.java b/src/main/java/com/online/edu/entity/stat/vo/AdminStatVO.java new file mode 100644 index 0000000..a4c7198 --- /dev/null +++ b/src/main/java/com/online/edu/entity/stat/vo/AdminStatVO.java @@ -0,0 +1,52 @@ +package com.online.edu.entity.stat.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class AdminStatVO implements Serializable { + @Schema(description = "管理员数目") + private Integer adminCount; + + @Schema(description = "已禁用管理员数目") + private Integer disabledAdminCount; + + @Schema(description = "教师数目") + private Integer teacherCount; + + + @Schema(description = "已禁用教师数目") + private Integer disabledTeacherCount; + + + private Integer disabledStudentCount; + + @Schema(description = "课程数目") + private Integer courseCount; + + + @Schema(description = "公开开课课程数目") + private Integer enabledCourseCount; + + @Schema(description = "已禁用课程数目") + private Integer disabledCourseCount; + + @Schema(description = "未上架课程数目") + private Integer editingCourseCount; + + @Schema(description = "审核中课程数目") + private Integer auditingCourseCount; + + @Schema(description = "已驳回课程数目") + private Integer rejectedCourseCount; + + + @Schema(description = "资源总数") + private Integer resourceCount; + + @Schema(description = "订单总数") + private Integer orderCount; + +} diff --git a/src/main/java/com/online/edu/entity/userInfo/SocialUser.java b/src/main/java/com/online/edu/entity/userInfo/SocialUser.java deleted file mode 100644 index fa5426b..0000000 --- a/src/main/java/com/online/edu/entity/userInfo/SocialUser.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.online.edu.entity.userInfo; - -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import lombok.Data; - -import java.io.Serializable; -import java.util.Date; - -/** - * 第三方登录用户 - * - * @TableName social_user - */ -@Data -public class SocialUser implements Serializable { - private static final long serialVersionUID = 1L; - /** - * 登录用户id - */ - @TableId(value = "id", type = IdType.ASSIGN_ID) - - private String id; - /** - * 用户id - */ - - private String userId; - /** - * 对应的授权id - */ - private String openId; - /** - * 创建时间 - */ - private Date createdAt; - /** - * 更新时间 - */ - private Date updatedAt; -} \ No newline at end of file diff --git a/src/main/java/com/online/edu/entity/verification/BaseVerifyCode.java b/src/main/java/com/online/edu/entity/verification/BaseVerifyCode.java deleted file mode 100644 index 5eb9ef3..0000000 --- a/src/main/java/com/online/edu/entity/verification/BaseVerifyCode.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.online.edu.entity.verification; - -import lombok.Data; - -import java.io.Serializable; -import java.time.LocalDateTime; - - -@Data -public class BaseVerifyCode implements Serializable { - - private String verifyCode; - - private LocalDateTime expireTime; - - public BaseVerifyCode(String verifyCode, int expireSecond) { - this.verifyCode = verifyCode; - this.expireTime = LocalDateTime.now().plusSeconds(expireSecond); - } - - public BaseVerifyCode(String verifyCode, LocalDateTime expireTime) { - this.verifyCode = verifyCode; - this.expireTime = expireTime; - } - - //判断是否过期 - public boolean isExpire() { - return LocalDateTime.now().isAfter(expireTime); - } -} diff --git a/src/main/java/com/online/edu/entity/verification/ImageVerifyCode.java b/src/main/java/com/online/edu/entity/verification/ImageVerifyCode.java deleted file mode 100644 index 2d6dc94..0000000 --- a/src/main/java/com/online/edu/entity/verification/ImageVerifyCode.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.online.edu.entity.verification; - -import java.awt.image.BufferedImage; -import java.time.LocalDateTime; - - -public class ImageVerifyCode extends BaseVerifyCode { - - private BufferedImage image; - - - public ImageVerifyCode(BufferedImage image, String verifyCode, int expireSecond) { - super(verifyCode, expireSecond); - this.image = image; - } - - public ImageVerifyCode(BufferedImage image, String verifyCode, LocalDateTime expireTime) { - super(verifyCode, expireTime); - this.image = image; - } - - public BufferedImage getImage() { - return image; - } - - public ImageVerifyCode setImage(BufferedImage image) { - this.image = image; - return this; - } -} diff --git a/src/main/java/com/online/edu/mapper/banner/BannerMapper.java b/src/main/java/com/online/edu/mapper/banner/BannerMapper.java new file mode 100644 index 0000000..c62b701 --- /dev/null +++ b/src/main/java/com/online/edu/mapper/banner/BannerMapper.java @@ -0,0 +1,35 @@ +package com.online.edu.mapper.banner; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.online.edu.common.PageParam; +import com.online.edu.common.PageResult; +import com.online.edu.entity.banner.Banner; +import com.online.edu.entity.banner.vo.BannerQueryVO; +import org.apache.ibatis.annotations.Param; + +/** + * @author Nvnqs + * @description 针对表【banner(banner表)】的数据库操作Mapper + */ +public interface BannerMapper extends BaseMapper { + + default PageResult selectPage(BannerQueryVO queryVO) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper() + .like(queryVO.getTitle() != null, Banner::getTitle, queryVO.getTitle()) + .eq(queryVO.getEnable() != null, Banner::getEnable, Boolean.TRUE.equals(queryVO.getEnable()) ? 1 : 0) + .orderByDesc(Banner::getSort); + IPage mpPage = PageParam.buildPage(queryVO); + selectPage(mpPage, wrapper); + // 转换返回 + return new PageResult<>(mpPage.getRecords(), mpPage.getTotal()); + } + + int updateEnableById(@Param("enable") Integer enable, @Param("id") Integer id); + +} + + + + diff --git a/src/main/java/com/online/edu/mapper/course/CommentMapper.java b/src/main/java/com/online/edu/mapper/course/CommentMapper.java index 681dfc2..93035bd 100644 --- a/src/main/java/com/online/edu/mapper/course/CommentMapper.java +++ b/src/main/java/com/online/edu/mapper/course/CommentMapper.java @@ -1,5 +1,4 @@ package com.online.edu.mapper.course; -import org.apache.ibatis.annotations.Param; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; @@ -8,6 +7,7 @@ import com.online.edu.common.PageParam; import com.online.edu.common.PageResult; import com.online.edu.entity.course.Comment; import com.online.edu.entity.course.vo.CommentQueryVO; +import org.apache.ibatis.annotations.Param; /** * @author Nvnqs @@ -19,6 +19,7 @@ public interface CommentMapper extends BaseMapper { default PageResult selectPage(CommentQueryVO queryVO) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper() .eq(queryVO.getCourseId() != null, Comment::getCourseId, queryVO.getCourseId()) + .in(queryVO.getCourses() != null, Comment::getCourseId, queryVO.getCourses()) .eq(queryVO.getStudentId() != null, Comment::getStudentId, queryVO.getStudentId()) .between(queryVO.getNewTime() != null && queryVO.getOldTime() != null, Comment::getCreatedAt, queryVO.getOldTime(), queryVO.getNewTime()) .eq(queryVO.getIsDeleted() != null, Comment::getIsDeleted, queryVO.getIsDeleted()) diff --git a/src/main/java/com/online/edu/mapper/course/CourseInfoMapper.java b/src/main/java/com/online/edu/mapper/course/CourseInfoMapper.java index a10c55b..01723a4 100644 --- a/src/main/java/com/online/edu/mapper/course/CourseInfoMapper.java +++ b/src/main/java/com/online/edu/mapper/course/CourseInfoMapper.java @@ -25,6 +25,7 @@ public interface CourseInfoMapper extends BaseMapper { .eq(queryVO.getTeacherId() != null, CourseInfo::getTeacherId, queryVO.getTeacherId()) .eq(queryVO.getTypeId() != null, CourseInfo::getTypeId, queryVO.getTypeId()) .eq(queryVO.getStatus() != null, CourseInfo::getStatus, queryVO.getStatus()) + .ge(queryVO.getStatus() == null, CourseInfo::getStatus, 2) .between(queryVO.getMinPrice() != null && queryVO.getMaxPrice() != null, CourseInfo::getPrice, queryVO.getMinPrice(), queryVO.getMaxPrice()) .eq(queryVO.getIsDeleted() != null, CourseInfo::getIsDeleted, queryVO.getIsDeleted()) .eq(queryVO.getIsDeleted() == null, CourseInfo::getIsDeleted, 0) @@ -38,6 +39,8 @@ public interface CourseInfoMapper extends BaseMapper { int updateIsDeletedById(@Param("isDeleted") Integer isDeleted, @Param("id") String id); List listAll(@Param("teacherId") String teacherId); + + List listAllId(@Param("teacherId") String teacherId); } diff --git a/src/main/java/com/online/edu/mapper/message/MessageMapper.java b/src/main/java/com/online/edu/mapper/message/MessageMapper.java index 5620999..03472fa 100644 --- a/src/main/java/com/online/edu/mapper/message/MessageMapper.java +++ b/src/main/java/com/online/edu/mapper/message/MessageMapper.java @@ -1,16 +1,22 @@ package com.online.edu.mapper.message; -import com.online.edu.entity.message.Message; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.online.edu.entity.message.Message; +import org.apache.ibatis.annotations.Param; /** -* @author Nvnqs -* @description 针对表【message(消息表)】的数据库操作Mapper -* @createDate 2023-06-17 14:32:31 -* @Entity com.online.edu.entity.message.Message -*/ + * @author Nvnqs + * @description 针对表【message(消息表)】的数据库操作Mapper + * @createDate 2023-06-17 14:32:31 + * @Entity com.online.edu.entity.message.Message + */ public interface MessageMapper extends BaseMapper { + int updateReadStatusByReceiverId(@Param("readStatus") Integer readStatus, @Param("receiverId") String receiverId); + + int updateDeletedByReceiverId(@Param("deleted") Integer deleted, @Param("receiverId") String receiverId); + + int updateDeletedByReceiverIdAndId(@Param("deleted") Integer deleted, @Param("receiverId") String receiverId, @Param("id") String id); } diff --git a/src/main/java/com/online/edu/mapper/message/MessageTemplateMapper.java b/src/main/java/com/online/edu/mapper/message/MessageTemplateMapper.java deleted file mode 100644 index 0f4e77d..0000000 --- a/src/main/java/com/online/edu/mapper/message/MessageTemplateMapper.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.online.edu.mapper.message; - -import com.online.edu.entity.message.MessageTemplate; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -/** -* @author Nvnqs -* @description 针对表【message_template(站内信模板表)】的数据库操作Mapper -* @createDate 2023-06-17 14:32:31 -* @Entity com.online.edu.entity.message.MessageTemplate -*/ -public interface MessageTemplateMapper extends BaseMapper { - -} - - - - 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 e74b287..55bab45 100644 --- a/src/main/java/com/online/edu/mapper/order/CourseElectionMapper.java +++ b/src/main/java/com/online/edu/mapper/order/CourseElectionMapper.java @@ -1,10 +1,15 @@ package com.online.edu.mapper.order; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.online.edu.common.PageParam; +import com.online.edu.common.PageResult; import com.online.edu.entity.order.CourseElection; +import com.online.edu.entity.order.vo.CourseElectionQueryVO; +import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; -import java.util.Date; import java.util.List; /** @@ -13,6 +18,7 @@ import java.util.List; * @createDate 2023-06-04 17:20:56 * @Entity com.online.edu.entity.order.CourseElection */ +@Mapper public interface CourseElectionMapper extends BaseMapper { int insertAll(CourseElection courseElection); @@ -20,8 +26,25 @@ public interface CourseElectionMapper extends BaseMapper { List getByCourse(@Param("courseId") Long courseId); - int updateById(@Param("serialNumber") String serialNumber, @Param("status") Integer status ,@Param("updateAt") Date updateAt); - + int updateById(@Param("serialNumber") String serialNumber, @Param("status") Integer status); + + + default PageResult selectPage(CourseElectionQueryVO queryVO) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper() + .like(queryVO.getSerialNumber() != null, CourseElection::getSerialNumber, queryVO.getSerialNumber()) + .like(queryVO.getStudentName() != null, CourseElection::getStudentName, queryVO.getStudentName()) + .eq(queryVO.getStatus() != null, CourseElection::getStatus, queryVO.getStatus()) + .between(queryVO.getNewDate() != null && queryVO.getOldDate() != null, CourseElection::getCreatedAt, + queryVO.getOldDate(), queryVO.getNewDate()) + + .eq(queryVO.getIsDeleted() != null, CourseElection::getIsDeleted, queryVO.getIsDeleted()) + .eq(queryVO.getIsDeleted() == null, CourseElection::getIsDeleted, 0) + .orderByDesc(CourseElection::getId); + IPage mpPage = PageParam.buildPage(queryVO); + selectPage(mpPage, wrapper); + // 转换返回 + return new PageResult<>(mpPage.getRecords(), mpPage.getTotal()); + } } 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 487d2fa..f2c991c 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,6 @@ 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; @@ -16,7 +15,12 @@ import java.util.Date; public interface CourseOrderMapper extends BaseMapper { int insertAll(CourseOrder courseOrder); - int updateById(@Param("serialNumber") String serialNumber, @Param("tradeState") String tradeState, @Param("updateAt") Date updateAt); + int updateById(@Param("serialNumber") String serialNumber, @Param("tradeState") String tradeState, + @Param("payedAt") Date payedAt, @Param("transactionId") String transactionId); + + int updateWaitPayById(@Param("serialNumber") String serialNumber, @Param("tradeState") String tradeState); + + } diff --git a/src/main/java/com/online/edu/mapper/rbac/UserMapper.java b/src/main/java/com/online/edu/mapper/rbac/UserMapper.java index 9fb016f..892f225 100644 --- a/src/main/java/com/online/edu/mapper/rbac/UserMapper.java +++ b/src/main/java/com/online/edu/mapper/rbac/UserMapper.java @@ -77,4 +77,5 @@ public interface UserMapper extends BaseMapper { // 转换返回 return new PageResult<>(mpPage.getRecords(), mpPage.getTotal()); } + } diff --git a/src/main/java/com/online/edu/mapper/rbac/UserRoleRelationMapper.java b/src/main/java/com/online/edu/mapper/rbac/UserRoleRelationMapper.java index e41ac38..36a12ce 100644 --- a/src/main/java/com/online/edu/mapper/rbac/UserRoleRelationMapper.java +++ b/src/main/java/com/online/edu/mapper/rbac/UserRoleRelationMapper.java @@ -24,6 +24,9 @@ public interface UserRoleRelationMapper { List getUserNameByRoleId(@Param("roleId") String roleId); int getByUserIdAndRoleId(@Param("userId") String userId, @Param("roleId") String roleId); + + + List getByRoleId(@Param("roleId") String roleId); } diff --git a/src/main/java/com/online/edu/service/banner/BannerService.java b/src/main/java/com/online/edu/service/banner/BannerService.java new file mode 100644 index 0000000..75301ff --- /dev/null +++ b/src/main/java/com/online/edu/service/banner/BannerService.java @@ -0,0 +1,24 @@ +package com.online.edu.service.banner; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.online.edu.common.PageResult; +import com.online.edu.entity.banner.Banner; +import com.online.edu.entity.banner.vo.BannerQueryVO; + +import java.util.List; + + +/** + * @author Nvnqs + */ +public interface BannerService extends IService { + PageResult query(BannerQueryVO bannerQuery); + + Banner enable(Integer bannerId); + + Banner disable(Integer bannerId); + + Banner delete(Integer bannerId); + + List get(); +} diff --git a/src/main/java/com/online/edu/service/banner/impl/BannerServiceImpl.java b/src/main/java/com/online/edu/service/banner/impl/BannerServiceImpl.java new file mode 100644 index 0000000..51a4e31 --- /dev/null +++ b/src/main/java/com/online/edu/service/banner/impl/BannerServiceImpl.java @@ -0,0 +1,60 @@ +package com.online.edu.service.banner.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.online.edu.common.PageResult; +import com.online.edu.entity.banner.Banner; +import com.online.edu.entity.banner.vo.BannerQueryVO; +import com.online.edu.mapper.banner.BannerMapper; +import com.online.edu.service.banner.BannerService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author Nvnqs + */ +@Service +public class BannerServiceImpl extends ServiceImpl + implements BannerService { + + + @Override + public PageResult query(BannerQueryVO bannerQuery) { + return baseMapper.selectPage(bannerQuery); + } + + @Override + public Banner enable(Integer bannerId) { + Banner banner = getById(bannerId); + banner.setEnable(true); + baseMapper.updateEnableById(1, bannerId); + return banner; + } + + @Override + public Banner disable(Integer bannerId) { + Banner banner = getById(bannerId); + banner.setEnable(false); + baseMapper.updateEnableById(0, bannerId); + return banner; + } + + @Override + public Banner delete(Integer bannerId) { + Banner banner = getById(bannerId); + removeById(bannerId); + return banner; + } + + @Override + public List get() { + BannerQueryVO bannerQuery = new BannerQueryVO(); + bannerQuery.setEnable(true); + bannerQuery.setPageSize(1000); + return query(bannerQuery).getList(); + } +} + + + + diff --git a/src/main/java/com/online/edu/service/course/CourseInfoService.java b/src/main/java/com/online/edu/service/course/CourseInfoService.java index bccfa83..595e539 100644 --- a/src/main/java/com/online/edu/service/course/CourseInfoService.java +++ b/src/main/java/com/online/edu/service/course/CourseInfoService.java @@ -25,8 +25,14 @@ public interface CourseInfoService extends IService { PageResult convertToVO(PageResult courseInfoPageResult); + CourseInfoVO convertToVO(CourseInfo courseInfoPageResult); + + boolean setIsDeleted(String courseId, Integer isDeleted); List listAll(String teacherId); + + List listAllId(String teacherId); + } diff --git a/src/main/java/com/online/edu/service/course/impl/CommentServiceImpl.java b/src/main/java/com/online/edu/service/course/impl/CommentServiceImpl.java index af38410..477c6ef 100644 --- a/src/main/java/com/online/edu/service/course/impl/CommentServiceImpl.java +++ b/src/main/java/com/online/edu/service/course/impl/CommentServiceImpl.java @@ -5,8 +5,12 @@ import com.online.edu.common.PageResult; import com.online.edu.entity.course.Comment; import com.online.edu.entity.course.vo.CommentQueryVO; import com.online.edu.entity.course.vo.NewCommentVO; +import com.online.edu.entity.rbac.UserInfo; import com.online.edu.mapper.course.CommentMapper; import com.online.edu.service.course.CommentService; +import com.online.edu.service.course.CourseInfoService; +import com.online.edu.service.rbac.UserService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** @@ -18,6 +22,12 @@ import org.springframework.stereotype.Service; public class CommentServiceImpl extends ServiceImpl implements CommentService { + @Autowired + UserService userService; + + @Autowired + CourseInfoService courseInfoService; + @Override public boolean checkCommented(String courseId, String studentId) { return baseMapper.countByCourseIdAndStudentIdAndIsDeleted(courseId, studentId) > 0; @@ -25,11 +35,12 @@ public class CommentServiceImpl extends ServiceImpl @Override public Comment addComment(NewCommentVO newCommentVO) { - if(newCommentVO == null || checkCommented(newCommentVO.getCourseId(), newCommentVO.getStudentId())) { + if (newCommentVO == null) { return null; } - Comment comment = newCommentVO.buildComment(); - if(save(comment)){ + UserInfo userInfo = userService.getById(newCommentVO.getStudentId()); + Comment comment = newCommentVO.buildComment(userInfo); + if (save(comment)) { return comment; } return null; @@ -47,6 +58,9 @@ public class CommentServiceImpl extends ServiceImpl @Override public PageResult query(CommentQueryVO query) { + if (query.getTeacherId() != null) { + query.setCourses(courseInfoService.listAllId(query.getTeacherId())); + } return baseMapper.selectPage(query); } @@ -54,6 +68,7 @@ public class CommentServiceImpl extends ServiceImpl public boolean setIsDeleted(String commentId, Integer isDeleted) { return baseMapper.updateIsDeletedById(isDeleted,commentId) > 0; } + } diff --git a/src/main/java/com/online/edu/service/course/impl/CourseInfoServiceImpl.java b/src/main/java/com/online/edu/service/course/impl/CourseInfoServiceImpl.java index d62bfd8..21c6eda 100644 --- a/src/main/java/com/online/edu/service/course/impl/CourseInfoServiceImpl.java +++ b/src/main/java/com/online/edu/service/course/impl/CourseInfoServiceImpl.java @@ -1,17 +1,24 @@ package com.online.edu.service.course.impl; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.online.edu.common.PageResult; import com.online.edu.entity.course.CourseInfo; import com.online.edu.entity.course.CourseType; import com.online.edu.entity.course.vo.*; +import com.online.edu.entity.message.vo.MessageSendVO; +import com.online.edu.entity.rbac.UserInfoDAO; +import com.online.edu.entity.resource.CourseSection; import com.online.edu.entity.userInfo.TeacherInfo; import com.online.edu.mapper.course.CourseInfoMapper; import com.online.edu.service.course.CourseInfoService; import com.online.edu.service.course.CourseTypeService; +import com.online.edu.service.message.MessageService; import com.online.edu.service.rbac.UserService; +import com.online.edu.service.resource.CourseSectionService; import com.online.edu.service.userInfo.TeacherInfoService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -26,18 +33,24 @@ public class CourseInfoServiceImpl extends ServiceImpl receivers = new ArrayList<>(); + receivers.add(teacherId); + sendVO.setReceivers(receivers); + + + if (status < 0) { + sendVO.setMessageTitle("课程被驳回"); + sendVO.setMessageBody(StrUtil.format("您的课程《{}》被驳回,请进行修改。", currentCourse.getTitle())); + } else if (status > 0) { + sendVO.setMessageTitle("课程通过审核"); + sendVO.setMessageBody(StrUtil.format("您的课程《{}》已通过审核。", currentCourse.getTitle())); + } + messageService.sendSystemMessage(sendVO); + } return updateCourse(new CourseUpdateVO().setId(courseId).setStatus(status)); } @Override public PageResult query(CourseQueryVO courseQueryVO) { + return baseMapper.selectPage(courseQueryVO); } @Override public PageResult convertToVO(PageResult courseInfoPageResult) { List courses = new ArrayList<>(); - for(CourseInfo info: courseInfoPageResult.getList()){ - TeacherInfo teacherInfo = teacherInfoService.lambdaQuery().eq(TeacherInfo::getTeacherId,info.getTeacherId()).one(); + for (CourseInfo info : courseInfoPageResult.getList()) { + TeacherInfo teacherInfo = teacherInfoService.lambdaQuery().eq(TeacherInfo::getTeacherId, info.getTeacherId()).one(); CourseType type = courseTypeService.getById(info.getTypeId()); - courses.add(CourseInfoVO.build(info,teacherInfo.getTeacherName(),teacherInfo.getTeacherDescription(), - teacherInfo.getTeacherAvatar(),type==null?"0":type.getCourseType())); + Long count = courseSectionService.lambdaQuery().eq(CourseSection::getCourseId, info.getId()).count(); + courses.add(CourseInfoVO.build(info, teacherInfo.getTeacherName(), teacherInfo.getTeacherDescription(), + teacherInfo.getTeacherAvatar(), type == null ? "0" : type.getCourseType(), Math.toIntExact(count))); } return new PageResult<>(courses, courseInfoPageResult.getTotal()); } + @Override + public CourseInfoVO convertToVO(CourseInfo courseInfo) { + TeacherInfo teacherInfo = teacherInfoService.lambdaQuery().eq(TeacherInfo::getTeacherId, courseInfo.getTeacherId()).one(); + CourseType type = courseTypeService.getById(courseInfo.getTypeId()); + Long count = courseSectionService.lambdaQuery().eq(CourseSection::getCourseId, courseInfo.getId()).count(); + return CourseInfoVO.build(courseInfo, teacherInfo.getTeacherName(), teacherInfo.getTeacherDescription(), + teacherInfo.getTeacherAvatar(), type == null ? "0" : type.getCourseType(), Math.toIntExact(count)); + } + @Override public boolean setIsDeleted(String courseId, Integer isDeleted) { - return baseMapper.updateIsDeletedById(isDeleted,courseId) > 0; + return baseMapper.updateIsDeletedById(isDeleted, courseId) > 0; } @Override public List listAll(String teacherId) { return baseMapper.listAll(teacherId); } + + @Override + public List listAllId(String teacherId) { + return baseMapper.listAllId(teacherId); + } } diff --git a/src/main/java/com/online/edu/service/message/MessageService.java b/src/main/java/com/online/edu/service/message/MessageService.java index 3826122..3aecc84 100644 --- a/src/main/java/com/online/edu/service/message/MessageService.java +++ b/src/main/java/com/online/edu/service/message/MessageService.java @@ -2,6 +2,10 @@ package com.online.edu.service.message; import com.baomidou.mybatisplus.extension.service.IService; import com.online.edu.entity.message.Message; +import com.online.edu.entity.message.vo.MessageSendVO; +import com.online.edu.entity.message.vo.MessageVO; + +import java.util.List; /** * @author Nvnqs @@ -10,4 +14,15 @@ import com.online.edu.entity.message.Message; */ public interface MessageService extends IService { + void sendSystemMessage(MessageSendVO sendVO); + + List listRecieved(String userId); + + Long countUnread(String userId); + + Long markAsRead(String userId); + + boolean clear(String userId); + + boolean delete(String id, String userId); } diff --git a/src/main/java/com/online/edu/service/message/MessageTemplateService.java b/src/main/java/com/online/edu/service/message/MessageTemplateService.java deleted file mode 100644 index be0556f..0000000 --- a/src/main/java/com/online/edu/service/message/MessageTemplateService.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.online.edu.service.message; - -import com.baomidou.mybatisplus.extension.service.IService; -import com.online.edu.entity.message.MessageTemplate; - -/** - * @author Nvnqs - * @description 针对表【message_template(站内信模板表)】的数据库操作Service - * @createDate 2023-06-04 17:20:56 - */ -public interface MessageTemplateService extends IService { - -} diff --git a/src/main/java/com/online/edu/service/message/impl/MessageServiceImpl.java b/src/main/java/com/online/edu/service/message/impl/MessageServiceImpl.java index 012e63d..7ec163a 100644 --- a/src/main/java/com/online/edu/service/message/impl/MessageServiceImpl.java +++ b/src/main/java/com/online/edu/service/message/impl/MessageServiceImpl.java @@ -2,10 +2,17 @@ package com.online.edu.service.message.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.online.edu.entity.message.Message; +import com.online.edu.entity.message.vo.MessageSendVO; +import com.online.edu.entity.message.vo.MessageVO; import com.online.edu.mapper.message.MessageMapper; import com.online.edu.service.message.MessageService; +import com.online.edu.service.rbac.UserService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + /** * @author Nvnqs * @description 针对表【message(消息表)】的数据库操作Service实现 @@ -15,6 +22,49 @@ import org.springframework.stereotype.Service; public class MessageServiceImpl extends ServiceImpl implements MessageService { + @Autowired + UserService userService; + + @Override + public void sendSystemMessage(MessageSendVO sendVO) { + List messages = sendVO.build(); + saveBatch(messages); + } + + @Override + public List listRecieved(String userId) { + List messages = lambdaQuery().eq(Message::getReceiverId, userId) + .eq(Message::getDeleted, 0).list(); + List result = new ArrayList<>(); + for (Message message : messages) { + String displayName = userService.getById(message.getSenderId()).getDisplayName(); + result.add(new MessageVO(message, displayName)); + } + return result; + } + + @Override + public Long countUnread(String userId) { + return lambdaQuery().eq(Message::getReceiverId, userId) + .eq(Message::getDeleted, 0).ne(Message::getReadStatus, 1).count(); + } + + @Override + public Long markAsRead(String userId) { + + return (long) baseMapper.updateReadStatusByReceiverId(1, userId); + } + + @Override + public boolean clear(String userId) { + return baseMapper.updateDeletedByReceiverId(1, userId) > 0; + } + + @Override + public boolean delete(String id, String userId) { + baseMapper.updateDeletedByReceiverIdAndId(1, userId, id); + return lambdaQuery().eq(Message::getReceiverId, userId).eq(Message::getId, id).count() > 0; + } } diff --git a/src/main/java/com/online/edu/service/message/impl/MessageTemplateServiceImpl.java b/src/main/java/com/online/edu/service/message/impl/MessageTemplateServiceImpl.java deleted file mode 100644 index 8265832..0000000 --- a/src/main/java/com/online/edu/service/message/impl/MessageTemplateServiceImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.online.edu.service.message.impl; - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.online.edu.entity.message.MessageTemplate; -import com.online.edu.mapper.message.MessageTemplateMapper; -import com.online.edu.service.message.MessageTemplateService; -import org.springframework.stereotype.Service; - -/** - * @author Nvnqs - * @description 针对表【message_template(站内信模板表)】的数据库操作Service实现 - * @createDate 2023-06-04 17:20:56 - */ -@Service -public class MessageTemplateServiceImpl extends ServiceImpl - implements MessageTemplateService { - -} - - - - 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 e1d904a..934b3c1 100644 --- a/src/main/java/com/online/edu/service/order/CourseElectionService.java +++ b/src/main/java/com/online/edu/service/order/CourseElectionService.java @@ -2,8 +2,7 @@ package com.online.edu.service.order; import com.baomidou.mybatisplus.extension.service.IService; import com.online.edu.entity.order.CourseElection; - -import java.util.List; +import com.online.edu.entity.order.CourseOrder; /** * @author Nvnqs @@ -12,9 +11,6 @@ import java.util.List; */ public interface CourseElectionService extends IService { - boolean electCourse(CourseElection courseElection); - - List getById(Long studentid); + CourseOrder electCourse(String courseId, String 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 72becd1..6ac9d71 100644 --- a/src/main/java/com/online/edu/service/order/CourseOrderService.java +++ b/src/main/java/com/online/edu/service/order/CourseOrderService.java @@ -1,8 +1,13 @@ package com.online.edu.service.order; import com.baomidou.mybatisplus.extension.service.IService; +import com.online.edu.common.PageResult; import com.online.edu.entity.order.CourseElection; import com.online.edu.entity.order.CourseOrder; +import com.online.edu.entity.order.vo.CourseElectionQueryVO; +import com.online.edu.entity.order.vo.CourseOrderListVO; + +import java.util.List; /** * @author Nvnqs @@ -12,5 +17,7 @@ import com.online.edu.entity.order.CourseOrder; public interface CourseOrderService extends IService { boolean save(CourseOrder courseOrder); - CourseOrder buildCourseOrder(CourseElection courseElection); + PageResult query(CourseElectionQueryVO queryVO); + + List buildVO(List elections); } 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 index e59ccf6..91965b1 100644 --- a/src/main/java/com/online/edu/service/order/impl/AlipayService.java +++ b/src/main/java/com/online/edu/service/order/impl/AlipayService.java @@ -2,6 +2,7 @@ package com.online.edu.service.order.impl; import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; import com.alipay.easysdk.factory.Factory; import com.alipay.easysdk.kernel.util.ResponseChecker; import com.alipay.easysdk.payment.common.models.AlipayTradeQueryResponse; @@ -9,13 +10,11 @@ import com.alipay.easysdk.payment.page.models.AlipayTradePagePayResponse; import com.online.edu.common.CommonResult; 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.Date; -import java.util.Map; /** * 支付服务 @@ -26,6 +25,7 @@ public class AlipayService { @Autowired CourseOrderMapper courseOrderMapper; + @Autowired CourseElectionMapper courseElectionMapper; @@ -38,9 +38,10 @@ public class AlipayService { */ 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.valueOf(money), "http://localhost:9530/#/"); String payForm = null; if (ResponseChecker.success(pay)) { + courseOrderMapper.updateWaitPayById(serialNumber, "WAIT_BUYER_PAY"); payForm = pay.getBody(); } return payForm; @@ -56,14 +57,15 @@ public class AlipayService { 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()); + JSONObject map = JSON.parseObject(query.getHttpBody()); + JSONObject resultMap = JSON.parseObject(map.get("alipay_trade_query_response").toString()); Object trade_status = resultMap.get("trade_status"); + String trade_no = (String) resultMap.get("trade_no"); if ("TRADE_SUCCESS".equals(trade_status) || "TRADE_FINISHED".equals(trade_status)) { - courseOrderMapper.updateById(outTradeNo,"Trade_Finished",new Date()); - courseElectionMapper.updateById(outTradeNo, 1,new Date()); + courseOrderMapper.updateById(outTradeNo, "TRADE_FINISHED", new Date(), trade_no); + courseElectionMapper.updateById(outTradeNo, 1); } else { - return CommonResult.error(400,"支付失败"); + return CommonResult.error(400, "支付失败"); } // 返回交易结果, 是否交易成功需要根据该对象中的 trade_status 来确定 // trade_status 的枚举值如下, 请见 https://opendocs.alipay.com/apis/api_1/alipay.trade.query 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 dd3e49f..37273a2 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 @@ -1,13 +1,21 @@ package com.online.edu.service.order.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.online.edu.entity.course.CourseInfo; 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.service.course.CourseInfoService; import com.online.edu.service.order.CourseElectionService; +import com.online.edu.service.order.CourseOrderService; +import com.online.edu.service.rbac.UserService; +import com.online.edu.service.userInfo.TeacherInfoService; +import com.online.edu.utils.OrderSerialNumberUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.List; +import java.math.BigDecimal; +import java.util.Date; /** * @author Nvnqs @@ -20,18 +28,48 @@ public class CourseElectionServiceImpl extends ServiceImpl getById(Long studentid){ return courseElectionMapper.getById(studentid);} @Override - public List getByCourse(Long courseid){ return courseElectionMapper.getById(courseid);} + public CourseOrder electCourse(String courseId, String studentId) { + CourseInfo info = courseInfoService.getById(courseId); + if (info == null) { + return null; + } + CourseElection courseElection = new CourseElection().setCourseId(courseId) + .setCourseName(info.getTitle()).setPrice(info.getPrice()).setIsDeleted(0); + String teacherId = info.getTeacherId(); + courseElection.setTeacherName(teacherInfoService.getById(teacherId).getTeacherName()); + courseElection.setStudentId(studentId).setStudentName(userService.getById(studentId).getDisplayName()); + courseElection.setSerialNumber(OrderSerialNumberUtil.getSerialNumber()); + + CourseOrder order; + if (BigDecimal.ZERO.equals(info.getPrice())) { + courseElection.setStatus(1); + order = new CourseOrder().setSerialNumber(courseElection.getSerialNumber()) + .setPayedat(new Date()).setPrice(BigDecimal.ZERO).setIsDeleted(0).setTradeState("TRADE_FINISHED") + .setCreatedAt(new Date()).setUpdatedAt(new Date()); + } + courseElection.setStatus(0).setPrice(info.getPrice()); + save(courseElection); + order = new CourseOrder().setSerialNumber(courseElection.getSerialNumber()) + .setPrice(courseElection.getPrice()).setIsDeleted(0).setTradeState("INITIAL") + .setCreatedAt(new Date()).setUpdatedAt(new Date()); + courseOrderService.save(order); + return order; + } + } 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 53a529f..256e9b5 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,14 +1,20 @@ package com.online.edu.service.order.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.online.edu.common.PageResult; import com.online.edu.entity.order.CourseElection; import com.online.edu.entity.order.CourseOrder; +import com.online.edu.entity.order.vo.CourseElectionQueryVO; +import com.online.edu.entity.order.vo.CourseOrderListVO; +import com.online.edu.mapper.order.CourseElectionMapper; import com.online.edu.mapper.order.CourseOrderMapper; import com.online.edu.service.order.CourseOrderService; -import com.online.edu.utils.OrderSerialNumberUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + /** * @author Nvnqs * @description 针对表【course_order(订单)】的数据库操作Service实现 @@ -17,18 +23,32 @@ import org.springframework.stereotype.Service; @Service public class CourseOrderServiceImpl extends ServiceImpl implements CourseOrderService { + @Autowired - CourseOrderMapper courseOrderMapper; + CourseElectionMapper courseElectionMapper; @Override - public boolean save(CourseOrder courseOrder){ - return courseOrderMapper.insertAll(courseOrder) != 0; + public boolean save(CourseOrder courseOrder) { + return baseMapper.insertAll(courseOrder) != 0; } @Override - public CourseOrder buildCourseOrder(CourseElection courseElection) { - return new CourseOrder().setPrice(courseElection.getPrice()).setTradeState("Not_Finished") - .setSerialNumber(OrderSerialNumberUtil.getSerialNumber()).setIsDeleted(0); + public PageResult query(CourseElectionQueryVO queryVO) { + return courseElectionMapper.selectPage(queryVO); + + } + + + @Override + public List buildVO(List elections) { + List serials = new ArrayList<>(); + List result = new ArrayList<>(); + elections.forEach(courseElection -> { + String serial = courseElection.getSerialNumber(); + result.add(new CourseOrderListVO(lambdaQuery() + .eq(CourseOrder::getSerialNumber, serial).one(), courseElection)); + }); + return result; } } diff --git a/src/main/java/com/online/edu/service/rbac/UserService.java b/src/main/java/com/online/edu/service/rbac/UserService.java index a23a813..39cc9ae 100644 --- a/src/main/java/com/online/edu/service/rbac/UserService.java +++ b/src/main/java/com/online/edu/service/rbac/UserService.java @@ -65,6 +65,8 @@ public interface UserService extends IService { boolean delUserRole(String userId, String roleId); + long countUserRole(String roleId, Integer status); + PageResult query(UserQueryVO userQueryVO); boolean delUser(String username); diff --git a/src/main/java/com/online/edu/service/rbac/impl/AuthServiceImpl.java b/src/main/java/com/online/edu/service/rbac/impl/AuthServiceImpl.java index 15cd4ea..718fe76 100644 --- a/src/main/java/com/online/edu/service/rbac/impl/AuthServiceImpl.java +++ b/src/main/java/com/online/edu/service/rbac/impl/AuthServiceImpl.java @@ -55,7 +55,7 @@ public class AuthServiceImpl implements AuthService { } UserInfo user = new UserInfo(); Long id = IdWorker.getId(user); - + newUserVO.getRoles().add("3"); user.setId(String.valueOf(id)).setUsername(newUserVO.getUsername()) .setPassword(passwordEncoder.encode(newUserVO.getPassword())) .setDisplayName(newUserVO.getDisplayName()) @@ -88,7 +88,6 @@ public class AuthServiceImpl implements AuthService { } UserInfo user = new UserInfo(); Long id = IdWorker.getId(user); - user.setId(String.valueOf(id)).setUsername(registerVO.getUsername()) .setPassword(passwordEncoder.encode(registerVO.getPassword())) .setDisplayName(registerVO.getDisplayName()) @@ -99,7 +98,7 @@ public class AuthServiceImpl implements AuthService { } else { if (userRoleRelationMapper.addAll(new UserRoleRelation().setUserId( userMapper.getIdByUsername(registerVO.getUsername()) - ).setRoleId("1")) == 0) { + ).setRoleId("3")) == 0) { String userId = userMapper.getIdByUsername(registerVO.getUsername()); userRoleRelationMapper.delByUserId(userId); userMapper.delById(userId); diff --git a/src/main/java/com/online/edu/service/rbac/impl/UserServiceImpl.java b/src/main/java/com/online/edu/service/rbac/impl/UserServiceImpl.java index 13f4ddf..ef26956 100644 --- a/src/main/java/com/online/edu/service/rbac/impl/UserServiceImpl.java +++ b/src/main/java/com/online/edu/service/rbac/impl/UserServiceImpl.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Set; +import java.util.concurrent.atomic.AtomicLong; @Service public class UserServiceImpl extends ServiceImpl implements UserService { @@ -73,6 +74,17 @@ public class UserServiceImpl extends ServiceImpl implement return userRoleRelationMapper.delByUserIdAndRoleId(userId, roleId) > 0; } + @Override + public long countUserRole(String roleId, Integer status) { + List users = userRoleRelationMapper.getByRoleId(roleId); + AtomicLong result = new AtomicLong(); + users.forEach(user -> { + result.addAndGet(lambdaQuery().eq(UserInfo::getId, user.getUserId()).eq(UserInfo::getStatus, status) + .eq(UserInfo::getIsDeleted, 0).count()); + }); + return result.get(); + } + @Override public PageResult query(UserQueryVO userQueryVO) { return baseMapper.selectPage(userQueryVO); diff --git a/src/main/java/com/online/edu/service/resource/ResourceService.java b/src/main/java/com/online/edu/service/resource/ResourceService.java index 7207814..e2bf267 100644 --- a/src/main/java/com/online/edu/service/resource/ResourceService.java +++ b/src/main/java/com/online/edu/service/resource/ResourceService.java @@ -16,6 +16,11 @@ public interface ResourceService { boolean addStatic(StaticResource resource); + boolean updateStatic(StaticResource resource); + + boolean delStatic(String resourceId); + + boolean addLive(LiveResource resource); boolean addHomework(HomeworkResource resource); diff --git a/src/main/java/com/online/edu/service/resource/VideoService.java b/src/main/java/com/online/edu/service/resource/VideoService.java index 1b77a56..0f2bbaf 100644 --- a/src/main/java/com/online/edu/service/resource/VideoService.java +++ b/src/main/java/com/online/edu/service/resource/VideoService.java @@ -1,13 +1,20 @@ package com.online.edu.service.resource; -import com.online.edu.entity.resource.Video; import com.baomidou.mybatisplus.extension.service.IService; +import com.online.edu.entity.resource.OSSFile; +import com.online.edu.entity.resource.Video; /** -* @author Nvnqs -* @description 针对表【video(视频)】的数据库操作Service -* @createDate 2023-06-05 22:57:35 -*/ + * @author Nvnqs + * @description 针对表【video(视频)】的数据库操作Service + * @createDate 2023-06-05 22:57:35 + */ public interface VideoService extends IService