Browse Source

传感器-GPS-code

WXF 3 years ago
parent
commit
82757a30c3

+ 0 - 88
simulation-resource-common/src/main/java/com/css/simulation/resource/common/util/processbar/ProgressBar.java

@@ -1,88 +0,0 @@
-//
-// Source code recreated from a .class file by IntelliJ IDEA
-// (powered by Fernflower decompiler)
-//
-
-package com.css.simulation.resource.common.util.processbar;
-
-import com.css.simulation.resource.common.controller.RedisController;
-
-import java.io.PrintStream;
-import java.time.LocalDateTime;
-
-public class ProgressBar {
-    private ProgressState progress;
-    private ProgressThread target;
-    private Thread thread;
-
-    public ProgressBar(RedisController redisController, String task, long initialMax) {
-        this(redisController, task, initialMax, 1000, System.err);
-    }
-
-
-    public ProgressBar(RedisController redisController, String task, long initialMax, int updateIntervalMillis, PrintStream os) {
-        this.progress = new ProgressState(task, initialMax);
-        this.target = new ProgressThread(this.progress, (long)updateIntervalMillis, os, redisController);
-        this.thread = new Thread(this.target);
-    }
-
-    public ProgressBar start() {
-        this.progress.startTime = LocalDateTime.now();
-        this.thread.start();
-        return this;
-    }
-
-    public ProgressBar stepBy(long n) {
-        this.progress.stepBy(n);
-        return this;
-    }
-
-    public ProgressBar stepTo(long n) {
-        this.progress.stepTo(n);
-        return this;
-    }
-
-    public ProgressBar step() {
-        this.progress.stepBy(1L);
-        return this;
-    }
-
-    public ProgressBar maxHint(long n) {
-        this.progress.maxHint(n);
-        return this;
-    }
-
-    public ProgressBar stop() {
-        this.target.kill();
-
-        try {
-            this.thread.join();
-            this.target.consoleStream.print("\n");
-            this.target.consoleStream.flush();
-        } catch (InterruptedException var2) {
-        }
-
-        return this;
-    }
-
-    public ProgressBar setExtraMessage(String msg) {
-        this.progress.setExtraMessage(msg);
-        return this;
-    }
-
-    public long getCurrent() {
-        return this.progress.getCurrent();
-    }
-
-    public long getMax() {
-        return this.progress.getMax();
-    }
-
-    public String getTask() {
-        return this.progress.getTask();
-    }
-
-    public String getExtraMessage() {
-        return this.progress.getExtraMessage();
-    }
-}

+ 0 - 62
simulation-resource-common/src/main/java/com/css/simulation/resource/common/util/processbar/ProgressState.java

@@ -1,62 +0,0 @@
-//
-// Source code recreated from a .class file by IntelliJ IDEA
-// (powered by Fernflower decompiler)
-//
-
-package com.css.simulation.resource.common.util.processbar;
-
-import java.time.LocalDateTime;
-
-class ProgressState {
-    String task;
-    long current = 0L;
-    long max = 0L;
-    LocalDateTime startTime = null;
-    String extraMessage = "";
-
-    ProgressState(String task, long initialMax) {
-        this.task = task;
-        this.max = initialMax;
-    }
-
-    synchronized void maxHint(long n) {
-        this.max = n;
-    }
-
-    synchronized void stepBy(long n) {
-        this.current += n;
-        if (this.current > this.max) {
-            this.max = this.current;
-        }
-
-    }
-
-    synchronized void stepTo(long n) {
-        this.current = n;
-        if (this.current > this.max) {
-            this.max = this.current;
-        }
-
-    }
-
-    synchronized void setExtraMessage(String msg) {
-        this.extraMessage = msg;
-    }
-
-    String getTask() {
-        return this.task;
-    }
-
-    synchronized String getExtraMessage() {
-        return this.extraMessage;
-    }
-
-    synchronized long getCurrent() {
-        return this.current;
-    }
-
-    synchronized long getMax() {
-        return this.max;
-    }
-}
-

+ 0 - 103
simulation-resource-common/src/main/java/com/css/simulation/resource/common/util/processbar/ProgressStream.java

@@ -1,103 +0,0 @@
-package com.css.simulation.resource.common.util.processbar;/*
- * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2017 MinIO, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import com.css.simulation.resource.common.controller.RedisController;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-public class ProgressStream extends InputStream {
-    private InputStream in;
-    private ProgressBar pb;
-
-    /**
-     * ProgressStream implements an extends InputStream while also writing out the read progress on
-     * console. ProgressStream can be used as a direct replacement for any InputStream compatible
-     * input.
-     *
-     * @param msg Custom message string.
-     * @param stream InputStream to be wrapped.
-     * @throws IOException For any exception generated by the InputStream.
-     */
-    public ProgressStream(RedisController redisController, String msg, InputStream stream) throws IOException {
-        this(redisController, msg, (long) stream.available(), stream);
-    }
-
-    /**
-     * ProgressStream implements an extends InputStream while also writing out the read progress on
-     * console. ProgressStream can be used as a direct replacement for any InputStream compatible
-     * input.
-     *
-     * @param msg Custom message string.
-     * @param size Size of the progress bar.
-     * @param stream InputStream to be wrapped.
-     * @throws IOException For any exception generated by the InputStream.
-     */
-    public ProgressStream(RedisController redisController, String msg, long size, InputStream stream)
-            throws IOException {
-        super();
-
-        // Allocate the reader.
-        this.in = stream;
-
-        // Initialize progress bar.
-        this.pb = new ProgressBar(redisController, msg, size);
-        this.pb.start();
-    }
-
-    @Override
-    public int available() throws IOException {
-        return this.in.available();
-    }
-
-    @Override
-    public void close() throws IOException {
-        this.pb.stop();
-        this.in.close();
-        return;
-    }
-
-    @Override
-    public int read() throws IOException {
-        this.pb.step();
-        return this.in.read();
-    }
-
-    @Override
-    public int read(byte[] toStore) throws IOException {
-        int readBytes = this.in.read(toStore);
-        this.pb.stepBy(readBytes); // Update progress bar.
-        return readBytes;
-    }
-
-    @Override
-    public int read(byte[] toStore, int off, int len) throws IOException {
-        int readBytes = this.in.read(toStore, off, len);
-        this.pb.stepBy(readBytes);
-        return readBytes;
-    }
-
-    @Override
-    public long skip(long n) throws IOException {
-        this.pb.stepTo(n);
-        return this.in.skip(n);
-    }
-
-    @Override
-    public boolean markSupported() {
-        return false;
-    }
-}

+ 0 - 88
simulation-resource-common/src/main/java/com/css/simulation/resource/common/util/processbar/ProgressThread.java

@@ -1,88 +0,0 @@
-//
-// Source code recreated from a .class file by IntelliJ IDEA
-// (powered by Fernflower decompiler)
-//
-
-package com.css.simulation.resource.common.util.processbar;
-
-import api.common.pojo.param.RedisParameter;
-import com.css.simulation.resource.common.controller.RedisController;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.data.redis.core.StringRedisTemplate;
-import org.springframework.stereotype.Component;
-
-import java.io.PrintStream;
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.time.Duration;
-
-
-public class ProgressThread implements Runnable {
-    private final RedisController redisController;
-    volatile boolean running;
-    ProgressState progress;
-    long updateInterval;
-    PrintStream consoleStream;
-
-//    @Autowired
-//    RedisController redisController;
-
-//    @Autowired
-//    StringRedisTemplate redisTemplate;
-
-
-    ProgressThread(ProgressState progress, long updateInterval, PrintStream consoleStream,RedisController redisController) {
-        this.progress = progress;
-        this.updateInterval = updateInterval;
-        this.consoleStream = consoleStream;
-        this.redisController = redisController;
-    }
-
-    double progress() {
-        return this.progress.max == 0L ? 0.0D : (double)this.progress.current / (double)this.progress.max;
-    }
-
-
-    /**
-     * 保存文件进度
-     */
-    void refresh() {
-
-        //保存进度
-        Long progressMax = this.progress.max;
-        Long progressCurrent = this.progress.current;
-        String task = this.progress.task;
-//        System.out.println("上传进度:"+task);
-        Double radio = new BigDecimal(Double.valueOf(progressCurrent)/Double.valueOf(progressMax)).setScale(2, RoundingMode.UP).doubleValue();
-//        System.out.println("上传进度:"+radio);
-        RedisParameter redisParameter = new RedisParameter();
-        redisParameter.setKey(task);
-        redisParameter.setValue(radio.toString());
-        redisParameter.setMinutes(1440);//24小时清除
-
-        this.redisController.set(redisParameter);
-//        redisTemplate.opsForValue().set(redisParameter.getKey(), redisParameter.getValue(), Duration.ofMinutes(redisParameter.getMinutes()));
-
-
-    }
-
-    void kill() {
-        this.running = false;
-    }
-
-    public void run() {
-        this.running = true;
-
-        try {
-            while(this.running) {
-                this.refresh();
-                Thread.sleep(this.updateInterval);
-            }
-
-            this.refresh();
-        } catch (InterruptedException var2) {
-        }
-
-    }
-}

+ 5 - 19
simulation-resource-server/src/main/java/com/css/simulation/resource/model/service/GpsService.java

@@ -6,8 +6,8 @@ import api.common.pojo.po.model.GpsPO;
 import api.common.pojo.vo.model.GpsVO;
 import api.common.util.ObjectUtil;
 import api.common.util.StringUtil;
-import api.common.util.TimeUtil;
 import com.css.simulation.resource.common.utils.AuthUtil;
+import com.css.simulation.resource.common.utils.PoUtil;
 import com.css.simulation.resource.model.mapper.GpsMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -41,13 +41,7 @@ public class GpsService {
 
     public GpsPO saveGps(GpsPO gpsPO) {
         //常规字段赋值
-        String currentUserId = AuthUtil.getCurrentUserId();
-        Timestamp currentTime = TimeUtil.getNowForMysql();
-        gpsPO.setCreateUserId(currentUserId);
-        gpsPO.setCreateTime(currentTime);
-        gpsPO.setModifyUserId(currentUserId);
-        gpsPO.setModifyTime(currentTime);
-        gpsPO.setIsDeleted(DictConstants.NO);
+        PoUtil.initAddPo(gpsPO);
         gpsPO.setShare(DictConstants.NO);//私有
         //名称校验
         List<GpsVO> list = gpsMapper.checkGpsName(gpsPO);
@@ -58,7 +52,7 @@ public class GpsService {
         String id = gpsPO.getId();
         if(ObjectUtil.isNull(id)){//新增
             gpsPO.setId(StringUtil.getRandomUUID());
-            gpsPO.setSensorCode(StringUtil.getRandomUUID());
+            gpsPO.setSensorCode(StringUtil.getRandomCode());
             gpsMapper.insert(gpsPO);
         }else{//修改
             gpsMapper.update(gpsPO);
@@ -78,13 +72,7 @@ public class GpsService {
             return gpsPO;
         }
         //常规字段赋值
-        String currentUserId = AuthUtil.getCurrentUserId();
-        Timestamp currentTime = TimeUtil.getNowForMysql();
-        gpsPO.setCreateUserId(currentUserId);
-        gpsPO.setCreateTime(currentTime);
-        gpsPO.setModifyUserId(currentUserId);
-        gpsPO.setModifyTime(currentTime);
-        gpsPO.setIsDeleted(DictConstants.NO);
+        PoUtil.initAddPo(gpsPO);
         gpsPO.setId(StringUtil.getRandomUUID());
         gpsPO.setSensorCode(StringUtil.getRandomCode());
         gpsMapper.insert(gpsPO);
@@ -92,9 +80,7 @@ public class GpsService {
     }
 
     public int delGpsById(GpsPO gpsPO) {
-        gpsPO.setIsDeleted(DictConstants.YES);
-        gpsPO.setModifyUserId(AuthUtil.getCurrentUserId());
-        gpsPO.setModifyTime(TimeUtil.getNowForMysql());
+        PoUtil.initDelPo(gpsPO);
         int i = gpsMapper.delGpsById(gpsPO);
         return i;
     }