|
|
@@ -10,7 +10,15 @@ import com.usoftchina.uu.account.dto.AccountDTO;
|
|
|
import com.usoftchina.uu.account.dto.CompanyDTO;
|
|
|
import com.usoftchina.uu.account.dto.DeviceInfoDTO;
|
|
|
import com.usoftchina.uu.account.dto.TokenDTO;
|
|
|
+import com.usoftchina.uu.app.api.AppConfigApi;
|
|
|
+import com.usoftchina.uu.app.dto.AppGroupDTO;
|
|
|
import com.usoftchina.uu.exception.ExceptionCode;
|
|
|
+import com.usoftchina.uu.home.api.HomeConfigApi;
|
|
|
+import com.usoftchina.uu.home.dto.HomeConfigDTO;
|
|
|
+import com.usoftchina.uu.message.api.MessageApi;
|
|
|
+import com.usoftchina.uu.message.api.MessageConfigApi;
|
|
|
+import com.usoftchina.uu.message.dto.MessageConfigDTO;
|
|
|
+import com.usoftchina.uu.message.dto.UnreadMessageCountDTO;
|
|
|
import com.usoftchina.uu.mobile.grpc.api.*;
|
|
|
import com.usoftchina.uu.mobile.grpc.interceptor.MobileAuthenticationInterceptor;
|
|
|
import com.usoftchina.uu.mobile.grpc.util.MobileBeanMapper;
|
|
|
@@ -44,6 +52,18 @@ public class MobileAccountServiceImpl extends AccountServiceGrpc.AccountServiceI
|
|
|
@Autowired
|
|
|
private CompanyApi companyApi;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private MessageConfigApi messageConfigApi;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AppConfigApi appConfigApi;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private HomeConfigApi homeConfigApi;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MessageApi messageApi;
|
|
|
+
|
|
|
@Override
|
|
|
public void signup(AccountSignupRequest request, StreamObserver<AccountSignupResponse> responseObserver) {
|
|
|
AccountSignupResponse.Builder builder = AccountSignupResponse.newBuilder();
|
|
|
@@ -56,6 +76,7 @@ public class MobileAccountServiceImpl extends AccountServiceGrpc.AccountServiceI
|
|
|
builder.setResponseHeader(ResponseUtils.fail(ExceptionCode.USER_REGISTER_FAILED));
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
+ logger.error("signup error", e);
|
|
|
builder.setResponseHeader(ResponseUtils.error(e));
|
|
|
}
|
|
|
responseObserver.onNext(builder.build());
|
|
|
@@ -104,6 +125,37 @@ public class MobileAccountServiceImpl extends AccountServiceGrpc.AccountServiceI
|
|
|
TokenDTO tokenDTO = new TokenDTO(accountDTO.getId(), activeCompanyId);
|
|
|
tokenApi.save(tokenDTO);
|
|
|
AuthedToken token = MobileBeanMapper.map(tokenDTO);
|
|
|
+ // 已选择默认公司的情况下,直接返回全部配置及统计信息
|
|
|
+ if (null != activeCompanyId) {
|
|
|
+ // 消息配置
|
|
|
+ List<MessageConfigDTO> messageConfigDTOList = messageConfigApi.findEnabled(activeCompanyId);
|
|
|
+ if (!CollectionUtils.isEmpty(messageConfigDTOList)) {
|
|
|
+ messageConfigDTOList.forEach(messageConfigDTO -> {
|
|
|
+ builder.addMessageConfig(MobileBeanMapper.map(messageConfigDTO));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 未读消息统计
|
|
|
+ List<UnreadMessageCountDTO> unreadMessageCountDTOList = messageApi.getAllUnreadCount(accountDTO.getId(), activeCompanyId);
|
|
|
+ if (!CollectionUtils.isEmpty(unreadMessageCountDTOList)) {
|
|
|
+ unreadMessageCountDTOList.forEach(unreadMessageCountDTO -> {
|
|
|
+ builder.addUnreadMessageCount(MobileBeanMapper.map(unreadMessageCountDTO));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 应用配置
|
|
|
+ List<AppGroupDTO> appGroupDTOList = appConfigApi.findEnabled(activeCompanyId);
|
|
|
+ if (!CollectionUtils.isEmpty(appGroupDTOList)) {
|
|
|
+ appGroupDTOList.forEach(appGroupDTO -> {
|
|
|
+ builder.addAppGroupConfig(MobileBeanMapper.map(appGroupDTO));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 我的主页配置
|
|
|
+ List<HomeConfigDTO> homeConfigDTOList = homeConfigApi.findEnabled(activeCompanyId);
|
|
|
+ if (!CollectionUtils.isEmpty(homeConfigDTOList)) {
|
|
|
+ homeConfigDTOList.forEach(homeConfigDTO -> {
|
|
|
+ builder.addHomeConfig(MobileBeanMapper.map(homeConfigDTO));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
builder.setAuthedToken(token)
|
|
|
.setAccount(accountInfo)
|
|
|
@@ -122,21 +174,52 @@ public class MobileAccountServiceImpl extends AccountServiceGrpc.AccountServiceI
|
|
|
public void switchCompany(SwitchCompanyRequest request, StreamObserver<SwitchCompanyResponse> responseObserver) {
|
|
|
SwitchCompanyResponse.Builder builder = SwitchCompanyResponse.newBuilder();
|
|
|
try {
|
|
|
- AccountDTO accountDTO = AccountHolder.get();
|
|
|
+ Long accountId = AccountHolder.get().getId();
|
|
|
Long companyId = request.getCompanyId();
|
|
|
- if (accountApi.hasBindCompany(accountDTO.getId(), companyId)) {
|
|
|
+ // null == companyId 表示切换到个人身份
|
|
|
+ if (null == companyId || accountApi.hasBindCompany(accountId, companyId)) {
|
|
|
// 保存新token
|
|
|
- TokenDTO tokenDTO = new TokenDTO(accountDTO.getId(), companyId);
|
|
|
+ TokenDTO tokenDTO = new TokenDTO(accountId, companyId);
|
|
|
tokenApi.save(tokenDTO);
|
|
|
AuthedToken token = MobileBeanMapper.map(tokenDTO);
|
|
|
// 删除原token
|
|
|
tokenApi.removeByPrimaryKey(TokenHolder.get().getId());
|
|
|
TokenHolder.set(tokenDTO);
|
|
|
+ // 下面返回配置及统计信息
|
|
|
+ // 消息配置
|
|
|
+ List<MessageConfigDTO> messageConfigDTOList = messageConfigApi.findEnabled(companyId);
|
|
|
+ if (!CollectionUtils.isEmpty(messageConfigDTOList)) {
|
|
|
+ messageConfigDTOList.forEach(messageConfigDTO -> {
|
|
|
+ builder.addMessageConfig(MobileBeanMapper.map(messageConfigDTO));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 未读消息统计
|
|
|
+ List<UnreadMessageCountDTO> unreadMessageCountDTOList = messageApi.getAllUnreadCount(accountId, companyId);
|
|
|
+ if (!CollectionUtils.isEmpty(unreadMessageCountDTOList)) {
|
|
|
+ unreadMessageCountDTOList.forEach(unreadMessageCountDTO -> {
|
|
|
+ builder.addUnreadMessageCount(MobileBeanMapper.map(unreadMessageCountDTO));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 应用配置
|
|
|
+ List<AppGroupDTO> appGroupDTOList = appConfigApi.findEnabled(companyId);
|
|
|
+ if (!CollectionUtils.isEmpty(appGroupDTOList)) {
|
|
|
+ appGroupDTOList.forEach(appGroupDTO -> {
|
|
|
+ builder.addAppGroupConfig(MobileBeanMapper.map(appGroupDTO));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 我的主页配置
|
|
|
+ List<HomeConfigDTO> homeConfigDTOList = homeConfigApi.findEnabled(companyId);
|
|
|
+ if (!CollectionUtils.isEmpty(homeConfigDTOList)) {
|
|
|
+ homeConfigDTOList.forEach(homeConfigDTO -> {
|
|
|
+ builder.addHomeConfig(MobileBeanMapper.map(homeConfigDTO));
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
builder.setResponseHeader(ResponseUtils.success())
|
|
|
.setAuthedToken(token);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
+ logger.error("switchCompany error", e);
|
|
|
builder.setResponseHeader(ResponseUtils.error(e));
|
|
|
}
|
|
|
responseObserver.onNext(builder.build());
|
|
|
@@ -152,13 +235,14 @@ public class MobileAccountServiceImpl extends AccountServiceGrpc.AccountServiceI
|
|
|
|
|
|
List<CompanyDTO> companyDTOList = companyApi.findByAccountId(accountDTO.getId());
|
|
|
if (null != companyDTOList) {
|
|
|
- for (int i = 0, len = companyDTOList.size(); i < len; i++) {
|
|
|
- builder.setCompany(i, MobileBeanMapper.map(companyDTOList.get(i)));
|
|
|
- }
|
|
|
+ companyDTOList.forEach(companyDTO -> {
|
|
|
+ builder.addCompany(MobileBeanMapper.map(companyDTO));
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
builder.setResponseHeader(ResponseUtils.success());
|
|
|
} catch (Exception e) {
|
|
|
+ logger.error("getInfo error", e);
|
|
|
builder.setResponseHeader(ResponseUtils.error(e));
|
|
|
}
|
|
|
responseObserver.onNext(builder.build());
|
|
|
@@ -184,6 +268,7 @@ public class MobileAccountServiceImpl extends AccountServiceGrpc.AccountServiceI
|
|
|
|
|
|
builder.setResponseHeader(ResponseUtils.success());
|
|
|
} catch (Exception e) {
|
|
|
+ logger.error("saveInfo error", e);
|
|
|
builder.setResponseHeader(ResponseUtils.error(e));
|
|
|
}
|
|
|
responseObserver.onNext(builder.build());
|
|
|
@@ -200,6 +285,7 @@ public class MobileAccountServiceImpl extends AccountServiceGrpc.AccountServiceI
|
|
|
|
|
|
builder.setResponseHeader(ResponseUtils.success());
|
|
|
} catch (Exception e) {
|
|
|
+ logger.error("signout error", e);
|
|
|
builder.setResponseHeader(ResponseUtils.error(e));
|
|
|
}
|
|
|
responseObserver.onNext(builder.build());
|