package com.fzzy.push.gd2020;
|
|
import com.alibaba.fastjson.JSON;
|
import com.fzzy.api.Constant;
|
import com.fzzy.api.data.ApiParam;
|
import com.fzzy.api.data.AuthToken;
|
import com.fzzy.api.data.PushProtocol;
|
import com.fzzy.api.dto.ResponseDto;
|
import com.fzzy.api.entity.*;
|
import com.fzzy.api.service.ApiCommonService;
|
import com.fzzy.api.service.ApiRemoteService;
|
import com.fzzy.api.utils.*;
|
import com.fzzy.api.view.repository.ApiLogRep;
|
import com.fzzy.push.gd2020.v2.*;
|
|
import lombok.Data;
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.util.Date;
|
|
/**
|
* @author vince.xu
|
* @Title: ApiService
|
* @ProjectName igds-api
|
* @Description: 上传数据服务类
|
* @date 2022-9-216:27
|
*/
|
@Slf4j
|
@Data
|
@Component(GDApiRemoteService.BEAN_ID)
|
public class GDApiRemoteService implements ApiRemoteService {
|
|
|
public static final String BEAN_ID = "gd.ApiRemoteService";
|
|
@Autowired
|
private RedisUtil redisUtil;
|
|
@Autowired
|
private ApiCommonService apiCommonService;
|
|
@Autowired
|
private ApiLogRep apiLogRep;
|
|
|
/**
|
* 粮食品种 -油脂类型标记
|
*/
|
private String LSPZ_YZ_TAG = "211";
|
|
|
@Override
|
public String getProtocol() {
|
return PushProtocol.SB_GD_2020.getCode();
|
}
|
|
@Override
|
public ResponseDto pushData(ApiParam param, ApiConfs conf, Object data) {
|
|
String inteId = param.getInteId();
|
String kqdm = param.getKqdm();
|
String bizId = param.getBizId();
|
ResponseDto responseDto;
|
//添加LOGO
|
ApiLog apiLog = new ApiLog();
|
|
try {
|
if (null == conf) {
|
conf = apiCommonService.getConf(kqdm);
|
}
|
//获取TOKEN
|
AuthToken token = getAuthToken(conf);
|
|
apiLog.setId(ContextUtil.getUUID());
|
if (!Constant.API_CODE_1109.equals(inteId)) {
|
apiLog.setData(JSON.toJSONString(data));
|
}
|
apiLog.setInteId(inteId);
|
apiLog.setKqdm(kqdm);
|
apiLog.setUploadTime(new Date());
|
|
if (conf == null) {
|
responseDto = new ResponseDto(99, "没有获取到上传配置", bizId);
|
apiLog.setStatus(99);
|
apiLog.setResult("没有获取到上传配置");
|
apiLogRep.save(apiLog);
|
return responseDto;
|
}
|
if (null == token.getToken()) {
|
responseDto = new ResponseDto(99, "没有获取到TOKEN信息", bizId);
|
apiLog.setStatus(99);
|
apiLog.setResult("没有获取到TOKEN信息");
|
apiLogRep.save(apiLog);
|
return responseDto;
|
}
|
|
InvokeResult invokeResult = null;
|
|
|
//企业信息
|
if (Constant.API_CODE_1101.equals(param.getInteId())) {
|
Api1101 apiData = (Api1101) data;
|
invokeResult = CompanyWebService.newInstance().webService(token, conf, apiData);
|
}
|
|
//仓储人员信息
|
if (Constant.API_CODE_1112.equals(param.getInteId())) {
|
Api1112 apiData = (Api1112) data;
|
invokeResult = CompanyStaffWebService.newInstance().webService(token, conf, apiData);
|
}
|
|
//库点信息
|
if (Constant.API_CODE_1102.equals(param.getInteId())) {
|
Api1102 apiData = (Api1102) data;
|
invokeResult = StoreLocationWebService.newInstance().webService(token, conf, apiData);
|
}
|
|
//仓房信息
|
if (Constant.API_CODE_1103.equals(param.getInteId())) {
|
Api1103 apiData = (Api1103) data;
|
invokeResult = StoreHouseWebService.newInstance().webService(token, conf, apiData);
|
}
|
|
//廒间信息
|
if (Constant.API_CODE_1104.equals(param.getInteId())) {
|
Api1104 apiData = (Api1104) data;
|
//获取仓房信息
|
Api1103 api1103 = apiCommonService.getApi1103Cache(apiData.getCfbh());
|
|
invokeResult = GranaryWebService.newInstance().webService(token, conf, apiData, api1103);
|
}
|
|
//货位信息
|
if (Constant.API_CODE_1105.equals(param.getInteId())) {
|
Api1105 apiData = (Api1105) data;
|
|
//获取仓房信息,根据变化长度获取 ,需要确认广东省 货位编码: 仓房编码 + 3位廒间编码 + 2位货位编码
|
String cfbh = apiData.getHwdm().substring(0, apiData.getHwdm().length() - 5);
|
Api1103 api1103 = apiCommonService.getApi1103Cache(cfbh);
|
|
invokeResult = GoodsAllocationWebService.newInstance().webService(token, conf, apiData, api1103);
|
}
|
|
//油罐信息
|
if (Constant.API_CODE_1106.equals(param.getInteId())) {
|
Api1106 apiData = (Api1106) data;
|
invokeResult = OilTankWebService.newInstance().webService(token, conf, apiData);
|
}
|
|
//设备信息
|
if (Constant.API_CODE_1107.equals(param.getInteId())) {
|
Api1107 apiData = (Api1107) data;
|
invokeResult = DeviceWebService.newInstance().webService(token, conf, apiData);
|
}
|
|
//粮食库存信息 包含粮仓和油脂
|
if (Constant.API_CODE_1208.equals(param.getInteId())) {
|
Api1208 apiData = (Api1208) data;
|
|
//获取货位信息
|
Api1105 api1105 = apiCommonService.getApi1105Cache(apiData.getHwdm());
|
//获取库区信息
|
Api1102 api1102 = apiCommonService.getApi1102Cache(apiData.getKqdm());
|
|
//根据粮食品种类型判断是粮仓还是油脂
|
if (apiData.getLspzdm().startsWith(LSPZ_YZ_TAG)) {//说明存的是油脂,依次判断为油罐仓,是否判断合理根据库区实际参数调整
|
invokeResult = InventoryRecordLiquidWebService.newInstance().webService(token, conf, apiData, api1102, api1105);
|
} else {
|
invokeResult = InventoryInsertRecordSolidWebService.newInstance().webService(token, conf, apiData, api1102, api1105);
|
}
|
}
|
|
//损溢单接口数据
|
if (Constant.API_CODE_1209.equals(param.getInteId())) {
|
Api1209 apiData = (Api1209) data;
|
invokeResult = IncomeStatementWebservice.newInstance().webService(token, conf, apiData);
|
}
|
|
//性质转变单数据接口
|
if (Constant.API_CODE_1210.equals(param.getInteId())) {
|
|
Api1210 apiData = (Api1210) data;
|
|
invokeResult = TransferNatureWebservice.newInstance().webService(token, conf, apiData);
|
}
|
|
|
//粮情监测数据接口
|
if (Constant.API_CODE_1302.equals(param.getInteId())) {
|
Api1302 apiData = (Api1302) data;
|
|
//获取货位信息
|
Api1105 api1105 = apiCommonService.getApi1105Cache(apiData.getHwdm());
|
|
invokeResult = GrainConditionCheckTempHumWebService.newInstance().webService(token, conf, apiData, api1105);
|
}
|
|
//入库数据
|
if (Constant.API_CODE_1202.equals(param.getInteId())) {
|
Api1202 apiData = (Api1202) data;
|
invokeResult = InStorageWebService.newInstance().webService(token, conf, apiData);
|
}
|
|
//入库过磅
|
if (Constant.API_CODE_1202.equals(param.getInteId())) {
|
Api1202 apiData = (Api1202) data;
|
|
//获取仓房信息,根据变化长度获取 ,需要确认广东省 货位编码: 仓房编码 + 3位廒间编码 + 2位货位编码
|
String cfbh = apiData.getHwdm().substring(0, apiData.getHwdm().length() - 5);
|
Api1103 api1103 = apiCommonService.getApi1103Cache(cfbh);
|
|
invokeResult = InStorageDetailWebService.newInstance().webService(token, conf, apiData, api1103);
|
}
|
|
//入库质检
|
if (Constant.API_CODE_1203.equals(param.getInteId())) {
|
Api1203 apiData = (Api1203) data;
|
invokeResult = InstoreCheckWebservice.newInstance().webservice(token, conf, apiData);
|
}
|
|
//入库核算
|
if (Constant.API_CODE_1204.equals(param.getInteId())) {
|
Api1204 api1204 = (Api1204) data;
|
invokeResult = InstoreAccountsWebservice.newInstance().webservice(token, conf, api1204);
|
}
|
|
|
//出库数据
|
if (Constant.API_CODE_1205.equals(param.getInteId())) {
|
Api1205 apiData = (Api1205) data;
|
invokeResult = OutStorageWebService.newInstance().webservice(token, conf, apiData);
|
}
|
|
//出库过磅
|
if (Constant.API_CODE_1205.equals(param.getInteId())) {
|
Api1205 apiData = (Api1205) data;
|
//获取仓房信息,根据变化长度获取 ,需要确认广东省 货位编码: 仓房编码 + 3位廒间编码 + 2位货位编码
|
String cfbh = apiData.getHwdm().substring(0, apiData.getHwdm().length() - 5);
|
Api1103 api1103 = apiCommonService.getApi1103Cache(cfbh);
|
|
invokeResult = OutStorageDetailWebService.newInstance().webservice(token, conf, apiData, api1103);
|
}
|
|
|
//出库结算
|
if (Constant.API_CODE_1206.equals(param.getInteId())) {
|
Api1206 apiData = (Api1206) data;
|
invokeResult = OutStorageAccountsWebservice.newInstance().webservice(token, conf, apiData);
|
}
|
|
//气体数据
|
if (Constant.API_CODE_1304.equals(param.getInteId())) {
|
Api1304 apiData = (Api1304) data;
|
|
//获取仓房信息,根据变化长度获取 ,需要确认广东省 货位编码: 仓房编码 + 3位廒间编码 + 2位货位编码
|
String cfbh = apiData.getHwdm().substring(0, apiData.getHwdm().length() - 5);
|
Api1103 api1103 = apiCommonService.getApi1103Cache(cfbh);
|
|
invokeResult = GrainConditionCheckGasWebservice.newInstance().webservice(token, conf, apiData, api1103);
|
}
|
|
//虫害数据
|
if (Constant.API_CODE_1303.equals(param.getInteId())) {
|
Api1303 apiData = (Api1303) data;
|
|
//获取仓房信息,根据变化长度获取 ,需要确认广东省 货位编码: 仓房编码 + 3位廒间编码 + 2位货位编码
|
String cfbh = apiData.getHwdm().substring(0, apiData.getHwdm().length() - 5);
|
Api1103 api1103 = apiCommonService.getApi1103Cache(cfbh);
|
|
invokeResult = GrainConditionCheckWormWebservice.newInstance().webservice(token, conf, apiData, api1103);
|
}
|
|
//质检数据
|
if (Constant.API_CODE_1310.equals(param.getInteId())) {
|
Api1310 apiData = (Api1310) data;
|
invokeResult = ZlglInventoryWebservice.newInstance().Webservice(token, conf, apiData);
|
}
|
|
//轮换计划
|
if (Constant.API_CODE_1403.equals(param.getInteId())) {
|
Api1403 apiData = (Api1403) data;
|
invokeResult = LhjhWebService.newInstance().Webservice(token, conf, apiData);
|
}
|
|
//轮换详细
|
if (Constant.API_CODE_1404.equals(param.getInteId())) {
|
Api1404 apiData = (Api1404) data;
|
invokeResult = LhjhDetailWebService.newInstance().webService(token, conf, apiData);
|
}
|
|
//合同数据
|
if (Constant.API_CODE_1201.equals(param.getInteId())) {
|
Api1201 apiData = (Api1201) data;
|
invokeResult = ContractWebService.newInstance().webService(token, conf, apiData);
|
}
|
|
|
//TODO 上传附件
|
if (Constant.API_CODE_1109.equals(param.getInteId())) {
|
Api1109 apiData = (Api1109) data;
|
// invokeResult = FileServerWebService.getWs();
|
}
|
|
|
if (null == invokeResult) {
|
responseDto = new ResponseDto(GDResult.CODE_500.getCode(), GDResult.CODE_500.getName(), bizId);
|
apiLog.setStatus(responseDto.getSuccess());
|
apiLog.setResult(responseDto.getMsg());
|
apiLogRep.save(apiLog);
|
return responseDto;
|
}
|
|
if (GDResult.CODE_200.getCode() == invokeResult.getCode()) {
|
responseDto = new ResponseDto(0, GDResult.CODE_200.getName(), bizId);
|
} else {
|
apiLog.setStatus(invokeResult.getCode());
|
responseDto = new ResponseDto(invokeResult.getCode(), invokeResult.getData(), bizId);
|
}
|
|
apiLog.setStatus(responseDto.getSuccess());
|
apiLog.setResult(responseDto.getMsg());
|
|
} catch (Exception e) {
|
log.error(e.getMessage(), e);
|
|
responseDto = new ResponseDto(99, e.getMessage());
|
apiLog.setStatus(responseDto.getSuccess());
|
apiLog.setResult(responseDto.getMsg());
|
}
|
|
|
apiLogRep.save(apiLog);
|
|
return responseDto;
|
}
|
|
@Override
|
public ResponseDto pushData(ApiParam param, Object data) {
|
return pushData(param, null, data);
|
}
|
|
|
/**
|
* @Desc: 国标自定义方法
|
* @author: Andy
|
* @update-time: 2022/10/10
|
*/
|
public ResponseDto pushData(String inteId, String kqdm, String bizId, Object data) {
|
ApiConfs conf = apiCommonService.getConf(kqdm);
|
|
ApiParam param = new ApiParam(conf);
|
|
param.setInteId(inteId);
|
param.setInteCategory(inteId.substring(0, 2));
|
param.setBizId(bizId);
|
|
return pushData(param, conf, data);
|
}
|
|
|
/**
|
* 代码调整
|
*
|
* @param conf
|
* @return
|
*/
|
public AuthToken getAuthToken(ApiConfs conf) {
|
try {
|
|
String key = RedisConst.buildKey(RedisConst.KYE_TOKEN, conf.getKqdm());
|
|
AuthToken token = (AuthToken) redisUtil.get(key);
|
if (null != token) return token;
|
|
|
log.info("-----------------------------重新获取TOKEN-----------------------------");
|
|
token = AuthTokenWebService.newInstance().getToken(conf.getApiUrl(), conf.getUserName(), conf.getPassword());
|
|
|
redisUtil.set(key, token);
|
|
return token;
|
} catch (Exception e) {
|
log.error(e.getMessage(), e);
|
return null;
|
}
|
}
|
|
}
|