first commit 20230223

master
CL 2 years ago
commit ce9c9171a3

@ -0,0 +1,80 @@
// 获取指定日期汇率
jQuery(document).ready(function(){
//选择下拉框触发的事件
WfForm.bindDetailFieldChangeEvent("field11006,field32516", function(id,rowIndex,value){
// console.log("WfForm.bindDetailFieldChangeEvent--",id,rowIndex,value);
var code=WfForm.getSelectShowName("field11006_"+rowIndex);
var date=WfForm.getFieldValue("field32516_"+rowIndex);
// console.log(code)
// console.log(date)
checkMain(rowIndex,code,date);
});
WfForm.bindDetailFieldChangeEvent("field19674,field32535", function(id,rowIndex,value){
// console.log("WfForm.bindDetailFieldChangeEvent--",id,rowIndex,value);
var code=WfForm.getSelectShowName("field32535_"+rowIndex);
var date=WfForm.getFieldValue("field19674_"+rowIndex);
checkMain2(rowIndex,code,date);
});
//
function checkMain(rowIndex,code,date){
if(code&&date){
$.ajax({
type:"post",
url:"/api/workflow/aixinspan/rate",
data:{"code":code,"date":date},
dataType:"json",
success:function(req){
// console.log("------------ajax---------------")
// console.log(req.code)
if(req.code==1){
//给字段赋值
WfForm.changeFieldValue("field32517_"+rowIndex, {value:req.data});
}else{
window.top.Dialog.alert(req.msg)
//给字段赋值
WfForm.changeFieldValue("field32517_"+rowIndex, {value:""});
}
}
});
}
}
function checkMain2(rowIndex,code,date){
if(code&&date){
$.ajax({
type:"post",
url:"/api/workflow/aixinspan/rate",
data:{"code":code,"date":date},
dataType:"json",
success:function(req){
// console.log("------------ajax---------------")
// console.log(req.code)
if(req.code==1){
//给字段赋值
WfForm.changeFieldValue("field32536_"+rowIndex, {value:req.data});
}else{
window.top.Dialog.alert(req.msg)
//给字段赋值
WfForm.changeFieldValue("field32536_"+rowIndex, {value:""});
}
}
});
}
}
});

@ -0,0 +1,2 @@
#AppCode
AppCode=6f926d7c60de4927b312d3017fcec53a

@ -0,0 +1,117 @@
package com.engine.web.aixinaction;
import com.alibaba.fastjson.JSON;
import com.api.aixinchina.utils.HttpUtils;
import com.api.aixinchina.utils.R;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.general.BaseBean;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author:CL
* @date:2023/1/29 8:34
*/
public class AixinAction {
private static final Logger LOGGER = LoggerFactory.getLogger("爱信中国");
@POST
@Path("/rate")
public R<String> getRate(@Context HttpServletRequest request, @Context HttpServletResponse response) throws ParseException {
LOGGER.info("com.engine.web.aixinaction.AixinAction 已进入 rate接口");
// 读取AppCode
BaseBean bb=new BaseBean();
String AppCode = bb.getPropValue("aixinChina", "AppCode");
if(AppCode==""){
return R.error("请填写正确的AppCode");
}
// 获取币种名称
String codeName = request.getParameter("code");
if ("RMB".equals(codeName)) {
return R.success("100.00");
}
// 或许要查询汇率的日期
String date = request.getParameter("date");
// 因为阿里云只能按月查询且格式必须yyyyMM 对日期进行格式转换
Date date1 = new SimpleDateFormat("yyyy-MM-dd").parse(date);
String result = new SimpleDateFormat("yyyyMM").format(date1);
// 访问第三方阿里云接口
String host = "http://ali-waihui.showapi.com";
String path = "/bankhis";
String method = "GET";
String appcode = AppCode;
Map<String, String> headers = new HashMap<String, String>();
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
headers.put("Authorization", "APPCODE " + appcode);
Map<String, String> querys = new HashMap<String, String>();
// 货币编号
querys.put("code", codeName);
querys.put("month", result);
try {
HttpResponse rageResponse = HttpUtils.doGet(host, path, method, headers, querys);
// 获取查询的结果 转为map
String mes = EntityUtils.toString(rageResponse.getEntity());
// 第一次结果的map
HashMap resultMap = JSON.parseObject(mes, HashMap.class);
LOGGER.info("com.engine.web.aixinaction.AixinAction 阿里云调用结果[{}]",resultMap);
// 筛选第一次结果获取body
HashMap bodyMap = JSON.parseObject(resultMap.get("showapi_res_body").toString(), HashMap.class);
// 获取返回的状态码 code
Integer retCode = (Integer) bodyMap.get("ret_code");
//判断阿里云api是否访问成功 ret_code为0查询成功 否则 查询失败 不扣费
if (retCode == 0) {
// 获取到最终需要的list
List<Map<String, String>> rateList = (List<Map<String, String>>) bodyMap.get("list");
for (Map<String, String> map : rateList) {
// 发布日期
String publish_time = map.get("publish_time");
// 判断日期是否为需要的日期 返回对应的中行折算价
if ( date.equals(publish_time)) {
//中行折算价
String middle_rate = map.get("middle_rate");
return R.success(middle_rate);
}
}
return R.error("该天未查询到汇率,请您重新输入");
} else {
// 阿里云code调用失败的return 返回他的提示信息
String remark = (String) bodyMap.get("remark");
return R.error(remark);
}
} catch (Exception e) {
LOGGER.info("com.engine.web.aixinaction.AixinAction catch捕获",e);
return R.error("出现异常,请联系管理员");
}
}
}

@ -0,0 +1,2 @@
修改AppCode
WEAVER\ecology\WEB-INF\prop\aixinChina.properties

@ -0,0 +1,11 @@
WEAVER\ecology\classbean\com\api\aixinchina\utils\HttpUtils.class
WEAVER\ecology\classbean\com\api\aixinchina\utils\R.class
WEAVER\ecology\classbean\com\api\aixinchina\AixinAction.class
WEAVER\ecology\classbean\com\engine\web\aixinactions\AixinAction.class
修改AppCode
WEAVER\ecology\WEB-INF\prop\aixinChina.properties
Loading…
Cancel
Save