| | |
| | | package com.zy.common.service.erp; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.annotations.TableField; |
| | | import com.baomidou.mybatisplus.annotations.TableName; |
| | | import com.core.common.Cools; |
| | | import com.zy.third.erp.entity.InDetTB; |
| | | import lombok.SneakyThrows; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | List<T> list = new ArrayList<>(); |
| | | if (null != result) { |
| | | for (Map<String, Object> entity : result) { |
| | | list.add(Cools.conver(entity, cls)); |
| | | //用最笨的方法转换,也可以用下面的process方法(还没有写全) |
| | | list.add(JSONObject.parseObject(JSONObject.toJSONString(entity), cls)); |
| | | //list.add(Cools.conver(entity, cls)); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | @SneakyThrows |
| | | public <T> void process(Map<String, Object> entity, Class<T> cls) { |
| | | for (Map.Entry<String, Object> entry : entity.entrySet()) { |
| | | String fieldName = entry.getKey(); |
| | | Object value = entry.getValue(); |
| | | |
| | | Field field = cls.getDeclaredField(fieldName); |
| | | field.setAccessible(true); |
| | | |
| | | if (value instanceof Integer && field.getType() == int.class || field.getType() == Integer.class) { |
| | | field.setInt(cls, (Integer) value); |
| | | } else if (value instanceof String && field.getType() == String.class) { |
| | | field.set(cls, value); |
| | | } |
| | | // 其他类型可以类似处理 |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 扫描所有实力类属性里的TableField注解,并将里面的值作为column |
| | | * |
| | | * @param cls |
| | | * @param <T> |
| | | * @return |
| | |
| | | * key: id, value: 1 等同于 WHERE id = 1 |
| | | * 如果要查询字符串需要自行加上'' |
| | | * key:name, value: 'zhs'等同于 WHERE name = 'zhs' |
| | | * |
| | | * @param cls |
| | | * @param condition |
| | | * @param <T> |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /*****************************************************************************/ |
| | | /********************************* 核心层 *********************************/ |
| | | /*****************************************************************************/ |
| | | |
| | | |
| | | |
| | | private List<Map<String, Object>> executeQuery(String sql) { |
| | |
| | | Connection conn = null; |
| | | try { |
| | | conn = getConn(); |
| | | if(null != conn) |
| | | { |
| | | if (null != conn) { |
| | | pstm = conn.prepareStatement(sql); |
| | | |
| | | pstm.setQueryTimeout(QUERY_TIMEOUT_SECONDS); |