Преглед изворни кода

调整绑定与解绑的逻辑

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

+ 3 - 8
platform-shop/src/main/java/com/platform/controller/SceneController.java

@@ -77,7 +77,7 @@ public class SceneController extends AbstractController{
             return R.error("参数有误");
         }
         if(!ObjectUtils.isEmpty(sceneParam.getId())){
-            sceneService.update(sceneParam);
+            sceneService.update(sceneParam,true);
         }else{
             // 获取情景信息
             RequestScene requestScene = new RequestScene();
@@ -238,7 +238,7 @@ public class SceneController extends AbstractController{
                         // 判断名称是否修改,如果修改,则同步到本地
                         if (!object.get("sceneName").toString().equals(sceneEntity.getName())) {
                             sceneEntity.setName(object.get("sceneName").toString());
-                            sceneService.update(sceneEntity);
+                            sceneService.update(sceneEntity,true);
                         }
                     }
                     object.put("lived", true);
@@ -346,12 +346,7 @@ public class SceneController extends AbstractController{
         if(ObjectUtils.isEmpty(brandEntity)){
             return R.error("场景获取失败!");
         }
-        BrandBindUserVo brandBindUserVo = new BrandBindUserVo();
-        brandBindUserVo.setUserId(getUserId());
-        brandBindUserVo.setBrandId(brandEntity.getId().intValue());
-        brandBindUserVo.setCanShow(0);
-        brandBindUserVo.setType(1);
-        brandService.bindUsers(Arrays.asList(brandBindUserVo));
+        brandService.bindUser(getUserId(),brandEntity.getId().intValue(),0);
         return R.ok("生成直播间功能,请前往直播间查看。");
     }
 

+ 29 - 8
platform-shop/src/main/java/com/platform/controller/SysUserController.java

@@ -3,13 +3,9 @@ package com.platform.controller;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.platform.annotation.SysLog;
-import com.platform.entity.SysDeptEntity;
-import com.platform.entity.SysRoleEntity;
-import com.platform.entity.SysUserEntity;
+import com.platform.entity.*;
 import com.platform.enums.SysRoleEnum;
-import com.platform.service.SysRoleService;
-import com.platform.service.SysUserRoleService;
-import com.platform.service.SysUserService;
+import com.platform.service.*;
 import com.platform.service.custom.MySysUserBrandService;
 import com.platform.service.impl.SysDeptServiceImpl;
 import com.platform.service.impl.ZhiHouseService;
@@ -66,6 +62,15 @@ public class SysUserController extends AbstractController {
     @Autowired
     private ZhiHouseService zhiHouseService;
 
+    @Autowired
+    private SceneService sceneService;
+
+    @Autowired
+    private BrandService brandService;
+
+    @Autowired
+    private GoodsService goodsService;
+
     @Value("${scenePath}")
     private String scenePath;
 
@@ -223,10 +228,26 @@ public class SysUserController extends AbstractController {
         //更新密码
         sysUserService.updatePassword(getUser().getMobile(), null, null, fdkkUser);
 
-        zhiHouseService.bind4dkkUser(fdkkUser,null,token);
-
         // 指房宝解绑
+        zhiHouseService.bind4dkkUser(fdkkUser,null,token);
 
+        Long currentUserId = getUserId();
+
+        List<SceneEntity> scenes = sceneService.queryByUserId(currentUserId);
+        scenes.parallelStream().filter(scene -> scene.getSceneUrl().contains("www.4dkankan.com")
+                || scene.getSceneUrl().contains("test.4dkankan.com")).forEach(scene -> {
+            // 四维看看场景数据解绑
+            scene.setCreateUserId(null);
+            sceneService.update(scene, false);
+            // 四维看看场景直播间数据解绑
+            BrandEntity brandEntity = brandService.queryByScene(scene.getSceneNum());
+            if(ObjectUtils.isEmpty(brandEntity)){
+                return;
+            }
+            brandService.unbindUser(currentUserId,brandEntity.getId().intValue());
+            // 直播间商品删除
+            goodsService.deleteByBrandId(brandEntity.getId());
+        });
         return R.ok();
     }
 

+ 3 - 0
platform-shop/src/main/java/com/platform/dao/GoodsDao.java

@@ -1,6 +1,7 @@
 package com.platform.dao;
 
 import com.platform.entity.GoodsEntity;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * Dao
@@ -11,4 +12,6 @@ import com.platform.entity.GoodsEntity;
  */
 public interface GoodsDao extends BaseDao<GoodsEntity> {
     Integer queryMaxId();
+
+    int deleteByBrandId(@Param("brandId") Long brandId);
 }

+ 4 - 0
platform-shop/src/main/java/com/platform/service/BrandService.java

@@ -103,4 +103,8 @@ public interface BrandService {
     BrandEntity generateDefaultLiveRoom(String sceneNum);
 
     void bindUsers(List<BrandBindUserVo> brandBindUserVoList);
+
+    void bindUser(Long userId,Integer brandId,Integer canShow);
+
+    void unbindUser(Long userId,Integer brandId);
 }

+ 2 - 0
platform-shop/src/main/java/com/platform/service/GoodsService.java

@@ -131,4 +131,6 @@ public interface GoodsService {
      * @return
      */
     int unSale(Integer id);
+
+    int deleteByBrandId(Long id);
 }

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

@@ -55,7 +55,7 @@ public interface SceneService {
      * @param brand 实体
      * @return 更新条数
      */
-    R update(SceneEntity brand);
+    R update(SceneEntity brand,boolean checkName);
 
     /**
      * 根据主键删除

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

@@ -363,70 +363,65 @@ public class BrandServiceImpl implements BrandService {
     }
 
     public void bindUsers(List<BrandBindUserVo> brandBindUserVoList) {
-        for(BrandBindUserVo brandBindUserVo : brandBindUserVoList){
-            if(null == brandBindUserVo.getType()){
-                continue;
-            }
-            SysUserBrand dbUserBrand  = mySysUserBrandService.getUserBrandById(brandBindUserVo.getUserId() ,
-                    brandBindUserVo.getBrandId());
-            //绑定或者修改带看权限
-            if(brandBindUserVo.getType().compareTo(1) == 0){
-                if(brandBindUserVo.getCanShow().compareTo(1) != 0 && brandBindUserVo.getCanShow().compareTo(0) != 0){
-                    log.info("带看权限类型非法");
-                    continue;
-                }
-                if(null != dbUserBrand){
-                    //默认为更新带看权限
-                    if(null == brandBindUserVo.getCanShow()){
-                        continue;
-                    }
-                    if(null != dbUserBrand.getCanShow() && dbUserBrand.getCanShow().compareTo(brandBindUserVo.getCanShow()) == 0){
-                        log.info("此用户权限已改过,无需重复修改");
-                        continue;
-                    }
-                    dbUserBrand.setCanShow(brandBindUserVo.getCanShow());
-                    int update = mySysUserBrandService.updateSysUserBrand(dbUserBrand);
-                    if(update != 1){
-                        log.info("更新权限失败");
-                    }
-                }else{
-                    //新增绑定关系
-                    SysUserEntity sysUserEntity = sysUserService.queryObject(brandBindUserVo.getUserId());
-                    if(null == sysUserEntity){
-                        log.info("用户不存在");
-                        continue;
+        brandBindUserVoList.parallelStream().filter(vo -> !ObjectUtils.isEmpty(vo.getType())).forEach(vo -> {
+                    //绑定或者修改带看权限
+                    if (vo.getType().compareTo(1) == 0) {
+                        bindUser(vo.getUserId(), vo.getBrandId(), vo.getCanShow());
+                    } else {
+                        unbindUser(vo.getUserId(), vo.getBrandId());
                     }
-                    BrandEntity brandEntity = queryObject(brandBindUserVo.getBrandId());
-                    if(null == brandEntity){
-                        log.info("店铺不存在");
-                        continue;
-                    }
-                    dbUserBrand = new SysUserBrand();
-                    dbUserBrand.setBrandId(brandEntity.getId().longValue());
-                    dbUserBrand.setUserId(brandBindUserVo.getUserId());
-                    dbUserBrand.setCanShow(brandBindUserVo.getCanShow());
-                    dbUserBrand.setEnable(1);
-                    dbUserBrand.setPhoneNum(sysUserEntity.getMobile());
-                    dbUserBrand.setSceneNum(brandEntity.getSceneNum());
-                    int insert = mySysUserBrandService.addRelation(dbUserBrand);
-                    if(insert != 1){
-                        log.info("绑定失败,请重试");
-                    }
-                }
-            }else{
-                //解绑
-                if(null == dbUserBrand){
-                    log.info("用户之前未绑定,无需解绑");
-                    continue;
-                }
-                dbUserBrand.setCanShow(brandBindUserVo.getCanShow());
-                dbUserBrand.setEnable(0);
-                int update = mySysUserBrandService.updateSysUserBrand(dbUserBrand);
-                if(update != 1){
-                    log.info("解绑失败");
                 }
+        );
+    }
+
+    public void bindUser(Long userId,Integer brandId,Integer canShow) {
+        SysUserBrand dbUserBrand  = mySysUserBrandService.getUserBrandById(userId,brandId);
+        if(ObjectUtils.isEmpty(canShow) || (canShow.compareTo(1) != 0 && canShow.compareTo(0) != 0)){
+            log.info("带看权限类型非法");
+            return;
+        }
+        if(null != dbUserBrand){
+            if(null != dbUserBrand.getCanShow() && dbUserBrand.getCanShow().compareTo(canShow) == 0){
+                log.info("此用户权限已改过,无需重复修改");
+                return;
+            }
+            dbUserBrand.setCanShow(canShow);
+            mySysUserBrandService.updateSysUserBrand(dbUserBrand);
+        }else{
+            //新增绑定关系
+            SysUserEntity sysUserEntity = sysUserService.queryObject(userId);
+            if(null == sysUserEntity){
+                log.info("用户不存在");
+                return;
             }
+            BrandEntity brandEntity = queryObject(brandId);
+            if(null == brandEntity){
+                log.info("店铺不存在");
+                return;
+            }
+            dbUserBrand = new SysUserBrand();
+            dbUserBrand.setBrandId(brandId.longValue());
+            dbUserBrand.setUserId(userId);
+            dbUserBrand.setCanShow(canShow);
+            dbUserBrand.setEnable(1);
+            dbUserBrand.setPhoneNum(sysUserEntity.getMobile());
+            dbUserBrand.setSceneNum(brandEntity.getSceneNum());
+            mySysUserBrandService.addRelation(dbUserBrand);
+        }
+    }
 
+    public void unbindUser(Long userId,Integer brandId) {
+        SysUserBrand dbUserBrand  = mySysUserBrandService.getUserBrandById(userId ,brandId);
+        //解绑
+        if(null == dbUserBrand){
+            log.info("用户之前未绑定,无需解绑");
+            return;
+        }
+        dbUserBrand.setCanShow(0);
+        dbUserBrand.setEnable(0);
+        int update = mySysUserBrandService.updateSysUserBrand(dbUserBrand);
+        if(update != 1){
+            log.info("解绑失败");
         }
     }
 }

+ 5 - 0
platform-shop/src/main/java/com/platform/service/impl/GoodsServiceImpl.java

@@ -432,4 +432,9 @@ public class GoodsServiceImpl implements GoodsService {
         goodsEntity.setUpdateTime(new Date());
         return goodsDao.update(goodsEntity);
     }
+
+    @Override
+    public int deleteByBrandId(Long brandId) {
+        return goodsDao.deleteByBrandId(brandId);
+    }
 }

+ 10 - 4
platform-shop/src/main/java/com/platform/service/impl/SceneServiceImpl.java

@@ -62,10 +62,12 @@ public class SceneServiceImpl implements SceneService {
     }
 
     @Override
-    public R update(SceneEntity brand) {
-        SceneEntity SceneEntity = sceneDao.findByName(brand.getName());
-        if(SceneEntity != null && SceneEntity.getId().intValue() != brand.getId().intValue()){
-            return R.error("店铺名称重复");
+    public R update(SceneEntity brand,boolean checkName) {
+        if(checkName){
+            SceneEntity SceneEntity = sceneDao.findByName(brand.getName());
+            if(SceneEntity != null && SceneEntity.getId().intValue() != brand.getId().intValue()){
+                return R.error("店铺名称重复");
+            }
         }
         int update = sceneDao.update(brand);
         if(update != 1){
@@ -124,6 +126,10 @@ public class SceneServiceImpl implements SceneService {
                 // 查询本地场景是否存在
                 SceneEntity sceneEntity = queryByScene(map.get("num"));
                 if (!ObjectUtils.isEmpty(sceneEntity)) {
+                    if(ObjectUtils.isEmpty(sceneEntity.getCreateUserId())){
+                        sceneEntity.setCreateUserId(userId);
+                        update(sceneEntity,false);
+                    }
                     return;
                 }
                 SceneEntity scene = new SceneEntity();

+ 4 - 0
platform-shop/src/main/resources/com/platform/dao/GoodsDao.xml

@@ -376,4 +376,8 @@
     <select id="queryMaxId" resultType="java.lang.Integer" parameterType="map">
         SELECT MAX(id) FROM nideshop_goods
     </select>
+
+    <delete id="deleteByBrandId">
+        delete from nideshop_goods where brand_id = #{brandId}
+    </delete>
 </mapper>