|
@@ -10,9 +10,13 @@ import com.uas.eis.config.DonlimConfig;
|
|
|
import com.uas.eis.core.config.SpObserver;
|
|
import com.uas.eis.core.config.SpObserver;
|
|
|
import com.uas.eis.core.support.TokenProperties;
|
|
import com.uas.eis.core.support.TokenProperties;
|
|
|
import com.uas.eis.dao.*;
|
|
import com.uas.eis.dao.*;
|
|
|
|
|
+import com.uas.eis.dto.FindOrderRelationInvoiceDTO;
|
|
|
|
|
+import com.uas.eis.dto.FindOrderRelationInvoiceReq;
|
|
|
|
|
+import com.uas.eis.dto.FindOrderRelationInvoiceResp;
|
|
|
import com.uas.eis.entity.*;
|
|
import com.uas.eis.entity.*;
|
|
|
import com.uas.eis.sdk.entity.ApiResult;
|
|
import com.uas.eis.sdk.entity.ApiResult;
|
|
|
import com.uas.eis.sdk.resp.ApiResponse;
|
|
import com.uas.eis.sdk.resp.ApiResponse;
|
|
|
|
|
+import com.uas.eis.service.CommonService;
|
|
|
import com.uas.eis.service.ERPService;
|
|
import com.uas.eis.service.ERPService;
|
|
|
import com.uas.eis.utils.*;
|
|
import com.uas.eis.utils.*;
|
|
|
import nuonuo.open.sdk.NNOpenSDK;
|
|
import nuonuo.open.sdk.NNOpenSDK;
|
|
@@ -40,6 +44,8 @@ public class ERPServiceImpl implements ERPService {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private DonlimConfig donlimConfig;
|
|
private DonlimConfig donlimConfig;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private CommonService commonService;
|
|
|
@Override
|
|
@Override
|
|
|
public Map<String, Object> pushInvoiceOrder(String master, int id) {
|
|
public Map<String, Object> pushInvoiceOrder(String master, int id) {
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
@@ -172,24 +178,24 @@ public class ERPServiceImpl implements ERPService {
|
|
|
return null;//对接信息为配置
|
|
return null;//对接信息为配置
|
|
|
}
|
|
}
|
|
|
String url=donlimConfig.getRoute();
|
|
String url=donlimConfig.getRoute();
|
|
|
- System.out.println(url);
|
|
|
|
|
|
|
+// System.out.println(url);
|
|
|
String appKey = donlimConfig.getAppKey();
|
|
String appKey = donlimConfig.getAppKey();
|
|
|
String appSecret = donlimConfig.getAppSecret();
|
|
String appSecret = donlimConfig.getAppSecret();
|
|
|
String token = donlimConfig.getToken();
|
|
String token = donlimConfig.getToken();
|
|
|
String taxnum= donlimConfig.getTaxnum();
|
|
String taxnum= donlimConfig.getTaxnum();
|
|
|
if(donlimConfig.isProd()){
|
|
if(donlimConfig.isProd()){
|
|
|
- System.out.println("prod");
|
|
|
|
|
|
|
+// System.out.println("prod");
|
|
|
appKey = obs[0].toString();
|
|
appKey = obs[0].toString();
|
|
|
appSecret = obs[1].toString();
|
|
appSecret = obs[1].toString();
|
|
|
token = obs[2].toString();// 访问令牌
|
|
token = obs[2].toString();// 访问令牌
|
|
|
taxnum = obs[3].toString();// 授权企业税号
|
|
taxnum = obs[3].toString();// 授权企业税号
|
|
|
}else{
|
|
}else{
|
|
|
- System.out.println("dev");
|
|
|
|
|
|
|
+// System.out.println("dev");
|
|
|
}
|
|
}
|
|
|
SpObserver.putSp(master);
|
|
SpObserver.putSp(master);
|
|
|
SqlRowList rs_main = baseDao.queryForRowSet("select * from invoiceOrder left join customer on io_cucode=cu_code where io_id="+id);
|
|
SqlRowList rs_main = baseDao.queryForRowSet("select * from invoiceOrder left join customer on io_cucode=cu_code where io_id="+id);
|
|
|
if(rs_main.next()){
|
|
if(rs_main.next()){
|
|
|
- System.out.println(taxnum);
|
|
|
|
|
|
|
+// System.out.println(taxnum);
|
|
|
String code= rs_main.getGeneralString("io_code");
|
|
String code= rs_main.getGeneralString("io_code");
|
|
|
NNOpenSDK sdk = NNOpenSDK.getIntance();
|
|
NNOpenSDK sdk = NNOpenSDK.getIntance();
|
|
|
String method = "nuonuo.OpeMplatform.findOrderState"; // API方法名
|
|
String method = "nuonuo.OpeMplatform.findOrderState"; // API方法名
|
|
@@ -199,12 +205,18 @@ public class ERPServiceImpl implements ERPService {
|
|
|
String content=JSONArray.toJSONString(reqParam);
|
|
String content=JSONArray.toJSONString(reqParam);
|
|
|
String senid = UUID.randomUUID().toString().replace("-", ""); // 唯一标识,32位随机码,无需修改,保持默认即可
|
|
String senid = UUID.randomUUID().toString().replace("-", ""); // 唯一标识,32位随机码,无需修改,保持默认即可
|
|
|
String result = sdk.sendPostSyncRequest(url, senid, appKey, appSecret, token, taxnum, method, content);
|
|
String result = sdk.sendPostSyncRequest(url, senid, appKey, appSecret, token, taxnum, method, content);
|
|
|
|
|
+ System.out.println(result);
|
|
|
FindOrderStateResp resp = JSON.parseObject(result , new TypeReference<FindOrderStateResp>() {});
|
|
FindOrderStateResp resp = JSON.parseObject(result , new TypeReference<FindOrderStateResp>() {});
|
|
|
System.out.println(resp.getCode());
|
|
System.out.println(resp.getCode());
|
|
|
System.out.println(resp.getMessage());
|
|
System.out.println(resp.getMessage());
|
|
|
- System.out.println(resp.getData().getInvoiceStatus());
|
|
|
|
|
- System.out.println(resp.getData().getErrorMsg());
|
|
|
|
|
- System.out.println(result);//{"status":"0000","message":"调用成功","data":{"invoiceStatus":"0","errorMsg":null}}
|
|
|
|
|
|
|
+// System.out.println(resp.getData().getInvoiceStatus());
|
|
|
|
|
+// System.out.println(resp.getData().getErrorMsg());
|
|
|
|
|
+// Map<Object, Object> res=JSONUtil.toMap(result);
|
|
|
|
|
+ baseDao.execute("update invoiceOrder set IO_INVOICESTATUS = '"+resp.getData().getInvoiceStatus()+"'"
|
|
|
|
|
+ +",io_errorMsg='"+StringUtil.nvl(resp.getData().getErrorMsg(),"")+"'"
|
|
|
|
|
+// +(StringUtil.hasText(resp.getData().getErrorMsg())?",io_errorMsg ='"+resp.getData().getErrorMsg()+"'":"")
|
|
|
|
|
+ +" where io_id = '"+id+"'");
|
|
|
|
|
+// System.out.println(result);//{"status":"0000","message":"调用成功","data":{"invoiceStatus":"0","errorMsg":null}}
|
|
|
map.put("success", true);
|
|
map.put("success", true);
|
|
|
map.put("result", result);
|
|
map.put("result", result);
|
|
|
return map;
|
|
return map;
|
|
@@ -271,4 +283,104 @@ public class ERPServiceImpl implements ERPService {
|
|
|
}
|
|
}
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Map<String, Object> getElecInvoicesById(String master, Integer id) {
|
|
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
|
|
+ Object[] obs=baseDao.getFieldsDataByCondition("YITOA_DATACENTER.dock_invoice_config",new String[]{"appKey","appSecret","token","taxnum"},"username='"+master+"'");
|
|
|
|
|
+ if(obs==null){
|
|
|
|
|
+ return null;//对接信息为配置
|
|
|
|
|
+ }
|
|
|
|
|
+// System.out.println(url);
|
|
|
|
|
+ String appKey = donlimConfig.getAppKey();
|
|
|
|
|
+ String appSecret = donlimConfig.getAppSecret();
|
|
|
|
|
+ String token = donlimConfig.getToken();
|
|
|
|
|
+ String taxnum= donlimConfig.getTaxnum();
|
|
|
|
|
+ if(donlimConfig.isProd()){
|
|
|
|
|
+// System.out.println("prod");
|
|
|
|
|
+ appKey = obs[0].toString();
|
|
|
|
|
+ appSecret = obs[1].toString();
|
|
|
|
|
+ token = obs[2].toString();// 访问令牌
|
|
|
|
|
+ taxnum = obs[3].toString();// 授权企业税号
|
|
|
|
|
+ }else{
|
|
|
|
|
+// System.out.println("dev");
|
|
|
|
|
+ }
|
|
|
|
|
+ SpObserver.putSp(master);
|
|
|
|
|
+ SqlRowList ioList = baseDao.queryForRowSet("select io_id,io_code from "+master+".invoiceOrder left join "+master+".customer on io_cucode=cu_code " +
|
|
|
|
|
+ " where io_id = "+id);
|
|
|
|
|
+ while(ioList.next()) {
|
|
|
|
|
+ map = getElecInvoices(appKey,appSecret,token,taxnum,ioList.getGeneralInt("io_id"),ioList.getGeneralString("io_code"));
|
|
|
|
|
+ }
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Map<String, Object> getElecInvoices(String appKey,String appSecret,String token,String taxnum,int ioid,String ioCode){
|
|
|
|
|
+ Map<String, Object> res = new HashMap<String, Object>();
|
|
|
|
|
+ String url=donlimConfig.getRoute();
|
|
|
|
|
+ String errCode = "-999";
|
|
|
|
|
+ String errMsg = "";
|
|
|
|
|
+ try {
|
|
|
|
|
+ //调用对接
|
|
|
|
|
+ FindOrderRelationInvoiceReq foriReq = new FindOrderRelationInvoiceReq();
|
|
|
|
|
+ foriReq.setOriginalOrderNo(ioCode);//订单编号
|
|
|
|
|
+ foriReq.setSaleTaxNum(taxnum);//销方税号
|
|
|
|
|
+ foriReq.setNeedInvoiceSourceDetail("0");//是否需要发票所来源的订单明细,1-是, 0-否(不填默认 0) 当为0时,将不回传orderDetailCallBackVOS。先默认不需要明细
|
|
|
|
|
+ // System.out.println(JSONArray.toJSONString(foriReq));
|
|
|
|
|
+ NNOpenSDK sdk = NNOpenSDK.getIntance();
|
|
|
|
|
+ String method = "nuonuo.OpeMplatform.findOrderRelationInvoice"; // API方法名
|
|
|
|
|
+ String content =sdk.convertToUtf8(JSONArray.toJSONString(foriReq));
|
|
|
|
|
+ String senid = UUID.randomUUID().toString().replace("-", ""); // 唯一标识,32位随机码,无需修改,保持默认即可
|
|
|
|
|
+ String result = sdk.sendPostSyncRequest(url, senid, appKey, appSecret, token, taxnum, method, content);
|
|
|
|
|
+ // System.out.println(result);
|
|
|
|
|
+ FindOrderRelationInvoiceResp resp = JSON.parseObject(result , new TypeReference<FindOrderRelationInvoiceResp>() {});
|
|
|
|
|
+ errCode = resp.getStatus();
|
|
|
|
|
+ errMsg = resp.getMessage();
|
|
|
|
|
+ logger.info("ElecInvoice-DownLoad-master: {} ,id {} status {} message {}",SpObserver.getSp(),ioid,errCode,errMsg);
|
|
|
|
|
+ if("0000".equals(errCode)){//调用成功
|
|
|
|
|
+ //记录发票明细
|
|
|
|
|
+ baseDao.execute(getElecInvoicesSqls(ioid,resp.getData()));
|
|
|
|
|
+ commonService.logSRecord("订单关联发票对接",ioid);
|
|
|
|
|
+ }else if(!"8958".equals(errCode)){// {"status":"8958","message":"该订单对应的开票单不存在","data":null} 没有开票单的不记录对接失败日志
|
|
|
|
|
+ if(errMsg.length() > 3990){
|
|
|
|
|
+ errMsg = errMsg.substring(0,3990);
|
|
|
|
|
+ }
|
|
|
|
|
+ baseDao.execute("update invoiceOrder set io_errorMsg='"+errMsg+"' where io_id="+ioid);
|
|
|
|
|
+ commonService.logFRecord("订单关联发票对接","("+errCode+")"+errMsg,ioid);
|
|
|
|
|
+ }
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ errMsg = "发票获取异常";
|
|
|
|
|
+ if(StringUtil.hasText(e.getMessage())){
|
|
|
|
|
+ errMsg = e.getMessage();
|
|
|
|
|
+ }else if(e.getCause()!=null&&StringUtil.hasText(e.getCause().getMessage())){
|
|
|
|
|
+ errMsg = e.getCause().getMessage();
|
|
|
|
|
+ }
|
|
|
|
|
+ commonService.logFRecord("订单关联发票对接",errMsg.replaceAll("'","''"),ioid);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(StringUtil.hasText(errMsg)&&!"调用成功".equals(errMsg)){
|
|
|
|
|
+ res.put("success", false);
|
|
|
|
|
+ res.put("errCode", errCode);
|
|
|
|
|
+ res.put("errMsg", errMsg);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ res.put("success", true);
|
|
|
|
|
+ }
|
|
|
|
|
+ return res;
|
|
|
|
|
+ }
|
|
|
|
|
+ private List<String> getElecInvoicesSqls(int ioid,List<FindOrderRelationInvoiceDTO> data){
|
|
|
|
|
+ List<String> sqls = new ArrayList<String>();
|
|
|
|
|
+ boolean syncToBillOut = baseDao.isDBSetting("BillOut","syncToBillOut");
|
|
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
|
|
+ sqls.add(data.get(i).toMergeSql(ioid,(i+1)));
|
|
|
|
|
+ }
|
|
|
|
|
+ sqls.add("update ELECINVOICE set ei_refno = (case when ei_invoiceLine in ('bs','pc','es','ec') then ei_allElectronicInvoiceNumber else ei_invoiceNumber end) " +
|
|
|
|
|
+ "where ei_ioid = "+ioid+" and EI_INVOICESTATE = 1 and EI_EXCEPTIONMESSAGE is null and (ei_allElectronicInvoiceNumber is not null or ei_invoiceNumber is not null )");
|
|
|
|
|
+ sqls.add("update invoiceOrder set io_refno = (select (min(ei_refno)||(case when max(ei_refno) <> min(ei_refno) then '-'||max(ei_refno) else '' end)) from ELECINVOICE where ei_ioid = io_id)" +
|
|
|
|
|
+ "where io_id = "+ioid);
|
|
|
|
|
+ //更新开票记录
|
|
|
|
|
+ if(syncToBillOut){
|
|
|
|
|
+ sqls.add("update BillOut set bi_refno = (select max(io_refno) from invoiceOrder where io_id = "+ioid+" and io_biid = bi_id) where bi_id in (select io_biid from invoiceOrder where io_id = "+ioid+" and io_refno is not null)");
|
|
|
|
|
+ }
|
|
|
|
|
+ //System.out.println("sqls:");
|
|
|
|
|
+// System.out.println(sqls);
|
|
|
|
|
+ return sqls;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|