提交 efda1d33 authored 作者: inroi's avatar inroi

微调

上级 5ca392e4
...@@ -40,6 +40,8 @@ public class CommonHttpApi { ...@@ -40,6 +40,8 @@ public class CommonHttpApi {
public String mallAddress; public String mallAddress;
public Map<String, Object> header;
public boolean flag = false; public boolean flag = false;
@Autowired @Autowired
...@@ -61,6 +63,10 @@ public class CommonHttpApi { ...@@ -61,6 +63,10 @@ public class CommonHttpApi {
return initConnectParam; return initConnectParam;
} }
public void setHeader(Map<String, Object> header) {
this.header = header;
}
public void setFlag(boolean flag) { public void setFlag(boolean flag) {
this.flag = flag; this.flag = flag;
} }
...@@ -97,7 +103,11 @@ public class CommonHttpApi { ...@@ -97,7 +103,11 @@ public class CommonHttpApi {
public String commonHttpSync(List<Integer> idList) { public String commonHttpSync(List<Integer> idList) {
try { try {
return HttpUtil.httpPost(mallAddress + "api/dataSyn/getSyn", JsonUtil.toString(idList)).getBody(); if (flag) {
return HttpUtil.httpPost(mallAddress + "api/dataSyn/getSyn", header, JsonUtil.toString(idList)).getBody();
} else {
throw new MallCommonException(LOGIN_MESSAGE);
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new MallCommonException(LOGIN_MESSAGE); throw new MallCommonException(LOGIN_MESSAGE);
...@@ -106,7 +116,11 @@ public class CommonHttpApi { ...@@ -106,7 +116,11 @@ public class CommonHttpApi {
public String commonHttpPostByUpdate(String data) { public String commonHttpPostByUpdate(String data) {
try { try {
return HttpUtil.httpPost(mallAddress + "api/dataSyn/success", data).getBody(); if (flag) {
return HttpUtil.httpPost(mallAddress + "api/dataSyn/success", header, data).getBody();
} else {
throw new MallCommonException(LOGIN_MESSAGE);
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new MallCommonException(LOGIN_MESSAGE); throw new MallCommonException(LOGIN_MESSAGE);
...@@ -114,14 +128,15 @@ public class CommonHttpApi { ...@@ -114,14 +128,15 @@ public class CommonHttpApi {
} }
public String commonHttpSyncData(Map<String, String> config, String queueId, String name, List<String> keyList, Map<String, Object> where) { public String commonHttpSyncData(Map<String, String> config, String queueId, String name, List<String> keyList, Map<String, Object> where) {
try {
if (flag) {
Map<String, Object> request = new HashMap<>(3); Map<String, Object> request = new HashMap<>(3);
request.put("form", config.get("sFormId")); request.put("form", config.get("sFormId"));
request.put("fields", String.join(",", keyList)); request.put("fields", String.join(",", keyList));
request.putAll(where); request.putAll(where);
try {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
String response = HttpUtil.httpPost(mallAddress + "api/dataSyn/synData", JsonUtil.toString(request)).getBody(); String response = HttpUtil.httpPost(mallAddress + "api/dataSyn/synData", header, JsonUtil.toString(request)).getBody();
long costTime = System.currentTimeMillis() - start; long costTime = System.currentTimeMillis() - start;
Map<String, Object> map = ThreadLocalConfig.get(); Map<String, Object> map = ThreadLocalConfig.get();
...@@ -130,6 +145,9 @@ public class CommonHttpApi { ...@@ -130,6 +145,9 @@ public class CommonHttpApi {
productLogUtil.productSyncLogCreate(Integer.valueOf(config.get("productId")), queueId, name, config.get("docType"), config.get("direction"), JsonUtil.toString(request), response); productLogUtil.productSyncLogCreate(Integer.valueOf(config.get("productId")), queueId, name, config.get("docType"), config.get("direction"), JsonUtil.toString(request), response);
return response; return response;
} else {
throw new MallCommonException(LOGIN_MESSAGE);
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new MallCommonException(LOGIN_MESSAGE); throw new MallCommonException(LOGIN_MESSAGE);
......
package com.system.controller; package com.system.controller;
import com.system.transfer.configure.InitConnectParamCreateInVo; import com.system.transfer.configure.InitConnectParamCheckInVo;
import com.system.transfer.configure.InitConnectParamRefreshInVo;
import com.system.transfer.response.RestResponse; import com.system.transfer.response.RestResponse;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -16,8 +18,14 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -16,8 +18,14 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/api") @RequestMapping("/api")
public class MallCommonSyncConfigController { public class MallCommonSyncConfigController {
@PostMapping("/init/connect/param/create") @ApiOperation("商城配置刷新")
public RestResponse initConnectParamCreate(@RequestBody InitConnectParamCreateInVo inVo) { @PostMapping("/init/connect/param/refresh")
public RestResponse initConnectParamRefresh(@RequestBody InitConnectParamRefreshInVo inVo) {
return RestResponse.success();
}
@PostMapping("/init/connect/param/check")
public RestResponse initConnectParamCheck(@RequestBody InitConnectParamCheckInVo inVo) {
return RestResponse.success(); return RestResponse.success();
} }
......
package com.system.scheduler; package com.system.scheduler;
import com.system.api.CommonHttpApi; import com.system.api.CommonHttpApi;
import com.system.constants.Constants;
import com.system.model.InitConnectParam; import com.system.model.InitConnectParam;
import com.system.utils.HttpUtil;
import com.system.utils.JsonUtil;
import com.system.utils.StringUtil; import com.system.utils.StringUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.util.CollectionUtils;
import java.util.HashMap;
import java.util.Map;
/** /**
* @author Inori * @author Inori
...@@ -28,24 +36,34 @@ public class MallLoginScheduler { ...@@ -28,24 +36,34 @@ public class MallLoginScheduler {
InitConnectParam initConnectParam = commonHttpApi.getInitConnectParam(); InitConnectParam initConnectParam = commonHttpApi.getInitConnectParam();
if (StringUtil.isNotNull(initConnectParam)) { if (StringUtil.isNotNull(initConnectParam)) {
boolean flag;
try { try {
//TODO 商城登陆 //TODO 商城登陆
flag = true; Map<String, Object> request = new HashMap<>(2);
} catch (Exception e) { request.put("mobile", initConnectParam.getAccount());
flag = false; request.put("password", initConnectParam.getPassword());
log.info("商城登录失败!"); String response = HttpUtil.httpPost(initConnectParam.getMallAddress() + "auth/login_by_mobile", JsonUtil.toString(request)).getBody();
}
if (flag) { Map<String, Object> map = JsonUtil.toMap(response, String.class, Object.class);
if (!CollectionUtils.isEmpty(map)) {
if (map.containsKey(Constants.CODE_NAME) && HttpStatus.OK.value() == Integer.parseInt(String.valueOf(map.get(Constants.CODE_NAME)))) {
Map<String, Object> data = JsonUtil.toMap(JsonUtil.toString(map.get(Constants.DATE_NAME)), String.class, Object.class);
Map<String, Object> header = new HashMap<>(1);
header.put("Authorization", data.get("token"));
commonHttpApi.setHeader(header);
commonHttpApi.setFlag(true);
log.info("商城登录成功!"); log.info("商城登录成功!");
}
} else { } else {
commonHttpApi.setFlag(false);
log.info("商城登录失败!");
}
} catch (Exception e) {
e.printStackTrace();
log.info("商城登录失败!"); log.info("商城登录失败!");
} }
commonHttpApi.setFlag(flag);
} else { } else {
commonHttpApi.setFlag(false); commonHttpApi.setFlag(false);
log.info("商城登录失败!");
} }
} }
......
...@@ -6,7 +6,6 @@ import com.system.mall.MallCommonApi; ...@@ -6,7 +6,6 @@ import com.system.mall.MallCommonApi;
import com.system.serivce.ISynchronizationService; import com.system.serivce.ISynchronizationService;
import com.system.transfer.mall.MallTriggerSynchronizationInVo; import com.system.transfer.mall.MallTriggerSynchronizationInVo;
import com.system.transfer.mall.SynchronizationRecordsListOutVoRecords; import com.system.transfer.mall.SynchronizationRecordsListOutVoRecords;
import com.system.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -61,7 +60,6 @@ public class SynchronizationServiceImpl implements ISynchronizationService { ...@@ -61,7 +60,6 @@ public class SynchronizationServiceImpl implements ISynchronizationService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void synchronization(List<Integer> request) { public void synchronization(List<Integer> request) {
System.out.println("----->" + JsonUtil.toString(request));
List<Map<String, Object>> tempList = mallCommonApi.getSynchronizationRecords(request); List<Map<String, Object>> tempList = mallCommonApi.getSynchronizationRecords(request);
if (!CollectionUtils.isEmpty(tempList)) { if (!CollectionUtils.isEmpty(tempList)) {
......
...@@ -2,34 +2,33 @@ package com.system.transfer.configure; ...@@ -2,34 +2,33 @@ package com.system.transfer.configure;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotBlank;
/** /**
* @author Inori * @author Inori
*/ */
@Data @Data
public class InitConnectParamCreateInVo { public class InitConnectParamCheckInVo {
/** /**
* 商城地址 * 商城地址
*/ */
@NotBlank(message = "参数mallAddress缺失")
private String mallAddress; private String mallAddress;
/** /**
* 用户名 * 用户名
*/ */
@NotBlank(message = "参数account缺失")
private String account; private String account;
/** /**
* 密码 * 密码
*/ */
@NotBlank(message = "参数password缺失")
private String password; private String password;
/**
* 任务时长/分钟
*/
private Integer duration;
} }
package com.system.transfer.configure;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
* @author Inori
*/
@Data
public class InitConnectParamRefreshInVo {
/**
* 商城地址
*/
@NotBlank(message = "参数mallAddress缺失")
private String mallAddress;
/**
* 用户名
*/
@NotBlank(message = "参数account缺失")
private String account;
/**
* 密码
*/
@NotBlank(message = "参数password缺失")
private String password;
/**
* 任务时长/分钟
*/
@NotNull(message = "参数duration缺失")
private Integer duration;
/**
* 接收地址
*/
private String receiveAddress;
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论