Kaynağa Gözat

代码优化

黄远 5 yıl önce
ebeveyn
işleme
0437777a0f

+ 4 - 4
lift-system-service/pom.xml

@@ -18,10 +18,10 @@
             <artifactId>xwy-spring-boot</artifactId>
         </dependency>
 
-<!--        <dependency>-->
-<!--            <groupId>cn.com.xwy</groupId>-->
-<!--            <artifactId>xwy-cloud-dependencies</artifactId>-->
-<!--        </dependency>-->
+        <dependency>
+            <groupId>cn.com.xwy</groupId>
+            <artifactId>xwy-cloud-dependencies</artifactId>
+        </dependency>
 
         <!-- 添加公共模块依赖 -->
         <dependency>

+ 1 - 2
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/LoginService.java

@@ -16,7 +16,6 @@ import cn.com.xwy.boot.web.dto.RestResponse;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
@@ -142,7 +141,7 @@ public class LoginService implements ILoginService {
         UserResponse userResponse = new UserResponse();
         //校验团队信息
         MaintenanceCompany maintenanceCompany = maintenanceCompanyService.getById(companyId);
-        if(maintenanceCompany == null){
+        if (maintenanceCompany == null) {
             return RestResponse.success(ApiConstants.RESULT_SUCCESS, "切换团队不存在");
         }
         maintenanceCompany.setCurrentTeamFlag(true);

+ 7 - 1
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/MtCompanyUserService.java

@@ -18,6 +18,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
 import javax.annotation.Resource;
 import java.util.ArrayList;
@@ -76,7 +77,12 @@ public class MtCompanyUserService extends ServiceImpl<MtCompanyUserMapper, MtCom
             userRole.setCompanyId(companyId);
             userRole.setRoleId(roleId);
             userRole.setUserId(userId);
-            userRoleService.save(userRole);
+            boolean saveUserRoleFlag = userRoleService.save(userRole);
+            if(!saveUserRoleFlag){
+                //事务强制回滚
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                return RestResponse.fail(ApiConstants.RESULT_ERROR, "保存角色信息失败");
+            }
         }
         return RestResponse.success(null, ApiConstants.RESULT_SUCCESS, "分配角色成功");
     }