浏览代码

Merge branch 'master' of http://47.100.37.243:10191/wutt/manHourHousekeeper

Min 11 月之前
父节点
当前提交
6185a1de99

+ 44 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/util/CodeUtil.java

@@ -0,0 +1,44 @@
+package com.management.platform.util;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.text.DecimalFormat;
+import java.util.Random;
+
+/**
+ * Author: 吴涛涛 cuiyi@itany.com
+ * Date : 2019 - 10 - 24 16:23
+ * Description:验证码生成工具
+ * Version: 1.0
+ */
+public class CodeUtil {
+
+
+    public HttpRespMsg getVcode(String mobile) {
+        HttpRespMsg msg = new HttpRespMsg();
+        if (mobile != null) {
+            Random r = new Random();
+            int val = r.nextInt(10000);
+            if (val < 1000) {
+                val += 1000;
+            }
+            String codeValStr = "" + val;
+//            Vcode record = new Vcode();
+//            record.setMobile(mobile);
+//            record.setVcode("" + val);
+//            vcodeMapper.insertSelective(record);
+//            try {
+//                SendSmsResponse sendSmsResponse = SmsDemo.sendSms(mobile, record.getVcode());
+//            } catch (ClientException e) {
+//                e.printStackTrace();
+//            }
+        }
+        return msg;
+    }
+
+    public static void main(String[] args) {
+        double temp = 1.42;
+        int thirdPosNum = ((int)(temp*1000))%10;
+        System.out.println(thirdPosNum);
+    }
+}

+ 153 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/util/FileUtil.java

@@ -0,0 +1,153 @@
+package com.management.platform.util;
+
+import com.fasterxml.jackson.annotation.ObjectIdGenerators;
+import org.apache.commons.io.FileUtils;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.*;
+import java.util.Arrays;
+
+/**
+ * 文件读取工具类
+ */
+public class FileUtil {
+
+    /**
+     * 获取容易识别的文件大小,比如KB, MB, GB
+     * @param size
+     * @return
+     */
+    public static String getReadableFileSize(long size) {
+        if (size < 1024) {//1K以内
+            return size + "byte";
+        } else if (size < 1024 * 1024) {//1M以内
+            return String.format("%.1fKB", (size*1.0f/1024));
+        } else if (size < 1024 * 1024 * 1024) {//1G以内
+            return String.format("%.1fMB", (size*1.0f/1024/1024));
+        } else {
+            return String.format("%.1fGB", (size*1.0f/1024/1024/1024));
+        }
+    }
+
+
+    /**
+     * 读取文件内容,作为字符串返回
+     */
+    public static String readFileAsString(String filePath) throws IOException {
+        File file = new File(filePath);
+        if (!file.exists()) {
+            throw new FileNotFoundException(filePath);
+        }
+
+        if (file.length() > 1024 * 1024 * 1024) {
+            throw new IOException("File is too large");
+        }
+
+        StringBuilder sb = new StringBuilder((int) (file.length()));
+        // 创建字节输入流  
+        FileInputStream fis = new FileInputStream(filePath);
+        // 创建一个长度为10240的Buffer
+        byte[] bbuf = new byte[10240];
+        // 用于保存实际读取的字节数  
+        int hasRead = 0;
+        while ((hasRead = fis.read(bbuf)) > 0) {
+            sb.append(new String(bbuf, 0, hasRead));
+        }
+        fis.close();
+        return sb.toString();
+    }
+
+    /**
+     * 根据文件路径读取byte[] 数组
+     */
+    public static byte[] readFileByBytes(String filePath) throws IOException {
+        File file = new File(filePath);
+        if (!file.exists()) {
+            throw new FileNotFoundException(filePath);
+        } else {
+            ByteArrayOutputStream bos = new ByteArrayOutputStream((int) file.length());
+            BufferedInputStream in = null;
+
+            try {
+                in = new BufferedInputStream(new FileInputStream(file));
+                short bufSize = 1024;
+                byte[] buffer = new byte[bufSize];
+                int len1;
+                while (-1 != (len1 = in.read(buffer, 0, bufSize))) {
+                    bos.write(buffer, 0, len1);
+                }
+
+                byte[] var7 = bos.toByteArray();
+                return var7;
+            } finally {
+                try {
+                    if (in != null) {
+                        in.close();
+                    }
+                } catch (IOException var14) {
+                    var14.printStackTrace();
+                }
+
+                bos.close();
+            }
+        }
+    }
+
+    /**
+     * 根据文件路径读取byte[] 数组
+     */
+    public static byte[] readFileByBytes(File file) throws IOException {
+        if (file == null) {
+            throw new FileNotFoundException("file is not null");
+        } else {
+            ByteArrayOutputStream bos = new ByteArrayOutputStream((int) file.length());
+            BufferedInputStream in = null;
+            try {
+                in = new BufferedInputStream(new FileInputStream(file));
+                short bufSize = 1024;
+                byte[] buffer = new byte[bufSize];
+                int len1;
+                while (-1 != (len1 = in.read(buffer, 0, bufSize))) {
+                    bos.write(buffer, 0, len1);
+                }
+
+                byte[] var7 = bos.toByteArray();
+                return var7;
+            } finally {
+                try {
+                    if (in != null) {
+                        in.close();
+                    }
+                } catch (IOException var14) {
+                    var14.printStackTrace();
+                }
+
+                bos.close();
+            }
+        }
+    }
+
+
+    /**
+     * 删除
+     *
+     * @param files
+     */
+    private void deleteFile(File... files) {
+        for (File file : files) {
+            if (file.exists()) {
+                file.delete();
+            }
+        }
+    }
+
+    public static void main(String[] args) {
+        String file = "C:\\gitproject\\manHourHousekeeper\\fhKeeper\\formulahousekeeper\\timesheet-workshop-h5\\dist";
+        String target = "D:\\www\\staticproject\\workshop_h5";
+        try {
+            FileUtils.copyDirectory(new File(file), new File(target));
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+}

+ 150 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/util/ZipUtil.java

@@ -0,0 +1,150 @@
+package com.management.platform.util;
+
+import com.alibaba.excel.util.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.*;
+import java.util.Enumeration;
+import java.util.zip.*;
+
+/**
+ * @Description 压缩与解压工具
+ * @Author      yanghanwei
+ * @Date        18:42 2019-11-20
+ * @Version     v1
+ **/
+public class ZipUtils {
+
+    private static final Logger logger = LoggerFactory.getLogger(ZipUtils.class);
+
+    /**
+     * 压缩 zip
+     * @param filePath  文件夹 全路径
+     * @param fileName  文件夹名称
+     * @param outPath   压缩文件保存路径
+     */
+    public static void zipFile(String filePath, String fileName, String outPath) {
+        logger.info("filePath:{}, fileName:{}, outPath:{}", filePath, fileName, outPath);
+        try {
+            //创建Test.zip文件
+            OutputStream is = new FileOutputStream(outPath);
+            //检查输出流,采用CRC32算法,保证文件的一致性
+            CheckedOutputStream cos = new CheckedOutputStream(is, new CRC32());
+            //创建zip文件的输出流
+            ZipOutputStream zos = new ZipOutputStream(cos);
+            //需要压缩的文件或文件夹对象
+            File file = new File(filePath);
+            //压缩文件的具体实现函数
+            zipFilePost(zos,file,filePath,fileName,outPath);
+            zos.close();
+            cos.close();
+            is.close();
+            System.out.println("压缩完成");
+        } catch (Exception e) {
+            logger.error("压缩失败zipFile,Exception:" + e);
+        }
+    }
+
+    /**
+     * 压缩文件
+     * @param zos       zip文件的输出流
+     * @param file      需要压缩的文件或文件夹对象
+     * @param filePath  压缩的文件路径
+     * @param fileName  需要压缩的文件夹名
+     * @param outPath   缩完成后保存为Test.zip文件
+     */
+    private static void zipFilePost(ZipOutputStream zos, File file, String filePath, String fileName, String outPath){
+
+        try{
+            String path = file.getPath();
+            String zosName = "";
+            if(!StringUtils.isEmpty(path)){
+                zosName = path.substring(path.indexOf(fileName));
+            }
+            File[] files = file.listFiles();
+            if(file.isDirectory() && files != null && files.length > 0) {
+                // 创建压缩文件的目录结构
+                zos.putNextEntry(new ZipEntry(zosName + File.separator));
+                for(File f : files) {
+                    zipFilePost(zos, f, filePath, fileName, outPath);
+                }
+            } else {
+                logger.info("正在压缩文件:{}",file.getName());
+                // 创建压缩文件
+                zos.putNextEntry(new ZipEntry(zosName));
+                // 用字节方式读取源文件
+                InputStream is = new FileInputStream(file.getPath());
+                // 创建一个缓存区
+                BufferedInputStream bis = new BufferedInputStream(is);
+                // 字节数组,每次读取1024个字节
+                byte [] b = new byte[1024];
+                // 循环读取,边读边写
+                while(bis.read(b)!=-1) {
+                    // 写入压缩文件
+                    zos.write(b);
+                }
+                //关闭流
+                bis.close();
+                is.close();
+            }
+        } catch (Exception e) {
+            logger.error("压缩文件失败zipFilePost,Exception:" + e);
+        }
+    }
+
+    public static void unzip(String sourcePath, String targetPath) {
+        //targetPath输出文件路径
+        File targetFile = new File(targetPath);
+        // 如果目录不存在,则创建
+        if (!targetFile.exists()) {
+            targetFile.mkdirs();
+        }
+        //sourcePath压缩包文件路径
+        try (ZipFile zipFile = new ZipFile(new File(sourcePath))) {
+            System.out.println("file nums:" + zipFile.size());
+            Enumeration enumeration = zipFile.entries();
+            while (enumeration.hasMoreElements()) {
+                //依次获取压缩包内的文件实体对象
+                ZipEntry entry = (ZipEntry) enumeration.nextElement();
+                String name = entry.getName();
+                if (entry.isDirectory()) {
+                    continue;
+                }
+                try (BufferedInputStream inputStream = new BufferedInputStream(zipFile.getInputStream(entry))) {
+                    // 需要判断文件所在的目录是否存在,处理压缩包里面有文件夹的情况
+                    String outName = targetPath + "/" + name;
+                    File outFile = new File(outName);
+                    File tempFile = new File(outName.substring(0, outName.lastIndexOf("/")));
+                    if (!tempFile.exists()) {
+                        tempFile.mkdirs();
+                    }
+                    try (BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outFile))) {
+                        int len;
+                        byte[] buffer = new byte[1024];
+                        while ((len = inputStream.read(buffer)) > 0) {
+                            outputStream.write(buffer, 0, len);
+                        }
+                    }
+
+                }
+
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+    public static void main(String[] args) throws Exception{
+//        String filePath = "/var/folders/88/jh37h0fj59l1f302jdryz4780000gn/T/201908月小微平台消耗-1574300435525/";
+//        // 需要压缩的文件夹名
+//        String fileName = "201908月小微平台消耗-1574300435525";
+//        // 压缩完成后保存为Test.zip文件,名字随意
+//        String outPath = "/var/folders/88/jh37h0fj59l1f302jdryz4780000gn/T/Test3.zip";
+//        zipFile(filePath, fileName, outPath);
+
+        String sourcePath = "C:\\gitproject\\manHourHousekeeper\\fhKeeper\\formulahousekeeper\\timesheet-workshop\\distPC.zip";
+        String targetPath = "C:\\文档资料\\distPC";
+        unzip(sourcePath, targetPath);
+    }
+}

+ 150 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/util/ZipUtils.java

@@ -0,0 +1,150 @@
+package com.management.platform.util;
+
+import com.alibaba.excel.util.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.*;
+import java.util.Enumeration;
+import java.util.zip.*;
+
+/**
+ * @Description 压缩与解压工具
+ * @Author      yanghanwei
+ * @Date        18:42 2019-11-20
+ * @Version     v1
+ **/
+public class ZipUtils {
+
+    private static final Logger logger = LoggerFactory.getLogger(ZipUtils.class);
+
+    /**
+     * 压缩 zip
+     * @param filePath  文件夹 全路径
+     * @param fileName  文件夹名称
+     * @param outPath   压缩文件保存路径
+     */
+    public static void zipFile(String filePath, String fileName, String outPath) {
+        logger.info("filePath:{}, fileName:{}, outPath:{}", filePath, fileName, outPath);
+        try {
+            //创建Test.zip文件
+            OutputStream is = new FileOutputStream(outPath);
+            //检查输出流,采用CRC32算法,保证文件的一致性
+            CheckedOutputStream cos = new CheckedOutputStream(is, new CRC32());
+            //创建zip文件的输出流
+            ZipOutputStream zos = new ZipOutputStream(cos);
+            //需要压缩的文件或文件夹对象
+            File file = new File(filePath);
+            //压缩文件的具体实现函数
+            zipFilePost(zos,file,filePath,fileName,outPath);
+            zos.close();
+            cos.close();
+            is.close();
+            System.out.println("压缩完成");
+        } catch (Exception e) {
+            logger.error("压缩失败zipFile,Exception:" + e);
+        }
+    }
+
+    /**
+     * 压缩文件
+     * @param zos       zip文件的输出流
+     * @param file      需要压缩的文件或文件夹对象
+     * @param filePath  压缩的文件路径
+     * @param fileName  需要压缩的文件夹名
+     * @param outPath   缩完成后保存为Test.zip文件
+     */
+    private static void zipFilePost(ZipOutputStream zos, File file, String filePath, String fileName, String outPath){
+
+        try{
+            String path = file.getPath();
+            String zosName = "";
+            if(!StringUtils.isEmpty(path)){
+                zosName = path.substring(path.indexOf(fileName));
+            }
+            File[] files = file.listFiles();
+            if(file.isDirectory() && files != null && files.length > 0) {
+                // 创建压缩文件的目录结构
+                zos.putNextEntry(new ZipEntry(zosName + File.separator));
+                for(File f : files) {
+                    zipFilePost(zos, f, filePath, fileName, outPath);
+                }
+            } else {
+                logger.info("正在压缩文件:{}",file.getName());
+                // 创建压缩文件
+                zos.putNextEntry(new ZipEntry(zosName));
+                // 用字节方式读取源文件
+                InputStream is = new FileInputStream(file.getPath());
+                // 创建一个缓存区
+                BufferedInputStream bis = new BufferedInputStream(is);
+                // 字节数组,每次读取1024个字节
+                byte [] b = new byte[1024];
+                // 循环读取,边读边写
+                while(bis.read(b)!=-1) {
+                    // 写入压缩文件
+                    zos.write(b);
+                }
+                //关闭流
+                bis.close();
+                is.close();
+            }
+        } catch (Exception e) {
+            logger.error("压缩文件失败zipFilePost,Exception:" + e);
+        }
+    }
+
+    public static void unzip(String sourcePath, String targetPath) {
+        //targetPath输出文件路径
+        File targetFile = new File(targetPath);
+        // 如果目录不存在,则创建
+        if (!targetFile.exists()) {
+            targetFile.mkdirs();
+        }
+        //sourcePath压缩包文件路径
+        try (ZipFile zipFile = new ZipFile(new File(sourcePath))) {
+            System.out.println("file nums:" + zipFile.size());
+            Enumeration enumeration = zipFile.entries();
+            while (enumeration.hasMoreElements()) {
+                //依次获取压缩包内的文件实体对象
+                ZipEntry entry = (ZipEntry) enumeration.nextElement();
+                String name = entry.getName();
+                if (entry.isDirectory()) {
+                    continue;
+                }
+                try (BufferedInputStream inputStream = new BufferedInputStream(zipFile.getInputStream(entry))) {
+                    // 需要判断文件所在的目录是否存在,处理压缩包里面有文件夹的情况
+                    String outName = targetPath + "/" + name;
+                    File outFile = new File(outName);
+                    File tempFile = new File(outName.substring(0, outName.lastIndexOf("/")));
+                    if (!tempFile.exists()) {
+                        tempFile.mkdirs();
+                    }
+                    try (BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outFile))) {
+                        int len;
+                        byte[] buffer = new byte[1024];
+                        while ((len = inputStream.read(buffer)) > 0) {
+                            outputStream.write(buffer, 0, len);
+                        }
+                    }
+
+                }
+
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+    public static void main(String[] args) throws Exception{
+//        String filePath = "/var/folders/88/jh37h0fj59l1f302jdryz4780000gn/T/201908月小微平台消耗-1574300435525/";
+//        // 需要压缩的文件夹名
+//        String fileName = "201908月小微平台消耗-1574300435525";
+//        // 压缩完成后保存为Test.zip文件,名字随意
+//        String outPath = "/var/folders/88/jh37h0fj59l1f302jdryz4780000gn/T/Test3.zip";
+//        zipFile(filePath, fileName, outPath);
+
+        String sourcePath = "C:\\gitproject\\manHourHousekeeper\\fhKeeper\\formulahousekeeper\\timesheet-workshop\\distPC.zip";
+        String targetPath = "C:\\文档资料\\distPC";
+        unzip(sourcePath, targetPath);
+    }
+}

+ 5 - 3
fhKeeper/formulahousekeeper/timesheet-workshop-h5/src/views/workView/fillReport.vue

@@ -37,13 +37,13 @@
               <van-stepper v-model="reportForm.finishNum" step="0.1" :min="0" :max="reportForm.num" :decimal-length="2" @change="onFinishNumChange"/>
               <van-stepper v-model="reportForm.finishNum" step="0.1" :min="0" :max="reportForm.num" :decimal-length="2" @change="onFinishNumChange"/>
             </template>
             </template>
           </van-cell>
           </van-cell>
-          <van-cell title="完成全部工作" >
+          <!-- <van-cell title="完成全部工作" >
             <template>
             <template>
               <div style="float:right;">
               <div style="float:right;">
                 <van-checkbox v-model="reportForm.isFinish" />
                 <van-checkbox v-model="reportForm.isFinish" />
               </div>
               </div>
             </template>
             </template>
-          </van-cell>
+          </van-cell> -->
           <van-cell title="中止工作" v-if="!reportForm.isFinish">
           <van-cell title="中止工作" v-if="!reportForm.isFinish">
             <template>
             <template>
               <div style="float:right;">
               <div style="float:right;">
@@ -156,7 +156,9 @@ export default {
       //件数发生改变时,检测如果和计划总件数一样,则算完成
       //件数发生改变时,检测如果和计划总件数一样,则算完成
       if (this.reportForm.finishNum == this.reportForm.num) {
       if (this.reportForm.finishNum == this.reportForm.num) {
           this.$set(this.reportForm, 'isFinish',true);
           this.$set(this.reportForm, 'isFinish',true);
-      } 
+      } else {
+         this.$set(this.reportForm, 'isFinish',false);
+      }
     },
     },
     back() {
     back() {
       this.$router.go(-1);
       this.$router.go(-1);