Browse Source

Merge remote-tracking branch 'origin/master'

hym 4 years ago
parent
commit
fcf4f94a2e

+ 161 - 0
operation_manager/src/main/java/com/huaxu/common/FileUploadUtil.java

@@ -0,0 +1,161 @@
+package com.huaxu.common;
+
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.lang.time.DateFormatUtils;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Date;
+
+/**
+ * @author wyy
+ * @date 2020-10-23 09:54
+ */
+public class FileUploadUtil {
+
+    /**
+     * 默认大小 50M
+     */
+    public static final long DEFAULT_MAX_SIZE = 50 * 1024 * 1024;
+    /**
+     * 默认的文件名最大长度 100
+     */
+    public static final int DEFAULT_FILE_NAME_LENGTH = 100;
+    /**
+     * 默认上传的地址
+     */
+    private static String defaultBaseDir = "/";
+    private static int counter = 0;
+
+    /**
+     * 根据文件路径上传
+     *
+     * @param baseDir 相对应用的基目录
+     * @param file    上传的文件
+     * @return 文件名称
+     * @throws IOException
+     */
+    public static final String uploadWeb(String baseDir, MultipartFile file) throws IOException {
+        try {
+            return upload(baseDir, file, MimeType.DEFAULT_ALLOWED_EXTENSION);
+        } catch (Exception e) {
+            throw new IOException(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * 获取文件名的后缀
+     *
+     * @param file 表单文件
+     * @return 后缀名
+     */
+    public static final String getExtension(MultipartFile file) {
+        String extension = FilenameUtils.getExtension(file.getOriginalFilename());
+        if (ToolUtil.isEmpty(extension)) {
+            extension = MimeType.getExtension(file.getContentType());
+        }
+        return extension;
+    }
+
+    /**
+     * 判断MIME类型是否是允许的MIME类型
+     *
+     * @param extension
+     * @param allowedExtension
+     * @return
+     */
+    public static final boolean isAllowedExtension(String extension, String[] allowedExtension) {
+        for (String str : allowedExtension) {
+            if (str.equalsIgnoreCase(extension)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * 文件大小校验
+     *
+     * @param file 上传的文件
+     * @return
+     * @throws InvalidExtensionException
+     */
+    public static final void assertAllowed(MultipartFile file, String[] allowedExtension)
+            throws InvalidExtensionException {
+        long size = file.getSize();
+        if (DEFAULT_MAX_SIZE != -1 && size > DEFAULT_MAX_SIZE) {
+            throw new RxcException("10004", "文件太大");
+        }
+
+        String fileName = file.getOriginalFilename();
+        String extension = getExtension(file);
+        if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension)) {
+            if (allowedExtension == MimeType.IMAGE_EXTENSION) {
+                throw new InvalidExtensionException.InvalidImageExtensionException(allowedExtension, extension,
+                        fileName);
+            } else if (allowedExtension == MimeType.FLASH_EXTENSION) {
+                throw new InvalidExtensionException.InvalidFlashExtensionException(allowedExtension, extension,
+                        fileName);
+            } else if (allowedExtension == MimeType.MEDIA_EXTENSION) {
+                throw new InvalidExtensionException.InvalidMediaExtensionException(allowedExtension, extension,
+                        fileName);
+            } else {
+                throw new InvalidExtensionException(allowedExtension, extension, fileName);
+            }
+        }
+    }
+
+    /**
+     * 编码文件名
+     */
+    public static final String extractFilename(MultipartFile file) {
+        String fileName = file.getOriginalFilename();
+        String extension = getExtension(file);
+        fileName = DateFormatUtils.format(new Date(), "yyyy/MM/dd") + File.separator + ToolUtil.encodingFilename(fileName) + "." + extension;
+        return fileName;
+    }
+
+    private static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException {
+        File desc = new File(uploadDir + File.separator + fileName);
+
+        if (!desc.getParentFile().exists()) {
+            desc.getParentFile().mkdirs();
+        }
+        if (!desc.exists()) {
+            desc.createNewFile();
+        }
+        return desc;
+    }
+
+    private static final String getPathFileName(String uploadDir, String fileName) throws IOException {
+       // int dirLastIndex = uploadDir.lastIndexOf("/") + 1;
+        //String currentDir = StringUtils.substring(uploadDir, dirLastIndex);
+        String pathFileName = uploadDir  + "/" + fileName;
+        return ToolUtil.path(pathFileName);
+    }
+
+    /**
+     * 文件上传
+     *
+     * @param baseDir 相对应用的基目录
+     * @param file    上传的文件
+     * @return 返回上传成功的文件名
+     * @throws IOException 比如读写文件出错时
+     */
+    public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension) throws RxcException, IOException, InvalidExtensionException {
+        int fileNamelength = file.getOriginalFilename().length();
+        if (fileNamelength > FileUploadUtil.DEFAULT_FILE_NAME_LENGTH) {
+            throw new RxcException("10004", "文件太大");
+        }
+
+        assertAllowed(file, allowedExtension);
+
+        String fileName = extractFilename(file);
+
+        File desc = getAbsoluteFile(baseDir, fileName);
+        file.transferTo(desc);
+        String pathFileName = getPathFileName(baseDir, fileName);
+        return pathFileName;
+    }
+}

+ 63 - 0
operation_manager/src/main/java/com/huaxu/common/InvalidExtensionException.java

@@ -0,0 +1,63 @@
+package com.huaxu.common;
+
+
+
+import org.apache.tomcat.util.http.fileupload.FileUploadException;
+
+import java.util.Arrays;
+
+/**
+ * 文件上传 误异常类
+ * 
+ * @author WYY
+ */
+public class InvalidExtensionException extends FileUploadException {
+    private static final long serialVersionUID = 1L;
+
+    private String[] allowedExtension;
+    private String extension;
+    private String filename;
+
+    public InvalidExtensionException(String[] allowedExtension, String extension, String filename) {
+        super("filename : [" + filename + "], extension : [" + extension + "], allowed extension : [" + Arrays.toString(allowedExtension) + "]");
+        this.allowedExtension = allowedExtension;
+        this.extension = extension;
+        this.filename = filename;
+    }
+
+    public String[] getAllowedExtension() {
+        return allowedExtension;
+    }
+
+    public String getExtension() {
+        return extension;
+    }
+
+    public String getFilename() {
+        return filename;
+    }
+
+    public static class InvalidImageExtensionException extends InvalidExtensionException {
+        private static final long serialVersionUID = 1L;
+
+        public InvalidImageExtensionException(String[] allowedExtension, String extension, String filename) {
+            super(allowedExtension, extension, filename);
+        }
+    }
+
+    public static class InvalidFlashExtensionException extends InvalidExtensionException {
+        private static final long serialVersionUID = 1L;
+
+        public InvalidFlashExtensionException(String[] allowedExtension, String extension, String filename) {
+            super(allowedExtension, extension, filename);
+        }
+    }
+
+    public static class InvalidMediaExtensionException extends InvalidExtensionException {
+        private static final long serialVersionUID = 1L;
+
+        public InvalidMediaExtensionException(String[] allowedExtension, String extension, String filename) {
+            super(allowedExtension, extension, filename);
+        }
+    }
+}

+ 45 - 0
operation_manager/src/main/java/com/huaxu/common/Md5Util.java

@@ -0,0 +1,45 @@
+package com.huaxu.common;
+
+import java.security.MessageDigest;
+
+
+public class Md5Util {
+    private static byte[] md5(String s){
+        MessageDigest algorithm;
+        try{
+            algorithm = MessageDigest.getInstance("MD5");
+            algorithm.reset();
+            algorithm.update(s.getBytes("UTF-8"));
+            byte[] messageDigest = algorithm.digest();
+            return messageDigest;
+        }
+        catch (Exception e){
+        }
+        return null;
+    }
+
+    private static final String toHex(byte hash[]){
+        if (hash == null){
+            return null;
+        }
+        StringBuffer buf = new StringBuffer(hash.length * 2);
+        int i;
+
+        for (i = 0; i < hash.length; i++){
+            if ((hash[i] & 0xff) < 0x10){
+                buf.append("0");
+            }
+            buf.append(Long.toString(hash[i] & 0xff, 16));
+        }
+        return buf.toString();
+    }
+
+    public static String hash(String s){
+        try{
+            return new String(toHex(md5(s)).getBytes("UTF-8"), "UTF-8");
+        }
+        catch (Exception e){
+            return s;
+        }
+    }
+}

+ 42 - 0
operation_manager/src/main/java/com/huaxu/common/MimeType.java

@@ -0,0 +1,42 @@
+package com.huaxu.common;
+
+public class MimeType {
+    public static final String IMAGE_PNG = "image/png";
+    public static final String IMAGE_JPG = "image/jpg";
+    public static final String IMAGE_JPEG = "image/jpeg";
+    public static final String IMAGE_BMP = "image/bmp";
+    public static final String IMAGE_GIF = "image/gif";
+    public static final String[] IMAGE_EXTENSION = {"bmp", "gif", "jpg", "jpeg", "png"};
+    public static final String[] FLASH_EXTENSION = {"swf", "flv"};
+    public static final String[] MEDIA_EXTENSION = {"swf", "flv", "mp3", "wav", "wma", "wmv",
+            "mid", "avi", "mpg", "asf", "rm", "rmvb"};
+
+    public static final String[] DEFAULT_ALLOWED_EXTENSION = {
+            // 图片
+            "bmp", "gif", "jpg", "jpeg", "png",
+            // word excel powerpoint
+            "doc", "docx", "xls", "xlsx", "ppt", "pptx", "html", "htm", "txt",
+            // 压缩文件
+            "rar", "zip", "gz", "bz2",
+            //许可证书
+            "lic",
+            // pdf
+            "pdf"};
+
+    public static String getExtension(String urlPrefix) {
+        switch (urlPrefix) {
+            case IMAGE_PNG:
+                return "png";
+            case IMAGE_JPG:
+                return "jpg";
+            case IMAGE_JPEG:
+                return "jpeg";
+            case IMAGE_BMP:
+                return "bmp";
+            case IMAGE_GIF:
+                return "gif";
+            default:
+                return "";
+        }
+    }
+}

+ 95 - 0
operation_manager/src/main/java/com/huaxu/common/ResourceUtil.java

@@ -0,0 +1,95 @@
+package com.huaxu.common;
+
+import org.apache.commons.io.IOUtils;
+import org.springframework.core.io.DefaultResourceLoader;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.core.io.support.ResourcePatternResolver;
+import org.springframework.util.ResourceUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * <p>资源供给</p>
+ *
+ * @author: WYY
+ * @date: 2019-03-26 17:57
+ * @version: 1.0.1
+ */
+public class ResourceUtil extends ResourceUtils {
+
+    private static ResourceLoader resourceLoader;
+    private static ResourcePatternResolver resourceResolver;
+
+    static {
+        resourceLoader = new DefaultResourceLoader();
+        resourceResolver = new PathMatchingResourcePatternResolver(resourceLoader);
+    }
+
+    /**
+     * 获取资源加载器(可读取jar内的文件)
+     *
+     * @author WYY
+     */
+    public static ResourceLoader getResourceLoader() {
+        return resourceLoader;
+    }
+
+    /**
+     * 获取ClassLoader
+     */
+    public static ClassLoader getClassLoader() {
+        return resourceLoader.getClassLoader();
+    }
+
+    /**
+     * 获取资源加载器(可读取jar内的文件)
+     */
+    public static Resource getResource(String location) {
+        return resourceLoader.getResource(location);
+    }
+
+    /**
+     * 获取资源文件流(用后记得关闭)
+     *
+     * @param location
+     * @throws IOException
+     * @author WYY
+     */
+    public static InputStream getResourceFileStream(String location) throws IOException {
+        Resource resource = resourceLoader.getResource(location);
+        return resource.getInputStream();
+    }
+
+    /**
+     * 获取资源文件内容
+     *
+     * @param location
+     * @author WYY
+     */
+    public static String getResourceFileContent(String location) {
+        try (InputStream is = getResourceFileStream(location)) {
+            return IOUtils.toString(is, "UTF-8");
+        } catch (IOException e) {
+            return "";
+        }
+    }
+
+    /**
+     * Spring 搜索资源文件
+     *
+     * @param locationPattern
+     * @author WYY
+     */
+    public static Resource[] getResources(String locationPattern) {
+        try {
+            Resource[] resources = resourceResolver.getResources(locationPattern);
+            return resources;
+        } catch (IOException e) {
+            return null;
+        }
+    }
+
+}

+ 48 - 0
operation_manager/src/main/java/com/huaxu/common/RxcException.java

@@ -0,0 +1,48 @@
+package com.huaxu.common;
+
+import lombok.Data;
+
+/**
+ * 自定义异常处理
+ * @author wyy
+ * @date 2020-03-12 15:42
+ */
+@Data
+public class RxcException extends RuntimeException {
+
+	private static final long serialVersionUID = 1L;
+	private String msg;
+	private String code = "50000";
+	private String subCode;
+	private String subMsg;
+
+	public RxcException(String msg) {
+		super(msg);
+		this.msg = msg;
+	}
+
+	public RxcException(String code, String msg, String subCode, String subMsg) {
+		super(msg);
+		this.msg = msg;
+		this.code = code;
+		this.subCode = subCode;
+		this.subMsg = subMsg;
+	}
+
+	public RxcException(String msg, Throwable e) {
+		super(msg, e);
+		this.msg = msg;
+	}
+
+	public RxcException(String msg, String code) {
+		super(msg);
+		this.msg = msg;
+		this.code = code;
+	}
+
+	public RxcException(String msg, String code, Throwable e) {
+		super(msg, e);
+		this.msg = msg;
+		this.code = code;
+	}
+}

+ 354 - 0
operation_manager/src/main/java/com/huaxu/common/ToolUtil.java

@@ -0,0 +1,354 @@
+package com.huaxu.common;
+
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.NumberUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.extra.spring.SpringUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.context.MessageSource;
+import org.springframework.context.i18n.LocaleContextHolder;
+
+import java.io.*;
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * 高频使用工具类
+ * @author wyy
+ * @date 2020-03-11 15:02
+ */
+public class ToolUtil {
+
+	private static int 							counter 							= 0;
+
+	
+	/**
+     * 获取随机字符,自定义长度
+     *
+     * @author wyy
+     * 2020-03-11 15:07
+     */
+    public static String getRandomString(int length) {
+        String base = "abcdefghijklmnopqrstuvwxyz0123456789";
+        Random random = new Random();
+        StringBuffer sb = new StringBuffer();
+        for (int i = 0; i < length; i++) {
+            int number = random.nextInt(base.length());
+            sb.append(base.charAt(number));
+        }
+        return sb.toString();
+    }
+	
+	/**
+	 * 判断对象是否为空  true 不为空
+	 * @author wyy
+	 * @date 2020-03-11 15:07
+	 */
+    public static boolean isNotEmpty(Object o) {
+        return !isEmpty(o);
+    }
+
+    /**
+     * 
+     * 对象是否为空 true 为空
+     * @author wyy
+     * @date 2020-03-11 15:09
+     */
+    public static boolean isEmpty(Object o) {
+        if (o == null) {
+            return true;
+        }
+        if (o instanceof String) {
+            if ("".equals(o.toString().trim())) {
+                return true;
+            }
+        } else if (o instanceof List) {
+            if (((List<?>) o).size() == 0) {
+                return true;
+            }
+        } else if (o instanceof Map) {
+            if (((Map<?, ?>) o).size() == 0) {
+                return true;
+            }
+        } else if (o instanceof Set) {
+            if (((Set<?>) o).size() == 0) {
+                return true;
+            }
+        } else if (o instanceof Object[]) {
+            if (((Object[]) o).length == 0) {
+                return true;
+            }
+        } else if (o instanceof int[]) {
+            if (((int[]) o).length == 0) {
+                return true;
+            }
+        } else if (o instanceof long[]) {
+            if (((long[]) o).length == 0) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * 对象组中是否存在空对象
+     *
+     * @author wyy
+     * @Date 2020-03-11 15:09
+     */
+    public static boolean isOneEmpty(Object... os) {
+        for (Object o : os) {
+            if (isEmpty(o)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * 对象组中是否全是空对象
+     *
+     * @author wyy
+     * @date 2020-03-11 15:09
+     */
+    public static boolean isAllEmpty(Object... os) {
+        for (Object o : os) {
+            if (!isEmpty(o)) {
+                return false;
+            }
+        }
+        return true;
+    }
+    
+    /**
+     * 根据消息键和参数 获取消息 委托给Spring messageSource
+     * 
+     * @param code 消息键
+     * @param args 参数
+     * @return 获取国际化翻译值
+     */
+    public static String message(String code, Object... args){
+        MessageSource messageSource = SpringUtil.getBean(MessageSource.class);
+        try{
+			return messageSource.getMessage(code, args, LocaleContextHolder.getLocale());
+		}catch (Exception e){
+        	return code;
+		}
+    }
+    
+    /**
+	 * 
+	 * 字节计算转换
+	 * 
+	 * <pre>
+	 * StrUtil.convertFileSize(1024)   			= 1kB
+	 * </pre>
+	 * @author wyy
+	 * @time 2019-04-03 12:29
+	 * @param size 字节大小
+	 * @return 转换后大小字符串
+	 *
+	 */
+	public static String convertFileSize(long size) {
+		long kb = 1024;
+        long mb = kb * 1024;
+        long gb = mb * 1024;
+        if (size >= gb)
+        {
+            return StrUtil.format("{} GB", NumberUtil.round((float) size / gb,2));
+        }
+        else if (size >= mb)
+        {
+            float f = NumberUtil.round((float) size / mb,2).floatValue();
+            return StrUtil.format(f > 100 ? "{} MB" : "{} MB", f);
+        }
+        else if (size >= kb)
+        {
+            float f = NumberUtil.round((float) size / kb,2).floatValue();
+            return StrUtil.format(f > 100 ? "{}  KB" : "{}  KB", f);
+        }
+        else
+        {
+            return StrUtil.format("{} B", size);
+        }
+	}
+	
+	public static String getMessage(Exception e){
+		StringWriter sw = null;
+		PrintWriter pw = null;
+		try {
+			sw = new StringWriter();
+			pw = new PrintWriter(sw);
+			e.printStackTrace(pw);
+			pw.flush();
+			sw.flush();
+		} finally {
+			if (sw != null) {
+				try {
+					sw.close();
+				} catch (IOException e1) {
+					e1.printStackTrace();
+				}
+			}
+			if (pw != null) {
+				pw.close();
+			}
+		}
+		return sw.toString();
+	}
+
+	public static boolean isBoolIp(String ipAddress) {
+		String ip = "([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}";
+		Pattern pattern = Pattern.compile(ip);
+		Matcher matcher = pattern.matcher(ipAddress);
+		return matcher.matches();
+	}
+
+
+	public static String createFolder(String folder){
+		folder += File.separator + DateUtil.format(new Date(),"yyyy") + File.separator + DateUtil.format(new Date(),"MM") +
+				File.separator + DateUtil.format(new Date(),"dd")+ File.separator;
+		FileUtil.mkdir(folder);
+		return folder;
+	}
+
+
+	/**
+	 * 编码文件名
+	 */
+	public static String encodingFilename(String fileName) {
+		fileName = fileName.replace("_", " ");
+		fileName = Md5Util.hash(fileName + System.nanoTime() + counter++);
+		return fileName;
+	}
+
+	public static String encodingExcelFilename(String filename){
+		filename = UUID.randomUUID().toString() + "_" + filename + ".xlsx";
+		return filename;
+	}
+
+    /**
+     * 修正路径,将 \\ 或 / 等替换为 File.separator
+     * @param path 待修正的路径
+     * @return 修正后的路径
+     */
+    public static String path(String path) {
+        String p = StringUtils.replace(path, "\\", "/");
+        p = StringUtils.join(StringUtils.split(p, "/"), "/");
+        if (!StringUtils.startsWithAny(p, "/") && StringUtils.startsWithAny(path, "\\", "/")) {
+            p += "/";
+        }
+        if (!StringUtils.endsWithAny(p, "/") && StringUtils.endsWithAny(path, "\\", "/")) {
+            p = p + "/";
+        }
+        if (path != null && path.startsWith("/")) {
+            p = "/" + p; // linux下路径
+        }
+        if (StringUtils.endsWithAny(p, "/")) {
+            p = p.substring(0, p.length() - 1);
+        }
+        return p;
+    }
+
+    /**
+     * 获取工程源文件所在路径
+     * @return
+     */
+    public static String getProjectPath(){
+        String projectPath = "";
+        try {
+            File file = ResourceUtil.getResource("").getFile();
+            if (file != null){
+                while(true){
+                    File f = new File(path(file.getPath() + "/src/main"));
+                    if (f.exists()){
+                        break;
+                    }
+                    f = new File(path(file.getPath() + "/target/classes"));
+                    if (f.exists()){
+                        break;
+                    }
+                    if (file.getParentFile() != null){
+                        file = file.getParentFile();
+                    }else{
+                        break;
+                    }
+                }
+                projectPath = file.toString();
+            }
+        } catch (FileNotFoundException e) {
+            // 忽略异常
+        } catch (IOException e) {
+            // 忽略异常
+        }
+        // 取不到,取当前工作路径
+        if (StringUtils.isBlank(projectPath)){
+            projectPath = System.getProperty("user.dir");
+        }
+        return projectPath;
+    }
+
+    /**
+     * 获取工程源文件所在路径
+     * @return
+     */
+    public static String getWebappPath(){
+        String webappPath = "";
+        try {
+            File file = ResourceUtil.getResource("").getFile();
+            if (file != null){
+                while(true){
+                    File f = new File(path(file.getPath() + "/WEB-INF/classes"));
+                    if (f.exists()){
+                        break;
+                    }
+                    f = new File(path(file.getPath() + "/src/main/webapp"));
+                    if (f.exists()){
+                        return f.getPath();
+                    }
+                    if (file.getParentFile() != null){
+                        file = file.getParentFile();
+                    }else{
+                        break;
+                    }
+                }
+                webappPath = file.toString();
+            }
+        } catch (FileNotFoundException e) {
+            // 忽略异常
+        } catch (IOException e) {
+            // 忽略异常
+        }
+        // 取不到,取当前工作路径
+        if (StringUtils.isBlank(webappPath)){
+            webappPath = System.getProperty("user.dir");
+        }
+        return webappPath;
+    }
+
+	/**
+	 * 数组以某种分隔符拼装
+	 * @param value Long数值
+	 * @param s 分隔符
+	 * @return 拼装之后的字符串
+	 */
+    public static String conversion(Object value, String s){
+    	String src = "";
+    	if(value instanceof  Long[]){
+    	    Long[] a = (Long[]) value;
+            for(Long l: a){
+                src += l+s;
+            }
+        }
+    	if(value instanceof List){
+            List<String> a = (List) value;
+            for(int i=0; i< a.size(); i++){
+                src += a.get(i)+s;
+            }
+        }
+		return  src.substring(0,src.length()-s.length());
+	}
+
+}

+ 39 - 0
operation_manager/src/main/java/com/huaxu/order/controller/WorkOrderManageController.java

@@ -1,6 +1,7 @@
 package com.huaxu.order.controller;
 
 import com.huaxu.client.UserCenterClient;
+import com.huaxu.common.FileUploadUtil;
 import com.huaxu.model.AjaxMessage;
 import com.huaxu.model.LoginUser;
 import com.huaxu.model.ResultStatus;
@@ -23,8 +24,11 @@ import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
 import java.util.*;
 
 @RestController
@@ -50,6 +54,12 @@ public class WorkOrderManageController {
     @Autowired
     UserCenterClient userCenterClient;
 
+    @Value("${UMIS.sys_config_path}")
+    private String baseDir;
+
+    @Value("${UMIS.sys_video_path}")
+    private String videoDir;
+
     /**
      * 新增一条数据
      *
@@ -248,4 +258,33 @@ public class WorkOrderManageController {
         }
         return new AjaxMessage<>(ResultStatus.OK);
     }
+
+    @ApiOperation(value = "上传图片")
+    @RequestMapping(value = "addImage", method = RequestMethod.POST)
+    @ResponseBody
+    public AjaxMessage<String> addImage(@ApiParam(value = "图片", required = true) @RequestParam("avatarfile") MultipartFile file) {
+        String avatar = "";
+        if (!file.isEmpty()) {
+            try {
+                avatar = FileUploadUtil.uploadWeb(baseDir, file);
+            } catch (IOException e) {
+                return new AjaxMessage<>(ResultStatus.ERROR, e.getMessage());
+            }
+        }
+        return new AjaxMessage<>(ResultStatus.OK, avatar);
+    }
+    @ApiOperation(value = "上传视频")
+    @RequestMapping(value = "addVideo", method = RequestMethod.POST)
+    @ResponseBody
+    public AjaxMessage<String> addVideo(@ApiParam(value = "视频", required = true) @RequestParam("avatarfile") MultipartFile file) {
+        String avatar = "";
+        if (!file.isEmpty()) {
+            try {
+                avatar = FileUploadUtil.uploadWeb(videoDir, file);
+            } catch (IOException e) {
+                return new AjaxMessage<>(ResultStatus.ERROR, e.getMessage());
+            }
+        }
+        return new AjaxMessage<>(ResultStatus.OK, avatar);
+    }
 }

+ 1 - 0
operation_manager/src/main/resources/application-dev.properties

@@ -83,6 +83,7 @@ dispath.routing.key=dipathKey
 spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
 UMIS.sys_config_path=/UMIS_USER_IMAGES/
 UMIS.sys_excel_path=/UMIS_USER_EXCEL/
+UMIS.sys_video_path=/UMIS_USER_VIDEOS/
 wf.svg.file.path=D:/test/
 
 

+ 1 - 0
operation_manager/src/main/resources/application-sit.properties

@@ -83,6 +83,7 @@ dispath.routing.key=dipathKey
 spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
 UMIS.sys_config_path=/UMIS_USER_IMAGES/
 UMIS.sys_excel_path=/UMIS_USER_EXCEL/
+UMIS.sys_video_path=/UMIS_USER_VIDEOS/
 wf.svg.file.path=D:/test/