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

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

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

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.Calendar;

public class FinalLogSqlEntity extends FastExtEntity {
    private static final long serialVersionUID = 1L;

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

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

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

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

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

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


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

    @Override
    public void setDefaultValue() {
        //取消触发sql监听
        put("sqlListener", false);

        set("sqlResult", 0);
        set("sqlTime", 0);
        set("logDateTime", FastDateUtils.getDateString());
    }

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

    }

    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 final_log_sql where date_format(logDateTime,'%Y-%m-%d') <= ? ";
        String format = simpleDateFormat.format(minCalendar.getTime());
        int updateBySql = updateBySql(sqlStr, format);
        if (updateBySql > 0) {
            FastExtHelper.addWaitInfo("系统SQL日志清除", "已成功删除" +
                    format + "之前的" + updateBySql + "条系统SQL日志!");
        }
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy