From 63a0c20343a2acc5c2c38031c5cde01ca4c4d9eb Mon Sep 17 00:00:00 2001 From: dinggang <2498628697@qq.com> Date: Tue, 26 Apr 2022 20:37:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91=E6=8C=87=E5=8D=97=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8A=E4=BC=A0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- renren-admin/pom.xml | 5 ++++ .../controller/CategoryController.java | 3 ++- .../modules/category/util/CommonUtils.java | 27 +++++++++++++++++++ .../impl/DevelopmentGuideServiceImpl.java | 7 ++--- .../service/impl/ResourceServiceImpl.java | 2 +- 5 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 renren-admin/src/main/java/io/renren/modules/category/util/CommonUtils.java diff --git a/renren-admin/pom.xml b/renren-admin/pom.xml index f70b333f..eb473c04 100644 --- a/renren-admin/pom.xml +++ b/renren-admin/pom.xml @@ -210,6 +210,11 @@ ${project.basedir}/lib/yawei-pso-2.0.2.jar ${yawei-pso.version} + + com.belerweb + pinyin4j + 2.5.1 + diff --git a/renren-admin/src/main/java/io/renren/modules/category/controller/CategoryController.java b/renren-admin/src/main/java/io/renren/modules/category/controller/CategoryController.java index 0b10fa9f..3470f53a 100644 --- a/renren-admin/src/main/java/io/renren/modules/category/controller/CategoryController.java +++ b/renren-admin/src/main/java/io/renren/modules/category/controller/CategoryController.java @@ -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 { diff --git a/renren-admin/src/main/java/io/renren/modules/category/util/CommonUtils.java b/renren-admin/src/main/java/io/renren/modules/category/util/CommonUtils.java new file mode 100644 index 00000000..7da9c337 --- /dev/null +++ b/renren-admin/src/main/java/io/renren/modules/category/util/CommonUtils.java @@ -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; + } +} diff --git a/renren-admin/src/main/java/io/renren/modules/developmentGuide/service/impl/DevelopmentGuideServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/developmentGuide/service/impl/DevelopmentGuideServiceImpl.java index 70b96fb3..0c127f5b 100644 --- a/renren-admin/src/main/java/io/renren/modules/developmentGuide/service/impl/DevelopmentGuideServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/developmentGuide/service/impl/DevelopmentGuideServiceImpl.java @@ -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; } } diff --git a/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java index 08bfd4c3..43cf61a7 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java @@ -129,7 +129,7 @@ public class ResourceServiceImpl extends CrudServiceImpl wrapper = new QueryWrapper<>(); wrapper.eq("data_resource_id", resourceEntity.getId()) - .eq("del_flag", 0); + .eq("del_f lag", 0); List attrEntities = attrDao.selectList(wrapper); resourceDTO.setInfoList(attrEntities); return resourceDTO;