Commit 74e4c5a4 authored by 廖旭伟's avatar 廖旭伟

添加文件下载接口

parent 67ee6dc7
...@@ -12,4 +12,6 @@ public class FindHandlingPageReq extends BaseApiReq { ...@@ -12,4 +12,6 @@ public class FindHandlingPageReq extends BaseApiReq {
private Integer size; private Integer size;
private String search; private String search;
private String url;
} }
package com.mortals.xhx.busiz.web; package com.mortals.xhx.busiz.web;
import cn.hutool.core.codec.Base64; import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
...@@ -12,24 +10,22 @@ import com.mortals.framework.annotation.UnAuth; ...@@ -12,24 +10,22 @@ import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ICacheService; import com.mortals.framework.service.ICacheService;
import com.mortals.xhx.busiz.req.ComplexHandleReq;
import com.mortals.xhx.busiz.req.ComplexImplementationReq; import com.mortals.xhx.busiz.req.ComplexImplementationReq;
import com.mortals.xhx.busiz.req.FindHandlingPageReq; import com.mortals.xhx.busiz.req.FindHandlingPageReq;
import com.mortals.xhx.busiz.req.accept.ComplexAcceptReq; import com.mortals.xhx.busiz.req.accept.ComplexAcceptReq;
import com.mortals.xhx.busiz.rsp.ApiResp; import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.busiz.rsp.ComplexApiResp;
import com.mortals.xhx.busiz.rsp.ImplementEventInfo; import com.mortals.xhx.busiz.rsp.ImplementEventInfo;
import com.mortals.xhx.busiz.rsp.implement.ComplexImplementDetailInfo; import com.mortals.xhx.busiz.rsp.implement.ComplexImplementDetailInfo;
import com.mortals.xhx.busiz.rsp.material.ComplexMaterialInfo; import com.mortals.xhx.busiz.rsp.material.ComplexMaterialInfo;
import com.mortals.xhx.busiz.rsp.situation.ComplexStituationInfo; import com.mortals.xhx.busiz.rsp.situation.ComplexStituationInfo;
import com.mortals.xhx.busiz.rsp.work.ComplexWorkInfo; import com.mortals.xhx.busiz.rsp.work.ComplexWorkInfo;
import com.mortals.xhx.common.code.ApiRespCodeEnum; import com.mortals.xhx.common.code.ApiRespCodeEnum;
import com.mortals.xhx.protocol.complex.ComplexApiRest; import com.mortals.xhx.protocol.complex.matter.model.rsp.AcceptRspInfo;
import com.mortals.xhx.protocol.complex.matter.model.rsp.*; import com.mortals.xhx.protocol.complex.matter.model.rsp.DictInfo;
import com.mortals.xhx.protocol.complex.matter.model.rsp.HandlingRspInfoList;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.axis.utils.StringUtils; import org.apache.axis.utils.StringUtils;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.math3.Field;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
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;
...@@ -40,7 +36,8 @@ import java.io.File; ...@@ -40,7 +36,8 @@ import java.io.File;
import java.util.List; import java.util.List;
import static com.mortals.xhx.common.key.Constant.HTTP_TIMEOUT; import static com.mortals.xhx.common.key.Constant.HTTP_TIMEOUT;
import static com.mortals.xhx.common.key.RedisKey.*; import static com.mortals.xhx.common.key.RedisKey.KEY_COMPLEX_REQ;
import static com.mortals.xhx.common.key.RedisKey.KEY_EVENT_IMPLEMENTATION_RESP;
/** /**
* 综窗对接api * 综窗对接api
...@@ -351,6 +348,38 @@ public class ComplexApiController { ...@@ -351,6 +348,38 @@ public class ComplexApiController {
} }
} }
/**
* 文件下载
*
* @param req
* @return
*/
@PostMapping("common/downloadFileFtp")
@UnAuth
public String downloadFileFtp(@RequestBody FindHandlingPageReq req) {
log.info("【查询字典值】【请求体】--> " + JSONObject.toJSONString(req));
req.setUrlPath("common/downloadFileFtp");
ApiResp<String> rsp = new ApiResp<>();
rsp.setMsg(ApiRespCodeEnum.SUCCESS.getLabel());
rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue());
try {
req.setNonce(RandomUtil.randomNumbers(6));
cacheService.lpush(KEY_COMPLEX_REQ, JSONObject.toJSONString(req));
String rest = cacheService.blpop(KEY_EVENT_IMPLEMENTATION_RESP + req.getNonce(), HTTP_TIMEOUT, String.class);
if (ObjectUtil.isEmpty(rest)) {
throw new AppException("请求访问超时");
}
Rest<String> eventRest = JSON.parseObject(rest, new TypeReference<Rest<String>>() {
});
return JSON.toJSONString(eventRest);
} catch (Exception e) {
log.error("接收数据失败", e);
rsp.setCode(ApiRespCodeEnum.FAILED.getValue());
rsp.setMsg(e.getMessage());
return JSON.toJSONString(rsp);
}
}
public static void main(String[] args) { public static void main(String[] args) {
File file = new File("E:\\pic\\1.png"); File file = new File("E:\\pic\\1.png");
......
...@@ -14,4 +14,6 @@ public class FindHandlingReq { ...@@ -14,4 +14,6 @@ public class FindHandlingReq {
private String waitHandlingSearch; private String waitHandlingSearch;
private String search; private String search;
private String isTongBan; private String isTongBan;
private String url;
} }
...@@ -124,4 +124,11 @@ public interface IComplexMatterService extends IComplexService { ...@@ -124,4 +124,11 @@ public interface IComplexMatterService extends IComplexService {
*/ */
Rest<HandlingRspInfoList> findHandlingPage(String deviceLogo, FindHandlingReq findHandlingReq); Rest<HandlingRspInfoList> findHandlingPage(String deviceLogo, FindHandlingReq findHandlingReq);
/**
* 下载文件
* @param deviceLogo
* @param findHandlingReq
*/
Rest<Object> downloadFileFtp(String deviceLogo, FindHandlingReq findHandlingReq);
} }
...@@ -8,7 +8,6 @@ import com.alibaba.fastjson.JSON; ...@@ -8,7 +8,6 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.service.ICacheService;
import com.mortals.xhx.protocol.complex.AbstractComplexService; import com.mortals.xhx.protocol.complex.AbstractComplexService;
import com.mortals.xhx.protocol.complex.ComplexApiRest; import com.mortals.xhx.protocol.complex.ComplexApiRest;
import com.mortals.xhx.protocol.complex.matter.model.req.AcceptReq; import com.mortals.xhx.protocol.complex.matter.model.req.AcceptReq;
...@@ -22,11 +21,10 @@ import com.mortals.xhx.protocol.complex.matter.model.rsp.matter.MatterWorkInfo; ...@@ -22,11 +21,10 @@ import com.mortals.xhx.protocol.complex.matter.model.rsp.matter.MatterWorkInfo;
import com.mortals.xhx.protocol.complex.matter.model.rsp.work.WorkInfo; import com.mortals.xhx.protocol.complex.matter.model.rsp.work.WorkInfo;
import com.mortals.xhx.protocol.complex.matter.service.IComplexMatterService; import com.mortals.xhx.protocol.complex.matter.service.IComplexMatterService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.util.ArrayList; import java.util.Base64;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -255,6 +253,25 @@ public class ComplexMatterServiceImpl extends AbstractComplexService implements ...@@ -255,6 +253,25 @@ public class ComplexMatterServiceImpl extends AbstractComplexService implements
return Rest.fail(complexApiRest.getMessage()); return Rest.fail(complexApiRest.getMessage());
} }
@Override
public Rest<Object> downloadFileFtp(String deviceLogo, FindHandlingReq findHandlingReq) {
String mattersApi = host + "/common/downloadFileFtp";
Map<String, String> paramMap = new HashMap<>();
paramMap.put("url", findHandlingReq.getUrl());
String deviceToken = checkToken(deviceLogo);
byte[] rest = HttpUtil.createGet(mattersApi)
.header("X-Access-Token", deviceToken)
.formStr(paramMap).timeout(-1)
.executeAsync().bodyBytes();
//log.info("downloadFileFtp resp:{}", rest);
if(rest.length>1024){
String base64Str = Base64.getEncoder().encodeToString(rest);
return Rest.ok("成功",base64Str);
}
return Rest.fail("下载文件不存在");
}
@Override @Override
public Rest<List<MaterialInfo>> getMaterialByEventAndSituation(String deviceLogo, ImplementationReq implementationReq) { public Rest<List<MaterialInfo>> getMaterialByEventAndSituation(String deviceLogo, ImplementationReq implementationReq) {
......
package com.mortals.xhx.thread;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.common.Rest;
import com.mortals.framework.service.ICacheService;
import com.mortals.xhx.protocol.complex.matter.model.req.FindHandlingReq;
import com.mortals.xhx.protocol.complex.matter.model.rsp.HandlingRspInfoList;
import com.mortals.xhx.protocol.complex.matter.service.IComplexMatterService;
import com.mortals.xhx.utils.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import static com.mortals.xhx.common.key.Constant.REDIS_RESP_TIMEOUT;
import static com.mortals.xhx.common.key.RedisKey.KEY_EVENT_IMPLEMENTATION_RESP;
@Slf4j
public class DownloadFileFtpSendTask implements Runnable{
private FindHandlingReq findHandlingReq;
private String deviceLogo;
private IComplexMatterService complexMatterService;
private ICacheService cacheService;
public DownloadFileFtpSendTask(String deviceLogo, FindHandlingReq findHandlingReq){
this.findHandlingReq = findHandlingReq;
this.deviceLogo = deviceLogo;
complexMatterService = SpringUtils.getBean(IComplexMatterService.class);
cacheService = SpringUtils.getBean(ICacheService.class);
}
@Override
public void run() {
try {
log.info("DownloadFileFtpSendTask启动发送");
Rest<Object> rest = complexMatterService.downloadFileFtp(deviceLogo, findHandlingReq);
cacheService.lpushForTime(KEY_EVENT_IMPLEMENTATION_RESP + findHandlingReq.getNonce(), REDIS_RESP_TIMEOUT, JSONObject.toJSONString(rest));
} catch (Exception e) {
log.error("发送异常:" + e);
}
}
}
...@@ -84,6 +84,10 @@ public class SendThread extends AbstractThread { ...@@ -84,6 +84,10 @@ public class SendThread extends AbstractThread {
FindHandlingReq implementationReq = JSONObject.parseObject(reqStr, FindHandlingReq.class); FindHandlingReq implementationReq = JSONObject.parseObject(reqStr, FindHandlingReq.class);
FindHandlingSendTask findHandlingSendTask = new FindHandlingSendTask(deviceCode, implementationReq); FindHandlingSendTask findHandlingSendTask = new FindHandlingSendTask(deviceCode, implementationReq);
ThreadPool.getInstance().execute(findHandlingSendTask); ThreadPool.getInstance().execute(findHandlingSendTask);
} else if ("common/downloadFileFtp".equals(urlPath)) {
FindHandlingReq implementationReq = JSONObject.parseObject(reqStr, FindHandlingReq.class);
DownloadFileFtpSendTask downloadFileFtpSendTask = new DownloadFileFtpSendTask(deviceCode, implementationReq);
ThreadPool.getInstance().execute(downloadFileFtpSendTask);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment