tianboguang пре 3 година
родитељ
комит
529adb2a06

+ 30 - 24
platform-shop/src/main/java/com/platform/controller/BrandController.java

@@ -22,6 +22,7 @@ import io.swagger.annotations.*;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.transaction.annotation.Transactional;
@@ -184,31 +185,36 @@ public class BrandController extends AbstractController{
             return R.error("场景码错误!");
         }
 
-        // 判断直播间名称是否重复
-        Map<String,Object> paramsMap = new HashMap<>();
-        paramsMap.put("name",params.getName());
-        List<BrandEntity> entities = brandService.queryList(paramsMap);
-        if(!ObjectUtils.isEmpty(entities)){
-            return R.error("直播间名称重复!");
-        }
-        BrandEntity brand = brandService.queryByScene(params.getSceneNum());
-        if(!ObjectUtils.isEmpty(brand)){
-            return R.error("该场景已经绑定直播间!");
-        }
-        brand = new BrandEntity();
-        BeanUtils.copyProperties(params,brand);
-        brand.setCreateUserId(getUserId());
-        if (ObjectUtils.isEmpty(brand.getType())) {
-            brand.setType(0);
-        }
-        // 生成直播间地址
-        String liveRoomUrl = scene.getSceneUrl().replaceAll("smobile.html", "shop.html");
-        brand.setLiveRoomUrl(liveRoomUrl);
+        try {
+            // 判断直播间名称是否重复
+            Map<String,Object> paramsMap = new HashMap<>();
+            paramsMap.put("name",params.getName());
+            List<BrandEntity> entities = brandService.queryList(paramsMap);
+            if(!ObjectUtils.isEmpty(entities)){
+                return R.error("直播间名称重复!");
+            }
+            BrandEntity brand = brandService.queryByScene(params.getSceneNum());
+            if(!ObjectUtils.isEmpty(brand)){
+                return R.error("该场景已经绑定直播间!");
+            }
+            brand = new BrandEntity();
+            BeanUtils.copyProperties(params,brand);
+            brand.setCreateUserId(getUserId());
+            if (ObjectUtils.isEmpty(brand.getType())) {
+                brand.setType(0);
+            }
+            // 生成直播间地址
+            String liveRoomUrl = scene.getSceneUrl().replaceAll("smobile.html", "shop.html");
+            brand.setLiveRoomUrl(liveRoomUrl);
 
-        brandService.save(brand);
-        //生成微信分享二维码
-        brandService.generalWxShareQrCode(brand , true);
-        brandService.sendDataToApi(brand);
+            brandService.save(brand);
+            //生成微信分享二维码
+            brandService.generalWxShareQrCode(brand , true);
+            brandService.sendDataToApi(brand);
+        } catch (BeansException e) {
+            e.printStackTrace();
+            return R.error(ObjectUtils.isEmpty(e.getMessage())?"该场景已经绑定直播间!":e.getMessage());
+        }
         return R.ok("新增商铺成功");
     }
 

+ 23 - 16
platform-shop/src/main/java/com/platform/controller/SceneController.java

@@ -328,25 +328,32 @@ public class SceneController extends AbstractController{
     @PostMapping("/generateDefaultLiveRoom")
     @RequiresPermissions("brand:delete")
     public R generateDefaultLiveRoom(@RequestBody SceneEntity requestScene) {
-        String sceneNum = requestScene.getSceneNum();
-        if(ObjectUtils.isEmpty(sceneNum)){
-            return R.error("参数有误!");
-        }
+        try {
+            String sceneNum = requestScene.getSceneNum();
+            if (ObjectUtils.isEmpty(sceneNum)) {
+                return R.error("参数有误!");
+            }
 
-        BrandEntity brand = brandService.queryByScene(sceneNum);
-        if(!ObjectUtils.isEmpty(brand)){
-            return R.error("直播间已存在!");
-        }
+            BrandEntity brand = brandService.queryByScene(sceneNum);
+            if (!ObjectUtils.isEmpty(brand)) {
+                return R.error("直播间已存在!");
+            }
 
-        SceneEntity entity = sceneService.queryByScene(sceneNum);
-        if(ObjectUtils.isEmpty(entity)){
-            updateShowStatus(requestScene);
-        }
-        BrandEntity brandEntity = brandService.generateDefaultLiveRoom(sceneNum);
-        if(ObjectUtils.isEmpty(brandEntity)){
-            return R.error("场景获取失败!");
+            SceneEntity entity = sceneService.queryByScene(sceneNum);
+            if (ObjectUtils.isEmpty(entity)) {
+                updateShowStatus(requestScene);
+            }
+            BrandEntity brandEntity = null;
+
+            brandEntity = brandService.generateDefaultLiveRoom(sceneNum);
+            if(ObjectUtils.isEmpty(brandEntity)){
+                return R.error("场景获取失败!");
+            }
+            brandService.bindUser(getUserId(),brandEntity.getId().intValue(),0);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return R.error(ObjectUtils.isEmpty(e.getMessage()) ? "生成直播间失败!" : e.getMessage());
         }
-        brandService.bindUser(getUserId(),brandEntity.getId().intValue(),0);
         return R.ok("生成直播间功能,请前往直播间查看。");
     }
 

+ 1 - 1
platform-shop/src/main/java/com/platform/service/impl/BrandServiceImpl.java

@@ -144,7 +144,7 @@ public class BrandServiceImpl implements BrandService {
     public int save(BrandEntity brand) {
         BrandEntity brandEntity = brandDao.findByName(brand.getName());
         if(brandEntity != null){
-            throw new ApiRRException("直播间生成失败,已经存在相同名称直播间");
+            throw new RuntimeException("直播间生成失败,已经存在相同名称直播间");
         }
         return brandDao.save(brand);
     }