From f8ab5663ef7220f8adc0fd8fcbd7d0cf84c6d77d Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期一, 02 八月 2021 12:15:14 +0800
Subject: [PATCH] update 日常字符串校验 统一重构到 StringUtils 便于维护扩展

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java |   48 +++++++++++++++++++++++++++++++++---------------
 1 files changed, 33 insertions(+), 15 deletions(-)

diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java
index 71035b9..495c2e9 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java
@@ -1,16 +1,22 @@
 package com.ruoyi.system.service.impl;
 
 import cn.hutool.core.lang.Validator;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.ruoyi.common.constant.UserConstants;
+import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
+import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.exception.CustomException;
+import com.ruoyi.common.utils.PageUtils;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.system.domain.SysPost;
+import com.ruoyi.system.domain.SysUserPost;
 import com.ruoyi.system.mapper.SysPostMapper;
 import com.ruoyi.system.mapper.SysUserPostMapper;
 import com.ruoyi.system.service.ISysPostService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -19,12 +25,19 @@
  * @author ruoyi
  */
 @Service
-public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPost> implements ISysPostService {
-    @Autowired
-    private SysPostMapper postMapper;
+public class SysPostServiceImpl extends ServicePlusImpl<SysPostMapper, SysPost, SysPost> implements ISysPostService {
 
     @Autowired
     private SysUserPostMapper userPostMapper;
+
+    @Override
+    public TableDataInfo<SysPost> selectPagePostList(SysPost post) {
+        LambdaQueryWrapper<SysPost> lqw = new LambdaQueryWrapper<SysPost>()
+                .like(StringUtils.isNotBlank(post.getPostCode()), SysPost::getPostCode, post.getPostCode())
+                .eq(StringUtils.isNotBlank(post.getStatus()), SysPost::getStatus, post.getStatus())
+                .like(StringUtils.isNotBlank(post.getPostName()), SysPost::getPostName, post.getPostName());
+        return PageUtils.buildDataInfo(page(PageUtils.buildPage(),lqw));
+    }
 
     /**
      * 鏌ヨ宀椾綅淇℃伅闆嗗悎
@@ -34,7 +47,10 @@
      */
     @Override
     public List<SysPost> selectPostList(SysPost post) {
-        return postMapper.selectPostList(post);
+        return list(new LambdaQueryWrapper<SysPost>()
+                .like(StringUtils.isNotBlank(post.getPostCode()), SysPost::getPostCode, post.getPostCode())
+                .eq(StringUtils.isNotBlank(post.getStatus()), SysPost::getStatus, post.getStatus())
+                .like(StringUtils.isNotBlank(post.getPostName()), SysPost::getPostName, post.getPostName()));
     }
 
     /**
@@ -44,7 +60,7 @@
      */
     @Override
     public List<SysPost> selectPostAll() {
-        return postMapper.selectPostAll();
+        return list();
     }
 
     /**
@@ -55,7 +71,7 @@
      */
     @Override
     public SysPost selectPostById(Long postId) {
-        return postMapper.selectPostById(postId);
+        return getById(postId);
     }
 
     /**
@@ -66,7 +82,7 @@
      */
     @Override
     public List<Integer> selectPostListByUserId(Long userId) {
-        return postMapper.selectPostListByUserId(userId);
+        return baseMapper.selectPostListByUserId(userId);
     }
 
     /**
@@ -78,7 +94,8 @@
     @Override
     public String checkPostNameUnique(SysPost post) {
         Long postId = Validator.isNull(post.getPostId()) ? -1L : post.getPostId();
-        SysPost info = postMapper.checkPostNameUnique(post.getPostName());
+        SysPost info = getOne(new LambdaQueryWrapper<SysPost>()
+                .eq(SysPost::getPostName, post.getPostName()).last("limit 1"));
         if (Validator.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) {
             return UserConstants.NOT_UNIQUE;
         }
@@ -94,7 +111,8 @@
     @Override
     public String checkPostCodeUnique(SysPost post) {
         Long postId = Validator.isNull(post.getPostId()) ? -1L : post.getPostId();
-        SysPost info = postMapper.checkPostCodeUnique(post.getPostCode());
+        SysPost info = getOne(new LambdaQueryWrapper<SysPost>()
+                .eq(SysPost::getPostCode, post.getPostCode()).last("limit 1"));
         if (Validator.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) {
             return UserConstants.NOT_UNIQUE;
         }
@@ -109,7 +127,7 @@
      */
     @Override
     public int countUserPostById(Long postId) {
-        return userPostMapper.countUserPostById(postId);
+        return userPostMapper.selectCount(new LambdaQueryWrapper<SysUserPost>().eq(SysUserPost::getPostId,postId));
     }
 
     /**
@@ -120,7 +138,7 @@
      */
     @Override
     public int deletePostById(Long postId) {
-        return postMapper.deletePostById(postId);
+        return baseMapper.deleteById(postId);
     }
 
     /**
@@ -138,7 +156,7 @@
                 throw new CustomException(String.format("%1$s宸插垎閰�,涓嶈兘鍒犻櫎", post.getPostName()));
             }
         }
-        return postMapper.deletePostByIds(postIds);
+        return baseMapper.deleteBatchIds(Arrays.asList(postIds));
     }
 
     /**
@@ -149,7 +167,7 @@
      */
     @Override
     public int insertPost(SysPost post) {
-        return postMapper.insertPost(post);
+        return baseMapper.insert(post);
     }
 
     /**
@@ -160,6 +178,6 @@
      */
     @Override
     public int updatePost(SysPost post) {
-        return postMapper.updatePost(post);
+        return baseMapper.updateById(post);
     }
 }

--
Gitblit v1.9.3