Commit 60544650 authored by Quxl's avatar Quxl

x

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