This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
web-sketch-webskt-query-agent/src/main/java/com/mesasoft/cn/util/ServiceUtils.java
zhanghongqing b3fa11d4b1 initialize
2022-08-09 16:54:16 +08:00

60 lines
2.1 KiB
Java

package com.mesasoft.cn.util;
import com.mesasoft.cn.service.ICategoryService;
import com.mesasoft.cn.service.IFileService;
import com.mesasoft.cn.service.IUserService;
import com.zhazhapan.modules.constant.ValueConsts;
import com.zhazhapan.util.Checker;
import com.zhazhapan.util.ReflectUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.lang.reflect.InvocationTargetException;
/**
* @author pantao
* @since 2018/2/28
*/
@Component
public class ServiceUtils {
private static IUserService userService;
private static IFileService fileService;
private static ICategoryService categoryService;
private static Logger logger = Logger.getLogger(ServiceUtils.class);
@Autowired
public ServiceUtils(IUserService userService, IFileService fileService, ICategoryService categoryService) {
ServiceUtils.userService = userService;
ServiceUtils.fileService = fileService;
ServiceUtils.categoryService = categoryService;
}
public static int getUserId(String usernameOrEmail) {
return Checker.isEmpty(usernameOrEmail) ? ValueConsts.ZERO_INT : userService.getUserId(usernameOrEmail);
}
public static long getFileId(String fileName) {
return Checker.isEmpty(fileName) ? ValueConsts.ZERO_INT : fileService.getFileId(fileName);
}
public static int getCategoryId(String categoryName) {
return Checker.isEmpty(categoryName) ? ValueConsts.ZERO_INT : categoryService.getIdByName(categoryName);
}
public static Object invokeFileFilter(Object object, String methodName, String user, String file, String
category, int offset) {
try {
return ReflectUtils.invokeMethodUseBasicType(object, methodName, new Object[]{getUserId(user), getFileId
(file), file, getCategoryId(category), offset});
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
logger.error(e.getMessage());
return null;
}
}
}