更新
This commit is contained in:
parent
426a2ccb3e
commit
9c8b1aa500
@ -6,12 +6,19 @@ import com.alibaba.fastjson.JSONObject;
|
|||||||
import com.xxl.job.core.context.XxlJobHelper;
|
import com.xxl.job.core.context.XxlJobHelper;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.client.RestClientException;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.ssssssss.magicboot.fxapi.HttpClientResult;
|
import org.ssssssss.magicboot.fxapi.HttpClientResult;
|
||||||
import org.ssssssss.magicboot.fxapi.HttpClientUtils;
|
import org.ssssssss.magicboot.fxapi.HttpClientUtils;
|
||||||
import org.ssssssss.magicboot.fxapi.XKTokenAccess;
|
import org.ssssssss.magicboot.fxapi.XKTokenAccess;
|
||||||
import org.ssssssss.magicboot.fxapi.model.CrmFXApiParam;
|
import org.ssssssss.magicboot.fxapi.model.CrmFXApiParam;
|
||||||
|
import org.ssssssss.magicboot.utils.CrmRequestUtil;
|
||||||
import org.ssssssss.magicboot.zdyutils.FXHTTP;
|
import org.ssssssss.magicboot.zdyutils.FXHTTP;
|
||||||
import org.ssssssss.magicboot.zdyutils.GcjJson;
|
import org.ssssssss.magicboot.zdyutils.GcjJson;
|
||||||
import org.ssssssss.magicboot.zdyutils.MagicApi;
|
import org.ssssssss.magicboot.zdyutils.MagicApi;
|
||||||
@ -26,6 +33,7 @@ import java.util.Map;
|
|||||||
@RequestMapping("/priceapprova")
|
@RequestMapping("/priceapprova")
|
||||||
public class priceapprovaController {
|
public class priceapprovaController {
|
||||||
static Logger log = LoggerFactory.getLogger("priceapprova");
|
static Logger log = LoggerFactory.getLogger("priceapprova");
|
||||||
|
private RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
new priceapprovaController().getSynDataAdd();
|
new priceapprovaController().getSynDataAdd();
|
||||||
@ -129,6 +137,8 @@ public class priceapprovaController {
|
|||||||
String platform_manufacturer_text__c = GcjJson.getNodeValue(str, "JSON.platform_manufacturer_text__c") != null ? GcjJson.getNodeValue(str, "JSON.platform_manufacturer_text__c").toString() : "";
|
String platform_manufacturer_text__c = GcjJson.getNodeValue(str, "JSON.platform_manufacturer_text__c") != null ? GcjJson.getNodeValue(str, "JSON.platform_manufacturer_text__c").toString() : "";
|
||||||
String quote_requirements__c = GcjJson.getNodeValue(str, "JSON.quote_requirements__c") != null ? GcjJson.getNodeValue(str, "JSON.quote_requirements__c").toString() : "";
|
String quote_requirements__c = GcjJson.getNodeValue(str, "JSON.quote_requirements__c") != null ? GcjJson.getNodeValue(str, "JSON.quote_requirements__c").toString() : "";
|
||||||
|
|
||||||
|
JSONArray specificationfile = (JSONArray) GcjJson.getNodeValue(str, "JSON.technical_specification__c");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String cemployeeid = "";
|
String cemployeeid = "";
|
||||||
@ -185,16 +195,16 @@ public class priceapprovaController {
|
|||||||
datajson.put("f9w5_platform",platform_manufacturer_text__c);
|
datajson.put("f9w5_platform",platform_manufacturer_text__c);
|
||||||
String implementation_needed__c = GcjJson.getNodeValue(str, "JSON.implementation_needed__c") != null ? GcjJson.getNodeValue(str, "JSON.implementation_needed__c").toString() : "";
|
String implementation_needed__c = GcjJson.getNodeValue(str, "JSON.implementation_needed__c") != null ? GcjJson.getNodeValue(str, "JSON.implementation_needed__c").toString() : "";
|
||||||
if("yes".equals(implementation_needed__c)){
|
if("yes".equals(implementation_needed__c)){
|
||||||
datajson.put("f9w5_implementation","0");
|
|
||||||
} else if ("no".equals(implementation_needed__c)) {
|
|
||||||
datajson.put("f9w5_implementation","1");
|
datajson.put("f9w5_implementation","1");
|
||||||
|
} else if ("no".equals(implementation_needed__c)) {
|
||||||
|
datajson.put("f9w5_implementation","0");
|
||||||
}
|
}
|
||||||
//是否送检
|
//是否送检
|
||||||
String is_inspected__c = GcjJson.getNodeValue(str, "JSON.is_inspected__c") != null ? GcjJson.getNodeValue(str, "JSON.is_inspected__c").toString() : "";
|
String is_inspected__c = GcjJson.getNodeValue(str, "JSON.is_inspected__c") != null ? GcjJson.getNodeValue(str, "JSON.is_inspected__c").toString() : "";
|
||||||
if("yes".equals(is_inspected__c)){
|
if("yes".equals(is_inspected__c)){
|
||||||
datajson.put("f9w5_isinspected","0");
|
|
||||||
} else if ("no".equals(is_inspected__c)) {
|
|
||||||
datajson.put("f9w5_isinspected","1");
|
datajson.put("f9w5_isinspected","1");
|
||||||
|
} else if ("no".equals(is_inspected__c)) {
|
||||||
|
datajson.put("f9w5_isinspected","0");
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONArray groupstandardarr = new JSONArray();
|
JSONArray groupstandardarr = new JSONArray();
|
||||||
@ -239,7 +249,7 @@ public class priceapprovaController {
|
|||||||
stringBuffer.append("参数解析错误,请联系开发人员");
|
stringBuffer.append("参数解析错误,请联系开发人员");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
getSynDataSave(stringBuffer,sendFlag,fxapi,dataId,nameData,strJson,getData);
|
getSynDataSave(stringBuffer,sendFlag,fxapi,dataId,nameData,strJson,getData,specificationfile);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -247,7 +257,7 @@ public class priceapprovaController {
|
|||||||
/**
|
/**
|
||||||
* 写数据
|
* 写数据
|
||||||
*/
|
*/
|
||||||
public void getSynDataSave(StringBuffer stringBuffer,Boolean sendFlag,FXHTTP fxapi,String dataId,String nameData,String obj,JSONObject str) {
|
public void getSynDataSave(StringBuffer stringBuffer,Boolean sendFlag,FXHTTP fxapi,String dataId,String nameData,String obj,JSONObject str,JSONArray specificationfile) {
|
||||||
String syn_type = "0";//同步类型 0新增 1修改 2删除
|
String syn_type = "0";//同步类型 0新增 1修改 2删除
|
||||||
String res_url = "http://192.168.31.233:8022/ierp/kapi/v2/f9w5/pmp/f9w5_pmp_priceapproval/priceapprovalSave";
|
String res_url = "http://192.168.31.233:8022/ierp/kapi/v2/f9w5/pmp/f9w5_pmp_priceapproval/priceapprovalSave";
|
||||||
String res_param = obj;
|
String res_param = obj;
|
||||||
@ -275,6 +285,35 @@ public class priceapprovaController {
|
|||||||
paramMap.put("sync_info__c", resjs.getString("message"));
|
paramMap.put("sync_info__c", resjs.getString("message"));
|
||||||
//回写json
|
//回写json
|
||||||
fxapi.upSynZDYFieldParam("", "project_quote_quotation__c", dataId, paramMap);
|
fxapi.upSynZDYFieldParam("", "project_quote_quotation__c", dataId, paramMap);
|
||||||
|
|
||||||
|
if(!specificationfile.isEmpty()){
|
||||||
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
List attachmentList = specificationfile;
|
||||||
|
MultiValueMap<String, Object> body = crmRequestUtil.attachmentuploadFile(attachmentList, Long.parseLong(erpid));
|
||||||
|
//开始封装请求实体
|
||||||
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||||
|
httpHeaders.set("accessToken", accessToken);
|
||||||
|
HttpEntity entity = new HttpEntity(body, httpHeaders);
|
||||||
|
//开始发起传输
|
||||||
|
JSONObject fileRes = new JSONObject();
|
||||||
|
try {
|
||||||
|
fileRes = restTemplate.postForObject("http://192.168.31.233:8022/ierp/kapi/v2/frame/attachment/uploadFile", entity, JSONObject.class);
|
||||||
|
Map<String, Object> paramMap2 = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
String message = fileRes.getString("message");
|
||||||
|
if("".equals(message) || message == null){
|
||||||
|
message = "上传成功";
|
||||||
|
}
|
||||||
|
paramMap.put("technical_upload_message__c", message);//数据ID
|
||||||
|
fxapi.upSynZDYFieldParam("", "project_quote_quotation__c", dataId, paramMap2);
|
||||||
|
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
sendFlag=true;
|
sendFlag=true;
|
||||||
stringBuffer.append("项目报价询价申请创建接口调用失败:"+resjs.getString("message"));
|
stringBuffer.append("项目报价询价申请创建接口调用失败:"+resjs.getString("message"));
|
||||||
|
@ -389,5 +389,77 @@ public class CrmRequestUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//上传询价单附件
|
||||||
|
public MultiValueMap<String, Object> attachmentuploadFile(List<?> fileList, Long erpId) {
|
||||||
|
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
||||||
|
|
||||||
|
JSONObject args = new JSONObject();
|
||||||
|
args.put("entityNumber","f9w5_pmp_priceapproval");
|
||||||
|
args.put("billPkId",erpId);
|
||||||
|
args.put("controlKey","f9w5_technicalstd");
|
||||||
|
|
||||||
|
body.add("attachmentUploadFileArgs", args);
|
||||||
|
|
||||||
|
if (fileList == null || fileList.isEmpty()) {
|
||||||
|
log.info("文件列表为空");
|
||||||
|
return body; // 返回空map而不是null
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Object fileObj : fileList) {
|
||||||
|
JSONObject fileData = JSON.parseObject(JSON.toJSONString(fileObj));
|
||||||
|
|
||||||
|
Map<String, Object> fileReq = new HashMap<>();
|
||||||
|
fileReq.put("corpAccessToken", getCRMToken());
|
||||||
|
fileReq.put("corpId", CertificateConstant.CORP_ID);
|
||||||
|
fileReq.put("mediaTypeDesc", "DOCUMENT");
|
||||||
|
fileReq.put("mediaId", fileData.getString("path"));
|
||||||
|
fileReq.put("igonreMediaIdConvert", false);
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
HttpEntity<Map<String, Object>> fileReqEntity = new HttpEntity<>(fileReq, headers);
|
||||||
|
|
||||||
|
try {
|
||||||
|
ResponseEntity<byte[]> fileResp = restTemplate.exchange(
|
||||||
|
"https://open.fxiaoke.com/media/download",
|
||||||
|
HttpMethod.POST,
|
||||||
|
fileReqEntity,
|
||||||
|
byte[].class);
|
||||||
|
|
||||||
|
if (fileResp.getStatusCode() == HttpStatus.OK && fileResp.getBody() != null) {
|
||||||
|
byte[] fileBytes = fileResp.getBody();
|
||||||
|
String fileName = fileData.getString("filename");
|
||||||
|
String contentType = fileData.getString("ext");
|
||||||
|
|
||||||
|
ByteArrayResource byteArrayResource = new ByteArrayResource(fileBytes) {
|
||||||
|
@Override
|
||||||
|
public String getFilename() {
|
||||||
|
return fileName != null ? fileName : UUID.randomUUID() + ".dat";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
HttpHeaders fileHeaders = new HttpHeaders();
|
||||||
|
fileHeaders.setContentDispositionFormData("file", byteArrayResource.getFilename());
|
||||||
|
|
||||||
|
try {
|
||||||
|
fileHeaders.setContentType(MediaType.parseMediaType(
|
||||||
|
contentType != null ? contentType : MediaType.APPLICATION_OCTET_STREAM_VALUE));
|
||||||
|
} catch (Exception e) {
|
||||||
|
fileHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpEntity<ByteArrayResource> fileEntity = new HttpEntity<>(byteArrayResource, fileHeaders);
|
||||||
|
body.add("file", fileEntity);
|
||||||
|
} else {
|
||||||
|
log.error("文件下载失败,mediaId: {}", fileData.getString("path"));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("下载文件出错", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user