|
@@ -6,16 +6,20 @@ import com.malk.server.aliwork.YDParam;
|
|
|
import com.malk.server.common.McR;
|
|
import com.malk.server.common.McR;
|
|
|
import com.malk.service.aliwork.YDClient;
|
|
import com.malk.service.aliwork.YDClient;
|
|
|
import com.malk.siku.service.SikuService;
|
|
import com.malk.siku.service.SikuService;
|
|
|
-import com.malk.siku.utils.MkUtil;
|
|
|
|
|
|
|
+import com.malk.siku.utils.MkBxUtil;
|
|
|
|
|
+import com.malk.siku.utils.MkYpUtil;
|
|
|
import com.malk.utils.UtilHttp;
|
|
import com.malk.utils.UtilHttp;
|
|
|
import com.malk.utils.UtilMap;
|
|
import com.malk.utils.UtilMap;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.logging.log4j.util.Strings;
|
|
|
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 java.util.Arrays;
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
|
+import java.io.InputStream;
|
|
|
|
|
+import java.net.HttpURLConnection;
|
|
|
|
|
+import java.net.URL;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Service
|
|
@Service
|
|
@@ -66,10 +70,138 @@ public class SikuServiceImpl implements SikuService {
|
|
|
Map body = new HashMap();
|
|
Map body = new HashMap();
|
|
|
body.put("partnerList", Arrays.asList(partner));
|
|
body.put("partnerList", Arrays.asList(partner));
|
|
|
|
|
|
|
|
- Map result = (Map) JSONObject.parse(UtilHttp.doPost("https://ng.maycur.com/api/openapi/tradingPartner/batch/save", MkUtil.initTokenHeader(), null, body));
|
|
|
|
|
|
|
+ Map result = (Map) JSONObject.parse(UtilHttp.doPost("https://ng.maycur.com/api/openapi/tradingPartner/batch/save", MkBxUtil.initTokenHeader(), null, body));
|
|
|
|
|
|
|
|
log.info("Result:",result);
|
|
log.info("Result:",result);
|
|
|
|
|
|
|
|
return McR.success();
|
|
return McR.success();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public McR saveYpApplication(Map map) {
|
|
|
|
|
+ String formInstId = UtilMap.getString(map, "formInstId");
|
|
|
|
|
+
|
|
|
|
|
+ Map formData = ydClient.queryData(YDParam.builder()
|
|
|
|
|
+ .formInstanceId(formInstId)
|
|
|
|
|
+ .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
|
|
|
|
|
+
|
|
|
|
|
+ Map application = new HashMap();
|
|
|
|
|
+ application.put("formSubTypeBizCode","KPSQD");//单据编码(云票系统内维护的)
|
|
|
|
|
+ application.put("bizCode", UtilMap.getString(formData,"serialNumberField_mknspz75"));//外部系统中的开票申请单业务编码。必须系统内唯一,用于判断开票申请单是否已导入。
|
|
|
|
|
+ Map clientLegalEntityOaDto = new HashMap();//客户开票信息对象
|
|
|
|
|
+ clientLegalEntityOaDto.put("invoiceTitle",UtilMap.getString(formData,"selectField_mkxmix7e"));//名称
|
|
|
|
|
+ clientLegalEntityOaDto.put("dutyParagraph",UtilMap.getString(formData,"textField_mm2wj87l"));//税号
|
|
|
|
|
+ clientLegalEntityOaDto.put("account",UtilMap.getString(formData,"textField_mm2wj87u"));//账号
|
|
|
|
|
+ clientLegalEntityOaDto.put("bankBranchName",UtilMap.getString(formData,"textField_mm2wj87t"));//银行
|
|
|
|
|
+ application.put("clientLegalEntityOaDto",clientLegalEntityOaDto);
|
|
|
|
|
+ application.put("legalEntityBizCode",UtilMap.getString(formData,"textField_mm2wj87x"));//公司主体code(后续传税号)
|
|
|
|
|
+ application.put("estimatedDate",System.currentTimeMillis());//预计开票时间
|
|
|
|
|
+ String fplx = UtilMap.getString(formData, "selectField_mkdnuvem");//发票类型
|
|
|
|
|
+ String estimatedInvoiceType = "";
|
|
|
|
|
+ switch (fplx){
|
|
|
|
|
+ case "应/免税普票":estimatedInvoiceType = "ELECTRONIC_VAT";break;//增值税普通发票(电子)
|
|
|
|
|
+ case "专票":estimatedInvoiceType = "ELECTRONIC_SPACIAL_VAT";break;//增值税电子专用发票
|
|
|
|
|
+ case "红冲":break;
|
|
|
|
|
+ case "形式发票":break;
|
|
|
|
|
+ case "收据":break;
|
|
|
|
|
+ default:break;
|
|
|
|
|
+ }
|
|
|
|
|
+ application.put("estimatedInvoiceType",estimatedInvoiceType);//发票类型
|
|
|
|
|
+
|
|
|
|
|
+ application.put("phoneNumber",UtilMap.getString(formData,"textField_mkdo0azf"));//收票人电话
|
|
|
|
|
+ application.put("email",UtilMap.getString(formData,"textField_mkdo0azn"));//收票邮箱
|
|
|
|
|
+ application.put("applicationComment",UtilMap.getString(formData,"textareaField_mkdo0aze"));//开票备注
|
|
|
|
|
+
|
|
|
|
|
+ Map item = new HashMap();
|
|
|
|
|
+ item.put("productBizCode","1001");//产品bizcode
|
|
|
|
|
+ item.put("invoiceName",UtilMap.getString(formData,"textField_mkgarw4d"));//开票名称
|
|
|
|
|
+ item.put("taxPercent",UtilMap.getDouble(formData,"numberField_mkgkboht"));//税率
|
|
|
|
|
+ item.put("quantity",1);//数量
|
|
|
|
|
+ item.put("forexName","CNY");//币种
|
|
|
|
|
+ item.put("exchangeRate",1);//外汇汇率
|
|
|
|
|
+ item.put("priceWithTax",UtilMap.getDouble(formData,"numberField_mkdo0azb"));//含税单价
|
|
|
|
|
+ item.put("taxClassShortCode",UtilMap.getString(formData,"textField_mm49zsli"));//税收分类编码
|
|
|
|
|
+
|
|
|
|
|
+ application.put("items",Arrays.asList(item));
|
|
|
|
|
+
|
|
|
|
|
+ Map result = MkYpUtil.application_oa(Arrays.asList(application));
|
|
|
|
|
+
|
|
|
|
|
+ return McR.success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void invoiceWriteBack(Map map) {
|
|
|
|
|
+ //获取发票信息
|
|
|
|
|
+ Map calloutParams = UtilMap.getMap(map, "calloutParams");
|
|
|
|
|
+ Map bizData = UtilMap.getMap(calloutParams, "bizData");
|
|
|
|
|
+
|
|
|
|
|
+ String bizCode = UtilMap.getString(bizData, "bizCode");//发票号码
|
|
|
|
|
+ String invoiceNumber = UtilMap.getString(bizData, "invoiceNumber");//发票号码
|
|
|
|
|
+ String pdfUrl = UtilMap.getString(bizData, "pdfUrl");//pdf文件下载地址
|
|
|
|
|
+ String downloadPageUrl = UtilMap.getString(bizData, "downloadPageUrl");//发票下载页面链接
|
|
|
|
|
+ List<Map> detailItems = (List<Map>) UtilMap.getList(bizData, "detailItems");
|
|
|
|
|
+ List<Map> documentCorrelates = UtilMap.getList(detailItems.get(0), "documentCorrelates");
|
|
|
|
|
+ String lsh = UtilMap.getString(documentCorrelates.get(0), "bizCode");//开票申请单编号
|
|
|
|
|
+
|
|
|
|
|
+ //回写宜搭
|
|
|
|
|
+ Map formData = new HashMap();
|
|
|
|
|
+ formData.put("radioField_mkxripcc","开票成功");
|
|
|
|
|
+ formData.put("textField_mkxripc6",invoiceNumber);
|
|
|
|
|
+ formData.put("textField_mm3aixk0",downloadPageUrl);
|
|
|
|
|
+
|
|
|
|
|
+ if (Strings.isNotBlank(pdfUrl)){
|
|
|
|
|
+ String fileName = invoiceNumber + ".pdf";
|
|
|
|
|
+ String downloadPath = "d:\\" + fileName;
|
|
|
|
|
+ downloadFile(pdfUrl,downloadPath);//下载pdf发票
|
|
|
|
|
+
|
|
|
|
|
+ String downloadUri = "http://localhost:8080/api/siku/files/"+fileName+"?option=download" + fileName;
|
|
|
|
|
+ String previewUri = "http://localhost:8080/api/siku/files/"+fileName+"?option=preview" + fileName;
|
|
|
|
|
+
|
|
|
|
|
+ Map attachmentField = new HashMap();
|
|
|
|
|
+ attachmentField.put("downloadUrl",downloadUri);
|
|
|
|
|
+ attachmentField.put("name",fileName);
|
|
|
|
|
+ attachmentField.put("previewUrl",previewUri);
|
|
|
|
|
+ attachmentField.put("url",downloadUri);
|
|
|
|
|
+ attachmentField.put("ext","pdf");
|
|
|
|
|
+ formData.put("attachmentField_mkxripc5",Arrays.asList(attachmentField));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ydClient.operateData(YDParam.builder()
|
|
|
|
|
+ .formInstanceId(bizCode)
|
|
|
|
|
+ .searchCondition(JSONObject.toJSONString(UtilMap.map("serialNumberField_mknspz75",lsh)))
|
|
|
|
|
+ .formUuid("FORM-A9A47B0365DB437F8F4C8E01B4468220K7GU")
|
|
|
|
|
+ .formDataJson(JSONObject.toJSONString(formData))
|
|
|
|
|
+ .build(), YDConf.FORM_OPERATION.upsert);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //文件下载到本地
|
|
|
|
|
+ private void downloadFile(String downloadUri,String downloadPath){
|
|
|
|
|
+ try {
|
|
|
|
|
+ URL url = new URL(downloadUri);
|
|
|
|
|
+
|
|
|
|
|
+ HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
|
|
|
|
|
+ int responseCode = httpConn.getResponseCode();
|
|
|
|
|
+
|
|
|
|
|
+ // 检查HTTP响应代码是否为200
|
|
|
|
|
+ if (responseCode == HttpURLConnection.HTTP_OK) {
|
|
|
|
|
+ InputStream inputStream = httpConn.getInputStream();
|
|
|
|
|
+ FileOutputStream outputStream = new FileOutputStream(downloadPath);
|
|
|
|
|
+
|
|
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
|
|
+ int bytesRead = -1;
|
|
|
|
|
+
|
|
|
|
|
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
|
|
|
|
|
+ outputStream.write(buffer, 0, bytesRead);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ outputStream.close();
|
|
|
|
|
+ inputStream.close();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.out.println("无法下载文件。HTTP响应代码: " + responseCode);
|
|
|
|
|
+ }
|
|
|
|
|
+ httpConn.disconnect();
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|