开发指南文件上传修改

This commit is contained in:
dinggang 2022-04-26 20:37:19 +08:00
parent 66e50fd582
commit 63a0c20343
5 changed files with 39 additions and 5 deletions

View File

@ -210,6 +210,11 @@
<systemPath>${project.basedir}/lib/yawei-pso-2.0.2.jar</systemPath>
<version>${yawei-pso.version}</version>
</dependency>
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.1</version>
</dependency>
</dependencies>
<build>

View File

@ -12,6 +12,7 @@ import io.renren.common.validator.group.UpdateGroup;
import io.renren.modules.category.dto.CategoryDTO;
import io.renren.modules.category.entity.Category;
import io.renren.modules.category.service.CategoryService;
import io.renren.modules.category.util.CommonUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
@ -66,7 +67,7 @@ public class CategoryController {
categoryDTO.setDelFlag(0);
//若为一级分类增加文件夹
if (ObjectUtils.isEmpty(categoryDTO.getPid())) {
File file = new File(devModelFilePath + File.pathSeparator + categoryDTO.getName());
File file = new File(devModelFilePath + File.pathSeparator + CommonUtils.getPinYinHeadChar(categoryDTO.getName()));
//文件路径不存在创建各种能力的子文件夹
if (! file.exists()) {
try {

View File

@ -0,0 +1,27 @@
package io.renren.modules.category.util;
import net.sourceforge.pinyin4j.PinyinHelper;
public class CommonUtils {
/**
* 得到中文首字母
* @param value
* @return
*/
public static String getPinYinHeadChar(Object value) {
String str = String.valueOf(value);
String convert = "";
for (int j = 0; j < str.length(); j++) {
char word = str.charAt(j);
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
if (pinyinArray != null) {
convert += pinyinArray[0].charAt(0);
} else {
// convert += word;
break;
}
}
return convert;
}
}

View File

@ -65,8 +65,8 @@ public class DevelopmentGuideServiceImpl implements DevelopmentGuideService {
String type = request.getParameter("type").toString();
String fileName = request.getParameter("fileName").toString();
logger.info("读取文件类型及文件名:" + type + ";" + fileName);
File folder = new File(devModelFilePath + File.pathSeparator + type + File.separator + fileName);
File path = new File(devModelFilePath + File.pathSeparator + type + File.separator);
File folder = new File(devModelFilePath + File.separator + type + File.separator + fileName);
File path = new File(devModelFilePath + File.separator + type + File.separator);
//文件保存过删除后重新保存
if (folder.exists()) {
if (folder.isFile()) {
@ -82,7 +82,8 @@ public class DevelopmentGuideServiceImpl implements DevelopmentGuideService {
logger.info("----------------------------------文件上传成功--------------------------------------");
} catch (IOException e) {
logger.info("----------------------------------文件上传失败--------------------------------------");
e.printStackTrace();
logger.info("异常描述" + e.getMessage());
throw e;
}
}