|
|
@ -1,15 +1,17 @@
|
|
|
|
package com.glxp.sale.admin.controller.sync;
|
|
|
|
package com.glxp.sale.admin.controller.sync;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.lang.Dict;
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
import com.glxp.sale.admin.constant.*;
|
|
|
|
import com.glxp.sale.admin.constant.*;
|
|
|
|
import com.glxp.sale.admin.entity.param.SystemParamConfigEntity;
|
|
|
|
import com.glxp.sale.admin.entity.param.SystemParamConfigEntity;
|
|
|
|
import com.glxp.sale.admin.entity.sync.*;
|
|
|
|
import com.glxp.sale.admin.entity.sync.*;
|
|
|
|
import com.glxp.sale.admin.http.SpGetHttp;
|
|
|
|
import com.glxp.sale.admin.http.SpGetHttp;
|
|
|
|
import com.glxp.sale.admin.http.SpPostHttp;
|
|
|
|
import com.glxp.sale.admin.http.SpPostHttp;
|
|
|
|
|
|
|
|
import com.glxp.sale.admin.idc.utils.UriUtils;
|
|
|
|
import com.glxp.sale.admin.req.sync.SpsSyncDataRequest;
|
|
|
|
import com.glxp.sale.admin.req.sync.SpsSyncDataRequest;
|
|
|
|
|
|
|
|
import com.glxp.sale.admin.req.sync.SyncUpLoadRequest;
|
|
|
|
import com.glxp.sale.admin.res.sync.*;
|
|
|
|
import com.glxp.sale.admin.res.sync.*;
|
|
|
|
import com.glxp.sale.admin.service.param.SystemParamConfigService;
|
|
|
|
import com.glxp.sale.admin.service.param.SystemParamConfigService;
|
|
|
|
import com.glxp.sale.admin.service.sync.BasicExportService;
|
|
|
|
import com.glxp.sale.admin.service.sync.BasicExportService;
|
|
|
@ -22,22 +24,28 @@ import lombok.RequiredArgsConstructor;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
|
|
|
|
|
import org.springframework.http.HttpMethod;
|
|
|
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.FileReader;
|
|
|
|
import java.io.FileReader;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
public class SpsSyncDataController {
|
|
|
|
public class SpsSyncDataController {
|
|
|
|
|
|
|
|
private final UriUtils uriUtils;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
RedisUtil redisUtil;
|
|
|
|
RedisUtil redisUtil;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
@ -291,5 +299,67 @@ public class SpsSyncDataController {
|
|
|
|
return ResultVOUtils.error(500, "更新失败!");
|
|
|
|
return ResultVOUtils.error(500, "更新失败!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("sps/sync/upload/data")
|
|
|
|
|
|
|
|
public Object uploadData(HttpServletRequest request, @RequestBody SyncUpLoadRequest upLoadRequest) {
|
|
|
|
|
|
|
|
String uri = uriUtils.parseUri(request.getRequestURL().toString());
|
|
|
|
|
|
|
|
String upperServerHost = systemParamConfigService.selectValueByParamKey("upper_server_ip");
|
|
|
|
|
|
|
|
if (StrUtil.isNotEmpty(upperServerHost)) {
|
|
|
|
|
|
|
|
uri = upperServerHost + "/" + uri;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
JSONObject jsonObject = redirect(request, uri, upLoadRequest.getExportType());
|
|
|
|
|
|
|
|
return jsonObject;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private JSONObject redirect(HttpServletRequest request, String uri, BasicExportTypeEnum exportType) {
|
|
|
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
|
|
|
HttpEntity<String> httpEntity = uriUtils.buildHeader(request);
|
|
|
|
|
|
|
|
String taskId = request.getHeader("taskId");
|
|
|
|
|
|
|
|
ResponseEntity<JSONObject> responseBody = null;
|
|
|
|
|
|
|
|
if (request.getMethod().equals("POST")) {
|
|
|
|
|
|
|
|
//写入日志
|
|
|
|
|
|
|
|
writeUploadLog(taskId, httpEntity.getBody(), exportType);
|
|
|
|
|
|
|
|
responseBody = restTemplate.postForEntity(uri, httpEntity, JSONObject.class);
|
|
|
|
|
|
|
|
} else if (request.getMethod().equals("GET")) {
|
|
|
|
|
|
|
|
writeUploadLog(taskId, httpEntity.getBody(), exportType);
|
|
|
|
|
|
|
|
responseBody = restTemplate.exchange(uri, HttpMethod.GET, httpEntity, JSONObject.class);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
JSONObject result = responseBody.getBody();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Async
|
|
|
|
|
|
|
|
public void writeUploadLog(String taskId, String content, BasicExportTypeEnum exportType) {
|
|
|
|
|
|
|
|
String key = gennerOrderUtils.getOrders();
|
|
|
|
|
|
|
|
BasicUploadStatusEntity basicUploadStatusEntity = new BasicUploadStatusEntity();
|
|
|
|
|
|
|
|
basicUploadStatusEntity.setId(key);
|
|
|
|
|
|
|
|
basicUploadStatusEntity.setTaskId(taskId);
|
|
|
|
|
|
|
|
basicUploadStatusEntity.setStartTime(DateUtil.getDateTime());
|
|
|
|
|
|
|
|
basicUploadStatusEntity.setIdDatas(exportType.getKey());
|
|
|
|
|
|
|
|
basicUploadStatusEntity.setType(exportType.getRemark());
|
|
|
|
|
|
|
|
basicUploadStatusEntity.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL);
|
|
|
|
|
|
|
|
basicUploadService.insertDownloadStatus(basicUploadStatusEntity);
|
|
|
|
|
|
|
|
FileUtils.makeDirectory(filePath + "upload/");
|
|
|
|
|
|
|
|
String fileName = filePath + "upload/" + exportType.getRemark() + "-" + taskId + ".udi";
|
|
|
|
|
|
|
|
FileUtils.SaveFileAs(content, fileName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Async
|
|
|
|
|
|
|
|
public void writeDownloadLog(String taskId, String content, BasicExportTypeEnum exportType) {
|
|
|
|
|
|
|
|
String key = gennerOrderUtils.getOrders();
|
|
|
|
|
|
|
|
BasicExportStatusEntity myEntity = new BasicExportStatusEntity();
|
|
|
|
|
|
|
|
myEntity.setId(key);
|
|
|
|
|
|
|
|
myEntity.setUpdateTime(new Date());
|
|
|
|
|
|
|
|
myEntity.setType(exportType.getRemark());
|
|
|
|
|
|
|
|
myEntity.setIdDatas(exportType.getKey());
|
|
|
|
|
|
|
|
myEntity.setStartTime(DateUtil.getDateTime());
|
|
|
|
|
|
|
|
myEntity.setTaskId(taskId);
|
|
|
|
|
|
|
|
myEntity.setStatus(Constant.SYNC_STATUS_WAIT);
|
|
|
|
|
|
|
|
basicExportService.insertExportStatus(myEntity);
|
|
|
|
|
|
|
|
FileUtils.makeDirectory(filePath + "download/");
|
|
|
|
|
|
|
|
String fileName = filePath + "/download/" + BasicProcessStatus.NEW_ALL_ORDER + "-" + taskId + ".udi";
|
|
|
|
|
|
|
|
FileUtils.SaveFileAs(content, fileName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|