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

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

The newest version!
package com.fastchar.extjs.systemtool.entity;

import com.fastchar.core.FastChar;
import com.fastchar.database.FastPage;
import com.fastchar.database.info.FastSqlInfo;
import com.fastchar.extjs.core.FastExtEntity;
import com.fastchar.utils.FastDateUtils;
import com.fastchar.utils.FastMD5Utils;
import com.fastchar.utils.FastNumberUtils;
import com.fastchar.utils.FastStringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 系统Socket连接日志数据库实体类
 *
 * @author Janesen
 * @date 2022/05/13 11:51
 */
public class FinalLogSocketClientEntity extends FastExtEntity {
    private static final long serialVersionUID = 1L;

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

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

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

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

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

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


        String sqlStr = "select t.*" +
                " from final_log_socket_client 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 FinalLogSocketClientEntity getDetails(int logId) {
        List linkColumns = new ArrayList<>();
        linkColumns.add("t.*");
        String sqlStr = "select " + FastStringUtils.join(linkColumns, ",") + " from final_log_socket_client as t" +
                " " +
                " where t.logId = ?  ";
        FinalLogSocketClientEntity entity = selectFirstBySql(sqlStr, logId);
        if (entity != null) {
            //to-do something
        }
        return entity;
    }

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

        List linkColumns = new ArrayList<>();
        linkColumns.add("t.*");

        StringBuilder sqlStr = new StringBuilder("select " + FastStringUtils.join(linkColumns, ",") + " from final_log_socket_client as t" +
                " " +
                " where 1=1 ");

        List values = new ArrayList<>();

        if (where != null) {
            for (Entry stringObjectEntry : where.entrySet()) {
                String key = stringObjectEntry.getKey();
                if (key.startsWith("^")) {
                    continue;
                }
                String prefix = "t.";
                if (key.contains("__")) {
                    prefix = key.split("__")[0] + ".";
                }
                Object value = stringObjectEntry.getValue();
                if (FastNumberUtils.isNumber(value)) {
                    sqlStr.append(" and ").append(prefix).append(key).append(" = ? ");
                    values.add(value);
                } else {
                    sqlStr.append(" and ").append(prefix).append(key).append(" like ? ");
                    values.add("%" + value + "%");
                }
            }
        }

        if (sort != null) {
            List sortKeys = new ArrayList<>();
            for (String key : sort.keySet()) {
                if (key.startsWith("^")) {
                    continue;
                }
                String prefix = "t.";
                if (key.contains("__")) {
                    prefix = key.split("__")[0] + ".";
                }
                sortKeys.add(prefix + 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 (FinalLogSocketClientEntity entity : pageList.getList()) {

        }
        return pageList;
    }
}