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

com.fastchar.extjs.systemtool.entity.FinalLogExceptionEntity Maven / Gradle / Ivy

The newest version!
package com.fastchar.extjs.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 com.fastchar.utils.FastLockUtils;
import com.fastchar.utils.FastMD5Utils;
import com.fastchar.utils.FastStringUtils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.concurrent.locks.ReentrantLock;

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

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

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

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

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

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

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


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

    @Override
    public void setDefaultValue() {
        set("logId", FastMD5Utils.MD5To16(FastStringUtils.buildUUID()));
        set("logDateTime", FastDateUtils.getDateString());
    }

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

    }


    public void clearData(int keepDay) {
        ReentrantLock lock = FastLockUtils.getLock(this.getClass().getSimpleName());
        if (lock.isLocked()) {
            return;
        }
        lock.lock();
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Calendar minCalendar = Calendar.getInstance();
            minCalendar.add(Calendar.DAY_OF_MONTH, -Math.max((keepDay - 1), 0));
            String sqlStr = "delete from final_log_exception where logDateTime < ? ";
            String format = simpleDateFormat.format(minCalendar.getTime());
            int updateBySql = updateBySql(sqlStr, format);
            if (updateBySql > 0) {
                FastChar.getLogger().info(this.getClass(), "已成功删除" +
                        format + "之前的" + updateBySql + "条系统SQL日志!");
            }
        } finally {
            lock.unlock();
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy