package com.thunisoft.ymtcinner.webService;
import java.lang.reflect.Method;
import javax.jws.WebService;
import org.apache.commons.lang.BooleanUtils;
import org.bouncycastle.crypto.InvalidCipherTextException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSONObject;
import com.thunisoft.ymtc.contants.YmtcConstants;
import com.thunisoft.ymtc.util.YmtcTapConfig;
import com.thunisoft.ymtcinner.common.YmtcDto;
import com.thunisoft.ymtcinner.common.YmtcRepose;
import com.thunisoft.ymtcinner.common.YmtcRequest;
import com.thunisoft.ymtcinner.consts.YmtcSjzhEnum;
import com.thunisoft.ymtcinner.util.SM2Util;
import com.thunisoft.ymtcinner.util.SpringUtil;
import lombok.extern.slf4j.Slf4j;
@WebService(serviceName = "ISjtbWebService",
targetNamespace = "http://service.ymtc.thunisoft.com",
endpointInterface = "com.thunisoft.ymtcinner.webService.ISjtbWebService"
)
@Component
@Slf4j
public class SjtbWebServiceImpl implements ISjtbWebService {
@Autowired
private YmtcTapConfig ymtcTapConfig;
@Override
public YmtcRepose ajtb(String str) throws InvalidCipherTextException {
String privateJieKey=ymtcTapConfig.getTapConfigDefault(YmtcConstants.PRIVATEKEYJIEM);
String privateJMKey=ymtcTapConfig.getTapConfigDefault(YmtcConstants.PRIVATEKEYJM);
String privateToken=ymtcTapConfig.getTapConfigDefault(YmtcConstants.PRIVATETOKEN);
YmtcRepose ymtcRepose =new YmtcRepose();
YmtcRequest ymtcRequest = JSONObject.parseObject(str,YmtcRequest.class);
if (!privateToken.equals(ymtcRequest.getToken())){
ymtcRepose.setMsg("token验证失败");
ymtcRepose.setCode(500);
return ymtcRepose;
}
String jmParams ="";
try {
jmParams =SM2Util.decryptString(privateJieKey, ymtcRequest.getParams());
} catch (Exception e){
log.error("解密失败,请检查私钥!{}",e);
ymtcRepose.setMsg("解密失败,请检查私钥!");
ymtcRepose.setCode(500);
return ymtcRepose;
}
YmtcDto ymtcDto = new YmtcDto();
try {
ymtcDto =JSONObject.parseObject(jmParams, YmtcDto.class);
YmtcSjzhEnum ymtcSjzh = YmtcSjzhEnum.getYmtcSjzh(ymtcDto.getMethodName());
Class<?> clazz =SpringUtil.getBean(ymtcSjzh.getClassName()).getClass();
// 获取方法
// 加载类
Method method;
// 不需要入参的
if (BooleanUtils.isTrue(ymtcSjzh.getSfyrc())){
method = clazz.getMethod(ymtcSjzh.getDyMethods(), ymtcSjzh.getParams());
}else {
method = clazz.getMethod(ymtcSjzh.getDyMethods());
}
// 如果方法是静态的,可以直接调用
// 如果方法是实例方法,需要先实例化对象
// 如果是静态方法,传入null
Class<?> params =ymtcSjzh.getParams();
Object newParams =JSONObject.parseObject(ymtcDto.getParams(),params);
Object result = null;
try {
if (ymtcSjzh.getSfyrc()){
result = method.invoke(SpringUtil.getBean(ymtcSjzh.getClassName()),newParams);
}else {
result = method.invoke(SpringUtil.getBean(ymtcSjzh.getClassName()));
}
ymtcRepose.setCode(200);
ymtcRepose.setData(SM2Util.encryptString(privateJMKey, JSONObject.toJSONString(result)));
ymtcRepose.setMsg("操作成功");
} catch (Exception e) {
ymtcRepose.setCode(500);
ymtcRepose.setData(SM2Util.encryptString(privateJMKey, JSONObject.toJSONString(result)));
ymtcRepose.setMsg("调用内网获取数据异常,请联系内网运维人员查看详细日志!");
}
} catch (Exception e) {
log.error("接口异常{},调用方法:{},调用参数:{}", e,ymtcDto.getMethodName(),ymtcDto.getParams());
}
return ymtcRepose;
}
}
package com.thunisoft.ymtcinner.consts;
import com.alibaba.fastjson.JSONObject;
import com.thunisoft.ymtc.bean.dto.AjPageDTO;
import com.thunisoft.ymtc.bean.dto.XqParamsDTO;
import com.thunisoft.ymtc.controller.AjxxListController;
import com.thunisoft.ymtc.service.impl.CommonYmtcAjServiceImpl;
import com.thunisoft.ymtcinner.business.ymtcrzxx.model.YmtcRzxx;
import com.thunisoft.ymtcinner.business.ymtcrzxx.service.YmtcRzxxService;
import com.thunisoft.ymtcinner.business.ymtcsjmd.model.YmtcSjmd;
import com.thunisoft.ymtcinner.business.ymtcsjmd.service.YmtcSjmdService;
import com.thunisoft.ymtcinner.business.ymtcwbmk.service.YmtcWbmkService;
import com.thunisoft.ymtcinner.business.ymtcyhfk.model.YmtcYhfk;
import com.thunisoft.ymtcinner.business.ymtcyhfk.service.YmtcYhfkService;
/**
* YmtcSjzh
* @description
* @author lenovo
* @date 2024/4/25 10:41
* @version TODO
*/
public enum YmtcSjzhEnum {
/** 1 获取外部模块 */
SELECTWBMKALL(YmtcWbmkService.class,null,"selectWbmkAll","selectAll",false),
/** 1 获取案件列表 */
SEARCHEMTAJ(AjxxListController.class, AjPageDTO.class,"searchEmtcAj","searchAjxxEmtcByAjbh",true),
/** 1 获取个案详情 */
SEARCHEMTXQ(AjxxListController.class, XqParamsDTO.class,"searchEmtcXq","getAjxqxx1",true),
/** 1 根据案号获取列表 */
SEARCHEMTAJBYAH(AjxxListController.class, JSONObject.class,"searchAjxxEmtcByAh","searchAjxxEmtcByAh",true),
/** 1 插入客户反馈数据 */
INSERYHFK(YmtcYhfkService.class, YmtcYhfk.class,"insertYhfk","insert",true),
/** 1 插入账号信息 */
INSERRZXX(YmtcRzxxService.class, YmtcRzxx.class,"insertRzxx","insert",true),
/** 1 查询账号信息 */
SELECTRZXX(YmtcRzxxService.class, YmtcRzxx.class,"selectRzxx","select",true),
/** 1 插入埋点数据 */
INSERMDSJ(YmtcSjmdService.class, YmtcSjmd.class,"insertMdsj","insert",true);
/** 1 外部调用的方法 */
private String methodsName;
/** 1 内部调用的方法 */
private String dyMethods;
/** 1 内部调用的类 */
private Class className;
/** 1 内部调用的类入参类型 */
private Class params;
/** 1 是否有入参 */
private Boolean sfyrc;
YmtcSjzhEnum(Class className, Class params,String methodsName,String dyMethods,Boolean sfyrc) {
this.className = className;
this.params = params;
this.methodsName=methodsName;
this.dyMethods=dyMethods;
this.sfyrc=sfyrc;
}
public static YmtcSjzhEnum getYmtcSjzh(String methodsName) {
for (YmtcSjzhEnum fylx : YmtcSjzhEnum.values()) {
if (fylx.methodsName.equals(methodsName)) {
return fylx;
}
}
return null;
}
public Class getClassName() {
return className;
}
public String getMethodsName() {
return methodsName;
}
public Class getParams() {
return params;
}
public String getDyMethods() {
return dyMethods;
}
public Boolean getSfyrc() {
return sfyrc;
}
}