|
|
|
@ -5,12 +5,20 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.weaver.common.authority.annotation.WeaPermission;
|
|
|
|
|
import com.weaver.common.base.entity.result.WeaResult;
|
|
|
|
|
import com.weaver.common.security.json.JSON;
|
|
|
|
|
import com.weaver.ebuilder.common.util.TenantContext;
|
|
|
|
|
import com.weaver.ebuilder.datasource.api.entity.ExecuteSqlEntity;
|
|
|
|
|
import com.weaver.ebuilder.datasource.api.enums.SourceType;
|
|
|
|
|
import com.weaver.ebuilder.datasource.api.service.DataSetService;
|
|
|
|
|
import com.weaver.framework.rpc.context.impl.TenantRpcContext;
|
|
|
|
|
import com.weaver.teams.api.tenant.Tenant;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -25,6 +33,9 @@ import java.util.Map;
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping({"/papi/secondev/workflow/controller" })
|
|
|
|
|
public class HTGD_IT13_GETIP_CONTROLLER {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private DataSetService dataSetService;
|
|
|
|
|
@GetMapping("/getip")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
@WeaPermission(publicPermission = true)
|
|
|
|
@ -32,11 +43,40 @@ public class HTGD_IT13_GETIP_CONTROLLER {
|
|
|
|
|
response.setContentType("application/x-www-form-urlencoded; charset=utf-8");
|
|
|
|
|
log.error("HTGD_IT13_GETIP_CONTROLLER"+ JSON.parseObjectToString(request));
|
|
|
|
|
String remoteAddr = request.getRemoteAddr();
|
|
|
|
|
String remoteUser = request.getRemoteUser();
|
|
|
|
|
log.error("remoteAddr:"+remoteAddr);
|
|
|
|
|
Map<String,Object> data = new HashMap<>();
|
|
|
|
|
data.put("ip",remoteAddr);
|
|
|
|
|
String sql = " select * from eteams.dbo.employee where id = " + remoteUser;
|
|
|
|
|
Map<String, Object> stringObjectMap = executeForQuery(null2String(SourceType.LOGIC), "weaver-hr-service", sql);
|
|
|
|
|
if(String.valueOf(stringObjectMap.get("status")).equals("OK")){
|
|
|
|
|
List<Map<String,Object>> records = (List<Map<String,Object>>)stringObjectMap.get("records");
|
|
|
|
|
if (records.size()>0){
|
|
|
|
|
Map<String, Object> map = records.get(0);
|
|
|
|
|
data.put("JOB_NUM",map.get("JOB_NUM"));
|
|
|
|
|
}else {
|
|
|
|
|
log.error("getCustomId 相关字段未找到");
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
log.error("getUserId status-->"+ stringObjectMap.get("status"));
|
|
|
|
|
}
|
|
|
|
|
data.put("ip",remoteAddr);
|
|
|
|
|
return WeaResult.success(JSONObject.toJSONString(data));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Map<String, Object> executeForQuery(String sourceType, String groupId, String sql) {
|
|
|
|
|
// log.error("executeForQuery sourceType-->" + sourceType + ",groupId-->" + groupId + ",sql-->" + sql);
|
|
|
|
|
final Tenant currentTenant = TenantContext.getCurrentTenant();
|
|
|
|
|
TenantRpcContext.setTargetTenantKey(String.valueOf(currentTenant));
|
|
|
|
|
ExecuteSqlEntity executeSqlEntity = new ExecuteSqlEntity();
|
|
|
|
|
executeSqlEntity.setSql(cn.hutool.core.codec.Base64.encode(sql));
|
|
|
|
|
executeSqlEntity.setGroupId(groupId); //groupid,可以访问 E10地址/api/datasource/ds/group?sourceType=LOGIC 获取
|
|
|
|
|
executeSqlEntity.setSourceType(SourceType.valueOf(sourceType));
|
|
|
|
|
// log.error("executeForQuery executeSqlEntity-->"+executeSqlEntity.getSql()+"-->"+executeSqlEntity.getGroupId()+"-->"+executeSqlEntity.getSourceType());
|
|
|
|
|
Map<String, Object> datas = dataSetService.executeSql(executeSqlEntity);
|
|
|
|
|
log.error("executeForQuery datas-->" + datas);
|
|
|
|
|
TenantRpcContext.removeTargetTenantKey();
|
|
|
|
|
return datas;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String null2String(String s){
|
|
|
|
|
return s == null ? "" : s;
|
|
|
|
|