calyrex 2.18
parent
796b65ea5f
commit
fb39e7a224
@ -0,0 +1,101 @@
|
||||
package com.weaver.seconddev.interfaces.workflow.controller;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.weaver.common.base.entity.result.WeaResult;
|
||||
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.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author: calyrex
|
||||
* @CreateTime: 2025-02-19
|
||||
* @Description:
|
||||
*/
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping({"/papi/secondev/workflow/controller" })
|
||||
public class Getgsjc_controller {
|
||||
|
||||
@Autowired
|
||||
private DataSetService dataSetService;
|
||||
@RequestMapping("/getgsjc")
|
||||
public WeaResult<JSONObject> run(@RequestParam Map<String,Object> params) {
|
||||
log.error("getgsjc_controller execute start");
|
||||
log.error("getgsjc_controller execute params : " + params);
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
String gsid = null2String(params.get("gsid"));
|
||||
String sql = "SELECT gsjc AS gsjc, gsjcdm AS gsjcdm" +
|
||||
"FROM (" +
|
||||
" SELECT t1.*, t2.id AS subcomid" +
|
||||
" FROM hrmsubcompanydefined t1" +
|
||||
" LEFT JOIN eteams.dbo.department t2" +
|
||||
" ON t1.FORM_DATA_ID = t2.formdata" +
|
||||
" AND t2.delete_type = 0" +
|
||||
" WHERE t1.DELETE_TYPE = 0" +
|
||||
") hsd" +
|
||||
" WHERE hsd.subcomid = " + gsid +
|
||||
" AND hsd.delete_type = 0";
|
||||
String sourceType = null2String(SourceType.LOGIC);
|
||||
String groupId = "weaver-doc-service";
|
||||
Map<String, Object> datas = executeForQuery(sourceType, groupId, sql);
|
||||
if(String.valueOf(datas.get("status")).equals("OK")){
|
||||
List<Map<String,Object>> records = (List<Map<String,Object>>)datas.get("records");
|
||||
if (records.size()>0){
|
||||
Map<String, Object> map = records.get(0);
|
||||
json.put("gsjc",map.get("gsjc"));
|
||||
json.put("gsjcdm",map.get("gsjcdm"));
|
||||
return WeaResult.success(json);
|
||||
}else {
|
||||
log.info("getCustomId 相关字段未找到");
|
||||
}
|
||||
}else {
|
||||
log.info("getUserId status-->"+ datas.get("status"));
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("getgsjc_controller execute error : " ,e);
|
||||
return WeaResult.fail(500, "getgsjc_controller execute error", e);
|
||||
}
|
||||
return WeaResult.success(json);
|
||||
}
|
||||
|
||||
public Map<String, Object> executeForQuery(String sourceType, String groupId, String sql) {
|
||||
// log.info("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.info("executeForQuery executeSqlEntity-->"+executeSqlEntity.getSql()+"-->"+executeSqlEntity.getGroupId()+"-->"+executeSqlEntity.getSourceType());
|
||||
Map<String, Object> datas = dataSetService.executeSql(executeSqlEntity);
|
||||
// log.info("executeForQuery datas-->" + datas);
|
||||
TenantRpcContext.removeTargetTenantKey();
|
||||
return datas;
|
||||
}
|
||||
|
||||
public static String null2String(String s){
|
||||
return s == null ? "" : s;
|
||||
}
|
||||
|
||||
public static String null2String(Object o){
|
||||
return o == null ? "" : o.toString();
|
||||
}
|
||||
|
||||
public static String null2String(String s1,String s2){
|
||||
return s1 == null ? (s2 == null ? "" : s2) : s1;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue