|
|
@@ -5,6 +5,7 @@ import com.uas.platform.b2c.prod.product.common.dao.CommonCountDao;
|
|
|
import com.uas.platform.b2c.prod.product.common.model.CommonCount;
|
|
|
import com.uas.platform.core.util.HttpUtil;
|
|
|
import java.util.Date;
|
|
|
+import org.apache.log4j.Logger;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
@@ -24,6 +25,8 @@ public class CommonTask {
|
|
|
|
|
|
private final JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
+ private final Logger logger = Logger.getLogger(getClass());
|
|
|
+
|
|
|
@Autowired
|
|
|
public CommonTask(CommonCountDao commonCountDao, JdbcTemplate jdbcTemplate) {
|
|
|
this.commonCountDao = commonCountDao;
|
|
|
@@ -37,6 +40,7 @@ public class CommonTask {
|
|
|
if (CommonCount.SourceType.HTTP.equals(commonCount.getSourceType())) {
|
|
|
try {
|
|
|
String responseText = HttpUtil.sendGetRequest(commonCount.getSql(), null).getResponseText();
|
|
|
+ logger.info(String.format("commonTask-%s: %s , result: %s", commonCount.getItem(), commonCount.getSql(), responseText));
|
|
|
if (!StringUtils.isEmpty(responseText)) {
|
|
|
if (commonCount.getSql().contains("113.105.74.140:8092")) {
|
|
|
commonCount.setCount(JSON.parseObject(responseText).getDouble("totalCount"));
|
|
|
@@ -45,14 +49,18 @@ public class CommonTask {
|
|
|
} else {
|
|
|
commonCount.setCount(Double.parseDouble(responseText));
|
|
|
}
|
|
|
+ commonCount.setUpdateTime(new Date());
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
+ logger.error(String.format("请求:%s,执行错误:%s", commonCount.getSql(), e.getMessage()));
|
|
|
}
|
|
|
} else {
|
|
|
// 默认,通过执行SQL语句获取数据结果
|
|
|
- commonCount.setCount(jdbcTemplate.queryForObject(commonCount.getSql(), Double.class));
|
|
|
+ Double count = jdbcTemplate.queryForObject(commonCount.getSql(), Double.class);
|
|
|
+ logger.info(String.format("commonTask-%s: %s , result: %s", commonCount.getItem(), commonCount.getSql(), count));
|
|
|
+ commonCount.setCount(count);
|
|
|
+ commonCount.setUpdateTime(new Date());
|
|
|
}
|
|
|
- commonCount.setUpdateTime(new Date());
|
|
|
}
|
|
|
commonCountDao.save(commonCounts);
|
|
|
}
|