whyclxw
2025-05-28 e16302f9d475c7cc4dd18c5abf1a23cb5502e362
src/main/java/com/whyc/util/CommonUtil.java
@@ -7,7 +7,6 @@
import org.springframework.boot.system.ApplicationHome;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.text.ParseException;
@@ -62,90 +61,35 @@
        ApplicationHome applicationHome = new ApplicationHome(CommonUtil.class);
        File jarFile = applicationHome.getDir();
        String baseDirPath;
        if(YamlProperties.runModel == 1) {
        if (YamlProperties.runModel == 1) {
            //开发路径
            baseDirPath = jarFile.getParentFile().toString();
        }else {
        } else {
            //打包路径
            baseDirPath = jarFile.toString();
        }
        return baseDirPath;
    }
    /**手动记录特定日志*/
    public static void record(long uId, int operationType, String msg){
        userLogService.record(uId,operationType,msg);
    }
    /**手动记录特定日志*/
    public static void record(long uId, int operationType, String msg,String msgDetail){
        userLogService.record(uId,operationType,msg,msgDetail);
    }
    /**手动记录特定日志*/
    public static void record2(HttpServletRequest request,long uId, int operationType, String msg,String msgDetail){
        userLogService.record2(request,uId,operationType,msg,msgDetail);
    /**
     * 手动记录特定日志
     */
    public static void record(long uId, int operationType, String msg, String msgEnUs) {
        userLogService.record(uId, operationType, msg, msgEnUs);
    }
    /**
     *
     * 在分表的情况下使用,按年分表,查询需要切割查询使用
     *
     * 根据传入的起止时间,按照年切割成不同时间段
     * @param startTimeStr 2021-01-01 10:00:00
     * @param endTimeStr 2023-05-01 10:10:10
     * @return  示例[2021,2022,2023]
     * 使用方法:
     *   根据返回的第一个数据,如果存在表,则查询筛选条件为>=输入的起始时间;不存在则弃用输入的起始时间
     *   根据返回的最后个数据,如果表存在,则查询筛选条件为<=输入的终止时间;不存在则弃用输入的终止时间
     *   返回的非第一最后数据,查询全表
     * 手动记录特定日志
     */
    public static List<Integer> getYearList(String startTimeStr,String endTimeStr) throws ParseException {
        Integer startYear = Integer.valueOf(startTimeStr.split("-")[0]);
        Integer endYear = Integer.valueOf(endTimeStr.split("-")[0]);
        List<Integer> yearList = new LinkedList<>();
        while (startYear<=endYear){
            yearList.add(startYear);
            startYear++;
        }
        return yearList;
    public static void record(long uId, int operationType, String msg, String msgDetail, String msgEnUs, String msgDetailEnUs) {
        userLogService.record(uId, operationType, msg, msgDetail, msgEnUs, msgDetailEnUs);
    }
    /**
     *
     * 在分表的情况下使用,按月分表,查询需要切割查询使用
     *
     * 根据传入的起止时间,按照月切割成不同时间段
     * @param startTimeStr 2022-11-01 10:00:00
     * @param endTimeStr 2023-05-01 10:10:10
     * @return  示例[2022_12,2023_1,2023_2,2023_3,2023_4,2023_5]
     * 使用方法:
     *   根据返回的第一个数据,如果存在表,则查询筛选条件为>=输入的起始时间;不存在则弃用输入的起始时间
     *   根据返回的最后个数据,如果表存在,则查询筛选条件为<=输入的终止时间;不存在则弃用输入的终止时间
     *   返回的非第一最后数据,查询全表
     * 手动记录特定日志
     */
    public static List<String> getMonthList(String startTimeStr,String endTimeStr) throws ParseException {
        Calendar startTimeCalendar = Calendar.getInstance();
        Date startTime = DateUtil.YYYY_MM_DD_HH_MM_SS.parse(startTimeStr);
        startTimeCalendar.setTime(startTime);
        Calendar endTimeCalendar = Calendar.getInstance();
        Date endTime = DateUtil.YYYY_MM_DD_HH_MM_SS.parse(endTimeStr);
        endTimeCalendar.setTime(endTime);
        /*String[] startTimeSplit = startTimeStr.split("-");
        int startYear = Integer.parseInt(startTimeSplit[0]);
        int startMonth = Integer.parseInt(startTimeSplit[1]);
        String[] endTimeSplit = endTimeStr.split("-");
        int endYear = Integer.parseInt(endTimeSplit[0]);
        int endMonth = Integer.parseInt(endTimeSplit[1]);*/
        List<String> yearMonthList = new LinkedList<>();
        while (!startTimeCalendar.after(endTimeCalendar)){ //起始时间大于终止时间则停止
            yearMonthList.add(startTimeCalendar.get(Calendar.YEAR)+"_"+(startTimeCalendar.get(Calendar.MONTH)+1));
            startTimeCalendar.add(Calendar.MONTH,1);
        }
        return yearMonthList;
    public static void record2(HttpServletRequest request, long uId, int operationType, String msg, String msgDetail, String msgEnUs, String msgDetailEnUs) {
        userLogService.record2(request, uId, operationType, msg, msgDetail, msgEnUs, msgDetailEnUs);
    }
}