Ver código fonte

考场列表包含VIP 接口修改

小么熊🐻 2 anos atrás
pai
commit
2ec2cadaa5

+ 37 - 3
jsjp-admin/src/main/java/com/miaxis/app/controller/exam/ExamInfoController.java

@@ -4,12 +4,20 @@ import com.miaxis.common.constant.Constants;
 import com.miaxis.common.core.controller.BaseController;
 import com.miaxis.common.core.domain.Response;
 import com.miaxis.common.core.page.ResponsePageInfo;
+import com.miaxis.common.utils.PrivateKeyUtil;
 import com.miaxis.exam.domain.ExamInfo;
+import com.miaxis.exam.dto.ExamInfoDto;
 import com.miaxis.exam.service.IExamInfoService;
+import com.miaxis.exam.vo.ExamInfoVipVo;
 import io.swagger.annotations.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.security.KeyFactory;
+import java.security.PrivateKey;
+import java.security.Signature;
+import java.security.spec.PKCS8EncodedKeySpec;
+import java.util.Base64;
 import java.util.List;
 
 /**
@@ -35,10 +43,11 @@ public class ExamInfoController extends BaseController {
             @ApiImplicitParam(name = "pageNum", value = "当前页码", dataType = "int", paramType = "query", required = false),
             @ApiImplicitParam(name = "pageSize", value = "每页数据量", dataType = "int", paramType = "query", required = false),
     })
-    public ResponsePageInfo<ExamInfo> list(@ModelAttribute ExamInfo examInfo) {
+    public ResponsePageInfo<ExamInfoVipVo> list(@ModelAttribute ExamInfoDto examInfoDto) throws Exception {
         startPage();
-        List<ExamInfo> list = examInfoService.selectExamInfoList(examInfo);
-        return toResponsePageInfo(list);
+        List<ExamInfoVipVo> examInfoVipVoList = examInfoService.selectExamInfoList(examInfoDto);
+        this.doSign(examInfoVipVoList);
+        return toResponsePageInfo(examInfoVipVoList);
     }
 
     /**
@@ -54,5 +63,30 @@ public class ExamInfoController extends BaseController {
     }
 
 
+    private void doSign(List<ExamInfoVipVo> examInfoVipVoList) throws Exception {
+
+        for (ExamInfoVipVo examInfoVipVo : examInfoVipVoList) {
+            String str = "";
+            if (examInfoVipVo.getUserId() != null) {
+                str += examInfoVipVo.getUserId();
+            }
+            if (examInfoVipVo.getExpirationTime() != null) {
+                str += examInfoVipVo.getExpirationTime().getTime();
+            }
+            if (examInfoVipVo.getIsVip() != null) {
+                str += examInfoVipVo.getIsVip();
+            }
+            // 进行签名服务
+            Signature signature = Signature.getInstance("SHA256withRSA");
+            KeyFactory kf = KeyFactory.getInstance("RSA");
+            PrivateKey privateKey = kf.generatePrivate(new PKCS8EncodedKeySpec(Base64.getDecoder().decode(PrivateKeyUtil.rsaPrivateKey)));
+            signature.initSign(privateKey);
+            signature.update(str.getBytes("UTF-8"));
+            byte[] signedData = signature.sign();
+            String sign = Base64.getEncoder().encodeToString(signedData);
+            examInfoVipVo.setSign(sign);
+        }
+    }
+
 
 }

+ 35 - 7
jsjp-admin/src/main/java/com/miaxis/app/controller/exam/VipUserExamController.java

@@ -2,9 +2,8 @@ package com.miaxis.app.controller.exam;
 
 import com.miaxis.common.constant.Constants;
 import com.miaxis.common.core.controller.BaseController;
-import com.miaxis.common.core.domain.entity.UserInfo;
 import com.miaxis.common.core.page.ResponsePageInfo;
-import com.miaxis.common.utils.SecurityUtils;
+import com.miaxis.common.utils.PrivateKeyUtil;
 import com.miaxis.examvip.domain.VipUserExam;
 import com.miaxis.examvip.service.IVipUserExamService;
 import io.swagger.annotations.Api;
@@ -14,6 +13,11 @@ import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.security.KeyFactory;
+import java.security.PrivateKey;
+import java.security.Signature;
+import java.security.spec.PKCS8EncodedKeySpec;
+import java.util.Base64;
 import java.util.List;
 
 /**
@@ -23,8 +27,8 @@ import java.util.List;
  * @date 2023-03-20
  */
 @RestController
-@RequestMapping(Constants.OPEN_PREFIX+"/vip/exam")
-@Api(tags={"【APP-考场会员】"})
+@RequestMapping(Constants.OPEN_PREFIX + "/vip/exam")
+@Api(tags = {"【APP-考场会员】"})
 public class VipUserExamController extends BaseController {
     @Autowired
     private IVipUserExamService vipUserExamService;
@@ -34,14 +38,38 @@ public class VipUserExamController extends BaseController {
      */
     @GetMapping("/list")
     @ApiOperation("查询当前用户考试会员列表")
-    public ResponsePageInfo<VipUserExam> list(Long userId){
+    public ResponsePageInfo<VipUserExam> list(Long userId,Long examId) throws Exception {
         VipUserExam vipUserExam = new VipUserExam();
         vipUserExam.setUserId(userId);
+        vipUserExam.setExamId(examId);
         List<VipUserExam> list = vipUserExamService.selectVipUserExamList(vipUserExam);
+        this.doSign(list);
         return toResponsePageInfo(list);
     }
-    
 
 
+    private void doSign(List<VipUserExam> userExamList) throws Exception {
 
-}
+        for (VipUserExam userExam : userExamList) {
+            String str = "";
+            if (userExam.getUserId() != null) {
+                str += userExam.getUserId();
+            }
+            if (userExam.getExpirationTime() != null) {
+                str += userExam.getExpirationTime().getTime();
+            }
+            if (userExam.getIsVip() != null) {
+                str += userExam.getIsVip();
+            }
+            // 进行签名服务
+            Signature signature = Signature.getInstance("SHA256withRSA");
+            KeyFactory kf = KeyFactory.getInstance("RSA");
+            PrivateKey privateKey = kf.generatePrivate(new PKCS8EncodedKeySpec(Base64.getDecoder().decode(PrivateKeyUtil.rsaPrivateKey)));
+            signature.initSign(privateKey);
+            signature.update(str.getBytes("UTF-8"));
+            byte[] signedData = signature.sign();
+            String sign = Base64.getEncoder().encodeToString(signedData);
+            userExam.setSign(sign);
+        }
+    }
+}

+ 3 - 15
jsjp-admin/src/main/java/com/miaxis/app/controller/userInfo/UserVipController.java

@@ -8,6 +8,7 @@ import java.security.Signature;
 import java.security.spec.PKCS8EncodedKeySpec;
 import java.util.*;
 
+import com.miaxis.common.utils.PrivateKeyUtil;
 import com.miaxis.newgzpt.domain.GzptVideoVip;
 import com.miaxis.newgzpt.vo.GzptVideoVipVO;
 import com.miaxis.userInfo.dto.UserVipDTO;
@@ -47,19 +48,6 @@ public class UserVipController extends BaseController {
     @Autowired
     private IUserVipService userVipService;
 
-    private String rsaPrivateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMLNHTgsyYOXDJVF8r4qCyb+8Uw4" +
-            "XKq8aThAhUIaPYIop+HJxETGbXk3e0o46i4iOX8RTv0i3jmhL6W0mSxy9ismfXPP7VtKgEt6VnMm" +
-            "ufsrQ2kcXyRsKmuwUd3rTH5gniXwLdIPF8V5ujiSq94nPHok1krDMWbss8Q7lcH2kQFHAgMBAAEC" +
-            "gYBh6Eu2TzRdMg79+7EciO8gA2Tt5SoWGipcPnl7lsqxX5O5dPpzgrPFB/CshlyVIVh6mA12Rw8g" +
-            "MfZLt7CA2asFdgGHfgCvMjsCnL2U1Nf1QFnsnGXmFXeVUvdy7XPILi75rVyOEAw+/f3KzjSA7B3w" +
-            "URE8M2QlIUcjm8LLyCVC4QJBAO+taJH7pVZGVn2upsOk14X08QU0lsQ7ufe/8VXe+IujwGMh34U6" +
-            "BHGV7grodtA7TvQ3mDggQLHB2+IxBWdDCrcCQQDQEVMI+CD7afEyN9rK/MAJwevtxNaTyEd1bhKw" +
-            "t6WKr1YbAdUz2gvnpCQjD1Gqt5yXHKu279msX9W4euXePG3xAkBUCYZn4UdIp+L9sHZSlQLoukik" +
-            "HZtbdOGw58Ez7blSJPl5CNB5wyz5sqtDcdzvCEyXvsKFs3FbonB5r9yIJ26jAkEAugGC1dXcxmWj" +
-            "dl1wf18M3qw6GkmJ+ntlRpmso8bJev3cYDB3RO99DQw0MhOT0qZqmrzK1bP+SJc0HMPhk5c6QQJA" +
-            "WRLIxmeM/P9X2mDjMrI46Wnn27QoKGgYSHdPxmLD0y7NUytf5HyCsY2vhA9FZcnikibax7SwzC/B" +
-            "D7yOXFAy/Q==";
-
 
     /**
      * 获取会员信息详细信息
@@ -185,7 +173,7 @@ public class UserVipController extends BaseController {
         // 进行签名服务
         Signature signature = Signature.getInstance("SHA256withRSA");
         KeyFactory kf = KeyFactory.getInstance("RSA");
-        PrivateKey privateKey = kf.generatePrivate(new PKCS8EncodedKeySpec(Base64.getDecoder().decode(rsaPrivateKey)));
+        PrivateKey privateKey = kf.generatePrivate(new PKCS8EncodedKeySpec(Base64.getDecoder().decode(PrivateKeyUtil.rsaPrivateKey)));
         signature.initSign(privateKey);
         signature.update(str.getBytes("UTF-8"));
         byte[] signedData = signature.sign();
@@ -222,7 +210,7 @@ public class UserVipController extends BaseController {
         // 进行签名服务
         Signature signature = Signature.getInstance("SHA256withRSA");
         KeyFactory kf = KeyFactory.getInstance("RSA");
-        PrivateKey privateKey = kf.generatePrivate(new PKCS8EncodedKeySpec(Base64.getDecoder().decode(rsaPrivateKey)));
+        PrivateKey privateKey = kf.generatePrivate(new PKCS8EncodedKeySpec(Base64.getDecoder().decode(PrivateKeyUtil.rsaPrivateKey)));
         signature.initSign(privateKey);
         signature.update(str.getBytes("UTF-8"));
         byte[] signedData = signature.sign();

+ 20 - 0
jsjp-common/src/main/java/com/miaxis/common/utils/PrivateKeyUtil.java

@@ -0,0 +1,20 @@
+package com.miaxis.common.utils;
+
+public class PrivateKeyUtil {
+
+
+     public static String rsaPrivateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMLNHTgsyYOXDJVF8r4qCyb+8Uw4" +
+            "XKq8aThAhUIaPYIop+HJxETGbXk3e0o46i4iOX8RTv0i3jmhL6W0mSxy9ismfXPP7VtKgEt6VnMm" +
+            "ufsrQ2kcXyRsKmuwUd3rTH5gniXwLdIPF8V5ujiSq94nPHok1krDMWbss8Q7lcH2kQFHAgMBAAEC" +
+            "gYBh6Eu2TzRdMg79+7EciO8gA2Tt5SoWGipcPnl7lsqxX5O5dPpzgrPFB/CshlyVIVh6mA12Rw8g" +
+            "MfZLt7CA2asFdgGHfgCvMjsCnL2U1Nf1QFnsnGXmFXeVUvdy7XPILi75rVyOEAw+/f3KzjSA7B3w" +
+            "URE8M2QlIUcjm8LLyCVC4QJBAO+taJH7pVZGVn2upsOk14X08QU0lsQ7ufe/8VXe+IujwGMh34U6" +
+            "BHGV7grodtA7TvQ3mDggQLHB2+IxBWdDCrcCQQDQEVMI+CD7afEyN9rK/MAJwevtxNaTyEd1bhKw" +
+            "t6WKr1YbAdUz2gvnpCQjD1Gqt5yXHKu279msX9W4euXePG3xAkBUCYZn4UdIp+L9sHZSlQLoukik" +
+            "HZtbdOGw58Ez7blSJPl5CNB5wyz5sqtDcdzvCEyXvsKFs3FbonB5r9yIJ26jAkEAugGC1dXcxmWj" +
+            "dl1wf18M3qw6GkmJ+ntlRpmso8bJev3cYDB3RO99DQw0MhOT0qZqmrzK1bP+SJc0HMPhk5c6QQJA" +
+            "WRLIxmeM/P9X2mDjMrI46Wnn27QoKGgYSHdPxmLD0y7NUytf5HyCsY2vhA9FZcnikibax7SwzC/B" +
+            "D7yOXFAy/Q==";
+
+
+}

+ 0 - 3
jsjp-service/src/main/java/com/miaxis/exam/domain/ExamInfo.java

@@ -69,8 +69,5 @@ public class ExamInfo extends BaseBusinessEntity {
     @ApiModelProperty(value = "价格")
     private Integer price;
 
-    /** 课程数 */
-    private transient Integer videoCount;
-
 
 }

+ 29 - 0
jsjp-service/src/main/java/com/miaxis/exam/dto/ExamInfoDto.java

@@ -0,0 +1,29 @@
+package com.miaxis.exam.dto;
+
+import com.miaxis.common.core.domain.BaseBusinessEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * 考场信息对象 exam_info
+ *
+ * @author miaxis
+ * @date 2023-03-20
+ */
+@Data
+@ApiModel(value = "ExamInfoDto", description = "考场信息输入对象")
+public class ExamInfoDto  {
+
+    @ApiModelProperty(value = "用户id",required = true)
+    private Long userId;
+
+    @ApiModelProperty(value = "考场名称")
+    private String name;
+
+    @ApiModelProperty(value = "城市ID")
+    private String cityId;
+
+
+
+}

+ 4 - 4
jsjp-service/src/main/java/com/miaxis/exam/mapper/ExamInfoMapper.java

@@ -2,8 +2,8 @@ package com.miaxis.exam.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.miaxis.exam.domain.ExamInfo;
-import com.miaxis.exam.vo.ExamInfoCityVo;
-import com.miaxis.exam.vo.ExamInfoProviceVo;
+import com.miaxis.exam.dto.ExamInfoDto;
+import com.miaxis.exam.vo.ExamInfoVipVo;
 
 import java.util.List;
 
@@ -17,10 +17,10 @@ public interface ExamInfoMapper extends BaseMapper<ExamInfo> {
     /**
      * 查询考场信息列表
      *
-     * @param examInfo 考场信息
+     * @param examInfoDto 考场信息
      * @return 考场信息集合
      */
-    List<ExamInfo> selectExamInfoList(ExamInfo examInfo);
+    List<ExamInfoVipVo> selectExamInfoList(ExamInfoDto examInfoDto);
 
 
 }

+ 4 - 4
jsjp-service/src/main/java/com/miaxis/exam/service/IExamInfoService.java

@@ -2,8 +2,8 @@ package com.miaxis.exam.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.miaxis.exam.domain.ExamInfo;
-import com.miaxis.exam.vo.ExamInfoCityVo;
-import com.miaxis.exam.vo.ExamInfoProviceVo;
+import com.miaxis.exam.dto.ExamInfoDto;
+import com.miaxis.exam.vo.ExamInfoVipVo;
 
 import java.util.List;
 
@@ -17,9 +17,9 @@ public interface IExamInfoService extends IService<ExamInfo>{
     /**
      * 查询考场信息列表
      *
-     * @param examInfo 考场信息
+     * @param examInfoDto 考场信息
      * @return 考场信息集合
      */
-    List<ExamInfo> selectExamInfoList(ExamInfo examInfo);
+    List<ExamInfoVipVo> selectExamInfoList(ExamInfoDto examInfoDto);
 
 }

+ 5 - 5
jsjp-service/src/main/java/com/miaxis/exam/service/impl/ExamInfoServiceImpl.java

@@ -2,10 +2,10 @@ package com.miaxis.exam.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.miaxis.exam.domain.ExamInfo;
+import com.miaxis.exam.dto.ExamInfoDto;
 import com.miaxis.exam.mapper.ExamInfoMapper;
 import com.miaxis.exam.service.IExamInfoService;
-import com.miaxis.exam.vo.ExamInfoCityVo;
-import com.miaxis.exam.vo.ExamInfoProviceVo;
+import com.miaxis.exam.vo.ExamInfoVipVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -25,12 +25,12 @@ public class ExamInfoServiceImpl extends ServiceImpl<ExamInfoMapper, ExamInfo> i
     /**
      * 查询考场信息列表
      *
-     * @param examInfo 考场信息
+     * @param examInfoDto 考场信息
      * @return 考场信息
      */
     @Override
-    public List<ExamInfo> selectExamInfoList(ExamInfo examInfo){
-        return examInfoMapper.selectExamInfoList(examInfo);
+    public List<ExamInfoVipVo> selectExamInfoList(ExamInfoDto examInfoDto){
+        return examInfoMapper.selectExamInfoList(examInfoDto);
     }
 
 

+ 1 - 1
jsjp-service/src/main/java/com/miaxis/exam/vo/ExamInfoCityVo.java

@@ -13,7 +13,7 @@ import lombok.Data;
  */
 @Data
 @ApiModel(value = "ExamInfoCityVo", description = "考场信息城市返回值")
-public class ExamInfoCityVo extends BaseBusinessEntity {
+public class ExamInfoCityVo  {
     private static final long serialVersionUID = 1L;
 
     /** 城市ID */

+ 69 - 0
jsjp-service/src/main/java/com/miaxis/exam/vo/ExamInfoVipVo.java

@@ -0,0 +1,69 @@
+package com.miaxis.exam.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 考场信息对象 exam_info
+ *
+ * @author miaxis
+ * @date 2023-03-20
+ */
+@Data
+@ApiModel(value = "ExamInfoVipVO", description = "考场信息返回对象")
+public class ExamInfoVipVo  {
+
+    @ApiModelProperty(value = "id")
+    private Long id;
+
+    /** 考场名称 */
+    @ApiModelProperty(value = "考场名称")
+    private String name;
+
+    /** 考场图片 */
+    @ApiModelProperty(value = "考场图片")
+    private String image;
+
+    /** 省份ID */
+    @ApiModelProperty(value = "省份ID")
+    private String provinceId;
+
+    /** 省份名称 */
+    @ApiModelProperty(value = "省份名称")
+    private String province;
+
+    /** 城市ID */
+    @ApiModelProperty(value = "城市ID")
+    private String cityId;
+
+    /** 城市名称 */
+    @ApiModelProperty(value = "城市名称")
+    private String city;
+
+    /** 城市名称 */
+    @ApiModelProperty(value = "价格")
+    private Integer price;
+
+    /** 课程数 */
+    @ApiModelProperty(value = "课程数")
+    private transient Integer videoCount;
+
+    /** 用户ID */
+    @ApiModelProperty(value = "用户ID")
+    private Long userId;
+
+    /** 到期时间 */
+    @ApiModelProperty(value = "到期时间")
+    private Date expirationTime;
+
+    @ApiModelProperty(value = "是否VIP")
+    private Integer isVip;
+
+    @ApiModelProperty(value = "签名")
+    private String sign;
+
+
+}

+ 4 - 1
jsjp-service/src/main/java/com/miaxis/examvip/domain/VipUserExam.java

@@ -66,8 +66,11 @@ public class VipUserExam extends BaseBusinessEntity {
     @ApiModelProperty(value = "到期时间")
     private Date expirationTime;
 
-    @ApiModelProperty(value = "到期时间")
+    @ApiModelProperty(value = "是否VIP")
     private Integer isVip;
 
+    @ApiModelProperty(value = "到期时间")
+    private String sign;
+
 
 }

+ 12 - 9
jsjp-service/src/main/resources/mapper/exam/ExamInfoMapper.xml

@@ -18,18 +18,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectExamInfoVo">
-        select *,(select count(1) from vip_exam_video v where v.exam_id = e.id) as video_count from exam_info e
+        select * from exam_info
     </sql>
 
-    <select id="selectExamInfoList" parameterType="ExamInfo" resultMap="ExamInfoResult">
-        <include refid="selectExamInfoVo"/>
+    <select id="selectExamInfoList" parameterType="com.miaxis.exam.dto.ExamInfoDto" resultType="com.miaxis.exam.vo.ExamInfoVipVo">
+        select *,(select count(1) from vip_exam_video v where v.exam_id = e.id) as video_count,
+            (case
+            when now() <![CDATA[<=]]> v.expiration_time then 1
+            when now()>v.expiration_time then 0
+            end) as is_vip,
+            v.expiration_time,v.user_id
+        from exam_info e left JOIN vip_user_exam v on e.id = v.exam_id
         <where>
-            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
-            <if test="image != null  and image != ''"> and image = #{image}</if>
-            <if test="provinceId != null  and provinceId != ''"> and province_id = #{provinceId}</if>
-            <if test="province != null  and province != ''"> and province = #{province}</if>
-            <if test="cityId != null  and cityId != ''"> and city_id = #{cityId}</if>
-            <if test="city != null  and city != ''"> and city = #{city}</if>
+            <if test="userId != null"> and v.user_id = #{userId}</if>
+            <if test="name != null  and name != ''"> and e.name like concat('%', #{name}, '%')</if>
+            <if test="cityId != null  and cityId != ''"> and e.city_id = #{cityId}</if>
         </where>
     </select>