package com.yunhai.userhome.controller.api;
import com.yunhai.platform.utils.model.BoaApp;
import com.yunhai.platform.utils.model.BoaAppType;
import com.yunhai.platform.utils.model.BoaUser;
import com.yunhai.userhome.config.Config;
import com.yunhai.userhome.entity.UserMessage;
import com.yunhai.userhome.service.AppRemoteService;
import com.yunhai.userhome.service.IUserMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* 消息中心接口(CAS 登录态,路径 {@code /{platform}/}),对齐旧 UserHome MessageController 契约。
*
响应字段与旧版 {@code getMessageByUserId} 完全一致:{id,msg,date,name,avatar,appPath,msgType}。
*/
@RestController
@RequestMapping(value = Config.API_PATH)
public class MessageController {
@Autowired
private IUserMessageService userMessageService;
@Autowired
private AppRemoteService appRemoteService;
/** schId=0 时推断:主学校 → 主归属组(bureau)→ 0(对齐旧版 school.id→bureau.id→0)。 */
private Integer resolveSchId(BoaUser user) {
if (user.getSchool() != null) {
return user.getSchool().getId();
}
if (user.getBureau() != null) {
return user.getBureau().getId();
}
return 0;
}
private List flattenApps(BoaUser user) {
List types = appRemoteService.getUserApps(user);
if (types == null) {
return new ArrayList<>();
}
List apps = new ArrayList<>();
for (BoaAppType t : types) {
if (t.getApps() != null) {
apps.addAll(t.getApps());
}
}
return apps;
}
// 获取个人最近消息(对齐旧 getMessageByUserId,响应 List