use of org.springframework.scheduling.annotation.Scheduled in project portal by ixinportal.
the class BaiWangTask method submitOrder.
// 1.订单资料推送
@Scheduled(cron = "0 0/7 * * * ?")
public void submitOrder() {
/**
* <REQUEST>
*<HEAD>
*<client_id>企业的 client_id</client_id>
*<access_token>二.1 接口获取到</access_token>
*<openID>二.2 接口获取到</openID>
*</HEAD>
*<BODY>
*<SQM>代办 CA 授权码</SQM>
*<TAXPAYER_NAME>企业名称</TAXPAYER_NAME>
*<SHORT_NAME>企业简称</SHORT_NAME>
*<IS_SZHY>企业证件类型</IS_SZHY>
*<TAX_REGISTER_NO>企业税号</TAX_REGISTER_NO>
*<ENT_PROVINCE>省份</ENT_PROVINCE>
*<ENT_CITY>城市</ENT_CITY>
*<LEGAL_PERSON>企业法人</LEGAL_PERSON>
*<ADDRESS>企业联系地址</ADDRESS>
*<ENT_EMAIL>企业邮箱</ENT_EMAIL>
*<A_NAME>企业联系人姓名</A_NAME>
*<A_MOBILE>企业联系电话</A_MOBILE>
*<A_ID_NO>企业联系人身份证号码</A_ID_NO>
*<A_EINVOICE_DEL>CA 申请表</A_EINVOICE_DEL>
*<A_BIZ_LIC>三证合一/营业执照</A_BIZ_LIC>
*<A_ID_FRONT>企业联系人身份证(正面)</A_ID_FRONT>
*<A_ID_BACK>企业联系人身份证(反面)</A_ID_BACK>
*<TAXPAYER_ID>申请 CA 企业对应唯一编号/当 type=1 时必传</TAXPAYER_ID>
*</BODY>
*</REQUEST>
*"<REQUEST><HEAD>"
*/
synchronized (BaiWangTaskLock) {
// start------------处理双机互斥----------
if (null == taskFlag) {
taskFlag = systemConfigService.isTimedTaskHost();
}
if (taskFlag.equals(false)) {
return;
}
// end------------处理双机互斥----------
if (!isConnection() || !isBaiWangDanJiConnection()) {
initBaiWang();
}
List<ExtraProduct> products = new ArrayList<>();
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus status = null;
try {
// 1.先判断有没有该接口类型的产品,没有则返回
products = extraProductService.getExtraProductBySIN(ComNames.SERVICE_INTERFACE_NAME_BWFPTPT);
if (null == products || products.isEmpty()) {
return;
}
for (ExtraProduct product : products) {
// 筛选是该产品,并且订单状态是3:已支付,待服务商审核,5:服务商审核拒绝 :这两种状态的订单
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("productId", product.getId());
paramMap.put("issubmit", 1);
paramMap.put("desc", 1);
// 2.查找是该产品的订单,并且订单状态是已支付,待服务商审核的订单.然后遍历订单信息
List<Map<String, Object>> Extrabills = sqlSession.selectList("com.itrus.portal.db.ExtraBillMapper.selectByCondition_BAIWANG", paramMap);
if (null == Extrabills || Extrabills.isEmpty()) {
continue;
}
Integer count = 0;
Integer count_danji = 0;
Map<String, String> resultMap = new HashMap<>();
for (Map<String, Object> bill : Extrabills) {
Long id = (Long) bill.get("id");
Boolean is_sendfpt = (Boolean) bill.get("is_sendfpt");
Boolean is_passfpt = (Boolean) bill.get("is_passfpt");
Boolean is_senddj = (Boolean) bill.get("is_senddj");
Boolean is_passdj = (Boolean) bill.get("is_passdj");
Long userinfoId = (Long) bill.get("unique_id");
// 企业信息
Enterprise enterprise = enterpriseService.getEnterpriseById((Long) bill.get("enterprise"));
// 其他附加信息
// 营业执照
BusinessLicense businessLicense = businessService.getBusinessByExtraBillId(id, null);
// 税务登记
TaxRegisterCert taxRegisterCert = taxCertService.getTaxRegisterCertByExtraBillId(id, null);
// 组织机构代码
// OrgCode orgCode = orgCodeService.getOrgCodeByExtraBillId(id, null);
// 代理人
// Agent agent = agentService.getAgentByExtraBillId(id, null);
// 用户
UserInfo userInfo = userInfoService.getUserInfoById(userinfoId);
// 开户行信息
OpenBankInfo openBankInfo = openBankInfoService.getOpenBankInfoByExtraBillId(id, null);
// 法人信息
IdentityCard identityCard = identityCardService.getIdentityCardByExtraBillId(id, null);
Integer type = 0;
Boolean isRefuse = (Boolean) bill.get("is_refuse");
if (null != isRefuse && isRefuse.equals(true)) {
type = 1;
}
// 0:税号 1:信用代码号
Integer credentialsType = null;
if (null != businessLicense && businessLicense.getBusinessType().equals(1)) {
credentialsType = 1;
} else if (null != taxRegisterCert) {
credentialsType = 0;
}
String TAX_REGISTER_NO = credentialsType == 1 ? businessLicense.getLicenseNo() : taxRegisterCert.getCertNo();
// 省份,当省份是几个直辖的或者特区的时候,省和市是一样的
// 北京市110000,天津市120000,上海市310000,重庆市500000,
// 香港,澳门,台湾先不做处理
String province = enterprise.getProvince();
boolean iscity = false;
if (province.equals("110000") || province.equals("120000") || province.equals("310000") || province.equals("500000")) {
iscity = true;
}
province = sysRegionService.getProvince(province);
// 城市
String city = "";
if (iscity) {
city = province;
} else {
city = sysRegionService.getCity(enterprise.getCity());
}
String param2 = "";
// 当没发送过到百旺发票通的时候,则进行发送
if (null == is_sendfpt || is_sendfpt.equals(false)) {
File file = new File(systemConfigService.getTrustDir().getPath() + File.separator + enterprise.getEnterpriseSn());
if (!file.exists()) {
file.mkdir();
}
File imgFile = new File(file, businessLicense.getImgFile());
FileInputStream fis = null;
fis = new FileInputStream(imgFile);
// 三证合一/营业执照
String A_BIZ_LIC = ImageToBase64Utils.GetFileBase64(fis);
// CompressImageUtils.getThumbPicture(A_BIZ_LIC, width, height);
if (A_BIZ_LIC.length() > BAI_WANG_MAX_IMG) {
A_BIZ_LIC = compressImage(A_BIZ_LIC);
}
fis.close();
// +"<A_ID_FRONT>"+"企业联系人身份证(正面)"+"</A_ID_FRONT>"
imgFile = new File(file, identityCard.getFrontImg());
fis = new FileInputStream(imgFile);
String A_ID_FRONT = ImageToBase64Utils.GetFileBase64(fis);
if (A_ID_FRONT.length() > BAI_WANG_MAX_IMG) {
A_ID_FRONT = compressImage(A_ID_FRONT);
}
fis.close();
// 若法人是合并上传的,则传递两张一样的照片过去
String A_ID_BACK = "";
if (StringUtils.isBlank(identityCard.getBackImg())) {
A_ID_BACK = A_ID_FRONT;
} else {
// +"<A_ID_BACK>"+"企业联系人身份证(反面)"+"</A_ID_BACK>"
imgFile = new File(file, identityCard.getBackImg());
fis = new FileInputStream(imgFile);
A_ID_BACK = ImageToBase64Utils.GetFileBase64(fis);
if (A_ID_BACK.length() > BAI_WANG_MAX_IMG) {
A_ID_BACK = compressImage(A_ID_BACK);
}
fis.close();
}
// +"<TAXPAYER_ID>"+"申请 CA 企业对应唯一编号/当 type=1 时必传"+"</TAXPAYER_ID>"
String TAXPAYER_ID = "";
if (type == 1) {
TAXPAYER_ID = bill.get("taxpayer_id").toString();
}
// 2.根据产品信息,去筛选企业信息.
// HTTPS 请求方式 POST 请求
// 1:type 0:代表 CA 新申请, 1: 新申请被驳回, 而再次推送修改过后的资料操作
// 服务商是否曾经拒绝过该订单,如果拒绝过.则为true;再次提交给服务商的时候,先判断这个值,如果为true,则进行特殊处理,发送之后,修改该值为false
// field boolean --fieldName isRefuse
// https://ip:port/Entoauth/thirdInvoiceService?sign=caApply&type=&xml=
param2 = "<REQUEST><HEAD>" + "<client_id>" + client_id + "</client_id>" + "<access_token>" + access_token + "</access_token>" + "<openID>" + openID + "</openID>" + "</HEAD>" + "<BODY>" + "<SQM>" + SQM + "</SQM>" + "<TAXPAYER_NAME>" + enterprise.getEnterpriseName() + "</TAXPAYER_NAME>" + "<SHORT_NAME>" + enterprise.getShortName() + "</SHORT_NAME>" + // 0:税号 1:信用代码号
"<IS_SZHY>" + credentialsType + "</IS_SZHY>" + // 企业税号或者企业三证合一之后的社会信用代码
"<TAX_REGISTER_NO>" + TAX_REGISTER_NO + "</TAX_REGISTER_NO>" + "<ENT_PROVINCE>" + province + "</ENT_PROVINCE>" + "<ENT_CITY>" + city + "</ENT_CITY>" + "<LEGAL_PERSON>" + identityCard.getName() + "</LEGAL_PERSON>" + "<ADDRESS>" + businessLicense.getBusinessPlace() + "</ADDRESS>" + "<ENT_EMAIL>" + bill.get("email").toString() + "</ENT_EMAIL>" + "<A_NAME>" + userInfo.getRealName() + "</A_NAME>" + "<A_MOBILE>" + bill.get("m_phone").toString() + "</A_MOBILE>" + "<A_ID_NO>" + identityCard.getIdCode() + "</A_ID_NO>" + "<A_EINVOICE_DEL></A_EINVOICE_DEL>" + "<A_BIZ_LIC>" + A_BIZ_LIC + "</A_BIZ_LIC>" + "<A_ID_FRONT>" + A_ID_FRONT + "</A_ID_FRONT>" + "<A_ID_BACK>" + A_ID_BACK + "</A_ID_BACK>" + "<TAXPAYER_ID>" + TAXPAYER_ID + "</TAXPAYER_ID>" + "</BODY>" + "</REQUEST>";
String param = URLEncoder.encode(new String(Base64.encode(param2.getBytes())), "UTF-8");
LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
// https://ip:port/Entoauth/thirdInvoiceService?sign=caApply&type=&xml=
// String urlAccessToken = baseUrl + "thirdInvoiceService?sign=caApply"
// + "&type=" + type + "&xml=" + param;
String urlAccessToken = baseUrl + "thirdInvoiceService";
URI uri;
uri = new URI(urlAccessToken);
map.add("sign", "caApply");
map.add("type", type);
map.add("xml", param);
String xml = restTemplate.postForObject(uri, map, String.class);
resultMap = parseXml(xml);
String recode = resultMap.get("REPLYCODE");
if (StringUtils.isNotBlank(recode) && recode.equals("0000")) {
ExtraBill extraBill = extraBillService.selectByPrimaryKey(id);
extraBill.setIsSendfpt(true);
// 两个平台都成功送审之后,订单状态改为服务商审核中
if (null != extraBill.getIsSenddj() && extraBill.getIsSenddj().equals(true)) {
extraBill.setBillStatus(ComNames.EXTRA_BILL_STATUS_4);
}
extraBill.setTaxpayerId(resultMap.get("TAXPAYER_ID").toString());
if (type == 1) {
// 曾经拒绝过的订单,再次推送成功
extraBill.setIsRefuse(false);
}
status = transactionManager.getTransaction(def);
extraBillService.updateByPrimaryKeySelective(extraBill);
transactionManager.commit(status);
count++;
} else {
log.error("推送订单失败_百旺发票通", "订单号:" + bill.get("bill_id").toString() + "错误码:" + resultMap.get("REPLYCODE") + "错误信息:" + resultMap.get("REPLYMSG") + ", 参数:" + param2);
LogUtil.syslog(sqlSession, "推送订单失败_百旺发票通", "订单号:" + bill.get("bill_id").toString() + "错误码:" + resultMap.get("REPLYCODE") + "错误信息:" + resultMap.get("REPLYMSG"));
}
}
// 当没发送到百旺单机的时候,重新发送
if (null == is_senddj || is_senddj.equals(false)) {
StringBuffer stringBuffer = new StringBuffer();
/**
* <?xml version="1.0" encoding="utf-8"?>
* <business comment="注册申请" id="ZCSQ">
* <body>
* <login_name><![CDATA[itruschina]]></login_name>
* <passwd><![CDATA[12345678]]></passwd>
* <skpbh><![CDATA[ceshi2017071311222333]]></skpbh>
* <nsrsbh><![CDATA[911101088020176222333]]></nsrsbh>
* <nsrmc><![CDATA[北京天威诚信电子商务服务有限公司测试070333]]></nsrmc>
* <city><![CDATA[北京市]]></city>
* <kh_usr_name><![CDATA[张三]]></kh_usr_name>
* <kh_lxdh><![CDATA[18878996333]]></kh_lxdh>
* <sfsy><![CDATA[1]]></sfsy>
* <bz><![CDATA[123]]></bz>
* <sqr_usr_name><![CDATA[何冠宏]]></sqr_usr_name>
* <sqr_lxdh><![CDATA[18878991333]]></sqr_lxdh>
* <sqr_ssgs><![CDATA[北京天威诚信电子商务服务有限公司]]></sqr_ssgs>
* <sfsf><![CDATA[1]]></sfsf>
* <sfje><![CDATA[0]]></sfje>
* </body>
* </business>
*/
stringBuffer.append("<?xml version='1.0' encoding='utf-8'?>");
stringBuffer.append("<business comment='注册申请' id='ZCSQ'>");
stringBuffer.append("<body>");
stringBuffer.append("<login_name><![CDATA[" + dan_ji_userName + "]]></login_name>");
stringBuffer.append("<passwd><![CDATA[" + dan_ji_passWord + "]]></passwd>");
stringBuffer.append("<skpbh><![CDATA[" + openBankInfo.getTaxNumber() + "]]></skpbh>");
stringBuffer.append("<nsrsbh><![CDATA[" + enterprise.getNsrsbh() + "]]></nsrsbh>");
stringBuffer.append("<nsrmc><![CDATA[" + enterprise.getEnterpriseName() + "]]></nsrmc>");
stringBuffer.append("<city><![CDATA[" + city + "]]></city>");
stringBuffer.append("<kh_usr_name><![CDATA[" + userInfo.getRealName() + "]]></kh_usr_name>");
stringBuffer.append("<kh_lxdh><![CDATA[" + bill.get("m_phone").toString() + "]]></kh_lxdh>");
// 试用就是1 ,正式就用0.这个是针对客户端是否试用的
stringBuffer.append("<sfsy><![CDATA[0]]></sfsy>");
stringBuffer.append("<bz><![CDATA[" + bill.get("bill_id").toString() + "]]></bz>");
stringBuffer.append("<sqr_usr_name><![CDATA[" + "王晓雪" + "]]></sqr_usr_name>");
stringBuffer.append("<sqr_lxdh><![CDATA[" + "13120460901" + "]]></sqr_lxdh>");
stringBuffer.append("<sqr_ssgs><![CDATA[" + "北京天威诚信电子商务服务有限公司" + "]]></sqr_ssgs>");
stringBuffer.append("<sfsf><![CDATA[1]]></sfsf>");
stringBuffer.append("<sfje><![CDATA[0]]></sfje>");
stringBuffer.append("</body>");
stringBuffer.append("</business>");
try {
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost(dan_ji_url, dan_ji_port, dan_ji_protocol);
HttpMethod method = null;
PostMethod post = new PostMethod("/fpfw/api/kpbusiness");
NameValuePair bw = new NameValuePair("bw", stringBuffer.toString());
NameValuePair[] nameValuePairs = { bw };
post.setRequestBody(nameValuePairs);
method = post;
client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
client.executeMethod(method);
String xml = new String(method.getResponseBodyAsString().getBytes("UTF-8"));
resultMap = parseXml(xml);
String returncode = resultMap.get("returncode");
if (StringUtils.isNotBlank(returncode) && returncode.equals("0")) {
ExtraBill extraBill = extraBillService.selectByPrimaryKey(id);
extraBill.setIsSenddj(true);
// 两个平台都成功送审之后,订单状态改为服务商审核中
if (null != extraBill.getIsSendfpt() && extraBill.getIsSendfpt().equals(true)) {
extraBill.setBillStatus(ComNames.EXTRA_BILL_STATUS_4);
}
status = transactionManager.getTransaction(def);
extraBillService.updateByPrimaryKeySelective(extraBill);
transactionManager.commit(status);
count_danji++;
} else {
/**
* 现在是<?xml version='1.0' encoding='utf-8'?><business version='1.0'><head></head><body><returncode>3</returncode><returnmsg>xml解析错误</returnmsg></body></business>
*/
log.error("推送订单失败_百旺单机", "订单号:" + bill.get("bill_id").toString() + "错误码:" + resultMap.get("returncode") + ", 错误信息:" + resultMap.get("returnmsg") + ", 参数:" + stringBuffer.toString());
LogUtil.syslog(sqlSession, "推送订单失败_百旺单机", "订单号:" + bill.get("bill_id").toString() + "错误码:" + resultMap.get("returncode") + ", 错误信息:" + resultMap.get("returnmsg"));
}
} catch (Exception e) {
e.printStackTrace();
log.error("推送订单失败_百旺单机", "订单号:" + bill.get("bill_id").toString() + "错误信息:" + e.getMessage() + ", 参数:" + stringBuffer.toString());
LogUtil.syslog(sqlSession, "推送订单失败_百旺单机", "订单号:" + bill.get("bill_id").toString() + "错误信息:" + e.getMessage());
continue;
}
}
}
LogUtil.syslog(sqlSession, "推送订单_百旺", "总共:" + Extrabills.size() + "条,发票通成功:" + count + "条, 单机成功:" + count_danji + "条");
}
} catch (Exception e) {
LogUtil.syslog(sqlSession, "推送订单失败_百旺", "错误信息:" + e.getMessage());
e.printStackTrace();
} finally {
if (status != null && !status.isCompleted()) {
transactionManager.rollback(status);
}
}
}
}
use of org.springframework.scheduling.annotation.Scheduled in project portal by ixinportal.
the class ChargingFailTask method ChargingAgain.
/**
* 遍历所有计费失败的记录,重新计费
*
* @Scheduled(fixedRate = 1000 * 60 * 60 * 24) 设置为每天凌晨2点触发
* @Scheduled(cron = "0 0 2 * * ?")
*/
@Scheduled(cron = "0 0/45 * * * ?")
public void ChargingAgain() {
// start------------处理双机互斥----------
// 系统是否配置同步任务的主机名
SysConfig sysConfigHost = sqlSession.selectOne("com.itrus.portal.db.SysConfigMapper.selectByType", "raInfoHost");
if (null == sysConfigHost) {
// 没有配置,直接返回
return;
}
String host = sysConfigHost.getConfig();
host = host.replaceAll(" ", "");
String[] hosts = host.split(",");
// 获取本机主机名称
InetAddress ia = null;
try {
ia = ia.getLocalHost();
} catch (UnknownHostException e1) {
e1.printStackTrace();
return;
}
String hostName = ia.getHostName();
boolean flag_check = false;
for (String str : hosts) {
if (hostName.equals(str.replaceAll(" ", ""))) {
flag_check = true;
}
}
// 判断本地主机名称是否与系统配置的同步主机名称一致,不一致则返回
if (!flag_check) {
return;
}
// end------------处理双机互斥----------
List<ChargingFail> chargingFails = chargingFailService.geChargingFails();
if (null == chargingFails || chargingFails.size() == 0) {
return;
}
for (int i = 0; i < chargingFails.size(); i++) {
ChargingFail chargingFail = chargingFails.get(i);
Map<String, Object> retMap = new HashMap<String, Object>();
ApplicationInfo applicationInfo = certificationChargingService.getApplicationInfoByAppId(chargingFail.getAppId());
AppService appService = certificationChargingService.getAppServiceByAppServiceId(chargingFail.getAppServiceId());
retMap = certificationChargingService.charging(chargingFail.getAppId(), chargingFail.getAppServiceId(), chargingFail.getTransinfoName(), chargingFail.getTransinfoId(), applicationInfo, appService, chargingFail.getTransinfoPrimaryId(), chargingFail.getTransinfoTableName());
Integer flag = (Integer) retMap.get("retCode");
// 若插入成功
if (null != flag && flag == 1) {
chargingFail.setIsValidity(false);
chargingFail.setModifyTime(new Date());
Charging charging = (Charging) retMap.get("charging");
chargingFail.setChargingId(charging.getChargingId());
chargingFailService.update(chargingFail);
}
}
}
use of org.springframework.scheduling.annotation.Scheduled in project portal by ixinportal.
the class ChargingRuleTask method setChargingRuleToInvalid.
/**
* 定时任务,将过期的计费规则置为无效
*
* @Scheduled(fixedRate = 1000 * 60 * 60 * 24)
* @Scheduled(cron = "0 0 2 * * ?")设置为每天凌晨2点触发
*/
@Scheduled(cron = "0 0/35 * * * ?")
public void setChargingRuleToInvalid() {
// start------------处理双机互斥----------
// 系统是否配置同步任务的主机名
SysConfig sysConfigHost = sqlSession.selectOne("com.itrus.portal.db.SysConfigMapper.selectByType", "raInfoHost");
if (null == sysConfigHost) {
// 没有配置,直接返回
return;
}
String host = sysConfigHost.getConfig();
host = host.replaceAll(" ", "");
String[] hosts = host.split(",");
// 获取本机主机名称
InetAddress ia = null;
try {
ia = ia.getLocalHost();
} catch (UnknownHostException e1) {
e1.printStackTrace();
return;
}
String hostName = ia.getHostName();
boolean flag_check = false;
for (String str : hosts) {
if (hostName.equals(str.replaceAll(" ", ""))) {
flag_check = true;
}
}
// 判断本地主机名称是否与系统配置的同步主机名称一致,不一致则返回
if (!flag_check) {
return;
}
// end------------处理双机互斥----------
CertificationChargingExample cce = new CertificationChargingExample();
CertificationChargingExample.Criteria criteria = cce.or();
Date now = new Date();
criteria.andEndTimeLessThan(now);
List<CertificationCharging> list = certificationChargingService.selectByExample(cce);
if (null != list && list.size() > 0) {
List<ServiceName> serviceNames = serviceNameService.selectListByCertificationChargings(list);
if (null != serviceNames && serviceNames.size() > 0) {
for (ServiceName serviceName : serviceNames) {
if (serviceName.getIsValidity() == true) {
serviceName.setIsValidity(false);
serviceNameService.update(serviceName);
LogUtil.syslog(sqlSession, "将计费规则置为无效", "计费规则id为:" + serviceName.getCertificationCharging() + ", 服务表id为:" + serviceName.getId());
}
}
}
}
}
use of org.springframework.scheduling.annotation.Scheduled in project jhipster-registry by jhipster.
the class ZuulUpdaterService method updateZuulRoutes.
@Scheduled(fixedDelay = 5_000)
public void updateZuulRoutes() {
boolean isDirty = false;
List<Application> applications = EurekaServerContextHolder.getInstance().getServerContext().getRegistry().getApplications().getRegisteredApplications();
for (Application application : applications) {
for (InstanceInfo instanceInfos : application.getInstances()) {
if (!instanceInfos.getStatus().equals(InstanceInfo.InstanceStatus.UP) && !instanceInfos.getStatus().equals(InstanceInfo.InstanceStatus.STARTING))
continue;
String instanceId = instanceInfos.getId();
String url = instanceInfos.getHomePageUrl();
log.debug("Checking instance {} - {} ", instanceId, url);
ZuulRouteDTO route = new ZuulRouteDTO(instanceId, application.getName().toLowerCase() + "/" + instanceId + "/**", null, url, zuulProperties.isStripPrefix(), zuulProperties.getRetryable(), null, instanceInfos.getStatus().toString());
if (zuulProperties.getRoutes().containsKey(instanceId)) {
log.debug("Instance '{}' already registered", instanceId);
if (!zuulProperties.getRoutes().get(instanceId).getUrl().equals(url) || !((ZuulRouteDTO) zuulProperties.getRoutes().get(instanceId)).getStatus().equals(instanceInfos.getStatus().toString())) {
log.debug("Updating instance '{}' with new URL: {}", instanceId, url);
zuulProperties.getRoutes().put(instanceId, route);
isDirty = true;
}
} else {
log.debug("Adding instance '{}' with URL: {}", instanceId, url);
zuulProperties.getRoutes().put(instanceId, route);
isDirty = true;
}
}
}
List<String> zuulRoutesToRemove = new ArrayList<>();
for (String key : zuulProperties.getRoutes().keySet()) {
if (applications.stream().flatMap(application -> application.getInstances().stream()).filter(instanceInfo -> instanceInfo.getId().equals(key)).count() == 0) {
log.debug("Removing instance '{}'", key);
zuulRoutesToRemove.add(key);
isDirty = true;
}
}
for (String key : zuulRoutesToRemove) {
zuulProperties.getRoutes().remove(key);
}
if (isDirty) {
log.info("Zuul routes have changed - refreshing the configuration");
this.publisher.publishEvent(new RoutesRefreshedEvent(routeLocator));
}
}
use of org.springframework.scheduling.annotation.Scheduled in project microservices by pwillhan.
the class YahooFeedJob method runYahooFeedService.
@Scheduled(fixedDelayString = "${com.cassandrawebtrader.fixedrate}")
public void runYahooFeedService() throws InterruptedException {
Boolean isRun = Boolean.valueOf(env.getProperty("com.cassandrawebtrader.runYahooFeedService").toUpperCase());
if (isRun) {
Integer sometime = Integer.valueOf(env.getProperty("com.cassandrawebtrader.sleep"));
String watchlistcode = env.getProperty("com.cassandrawebtrader.watchlistcode");
List<Watchlist> watchlists = (List<Watchlist>) watchlistRepository.findByWatchlistCode(watchlistcode);
for (Watchlist watchlist : watchlists) {
logger.info("Start getting " + watchlist.getSymbol() + " data.");
yahooFeedService.getData(watchlist.getSymbol());
logger.info("Finish getting " + watchlist.getSymbol() + " data.");
logger.info("Start scanning " + watchlist.getSymbol() + " data.");
scannerService.scan(watchlist.getSymbol());
logger.info("Finish scanning " + watchlist.getSymbol() + " data.");
Thread.sleep(sometime);
}
}
}
Aggregations