2.增加同步华信数据功能 3.修复钢料需求计划导入时由于历史数据需求期为空导致的异常 4.临时修改排产逻辑 5.增加登录账号及ip地址输出到日志中进行记录 6.增加生产环境启动时jpa注入参数master
parent
603ea180df
commit
971e71b59b
@ -0,0 +1,48 @@
|
|||||||
|
package com.dsic.gj_erp.datasync;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
//@Component
|
||||||
|
//@ConfigurationProperties(prefix = "data-sync",ignoreInvalidFields = true)
|
||||||
|
public class Config {
|
||||||
|
|
||||||
|
private String host;
|
||||||
|
private String port;
|
||||||
|
private Map<String,String> uri;
|
||||||
|
|
||||||
|
private Integer tokenExpTime=4*60*60;//token超时时长,默认4个小时
|
||||||
|
|
||||||
|
//发送请求需要携带head名称
|
||||||
|
private String tokenName;
|
||||||
|
private String typeName;
|
||||||
|
private String authType;
|
||||||
|
private String channelCodeName;
|
||||||
|
private String channelCode;
|
||||||
|
private String _channelCodeName;
|
||||||
|
private String _channelCode;
|
||||||
|
private String userCodeName;
|
||||||
|
private String xAuthTokenName;
|
||||||
|
|
||||||
|
//登录账号密码,密码采用md5加密
|
||||||
|
private String account;
|
||||||
|
private String pwd;//已加密,aff462d5872e714dadf9f17109527406
|
||||||
|
|
||||||
|
public String getRequestUrl(String name){
|
||||||
|
return host+":"+port+uri.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String,Object> getLoginFormData(){
|
||||||
|
return new HashMap<String,Object>(){{
|
||||||
|
put("usercode",account);
|
||||||
|
put("passwd",pwd);
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
package com.dsic.gj_erp.datasync;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateField;
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
|
import cn.hutool.core.util.ObjUtil;
|
||||||
|
import cn.hutool.http.HttpUtil;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.context.annotation.DependsOn;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
//@Component
|
||||||
|
@DependsOn("config")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DataHandler {
|
||||||
|
|
||||||
|
private final Config config;
|
||||||
|
private String token;
|
||||||
|
private DateTime expTime;
|
||||||
|
private String userCode;
|
||||||
|
private String xAuthToken;
|
||||||
|
|
||||||
|
public JSONObject execute(String methodName, JSONObject param){
|
||||||
|
if (ObjUtil.isEmpty(expTime)||DateTime.now().after(expTime)){
|
||||||
|
this.getToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
String result = HttpUtil.createPost(config.getRequestUrl(methodName))
|
||||||
|
.header(config.getTokenName(), token)
|
||||||
|
.header(config.getTypeName(), config.getAuthType())
|
||||||
|
.header(config.getChannelCodeName(), config.getChannelCode())
|
||||||
|
.header(config.get_channelCodeName(), config.get_channelCode())
|
||||||
|
.header(config.getXAuthTokenName(), xAuthToken)
|
||||||
|
.header(config.getUserCodeName(), userCode)
|
||||||
|
.body(JSONObject.toJSONString(param))
|
||||||
|
.execute().body();
|
||||||
|
try {
|
||||||
|
return JSONObject.parseObject(result);
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject getToken(){
|
||||||
|
Map<String, Object> loginFormData = config.getLoginFormData();
|
||||||
|
String result = HttpUtil.createPost(config.getRequestUrl(MethodType.login.name()))
|
||||||
|
.header(config.getTypeName(), config.getAuthType())
|
||||||
|
.header(config.getChannelCodeName(), config.getChannelCode())
|
||||||
|
.header(config.get_channelCodeName(), config.get_channelCode())
|
||||||
|
.form(loginFormData)
|
||||||
|
.execute().body();
|
||||||
|
try {
|
||||||
|
JSONObject loginResult = JSONObject.parseObject(result);
|
||||||
|
this.token=loginResult.getString(config.getTokenName());
|
||||||
|
this.expTime =DateTime.now().offset(DateField.SECOND,config.getTokenExpTime()-120);
|
||||||
|
this.xAuthToken=loginResult.getString(config.getXAuthTokenName());
|
||||||
|
this.userCode= (String) loginFormData.get("usercode");
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package com.dsic.gj_erp.datasync;
|
||||||
|
|
||||||
|
public enum MethodType {
|
||||||
|
login
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
package com.dsic.gj_erp.datasync;
|
||||||
|
|
||||||
|
//读取数据用
|
Loading…
Reference in new issue