Преглед на файлове

fix 排序增加拼音字段

Administrator преди 4 години
родител
ревизия
c62f1bcbe0

+ 6 - 0
ruoyi-system/pom.xml

@@ -36,6 +36,12 @@
             <version>0.4.8</version>
             <scope>compile</scope>
         </dependency>
+        <dependency>
+            <groupId>com.rnkrsoft.bopomofo4j</groupId>
+            <artifactId>bopomofo4j</artifactId>
+            <version>1.0.0</version>
+            <scope>compile</scope>
+        </dependency>
 
     </dependencies>
 

+ 6 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/grallery/ZbGallery.java

@@ -41,6 +41,12 @@ public class ZbGallery extends BaseEntity {
     @Excel(name = "中文名称")
     private String cnName;
 
+    /**
+     * 拼音
+     */
+    @Excel(name = "拼音")
+    private String pyName;
+
     /**
      * 俗名
      */

+ 3 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/grallery/ZbGalleryCategory.java

@@ -34,6 +34,9 @@ public class ZbGalleryCategory extends BaseEntity {
     @Excel(name = "分类名称")
     private String name;
 
+    @Excel(name = "拼音")
+    private String pyName;
+
     /**
      * 分类编码
      */

+ 2 - 0
ruoyi-system/src/main/java/com/ruoyi/system/dto/GalleryDto.java

@@ -42,6 +42,8 @@ public class GalleryDto implements Serializable {
     @JsonProperty("cnName")
     @NotEmpty(message = "中文名称不能为空")
     private String cnName;
+    @JsonProperty("pyName")
+    private String pyName;
     @JsonProperty("ptName")
     private String ptName;
     @JsonProperty("latinName")

+ 34 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ZbGalleryCategoryServiceImpl.java

@@ -6,9 +6,11 @@ import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.rnkrsoft.bopomofo4j.Bopomofo4j;
 import com.ruoyi.common.config.RuoYiConfig;
 import com.ruoyi.common.exception.BaseException;
 import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.spring.SpringUtils;
 import com.ruoyi.system.domain.grallery.ZbGalleryCategory;
 import com.ruoyi.system.dto.GalleryCategoryDto;
@@ -68,6 +70,22 @@ public class ZbGalleryCategoryServiceImpl extends ServiceImpl<ZbGalleryCategoryM
             final ZbGalleryCategory parent = baseMapper.selectById(parentId);
             zbGalleryCategory.setCode(parent.getCode());
         }
+        String name = zbGalleryCategory.getName();
+        if (StringUtils.isNotEmpty(name)){
+            Bopomofo4j.local();//启用本地模式(也就是禁用沙盒)
+            /**
+             * 将汉字句子转换拼音,支持声母带音调,数字音调,无音调三种格式
+             *
+             * @param words    句子
+             * @param toneType 拼音样式 0-声母带音调,1-数字音调在最后,2-无音调,默认值0
+             * @param upper    是否大写,默认为假(小写)
+             * @param cap      是否首字母大写,在upper为假时有效,默认为假(小写)
+             * @param split    分割符号,默认一个空格
+             * @return 拼音
+             */
+            String pinyin = Bopomofo4j.pinyin(name, 2, false, false, "");
+            zbGalleryCategory.setPyName(pinyin);
+        }
         return baseMapper.insert(zbGalleryCategory);
     }
 
@@ -87,6 +105,22 @@ public class ZbGalleryCategoryServiceImpl extends ServiceImpl<ZbGalleryCategoryM
             final ZbGalleryCategory parent = baseMapper.selectById(parentId);
             zbGalleryCategory.setCode(parent.getCode());
         }
+        String name = zbGalleryCategory.getName();
+        if (StringUtils.isNotEmpty(name)){
+            Bopomofo4j.local();//启用本地模式(也就是禁用沙盒)
+            /**
+             * 将汉字句子转换拼音,支持声母带音调,数字音调,无音调三种格式
+             *
+             * @param words    句子
+             * @param toneType 拼音样式 0-声母带音调,1-数字音调在最后,2-无音调,默认值0
+             * @param upper    是否大写,默认为假(小写)
+             * @param cap      是否首字母大写,在upper为假时有效,默认为假(小写)
+             * @param split    分割符号,默认一个空格
+             * @return 拼音
+             */
+            String pinyin = Bopomofo4j.pinyin(name, 2, false, false, "");
+            zbGalleryCategory.setPyName(pinyin);
+        }
         return baseMapper.updateById(zbGalleryCategory);
     }
 

+ 37 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ZbGalleryServiceImpl.java

@@ -4,11 +4,13 @@ import cn.hutool.core.util.StrUtil;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.rnkrsoft.bopomofo4j.Bopomofo4j;
 import com.ruoyi.common.config.RuoYiConfig;
 import com.ruoyi.common.enums.CommentType;
 import com.ruoyi.common.exception.BaseException;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
 import com.ruoyi.system.domain.ZbFile;
 import com.ruoyi.system.domain.grallery.ZbGallery;
@@ -73,12 +75,29 @@ public class ZbGalleryServiceImpl extends ServiceImpl<ZbGalleryMapper, ZbGallery
         gallery.setCreateTime(nowDate);
         String createBy = SecurityUtils.getUserId().toString();
         gallery.setCreateBy(createBy);
-
+        //把中文名称转换为拼音存储
+        String cnName = gallery.getCnName();
+        if (StringUtils.isNotEmpty(cnName)){
+            Bopomofo4j.local();//启用本地模式(也就是禁用沙盒)
+            /**
+             * 将汉字句子转换拼音,支持声母带音调,数字音调,无音调三种格式
+             *
+             * @param words    句子
+             * @param toneType 拼音样式 0-声母带音调,1-数字音调在最后,2-无音调,默认值0
+             * @param upper    是否大写,默认为假(小写)
+             * @param cap      是否首字母大写,在upper为假时有效,默认为假(小写)
+             * @param split    分割符号,默认一个空格
+             * @return 拼音
+             */
+            String pinyin = Bopomofo4j.pinyin(cnName, 2, false, false, "");
+            gallery.setPyName(pinyin);
+        }
         int insert = baseMapper.insert(gallery);
         if (insert <= 0) {
             throw new BaseException("图库保存失败");
         }
 
+
         //判断是否新增图库时,新增了图片
         if (zbGallery.getImgInfos().size() > 0) {
             List<ZbGalleryImg> imgList = zbGallery.getImgInfos().stream().filter(e -> e.getId() != null).map(x -> {
@@ -119,7 +138,23 @@ public class ZbGalleryServiceImpl extends ServiceImpl<ZbGalleryMapper, ZbGallery
         gallery.setCreateTime(nowDate);
         String createBy = SecurityUtils.getUserId().toString();
         gallery.setCreateBy(createBy);
-
+        //把中文名称转换为拼音存储
+        String cnName = gallery.getCnName();
+        if (StringUtils.isNotEmpty(cnName)){
+            Bopomofo4j.local();//启用本地模式(也就是禁用沙盒)
+            /**
+             * 将汉字句子转换拼音,支持声母带音调,数字音调,无音调三种格式
+             *
+             * @param words    句子
+             * @param toneType 拼音样式 0-声母带音调,1-数字音调在最后,2-无音调,默认值0
+             * @param upper    是否大写,默认为假(小写)
+             * @param cap      是否首字母大写,在upper为假时有效,默认为假(小写)
+             * @param split    分割符号,默认一个空格
+             * @return 拼音
+             */
+            String pinyin = Bopomofo4j.pinyin(cnName, 2, false, false, "");
+            gallery.setPyName(pinyin);
+        }
         int insert = baseMapper.updateById(gallery);
         if (insert <= 0) {
             throw new BaseException("图库保存失败");

+ 4 - 4
ruoyi-system/src/main/resources/mapper/system/ZbGalleryCategoryMapper.xml

@@ -53,7 +53,7 @@
                 </if>
             </if>
         </where>
-        order by code , sort, convert(name using gbk)
+        order by code , sort, py_name
     </select>
 
 
@@ -76,7 +76,7 @@
                 </if>
             </if>
         </where>
-        order by zgc.code DESC, zgc.sort, zgcp.name,convert(zgc.name using gbk)
+        order by zgc.code DESC, zgc.sort, zgcp.name,zgc.py_name
     </select>
     <select id="getDetailById" resultType="com.ruoyi.system.dto.GalleryCategoryDto">
         SELECT zgc.*,
@@ -101,7 +101,7 @@
         <where>
             zgcp.top = 1 and zgcp.code = #{categoryCode}
         </where>
-        order by zgc.code DESC,zgc.sort,zgcp.name,convert(zgc.name using gbk)
+        order by zgc.code DESC,zgc.sort,zgcp.name,zgc.py_name
     </select>
 
     <select id="getByParentIds" resultType="com.ruoyi.system.dto.GalleryCategoryDto">
@@ -120,7 +120,7 @@
                 </foreach>
             </where>
         </if>
-        order by zgc.code DESC, zgc.sort,zgcp.name,convert(zgc.name using gbk)
+        order by zgc.code DESC, zgc.sort,zgcp.name,zgc.py_name
     </select>
     <select id="checkHasChildren" resultType="java.lang.Integer">
         select 1

+ 4 - 3
ruoyi-system/src/main/resources/mapper/system/ZbGalleryMapper.xml

@@ -7,6 +7,7 @@
     <resultMap type="com.ruoyi.system.domain.grallery.ZbGallery" id="ZbGalleryResult">
         <result property="id" column="id"/>
         <result property="name" column="name"/>
+        <result property="pyName" column="py_name"/>
         <result property="cnName" column="cn_name"/>
         <result property="ptName" column="pt_name"/>
         <result property="latinName" column="latin_name"/>
@@ -24,7 +25,7 @@
     </resultMap>
 
     <sql id="selectZbGalleryVo">
-        select id, name, cn_name, pt_name, latin_name, distribution, years, celebrity, host, form, symptom, category, category_id, create_by, create_time, update_by, update_time, remark from zb_gallery
+        select id, name, cn_name,py_name, pt_name, latin_name, distribution, years, celebrity, host, form, symptom, category, category_id, create_by, create_time, update_by, update_time, remark from zb_gallery
     </sql>
 
     <select id="selectZbGalleryList" resultType="com.ruoyi.system.dto.GalleryDto">
@@ -68,7 +69,7 @@
             </if>
         </if>
         </where>
-        order by zg.category DESC, zg.sort, zg.latin_name is null, zg.latin_name, CONVERT(zg.cn_name using gb2312)
+        order by zg.category DESC, zg.sort, zg.latin_name is null, zg.latin_name, zg.py_name
     </select>
 
     <resultMap id="GalleryDtoMap" type="com.ruoyi.system.dto.GalleryDto">
@@ -137,7 +138,7 @@
                 </foreach>
             </where>
         </if>
-        order by zg.category DESC, zg.sort, zg.latin_name is null, zg.latin_name ,CONVERT(zg.cn_name USING gbk)
+        order by zg.category DESC, zg.sort, zg.latin_name is null, zg.latin_name ,zg.py_name
     </select>
 
     <select id="checkCategoryHasValue" resultType="java.lang.Integer">