Browse Source

版本更新

lihui001 3 years ago
parent
commit
7af37ee269
16 changed files with 974 additions and 9 deletions
  1. 4 4
      zoniot-common/zoniot-core-common/src/main/java/com/zcxk/core/common/pojo/PageResult.java
  2. 1 0
      zoniot-common/zoniot-core-mysql/pom.xml
  3. 1 0
      zoniot-common/zoniot-core-mysql/src/main/java/com/zcxk/core/mysql/pageing/Pagination.java
  4. 558 0
      zoniot-common/zoniot-core-redis/src/main/java/com/zcxk/core/utils/util/RedisUtil.java
  5. 23 1
      zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/BigDecimalUtils.java
  6. 94 0
      zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/CalcUtil.java
  7. 26 0
      zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/DateUtil.java
  8. 45 0
      zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/converter/DeviceTypeConverter.java
  9. 29 0
      zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/converter/Double1Serializer.java
  10. 29 0
      zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/converter/Double2Serializer.java
  11. 29 0
      zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/converter/Double3Serializer.java
  12. 24 0
      zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/converter/Object6Serialize.java
  13. 35 4
      zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/export/EasyExcelUtil.java
  14. 26 0
      zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/jsonSerializer/BigDecimalJsonSerializer.java
  15. 26 0
      zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/jsonSerializer/BigDecimalJsonSerializerTwo.java
  16. 24 0
      zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/jsonSerializer/DoubleJsonSerializer.java

+ 4 - 4
zoniot-common/zoniot-core-common/src/main/java/com/zcxk/core/common/pojo/PageResult.java

@@ -29,10 +29,10 @@ public class PageResult<T> {
     private Integer totalPages;
 
     @ApiModelProperty(value = "总条数", name = "totalSize")
-    private Integer totalSize;
+    private Integer total;
 
     @ApiModelProperty(value = "数据", name = "rows")
-    private List<T> rows;
+    private List<T> list;
 
     private PageResult() {
 
@@ -49,8 +49,8 @@ public class PageResult<T> {
             pageResult.setTotalPages(BigDecimal.ZERO.intValue());
         }
 
-        pageResult.setTotalSize(totalSize);
-        pageResult.setRows(list);
+        pageResult.setTotal(totalSize);
+        pageResult.setList(list);
         return pageResult;
     }
 

+ 1 - 0
zoniot-common/zoniot-core-mysql/pom.xml

@@ -32,6 +32,7 @@
             <artifactId>pagehelper-spring-boot-starter</artifactId>
             <version>1.2.10</version>
         </dependency>
+
     </dependencies>
 
     <build>

+ 1 - 0
zoniot-common/zoniot-core-mysql/src/main/java/com/zcxk/core/mysql/pageing/Pagination.java

@@ -41,6 +41,7 @@ public class Pagination<T> implements Serializable {
         this.total = page.getTotal();
     }
 
+
     public Pagination(List<T> list , long total){
         this.list = list ;
         this.total =total ;

+ 558 - 0
zoniot-common/zoniot-core-redis/src/main/java/com/zcxk/core/utils/util/RedisUtil.java

@@ -0,0 +1,558 @@
+package com.zcxk.core.utils.util;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.data.redis.connection.RedisServerCommands;
+import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
+import org.springframework.data.redis.core.HashOperations;
+import org.springframework.data.redis.core.ListOperations;
+import org.springframework.data.redis.core.RedisCallback;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.RedisSerializer;
+import org.springframework.data.redis.support.atomic.RedisAtomicLong;
+import org.springframework.stereotype.Component;
+
+import java.nio.charset.Charset;
+import java.util.*;
+
+/**
+ * @Description Redis工具类
+ */
+@Component
+@Slf4j
+public class RedisUtil {
+
+
+    /**
+     * 默认编码
+     */
+    private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
+
+    /**
+     * Spring Redis Template
+     */
+    private RedisTemplate<String, String> redisTemplate;
+
+    private JedisConnectionFactory jedisConnectionFactory;
+
+    public RedisUtil(RedisTemplate<String, String> redisTemplate) {
+        this.redisTemplate = redisTemplate;
+    }
+
+    /**
+     * 添加到带有 过期时间的  缓存
+     *
+     * @param key   redis主键
+     * @param value 值
+     * @param time  过期时间
+     */
+    public void setExpire(final byte[] key, final byte[] value, final long time) {
+        redisTemplate.execute((RedisCallback<Long>) connection -> {
+            connection.set(key, value);
+            connection.expire(key, time);
+            log.info("[redisTemplate redis]放入 缓存  url:{} ========缓存时间为{}秒", key, time);
+            return 1L;
+        });
+    }
+    public void setExpire(final byte[] key, final byte[] value) {
+        redisTemplate.execute((RedisCallback<Long>) connection -> {
+            connection.set(key, value);
+            log.info("[redisTemplate redis]放入 缓存  url:{} ========", key);
+            return 1L;
+        });
+    }
+
+    public void setExpire(String key,final long time) {
+    	redisTemplate.execute((RedisCallback<Long>) connection -> {
+    		RedisSerializer<String> serializer = getRedisSerializer();
+            connection.expire(serializer.serialize(key), time);
+            log.info("[redisTemplate redis]放入 缓存  url:{} ========缓存时间为{}秒", key, time);
+            return 1L;
+        });
+    }
+    /**
+     * 添加到带有 过期时间的  缓存
+     *
+     * @param key   redis主键
+     * @param value 值
+     * @param time  过期时间
+     */
+    public void setExpire(final String key, final String value, final long time) {
+        redisTemplate.execute((RedisCallback<Long>) connection -> {
+            RedisSerializer<String> serializer = getRedisSerializer();
+            byte[] keys = serializer.serialize(key);
+            byte[] values = serializer.serialize(value);
+            connection.set(keys, values);
+            connection.expire(keys, time);
+            log.info("[redisTemplate redis]放入 缓存  url:{} ========缓存时间为{}秒", key, time);
+            return 1L;
+        });
+    }
+
+    /**
+     * 一次性添加数组到   过期时间的  缓存,不用多次连接,节省开销
+     *
+     * @param keys   redis主键数组
+     * @param values 值数组
+     * @param time   过期时间
+     */
+    public void setExpire(final String[] keys, final String[] values, final long time) {
+        redisTemplate.execute((RedisCallback<Long>) connection -> {
+            RedisSerializer<String> serializer = getRedisSerializer();
+            for (int i = 0; i < keys.length; i++) {
+                byte[] bKeys = serializer.serialize(keys[i]);
+                byte[] bValues = serializer.serialize(values[i]);
+                connection.set(bKeys, bValues);
+                connection.expire(bKeys, time);
+                log.info("[redisTemplate redis]放入 缓存  url:{} ========缓存时间为:{}秒", keys[i], time);
+            }
+            return 1L;
+        });
+    }
+
+
+    /**
+     * 一次性添加数组到   过期时间的  缓存,不用多次连接,节省开销
+     *
+     * @param keys   the keys
+     * @param values the values
+     */
+    public void set(final String[] keys, final String[] values) {
+        redisTemplate.execute((RedisCallback<Long>) connection -> {
+            RedisSerializer<String> serializer = getRedisSerializer();
+            for (int i = 0; i < keys.length; i++) {
+                byte[] bKeys = serializer.serialize(keys[i]);
+                byte[] bValues = serializer.serialize(values[i]);
+                connection.set(bKeys, bValues);
+                log.info("[redisTemplate redis]放入 缓存  url:{}", keys[i]);
+            }
+            return 1L;
+        });
+    }
+
+
+    /**
+     * 添加到缓存
+     *
+     * @param key   the key
+     * @param value the value
+     */
+    public void set(final String key, final String value) {
+        redisTemplate.execute((RedisCallback<Long>) connection -> {
+            RedisSerializer<String> serializer = getRedisSerializer();
+            byte[] keys = serializer.serialize(key);
+            byte[] values = serializer.serialize(value);
+            connection.set(keys, values);
+            log.info("[redisTemplate redis]放入 缓存  url:{}", key);
+            return 1L;
+        });
+    }
+
+    /**
+     * 查询在这个时间段内即将过期的key
+     *
+     * @param key  the key
+     * @param time the time
+     * @return the list
+     */
+    public List<String> willExpire(final String key, final long time) {
+        final List<String> keysList = new ArrayList<>();
+        redisTemplate.execute((RedisCallback<List<String>>) connection -> {
+            Set<String> keys = redisTemplate.keys(key + "*");
+            for (String key1 : keys) {
+                Long ttl = connection.ttl(key1.getBytes(DEFAULT_CHARSET));
+                if (0 <= ttl && ttl <= 2 * time) {
+                    keysList.add(key1);
+                }
+            }
+            return keysList;
+        });
+        return keysList;
+    }
+
+
+    /**
+     * 查询在以keyPatten的所有  key
+     *
+     * @param keyPatten the key patten
+     * @return the set
+     */
+    public Set<String> keys(final String keyPatten) {
+        return redisTemplate.execute((RedisCallback<Set<String>>) connection -> redisTemplate.keys(keyPatten + "*"));
+    }
+
+    /**
+     * 根据key获取对象
+     *
+     * @param key the key
+     * @return the byte [ ]
+     */
+    public byte[] get(final byte[] key) {
+        byte[] result = redisTemplate.execute((RedisCallback<byte[]>) connection -> connection.get(key));
+        //log.info("[redisTemplate redis]取出 缓存  url:{} ", key);
+        return result;
+    }
+
+    /**
+     * 根据key获取对象
+     *
+     * @param key the key
+     * @return the string
+     */
+    public String get(final String key) {
+        String resultStr = redisTemplate.execute((RedisCallback<String>) connection -> {
+            RedisSerializer<String> serializer = getRedisSerializer();
+            byte[] keys = serializer.serialize(key);
+            byte[] values = connection.get(keys);
+            return serializer.deserialize(values);
+        });
+        //log.info("[redisTemplate redis]取出 缓存  url:{} ", key);
+        return resultStr;
+    }
+
+
+    /**
+     * 根据key获取对象
+     *
+     * @param keyPatten the key patten
+     * @return the keys values
+     */
+    public Map<String, String> getKeysValues(final String keyPatten) {
+        log.info("[redisTemplate redis]  getValues()  patten={} ", keyPatten);
+        return redisTemplate.execute((RedisCallback<Map<String, String>>) connection -> {
+            RedisSerializer<String> serializer = getRedisSerializer();
+            Map<String, String> maps = new HashMap<>();
+            Set<String> keys = redisTemplate.keys(keyPatten + "*");
+            for (String key : keys) {
+                byte[] bKeys = serializer.serialize(key);
+                byte[] bValues = connection.get(bKeys);
+                String value = serializer.deserialize(bValues);
+                maps.put(key, value);
+            }
+            return maps;
+        });
+    }
+
+    /**
+     * Ops for hash hash operations.
+     *
+     * @return the hash operations
+     */
+    public HashOperations<String, String, String> opsForHash() {
+        return redisTemplate.opsForHash();
+    }
+
+    /**
+     * 对HashMap操作
+     *
+     * @param key       the key
+     * @param hashKey   the hash key
+     * @param hashValue the hash value
+     */
+    public void putHashValue(String key, String hashKey, String hashValue) {
+        log.info("[redisTemplate redis]  putHashValue()  key={},hashKey={},hashValue={} ", key, hashKey, hashValue);
+        opsForHash().put(key, hashKey, hashValue);
+    }
+
+    /**
+     * 获取单个field对应的值
+     *
+     * @param key     the key
+     * @param hashKey the hash key
+     * @return the hash values
+     */
+    public Object getHashValues(String key, String hashKey) {
+        log.info("[redisTemplate redis]  getHashValues()  key={},hashKey={}", key, hashKey);
+        return opsForHash().get(key, hashKey);
+    }
+
+    /**
+     * 根据key值删除
+     *
+     * @param key      the key
+     * @param hashKeys the hash keys
+     */
+    public void delHashValues(String key, Object... hashKeys) {
+        log.info("[redisTemplate redis]  delHashValues()  key={}", key);
+        opsForHash().delete(key, hashKeys);
+    }
+
+    /**
+     * key只匹配map
+     *
+     * @param key the key
+     * @return the hash value
+     */
+    public Map<String, String> getHashValue(String key) {
+        log.info("[redisTemplate redis]  getHashValue()  key={}", key);
+        return opsForHash().entries(key);
+    }
+
+    /**
+     * 批量添加
+     *
+     * @param key the key
+     * @param map the map
+     */
+    public void putHashValues(String key, Map<String, String> map) {
+        opsForHash().putAll(key, map);
+    }
+
+    /**
+     * 集合数量
+     *
+     * @return the long
+     */
+    public long dbSize() {
+        return redisTemplate.execute(RedisServerCommands::dbSize);
+    }
+
+    /**
+     * 清空redis存储的数据
+     *
+     * @return the string
+     */
+    public String flushDB() {
+        return redisTemplate.execute((RedisCallback<String>) connection -> {
+            connection.flushDb();
+            return "ok";
+        });
+    }
+
+    /**
+     * 判断某个主键是否存在
+     *
+     * @param key the key
+     * @return the boolean
+     */
+    public boolean exists(final String key) {
+        return redisTemplate.execute((RedisCallback<Boolean>) connection -> connection.exists(key.getBytes(DEFAULT_CHARSET)));
+    }
+
+
+    /**
+     * 删除key
+     *
+     * @param keys the keys
+     * @return the long
+     */
+    public long del(final String... keys) {
+        return redisTemplate.execute((RedisCallback<Long>) connection -> {
+            long result = 0;
+            for (String key : keys) {
+                result = connection.del(key.getBytes(DEFAULT_CHARSET));
+            }
+            return result;
+        });
+    }
+
+    /**
+     * 删除key
+     *
+     * @param keys the keys
+     * @return the long
+     */
+    public long del(final byte[]... keys) {
+        return redisTemplate.execute((RedisCallback<Long>) connection -> {
+            long result = 0;
+            for (byte[] key : keys) {
+                result = connection.del(key);
+            }
+            return result;
+        });
+    }
+
+    /**
+     * 获取 RedisSerializer
+     *
+     * @return the redis serializer
+     */
+    protected RedisSerializer<String> getRedisSerializer() {
+        return redisTemplate.getStringSerializer();
+    }
+
+    /**
+     * 对某个主键对应的值加一,value值必须是全数字的字符串
+     *
+     * @param key the key
+     * @return the long
+     */
+    public long incr(final String key) {
+        return redisTemplate.execute((RedisCallback<Long>) connection -> {
+            RedisSerializer<String> redisSerializer = getRedisSerializer();
+            return connection.incr(redisSerializer.serialize(key));
+        });
+    }
+
+    /**
+     * redis List 引擎
+     *
+     * @return the list operations
+     */
+    public ListOperations<String, String> opsForList() {
+        return redisTemplate.opsForList();
+    }
+
+    /**
+     * redis List数据结构 : 将一个或多个值 value 插入到列表 key 的表头
+     *
+     * @param key   the key
+     * @param value the value
+     * @return the long
+     */
+    public Long leftPush(String key, String value) {
+        return opsForList().leftPush(key, value);
+    }
+
+    /**
+     * redis List数据结构 : 移除并返回列表 key 的头元素
+     *
+     * @param key the key
+     * @return the string
+     */
+    public String leftPop(String key) {
+        return opsForList().leftPop(key);
+    }
+
+    /**
+     * redis List数据结构 :将一个或多个值 value 插入到列表 key 的表尾(最右边)。
+     *
+     * @param key   the key
+     * @param value the value
+     * @return the long
+     */
+    public Long in(String key, String value) {
+        return opsForList().rightPush(key, value);
+    }
+
+    /**
+     * redis List数据结构 : 移除并返回列表 key 的末尾元素
+     *
+     * @param key the key
+     * @return the string
+     */
+    public String rightPop(String key) {
+        return opsForList().rightPop(key);
+    }
+
+
+    /**
+     * redis List数据结构 : 返回列表 key 的长度 ; 如果 key 不存在,则 key 被解释为一个空列表,返回 0 ; 如果 key 不是列表类型,返回一个错误。
+     *
+     * @param key the key
+     * @return the long
+     */
+    public Long length(String key) {
+        return opsForList().size(key);
+    }
+
+
+    /**
+     * redis List数据结构 : 根据参数 i 的值,移除列表中与参数 value 相等的元素
+     *
+     * @param key   the key
+     * @param i     the
+     * @param value the value
+     */
+    public void remove(String key, long i, String value) {
+        opsForList().remove(key, i, value);
+    }
+
+    /**
+     * redis List数据结构 : 将列表 key 下标为 index 的元素的值设置为 value
+     *
+     * @param key   the key
+     * @param index the index
+     * @param value the value
+     */
+    public void set(String key, long index, String value) {
+        opsForList().set(key, index, value);
+    }
+
+    /**
+     * redis List数据结构 : 返回列表 key 中指定区间内的元素,区间以偏移量 start 和 end 指定。
+     *
+     * @param key   the key
+     * @param start the start
+     * @param end   the end
+     * @return the list
+     */
+    public List<String> getList(String key, int start, int end) {
+        return opsForList().range(key, start, end);
+    }
+
+    /**
+     * redis List数据结构 : 批量存储
+     *
+     * @param key  the key
+     * @param list the list
+     * @return the long
+     */
+    public Long leftPushAll(String key, List<String> list) {
+        return opsForList().leftPushAll(key, list);
+    }
+
+    /**
+     * redis List数据结构 : 将值 value 插入到列表 key 当中,位于值 index 之前或之后,默认之后。
+     *
+     * @param key   the key
+     * @param index the index
+     * @param value the value
+     */
+    public void insert(String key, long index, String value) {
+        opsForList().set(key, index, value);
+    }
+
+    /**
+     * 利用redis的单线程原子自增性保证数据自增的唯一性
+     *
+     * @param key
+     * @return
+     */
+    public RedisAtomicLong getRedisAtomicLong(String key) {
+        return new RedisAtomicLong(key, jedisConnectionFactory);
+    }
+
+    /**
+     * ZINCRBY key increment member
+     *
+     * @param key
+     * @param increment
+     * @param member
+     */
+    public void doZincrby(String key, Integer increment, String member) {
+        redisTemplate.execute((RedisCallback<Double>) connection -> {
+            RedisSerializer<String> redisSerializer = getRedisSerializer();
+            return connection.zIncrBy(redisSerializer.serialize(key), increment, redisSerializer.serialize(member));
+        });
+    }
+
+    /**
+     * ZREVRANGE key start stop [WITHSCORES]
+     *
+     * @return
+     */
+    public List<String> doZrevrange(String key, Integer start, Integer end) {
+        List<String> stringList = new ArrayList<>();
+        RedisSerializer<String> redisSerializer = getRedisSerializer();
+        Set<byte[]> strBytes = redisTemplate.execute((RedisCallback<Set<byte[]>>) connection -> connection.zRevRange(redisSerializer.serialize(key), start, end));
+        Iterator byteIter = strBytes.iterator();
+        while (byteIter.hasNext()) {
+            stringList.add(redisSerializer.deserialize((byte[]) byteIter.next()));
+        }
+        return stringList;
+    }
+
+    public void setAdd(final String key, final String value) {
+        redisTemplate.opsForSet().add(key, value);
+    }
+
+    public void setRemove(final String key, final String value) {
+        redisTemplate.opsForSet().remove(key, value);
+    }
+
+    public Set<String> members(final String key) {
+        return redisTemplate.opsForSet().members(key);
+    }
+
+}
+

+ 23 - 1
zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/BigDecimalUtils.java

@@ -49,12 +49,24 @@ public class BigDecimalUtils {
     * @param value, value2
     * @return java.math.BigDecimal
     **/
+    public static BigDecimal multiply(Object value, Object value2){
+        return multiply(new BigDecimal(value.toString()), new BigDecimal(value2.toString()), 2);
+    }
+
+    /**
+    * 减法
+    * @author Andy
+    * @date 17:56 2021/8/11
+    * @param value:
+    * @param value2:
+    * @return java.math.BigDecimal
+    **/
     public static BigDecimal subtract(Object value, Object value2){
         return subtract(new BigDecimal(value.toString()), new BigDecimal(value2.toString()));
     }
 
     /**
-     * 乘法
+     * 
      * @param value
      * @param value2
      * @return
@@ -63,5 +75,15 @@ public class BigDecimalUtils {
         return value.subtract(value2);
     }
 
+    /**
+     * 乘法
+     * @param value
+     * @param value2
+     * @return
+     */
+    public static BigDecimal multiply(BigDecimal value, BigDecimal value2, int scale){
+        return value.multiply(value2).setScale(scale,BigDecimal.ROUND_HALF_UP);
+    }
+
 
 }

+ 94 - 0
zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/CalcUtil.java

@@ -0,0 +1,94 @@
+package com.zcxk.core.utils;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2020-11-19 8:35
+ */
+public class CalcUtil {
+
+    private static ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
+
+    private static ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("nashorn");
+
+    /**
+     * 调用js方法执行表达式
+     * @param expression
+     */
+    public static String executeExpression(String expression) throws ScriptException {
+        return String.valueOf(scriptEngine.eval(expression));
+    }
+
+    /**
+     * 根据比较符号返回结果 ( >、≥、<、≤、=、≠ )
+     * 比较规则  param1  (sign)  param2
+     * 参数为 null 则默认为 0,符号不存在或为空则返回 false
+     * @param param1
+     * @param param2
+     * @return
+     */
+    public static Boolean compareBySign(Double param1 , Double param2 , String sign){
+           int result = new BigDecimal( param1 != null?param1 :0 ).compareTo(new BigDecimal(param2 != null?param2 :0 ));
+        switch (sign){
+            case ">": return result == 1;
+            case "≥": return result != -1;
+            case "<": return result == -1;
+            case "≤": return result != 1;
+            case "=": return result == 0;
+            case "≠": return result != 0;
+        }
+        return false;
+    }
+
+    public static Boolean compareBySign(BigDecimal param1 , BigDecimal param2 , String sign){
+        int result = param1.compareTo(param2);
+        switch (sign){
+            case ">": return result == 1;
+            case "≥": return result != -1;
+            case "<": return result == -1;
+            case "≤": return result != 1;
+            case "=": return result == 0;
+            case "≠": return result != 0;
+        }
+        return false;
+    }
+
+    public static Boolean compareBySign(BigDecimal param1 ,String operation, BigDecimal param2 , String sign, BigDecimal param3) {
+        BigDecimal operationResult = operation(param1, operation, param2);
+        int result = operationResult.compareTo(param3);
+        switch (sign){
+            case ">": return result == 1;
+            case "≥": return result != -1;
+            case "<": return result == -1;
+            case "≤": return result != 1;
+            case "=": return result == 0;
+            case "≠": return result != 0;
+            default: return false;
+        }
+    }
+
+
+    public static BigDecimal operation(BigDecimal param1, String operation, BigDecimal param2){
+        switch (operation) {
+            case "+": return param1.add(param2);
+            case "-": return param1.subtract(param2);
+            case "*": return param1.multiply(param2);
+            case "/": return param1.divide(param2, 2, RoundingMode.HALF_UP);
+            default :
+                return null;
+        }
+    }
+
+
+    public static void main(String[] args) throws ScriptException{
+       System.out.println( CalcUtil.operation(new BigDecimal("17339.98") ,"+", new BigDecimal("17389.73")));
+    }
+
+
+}

+ 26 - 0
zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/DateUtil.java

@@ -8,6 +8,7 @@ import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collections;
@@ -2118,4 +2119,29 @@ public class DateUtil extends DateFormatUtils {
         DateTimeFormatter df = DateTimeFormatter.ofPattern(parsePatterns[1]);
         return  df.format(time);
     }
+
+
+    public static Date addDayOfDate(Date date,int i){
+        Calendar c = Calendar.getInstance();
+        c.setTime(date);
+        c.add(Calendar.DATE, i);
+        Date newDate = c.getTime();
+        return newDate;
+    }
+
+    public static Date addMinuteOfDate(Date date,int i){
+        if (date == null) {
+            return null;
+        }
+        Calendar c = Calendar.getInstance();
+        c.setTime(date);
+        c.add(Calendar.MINUTE, i);
+        Date newDate = c.getTime();
+        return newDate;
+    }
+
+    public static long minutesBetween(Date startTime, Date endTime){
+        return ChronoUnit.MINUTES.between(Instant.ofEpochMilli(startTime.getTime()), Instant.ofEpochMilli(endTime.getTime()));
+    }
+
 }

+ 45 - 0
zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/converter/DeviceTypeConverter.java

@@ -0,0 +1,45 @@
+package com.zcxk.core.utils.converter;
+
+import com.alibaba.excel.converters.Converter;
+import com.alibaba.excel.enums.CellDataTypeEnum;
+import com.alibaba.excel.metadata.CellData;
+import com.alibaba.excel.metadata.GlobalConfiguration;
+import com.alibaba.excel.metadata.property.ExcelContentProperty;
+
+/**
+ * @description 设备类型转换
+ * @auto wangli
+ * @data 2020-11-17 21:57
+ */
+public class DeviceTypeConverter implements Converter<Integer> {
+    // 在java中的类型是什么
+    @Override
+    public Class supportJavaTypeKey() {
+        return Integer.class;
+    }
+    // 在excel中的类型是什么
+    @Override
+    public CellDataTypeEnum supportExcelTypeKey() {
+        return CellDataTypeEnum.STRING;
+    }
+    // 将excel的数据类型转为java数据类型
+    @Override
+    public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
+        String stringValue = cellData.getStringValue();
+        if (stringValue == null) {
+            throw new RuntimeException("性别填写为空");
+        }
+        if ("男".equals(stringValue)) {
+            return 1;
+        }
+        return 0;
+    }
+    // 将java的数据类型转为excel数据类型
+    @Override
+    public CellData convertToExcelData(Integer s, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
+        if	(s == 0){
+            return new CellData("女");
+        }
+        return new CellData("男");
+    }
+}

+ 29 - 0
zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/converter/Double1Serializer.java

@@ -0,0 +1,29 @@
+package com.zcxk.core.utils.converter;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+
+import java.io.IOException;
+import java.text.DecimalFormat;
+
+public class Double1Serializer extends JsonSerializer<Double> {
+
+    private DecimalFormat df = new DecimalFormat("0.#");
+
+    /**
+     * 小数保留1位返回给前端序列化器
+     * @param data
+     * @param jsonGenerator
+     * @param serializerProvider
+     * @throws IOException
+     */
+    @Override
+    public void serialize(Double data, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
+            throws IOException {
+        if (data != null) {
+            jsonGenerator.writeNumber(df.format(data));
+        }
+    }
+
+}

+ 29 - 0
zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/converter/Double2Serializer.java

@@ -0,0 +1,29 @@
+package com.zcxk.core.utils.converter;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+
+import java.io.IOException;
+import java.text.DecimalFormat;
+
+public class Double2Serializer extends JsonSerializer<Double> {
+
+    private DecimalFormat df = new DecimalFormat("0.##");
+
+    /**
+     * 小数保留3位返回给前端序列化器
+     * @param data
+     * @param jsonGenerator
+     * @param serializerProvider
+     * @throws IOException
+     */
+    @Override
+    public void serialize(Double data, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
+            throws IOException {
+        if (data != null) {
+            jsonGenerator.writeNumber(df.format(data));
+        }
+    }
+
+}

+ 29 - 0
zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/converter/Double3Serializer.java

@@ -0,0 +1,29 @@
+package com.zcxk.core.utils.converter;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+
+import java.io.IOException;
+import java.text.DecimalFormat;
+
+public class Double3Serializer extends JsonSerializer<Double> {
+
+    private DecimalFormat df = new DecimalFormat("0.###");
+
+    /**
+     * 小数保留3位返回给前端序列化器
+     * @param data
+     * @param jsonGenerator
+     * @param serializerProvider
+     * @throws IOException
+     */
+    @Override
+    public void serialize(Double data, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
+            throws IOException {
+        if (data != null) {
+            jsonGenerator.writeNumber(df.format(data));
+        }
+    }
+
+}

+ 24 - 0
zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/converter/Object6Serialize.java

@@ -0,0 +1,24 @@
+package com.zcxk.core.utils.converter;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+public class Object6Serialize extends JsonSerializer<Object> {
+    //修改要除的数据  
+    private static final BigDecimal TEMP = BigDecimal.valueOf(1000000L);
+ 
+    @Override
+    public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
+        if (value != null) {
+            BigDecimal bigDecimal = new BigDecimal(value.toString());
+            //参考该方法 第二个参数是几就保留几位小数 第三个参数 参考 RoundingMode.java
+            gen.writeNumber(bigDecimal.divide(TEMP, 3, RoundingMode.DOWN));
+        }
+    }
+ 
+}

+ 35 - 4
zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/export/EasyExcelUtil.java

@@ -1,6 +1,9 @@
 package com.zcxk.core.utils.export;
 
 import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.ExcelWriter;
+import com.alibaba.excel.metadata.BaseRowModel;
+import com.alibaba.excel.metadata.Sheet;
 import com.alibaba.excel.support.ExcelTypeEnum;
 import com.alibaba.excel.write.metadata.style.WriteCellStyle;
 import com.alibaba.excel.write.metadata.style.WriteFont;
@@ -15,6 +18,7 @@ import org.apache.poi.ss.usermodel.VerticalAlignment;
 import javax.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.util.Date;
@@ -62,10 +66,13 @@ public  class EasyExcelUtil {
 
     public static void excelWrite(HttpServletResponse response,Class t, String excelName, List data) throws Exception {
         String fileName =  excelName +"-"+ DateUtil.format(new Date(), "yyyyMMddHHmmss")  + ".xlsx";
-        response.setContentType("APPLICATION/OCTET-STREAM");
-        response.setCharacterEncoding("utf-8");
-        String headStr = "attachment;filename*=UTF-8''" + URLEncoder.encode(fileName, "UTF-8");
-        response.setHeader("Content-Disposition", headStr);
+        response.setContentType("application/vnd.ms-excel");
+        response.setCharacterEncoding("utf8");
+        response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
+        response.setHeader("Pragma", "public");
+        response.setHeader("Cache-Control", "no-store");
+        response.addHeader("Cache-Control", "max-age=0");
+
         EasyExcel.write(response.getOutputStream(), t)
                 .excelType(ExcelTypeEnum.XLSX)
                 .registerWriteHandler(new CustemhandlerUtils())
@@ -75,6 +82,30 @@ public  class EasyExcelUtil {
     }
 
 
+    /**
+     * 导出文件时为Writer生成OutputStream.
+     *
+     * @param fileName 文件名
+     * @param response response
+     * @return ""
+     */
+    private static OutputStream getOutputStream(String fileName,
+                                                HttpServletResponse response) throws Exception {
+        try {
+            fileName = URLEncoder.encode(fileName, "UTF-8");
+            response.setContentType("application/vnd.ms-excel");
+            response.setCharacterEncoding("utf8");
+            response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".xlsx");
+            response.setHeader("Pragma", "public");
+            response.setHeader("Cache-Control", "no-store");
+            response.addHeader("Cache-Control", "max-age=0");
+            return response.getOutputStream();
+        } catch (IOException e) {
+            throw new Exception("导出excel表格失败!", e);
+        }
+    }
+
+
     private static final String getPathFileName(String uploadDir, String fileName) throws IOException {
         String pathFileName = uploadDir  + "/" + fileName;
         return ToolUtil.path(pathFileName);

+ 26 - 0
zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/jsonSerializer/BigDecimalJsonSerializer.java

@@ -0,0 +1,26 @@
+package com.zcxk.core.utils.jsonSerializer;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+
+/**
+ * @description BigDecimal保留三位小数
+ * @auto wangli
+ * @data 2020/12/31 14:17
+ */
+public class BigDecimalJsonSerializer extends JsonSerializer<BigDecimal> {
+
+    private DecimalFormat df = new DecimalFormat("0.000");
+
+    @Override
+    public void serialize(BigDecimal bigDecimal, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
+        if(bigDecimal != null){
+            jsonGenerator.writeString(df.format(bigDecimal));
+        }
+    }
+}

+ 26 - 0
zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/jsonSerializer/BigDecimalJsonSerializerTwo.java

@@ -0,0 +1,26 @@
+package com.zcxk.core.utils.jsonSerializer;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+
+/**
+ * @description BigDecimal保留两位小数
+ * @auto wangli
+ * @data 2020/12/31 14:17
+ */
+public class BigDecimalJsonSerializerTwo extends JsonSerializer<BigDecimal> {
+
+    private DecimalFormat df = new DecimalFormat("0.00");
+
+    @Override
+    public void serialize(BigDecimal bigDecimal, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
+        if(bigDecimal != null){
+            jsonGenerator.writeString(df.format(bigDecimal));
+        }
+    }
+}

+ 24 - 0
zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/jsonSerializer/DoubleJsonSerializer.java

@@ -0,0 +1,24 @@
+package com.zcxk.core.utils.jsonSerializer;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+
+import java.io.IOException;
+import java.text.DecimalFormat;
+
+/**
+ * @description Double保留三位小数
+ * @auto wangli
+ * @data 2020/12/31 14:17
+ */
+public class DoubleJsonSerializer extends JsonSerializer<Double> {
+
+    private DecimalFormat df = new DecimalFormat("0.000");
+    @Override
+    public void serialize(Double aDouble, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
+        if(aDouble != null) {
+            jsonGenerator.writeString(df.format(aDouble));
+        }
+    }
+}