Browse Source

Signed-off-by: Lgx <361400959>

Lgx 4 years ago
parent
commit
0cc857bfd9

+ 10 - 4
src/main/java/com/github/binarywang/demo/wx/cp/controller/ExternalUserController.java

@@ -6,22 +6,22 @@ import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
+import com.baomidou.mybatisplus.plugins.Page;
 import com.github.binarywang.demo.wx.cp.model.ExternalMobileExcel;
 import com.github.binarywang.demo.wx.cp.model.ExternalUser;
 import com.github.binarywang.demo.wx.cp.model.ExternalUserExcel;
 import com.github.binarywang.demo.wx.cp.service.impl.ExternalMobileService;
 import com.github.binarywang.demo.wx.cp.service.impl.ExternalUserService;
 import com.github.binarywang.demo.wx.cp.utils.ExcelUtils;
+import com.github.binarywang.demo.wx.cp.utils.FiltersData;
 import com.github.binarywang.demo.wx.cp.utils.ResultObject;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 import com.alibaba.fastjson.JSON;
 
@@ -166,5 +166,11 @@ public class ExternalUserController {
         return count;
     }
 
+    @ResponseBody
+    @RequestMapping(value = "/getExternalUserList", method = RequestMethod.POST)
+    public Map<String,Object> getExternalUserList(@RequestBody FiltersData data){
+        return externalUserService.queryExternalList(data);
+    }
+
 
 }

+ 8 - 0
src/main/java/com/github/binarywang/demo/wx/cp/dao/foo/ExternalUserMapper.java

@@ -1,11 +1,13 @@
 package com.github.binarywang.demo.wx.cp.dao.foo;
 
 import com.baomidou.mybatisplus.mapper.BaseMapper;
+import com.baomidou.mybatisplus.plugins.Page;
 import com.github.binarywang.demo.wx.cp.model.ExternalUser;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 
+import java.awt.print.Pageable;
 import java.util.List;
 
 @Mapper
@@ -14,5 +16,11 @@ public interface ExternalUserMapper extends BaseMapper<ExternalUser> {
     @Select("SELECT count(1) FROM external_user where is_delete=1 and remark_mobiles= #{mobile}")
     int getExternalUserCount(@Param("mobile")String mobile);
 
+    @Select("SELECT * from (select  row_number() over (  order by u.createtime DESC)  as rownum,u.* from external_user u  ${sqlStr}) A where A.rownum>#{index} AND A.rownum<#{size} ")
+    List<ExternalUser> queryExternalList(@Param("sqlStr")String sqlStr, @Param("index")Integer index,@Param("size")Integer size);
+
+    @Select("select count(1) from external_user u ${sqlStr} ")
+    int queryExternalCount(@Param("sqlStr")String sqlStr);
+
     int InsertExternalUser(@Param("externalUser") ExternalUser externalUser);
 }

+ 4 - 0
src/main/java/com/github/binarywang/demo/wx/cp/service/IExternalUserService.java

@@ -1,11 +1,15 @@
 package com.github.binarywang.demo.wx.cp.service;
 
+import com.baomidou.mybatisplus.plugins.Page;
 import com.baomidou.mybatisplus.service.IService;
 import com.github.binarywang.demo.wx.cp.model.ExternalUser;
+import com.github.binarywang.demo.wx.cp.utils.FiltersData;
 
 import java.util.List;
+import java.util.Map;
 
 public interface IExternalUserService extends IService<ExternalUser> {
      Integer updateExternalUser(ExternalUser externalUser);
      Integer getExternalCount(String mobile);
+     Map<String,Object> queryExternalList(FiltersData data);
 }

+ 22 - 0
src/main/java/com/github/binarywang/demo/wx/cp/service/impl/ExternalUserService.java

@@ -1,5 +1,6 @@
 package com.github.binarywang.demo.wx.cp.service.impl;
 
+import com.baomidou.mybatisplus.plugins.Page;
 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
 import com.github.binarywang.demo.wx.cp.dao.foo.ExternalUserMapper;
 import com.github.binarywang.demo.wx.cp.dao.foo.TokenMapper;
@@ -7,6 +8,8 @@ import com.github.binarywang.demo.wx.cp.model.ExternalUser;
 import com.github.binarywang.demo.wx.cp.model.Token;
 import com.github.binarywang.demo.wx.cp.service.IExternalUserService;
 import com.github.binarywang.demo.wx.cp.service.ITokenService;
+import com.github.binarywang.demo.wx.cp.utils.FiltersData;
+import com.github.binarywang.demo.wx.cp.utils.FiltersUtils;
 import org.apache.ibatis.annotations.Param;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -14,7 +17,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
@@ -33,4 +38,21 @@ public class ExternalUserService extends ServiceImpl<ExternalUserMapper, Externa
     public Integer getExternalCount(String mobile) {
         return this.baseMapper.getExternalUserCount(mobile);
     }
+
+    @Override
+    public Map<String,Object> queryExternalList(FiltersData data) {
+        Map<String,Object> map=new HashMap<String,Object>();
+        int start = (data.getPageIndex()-1) * data.getPageSize();
+        int end = (start + 1 + data.getPageSize());
+        //动态条件
+        String sqlStr=data.getFilterString();
+        Integer totalCount=0;
+        List<ExternalUser> list = this.baseMapper.queryExternalList(sqlStr,start,end);
+        if(list!=null && list.size()>0){
+            totalCount=this.baseMapper.queryExternalCount(sqlStr);
+            map.put("items",list);
+            map.put("totalCount",totalCount);
+        }
+        return map;
+    }
 }

+ 134 - 0
src/main/java/com/github/binarywang/demo/wx/cp/utils/FiltersData.java

@@ -0,0 +1,134 @@
+package com.github.binarywang.demo.wx.cp.utils;
+
+
+import freemarker.template.utility.StringUtil;
+
+import java.util.List;
+import java.util.Map;
+
+public class FiltersData {
+
+    private int pageIndex;
+    private int pageSize;
+    private List<FiltersUtils> filters;
+
+    private Integer sortDirection;
+
+    private String sortField;
+
+    public int getPageIndex() {
+        return pageIndex;
+    }
+
+    public void setPageIndex(int pageIndex) {
+        this.pageIndex = pageIndex;
+    }
+
+    public int getPageSize() {
+        return pageSize;
+    }
+
+    public void setPageSize(int pageSize) {
+        this.pageSize = pageSize;
+    }
+
+    public List<FiltersUtils> getFilters() {
+        return filters;
+    }
+
+    public void setFilters(List<FiltersUtils> filters) {
+        this.filters = filters;
+    }
+
+    public Integer getSortDirection() {
+        return sortDirection;
+    }
+
+    public void setSortDirection(Integer sortDirection) {
+        this.sortDirection = sortDirection;
+    }
+
+    public String getSortField() {
+        return sortField;
+    }
+
+    public void setSortField(String sortField) {
+        this.sortField = sortField;
+    }
+
+    public  String getFilterString() {
+        String queryCondition = " where 1=1 ";
+        if (this.getFilters() != null) {
+            for (FiltersUtils item : this.getFilters()) {
+                if (item != null && (item.getValue()!=null || (item.getRules() != null && item.getRules().size() > 0))) {
+                    String val = item.getValue();
+                    String field = item.getField();
+                    String operate = item.getOperate();
+                    switch (operate) {
+                        case "equal":
+                            queryCondition += " and " + field + "=  '" + val + "'";
+                            break;
+                        case "notequal":
+                            queryCondition += " and " + field + "!=  '" + val+"'";
+
+                            break;
+                        case "less":
+                            queryCondition += " and " + field + "< '" + val+"'";
+
+                            break;
+                        case "lessorequal":
+                            queryCondition += " and " + field + "<= '" + val+"'";
+
+                            break;
+                        case "greater":
+                            queryCondition += " and " + field + "> '" + val+"'";
+
+                            break;
+                        case "greaterorequal":
+                            queryCondition += " and " + field + ">= '" + val+"'";
+
+                            break;
+                        case "contains":
+                            queryCondition += " and " + field + " like '%" + val + "%'";
+
+                            break;
+                        case "startswith":
+                            queryCondition += " and " + field + " >='" + val + "'";
+
+                            break;
+                        case "endswith":
+                            queryCondition += " and " + field + " <= '" + val + "'";
+
+                            break;
+                        case "or":
+                            String innerCondition = "1 = 1";
+                            List<Map<String, Object>> rulesMap = item.getRules();
+                            for (Map<String, Object> stringObjectMap : rulesMap) {
+                                String rulesField = (String) stringObjectMap.get("field");
+                                String rulesValue = (String) stringObjectMap.get("value");
+                                innerCondition += " or "+rulesField+" = '"+rulesValue+"'";
+                            }
+
+                            innerCondition = innerCondition.replace("1 = 1 or", "");
+                            queryCondition += " and (" + innerCondition + ")";
+
+                            break;
+                        case "nestand":
+                            String innerConditionNest = "1 = 1";
+                            List<Map<String, Object>> rules = item.getRules();
+                            for (Map<String, Object> stringObjectMap : rules) {
+                                String rulesField = (String) stringObjectMap.get("field");
+                                String rulesvalue = (String) stringObjectMap.get("value");
+                                innerConditionNest += " and "+rulesField+" = '"+rulesvalue+"'";
+                            }
+                            innerConditionNest = innerConditionNest.replace("1 = 1 and", "");
+                            queryCondition += " and (" + innerConditionNest + ")";
+
+                            break;
+                    }
+                }
+            }
+        }
+        return queryCondition;
+    }
+}

+ 44 - 0
src/main/java/com/github/binarywang/demo/wx/cp/utils/FiltersUtils.java

@@ -0,0 +1,44 @@
+package com.github.binarywang.demo.wx.cp.utils;
+
+
+import java.util.List;
+import java.util.Map;
+
+public class FiltersUtils {
+
+    //查询添加
+    private String field;
+    private String operate;
+    private String value;
+    private List<Map<String, Object>> rules;
+
+
+    public List<Map<String, Object>> getRules() {return rules;}
+
+    public void setRules(List<Map<String, Object>> rules) {this.rules = rules;}
+
+
+    public String getField() {
+        return field;
+    }
+
+    public void setField(String field) {
+        this.field = field;
+    }
+
+    public String getOperate() {
+        return operate;
+    }
+
+    public void setOperate(String operate) {
+        this.operate = operate;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+}