|
@@ -0,0 +1,98 @@
|
|
|
|
|
+package com.etotem.cfc.service;
|
|
|
|
|
+
|
|
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
|
|
+import com.etotem.cfc.entity.UserShortcutConfig;
|
|
|
|
|
+import com.etotem.cfc.entity.UserAppUsage;
|
|
|
|
|
+import com.etotem.cfc.mapper.UserShortcutConfigMapper;
|
|
|
|
|
+import com.etotem.cfc.mapper.UserAppUsageMapper;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@Service
|
|
|
|
|
+public class HomeShortcutService {
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private UserShortcutConfigMapper userShortcutConfigMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private UserAppUsageMapper userAppUsageMapper;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 返回用户快捷配置 + 频度映射。
|
|
|
|
|
+ * 应用库本身是前端常量,后端只需返回用户侧数据。
|
|
|
|
|
+ */
|
|
|
|
|
+ public Result<Map<String, Object>> getAppLibrary(Long userId) {
|
|
|
|
|
+ List<UserShortcutConfig> configs = userShortcutConfigMapper.selectByUserId(userId);
|
|
|
|
|
+
|
|
|
|
|
+ List<Map<String, Object>> myShortcuts = configs.stream().map(c -> {
|
|
|
|
|
+ Map<String, Object> m = new HashMap<>();
|
|
|
|
|
+ m.put("appKey", c.getAppKey());
|
|
|
|
|
+ m.put("locked", c.getLocked());
|
|
|
|
|
+ m.put("sortOrder", c.getSortOrder());
|
|
|
|
|
+ return m;
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ List<UserAppUsage> usages = userAppUsageMapper.selectList(null);
|
|
|
|
|
+ Map<String, Integer> usageMap = new HashMap<>();
|
|
|
|
|
+ for (UserAppUsage u : usages) {
|
|
|
|
|
+ usageMap.put(u.getAppKey(), u.getEnterCount());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> resp = new HashMap<>();
|
|
|
|
|
+ resp.put("myShortcuts", myShortcuts);
|
|
|
|
|
+ resp.put("usage", usageMap);
|
|
|
|
|
+ return Result.success(resp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public Result<Void> saveShortcutConfig(Long userId, List<Map<String, Object>> items) {
|
|
|
|
|
+ userShortcutConfigMapper.delete(
|
|
|
|
|
+ new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<UserShortcutConfig>()
|
|
|
|
|
+ .eq("user_id", userId));
|
|
|
|
|
+ for (Map<String, Object> item : items) {
|
|
|
|
|
+ String appKey = (String) item.get("appKey");
|
|
|
|
|
+ if (appKey == null || appKey.isEmpty()) continue;
|
|
|
|
|
+ UserShortcutConfig c = new UserShortcutConfig();
|
|
|
|
|
+ c.setUserId(userId);
|
|
|
|
|
+ c.setAppKey(appKey);
|
|
|
|
|
+ c.setLocked(item.get("locked") != null ? ((Number) item.get("locked")).intValue() : 0);
|
|
|
|
|
+ c.setSortOrder(item.get("sortOrder") != null ? ((Number) item.get("sortOrder")).intValue() : 0);
|
|
|
|
|
+ userShortcutConfigMapper.insert(c);
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.success(null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public Result<Void> reportEnter(Long userId, String appKey) {
|
|
|
|
|
+ if (userId == null || appKey == null || appKey.isEmpty()) {
|
|
|
|
|
+ return Result.error("参数缺失");
|
|
|
|
|
+ }
|
|
|
|
|
+ UserAppUsage u = userAppUsageMapper.selectByUserIdAndAppKey(userId, appKey);
|
|
|
|
|
+ if (u == null) {
|
|
|
|
|
+ u = new UserAppUsage();
|
|
|
|
|
+ u.setUserId(userId);
|
|
|
|
|
+ u.setAppKey(appKey);
|
|
|
|
|
+ u.setEnterCount(1);
|
|
|
|
|
+ u.setLastEnterAt(new Date());
|
|
|
|
|
+ userAppUsageMapper.insert(u);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ u.setEnterCount(u.getEnterCount() + 1);
|
|
|
|
|
+ u.setLastEnterAt(new Date());
|
|
|
|
|
+ userAppUsageMapper.updateById(u);
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.success(null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public Result<Void> resetToDefault(Long userId) {
|
|
|
|
|
+ userShortcutConfigMapper.delete(
|
|
|
|
|
+ new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<UserShortcutConfig>()
|
|
|
|
|
+ .eq("user_id", userId));
|
|
|
|
|
+ return Result.success(null);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|