Merge remote-tracking branch 'origin/main' into main

This commit is contained in:
fang 2024-11-13 09:47:55 +08:00
commit 9cc64cd648
3 changed files with 61 additions and 13 deletions

View File

@ -83,4 +83,15 @@ public class AuthService {
} }
return null; return null;
} }
public static void logout(String eoss_ip,String session_id){
String url = String.format("%s/sso2/authCenter/logout", eoss_ip);
// 构建 URL添加查询参数
String urlWithParams = UriComponentsBuilder.fromHttpUrl(url)
.queryParam("sessionId", session_id)
.toUriString(); // 生成带参数的完整 URL
ResponseEntity<String> response = restTemplate.exchange(urlWithParams, HttpMethod.GET,null, String.class);
logger.info(String.format("logout→返回结果:%s",response.getBody()));
}
} }

View File

@ -2,12 +2,18 @@ package shkd.sys.sys.eoss;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import kd.bos.cache.CacheFactory;
import kd.bos.cache.DistributeSessionlessCache;
import kd.bos.logging.Log; import kd.bos.logging.Log;
import kd.bos.logging.LogFactory; import kd.bos.logging.LogFactory;
import kd.bos.login.thirdauth.ThirdSSOAuthHandler; import kd.bos.login.thirdauth.ThirdSSOAuthHandler;
import kd.bos.login.thirdauth.UserAuthResult; import kd.bos.login.thirdauth.UserAuthResult;
import kd.bos.login.thirdauth.UserProperType; import kd.bos.login.thirdauth.UserProperType;
import kd.bos.servicehelper.user.UserServiceHelper;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -34,14 +40,25 @@ public class SSOPluginLogin implements ThirdSSOAuthHandler {
public void callTrdSSOLogin(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String s) { public void callTrdSSOLogin(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String s) {
//认证中心的登录地址 //认证中心的登录地址
logger.info(String.format("eoss_ip:%s,client_id:%s,client_secret:%s,重定向地址:%s",EOSS_IP,CLIENT_ID,CLIENT_SECRET,s)); logger.info(String.format("eoss_ip:%s,client_id:%s,client_secret:%s,重定向地址:%s",EOSS_IP,CLIENT_ID,CLIENT_SECRET,s));
try { try {
//重定向的统一认证的地址 String ssourl= EOSS_IP+"/service/SGE-project-sctz-master/pc/dist/login.html";
/** if (httpServletRequest.getRequestURI().contains("/auth/logout.do")){
* 获取授权码 String userName = UserServiceHelper.getCurrentUser("name").getString("name");
*/ DistributeSessionlessCache cache = CacheFactory.getCommonCacheFactory().getDistributeSessionlessCache("customRegion");
String ssourl=String.format("%s/sso2/authCenter/authorize?client_id=%s&response_type=code&authType=0&redirect_uri=%s", String userKey = "user_sessionId_" + userName; // 构造一个唯一的键
EOSS_IP,CLIENT_ID,s); String sessionId = cache.get(userKey);
logger.info(String.format("重定向地址→sendRedirect%s",ssourl)); if (sessionId != null) {
AuthService.logout(EOSS_IP, sessionId);
}
}else{
/**
*重定向的统一认证的地址 获取授权码
*/
ssourl=String.format("%s/sso2/authCenter/authorize?client_id=%s&response_type=code&authType=0&redirect_uri=%s",
EOSS_IP,CLIENT_ID,s);
logger.info(String.format("重定向地址→sendRedirect%s",ssourl));
}
httpServletResponse.sendRedirect(ssourl); httpServletResponse.sendRedirect(ssourl);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@ -61,9 +78,11 @@ public class SSOPluginLogin implements ThirdSSOAuthHandler {
UserAuthResult result=new UserAuthResult(); UserAuthResult result=new UserAuthResult();
//获取返回的授权码 //获取返回的授权码
String code = httpServletRequest.getParameter("code"); String code = httpServletRequest.getParameter("code");
logger.info(String.format("getTrdSSOAuth→code%s",code)); //获取返回的 sessionId
String sessionId = httpServletRequest.getParameter("sessionId");
logger.info(String.format("getTrdSSOAuth→授权码code%s",code));
if (StringUtils.isEmpty(code)){ if (StringUtils.isEmpty(code)){
logger.error("getTrdSSOAuth→code为空"); logger.error("getTrdSSOAuth→授权码code为空");
result.setSucess(false); result.setSucess(false);
}else { }else {
try { try {
@ -81,6 +100,11 @@ public class SSOPluginLogin implements ThirdSSOAuthHandler {
result.setUser(user); result.setUser(user);
result.setSucess(true); result.setSucess(true);
logger.info("SSO用户登录成功进入苍穹系统"); logger.info("SSO用户登录成功进入苍穹系统");
String userKey = "user_sessionId_" + user; // 构造一个唯一的键
DistributeSessionlessCache cache = CacheFactory.getCommonCacheFactory().getDistributeSessionlessCache("customRegion");
cache.put(userKey,sessionId);//将自定义参数加入缓存
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -6,6 +6,8 @@ import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.openapi.api.plugin.ApiSavePlugin; import kd.bos.openapi.api.plugin.ApiSavePlugin;
import kd.bos.openapi.api.plugin.ApiSerializerPlugin; import kd.bos.openapi.api.plugin.ApiSerializerPlugin;
import kd.bos.openapi.api.plugin.SerializerResult; import kd.bos.openapi.api.plugin.SerializerResult;
@ -24,13 +26,14 @@ import java.util.Map;
* @Date 2024/11/7 * @Date 2024/11/7
*/ */
public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin { public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin {
private static final Log logger = LogFactory.getLog(PayBillApiSavePlugin.class);
private static final long serialVersionUID = 7055073356277386444L; private static final long serialVersionUID = 7055073356277386444L;
private String shkd_businessid; private String shkd_businessid;
private String shkd_businessnumber; private String shkd_businessnumber;
@Override @Override
public List<Map<String, Object>> preHandleRequestData(List<Map<String, Object>> reqData) { public List<Map<String, Object>> preHandleRequestData(List<Map<String, Object>> reqData) {
logger.info("接口调用接口参数:{}", reqData);
//付款处理 收款人ID payee 付款银行.编码 payerbank_number payeetype 收款人类型 payeenumber 收款人编码 //付款处理 收款人ID payee 付款银行.编码 payerbank_number payeetype 收款人类型 payeenumber 收款人编码
//payeracctbank_number 付款银行账号.number //payeracctbank_number 付款银行账号.number
@ -51,6 +54,7 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin
Object payeetype = map.get("payeetype");//如果是收款人类型 则为付款处理保存接口 Object payeetype = map.get("payeetype");//如果是收款人类型 则为付款处理保存接口
Object payertype = map.get("payertype");//如果是付款人类型 则为收款处理保存接口 Object payertype = map.get("payertype");//如果是付款人类型 则为收款处理保存接口
if (payeetype != null) { if (payeetype != null) {
logger.info("进入付款处理单API");
objectType = payeetype.toString(); objectType = payeetype.toString();
objectNumber = map.get("payeenumber").toString(); objectNumber = map.get("payeenumber").toString();
fieldName1 = "payee"; fieldName1 = "payee";
@ -58,12 +62,14 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin
bankNumber = map.get("payeracctbank_number").toString(); bankNumber = map.get("payeracctbank_number").toString();
fieldName2 = "payerbank_number"; fieldName2 = "payerbank_number";
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(objectType, "id", new QFilter("billno", QCP.equals, objectNumber).toArray()); DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(objectType, "id", new QFilter("billno", QCP.equals, objectNumber).toArray());
logger.info("objectType:{},objectNumber:{}", objectType, objectNumber);
DynamicObject amAccountbank = BusinessDataServiceHelper.loadSingle("am_accountbank", "id,bank,bank.number", new QFilter("number", QCP.equals, bankNumber).toArray()); DynamicObject amAccountbank = BusinessDataServiceHelper.loadSingle("am_accountbank", "id,bank,bank.number", new QFilter("number", QCP.equals, bankNumber).toArray());
logger.info("amAccountbank:{}", amAccountbank);
map.put(fieldName1, dynamicObject.getString("id")); map.put(fieldName1, dynamicObject.getString("id"));
map.put(fieldName2, amAccountbank.getDynamicObject("bank").getString("number")); map.put(fieldName2, amAccountbank.getDynamicObject("bank").getString("number"));
} }
if (payertype != null){ if (payertype != null) {
objectType = payertype.toString(); objectType = payertype.toString();
objectNumber = map.get("payernumber").toString(); objectNumber = map.get("payernumber").toString();
fieldName1 = "payer"; fieldName1 = "payer";
@ -71,7 +77,9 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin
bankNumber = map.get("accountbank_number").toString(); bankNumber = map.get("accountbank_number").toString();
fieldName2 = "payeebank_number"; fieldName2 = "payeebank_number";
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(objectType, "id", new QFilter("billno", QCP.equals, objectNumber).toArray()); DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(objectType, "id", new QFilter("billno", QCP.equals, objectNumber).toArray());
logger.info("objectType:{},objectNumber:{}", objectType, objectNumber);
DynamicObject amAccountbank = BusinessDataServiceHelper.loadSingle("am_accountbank", "id,bank,bank.number", new QFilter("number", QCP.equals, bankNumber).toArray()); DynamicObject amAccountbank = BusinessDataServiceHelper.loadSingle("am_accountbank", "id,bank,bank.number", new QFilter("number", QCP.equals, bankNumber).toArray());
logger.info("amAccountbank:{}", amAccountbank);
map.put(fieldName1, dynamicObject.getString("id")); map.put(fieldName1, dynamicObject.getString("id"));
map.put(fieldName2, amAccountbank.getDynamicObject("bank").getString("number")); map.put(fieldName2, amAccountbank.getDynamicObject("bank").getString("number"));
} }
@ -80,14 +88,17 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin
// shkd_businessid // shkd_businessid
// shkd_businessnumber // shkd_businessnumber
// shkd_businessname // shkd_businessname
logger.info("最终处理 → 调用接口参数:{}", reqData);
} }
return reqData; return reqData;
} }
@Override @Override
public SerializerResult serialize(Object response, String accept, String contentType) { public SerializerResult serialize(Object response, String accept, String contentType) {
logger.info("进入serialize方法");
try { try {
if (contentType.contains(MediaType.APPLICATION_JSON)) { if (contentType.contains(MediaType.APPLICATION_JSON)) {
logger.info("进入if");
//返回text文本 //返回text文本
String responseStr = new ObjectMapper().writeValueAsString(response); String responseStr = new ObjectMapper().writeValueAsString(response);
JSONObject jsonObject = JSON.parseObject(responseStr); JSONObject jsonObject = JSON.parseObject(responseStr);
@ -100,13 +111,15 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin
result.getJSONObject(0).put("shkd_businessnumber", shkd_businessnumber); result.getJSONObject(0).put("shkd_businessnumber", shkd_businessnumber);
return new SerializerResult(MediaType.TEXT_PLAIN, jsonObject.toJSONString()); return new SerializerResult(MediaType.TEXT_PLAIN, jsonObject.toJSONString());
} else { } else {
logger.info("进入else");
//其他类型的出参序列化 //其他类型的出参序列化
return null; return null;
} }
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
logger.info("catch");
//处理异常时严禁抛出异常可以定义自己的错误返回信息 //处理异常时严禁抛出异常可以定义自己的错误返回信息
String result="..."; String result = "...";
return new SerializerResult(MediaType.TEXT_PLAIN,result); return new SerializerResult(MediaType.TEXT_PLAIN, result);
} }
} }
} }