From c3ff7417bcc2746016a494f894719c52ea3659a0 Mon Sep 17 00:00:00 2001
From: CZT <czt18638530771@163.com>
Date: 星期一, 26 六月 2023 20:58:56 +0800
Subject: [PATCH] 优化文件接口--分页条件查询

---
 src/main/java/com/fzzy/api/entity/Api1109.java    |    2 
 src/main/java/com/fzzy/api/view/pr/Api1109PR.java |   61 ++++++++++++++++++--
 src/main/java/com/fzzy/api/view/Api1109.view.xml  |   80 ++++++++++++++++++++++++--
 3 files changed, 128 insertions(+), 15 deletions(-)

diff --git a/src/main/java/com/fzzy/api/entity/Api1109.java b/src/main/java/com/fzzy/api/entity/Api1109.java
index 6bf2296..7f6ebfa 100644
--- a/src/main/java/com/fzzy/api/entity/Api1109.java
+++ b/src/main/java/com/fzzy/api/entity/Api1109.java
@@ -17,7 +17,7 @@
 
 public class Api1109 implements Serializable {
 
-
+    public static String SORT_PROP = "id";
     /**
      *
      */
diff --git a/src/main/java/com/fzzy/api/view/Api1109.view.xml b/src/main/java/com/fzzy/api/view/Api1109.view.xml
index 0ecc26a..a3e0704 100644
--- a/src/main/java/com/fzzy/api/view/Api1109.view.xml
+++ b/src/main/java/com/fzzy/api/view/Api1109.view.xml
@@ -62,12 +62,41 @@
         <Property name="dataType">DateTime</Property>
       </PropertyDef>
     </DataType>
+    <DataType name="dtParam">
+        <Property name="creationType">com.fzzy.api.data.ApiParam</Property>
+        <PropertyDef name="kqdm">
+            <Property></Property>
+            <Property name="label">鎵�灞炲簱鍖�</Property>
+        </PropertyDef>
+        <PropertyDef name="start">
+            <Property name="dataType">Date</Property>
+            <Property name="label">寮�濮嬫椂闂�</Property>
+        </PropertyDef>
+        <PropertyDef name="end">
+            <Property name="dataType">Date</Property>
+            <Property name="label">鎴鏃堕棿</Property>
+        </PropertyDef>
+        <PropertyDef name="czbz">
+            <Property></Property>
+            <Property name="label">鎿嶄綔鏍囧織</Property>
+            <Property name="mapping">
+                <Property name="mapValues">${dorado.getDataProvider(&quot;apiTriggerService#trigger&quot;).getResult(&quot;CZBZ&quot;)}</Property>
+                <Property name="keyProperty">code</Property>
+                <Property name="valueProperty">name</Property>
+            </Property>
+        </PropertyDef>
+    </DataType>
   </Model>
   <View layout="regionPadding:10">
     <Property name="packages">font-awesome,css-common</Property>
     <DataSet id="dsMain">
       <Property name="dataType">[dtMain]</Property>
       <Property name="dataProvider">api1109PR#listAll</Property>
+      <Property name="pageSize">20</Property>
+    </DataSet>
+    <DataSet id="dsQuery">
+        <ClientEvent name="onReady">self.insert();</ClientEvent>
+        <Property name="dataType">dtParam</Property>
     </DataSet>
     <ToolBar>
       <ToolBarLabel>
@@ -76,14 +105,14 @@
           <Property name="font-weight">bold</Property>
         </Property>
       </ToolBarLabel>
-      <ToolBarButton>
-        <ClientEvent name="onClick">view.get(&quot;#dsMain&quot;).flushAsync();&#xD;
-</ClientEvent>
-        <Property name="caption">鍒锋柊</Property>
-        <Property name="iconClass">fa fa-search</Property>
-        <Property name="width">100</Property>
-        <Property name="exClassName">toolbar-button-push</Property>
-      </ToolBarButton>
+        <ToolBarButton>
+            <ClientEvent name="onClick">var query = view.get(&quot;#dsQuery&quot;).getData();&#xD;
+                view.get(&quot;#dsMain&quot;).set(&quot;parameter&quot;,query).flushAsync();</ClientEvent>
+            <Property name="caption">鏌ヨ</Property>
+            <Property name="iconClass">fa fa-search</Property>
+            <Property name="width">100</Property>
+            <Property name="exClassName">toolbar-button-push</Property>
+        </ToolBarButton>
       <ToolBarButton>
         <ClientEvent name="onClick">view.get(&quot;#dsMain&quot;).insert();&#xD;
 view.get(&quot;#dialogMain&quot;).show();</ClientEvent>
@@ -165,6 +194,34 @@
         <Property name="exClassName">toolbar-button</Property>
       </ToolBarButton>
     </ToolBar>
+    <AutoForm>
+        <Property name="dataSet">dsQuery</Property>
+        <Property name="cols">*,*,*,*</Property>
+        <Property name="labelAlign">right</Property>
+        <Property name="labelSeparator">锛�</Property>
+        <Property name="labelWidth">90</Property>
+        <AutoFormElement>
+            <Property name="name">kqdm</Property>
+            <Property name="property">kqdm</Property>
+            <Editor/>
+        </AutoFormElement>
+        <AutoFormElement>
+            <Property name="name">start</Property>
+            <Property name="property">start</Property>
+            <Editor/>
+        </AutoFormElement>
+        <AutoFormElement>
+            <Property name="name">end</Property>
+            <Property name="property">end</Property>
+            <Editor/>
+        </AutoFormElement>
+        <AutoFormElement>
+            <Property name="name">czbz</Property>
+            <Property name="property">czbz</Property>
+            <Property name="trigger">autoMappingDropDown2</Property>
+            <Editor/>
+        </AutoFormElement>
+    </AutoForm>
     <DataGrid id="dgMain">
       <Property name="dataSet">dsMain</Property>
       <Property name="selectionMode">multiRows</Property>
@@ -201,6 +258,13 @@
         <Property name="property">zhgxsj</Property>
       </DataColumn>
     </DataGrid>
+    <ToolBar layoutConstraint="bottom">
+        <Fill/>
+        <DataPilot>
+            <Property name="itemCodes">pageSize,pages</Property>
+            <Property name="dataSet">dsMain</Property>
+        </DataPilot>
+    </ToolBar>
     <Dialog id="dialogMain">
       <Property name="width">1000</Property>
       <Property name="caption">鏂囦欢淇℃伅</Property>
diff --git a/src/main/java/com/fzzy/api/view/pr/Api1109PR.java b/src/main/java/com/fzzy/api/view/pr/Api1109PR.java
index f3bd298..c8d1101 100644
--- a/src/main/java/com/fzzy/api/view/pr/Api1109PR.java
+++ b/src/main/java/com/fzzy/api/view/pr/Api1109PR.java
@@ -3,6 +3,7 @@
 import com.bstek.dorado.annotation.DataProvider;
 import com.bstek.dorado.annotation.DataResolver;
 import com.bstek.dorado.annotation.Expose;
+import com.bstek.dorado.data.provider.Page;
 import com.fzzy.api.data.ApiParam;
 import com.fzzy.api.service.ApiCommonService;
 import com.fzzy.api.service.ApiPushManager;
@@ -13,17 +14,23 @@
 import com.fzzy.api.entity.ApiConfs;
 import com.fzzy.api.utils.ContextUtil;
 import com.fzzy.api.view.repository.Api1109Rep;
-
 import lombok.extern.slf4j.Slf4j;
-
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Component;
-
 import sun.misc.BASE64Encoder;
-
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
 import java.io.*;
+import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -50,8 +57,50 @@
 	 * @return
 	 */
 	@DataProvider
-	public List<Api1109> listAll() {
-		return api1109Rep.findAll();
+	public void listAll(Page<Api1109> page, ApiParam param) {
+		//澶氬弬鏁板垎椤垫煡璇�
+		Pageable pageable = PageRequest.of(page.getPageNo() - 1, page.getPageSize(), Sort.Direction.DESC, Api1109.SORT_PROP);
+
+		if (null == param) {
+			org.springframework.data.domain.Page<Api1109> japPage = api1109Rep.findAll(pageable);
+			page.setEntityCount((int) japPage.getTotalElements());
+			page.setEntities(japPage.getContent());
+
+			return;
+		}
+
+		Specification<Api1109> specification = new Specification<Api1109>() {
+			private static final long serialVersionUID = 1L;
+
+			public Predicate toPredicate(Root<Api1109> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
+				List<Predicate> predicates = new ArrayList<Predicate>(); //鎵�鏈夌殑鏂█
+
+				if (StringUtils.isNotBlank(param.getKqdm())) {
+					Predicate predicate1 = cb.equal(root.get("kqdm"), param.getKqdm());
+					predicates.add(predicate1);
+				}
+
+				if (StringUtils.isNotBlank(param.getCzbz())) {
+					Predicate predicate2 = cb.equal(root.get("czbz"), param.getCzbz());
+					predicates.add(predicate2);
+				}
+				if (null != param.getStart()) {
+					Predicate predicate3 = cb.greaterThan(root.<Date>get("qdrq"), ContextUtil.getCurZero(param.getStart()));
+					predicates.add(predicate3);
+				}
+
+				if (null != param.getEnd()) {
+					Predicate predicate4 = cb.lessThan(root.<Date>get("qdrq"), ContextUtil.getNextZero(param.getEnd()));
+					predicates.add(predicate4);
+				}
+				return cb.and(predicates.toArray(new Predicate[0]));
+			}
+		};
+
+		log.debug("---------鍒嗛〉鍙傛暟鏌ヨ----------{}", param.toString());
+		org.springframework.data.domain.Page<Api1109> japPage = api1109Rep.findAll(specification, pageable);
+		page.setEntityCount((int) japPage.getTotalElements());
+		page.setEntities(japPage.getContent());
 	}
 
 	/**

--
Gitblit v1.9.3