Browse Source

[fix]
1、公共方法统一处理url为空的情况

limeng 4 months ago
parent
commit
9d28d0e9f0

+ 5 - 10
application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/JobProjectToWebController.java

@@ -86,12 +86,9 @@ public class JobProjectToWebController {
         MyPageData<JobProjectVo> jobProjectVoMyPageData = MyPageUtil.makeResponseData(jobProjectList, JobProjectVo.class);
         List<JobProjectVo> dataList = jobProjectVoMyPageData.getDataList();
         //先把imgUrl由jaon转换为List<FileUrlObject>
-        dataList.stream().forEach(item ->
-        {
-            if (StringUtils.isNotEmpty(item.getJobUrl())) {
-                List<String> jobUrl = UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), item.getJobUrl());
-                item.setJobUrlsAfterConvert(jobUrl);
-            }
+        dataList.stream().forEach(item ->{
+            List<String> jobUrl = UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), item.getJobUrl());
+            item.setJobUrlsAfterConvert(jobUrl);
         });
 
         return ResponseResult.success(jobProjectVoMyPageData);
@@ -117,10 +114,8 @@ public class JobProjectToWebController {
             // 使用 Jackson 的 ObjectMapper 进行转换
             ObjectMapper objectMapper = new ObjectMapper();
             TourismFile tourismFile = objectMapper.convertValue(jobProjectVo.getJobFile(), TourismFile.class);
-            if (StringUtils.isNotEmpty(tourismFile.getFileUrl())) {
-                tourismFile.setFileUrlsAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), tourismFile.getFileUrl()));
-                jobProjectVo.setJobFile(MapConvertUtils.convertObjectToMap(tourismFile));
-            }
+            tourismFile.setFileUrlsAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), tourismFile.getFileUrl()));
+            jobProjectVo.setJobFile(MapConvertUtils.convertObjectToMap(tourismFile));
         }
         if(jobProjectVo != null) {
             jobProjectVo.setContactCodeConvert("https://v.xiaoyaotravel.com/image/ContactQRCode/labor_service.png");

+ 11 - 11
application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/LoginToWebsiteController.java

@@ -284,17 +284,17 @@ public class LoginToWebsiteController {
             @MyRequestBody String smsCode,
             @MyRequestBody String countryCode) throws UnsupportedEncodingException
     {
-//        if(smsSwitch.isEnable()) {
-//            // 校验短信验证码
-//            String smsCodeKey = CacheConstants.getSmsCodeKey(loginMoblie);
-//            RBucket<String> bucket = redissonClient.getBucket(smsCodeKey);
-//            String redisCode = bucket.get();
-//            if(StringUtils.isBlank(redisCode) || !redisCode.equals(smsCode)){
-//                return ResponseResult.error(ErrorCodeEnum.SMS_CODE_ERR);
-//            }
-//            // 短信验证码校验成功,清除验证码
-//            bucket.delete();
-//        }
+        if(smsSwitch.isEnable()) {
+            // 校验短信验证码
+            String smsCodeKey = CacheConstants.getSmsCodeKey(loginMoblie);
+            RBucket<String> bucket = redissonClient.getBucket(smsCodeKey);
+            String redisCode = bucket.get();
+            if(StringUtils.isBlank(redisCode) || !redisCode.equals(smsCode)){
+                return ResponseResult.error(ErrorCodeEnum.SMS_CODE_ERR);
+            }
+            // 短信验证码校验成功,清除验证码
+            bucket.delete();
+        }
         // 查询用户信息
         TourUser tourUser = tourUserService.getOne(Wrappers.<TourUser>lambdaQuery().eq(TourUser::getMobile, loginMoblie));
         // 如果用户信息不存在,则新建

+ 1 - 4
application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/WebSiteTourismTravelNotesPublishController.java

@@ -100,7 +100,6 @@ public class WebSiteTourismTravelNotesPublishController {
             tourismProjectTravelNotesWrite.setTourismUrl(coverImageList.get(0).getContent());
         }
 
-
         //判断是新增还是更新
         if(tourismProjectTravelNotesWrite == null){
             TourismProjectTravelNotesWrite tourismProjectTravelNotesWriteSave =
@@ -162,9 +161,7 @@ public class WebSiteTourismTravelNotesPublishController {
         List<TourismProjectTravelNotesWriteCovertVo> dataList = tourismProjectTravelNotesWriteVoMyPageData.getDataList();
         if(CollectionUtils.isNotEmpty(dataList)){
             dataList.stream().forEach(item->{
-                if(item.getTourismUrl()!= null) {
-                    item.setTourismTavelNotesUrl(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), item.getTourismUrl()));
-                }
+                item.setTourismTavelNotesUrl(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), item.getTourismUrl()));
             });
         }
         return ResponseResult.success(tourismProjectTravelNotesWriteVoMyPageData);

+ 1 - 3
application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/WebsiteTourismProjectTravelNotesController.java

@@ -179,9 +179,7 @@ public class WebsiteTourismProjectTravelNotesController {
         List<TourismProjectTravelNotesWriteVo> dataList = tourismProjectTravelNotesWriteVoMyPageData.getDataList();
         if(CollectionUtils.isNotEmpty(dataList)){
             dataList.stream().forEach(item->{
-                if(item.getTourismUrl() != null) {
-                    item.setTourismUrlsAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), item.getTourismUrl()));
-                }
+                item.setTourismUrlsAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), item.getTourismUrl()));
             });
         }
 

+ 7 - 23
application-webadmin/src/main/java/com/tourism/webadmin/app/website/service/impl/BasicToWebServiceImpl.java

@@ -70,9 +70,7 @@ public class BasicToWebServiceImpl implements BasicToWebService
         List<BannerInfoVo> dataList = bannerInfoVoMyPageData.getDataList();
             //先把imgUrl由jaon转换为List<FileUrlObject>
         dataList.stream().forEach(item ->{
-            if (StringUtils.isNotEmpty(item.getImgUrl())) {
-                item.setImgUrlsAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), item.getImgUrl()));
-            }
+            item.setImgUrlsAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), item.getImgUrl()));
         });
 
         return bannerInfoVoMyPageData;
@@ -117,9 +115,7 @@ public class BasicToWebServiceImpl implements BasicToWebService
         List<DirectoryInfoVo> dataList = directoryInfoVoMyPageData.getDataList();
         //先把imgUrl由jaon转换为List<FileUrlObject>
         dataList.stream().forEach(item ->{
-            if (StringUtils.isNotEmpty(item.getHotPictureUrl())) {
-                item.setHotPictureUrlsAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), item.getHotPictureUrl()));
-            }
+            item.setHotPictureUrlsAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), item.getHotPictureUrl()));
         });
         return directoryInfoVoMyPageData;
     }
@@ -144,9 +140,7 @@ public class BasicToWebServiceImpl implements BasicToWebService
         MyPageData<TourismProjectTravelNotesWriteVo> pageData = MyPageUtil.makeResponseData(writeList, TourismProjectTravelNotesWriteVo.class);
         List<TourismProjectTravelNotesWriteVo> dataList = pageData.getDataList();
         dataList.stream().forEach(item->{
-            if (StringUtils.isNotEmpty(item.getTourismUrl())) {
-                item.setHomeHotPicturesAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), item.getTourismUrl()));
-            }
+            item.setHomeHotPicturesAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), item.getTourismUrl()));
         });
 
         return pageData;
@@ -200,9 +194,7 @@ public class BasicToWebServiceImpl implements BasicToWebService
         List<TourismProjectTravelNotesWriteVo> dataList = pageData.getDataList();
 
         dataList.stream().forEach(item->{
-            if(StringUtils.isNotEmpty(item.getTourismUrl())){
-                item.setTourismUrlsAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), item.getTourismUrl()));
-            }
+            item.setTourismUrlsAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), item.getTourismUrl()));
         });
 
         return pageData;
@@ -228,17 +220,9 @@ public class BasicToWebServiceImpl implements BasicToWebService
                 MyModelUtil.copyTo(writeDto, TourismProjectTravelNotesWriteVo.class);
 
         if(writeVo != null) {
-            if (StringUtils.isNotEmpty(writeVo.getTourismUrl())) {
-                writeVo.setTourismUrlsAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), writeVo.getTourismUrl()));
-            }
-
-            if (StringUtils.isNotEmpty(writeVo.getTourismUrl())) {
-                writeVo.setHomeHotPicturesAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), writeVo.getTourismUrl()));
-            }
-
-            if (StringUtils.isNotEmpty(writeVo.getTravelNotesBanner())) {
-                writeVo.setTravelNotesBannerAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), writeVo.getTravelNotesBanner()));
-            }
+            writeVo.setTourismUrlsAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), writeVo.getTourismUrl()));
+            writeVo.setHomeHotPicturesAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), writeVo.getTourismUrl()));
+            writeVo.setTravelNotesBannerAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), writeVo.getTravelNotesBanner()));
         }
         return writeVo;
     }

+ 3 - 6
application-webadmin/src/main/java/com/tourism/webadmin/app/website/service/impl/TourismProjectToWebServiceImpl.java

@@ -105,8 +105,7 @@ public class TourismProjectToWebServiceImpl implements TourismProjectToWebServic
 
         List<TourismProjectVo> dataList = tourismProjectVoMyPageData.getDataList();
         //先把imgUrl由jaon转换为List<FileUrlObject>
-        dataList.stream().forEach(item ->
-        {
+        dataList.stream().forEach(item ->{
             List<String> urlList = UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), item.getHomeHotPicture());
             item.setHomeHotPicturesAfterConvert(urlList);
             List<String> arrayList = UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), item.getTourismUrl());
@@ -130,10 +129,8 @@ public class TourismProjectToWebServiceImpl implements TourismProjectToWebServic
             // 使用 Jackson 的 ObjectMapper 进行转换
             ObjectMapper objectMapper = new ObjectMapper();
             TourismFile tourismFile = objectMapper.convertValue(tourismProjectVo.getTourismFile(), TourismFile.class);
-            if(StringUtils.isNotEmpty(tourismFile.getFileUrl())){
-                tourismFile.setFileUrlsAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), tourismFile.getFileUrl()));
-                tourismProjectVo.setTourismFile(MapConvertUtils.convertObjectToMap(tourismFile));
-            }
+            tourismFile.setFileUrlsAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), tourismFile.getFileUrl()));
+            tourismProjectVo.setTourismFile(MapConvertUtils.convertObjectToMap(tourismFile));
         }
         //二维码路径赋值
 //        tourismProjectVo.setContactCode("[{\"name\":\"微信图片_20241021154757.png\",\"downloadUri\":\"/admin/app/tourTourismProjectTravelNotes/download\",\"filename\":\"6b92b75edcc04da1bd6e4af056911730.png\",\"uploadPath\":\"image/TourTourismProjectTravelNotes/contactCode\"}]");

+ 10 - 11
common/common-additional/src/main/java/com/tourism/common/additional/utils/UrlConvertUtils.java

@@ -1,29 +1,28 @@
 package com.tourism.common.additional.utils;
 
 import com.tourism.common.additional.model.FileUrlObject;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.CollectionUtils;
 
-import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 
 public class UrlConvertUtils {
 
     public static List<String> urlConvert(String hostIpPort, String url){
+        if(StringUtils.isBlank(url)){
+            return new ArrayList<>();
+        }
         ArrayList<String> arrayList = new ArrayList<>();
         if(url.contains("https")){
             arrayList.add(url);
         }else {
-            if (StringUtils.isNotEmpty(url)) {
-                List<FileUrlObject> fileUrlObjectList = JsonUtils.parseFileUrlArray(url, FileUrlObject.class);
-                if (!CollectionUtils.isEmpty(fileUrlObjectList)) {
-                    //遍历每个元素的数组对象,对元素的url对象进行拼接
-                    for (FileUrlObject y : fileUrlObjectList) {
-                        String hotPictureUrlsAfterConvert =
-                                hostIpPort + "/" + y.getUploadPath() + "/" + y.getFilename();
-                        arrayList.add(hotPictureUrlsAfterConvert);
-                    }
+            List<FileUrlObject> fileUrlObjectList = JsonUtils.parseFileUrlArray(url, FileUrlObject.class);
+            if (!CollectionUtils.isEmpty(fileUrlObjectList)) {
+                //遍历每个元素的数组对象,对元素的url对象进行拼接
+                for (FileUrlObject y : fileUrlObjectList) {
+                    String hotPictureUrlsAfterConvert =
+                            hostIpPort + "/" + y.getUploadPath() + "/" + y.getFilename();
+                    arrayList.add(hotPictureUrlsAfterConvert);
                 }
             }
         }