Commit 60544650 authored by Quxl's avatar Quxl

x

parent dc8d3e69
...@@ -68,7 +68,7 @@ public class SI011ACTUALSALESSyncOutServiceTask { ...@@ -68,7 +68,7 @@ public class SI011ACTUALSALESSyncOutServiceTask {
} }
private void sendData(SI011ACTUALSALESSyncOut SI011ACTUALSALESSyncOut) { private void sendData(SI011ACTUALSALESSyncOut SI011ACTUALSALESSyncOut) {
Page page = new Page(1L, 1000L, new String[] {"DIS_CODE", "TRACE_NO"}); Page page = new Page(1L, 1000L, new String[] {"DIS_CODE", "SALES_NO"});
String sql = "SELECT * FROM t_dis_sales WHERE SEND_STATUS = 'N'"; String sql = "SELECT * FROM t_dis_sales WHERE SEND_STATUS = 'N'";
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;
...@@ -78,7 +78,7 @@ public class SI011ACTUALSALESSyncOutServiceTask { ...@@ -78,7 +78,7 @@ public class SI011ACTUALSALESSyncOutServiceTask {
list.addAll(tmp); list.addAll(tmp);
page.toNextPage(); page.toNextPage();
} while(tmp != null && tmp.size() > 0); } while(tmp != null && tmp.size() > 0);
Map<String, List<Map<String, Object>>> datas = CollectionUtil.toGroupList(list, "DIS_CODE", "TRACE_NO"); Map<String, List<Map<String, Object>>> datas = CollectionUtil.toGroupList(list, "DIS_CODE", "SALES_NO");
for(List<Map<String, Object>> vList : datas.values()) { for(List<Map<String, Object>> vList : datas.values()) {
try { try {
this.sendData(SI011ACTUALSALESSyncOut, vList); this.sendData(SI011ACTUALSALESSyncOut, vList);
......
package com.egolm.sso.services; package com.egolm.sso.services;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
...@@ -8,13 +12,15 @@ import java.util.HashMap; ...@@ -8,13 +12,15 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.bouncycastle.util.encoders.Base64;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DuplicateKeyException; import org.springframework.dao.DuplicateKeyException;
import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.CallableStatementCallback;
import org.springframework.jdbc.core.CallableStatementCreator;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
...@@ -29,7 +35,7 @@ import com.egolm.sso.util.SqlUtil.Sql; ...@@ -29,7 +35,7 @@ import com.egolm.sso.util.SqlUtil.Sql;
import com.egolm.sso.util.StringUtil; import com.egolm.sso.util.StringUtil;
@Service @Service
@Scope(value=ConfigurableBeanFactory.SCOPE_SINGLETON) @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON)
public class CommonService { public class CommonService {
@Autowired @Autowired
...@@ -59,25 +65,46 @@ public class CommonService { ...@@ -59,25 +65,46 @@ public class CommonService {
@Value("${dataTracking.isOpen}") @Value("${dataTracking.isOpen}")
private boolean isOpen; private boolean isOpen;
public Long getNextval(String sName) {
return getNextvalBySql(sName);
}
public Long getNextvalByProc(String sName) {
return this.jdbcTemplate.execute(new CallableStatementCreator() {
public CallableStatement createCallableStatement(Connection connection) throws SQLException {
String storedProc = "{call getNextval(?, ?)}";
CallableStatement cs = connection.prepareCall(storedProc);
cs.setString(1, sName);
cs.registerOutParameter(2, Types.BIGINT);
return cs;
}
}, new CallableStatementCallback<Long>() {
public Long doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
cs.execute();
return cs.getLong(2);
}
});
}
@Transactional(propagation=Propagation.NOT_SUPPORTED) @Transactional(propagation=Propagation.NOT_SUPPORTED)
public synchronized Long getNextval(String sName) { public Long getNextvalBySql(String sName) {
try { try {
Map<String, Object> seqMap = jdbcTemplate.queryForMap("select * from x_sequence where name = ?", sName); Map<String, Object> seqMap = jdbcTemplate.queryForMap("select * from x_sequence where name = ?", sName);
Integer id = (Integer)seqMap.get("id"); Integer id = (Integer) seqMap.get("id");
Long step = (Long)seqMap.get("step"); Long step = (Long) seqMap.get("step");
Long max = (Long)seqMap.get("max"); Long max = (Long) seqMap.get("max");
Long min = (Long)seqMap.get("min"); Long min = (Long) seqMap.get("min");
Long value = (Long)seqMap.get("value"); Long value = (Long) seqMap.get("value");
Long nextValue = value + step; Long nextValue = value + step;
if(value > max || value < min) { if (value > max || value < min) {
throw new XRException(MessageFormat.format("序列已超出许可范围[{0}]", sName)); throw new XRException(MessageFormat.format("序列已超出许可范围[{0}]", sName));
} else { } else {
String sql = "update x_sequence set value = ? where id = ? and value < ?"; String sql = "update x_sequence set value = ? where id = ? and value < ?";
int count = jdbcTemplate.update(sql, nextValue, id, nextValue); int count = jdbcTemplate.update(sql, nextValue, id, nextValue);
if(count == 1) { if (count == 1) {
return value; return value;
} else if(count == 0) { } else if (count == 0) {
return this.getNextval(sName); return this.getNextval(sName);
} else { } else {
throw new XRException(MessageFormat.format("序列错误[{0}]", sName)); throw new XRException(MessageFormat.format("序列错误[{0}]", sName));
...@@ -94,6 +121,10 @@ public class CommonService { ...@@ -94,6 +121,10 @@ public class CommonService {
} }
} }
public static void main(String[] args) {
System.out.println(Long.MAX_VALUE);
}
public String getNextBatch(Date day, String sPrefix, String sName) { public String getNextBatch(Date day, String sPrefix, String sName) {
String dateString = DateUtil.formatDate(day, "yyyyMMdd"); String dateString = DateUtil.formatDate(day, "yyyyMMdd");
sName = sPrefix + "_" + sName + "_" + dateString; sName = sPrefix + "_" + sName + "_" + dateString;
...@@ -107,7 +138,7 @@ public class CommonService { ...@@ -107,7 +138,7 @@ public class CommonService {
return "select as_limit.* from (" + sql + ") as_limit" + limitKeys + " limit " + start + ", " + limit; return "select as_limit.* from (" + sql + ") as_limit" + limitKeys + " limit " + start + ", " + limit;
} }
@Transactional(propagation=Propagation.NOT_SUPPORTED) @Transactional(propagation = Propagation.NOT_SUPPORTED)
public void saveApiAccessLog(String METHOD, String ADDRESS, String RESULT) { public void saveApiAccessLog(String METHOD, String ADDRESS, String RESULT) {
Date now = new Date(); Date now = new Date();
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
...@@ -131,7 +162,8 @@ public class CommonService { ...@@ -131,7 +162,8 @@ public class CommonService {
public String getToken() { public String getToken() {
Date now = new Date(); Date now = new Date();
if(token != null && tokenCreateTime != null && (tokenCreateTime.getTime() + ((tokenExpireMinute-2)*60L*1000L)) > now.getTime()) { if (token != null && tokenCreateTime != null
&& (tokenCreateTime.getTime() + ((tokenExpireMinute - 2) * 60L * 1000L)) > now.getTime()) {
return token; return token;
} }
String requestUrl = baseUrl + tokenUri; String requestUrl = baseUrl + tokenUri;
...@@ -142,7 +174,7 @@ public class CommonService { ...@@ -142,7 +174,7 @@ public class CommonService {
String resultText = HttpUtil.post(requestUrl, parameters, null); String resultText = HttpUtil.post(requestUrl, parameters, null);
JSONObject jsonObject = JSONObject.parseObject(resultText); JSONObject jsonObject = JSONObject.parseObject(resultText);
Boolean isSuccess = jsonObject.getBoolean("success"); Boolean isSuccess = jsonObject.getBoolean("success");
if(isSuccess != null && isSuccess) { if (isSuccess != null && isSuccess) {
tokenCreateTime = now; tokenCreateTime = now;
token = jsonObject.getString("token"); token = jsonObject.getString("token");
return token; return token;
...@@ -151,12 +183,13 @@ public class CommonService { ...@@ -151,12 +183,13 @@ public class CommonService {
} }
} }
public String saveOrderTracking(String traceNo, String orderType, String orderNo, String disCode, String action, String result, String message, String errorMessage) { public String saveOrderTracking(String traceNo, String orderType, String orderNo, String disCode, String action,
if(isOpen) { String result, String message, String errorMessage) {
if (isOpen) {
String requestUrl = baseUrl + insertOrderTrackingUri; String requestUrl = baseUrl + insertOrderTrackingUri;
String token = this.getToken(); String token = this.getToken();
Map<String, String> headers = new HashMap<String, String>(); Map<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", "Bearer "+ token); headers.put("Authorization", "Bearer " + token);
Map<String, Object> parameters = new HashMap<String, Object>(); Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("traceNo", traceNo); parameters.put("traceNo", traceNo);
parameters.put("orderType", orderType); parameters.put("orderType", orderType);
...@@ -173,17 +206,13 @@ public class CommonService { ...@@ -173,17 +206,13 @@ public class CommonService {
public static class TrackingTokenException extends RuntimeException { public static class TrackingTokenException extends RuntimeException {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public TrackingTokenException(String msg) { public TrackingTokenException(String msg) {
super(msg); super(msg);
} }
} }
public static void main(String[] args) { public static class Page implements java.io.Serializable {
String string = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlSWRzIjpbIjM1YmY2NmI4LWQ2NzQtNDNkNy1iNjc3LTc0N2QwMWJhNDZiMyJdLCJ1c2VyX25hbWUiOiJ0cmFuY2UiLCJzY29wZSI6WyJDTElFTlQiXSwiZXhwaXJhdGlvbiI6MTU2NTAwODQ2ODA2NCwiZXhwIjoxNTY1MDA4NDY4LCJhdXRob3JpdGllcyI6WyJ0cmFuY2UiXSwianRpIjoiNGFmMjlhZTItZWJhYy00ZTg5LWExZDAtODUyYWEwZDhkNWM2IiwiY2xpZW50X2lkIjoicGMifQ.cCaEDqpB-yZQp-zmjYAv2igS1IdsjZVd-OT0EOfvdt4";
System.out.println(new String(Base64.decode(string)));
}
public static class Page implements java.io.Serializable{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -204,7 +233,8 @@ public class CommonService { ...@@ -204,7 +233,8 @@ public class CommonService {
protected String[] limitKey; protected String[] limitKey;
public Page() {} public Page() {
}
public Page(String... limitKey) { public Page(String... limitKey) {
this.limitKey = limitKey; this.limitKey = limitKey;
...@@ -212,8 +242,11 @@ public class CommonService { ...@@ -212,8 +242,11 @@ public class CommonService {
/** /**
* 构造函数 * 构造函数
* @param index 分页查询的页索引 *
* @param limit 每页显示的条数 * @param index
* 分页查询的页索引
* @param limit
* 每页显示的条数
*/ */
public Page(Long index, Long limit) { public Page(Long index, Long limit) {
this.index = index; this.index = index;
...@@ -261,14 +294,16 @@ public class CommonService { ...@@ -261,14 +294,16 @@ public class CommonService {
/** /**
* 计算总分页页数 * 计算总分页页数
*
* @return * @return
*/ */
public Long getPageTotal() { public Long getPageTotal() {
return total%limit == 0 ? (total/limit) : (total/limit + 1); return total % limit == 0 ? (total / limit) : (total / limit + 1);
} }
/** /**
* 计算分页查询开始行的行标 * 计算分页查询开始行的行标
*
* @return 分页查询开始行标 * @return 分页查询开始行标
*/ */
public Long getFirstRowNumber() { public Long getFirstRowNumber() {
...@@ -277,6 +312,7 @@ public class CommonService { ...@@ -277,6 +312,7 @@ public class CommonService {
/** /**
* 计算分页查询结束行的行标 * 计算分页查询结束行的行标
*
* @return 分页查询结束行标 * @return 分页查询结束行标
*/ */
public Long getLastRowNumber() { public Long getLastRowNumber() {
...@@ -290,17 +326,17 @@ public class CommonService { ...@@ -290,17 +326,17 @@ public class CommonService {
Long i = 1L; Long i = 1L;
Long prefPage = index; Long prefPage = index;
Long nextPage = index; Long nextPage = index;
do{ do {
prefPage = index - i; prefPage = index - i;
nextPage = index + i; nextPage = index + i;
if(prefPage >= 1) { if (prefPage >= 1) {
list.add(0, prefPage); list.add(0, prefPage);
} }
if(nextPage <= lastIndex) { if (nextPage <= lastIndex) {
list.add(nextPage); list.add(nextPage);
} }
i++; i++;
} while(list.size() < 6 && (prefPage >= 1 || nextPage <= lastIndex)); } while (list.size() < 6 && (prefPage >= 1 || nextPage <= lastIndex));
return list.toArray(new Long[list.size()]); return list.toArray(new Long[list.size()]);
} }
...@@ -309,7 +345,7 @@ public class CommonService { ...@@ -309,7 +345,7 @@ public class CommonService {
} }
public void setLimitKey(String... limitKey) { public void setLimitKey(String... limitKey) {
if(this.limitKey == null) { if (this.limitKey == null) {
this.limitKey = limitKey; this.limitKey = limitKey;
} else { } else {
List<String> strs = new ArrayList<String>(); List<String> strs = new ArrayList<String>();
......
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