2025-06-24 18:01:25 +08:00
|
|
|
|
package com.czlis.interfaceCommon.utils;
|
2025-05-21 16:19:52 +08:00
|
|
|
|
|
2025-06-27 13:05:23 +08:00
|
|
|
|
import cn.hutool.core.util.XmlUtil;
|
2025-05-21 16:19:52 +08:00
|
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
|
|
|
import cn.hutool.http.HttpResponse;
|
2025-06-27 13:05:23 +08:00
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
2025-05-21 16:19:52 +08:00
|
|
|
|
import com.czlis.common.config.RuoYiConfig;
|
2025-07-01 11:52:54 +08:00
|
|
|
|
import com.czlis.interfaceCommon.constants.LisinterfaceNameConstants;
|
2025-05-21 16:19:52 +08:00
|
|
|
|
import com.czlis.common.core.domain.Result;
|
|
|
|
|
|
import com.czlis.interfaceCommon.mapper.LisInterfaceMapper;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
2025-06-27 13:05:23 +08:00
|
|
|
|
|
2025-05-21 16:19:52 +08:00
|
|
|
|
@Slf4j
|
|
|
|
|
|
@Component
|
|
|
|
|
|
public class LisInterfaceUtil {
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
LisInterfaceMapper lisInterfaceMapper;
|
2025-06-27 13:05:23 +08:00
|
|
|
|
@Resource
|
|
|
|
|
|
CommonUtil commonUtil;
|
2025-05-21 16:19:52 +08:00
|
|
|
|
|
2025-06-27 13:05:23 +08:00
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param type
|
|
|
|
|
|
* @param inValue
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2025-05-21 16:19:52 +08:00
|
|
|
|
public Result invokeLisInterface(String type,String inValue) {
|
2025-06-27 13:05:23 +08:00
|
|
|
|
String interfaceType = commonUtil.getComOptValue("HISOPT","SP_INTER");
|
2025-05-21 16:19:52 +08:00
|
|
|
|
switch (interfaceType){
|
2025-06-27 13:05:23 +08:00
|
|
|
|
case "2": //存储过程
|
2025-05-21 16:19:52 +08:00
|
|
|
|
return invokeSP(type, inValue);
|
2025-06-27 13:05:23 +08:00
|
|
|
|
case "3": //http方式
|
2025-05-21 16:19:52 +08:00
|
|
|
|
return invokeHttp(type, inValue);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-27 13:05:23 +08:00
|
|
|
|
return new Result("-1","无效的接口方式,请检查参数设置!!");
|
2025-05-21 16:19:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 存储过程方式调用接口
|
|
|
|
|
|
* @param type
|
|
|
|
|
|
* @param inValue
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2025-06-27 13:05:23 +08:00
|
|
|
|
//@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
|
private Result invokeSP(String type,String inValue){
|
2025-05-21 16:19:52 +08:00
|
|
|
|
Map<String,Object> map = new HashMap<>();
|
2025-06-27 13:05:23 +08:00
|
|
|
|
//为了兼容老接口,存储过程方式使用的是xml,这里需要把入参转成xml格式
|
|
|
|
|
|
String xmlStr = changeXml(inValue);
|
|
|
|
|
|
map.put("invalue",xmlStr);
|
2025-05-21 16:19:52 +08:00
|
|
|
|
map.put("retcode","");
|
|
|
|
|
|
map.put("retmsg","");
|
|
|
|
|
|
switch (type){
|
2025-06-27 13:05:23 +08:00
|
|
|
|
case LisinterfaceNameConstants.GETREQINTERFACE:
|
2025-05-21 16:19:52 +08:00
|
|
|
|
lisInterfaceMapper.sp_lis_getreqinterface(map);
|
|
|
|
|
|
break;
|
2025-06-27 13:05:23 +08:00
|
|
|
|
case LisinterfaceNameConstants.SETDICT:
|
2025-05-21 16:19:52 +08:00
|
|
|
|
lisInterfaceMapper.sp_lis_setdict(map);
|
|
|
|
|
|
break;
|
2025-06-27 13:05:23 +08:00
|
|
|
|
case LisinterfaceNameConstants.SETREPORT:
|
2025-05-21 16:19:52 +08:00
|
|
|
|
lisInterfaceMapper.sp_lis_setreport(map);
|
|
|
|
|
|
break;
|
2025-06-27 13:05:23 +08:00
|
|
|
|
case LisinterfaceNameConstants.SETREQSTATUS:
|
2025-05-21 16:19:52 +08:00
|
|
|
|
lisInterfaceMapper.sp_lis_setreqstatus(map);
|
|
|
|
|
|
break;
|
2025-06-27 13:05:23 +08:00
|
|
|
|
case LisinterfaceNameConstants.DAYMESSAGE:
|
2025-05-21 16:19:52 +08:00
|
|
|
|
lisInterfaceMapper.sp_lis_daymessage(map);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
String retCode = String.valueOf(map.get("retcode"));
|
|
|
|
|
|
String retMsg = String.valueOf(map.get("retmsg"));
|
|
|
|
|
|
log.info("调用存储过程{}返回值:{},{}",type,retCode,retMsg);
|
|
|
|
|
|
if(retCode.equals("0")){
|
|
|
|
|
|
return new Result("0","调用接口成功!");
|
|
|
|
|
|
}else{
|
|
|
|
|
|
return new Result("-1","调用接口失败!"+retMsg);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* http方式调用接口
|
|
|
|
|
|
* @param transCode
|
|
|
|
|
|
* @param jsonStr
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2025-06-27 13:05:23 +08:00
|
|
|
|
private Result invokeHttp(String transCode,String jsonStr){
|
2025-05-21 16:19:52 +08:00
|
|
|
|
String interfaceUrl = RuoYiConfig.getInterfaceUrl();
|
|
|
|
|
|
if(interfaceUrl == null || "".equals(interfaceUrl)) return new Result("-1","没有配置地址,请检查interfaceUrl配置项!!!");
|
|
|
|
|
|
interfaceUrl = interfaceUrl+"/"+transCode;
|
|
|
|
|
|
String retMsg = "";
|
|
|
|
|
|
try {
|
|
|
|
|
|
HttpRequest httpRequest = HttpRequest.post(interfaceUrl);
|
|
|
|
|
|
httpRequest.header("Content-Type","application/json");
|
|
|
|
|
|
HttpResponse httpResponse = httpRequest.body(jsonStr).execute();
|
|
|
|
|
|
int status = httpResponse.getStatus();
|
|
|
|
|
|
retMsg = httpResponse.body();
|
|
|
|
|
|
if (status != 200) {
|
|
|
|
|
|
log.info("调用http接口失败:"+retMsg);
|
|
|
|
|
|
return new Result("-1","调用http接口失败:"+retMsg);
|
|
|
|
|
|
}
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
log.error("调用lis的http接口出错:",e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return new Result("0","调用接口成功!",retMsg);
|
|
|
|
|
|
}
|
2025-06-27 13:05:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String changeXml(String inValue){
|
|
|
|
|
|
JSONObject jsonObj = JSONUtil.parseObj(inValue);
|
|
|
|
|
|
Map<String,Object> map = jsonObj.toBean(Map.class);
|
|
|
|
|
|
return XmlUtil.mapToXmlStr(map, "Request");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-21 16:19:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|