feat: complete reverse engineering, standard Maven structure, detailed code annotations and IoT-M platform architecture

This commit is contained in:
rick committed 2026-11-16 14:35:53 +08:00
1 parent e8dc09fb3c
commit cd6a4c70e7
3045 files changed
+566733 -1

No files matched your search

@@ -0,0 +1,82 @@
package com.midm.controller;
import com.google.common.base.Strings;
import com.midm.model.org.User;
import com.midm.security.UserPrincipal;
import com.midm.service.org.SiteService;
import com.midm.service.org.UserService;
import com.midm.service.system.LocaleService;
import com.mitac.cell.utils.McStringUtils;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.servlet.LocaleResolver;
public class BaseController {
@Autowired
protected LocaleResolver localeResolver;
@Autowired
protected LocaleService localeService;
@Autowired
protected UserService userService;
@Autowired
protected SiteService siteService;
protected User user = null;
protected String theme = "default";
protected void init(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
this.init(request, response, authentication, (String)null);
}
protected void init(HttpServletRequest request, HttpServletResponse response, Authentication authentication, String localeTag) {
this.determineUser(request, authentication);
String userLocale = !Strings.isNullOrEmpty(localeTag) ? localeTag : (this.user != null ? this.user.getSettingAsString("language") : request.getLocale().toLanguageTag());
if (McStringUtils.isNullOrEmpty(userLocale)) {
userLocale = request.getLocale().toLanguageTag();
}
Locale altLocale = this.localeService.findAltLocale(userLocale);
if (this.user != null) {
String altLocaleTag = altLocale.toLanguageTag();
if (userLocale == null || !this.user.isSameLocale(altLocaleTag)) {
this.userService.changeLocale(this.user, altLocaleTag);
}
}
this.localeResolver.setLocale(request, response, altLocale);
}
protected String getView(Authentication authentication, String viewName) {
return this.getResource(authentication, viewName + ".html");
}
protected String getResource(Authentication authentication, String fileName) {
User user = UserPrincipal.getUser(authentication);
String theme = user == null ? "default" : user.getTheme();
return theme + fileName;
}
protected String getTemplateResource(Authentication authentication, String fileName) {
if (this.user == null) {
this.user = UserPrincipal.getUser(authentication);
}
String theme = this.user == null ? "default" : this.user.getTheme();
return "templates/" + theme + fileName;
}
private void determineUser(HttpServletRequest request, Authentication authentication) {
if (authentication != null) {
synchronized(authentication) {
this.user = UserPrincipal.getUser(authentication);
this.theme = this.user != null ? this.user.getTheme() : "default";
}
} else {
this.user = null;
this.theme = "default";
}
}
}