支持外部数据源
This commit is contained in:
parent
e9c95918eb
commit
c4831a1612
|
|
@ -6,12 +6,7 @@ import java.io.Serializable;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @className:
|
||||
* @Description:
|
||||
* @Author:罗威
|
||||
* @date:
|
||||
*/
|
||||
|
||||
public class DataType implements Serializable {
|
||||
public final static String STRING="string";
|
||||
public final static String NUMBER="number";
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.conn.RecordSetDataSource;
|
||||
import weaver.general.BaseBean;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
|
@ -27,6 +29,10 @@ public class FormulaRunServiceImpl extends Service implements FormulaRunService
|
|||
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
private final BaseBean baseBean = new BaseBean();
|
||||
|
||||
private final Boolean isLog = "true".equals(baseBean.getPropValue("hrmSalary", "log"));
|
||||
|
||||
|
||||
@Override
|
||||
public Object run(ExpressFormula expressFormula, List<FormulaVar> formulaVars, DataCollectionEmployee simpleEmployee) throws Exception {
|
||||
|
|
@ -42,37 +48,65 @@ public class FormulaRunServiceImpl extends Service implements FormulaRunService
|
|||
}
|
||||
|
||||
private String runSQL(ExpressFormula expressFormula, List<FormulaVar> formulaVars) {
|
||||
log.info("SQL ExpressFormula {}, formulaVars {}", expressFormula, formulaVars);
|
||||
RecordSet rs = new RecordSet();
|
||||
String formulaRunScript = expressFormula.getFormulaRunScript();
|
||||
if (isLog) {
|
||||
log.info("SQL ExpressFormula {}, formulaVars {}", expressFormula, formulaVars);
|
||||
}
|
||||
|
||||
//解析配置,获取返回值、数据源
|
||||
String extendParam = expressFormula.getExtendParam();
|
||||
String sqlReturnKey = "";
|
||||
String datasourceId = "";
|
||||
try {
|
||||
JsonNode jsonNode = objectMapper.readTree(extendParam);
|
||||
//返回值配置
|
||||
JsonNode sqlReturnKeyNode = jsonNode.get("sqlReturnKey");
|
||||
if (sqlReturnKeyNode != null) {
|
||||
sqlReturnKey = sqlReturnKeyNode.asText();
|
||||
}
|
||||
//数据源配置
|
||||
JsonNode datasourceNode = jsonNode.get("datasource");
|
||||
if (datasourceNode != null) {
|
||||
JsonNode datasourceIdNode = datasourceNode.get("datasourceId");
|
||||
if (datasourceIdNode != null) {
|
||||
datasourceId = datasourceIdNode.asText();
|
||||
}
|
||||
}
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("express execute fail, sql extendParam parse fail", e);
|
||||
}
|
||||
|
||||
String sql = formulaRunScript;
|
||||
//解析sql
|
||||
String sql = expressFormula.getFormulaRunScript();
|
||||
for (FormulaVar formulaVar : formulaVars) {
|
||||
sql = sql.replaceAll(formulaVar.getFieldId(), "'" + formulaVar.getContent() + "'");
|
||||
}
|
||||
log.info("sql run {}", sql);
|
||||
if (rs.execute(sql)) {
|
||||
if (rs.next()) {
|
||||
return rs.getString(sqlReturnKey);
|
||||
if (isLog) {
|
||||
log.info("sql run {}", sql);
|
||||
}
|
||||
|
||||
//外部数据源
|
||||
if (StringUtils.isNotBlank(datasourceId)) {
|
||||
RecordSetDataSource rs = new RecordSetDataSource(datasourceId);
|
||||
if (rs.executeSql(sql)) {
|
||||
if (rs.next()) {
|
||||
return rs.getString(sqlReturnKey);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
RecordSet rs = new RecordSet();
|
||||
if (rs.execute(sql)) {
|
||||
if (rs.next()) {
|
||||
return rs.getString(sqlReturnKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
private Object runFormula(ExpressFormula expressFormula, List<FormulaVar> formulaVars) throws Exception {
|
||||
log.info("FORMULA ExpressFormula {}, formulaVars {}", expressFormula, formulaVars);
|
||||
|
||||
if (isLog) {
|
||||
log.info("FORMULA ExpressFormula {}, formulaVars {}", expressFormula, formulaVars);
|
||||
}
|
||||
DefaultContext<String, Object> context = new DefaultContext<String, Object>();
|
||||
formulaVars.forEach(v -> {
|
||||
if (DataType.NUMBER.equals(v.getFieldType()) && NumberUtils.isCreatable(v.getContent())) {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class SalaryEmployeeServiceImpl extends Service implements SalaryEmployee
|
|||
private EmployBiz employBiz = new EmployBiz();
|
||||
|
||||
private SalarySobRangeService getSalarySobRangeService(User user) {
|
||||
return (SalarySobRangeService) ServiceUtil.getService(SalarySobRangeServiceImpl.class, user);
|
||||
return ServiceUtil.getService(SalarySobRangeServiceImpl.class, user);
|
||||
}
|
||||
|
||||
private EmployMapper getEmployMapper() {
|
||||
|
|
@ -95,10 +95,10 @@ public class SalaryEmployeeServiceImpl extends Service implements SalaryEmployee
|
|||
|
||||
@Override
|
||||
public List<DataCollectionEmployee> getEmployeeByIds(List<Long> simpleEmployeeIds) {
|
||||
if(CollectionUtils.isEmpty(simpleEmployeeIds)){
|
||||
return new ArrayList<>();
|
||||
if (CollectionUtils.isEmpty(simpleEmployeeIds)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return getEmployMapper().getEmployeeByIds(simpleEmployeeIds);
|
||||
return getEmployMapper().getEmployeeByIds(simpleEmployeeIds);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -62,5 +63,14 @@ public class SalaryFormulaController {
|
|||
return new ResponseResult<SalaryFormulaSaveParam, FormulaPO>(user).run(getSalaryFormulaWrapper(user)::save, param);
|
||||
}
|
||||
|
||||
//数据源列表
|
||||
@POST
|
||||
@Path("/datasource/list")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String datasource(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
User user = HrmUserVarify.getUser(request, response);
|
||||
return new ResponseResult<String, ArrayList>(user).run(getSalaryFormulaWrapper(user)::datasourceList);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@ package com.engine.salary.wrapper;
|
|||
import com.engine.common.util.ServiceUtil;
|
||||
import com.engine.core.impl.Service;
|
||||
import com.engine.salary.entity.salaryformula.ExpressFormula;
|
||||
import com.engine.salary.entity.salaryformula.param.SalaryFormulaSaveParam;
|
||||
import com.engine.salary.entity.salaryformula.po.FormulaPO;
|
||||
import com.engine.salary.entity.salaryformula.po.FormulaVar;
|
||||
import com.engine.salary.entity.salaryformula.bo.SalaryFormulaBO;
|
||||
import com.engine.salary.entity.salaryformula.dto.ExpressFormulaDTO;
|
||||
import com.engine.salary.entity.salaryformula.param.SalaryFormulaFieldQueryParam;
|
||||
import com.engine.salary.entity.salaryformula.param.SalaryFormulaSaveParam;
|
||||
import com.engine.salary.entity.salaryformula.po.FormulaPO;
|
||||
import com.engine.salary.entity.salaryformula.po.FormulaVar;
|
||||
import com.engine.salary.exception.SalaryRunTimeException;
|
||||
import com.engine.salary.service.RemoteExcelService;
|
||||
import com.engine.salary.service.SalaryFormulaService;
|
||||
|
|
@ -16,7 +16,9 @@ import com.engine.salary.service.impl.RemoteExcelServiceImpl;
|
|||
import com.engine.salary.service.impl.SalaryFormulaServiceImpl;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import weaver.hrm.User;
|
||||
import weaver.servicefiles.DataSourceXML;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -72,4 +74,10 @@ public class SalaryFormulaWrapper extends Service {
|
|||
public FormulaPO save(SalaryFormulaSaveParam salaryFormulaSaveParam) {
|
||||
return getSalaryFormulaService(user).save(salaryFormulaSaveParam);
|
||||
}
|
||||
|
||||
public ArrayList datasourceList() {
|
||||
DataSourceXML dataSourceXML = new DataSourceXML();
|
||||
ArrayList pointArrayList = dataSourceXML.getPointArrayList();
|
||||
return pointArrayList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue