All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fastchar.systemtool.entity.FinalLogHttpEntity Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
package com.fastchar.systemtool.entity;

import com.fastchar.annotation.AFastClassFind;
import com.fastchar.core.FastChar;
import com.fastchar.extjs.FastExtHelper;
import com.fastchar.extjs.core.FastExtEntity;
import com.fastchar.database.FastPage;
import com.fastchar.database.info.FastSqlInfo;
import com.fastchar.utils.FastDateUtils;

import java.text.SimpleDateFormat;
import java.util.*;

import com.fastchar.utils.FastStringUtils;
import com.fastchar.utils.FastNumberUtils;

/**
 * 系统HTTP日志数据库实体类
 *
 * @author Janesen
 * @date 2021/08/23 10:38
 */
@AFastClassFind("com.fastchar.http.core.FastHttpRequest")
public class FinalLogHttpEntity extends FastExtEntity {
    private static final long serialVersionUID = 1L;

    public static FinalLogHttpEntity dao() {
        return FastChar.getOverrides().singleInstance(FinalLogHttpEntity.class);
    }

    public static FinalLogHttpEntity newInstance() {
        return FastChar.getOverrides().newInstance(FinalLogHttpEntity.class);
    }

    @Override
    public String getTableName() {
        return "final_log_http";
    }

    @Override
    public String getTableDetails() {
        return "系统HTTP日志";
    }

    @Override
    public String getEntityCode() {
        return this.getClass().getSimpleName();
    }

    @Override
    public FastPage showList(int page, int pageSize) {


        String sqlStr = "select t.*" +
                " from final_log_http as t" +
                " ";
        FastSqlInfo sqlInfo = toSelectSql(sqlStr);
        return selectBySql(page, pageSize, sqlInfo.getSql(), sqlInfo.toParams());
    }

    @Override
    public void setDefaultValue() {
        set("logDateTime", FastDateUtils.getDateString());
    }

    @Override
    public void convertValue() {
        super.convertValue();

    }


    /**
     * 获得数据详情
     */
    public FinalLogHttpEntity getDetails(int logId) {

        String sqlStr = "select t.* from final_log_http as t" +
                " " +
                " where t.logId = ?  ";
        FinalLogHttpEntity entity = selectFirstBySql(sqlStr, logId);
        if (entity != null) {
            //to-do something
        }
        return entity;
    }

    /**
     * 获得本实体列表集合
     *
     * @return 分页数据
     */
    public FastPage getList(int page, int pageSize, Map where, Map sort) {


        StringBuilder sqlStr = new StringBuilder("select t.* from final_log_http as t" +
                " " +
                " where 1=1 ");

        List values = new ArrayList<>();

        if (where != null) {
            for (String key : where.keySet()) {
                if (key.startsWith("^")) {
                    continue;
                }
                Object value = where.get(key);
                if (FastNumberUtils.isNumber(value)) {
                    sqlStr.append(" and t.").append(key).append(" = ? ");
                    values.add(value);
                } else {
                    sqlStr.append(" and t.").append(key).append(" like ? ");
                    values.add("%" + value + "%");
                }
            }
        }

        if (sort != null) {
            List sortKeys = new ArrayList<>();
            for (String key : sort.keySet()) {
                if (key.startsWith("^")) {
                    continue;
                }
                sortKeys.add(" t." + key + " " + sort.get(key));
            }
            if (sortKeys.size() > 0) {
                sqlStr.append(" order by ").append(FastStringUtils.join(sortKeys, ","));
            }
        }

        FastPage pageList = selectBySql(page, pageSize, sqlStr.toString(), values);
        for (FinalLogHttpEntity entity : pageList.getList()) {

        }
        return pageList;
    }


    public void clearData(int keepDay) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Calendar minCalendar = Calendar.getInstance();
        minCalendar.add(Calendar.DAY_OF_MONTH, -(keepDay + 1));
        String sqlStr = "delete from " + getTableName() + " where date_format(logDateTime,'%Y-%m-%d') <= ? ";
        String format = simpleDateFormat.format(minCalendar.getTime());
        int updateBySql = updateBySql(sqlStr, format);
        if (updateBySql > 0) {
            FastExtHelper.addWaitInfo(getTableDetails() + "清除", "已成功删除" +
                    format + "之前的" + updateBySql + "条" + getTableDetails() + "!");
        }
    }


}