Sfoglia il codice sorgente

Merge branch 'master' of http://116.63.33.55/git/nazw

ljh 2 anni fa
parent
commit
4727da787d

+ 1 - 1
nngkxxdp/src/main/java/com/example/nngkxxdp/configer/RedisConfig.java

@@ -35,7 +35,7 @@ public class RedisConfig extends CachingConfigurerSupport {
         Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<Object>(Object.class);
         ObjectMapper objectMapper = new ObjectMapper();
         objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
-        objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
+//        objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
         jackson2JsonRedisSerializer.setObjectMapper(objectMapper);
         // 设置key和value的序列化规则
         // key序列化

+ 38 - 7
nngkxxdp/src/main/java/com/example/nngkxxdp/service/impl/DepartmentItemRankServiceImpl.java

@@ -1,14 +1,18 @@
 package com.example.nngkxxdp.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.example.nngkxxdp.dao.*;
 import com.example.nngkxxdp.entity.*;
 import com.example.nngkxxdp.service.DepartmentItemRankService;
 import com.example.nngkxxdp.util.BaseResult;
+import com.example.nngkxxdp.util.RedisUtil;
 import com.example.nngkxxdp.util.ToCountUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -31,6 +35,9 @@ public class DepartmentItemRankServiceImpl implements DepartmentItemRankService
     @Autowired
     private ProcessingDao processingDao;
 
+    @Autowired
+    public RedisUtil redisUtil;
+
     public BaseResult queryDepartmentItemRankByArea(Integer area) {
         Map<String, Object> queryMap = new HashMap();
 
@@ -48,15 +55,13 @@ public class DepartmentItemRankServiceImpl implements DepartmentItemRankService
         listMatterRank.setThirdName(ToCountUtil.toTenName(listMatterRank.getThirdName()));
 
         DepartmentItemRank listTotal = this.departmentItemRankDao.queryDepartmentItemRankByArea(area, Integer.valueOf(3));
-        if ((listTotal != null) && (listTotal.getConutNumber() != null))
-        {
+        if ((listTotal != null) && (listTotal.getConutNumber() != null)) {
             String count = listTotal.getConutNumber().toString();
             char[] conutNumber = count.toCharArray();
             String[] conutNumbers = ToCountUtil.charToStringArray(conutNumber);
             json.put("conutNumbers", conutNumbers);
         }
-        if (!area.equals(Integer.valueOf(1)))
-        {
+        if (!area.equals(Integer.valueOf(1))) {
             ItemDetail listDetail = this.itemDetailDao.getItemDetailInfo();
             String count = listDetail.getTotalNumber().toString();
             char[] conutNumber = count.toCharArray();
@@ -100,14 +105,40 @@ public class DepartmentItemRankServiceImpl implements DepartmentItemRankService
     }
 
     public BaseResult getListMatterRank(Integer area) {
-        List<Processing> processingList = this.processingDao.getProessingByBatchInfo(area);
-        for (Processing processing : processingList)
-        {
+//        List<Processing> processingList = this.processingDao.getProessingByBatchInfo(area);
+//        for (Processing processing : processingList)
+//        {
+//            DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+//
+//            String strDate2 = dtf2.format(processing.getCreateTime()).split(" ")[0];
+//
+//            processing.setcTime(strDate2);
+//        }
+//        return BaseResult.ok(processingList);
+        List<Processing> list = new ArrayList();
+        if (area.intValue() == 1) {
+            list = JSON.parseArray(JSON.toJSONString(this.redisUtil.get("cqzw_yuk_1")), Processing.class);
+        } else {
+            list = JSON.parseArray(JSON.toJSONString(this.redisUtil.get("cqzw_yuk_2")), Processing.class);
+        }
+        List<Processing> processingList = new ArrayList();
+        int index;
+        if (list.size() > 10) {
+            for (int i = 0; i < 10; i++) {
+                index = ToCountUtil.GetRandomNum(1, list.size());
+                processingList.add(list.get(index - 1));
+            }
+        }
+        processingList = list;
+        for (Processing processing : processingList) {
             DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
 
             String strDate2 = dtf2.format(processing.getCreateTime()).split(" ")[0];
 
             processing.setcTime(strDate2);
+            if (processing.getHandlingName().length() > 6) {
+                processing.setHandlingName(processing.getHandlingName().substring(0, 6) + ".....");
+            }
         }
         return BaseResult.ok(processingList);
     }

+ 5 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/service/impl/ProblemUserServiceImpl.java

@@ -6,6 +6,7 @@ import com.example.nngkxxdp.entity.ProblemUser;
 import com.example.nngkxxdp.entity.User;
 import com.example.nngkxxdp.service.ProblemUserService;
 import com.example.nngkxxdp.util.*;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
@@ -27,6 +28,9 @@ public class ProblemUserServiceImpl implements ProblemUserService {
     @Value("${login.loginOutTime}")
     private int loginOutTime = 30;
 
+    @Autowired
+    private RedisUtil redisUtil;
+
     @Override
     public Map<String, Object> checkUserNameAndPassWord(String username, String password) {
         String md5 = SecureUtil.md5(password);
@@ -37,6 +41,7 @@ public class ProblemUserServiceImpl implements ProblemUserService {
         }
         String token = TokenUtil.token(username, loginOutTime);
         Map<String, Object> result = new HashMap<>();
+        redisUtil.set(token, problemUser.getId());
         result.put("utoken", token);
         result.put("username", problemUser.getUserName());
         result.put("pid", problemUser.getId());

+ 41 - 34
nngkxxdp/src/main/java/com/example/nngkxxdp/util/FileUtil.java

@@ -39,49 +39,47 @@ import sun.net.www.protocol.file.FileURLConnection;
  */
 public class FileUtil {
 
+    private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+
     /**
-     * @param multipartFile
-     * @param fileDir
-     * @return
-     * @throws Exception
-     * @Title: fileUpload
-     * @Description: 上传文件--多文件
-     * @author: zcf
-     * @date: 2020-11-16 17:52:56
-     * @returnType List<String>
+     * @param multipartFiles 文件数组
+     * @param fileDir        上传到的路径
+     * @return 文件上传之后, 保存到硬盘中文件的名称集合
+     * @author: zhoupeng
+     * @date: 2022-01-29 17:06:01
      */
-    public static List<String> fileUpload(MultipartFile[] multipartFile, String fileDir) throws Exception {
-        List<String> result = new ArrayList<>();
-        // 判断多文件上传
-//        if (multipartFile != null && multipartFile.length > 0) {
-//            for (int i = 0; i < multipartFile.length; i++) {
-//                //获取上传过来的文件名
-//                File temporaryFile = new File(fileDir + multipartFile[i].getOriginalFilename());
-//                multipartFile[i].transferTo(temporaryFile);
-//                String type = FileTypeUtil.getType(temporaryFile);
-//                String newName = (new Date()).getTime() + ((int) (Math.random() * 9000) + 1000) + "." + type;
-//                String filePath = fileDir + newName;
-//                File newFile = new File(filePath);
-//                temporaryFile.renameTo(newFile);
-//                // 返回结果
-//                result.add(newName);
-//            }
-//        }
-        if (multipartFile != null) {
-            for (int i = 0; i < multipartFile.length; i++) {
+    public static List<String> fileUpload(MultipartFile[] multipartFiles, String fileDir) throws IOException {
+        List<String> stringList = new ArrayList<>();
+        File folder = new File(fileDir);
+        //是否为目录
+        if (!folder.isDirectory()) {
+            //不是目录
+            folder.mkdirs();
+        }
+        if (Blank.isNotEmpty(multipartFiles) && multipartFiles.length > 0) {
+            for (int i = 0; i < multipartFiles.length; i++) {
                 //获取上传过来的文件名
-                File temporaryFile = new File(fileDir + multipartFile[i].getOriginalFilename());
-                multipartFile[i].transferTo(temporaryFile);
+                String originalFileName = multipartFiles[i].getOriginalFilename();
+                if (Blank.isEmpty(originalFileName)) {
+                    continue;
+                }
+                File temporaryFile = new File(fileDir + "\\" + originalFileName);
+                //保存文件
+                multipartFiles[i].transferTo(temporaryFile);
+//                stringList.add(originalFileName);
+
+                //如果需要更改文件的名称,使用其他命名方式,则执行下面的代码
                 String type = FileTypeUtil.getType(temporaryFile);
-                String newName = (new Date()).getTime() + ((int) (Math.random() * 9000) + 1000) + "." + type;
-                String filePath = fileDir + newName;
+                String newName = generTrfn() + "." + type;
+                String filePath = fileDir + "\\" + newName;
                 File newFile = new File(filePath);
+                //修改文件名
                 temporaryFile.renameTo(newFile);
                 // 返回结果
-                result.add("" + newName);
+                stringList.add(newName);
             }
         }
-        return result;
+        return stringList;
     }
 
     public static Map<String, Object> fileUploads(MultipartFile mFile, String fileDir) throws Exception {
@@ -549,4 +547,13 @@ public class FileUtil {
 //		loadRecourseFromJar();
 //	}
 
+    /**
+     * 返回时间(年月日时分秒毫秒)+4位随机数
+     *
+     * @return
+     */
+    public static String generTrfn() {
+        return simpleDateFormat.format(new Date()) + ((int) (Math.random() * 9000) + 1000);
+    }
+
 }

+ 415 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/util/RedisUtil.java

@@ -0,0 +1,415 @@
+package com.example.nngkxxdp.util;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author zhoupeng
+ * @date 2022/7/27
+ */
+@Component
+public class RedisUtil {
+
+    //    @Resource
+//    private RedisTemplate<String, Object> redisTemplate;
+    @Autowired
+    private RedisTemplate redisTemplate;
+
+    public boolean expire(String key, long time)
+    {
+        try
+        {
+            if (time > 0L) {
+                this.redisTemplate.expire(key, time, TimeUnit.SECONDS);
+            }
+            return true;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    public long getExpire(String key)
+    {
+        return this.redisTemplate.getExpire(key, TimeUnit.SECONDS).longValue();
+    }
+
+    public boolean hasKey(String key)
+    {
+        try
+        {
+            return this.redisTemplate.hasKey(key).booleanValue();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    public Object get(String key)
+    {
+        return key == null ? null : this.redisTemplate.opsForValue().get(key);
+    }
+
+    public boolean set(String key, Object value)
+    {
+        try
+        {
+            this.redisTemplate.opsForValue().set(key, value);
+            return true;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    public boolean set(String key, Object value, long time)
+    {
+        try
+        {
+            if (time > 0L) {
+                this.redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
+            } else {
+                set(key, value);
+            }
+            return true;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    public long incr(String key, long delta)
+    {
+        if (delta < 0L) {
+            throw new RuntimeException("递增因子必须大于0");
+        }
+        return this.redisTemplate.opsForValue().increment(key, delta).longValue();
+    }
+
+    public long decr(String key, long delta)
+    {
+        if (delta < 0L) {
+            throw new RuntimeException("递减因子必须大于0");
+        }
+        return this.redisTemplate.opsForValue().increment(key, -delta).longValue();
+    }
+
+    public Object hget(String key, String item)
+    {
+        return this.redisTemplate.opsForHash().get(key, item);
+    }
+
+    public Map<Object, Object> hmget(String key)
+    {
+        return this.redisTemplate.opsForHash().entries(key);
+    }
+
+    public boolean hmset(String key, Map<String, Object> map)
+    {
+        try
+        {
+            this.redisTemplate.opsForHash().putAll(key, map);
+            return true;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    public boolean hmset(String key, Map<String, Object> map, long time)
+    {
+        try
+        {
+            this.redisTemplate.opsForHash().putAll(key, map);
+            if (time > 0L) {
+                expire(key, time);
+            }
+            return true;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    public boolean hset(String key, String item, Object value)
+    {
+        try
+        {
+            this.redisTemplate.opsForHash().put(key, item, value);
+            return true;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    public boolean hset(String key, String item, Object value, long time)
+    {
+        try
+        {
+            this.redisTemplate.opsForHash().put(key, item, value);
+            if (time > 0L) {
+                expire(key, time);
+            }
+            return true;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    public void hdel(String key, Object... item)
+    {
+        this.redisTemplate.opsForHash().delete(key, item);
+    }
+
+    public boolean hHasKey(String key, String item)
+    {
+        return this.redisTemplate.opsForHash().hasKey(key, item).booleanValue();
+    }
+
+    public double hincr(String key, String item, long by)
+    {
+        return this.redisTemplate.opsForHash().increment(key, item, by).longValue();
+    }
+
+    public double hdecr(String key, String item, long by)
+    {
+        return this.redisTemplate.opsForHash().increment(key, item, -by).longValue();
+    }
+
+    public Set<Object> sGet(String key)
+    {
+        try
+        {
+            return this.redisTemplate.opsForSet().members(key);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    public boolean sHasKey(String key, Object value)
+    {
+        try
+        {
+            return this.redisTemplate.opsForSet().isMember(key, value).booleanValue();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    public long sSet(String key, Object... values)
+    {
+        try
+        {
+            return this.redisTemplate.opsForSet().add(key, values).longValue();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return 0L;
+    }
+
+    public long sSetAndTime(String key, long time, Object... values)
+    {
+        try
+        {
+            Long count = this.redisTemplate.opsForSet().add(key, values);
+            if (time > 0L) {
+                expire(key, time);
+            }
+            return count.longValue();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return 0L;
+    }
+
+    public long sGetSetSize(String key)
+    {
+        try
+        {
+            return this.redisTemplate.opsForSet().size(key).longValue();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return 0L;
+    }
+
+    public long setRemove(String key, Object... values)
+    {
+        try
+        {
+            Long count = this.redisTemplate.opsForSet().remove(key, values);
+            return count.longValue();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return 0L;
+    }
+
+    public List<Object> lGet(String key, long start, long end)
+    {
+        try
+        {
+            return this.redisTemplate.opsForList().range(key, start, end);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    public long lGetListSize(String key)
+    {
+        try
+        {
+            return this.redisTemplate.opsForList().size(key).longValue();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return 0L;
+    }
+
+    public Object lGetIndex(String key, long index)
+    {
+        try
+        {
+            return this.redisTemplate.opsForList().index(key, index);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    public boolean lSet(String key, Object value)
+    {
+        try
+        {
+            this.redisTemplate.opsForList().rightPush(key, value);
+            return true;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    public boolean lSet(String key, Object value, long time)
+    {
+        try
+        {
+            this.redisTemplate.opsForList().rightPush(key, value);
+            if (time > 0L) {
+                expire(key, time);
+            }
+            return true;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    public boolean lSet(String key, List<Object> value)
+    {
+        try
+        {
+            this.redisTemplate.opsForList().rightPushAll(key, value);
+            return true;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    public boolean lSet(String key, List<Object> value, long time)
+    {
+        try
+        {
+            this.redisTemplate.opsForList().rightPushAll(key, value);
+            if (time > 0L) {
+                expire(key, time);
+            }
+            return true;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    public boolean lUpdateIndex(String key, long index, Object value)
+    {
+        try
+        {
+            this.redisTemplate.opsForList().set(key, index, value);
+            return true;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    public long lRemove(String key, long count, Object value)
+    {
+        try
+        {
+            Long remove = this.redisTemplate.opsForList().remove(key, count, value);
+            return remove.longValue();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return 0L;
+    }
+}

+ 14 - 3
nngkxxdp/src/main/resources/application-dev.yml

@@ -23,9 +23,20 @@ spring:
     password: jd123456
   resources:
     static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${file.path},file:${file.location}
-#  mvc:
-#    favicon:
-#      enabled: false
+  #  mvc:
+  #    favicon:
+  #      enabled: false
+  redis:
+    database: 0
+    host: 127.0.0.1
+    port: 6379
+    #    password: 123456
+    jedis:
+      pool:
+        max-active: 50
+        max-idle: 20
+        min-idle: 5
+    #        max-wait: 5
 elasticsearch:
   ip: 192.168.1.253:9200
   # 索引名