Selaa lähdekoodia

fix 更新二维码查询

tjf 3 vuotta sitten
vanhempi
commit
01b2110060

+ 4 - 0
ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java

@@ -110,6 +110,10 @@ public class UserConstants
      * 门户查询查询码 redis key
      */
     public static final String QUERY_NUM_KEY = "query_num:";
+    /**
+     * 二维码
+     */
+    public static final String QR_IMAGE = "qr_image:";
 
     /**
      * 门户中用户档案拥有者回复短信的key,value存储申请查询人的手机号码

+ 25 - 15
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/QueryServiceImpl.java

@@ -134,11 +134,11 @@ public class QueryServiceImpl implements IQueryService {
                 SendSmsResponse sendSmsResponse = SendSmsUtils.sendSms(phone, "{\"code\":\"" + code + "\"}", accessKeyId, accessKeySecret, signName, templateCode);
                 QuerySendDetailsResponse querySendDetailsResponse = SendSmsUtils.querySendDetails(sendSmsResponse.getBizId(), phone, accessKeyId, accessKeySecret);
                 String ok = querySendDetailsResponse.getCode();
-                if ("OK".equals(ok)){
+                if ("OK".equals(ok)) {
                     //设置验证码10分钟有效期
-                    redisCache.setCacheObject(UserConstants.QUERY_CODE_KEY + phone,code,10,TimeUnit.MINUTES);
+                    redisCache.setCacheObject(UserConstants.QUERY_CODE_KEY + phone, code, 10, TimeUnit.MINUTES);
                     return AjaxResult.success("发送成功");
-                }else {
+                } else {
                     return AjaxResult.error(querySendDetailsResponse.getMessage());
                 }
             } catch (ClientException e) {
@@ -150,6 +150,7 @@ public class QueryServiceImpl implements IQueryService {
 
     /**
      * 给档案拥有者发送询问短信
+     *
      * @param reportQueryLog
      * @return
      */
@@ -157,37 +158,37 @@ public class QueryServiceImpl implements IQueryService {
     public AjaxResult sendQueryNum(ReportQueryLog reportQueryLog) {
         //发送查询码前,先校验验证码是否通过
         AjaxResult result = queryPublic(reportQueryLog);
-        if (!UserConstants.QUERY_SUCCESS.equals(result.get(MSG_TAG))){
+        if (!UserConstants.QUERY_SUCCESS.equals(result.get(MSG_TAG))) {
             return result;
         }
         //验证码通过后,给文档原始人,发送询问查询码的短信
         String reportNumber = reportQueryLog.getReportNumber();
-        if (StringUtils.isNotBlank(reportNumber)){
+        if (StringUtils.isNotBlank(reportNumber)) {
             ReportDetail reportDetail = reportDetailMapper.selectReportDetailByReportNumberDetail(reportNumber);
             //档案拥有者的手机号码
             String phonenumber = reportDetail.getPhonenumber();
-            if (StringUtils.isNotBlank(phonenumber)){
+            if (StringUtils.isNotBlank(phonenumber)) {
                 //给文档创建人发送询问短信
                 try {
                     String queryType = reportQueryLog.getQueryType();
                     StringBuilder sb = new StringBuilder();
                     String phone = "";
-                    if (UserConstants.QUERY_TYPE_PEOPLE.equals(queryType)){
+                    if (UserConstants.QUERY_TYPE_PEOPLE.equals(queryType)) {
                         sb.append(reportQueryLog.getQueryName()).append("(个人)");
                         phone = reportQueryLog.getQueryPhone();
                     }
-                    if (UserConstants.QUERY_TYPE_UNIT.equals(queryType)){
+                    if (UserConstants.QUERY_TYPE_UNIT.equals(queryType)) {
                         sb.append(reportQueryLog.getCompanyName()).append("(单位)");
                         phone = reportQueryLog.getCompanyPhone();
                     }
-                    SendSmsResponse sendSmsResponse = SendSmsUtils.sendSms(phonenumber, "{\"name\":\""+sb.toString()+"\",\"reportNumber\":\""+reportNumber+"\"}", accessKeyId, accessKeySecret, signNameQuery, templateCodeQuery);
+                    SendSmsResponse sendSmsResponse = SendSmsUtils.sendSms(phonenumber, "{\"name\":\"" + sb.toString() + "\",\"reportNumber\":\"" + reportNumber + "\"}", accessKeyId, accessKeySecret, signNameQuery, templateCodeQuery);
                     QuerySendDetailsResponse querySendDetailsResponse = SendSmsUtils.querySendDetails(sendSmsResponse.getBizId(), phonenumber, accessKeyId, accessKeySecret);
                     String ok = querySendDetailsResponse.getCode();
-                    if ("OK".equals(ok)){
+                    if ("OK".equals(ok)) {
                         //redis存储查询人的手机号码
-                        redisCache.setCacheObject(UserConstants.QUERY_NUM_CREATE + phonenumber,phone,30,TimeUnit.MINUTES);
+                        redisCache.setCacheObject(UserConstants.QUERY_NUM_CREATE + phonenumber, phone, 30, TimeUnit.MINUTES);
                         return AjaxResult.success("发送成功,请等待对方回复");
-                    }else {
+                    } else {
                         return AjaxResult.error(querySendDetailsResponse.getMessage());
                     }
                 } catch (ClientException e) {
@@ -207,8 +208,8 @@ public class QueryServiceImpl implements IQueryService {
     private AjaxResult queryByQr(ReportQueryLog reportQueryLog) {
         String qrImage = reportQueryLog.getQrImage();
         String remark = "";
-        if (StringUtils.isBlank(qrImage)){
-             remark = "未接收到二维码";
+        if (StringUtils.isBlank(qrImage)) {
+            remark = "未接收到二维码";
             reportQueryLog.setRemark(remark);
             reportQueryLogMapper.insertReportQueryLog(reportQueryLog);
             return AjaxResult.error(remark);
@@ -216,12 +217,21 @@ public class QueryServiceImpl implements IQueryService {
         try {
             //解析二维码
             String reportNumber = QRCodeUtils.decode(qrImage);
-            if (StringUtils.isBlank(reportNumber)){
+            if (StringUtils.isBlank(reportNumber)) {
                 remark = "二维码解析失败";
                 reportQueryLog.setRemark(remark);
                 reportQueryLogMapper.insertReportQueryLog(reportQueryLog);
                 return AjaxResult.error(remark);
             }
+            //查询二维码有效期
+            String verifyKey = UserConstants.QR_IMAGE + reportNumber;
+            Object cacheObject = redisCache.getCacheObject(verifyKey);
+            if (cacheObject == null) {
+                remark = "二维码已过期";
+                reportQueryLog.setRemark(remark);
+                reportQueryLogMapper.insertReportQueryLog(reportQueryLog);
+                return AjaxResult.error(remark);
+            }
             ReportDetail reportDetail = reportDetailMapper.selectReportDetailByReportNumber(reportNumber);
             reportDetail.setReportUrl(null);
             reportQueryLog.setIsSuccess("0");

+ 58 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ReportDetailServiceImpl.java

@@ -1,13 +1,17 @@
 package com.ruoyi.system.service.impl;
 
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 
 import com.ruoyi.common.config.RuoYiConfig;
 import com.ruoyi.common.constant.UserConstants;
+import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.QRCodeUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.system.domain.InspectInfor;
+import com.ruoyi.system.domain.QueryConfig;
+import com.ruoyi.system.mapper.QueryConfigMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ruoyi.system.mapper.ReportDetailMapper;
@@ -26,6 +30,12 @@ public class ReportDetailServiceImpl implements IReportDetailService
     @Autowired
     private ReportDetailMapper reportDetailMapper;
 
+    @Autowired
+    private QueryConfigMapper queryConfigMapper;
+
+    @Autowired
+    private RedisCache redisCache;
+
     /**
      * 查询报告信息
      * 
@@ -61,8 +71,20 @@ public class ReportDetailServiceImpl implements IReportDetailService
     {
         //生成二维码
         try {
+            //查询二维码的有效期
+            QueryConfig queryConfig = new QueryConfig();
+            queryConfig.setQueryMode("0");
+            QueryConfig queryConfigQr = queryConfigMapper.selectQueryConfig(queryConfig);
+            String qrTime = "30";
+            String qrUnit = "3";
+            if (queryConfigQr != null){
+                 qrTime = queryConfigQr.getQrTime();
+                 qrUnit = queryConfigQr.getQrUnit();
+            }
             //返回二维码地址
             String imagePath= QRCodeUtils.encode(reportDetail.getReportNumber(), null, RuoYiConfig.getUploadPath(), true);
+            String verifyKey = UserConstants.QR_IMAGE + reportDetail.getReportNumber();
+            redisCache.setCacheObject(verifyKey,imagePath,Integer.parseInt(qrTime),changeUnit(qrUnit));
             reportDetail.setQrPath(imagePath);
         } catch (Exception e) {
             e.printStackTrace();
@@ -83,8 +105,20 @@ public class ReportDetailServiceImpl implements IReportDetailService
         if (UserConstants.NOT_UNIQUE.equals(checkReportNumberUpdate(reportDetail))){
             //生成新的二维码覆盖
             try {
+                //查询二维码的有效期
+                QueryConfig queryConfig = new QueryConfig();
+                queryConfig.setQueryMode("0");
+                QueryConfig queryConfigQr = queryConfigMapper.selectQueryConfig(queryConfig);
+                String qrTime = "30";
+                String qrUnit = "3";
+                if (queryConfigQr != null){
+                    qrTime = queryConfigQr.getQrTime();
+                    qrUnit = queryConfigQr.getQrUnit();
+                }
                 //返回二维码地址
                 String imagePath= QRCodeUtils.encode(reportDetail.getReportNumber(), null, RuoYiConfig.getUploadPath(), true);
+                String verifyKey = UserConstants.QR_IMAGE + reportDetail.getReportNumber();
+                redisCache.setCacheObject(verifyKey,imagePath,Integer.parseInt(qrTime),changeUnit(qrUnit));
                 reportDetail.setQrPath(imagePath);
             } catch (Exception e) {
                 e.printStackTrace();
@@ -144,8 +178,32 @@ public class ReportDetailServiceImpl implements IReportDetailService
         ReportDetail infoOld = reportDetailMapper.selectReportDetailByReportId(reportId);
         if (!infoOld.getReportNumber().equals(reportDetail.getReportNumber()))
         {
+            //修改了报告编号,删除原先旧的key
+            String verifyKey = UserConstants.QR_IMAGE + infoOld.getReportNumber();
+            redisCache.deleteObject(verifyKey);
             return UserConstants.NOT_UNIQUE;
         }
         return UserConstants.UNIQUE;
     }
+
+    /**
+     * 转换单位
+     * @param unit
+     * @return
+     */
+    private TimeUnit changeUnit(String unit){
+        if ("0".equals(unit)){
+            return TimeUnit.SECONDS;
+        }
+        if ("1".equals(unit)){
+            return TimeUnit.MINUTES;
+        }
+        if ("2".equals(unit)){
+            return TimeUnit.HOURS;
+        }
+        if ("3".equals(unit)){
+            return TimeUnit.DAYS;
+        }
+        return TimeUnit.DAYS;
+    }
 }

+ 6 - 5
ruoyi-system/src/main/resources/mapper/system/ColumnNavigationBarMapper.xml

@@ -29,7 +29,7 @@
             resultMap="ColumnNavigationBarResult">
         <include refid="selectColumnNavigationBarVo"/>
         where
-        status = '0'
+        del_flag = 'N'
         <if test="parentId != null ">and parent_id = #{parentId}</if>
         <if test="ancestors != null  and ancestors != ''">and ancestors = #{ancestors}</if>
         <if test="columnName != null  and columnName != ''">and column_name like concat('%', #{columnName}, '%')</if>
@@ -44,13 +44,14 @@
         select column_id, column_name from column_navigation_bar
         where
         status = '0'
+        and del_flag = 'N'
         <if test="isTitle != null ">and is_title = #{isTitle}</if>
         <if test="isBottom != null ">and is_bottom = #{isBottom}</if>
     </select>
 
     <select id="selectColumnNavigationBarByColumnId" parameterType="Long" resultMap="ColumnNavigationBarResult">
         <include refid="selectColumnNavigationBarVo"/>
-        where column_id = #{columnId}
+        where column_id = #{columnId}  and del_flag = 'N'
     </select>
 
     <insert id="insertColumnNavigationBar" parameterType="ColumnNavigationBar" useGeneratedKeys="true"
@@ -122,15 +123,15 @@
 
     <select id="checkColumnNameUnique" resultMap="ColumnNavigationBarResult">
         <include refid="selectColumnNavigationBarVo"/>
-        where column_name = #{columnName} and parent_id = #{parentId} limit 1
+        where column_name = #{columnName} and parent_id = #{parentId}  and del_flag = 'N' limit 1
     </select>
 
     <select id="selectNormalChildrenColumnById" parameterType="Long" resultType="int">
-		select count(*) from column_navigation_bar where status = 0 and del_flag = 'N' and find_in_set(#{columnId}, ancestors)
+		select count(*) from column_navigation_bar where  del_flag = 'N' and find_in_set(#{columnId}, ancestors)
 	</select>
 
     <select id="selectChildrenColumnById" parameterType="Long" resultMap="ColumnNavigationBarResult">
-		select * from column_navigation_bar where find_in_set(#{columnId}, ancestors)
+		select * from column_navigation_bar where find_in_set(#{columnId}, ancestors) and del_flag = 'N'
 	</select>
 
     <update id="updateColumnChildren" parameterType="java.util.List">