单据上传功能代码提交

pro^2^2
郑明梁 2 years ago
parent c5b7ba7db5
commit 31d1c52a30

@ -314,6 +314,12 @@
<version>1.0.47_1</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>

@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageInfo;
import com.glxp.api.annotation.AuthRuleAnnotation;
@ -229,4 +230,22 @@ public class PlatformController {
return ResultVOUtils.success(pageSimpleResponse);
}
/**
*
*
* @return
*/
@AuthRuleAnnotation("")
@GetMapping("/udiwms/platform/uploadOrder")
public BaseResponse uploadOrder(String orderId) throws JsonProcessingException {
if (StrUtil.isBlank(orderId)) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
}
return platformService.uploadOrder(orderId);
}
}

@ -43,4 +43,6 @@ public interface UnitMaintainPlatformDao {
Long selectCount(@Param("unitId") String unitId, @Param("action") String action);
List<PlatformLinkResponse> selectDelectList(@Param("platformId") String platformId);
PlatformLinkResponse selectByUnitld(@Param("unitld") String unitld);
}

@ -190,4 +190,6 @@ public class FilterOrderRequest extends ListPageRequest {
private List<String> invoiceActions2;
private String orderBy;
private String uploadKey;
}

@ -0,0 +1,19 @@
package com.glxp.api.res.inout;
import com.glxp.api.entity.inout.*;
import lombok.Data;
import java.util.List;
@Data
public class IoUploadOrderResponse {
private List<IoOrderDetailCodeEntity> ioOrderDetailCodeEntityList;
private List<IoCodeTempEntity> ioCodeTempEntityList;
private IoOrderEntity ioOrderEntity;
private PlatformLinkResponse platformLinkRespons;
private List<IoOrderDetailBizEntity> ioOrderDetailBizEntityList;
private List<IoOrderDetailResultEntity> ioOrderDetailResultEntityList;
private List<IoOrderInvoiceEntity> ioOrderInvoiceEntityList;
}

@ -39,4 +39,6 @@ public class PlatformLinkResponse {
private String name;
private String host;
private String appid;
private String secretKey;
}

@ -2,6 +2,7 @@ package com.glxp.api.service.inout;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.entity.inout.UnitMaintainPlatformEntity;
import com.glxp.api.entity.system.PlatformEntity;
@ -105,5 +106,12 @@ public interface PlatformService {
*/
List<PlatformLinkResponse> selectDelectList(PlatformLinkRequest platformLinkRequest);
/**
*
*
* @return
*/
BaseResponse uploadOrder(String orderId) throws JsonProcessingException;
}

@ -5,31 +5,38 @@ import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper;
import com.glxp.api.common.enums.ResultEnum;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.dao.inout.PlatformDao;
import com.glxp.api.dao.inout.UnitMaintainPlatformDao;
import com.glxp.api.entity.inout.UnitMaintainPlatformEntity;
import com.glxp.api.dao.inout.*;
import com.glxp.api.entity.inout.*;
import com.glxp.api.entity.system.PlatformEntity;
import com.glxp.api.idc.service.FileService;
import com.glxp.api.req.inout.PlatformLinkRequest;
import com.glxp.api.res.inout.IoUploadOrderResponse;
import com.glxp.api.res.inout.PlatformLinkResponse;
import com.glxp.api.service.inout.PlatformService;
import com.glxp.api.util.HttpClient;
import com.glxp.api.service.inout.*;
import com.glxp.api.util.OkHttpCli;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.tools.ant.util.DateUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;
@Slf4j
@Service
@ -42,6 +49,24 @@ public class PlatformServiceImpl implements PlatformService {
private UnitMaintainPlatformDao unitMaintainPlatformDao;
@Resource
private OkHttpCli okHttpCli;
@Resource
IoOrderService ioOrderService;
@Resource
IoOrderDetailCodeService ioOrderDetailCodeService;
@Resource
IoCodeTempService ioCodeTempService;
@Resource
IoOrderDetailBizDao ioOrderDetailBizDao;
@Resource
IoOrderDetailResultDao ioOrderDetailResultDao;
@Resource
IoOrderInvoiceMapper ioOrderInvoiceMapper;
@Value("${file_path}")
private String filePath;
@Value("${API_KEY}")
private String apiKey;
@Value("${API_SECRET}")
private String apiSecret;
public int save(PlatformEntity platformEntity) {
if (StringUtils.isEmpty(platformEntity.getId())) {
@ -125,7 +150,7 @@ public class PlatformServiceImpl implements PlatformService {
* @param platformId
* @return
*/
public BaseResponse getTargetActions(String platformId, String invSubCode,String apiKey,String apiSecret) {
public BaseResponse getTargetActions(String platformId, String invSubCode, String apiKey, String apiSecret) {
PlatformEntity platformEntity = platformDao.get(platformId);
if (null == platformEntity) {
return ResultVOUtils.success();
@ -133,7 +158,7 @@ public class PlatformServiceImpl implements PlatformService {
String host = platformEntity.getHost();
Map<String, String> paramMap = new HashMap<>();
paramMap.put("invSubCode", invSubCode);
String resp = okHttpCli.doGet(host + "/udiwms/bussinessType/udimsFilter",paramMap,buildHeader(apiKey,apiSecret));
String resp = okHttpCli.doGet(host + "/udiwms/bussinessType/udimsFilter", paramMap, buildHeader(apiKey, apiSecret));
if (StrUtil.isNotBlank(resp) && resp.contains("20000")) {
return JSON.parseObject(resp, BaseResponse.class);
} else {
@ -143,7 +168,7 @@ public class PlatformServiceImpl implements PlatformService {
}
//获取自助平台一级仓库
public BaseResponse getTargetInv(String platformId,String apiKey,String apiSecret) {
public BaseResponse getTargetInv(String platformId, String apiKey, String apiSecret) {
PlatformEntity platformEntity = platformDao.get(platformId);
if (null == platformEntity) {
return ResultVOUtils.success();
@ -151,7 +176,7 @@ public class PlatformServiceImpl implements PlatformService {
String host = platformEntity.getHost();
String url = host + "/spms/inv/warehouse/filterInv/forUdims";
log.info("拉取自助平台仓库数据:" + url);
String resp = okHttpCli.doGet(url,buildHeader(apiKey,apiSecret));
String resp = okHttpCli.doGet(url, buildHeader(apiKey, apiSecret));
log.info("拉取结果:" + resp);
if (StrUtil.isNotBlank(resp) && resp.contains("20000")) {
try {
@ -168,7 +193,7 @@ public class PlatformServiceImpl implements PlatformService {
//获取自助平台一级仓库所属分库
public BaseResponse getTargetSubInv(String platformId, String invCode,String apiKey,String apiSecret) {
public BaseResponse getTargetSubInv(String platformId, String invCode, String apiKey, String apiSecret) {
PlatformEntity platformEntity = platformDao.get(platformId);
if (null == platformEntity) {
return ResultVOUtils.success();
@ -176,7 +201,7 @@ public class PlatformServiceImpl implements PlatformService {
String host = platformEntity.getHost();
Map<String, String> paramMap = new HashMap<>();
paramMap.put("invCode", invCode);
String resp = okHttpCli.doGet(host + "/spms/sub/inv/warehouse/getSubInvForUdims",paramMap,buildHeader(apiKey,apiSecret));
String resp = okHttpCli.doGet(host + "/spms/sub/inv/warehouse/getSubInvForUdims", paramMap, buildHeader(apiKey, apiSecret));
if (StrUtil.isNotBlank(resp) && resp.contains("20000")) {
return JSON.parseObject(resp, BaseResponse.class);
} else {
@ -284,8 +309,128 @@ public class PlatformServiceImpl implements PlatformService {
return unitMaintainPlatformDao.selectDelectList(platformLinkRequest.getPlatformId());
}
public String[] buildHeader(String apiKey,String apiSecret) {
@Override
public BaseResponse uploadOrder(String orderId) throws JsonProcessingException {
//查询单据信息
IoOrderEntity ioOrderEntity = ioOrderService.findByBillNo(orderId);
if (ioOrderEntity == null) {
return ResultVOUtils.error(999, "该单据不存在!");
}
//查询客户关联信息
PlatformLinkResponse platformLinkRespons = unitMaintainPlatformDao.selectByUnitld(ioOrderEntity.getFromCorp());
if(platformLinkRespons == null){
return ResultVOUtils.error(999, "该单没有设置补单条件!");
}
//获取单据详情
List<IoOrderDetailCodeEntity> ioOrderDetailCodeEntityList=ioOrderDetailCodeService.findByOrderId(orderId);
List<IoCodeTempEntity> ioCodeTempEntityList = ioCodeTempService.findByOrderId(orderId);
for (IoCodeTempEntity ioCodeTempEntity : ioCodeTempEntityList) {
Map<String, String> jsonMap = new HashMap<>();
jsonMap.put("code", ioCodeTempEntity.getCode());
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(jsonMap);
ioCodeTempEntity.setCode(json);
}
//获取业务单
QueryWrapper<IoOrderDetailBizEntity> ew=new QueryWrapper<>();
ew.eq("orderIdFk",orderId);
List<IoOrderDetailBizEntity> ioOrderDetailBizEntityList=ioOrderDetailBizDao.selectList(ew);
//获取结果单
QueryWrapper<IoOrderDetailResultEntity> ew1=new QueryWrapper<>();
ew1.eq("orderIdFk",orderId);
List<IoOrderDetailResultEntity> ioOrderDetailResultEntityList=ioOrderDetailResultDao.selectList(ew1);
//获取发票
QueryWrapper<IoOrderInvoiceEntity> ew2=new QueryWrapper<>();
ew2.eq("orderIdFk",orderId);
List<IoOrderInvoiceEntity> ioOrderInvoiceEntityList=ioOrderInvoiceMapper.selectList(ew2);
ArrayList<String> list=new ArrayList<>();
for (IoOrderInvoiceEntity ioOrderInvoiceEntity : ioOrderInvoiceEntityList) {
if(StrUtil.isNotBlank(ioOrderInvoiceEntity.getLicenseUrl())){
list.add(filePath + "/register/image2/" + ioOrderInvoiceEntity.getLicenseUrl());
ioOrderInvoiceEntity.setLicenseUrl("as" + ioOrderInvoiceEntity.getLicenseUrl());
}
}
relayFile(list,platformLinkRespons.getHost());
//组装数据
String host = platformLinkRespons.getHost();
IoUploadOrderResponse ioUploadOrderResponse=new IoUploadOrderResponse();
ioUploadOrderResponse.setIoOrderEntity(ioOrderEntity);
ioUploadOrderResponse.setPlatformLinkRespons(platformLinkRespons);
ioUploadOrderResponse.setIoCodeTempEntityList(ioCodeTempEntityList);
ioUploadOrderResponse.setIoOrderDetailCodeEntityList(ioOrderDetailCodeEntityList);
ioUploadOrderResponse.setIoOrderDetailResultEntityList(ioOrderDetailResultEntityList);
ioUploadOrderResponse.setIoOrderDetailBizEntityList(ioOrderDetailBizEntityList);
ioUploadOrderResponse.setIoOrderInvoiceEntityList(ioOrderInvoiceEntityList);
String resp = okHttpCli.doPostJson(host + "/spms/sub/inv/warehouse/addOrder",
JSON.toJSONString(ioUploadOrderResponse), buildHeader(platformLinkRespons.getAppid(), platformLinkRespons.getSecretKey()));
//回调结果 返回信息
if (StrUtil.isNotBlank(resp) && resp.contains("20000")) {
return JSON.parseObject(resp, BaseResponse.class);
} else {
log.error("获取自助平台分库失败");
return ResultVOUtils.error(500, "获取自助平台接口异常");
}
}
public String[] buildHeader(String apiKey, String apiSecret) {
String[] headers = {"api_key", apiKey, "secret_key", apiSecret};
return headers;
}
/*转发图片*/
private String relayFile(ArrayList<String> files, String ip) {
String host = ip;
String result = "";
if (!StringUtils.isEmpty(host)) {
host += "/udiwms/file/uploadFile";
OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(30, TimeUnit.SECONDS)//设置连接超时时间
.readTimeout(30, TimeUnit.SECONDS)//设置读取超时时间
.build();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
MultipartBody.Builder builder = new MultipartBody.Builder();
builder.setType(MultipartBody.FORM);
String fileType = "application/octet-stream";
if (files != null && files.size() > 0) {
for (int i = 0; i < files.size(); i++) {
if (!StringUtils.isEmpty(files.get(i))) {
File file = new File(files.get(i));
String fileName = files.get(i);
fileName = "as"+ fileName.substring(fileName.lastIndexOf("/")+1);
builder.addFormDataPart("files", fileName,
RequestBody.create(MediaType.parse(fileType), file));
}
}
}
RequestBody body = builder.build();
Request req = new Request.Builder()
.url(host)
.method("POST", body)
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.addHeader("format", "json")
.addHeader("apiKey", apiKey)
.addHeader("secretKey", apiSecret)
.addHeader("timestamp", DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"))
.addHeader("Access-Control-Allow-Headers", "Authorization, Origin, X-Requested-With, Content-Type, Accept")
.build();
try {
Response response = client.newCall(req).execute();
result = response.body().string();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return result;
}
}

@ -0,0 +1,79 @@
package com.glxp.api.util;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import java.io.*;
public class MultipartFileTest {
private static final Logger log = LoggerFactory.getLogger(MultipartFileTest.class);
private MultipartFileTest() { }
public static void main(String[] args) {
// 本地文件转为MultipartFile类型
String fileName="D:\\1s\\a6294b6b58de15136bb827dd1efdc76.jpg";
fileName = fileName.substring(fileName.lastIndexOf("/"));
}
public static MultipartFile getMultipartFile(InputStream inputStream, String fileName) {
FileItem fileItem = createFileItem(inputStream, fileName);
return new CommonsMultipartFile(fileItem);
}
public static MultipartFile[] getMultipartFiles(InputStream[] inputStream, String fileName) {
// 多文件转换
int length = inputStream.length;
MultipartFile[] multipartFiles = new MultipartFile[length];
for (int i = 0; i < length; i++) {
FileItem fileItem = createFileItem(inputStream[i], fileName);
multipartFiles[i] = new CommonsMultipartFile(fileItem);
}
return multipartFiles;
}
public static FileItem createFileItem(InputStream inputStream, String fileName) {
FileItemFactory factory = new DiskFileItemFactory(16, null);
FileItem fileItem = factory.createItem("file", MediaType.MULTIPART_FORM_DATA_VALUE, true, fileName);
int read = 0;
OutputStream os = null;
byte[] buffer = new byte[10 * 1024 * 1024];
try {
os = fileItem.getOutputStream();
while ((read = inputStream.read(buffer, 0, 4096)) != -1) {
os.write(buffer, 0, read);
}
inputStream.close();
} catch (IOException e) {
log.error("os write exception", e);
throw new IllegalArgumentException("文件流输出失败");
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
log.error("stream os close exception", e);
}
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
log.error("stream inputStream close exception", e);
}
}
}
return fileItem;
}
}

@ -117,6 +117,7 @@ public class OkHttpCli {
}
/**
* post , json
*

@ -15,6 +15,9 @@
(select name from basic_corp bc where bc.erpId = io.fromCorp) fromCorpName,
(select name from basic_corp bc where bc.erpId = io.customerId) customerName
from io_order as io
<if test="uploadKey != null and uploadKey != ''">
INNER JOIN io_unit_maintain_platform a2 on io.action = a2.sourceAction AND io.fromCorp = a2.unitId
</if>
<where>
<if test="id != null and id != ''">
AND id = #{id}
@ -42,7 +45,7 @@
AND deptCode = #{deptCode}
</if>
<if test="invCode != null and invCode != ''">
AND invCode = #{invCode}
AND io.invCode = #{invCode}
</if>
<if test="busType != null">
AND busType = #{busType}

@ -165,4 +165,24 @@
LEFT JOIN basic_bussiness_type b1 ON b1.action = io.sourceAction
where io.platformId = #{platformId}
</select>
<select id="selectByUnitld" resultType="com.glxp.api.res.inout.PlatformLinkResponse">
SELECT
io.id,
io.unitId,
io.platformId,
io.invCode,
io.invName,
io.invSubCode,
io.invSubName,
io.targetAction,
io.targetName,
io.sourceAction,
io.appid,
io.secretKey,
a1.host
FROM io_unit_maintain_platform io
inner join auth_platform a1 on a1.id = io.platformId
where io.unitId = #{unitld}
</select>
</mapper>
Loading…
Cancel
Save