|
@@ -30,6 +30,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.time.LocalDateTime;
|
|
@@ -103,7 +104,9 @@ public class MaintenanceCompanyServiceImpl extends ServiceImpl<MaintenanceCompan
|
|
|
maintenanceCompany.setIsCertificated(ApiConstants.CompanyConstants.MAINTENANCE_NOT_CERTIFICATE);
|
|
|
maintenanceCompany.setRemarks(maintenanceCompanyRequest.getRemarks());
|
|
|
maintenanceCompany.setLogoImg(maintenanceCompanyRequest.getLogoImg());
|
|
|
- this.save(maintenanceCompany);
|
|
|
+ if (!this.save(maintenanceCompany)) {
|
|
|
+ return RestResponse.fail(ApiConstants.RESULT_ERROR, "保存团队信息失败");
|
|
|
+ }
|
|
|
//公司id
|
|
|
Long companyId = maintenanceCompany.getId();
|
|
|
|
|
@@ -111,25 +114,37 @@ public class MaintenanceCompanyServiceImpl extends ServiceImpl<MaintenanceCompan
|
|
|
//1.设置申请用户为企业管理员
|
|
|
UserAccount userAccount = userAccountService.getByUserId(userId);
|
|
|
userAccount.setType(ApiConstants.UserConstants.TYPE_ENTERPRISE_ADMIN);
|
|
|
- userAccountService.updateById(userAccount);
|
|
|
+ if (!userAccountService.updateById(userAccount)) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return RestResponse.fail(ApiConstants.RESULT_ERROR, "更新用户信息失败");
|
|
|
+ }
|
|
|
//2.设置用户类型为企业管理员
|
|
|
MtCompanyUser mtCompanyUser = new MtCompanyUser();
|
|
|
mtCompanyUser.setCreateUserId(userId);
|
|
|
mtCompanyUser.setUserId(userId);
|
|
|
mtCompanyUser.setMtCompanyId(companyId);
|
|
|
- mtCompanyUserService.save(mtCompanyUser);
|
|
|
+ if (!mtCompanyUserService.save(mtCompanyUser)) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return RestResponse.fail(ApiConstants.RESULT_ERROR, "保存成员关联公司信息失败");
|
|
|
+ }
|
|
|
//3.创建默认角色-企业管理员
|
|
|
Role role = new Role();
|
|
|
role.setName(CommonEnum.DefaultRole.ENTERPRISE_ADMIN.getLabel());
|
|
|
role.setCompanyId(companyId);
|
|
|
role.setDescription("企业管理员");
|
|
|
- roleService.save(role);
|
|
|
+ if (!roleService.save(role)) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return RestResponse.fail(ApiConstants.RESULT_ERROR, "保存角色信息失败");
|
|
|
+ }
|
|
|
//4.创建用户角色关联关系
|
|
|
UserRole userRole = new UserRole();
|
|
|
userRole.setUserId(userId);
|
|
|
userRole.setRoleId(role.getId());
|
|
|
userRole.setCompanyId(companyId);
|
|
|
- userRoleService.save(userRole);
|
|
|
+ if (!userRoleService.save(userRole)) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return RestResponse.fail(ApiConstants.RESULT_ERROR, "保存创建者和角色关联关系失败");
|
|
|
+ }
|
|
|
|
|
|
return RestResponse.success(null, ApiConstants.RESULT_SUCCESS, "创建团队成功");
|
|
|
}
|
|
@@ -378,7 +393,7 @@ public class MaintenanceCompanyServiceImpl extends ServiceImpl<MaintenanceCompan
|
|
|
}
|
|
|
|
|
|
private long getLong(Long longValue) {
|
|
|
- if(longValue != null) {
|
|
|
+ if (longValue != null) {
|
|
|
return longValue;
|
|
|
}
|
|
|
return 0L;
|