Search in sources :

Example 1 with BeanMap

use of org.springframework.cglib.beans.BeanMap in project jeecg-boot by jeecgboot.

the class RedisServiceImpl method getMapForReport.

/**
 * 查询redis信息for报表
 * @param type 1redis key数量 2 占用内存 3redis信息
 * @return
 * @throws RedisConnectException
 */
@Override
public Map<String, JSONArray> getMapForReport(String type) throws RedisConnectException {
    Map<String, JSONArray> mapJson = new HashMap<String, JSONArray>();
    JSONArray json = new JSONArray();
    if ("3".equals(type)) {
        List<RedisInfo> redisInfo = getRedisInfo();
        for (RedisInfo info : redisInfo) {
            Map<String, Object> map = Maps.newHashMap();
            BeanMap beanMap = BeanMap.create(info);
            for (Object key : beanMap.keySet()) {
                map.put(key + "", beanMap.get(key));
            }
            json.add(map);
        }
        mapJson.put("data", json);
        return mapJson;
    }
    for (int i = 0; i < 5; i++) {
        JSONObject jo = new JSONObject();
        Map<String, Object> map;
        if ("1".equals(type)) {
            map = getKeysSize();
            jo.put("value", map.get("dbSize"));
        } else {
            map = getMemoryInfo();
            Integer used_memory = Integer.valueOf(map.get("used_memory").toString());
            jo.put("value", used_memory / 1000);
        }
        String create_time = DateUtil.formatTime(DateUtil.date((Long) map.get("create_time") - (4 - i) * 1000));
        jo.put("name", create_time);
        json.add(jo);
    }
    mapJson.put("data", json);
    return mapJson;
}
Also used : BeanMap(org.springframework.cglib.beans.BeanMap) JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) RedisInfo(org.jeecg.modules.monitor.domain.RedisInfo)

Example 2 with BeanMap

use of org.springframework.cglib.beans.BeanMap in project easyexcel by alibaba.

the class TempWriteTest method cglib.

@Test
public void cglib() {
    TempWriteData tempWriteData = new TempWriteData();
    tempWriteData.setName("1");
    tempWriteData.setName1("2");
    BeanMap beanMap = BeanMapUtils.create(tempWriteData);
    log.info("d1{}", beanMap.get("name"));
    log.info("d2{}", beanMap.get("name1"));
    TempWriteData tempWriteData2 = new TempWriteData();
    Map<String, String> map = new HashMap<>();
    map.put("name", "zs");
    BeanMap beanMap2 = BeanMapUtils.create(tempWriteData2);
    beanMap2.putAll(map);
    log.info("3{}", tempWriteData2.getName());
}
Also used : BeanMap(org.springframework.cglib.beans.BeanMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with BeanMap

use of org.springframework.cglib.beans.BeanMap in project easyexcel by alibaba.

the class ModelBuildEventListener method buildUserModel.

private Object buildUserModel(Map<Integer, ReadCellData<?>> cellDataMap, ReadSheetHolder readSheetHolder, AnalysisContext context) {
    ExcelReadHeadProperty excelReadHeadProperty = readSheetHolder.excelReadHeadProperty();
    Object resultModel;
    try {
        resultModel = excelReadHeadProperty.getHeadClazz().newInstance();
    } catch (Exception e) {
        throw new ExcelDataConvertException(context.readRowHolder().getRowIndex(), 0, new ReadCellData<>(CellDataTypeEnum.EMPTY), null, "Can not instance class: " + excelReadHeadProperty.getHeadClazz().getName(), e);
    }
    Map<Integer, Head> headMap = excelReadHeadProperty.getHeadMap();
    BeanMap dataMap = BeanMapUtils.create(resultModel);
    for (Map.Entry<Integer, Head> entry : headMap.entrySet()) {
        Integer index = entry.getKey();
        Head head = entry.getValue();
        String fieldName = head.getFieldName();
        if (!cellDataMap.containsKey(index)) {
            continue;
        }
        ReadCellData<?> cellData = cellDataMap.get(index);
        Object value = ConverterUtils.convertToJavaObject(cellData, head.getField(), ClassUtils.declaredExcelContentProperty(dataMap, readSheetHolder.excelReadHeadProperty().getHeadClazz(), fieldName), readSheetHolder.converterMap(), context, context.readRowHolder().getRowIndex(), index);
        if (value != null) {
            dataMap.put(fieldName, value);
        }
    }
    return resultModel;
}
Also used : Head(com.alibaba.excel.metadata.Head) ExcelDataConvertException(com.alibaba.excel.exception.ExcelDataConvertException) ExcelDataConvertException(com.alibaba.excel.exception.ExcelDataConvertException) ReadCellData(com.alibaba.excel.metadata.data.ReadCellData) BeanMap(org.springframework.cglib.beans.BeanMap) BeanMap(org.springframework.cglib.beans.BeanMap) Map(java.util.Map) ExcelReadHeadProperty(com.alibaba.excel.read.metadata.property.ExcelReadHeadProperty)

Example 4 with BeanMap

use of org.springframework.cglib.beans.BeanMap in project SaaS_IHRM by Han-YLun.

the class BeanMapUtils method mapToBean.

/**
 * 将map集合中的数据转化为指定对象的同名属性中
 */
public static <T> T mapToBean(Map<String, Object> map, Class<T> clazz) throws Exception {
    T bean = clazz.newInstance();
    BeanMap beanMap = BeanMap.create(bean);
    beanMap.putAll(map);
    return bean;
}
Also used : BeanMap(org.springframework.cglib.beans.BeanMap)

Example 5 with BeanMap

use of org.springframework.cglib.beans.BeanMap in project bubble-fireworks by fxbin.

the class BeanUtils method object2Map.

/**
 * object2Map
 *
 * @since 2020/5/28 10:36
 * @param object java.lang.Object
 * @param timestampDefault 日期类型是否默认默认转时间戳
 * @return java.util.Map<java.lang.String,java.lang.Object>
 */
public Map<String, Object> object2Map(Object object, boolean timestampDefault) {
    Assert.notNull(object, "object can't be null");
    BeanMap beanMap = BeanMap.create(object);
    if (timestampDefault) {
        Map<String, Object> map = new HashMap<>();
        beanMap.keySet().forEach(key -> map.put(String.valueOf(key), DateUtils.isDateType(beanMap.get(key)) ? DateUtils.toEpochMilli(beanMap.get(key)) : beanMap.get(key)));
        return map;
    }
    return beanMap;
}
Also used : BeanMap(org.springframework.cglib.beans.BeanMap)

Aggregations

BeanMap (org.springframework.cglib.beans.BeanMap)24 HashMap (java.util.HashMap)8 JSONObject (com.alibaba.fastjson.JSONObject)4 JSONArray (com.alibaba.fastjson.JSONArray)3 Map (java.util.Map)3 RedisInfo (org.jeecg.modules.monitor.domain.RedisInfo)3 Head (com.alibaba.excel.metadata.Head)2 Type (java.lang.reflect.Type)2 Test (org.junit.Test)2 BeanInfoUtils (sviolet.thistle.util.reflect.BeanInfoUtils)2 JSONArray (cn.hutool.json.JSONArray)1 JSONObject (cn.hutool.json.JSONObject)1 RedisInfo (com.albedo.java.modules.monitor.domain.RedisInfo)1 ExcelDataConvertException (com.alibaba.excel.exception.ExcelDataConvertException)1 ReadCellData (com.alibaba.excel.metadata.data.ReadCellData)1 ExcelContentProperty (com.alibaba.excel.metadata.property.ExcelContentProperty)1 ExcelReadHeadProperty (com.alibaba.excel.read.metadata.property.ExcelReadHeadProperty)1 CellWriteHandlerContext (com.alibaba.excel.write.handler.context.CellWriteHandlerContext)1 WriteHolder (com.alibaba.excel.write.metadata.holder.WriteHolder)1 Field (java.lang.reflect.Field)1