浏览代码

Merge branch 'dev' of lyr/patient-co-management into dev

lyr 8 年之前
父节点
当前提交
84a0916832

+ 18 - 248
patient-co-wlyy/pom.xml

@ -470,7 +470,11 @@
            <version>2.8.1</version>
        </dependency>
        <!-- TEST end -->
        <dependency>
            <groupId>org.csource</groupId>
            <artifactId>fastdfs_lib</artifactId>
            <version>1.25</version>
        </dependency>
    </dependencies>
    <dependencyManagement>
@ -503,149 +507,6 @@
                    </compilerArguments>
                </configuration>
            </plugin>
            <!-- war打包插件, 设定war包名称不带版本号 -->
            <!--<plugin>-->
            <!--<groupId>org.apache.maven.plugins</groupId>-->
            <!--<artifactId>maven-war-plugin</artifactId>-->
            <!--<version>2.4</version>-->
            <!--<configuration>-->
            <!--<warName>${project.artifactId}</warName>-->
            <!--</configuration>-->
            <!--</plugin>-->
            <!-- test插件, 仅测试名称为*Test的类,使用支持分组测试的surefire-junit47 driver -->
            <!--<plugin>-->
            <!--<groupId>org.apache.maven.plugins</groupId>-->
            <!--<artifactId>maven-surefire-plugin</artifactId>-->
            <!--<version>2.16</version>-->
            <!--<configuration>-->
            <!--<includes>-->
            <!--<include>**/*Test.java</include>-->
            <!--</includes>-->
            <!--<argLine>-Xmx256M</argLine>-->
            <!--</configuration>-->
            <!--<dependencies>-->
            <!--<dependency>-->
            <!--<groupId>org.apache.maven.surefire</groupId>-->
            <!--<artifactId>surefire-junit47</artifactId>-->
            <!--<version>2.16</version>-->
            <!--</dependency>-->
            <!--</dependencies>-->
            <!--</plugin>-->
            <!-- 增加functional test的Source目录 -->
            <!--<plugin>-->
            <!--<groupId>org.codehaus.mojo</groupId>-->
            <!--<artifactId>build-helper-maven-plugin</artifactId>-->
            <!--<version>1.8</version>-->
            <!--<executions>-->
            <!--<execution>-->
            <!--<id>add-functional-source</id>-->
            <!--<phase>generate-sources</phase>-->
            <!--<goals>-->
            <!--<goal>add-test-source</goal>-->
            <!--</goals>-->
            <!--<configuration>-->
            <!--<sources>-->
            <!--<source>src/test/functional</source>-->
            <!--</sources>-->
            <!--</configuration>-->
            <!--</execution>-->
            <!--</executions>-->
            <!--</plugin>-->
            <!-- cobertura插件, 设置不需要计算覆盖率的类 -->
            <!--<plugin>-->
            <!--<groupId>org.codehaus.mojo</groupId>-->
            <!--<artifactId>cobertura-maven-plugin</artifactId>-->
            <!--<version>2.6</version>-->
            <!--<configuration>-->
            <!--<instrumentation>-->
            <!--<excludes>-->
            <!--<exclude>**/entity/**/*.class</exclude>-->
            <!--<exclude>**/*Controller.class</exclude>-->
            <!--</excludes>-->
            <!--</instrumentation>-->
            <!--</configuration>-->
            <!--</plugin>-->
            <!-- enforcer插件, 避免被依赖的依赖引入过期的jar�? -->
            <!--<plugin>-->
            <!--<groupId>org.apache.maven.plugins</groupId>-->
            <!--<artifactId>maven-enforcer-plugin</artifactId>-->
            <!--<version>1.3.1</version>-->
            <!--<executions>-->
            <!--<execution>-->
            <!--<id>enforce-banned-dependencies</id>-->
            <!--<goals>-->
            <!--<goal>enforce</goal>-->
            <!--</goals>-->
            <!--<configuration>-->
            <!--<rules>-->
            <!--<requireMavenVersion>-->
            <!--<version>3.0.3</version>-->
            <!--</requireMavenVersion>-->
            <!--<requireJavaVersion>-->
            <!--<version>1.6</version>-->
            <!--</requireJavaVersion>-->
            <!--<bannedDependencies>-->
            <!--<searchTransitive>true</searchTransitive>-->
            <!--<excludes>-->
            <!--<exclude>commons-logging</exclude>-->
            <!--<exclude>aspectj:aspectj*</exclude>-->
            <!--<exclude>org.springframework</exclude>-->
            <!--</excludes>-->
            <!--<includes>-->
            <!--<include>org.springframework:*:4.0.*</include>-->
            <!--</includes>-->
            <!--</bannedDependencies>-->
            <!--</rules>-->
            <!--<fail>true</fail>-->
            <!--</configuration>-->
            <!--</execution>-->
            <!--</executions>-->
            <!--</plugin>-->
            <!-- jetty插件, 设定context path与spring profile -->
            <!--<plugin>-->
                <!--<groupId>org.mortbay.jetty</groupId>-->
                <!--<artifactId>jetty-maven-plugin</artifactId>-->
                <!--<version>${jetty.version}</version>-->
                <!--<configuration>-->
                    <!--<systemProperties>-->
                        <!--<systemProperty>-->
                            <!--<name>spring.profiles.active</name>-->
                            <!--<value>development</value>-->
                        <!--</systemProperty>-->
                    <!--</systemProperties>-->
                    <!--<useTestClasspath>true</useTestClasspath>-->
                    <!--<webAppConfig>-->
                        <!--<contextPath>/${project.artifactId}</contextPath>-->
                    <!--</webAppConfig>-->
                <!--</configuration>-->
            <!--</plugin>-->
            <!-- resources插件 -->
            <!--<plugin>-->
            <!--<groupId>org.apache.maven.plugins</groupId>-->
            <!--<artifactId>maven-resources-plugin</artifactId>-->
            <!--<version>2.6</version>-->
            <!--</plugin>-->
            <!--&lt;!&ndash; install插件 &ndash;&gt;-->
            <!--<plugin>-->
            <!--<groupId>org.apache.maven.plugins</groupId>-->
            <!--<artifactId>maven-install-plugin</artifactId>-->
            <!--<version>2.5.1</version>-->
            <!--</plugin>-->
            <!--&lt;!&ndash; ant插件 &ndash;&gt;-->
            <!--<plugin>-->
            <!--<groupId>org.apache.maven.plugins</groupId>-->
            <!--<artifactId>maven-antrun-plugin</artifactId>-->
            <!--<version>1.7</version>-->
            <!--</plugin>-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
@ -664,112 +525,21 @@
                            <file>${basedir}/src/main/resources/kaptcha-2.3.2.jar</file>
                        </configuration>
                    </execution>
                    <execution>
                        <phase>initialize</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <groupId>org.csource</groupId>
                            <artifactId>fastdfs_lib</artifactId>
                            <version>1.25</version>
                            <packaging>jar</packaging>
                            <file>${basedir}/src/main/resources/fastdfs_lib.jar</file>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <!--<pluginManagement>-->
        <!--<plugins>-->
        <!--&lt;!&ndash;This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.&ndash;&gt;-->
        <!--<plugin>-->
        <!--<groupId>org.eclipse.m2e</groupId>-->
        <!--<artifactId>lifecycle-mapping</artifactId>-->
        <!--<version>1.0.0</version>-->
        <!--<configuration>-->
        <!--<lifecycleMappingMetadata>-->
        <!--<pluginExecutions>-->
        <!--<pluginExecution>-->
        <!--<pluginExecutionFilter>-->
        <!--<groupId>-->
        <!--org.codehaus.mojo-->
        <!--</groupId>-->
        <!--<artifactId>-->
        <!--build-helper-maven-plugin-->
        <!--</artifactId>-->
        <!--<versionRange>-->
        <!--[1.8,)-->
        <!--</versionRange>-->
        <!--<goals>-->
        <!--<goal>add-test-source</goal>-->
        <!--</goals>-->
        <!--</pluginExecutionFilter>-->
        <!--<action>-->
        <!--<ignore></ignore>-->
        <!--</action>-->
        <!--</pluginExecution>-->
        <!--</pluginExecutions>-->
        <!--</lifecycleMappingMetadata>-->
        <!--</configuration>-->
        <!--</plugin>-->
        <!--</plugins>-->
        <!--</pluginManagement>-->
    </build>
    <profiles>
        <!-- 执行functional test -->
        <profile>
            <id>functional-test</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <argLine>-Xmx256M -XX:MaxPermSize=128m</argLine>
                            <includes>
                                <include>**/*FT.java</include>
                            </includes>
                            <!-- 支持taglib tld文件查找的必要设置 -->
                            <useSystemClassLoader>false</useSystemClassLoader>
                            <!-- 将mvn命令行传入的selenium driver参数传入surefire的JVM -->
                            <systemPropertyVariables>
                                <selenium.driver>${selenium.driver}</selenium.driver>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <!-- 执行@Category(Smoke.class)的TestCase -->
        <profile>
            <id>run-smoke</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <groups>org.springside.modules.test.category.Smoke</groups>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <!-- 刷新开发环境数据库 -->
        <profile>
            <id>refresh-db</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <configuration>
                            <target>
                                <property file="src/main/resources/application.development.properties"/>
                                <property file="src/main/resources/application.properties"/>
                                <sql driver="${jdbc.driver}" url="${jdbc.url}" userid="${jdbc.username}"
                                     password="${jdbc.password}" onerror="continue"
                                     encoding="${project.build.sourceEncoding}">
                                    <classpath refid="maven.test.classpath"/>
                                    <transaction src="src/main/resources/sql/h2/schema.sql"/>
                                    <transaction src="src/test/resources/data/h2/import-data.sql"/>
                                </sql>
                            </target>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

+ 27 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/config/FastDFSConfig.java

@ -0,0 +1,27 @@
package com.yihu.wlyy.config;
import com.yihu.wlyy.util.fastdfs.FastDFSClientPool;
import com.yihu.wlyy.util.fastdfs.FastDFSUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 * @author Sand
 * @version 1.0
 * @created 2015.11.27 16:08
 */
@Configuration
public class FastDFSConfig {
    @Bean
    public FastDFSClientPool fastDFSClientPool(){
        FastDFSClientPool clientPool = FastDFSClientPool.getInstance();
        return clientPool;
    }
    @Bean
    public FastDFSUtil fastDFSUtil(){
        FastDFSUtil util = new FastDFSUtil();
        return util;
    }
}

+ 1 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/consult/ConsultTeamService.java

@ -912,8 +912,7 @@ public class ConsultTeamService extends ConsultService {
        if (StringUtils.isEmpty(returnJson)) {
            throw new Exception("send consult finished IM message failed");
        } else {
            JSONObject jo = new JSONObject(returnJson);
            //设置消息ID
            JSONObject jo = new JSONObject(returnJson);            //设置消息ID
            consultTeam.setEndMsgId(jo.getInt("startId"));
            consultTeam.setEndOperator(endOperator);
            consultTeam.setEndType(endType);

+ 236 - 209
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/CommonUtil.java

@ -1,218 +1,245 @@
package com.yihu.wlyy.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.*;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.wlyy.config.FastDFSConfig;
import com.yihu.wlyy.util.fastdfs.FastDFSUtil;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
public class CommonUtil {
	/**
	 * 获取图片全路径
	 * 
	 * @return
	 */
	public static String getPhoneUrl(String url) {
		if (StringUtils.isEmpty(url)) {
			return "";
		} else {
			if (url.indexOf("http") > -1) {
				return url;
			} else {
				return SystemConf.getInstance().getServerUrl() + url;
			}
		}
	}
	public static String getMobileEncode(String mobile) {
		if (StringUtils.isNotEmpty(mobile) && mobile.length() == 11) {
			return mobile.substring(0, 4) + "****" + mobile.substring(8, 11);
		}
		return mobile;
	}
	public static String getIdcardEncode(String idcard) {
		if (idcard != null) {
			if (idcard.length() == 18) {
				return idcard.substring(0, 9) + "*******" + idcard.substring(16, 18);
			} else if (idcard.length() == 15) {
				return idcard.substring(0, 8) + "***" + idcard.substring(11, 15);
			}
		}
		return idcard;
	}
	/** 
	 * 对象转数组 
	 * @param obj 
	 * @return 
	 */
	public static byte[] toByteArray(Object obj) {
		byte[] bytes = null;
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		try {
			ObjectOutputStream oos = new ObjectOutputStream(bos);
			oos.writeObject(obj);
			oos.flush();
			bytes = bos.toByteArray();
			oos.close();
			bos.close();
		} catch (IOException ex) {
			ex.printStackTrace();
		}
		return bytes;
	}
	/** 
	 * 数组转对象 
	 * @param bytes 
	 * @return 
	 */
	public static Object toObject(byte[] bytes) {
		Object obj = null;
		try {
			ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
			ObjectInputStream ois = new ObjectInputStream(bis);
			obj = ois.readObject();
			ois.close();
			bis.close();
		} catch (IOException ex) {
			ex.printStackTrace();
		} catch (ClassNotFoundException ex) {
			ex.printStackTrace();
		}
		return obj;
	}
	public static final InputStream byte2Input(byte[] buf) {
		return new ByteArrayInputStream(buf);
	}
	public static final byte[] input2byte(InputStream inStream) throws IOException {
		ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
		byte[] buff = new byte[100];
		int rc = 0;
		while ((rc = inStream.read(buff, 0, 100)) > 0) {
			swapStream.write(buff, 0, rc);
		}
		byte[] in2b = swapStream.toByteArray();
		return in2b;
	}
	/**
	 * 返回:张三为张*
	 * @param name 姓名
	 * @return
	 */
	public static String getEncryptName(String name) {
		if (StringUtils.isEmpty(name)) {
			return null;
		}
		if (name.length() == 1) {
			return name;
		}
		// 获取姓
		String temp = name.substring(0, 1);
		for (int i = 1; i < name.length(); i++) {
			temp += "*";
		}
		return temp;
	}
	/**
	 * 拷贝临时图片到存储目录
	 * @param images
	 * @return
	 * @throws IOException
	 */
	public static String copyTempImage(String images) throws IOException {
		// 文件保存的临时路径
		String tempPath = SystemConf.getInstance().getTempPath() + File.separator;
		// 图片保存路径
		String imagePath = SystemConf.getInstance().getImagePath() + File.separator;
		String[] tempImages = images.split(",");
		String temp = "";
		for (String image : tempImages) {
			File file = new File(tempPath + image);
			File smallFile = new File(tempPath + image + "_small");
			if (file.exists() && smallFile.exists()) {
				// 原图拷贝路径
				File targetFile = new File(imagePath + image);
				// 缩略图拷贝路径
				File targetSmallFile = new File(imagePath + image + "_small");
				// 拷贝原图
				FileUtils.copyFile(file, targetFile);
				// 拷贝缩略图
				FileUtils.copyFile(smallFile, targetSmallFile);
				// 删除临时文件
				FileUtils.forceDelete(file);
				FileUtils.forceDelete(smallFile);
				if (temp.length() == 0) {
					temp = SystemConf.getInstance().getImageServer() + image;
				} else {
					temp += "," + SystemConf.getInstance().getImageServer() + image;
				}
			}
		}
		return temp;
	}
	/**
	 * 拷贝临时语音文件到存储目录
	 * @param images
	 * @return
	 * @throws IOException
	 */
	public static String copyTempVoice(String voices) throws IOException {
		// 文件保存的临时路径
		String tempPath = SystemConf.getInstance().getTempPath() + File.separator;
		// 语音保存路径
		String voicePath = SystemConf.getInstance().getVoicePath() + File.separator;
		String[] tempVoices = voices.split(",");
		String temp = "";
		for (String voice : tempVoices) {
			File file = new File(tempPath + voice);
			if (file.exists()) {
				// 目标文件
				File targetFile = new File(voicePath + voice);
				// 拷贝到指定路径
				FileUtils.copyFile(file, targetFile);
				// 删除临时文件
				FileUtils.forceDelete(file);
				if (temp.length() == 0) {
					temp = SystemConf.getInstance().getVoiceServer() + voice;
				} else {
					temp += "," + SystemConf.getInstance().getVoiceServer() + voice;
				}
			}
		}
		return temp;
	}
	/**
	 * 校验健康指标是否正常
	 * @param curValue 当前值
	 * @param standardMax 最大标准值
	 * @param standardMin 最小标准值
	 * @return 0正常,1高,-1低
	 */
	public static double checkHealthIndex(double curValue, double standardMax, double standardMin) {
		if (curValue <= 0) {
			return 0;
		}
		if (standardMax > 0 && curValue > standardMax) {
			return curValue;
		}
		// 低于标准值,暂不推
		// if (standardMin > 0 && curValue < standardMin) {
		// return -curValue;
		// }
		return 0;
	}
    /**
     * 获取图片全路径
     *
     * @return
     */
    public static String getPhoneUrl(String url) {
        if (StringUtils.isEmpty(url)) {
            return "";
        } else {
            if (url.indexOf("http") > -1) {
                return url;
            } else {
                return SystemConf.getInstance().getServerUrl() + url;
            }
        }
    }
    public static String getMobileEncode(String mobile) {
        if (StringUtils.isNotEmpty(mobile) && mobile.length() == 11) {
            return mobile.substring(0, 4) + "****" + mobile.substring(8, 11);
        }
        return mobile;
    }
    public static String getIdcardEncode(String idcard) {
        if (idcard != null) {
            if (idcard.length() == 18) {
                return idcard.substring(0, 9) + "*******" + idcard.substring(16, 18);
            } else if (idcard.length() == 15) {
                return idcard.substring(0, 8) + "***" + idcard.substring(11, 15);
            }
        }
        return idcard;
    }
    /**
     * 对象转数组
     *
     * @param obj
     * @return
     */
    public static byte[] toByteArray(Object obj) {
        byte[] bytes = null;
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try {
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(obj);
            oos.flush();
            bytes = bos.toByteArray();
            oos.close();
            bos.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return bytes;
    }
    /**
     * 数组转对象
     *
     * @param bytes
     * @return
     */
    public static Object toObject(byte[] bytes) {
        Object obj = null;
        try {
            ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
            ObjectInputStream ois = new ObjectInputStream(bis);
            obj = ois.readObject();
            ois.close();
            bis.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
        return obj;
    }
    public static final InputStream byte2Input(byte[] buf) {
        return new ByteArrayInputStream(buf);
    }
    public static final byte[] input2byte(InputStream inStream) throws IOException {
        ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
        byte[] buff = new byte[100];
        int rc = 0;
        while ((rc = inStream.read(buff, 0, 100)) > 0) {
            swapStream.write(buff, 0, rc);
        }
        byte[] in2b = swapStream.toByteArray();
        return in2b;
    }
    /**
     * 返回:张三为张*
     *
     * @param name 姓名
     * @return
     */
    public static String getEncryptName(String name) {
        if (StringUtils.isEmpty(name)) {
            return null;
        }
        if (name.length() == 1) {
            return name;
        }
        // 获取姓
        String temp = name.substring(0, 1);
        for (int i = 1; i < name.length(); i++) {
            temp += "*";
        }
        return temp;
    }
    /**
     * 拷贝临时图片到存储目录
     *
     * @param images
     * @return
     * @throws IOException
     */
    public static String copyTempImage(String images) throws IOException {
        // 文件保存的临时路径
        String tempPath = SystemConf.getInstance().getTempPath() + File.separator;
        // 图片保存路径
        String imagePath = SystemConf.getInstance().getImagePath() + File.separator;
        String[] tempImages = images.split(",");
        String temp = "";
        for (String image : tempImages) {
            File file = new File(tempPath + image);
            File smallFile = new File(tempPath + image + "_small");
            if (file.exists() && smallFile.exists()) {
                // 原图拷贝路径
                File targetFile = new File(imagePath + image);
                // 缩略图拷贝路径
                File targetSmallFile = new File(imagePath + image + "_small");
                // 拷贝原图
                FileUtils.copyFile(file, targetFile);
                // 拷贝缩略图
                FileUtils.copyFile(smallFile, targetSmallFile);
                // 删除临时文件
                FileUtils.forceDelete(file);
                FileUtils.forceDelete(smallFile);
                if (temp.length() == 0) {
                    temp = SystemConf.getInstance().getImageServer() + image;
                } else {
                    temp += "," + SystemConf.getInstance().getImageServer() + image;
                }
            }
        }
        return temp;
    }
    /**
     * 拷贝临时语音文件到存储目录
     *
     * @param voices
     * @return
     * @throws IOException
     */
    public static String copyTempVoice(String voices) throws IOException {
        // 文件保存的临时路径
        String tempPath = SystemConf.getInstance().getTempPath() + File.separator;
        // 语音保存路径
        String voicePath = SystemConf.getInstance().getVoicePath() + File.separator;
        String[] tempVoices = voices.split(",");
        String temp = "";
        for (String voice : tempVoices) {
            File file = new File(tempPath + voice);
            if (file.exists()) {
                // 目标文件
                File targetFile = new File(voicePath + voice);
                // 拷贝到指定路径
                FileUtils.copyFile(file, targetFile);
                // 删除临时文件
                FileUtils.forceDelete(file);
                if (temp.length() == 0) {
                    temp = SystemConf.getInstance().getVoiceServer() + voice;
                } else {
                    temp += "," + SystemConf.getInstance().getVoiceServer() + voice;
                }
            }
        }
        return temp;
    }
    /**
     * 校验健康指标是否正常
     *
     * @param curValue    当前值
     * @param standardMax 最大标准值
     * @param standardMin 最小标准值
     * @return 0正常,1高,-1低
     */
    public static double checkHealthIndex(double curValue, double standardMax, double standardMin) {
        if (curValue <= 0) {
            return 0;
        }
        if (standardMax > 0 && curValue > standardMax) {
            return curValue;
        }
        // 低于标准值,暂不推
        // if (standardMin > 0 && curValue < standardMin) {
        // return -curValue;
        // }
        return 0;
    }
    public static String copyTempFilesToFastDFS(String files) throws Exception {
        // 文件保存的临时路径
        String tempPath = SystemConf.getInstance().getTempPath() + File.separator;
        String[] fileArray = files.split(",");
        FastDFSUtil fastDFSUtil = new FastDFSConfig().fastDFSUtil();
        String fileUrls = "";
        for (String file : fileArray) {
            File f = new File(tempPath + file);
            if (f.exists()) {
                String fileName = f.getName();
                InputStream in = new FileInputStream(f);
                ObjectNode result = fastDFSUtil.upload(in, fileName.substring(fileName.lastIndexOf(".") + 1), "");
                in.close();
                if (result != null) {
                    fileUrls += (StringUtils.isEmpty(fileUrls) ? "" : ",") + result.get("fileUrl").toString().replaceAll("\"","");
                }
            }
        }
        return fileUrls;
    }
}

+ 134 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/fastdfs/FastDFSClientPool.java

@ -0,0 +1,134 @@
package com.yihu.wlyy.util.fastdfs;
import org.csource.common.MyException;
import org.csource.fastdfs.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
/**
 * Created by szx on 2015/9/19.
 */
public class FastDFSClientPool {
    private static volatile FastDFSClientPool pool;
    private Map<StorageClient, Boolean> map;
    private int maxPoolSize = 20;
    private int waitTime = 500;
    private int initPoolSize = 5;
    static {
        try {
            
            String basePath = FastDFSClientPool.class.getResource("/").getPath();
           
            ClientGlobal.init(FastDFSUtil.class.getResource("/config/fdfs_client.conf").getPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    private FastDFSClientPool() {
        init();
    }
    public static FastDFSClientPool getInstance() {
        if (pool == null) {
            synchronized (FastDFSClientPool.class) {
                if(pool == null) {
                    pool = new FastDFSClientPool();
                }
            }
        }
        System.out.println("FastDFSClientPool:"+pool.toString());
        return pool;
    }
    private void init() {
        try {
            map = new HashMap<StorageClient, Boolean>();
            //不做初始缓存
//            for (int i = 0; i < initPoolSize; i++) {
//                map.put(getNewStorageClient(), true);
//            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public TrackerServer getTrackerServer(){
        try {
            TrackerClient tracker = new TrackerClient();
            return tracker.getConnection();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
    private StorageClient getNewStorageClient() {
        try {
            TrackerClient tracker = new TrackerClient();
            TrackerServer trackerServer = tracker.getConnection();
            StorageClient client = new StorageClient(trackerServer, null);
            return client;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    public synchronized StorageClient getStorageClient() {
        StorageClient client = null;
        try {
            for (Entry<StorageClient, Boolean> entry : map.entrySet()) {
                if (entry.getValue()) {
                    client = entry.getKey();
                    System.out.println("从缓存中获得fastdfs client");
                    map.put(client, false);
                    break;
                }
            }
            if (client == null) {
                if(map.size()<maxPoolSize) {
                    System.out.println("创建新fastdfs client:");
                    client = getNewStorageClient();
                    map.put(client, false);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return client;
    }
    public void releaseStorageClient(StorageClient client) {
        if (client == null) {
            return;
        }
        try {
            if(map.containsKey(client)) {
                    map.put(client, true);
            } else {
                client =null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

+ 287 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/fastdfs/FastDFSUtil.java

@ -0,0 +1,287 @@
package com.yihu.wlyy.util.fastdfs;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.csource.common.MyException;
import org.csource.common.NameValuePair;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.ProtoCommon;
import org.csource.fastdfs.StorageClient;
import org.csource.fastdfs.StorageClient1;
import org.csource.fastdfs.TrackerServer;
/**
 * FastDFS 客户端工具.
 *
 * @author szx
 */
public class FastDFSUtil {
    public final static String GroupField = "groupName";
    public final static String RemoteFileField = "remoteFileName";
    public final static String FileIdField = "fid";
    public final static String FileUrlField = "fileUrl";
//    static TrackerClient tracker;
//    static TrackerServer trackerServer;
//    static StorageServer storageServer;
//    static StorageClient client;
//
//    static {
//        try {
//            XEnvironmentOption environmentOption = ServiceFactory.getService(Services.EnvironmentOption);
//            String basePath = FastDFSUtil.class.getResource("/").getPath();
//            String configFile = basePath + environmentOption.getOption(EnvironmentOptions.FastDFSConfig);
//
//            ClientGlobal.init(configFile);
//
//            tracker = new TrackerClient();
//            trackerServer = tracker.getConnection();
//            storageServer = null;
//            client = new StorageClient(trackerServer, storageServer);
//        } catch (FileNotFoundException e) {
//            LogService.getLogger(FastDFSUtil.class).fatal("FastDFS配置文件打开失败: " + e.getMessage());
//        } catch (IOException e) {
//            LogService.getLogger(FastDFSUtil.class).fatal("FastDFS初始化失败: " + e.getMessage());
//        } catch (MyException e) {
//            LogService.getLogger(FastDFSUtil.class).fatal("FastDFS初始化失败: " + e.getMessage());
//        }
//    }
    /**
     * 以输入流的方式上传文件
     * InputStream in = new FileInputStream("C://Desert.jpg");
     * ObjectNode msg = FileUtil.upload(in,"jpg", "沙漠");
     * in.close();
     *
     * @param in                输入流
     * @param fileExtension   文件扩展名,不要带“.”
     * @param description             文件名称(中文)
     * @return 返回值的格式如下:
     * {
     *      "groupName": "healthArchiveGroup",
     *      "remoteFileName": "/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg",
     *      "fid": "group1/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg",
     *      "fileURL": "http://172.19.103.13/healthArchiveGroup/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg"
     * }
     *
     * groupName 及 remoteFileName 可以用于查询在 fastDFS 中文件的信息,如果只是图片显示,可以忽略这两个值。
     * fid 保存了在 fastDFS 上的完整路径,为了避免将来服务器域名发生变更,最好使用本值.服务器的域名另外配置。
     * fileURL 保存了完整的 web 访问路径,为了避免将来服务器域名发生变更,最好不要直接使用本值。
     * 如果需要在下载时,可以显示原始文件名,请在访问file_url时,增加 attname 参数,如:
     *
     * http://host/healthArchiveGroup/M00/00/00/rBFuH1XdIseAUTZZAA1rIuRd3Es062.jpg?attname=a.jpg
     *
     * @throws Exception
     */
    public static ObjectNode upload(InputStream in, String fileExtension,
                                    String description) throws Exception {
        StorageClient client = FastDFSClientPool.getInstance().getStorageClient();
        try {
            NameValuePair[] fileMetaData;
            fileMetaData = new NameValuePair[1];
            fileMetaData[0] = new NameValuePair("description", description == null ? "" : description);
            ObjectMapper objectMapper = new ObjectMapper();
            ObjectNode message = objectMapper.createObjectNode();
            byte fileBuffer[] = new byte[in.available()];
            int len = 0;
            int temp = 0;                             //所有读取的内容都使用temp接收
            while ((temp = in.read()) != -1) {            //当没有读取完时,继续读取
                fileBuffer[len] = (byte) temp;
                len++;
            }
            in.close();
            TrackerServer trackerServer = FastDFSClientPool.getInstance().getTrackerServer();
            String[] results = client.upload_file(fileBuffer, fileExtension, fileMetaData);
            if (results != null) {
                String fileId;
                int ts;
                String token;
                String fileURl;
                InetSocketAddress socketAddress;
                String groupName = results[0];
                String remoteFile = results[1];
                message.put(GroupField, groupName);
                message.put(RemoteFileField, remoteFile);
                fileId = groupName + StorageClient1.SPLIT_GROUP_NAME_AND_FILENAME_SEPERATOR + remoteFile;
                message.put(FileIdField, fileId);
                socketAddress = trackerServer.getInetSocketAddress();
                fileURl = "http://" + socketAddress.getAddress().getHostAddress();
                if (ClientGlobal.g_tracker_http_port != 80) {
                    fileURl += ":" + ClientGlobal.g_tracker_http_port;
                }
                fileURl += "/" + fileId;
                if (ClientGlobal.g_anti_steal_token) {
                    ts = (int) (System.currentTimeMillis() / 1000);
                    token = ProtoCommon.getToken(fileId, ts, ClientGlobal.g_secret_key);
                    fileURl += "?token=" + token + "&ts=" + ts;
                }
                message.put(FileUrlField, fileURl);
                
                return message;
            } else {
                return null;
            }
        }finally {
            FastDFSClientPool.getInstance().releaseStorageClient(client);
        }
    }
    /**
     * 上传本地文件
     * ObjectNode  a = FileUtil.upload("C://Desert.jpg", "沙漠");
     * System.out.println(a.toString());
     *
     * @param fileName 本地文件的绝对路径,如 C://Desert.jpg
     * @param description    文件备注, 可以为空
     * @return {"groupName":"group1","remoteFileName":"/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg"
     * {
     *      "groupName": "healthArchiveGroup",
     *      "remoteFileName": "/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg",
     *      "fid": "group1/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg",
     *      "fileURL": "http://172.19.103.13/healthArchiveGroup/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg"
     * }
     *
     * groupName 及 remoteFileName 可以用于查询在 fastDFS 中文件的信息,如果只是图片显示,可以忽略这两个值。
     * fid 保存了在 fastDFS 上的完整路径,为了避免将来服务器域名发生变更,最好使用本值.服务器的域名另外配置。
     * fileURL 保存了完整的 web 访问路径,为了避免将来服务器域名发生变更,最好不要直接使用本值。
     * 如果需要在下载时,可以显示原始文件名,请在访问file_url时,增加 attname 参数,如:
     *
     * http://host/healthArchiveGroup/M00/00/00/rBFuH1XdIseAUTZZAA1rIuRd3Es062.jpg?attname=a.jpg
     *
     * @throws Exception
     */
    public static ObjectNode upload(String fileName, String description) throws Exception {
        StorageClient client = FastDFSClientPool.getInstance().getStorageClient();
        try {
            NameValuePair[] meta_list;
            meta_list = new NameValuePair[1];
            meta_list[0] = new NameValuePair("description", description == null ? "" : description);
            ObjectMapper objectMapper = new ObjectMapper();
            ObjectNode message = objectMapper.createObjectNode();
            String fileExtName = "";
            if (fileName.contains(".")) {
                fileExtName = fileName.substring(fileName.lastIndexOf(".") + 1);
            } else {
                throw new RuntimeException("上传失败, 文件缺失扩展名.");
            }
            TrackerServer trackerServer = FastDFSClientPool.getInstance().getTrackerServer();
            String[] results = client.upload_file(fileName, fileExtName, meta_list);
            if (results != null) {
                String fileId;
                int ts;
                String token;
                String fileUrl;
                InetSocketAddress inetSockAddr;
                String groupName = results[0];
                String remoteFileName = results[1];
                message.put(GroupField, groupName);
                message.put(RemoteFileField, remoteFileName);
                fileId = groupName + StorageClient1.SPLIT_GROUP_NAME_AND_FILENAME_SEPERATOR + remoteFileName;
                message.put(FileIdField, fileId);
                inetSockAddr = trackerServer.getInetSocketAddress();
                fileUrl = "http://" + inetSockAddr.getAddress().getHostAddress();
                if (ClientGlobal.g_tracker_http_port != 80) {
                    fileUrl += ":" + ClientGlobal.g_tracker_http_port;
                }
                fileUrl += "/" + fileId;
                if (ClientGlobal.g_anti_steal_token) {
                    ts = (int) (System.currentTimeMillis() / 1000);
                    token = ProtoCommon.getToken(fileId, ts, ClientGlobal.g_secret_key);
                    fileUrl += "?token=" + token + "&ts=" + ts;
                }
                message.put(FileUrlField, fileUrl);
                
                return message;
            } else {
                return null;
            }
        }finally {
            FastDFSClientPool.getInstance().releaseStorageClient(client);
        }
    }
    /**
     * 下载文件, 返回文件字节数组.
     *
     * @param groupName      在fastdfs上的卷名
     * @param remoteFileName 在fastdfs上的路径
     * @return 文件的字节码
     * @throws Exception
     */
    public static byte[] download(String groupName, String remoteFileName) throws Exception {
        StorageClient client = FastDFSClientPool.getInstance().getStorageClient();
        try {
            byte[] b = client.download_file(groupName, remoteFileName);
            return b;
        }
        finally {
            FastDFSClientPool.getInstance().releaseStorageClient(client);
        }
    }
    /**
     * 下载文件到本地路径上.
     *
     * @param groupName          在 fastDFS 上的卷名
     * @param remoteFileName    在 fastDFS 上的路径
     * @param localPath          本地路径
     *
     * @return 是否下载成功
     */
    public static String download(String groupName, String remoteFileName, String localPath) throws IOException, MyException {
        StorageClient client = FastDFSClientPool.getInstance().getStorageClient();
        try {
            String localFileName = localPath + "\\" + remoteFileName.replaceAll("/", "_");
            client.download_file(groupName, remoteFileName, 0, 0, localFileName);
            return localFileName;
        }finally {
            FastDFSClientPool.getInstance().releaseStorageClient(client);
        }
    }
    /**
     * 删除文件。
     *
     * @param groupName
     * @param remoteFileName
     */
    public static void delete(String groupName, String remoteFileName) throws IOException, MyException {
        StorageClient client = FastDFSClientPool.getInstance().getStorageClient();
        try {
            client.delete_file(groupName, remoteFileName);
        }finally {
            FastDFSClientPool.getInstance().releaseStorageClient(client);
        }
    }
}

+ 42 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/FileTestController.java

@ -0,0 +1,42 @@
package com.yihu.wlyy.web.statistic;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.wlyy.config.FastDFSConfig;
import com.yihu.wlyy.util.fastdfs.FastDFSUtil;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
/**
 * Created by lyr-pc on 2016/12/13.
 */
@RestController
@RequestMapping(value = "/test/file/")
@Api(description = "文件测试")
public class FileTestController extends BaseController {
    @Autowired
    FastDFSConfig fastDFSConfig;
    @ApiOperation(value = "文件上传", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    public String resolve(
            @ApiParam("文件")
            @RequestPart() MultipartFile file) throws Throwable {
        try {
            FastDFSUtil fastDFSUtil = fastDFSConfig.fastDFSUtil();
            ObjectNode result = fastDFSUtil.upload(file.getInputStream(), "png", "测试");
            return write(200,"上传成功","data",result.toString());
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"上传失败");
        }
    }
}

+ 10 - 0
patient-co-wlyy/src/main/resources/config/fdfs_client.conf

@ -0,0 +1,10 @@
connect_timeout = 2
network_timeout = 30
charset = ISO8859-1
http.tracker_http_port = 80
http.anti_steal_token = no
http.secret_key = FastDFS1234567890
#tracker_server = 172.19.103.13:22122
tracker_server = 192.168.131.127:22122
#172.19.103.54:22122

二进制
patient-co-wlyy/src/main/resources/fastdfs_lib.jar