Commit 8ff8c065 authored by Quxl's avatar Quxl

x

parent f18593ef
...@@ -20,10 +20,11 @@ import com.alibaba.fastjson.JSONObject; ...@@ -20,10 +20,11 @@ import com.alibaba.fastjson.JSONObject;
import com.egolm.sso.clients.ServiceFactory; import com.egolm.sso.clients.ServiceFactory;
import com.egolm.sso.config.XRException; import com.egolm.sso.config.XRException;
import com.egolm.sso.services.CommonService; import com.egolm.sso.services.CommonService;
import com.egolm.sso.services.CommonService.Page;
import com.egolm.sso.util.CollectionUtil; import com.egolm.sso.util.CollectionUtil;
import com.egolm.sso.util.DateUtil; import com.egolm.sso.util.DateUtil;
import com.egolm.sso.util.FileUtil; import com.egolm.sso.util.FileUtil;
import com.egolm.sso.util.SqlUtil;
import com.egolm.sso.util.SqlUtil.Page;
import com.egolm.sso.util.StringUtil; import com.egolm.sso.util.StringUtil;
import com.egolm.sso.util.ThrowableUtil; import com.egolm.sso.util.ThrowableUtil;
import com.egolm.sso.util.XMLUtil; import com.egolm.sso.util.XMLUtil;
...@@ -73,7 +74,7 @@ public class SI004INVENTORYSyncOutServiceTask { ...@@ -73,7 +74,7 @@ public class SI004INVENTORYSyncOutServiceTask {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
List<Map<String, Object>> tmp = null; List<Map<String, Object>> tmp = null;
do { do {
String limitSql = common.limitByMysql(sql, page); String limitSql = SqlUtil.limitByMysql(sql, page);
tmp = jdbcTemplate.queryForList(limitSql); tmp = jdbcTemplate.queryForList(limitSql);
list.addAll(tmp); list.addAll(tmp);
page.toNextPage(); page.toNextPage();
......
...@@ -20,10 +20,11 @@ import com.alibaba.fastjson.JSONObject; ...@@ -20,10 +20,11 @@ import com.alibaba.fastjson.JSONObject;
import com.egolm.sso.clients.ServiceFactory; import com.egolm.sso.clients.ServiceFactory;
import com.egolm.sso.config.XRException; import com.egolm.sso.config.XRException;
import com.egolm.sso.services.CommonService; import com.egolm.sso.services.CommonService;
import com.egolm.sso.services.CommonService.Page;
import com.egolm.sso.util.CollectionUtil; import com.egolm.sso.util.CollectionUtil;
import com.egolm.sso.util.DateUtil; import com.egolm.sso.util.DateUtil;
import com.egolm.sso.util.FileUtil; import com.egolm.sso.util.FileUtil;
import com.egolm.sso.util.SqlUtil;
import com.egolm.sso.util.SqlUtil.Page;
import com.egolm.sso.util.StringUtil; import com.egolm.sso.util.StringUtil;
import com.egolm.sso.util.ThrowableUtil; import com.egolm.sso.util.ThrowableUtil;
import com.egolm.sso.util.XMLUtil; import com.egolm.sso.util.XMLUtil;
...@@ -73,7 +74,7 @@ public class SI011ACTUALSALESSyncOutServiceTask { ...@@ -73,7 +74,7 @@ public class SI011ACTUALSALESSyncOutServiceTask {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
List<Map<String, Object>> tmp = null; List<Map<String, Object>> tmp = null;
do { do {
String limitSql = common.limitByMysql(sql, page); String limitSql = SqlUtil.limitByMysql(sql, page);
tmp = jdbcTemplate.queryForList(limitSql); tmp = jdbcTemplate.queryForList(limitSql);
list.addAll(tmp); list.addAll(tmp);
page.toNextPage(); page.toNextPage();
......
package com.egolm.sso.services; package com.egolm.sso.services;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -120,13 +117,6 @@ public class CommonService { ...@@ -120,13 +117,6 @@ public class CommonService {
return sPrefix + timeString + this.getNextval(sName + "_TRACE_" + dateString); return sPrefix + timeString + this.getNextval(sName + "_TRACE_" + dateString);
} }
public String limitByMysql(String sql, Page page) {
long start = (page.getIndex() - 1) * page.getLimit();
long limit = page.getLimit();
String limitKeys = StringUtil.join(", as_limit.", " order by as_limit.", "", "", page.getLimitKey());
return "select as_limit.* from (" + sql + ") as_limit" + limitKeys + " limit " + start + ", " + limit;
}
@Value("${dataTracking.tokenExpireMinute}") @Value("${dataTracking.tokenExpireMinute}")
private Long tokenExpireMinute; private Long tokenExpireMinute;
private static String token; private static String token;
...@@ -184,149 +174,4 @@ public class CommonService { ...@@ -184,149 +174,4 @@ public class CommonService {
} }
} }
public static class Page implements java.io.Serializable {
private static final long serialVersionUID = 1L;
/**
* 分页页数
*/
protected Long index = 1L;
/**
* 分页大小,即每页数据显示条数
*/
protected Long limit = 50L;
/**
* 数据总条数
*/
protected Long total = 0L;
protected String[] limitKey;
public Page() {
}
public Page(String... limitKey) {
this.limitKey = limitKey;
}
/**
* 构造函数
*
* @param index
* 分页查询的页索引
* @param limit
* 每页显示的条数
*/
public Page(Long index, Long limit) {
this.index = index;
this.limit = limit;
}
public Page(Long index, Long limit, String... limitKey) {
this.index = index;
this.limit = limit;
this.limitKey = limitKey;
}
public Long getIndex() {
Long pageTotal = getPageTotal();
if (index > pageTotal && pageTotal != null && pageTotal != 0) {
index = pageTotal + 1;
}
return index;
}
public Page toNextPage() {
this.index += 1;
return this;
}
public void setIndex(Long index) {
this.index = index;
}
public Long getLimit() {
return limit;
}
public void setLimit(Long limit) {
this.limit = limit;
}
public Long getTotal() {
return total;
}
public void setTotal(Long total) {
this.total = total;
}
/**
* 计算总分页页数
*
* @return
*/
public Long getPageTotal() {
return total % limit == 0 ? (total / limit) : (total / limit + 1);
}
/**
* 计算分页查询开始行的行标
*
* @return 分页查询开始行标
*/
public Long getFirstRowNumber() {
return ((index - 1) * limit) + 1;
}
/**
* 计算分页查询结束行的行标
*
* @return 分页查询结束行标
*/
public Long getLastRowNumber() {
return index * limit;
}
public Long[] getPageIndexs() {
Long lastIndex = this.getPageTotal();
List<Long> list = new ArrayList<Long>();
list.add(index);
Long i = 1L;
Long prefPage = index;
Long nextPage = index;
do {
prefPage = index - i;
nextPage = index + i;
if (prefPage >= 1) {
list.add(0, prefPage);
}
if (nextPage <= lastIndex) {
list.add(nextPage);
}
i++;
} while (list.size() < 6 && (prefPage >= 1 || nextPage <= lastIndex));
return list.toArray(new Long[list.size()]);
}
public String[] getLimitKey() {
return limitKey;
}
public void setLimitKey(String... limitKey) {
if (this.limitKey == null) {
this.limitKey = limitKey;
} else {
List<String> strs = new ArrayList<String>();
strs.addAll(Arrays.asList(this.limitKey));
strs.addAll(Arrays.asList(limitKey));
this.limitKey = strs.toArray(new String[strs.size()]);
}
}
}
} }
...@@ -2,6 +2,7 @@ package com.egolm.sso.util; ...@@ -2,6 +2,7 @@ package com.egolm.sso.util;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -52,6 +53,13 @@ public class SqlUtil { ...@@ -52,6 +53,13 @@ public class SqlUtil {
return new Sql(sql, args.toArray()); return new Sql(sql, args.toArray());
} }
public static String limitByMysql(String sql, Page page) {
long start = (page.getIndex() - 1) * page.getLimit();
long limit = page.getLimit();
String limitKeys = StringUtil.join(", as_limit.", " order by as_limit.", "", "", page.getLimitKey());
return "select as_limit.* from (" + sql + ") as_limit" + limitKeys + " limit " + start + ", " + limit;
}
public static class Sql { public static class Sql {
private String sql; private String sql;
...@@ -78,4 +86,149 @@ public class SqlUtil { ...@@ -78,4 +86,149 @@ public class SqlUtil {
} }
public static class Page implements java.io.Serializable {
private static final long serialVersionUID = 1L;
/**
* 分页页数
*/
protected Long index = 1L;
/**
* 分页大小,即每页数据显示条数
*/
protected Long limit = 50L;
/**
* 数据总条数
*/
protected Long total = 0L;
protected String[] limitKey;
public Page() {
}
public Page(String... limitKey) {
this.limitKey = limitKey;
}
/**
* 构造函数
*
* @param index
* 分页查询的页索引
* @param limit
* 每页显示的条数
*/
public Page(Long index, Long limit) {
this.index = index;
this.limit = limit;
}
public Page(Long index, Long limit, String... limitKey) {
this.index = index;
this.limit = limit;
this.limitKey = limitKey;
}
public Long getIndex() {
Long pageTotal = getPageTotal();
if (index > pageTotal && pageTotal != null && pageTotal != 0) {
index = pageTotal + 1;
}
return index;
}
public Page toNextPage() {
this.index += 1;
return this;
}
public void setIndex(Long index) {
this.index = index;
}
public Long getLimit() {
return limit;
}
public void setLimit(Long limit) {
this.limit = limit;
}
public Long getTotal() {
return total;
}
public void setTotal(Long total) {
this.total = total;
}
/**
* 计算总分页页数
*
* @return
*/
public Long getPageTotal() {
return total % limit == 0 ? (total / limit) : (total / limit + 1);
}
/**
* 计算分页查询开始行的行标
*
* @return 分页查询开始行标
*/
public Long getFirstRowNumber() {
return ((index - 1) * limit) + 1;
}
/**
* 计算分页查询结束行的行标
*
* @return 分页查询结束行标
*/
public Long getLastRowNumber() {
return index * limit;
}
public Long[] getPageIndexs() {
Long lastIndex = this.getPageTotal();
List<Long> list = new ArrayList<Long>();
list.add(index);
Long i = 1L;
Long prefPage = index;
Long nextPage = index;
do {
prefPage = index - i;
nextPage = index + i;
if (prefPage >= 1) {
list.add(0, prefPage);
}
if (nextPage <= lastIndex) {
list.add(nextPage);
}
i++;
} while (list.size() < 6 && (prefPage >= 1 || nextPage <= lastIndex));
return list.toArray(new Long[list.size()]);
}
public String[] getLimitKey() {
return limitKey;
}
public void setLimitKey(String... limitKey) {
if (this.limitKey == null) {
this.limitKey = limitKey;
} else {
List<String> strs = new ArrayList<String>();
strs.addAll(Arrays.asList(this.limitKey));
strs.addAll(Arrays.asList(limitKey));
this.limitKey = strs.toArray(new String[strs.size()]);
}
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment