2022-04-14 20:46:17 +08:00
|
|
|
package com.engine.salary.web;
|
|
|
|
|
|
2022-12-07 15:47:35 +08:00
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
2022-04-14 20:46:17 +08:00
|
|
|
import com.engine.common.util.ServiceUtil;
|
|
|
|
|
import com.engine.salary.entity.salaryformula.dto.ExpressFormulaDTO;
|
|
|
|
|
import com.engine.salary.entity.salaryformula.param.SalaryFormulaFieldQueryParam;
|
|
|
|
|
import com.engine.salary.entity.salaryformula.param.SalaryFormulaSaveParam;
|
2022-04-16 16:49:22 +08:00
|
|
|
import com.engine.salary.entity.salaryformula.po.FormulaPO;
|
2022-04-14 20:46:17 +08:00
|
|
|
import com.engine.salary.entity.salaryformula.po.FormulaVar;
|
|
|
|
|
import com.engine.salary.util.ResponseResult;
|
|
|
|
|
import com.engine.salary.wrapper.SalaryFormulaWrapper;
|
2022-12-07 15:47:35 +08:00
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
2022-04-14 20:46:17 +08:00
|
|
|
import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
2022-12-07 15:47:35 +08:00
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import weaver.conn.RecordSetDataSource;
|
2022-04-14 20:46:17 +08:00
|
|
|
import weaver.hrm.HrmUserVarify;
|
|
|
|
|
import weaver.hrm.User;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import javax.ws.rs.*;
|
|
|
|
|
import javax.ws.rs.core.Context;
|
|
|
|
|
import javax.ws.rs.core.MediaType;
|
2022-08-03 10:08:43 +08:00
|
|
|
import java.util.ArrayList;
|
2022-12-07 15:47:35 +08:00
|
|
|
import java.util.HashMap;
|
2022-04-14 20:46:17 +08:00
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
2022-12-07 15:47:35 +08:00
|
|
|
@Slf4j
|
2022-04-14 20:46:17 +08:00
|
|
|
public class SalaryFormulaController {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private SalaryFormulaWrapper getSalaryFormulaWrapper(User user) {
|
|
|
|
|
return (SalaryFormulaWrapper) ServiceUtil.getService(SalaryFormulaWrapper.class, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//变量项
|
|
|
|
|
@POST
|
|
|
|
|
@Path("/search/group")
|
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
public String fieldGroupList(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody Map<String, Object> param) {
|
|
|
|
|
User user = HrmUserVarify.getUser(request, response);
|
2022-04-25 18:06:09 +08:00
|
|
|
return new ResponseResult<Map<String, Object>, List<Map<String, Object>>>(user).run(getSalaryFormulaWrapper(user)::fieldGroupList, param);
|
2022-04-14 20:46:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//变量字段列表
|
|
|
|
|
@POST
|
|
|
|
|
@Path("/search/field")
|
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
public String fieldList(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody SalaryFormulaFieldQueryParam param) {
|
|
|
|
|
User user = HrmUserVarify.getUser(request, response);
|
2022-04-25 18:06:09 +08:00
|
|
|
return new ResponseResult<SalaryFormulaFieldQueryParam, List<FormulaVar>>(user).run(getSalaryFormulaWrapper(user)::fieldList, param);
|
2022-04-14 20:46:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取公式详情
|
|
|
|
|
@GET
|
|
|
|
|
@Path("/detail")
|
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
public String detail(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam(value = "formulaId") Long formulaId) {
|
|
|
|
|
User user = HrmUserVarify.getUser(request, response);
|
2022-04-25 18:06:09 +08:00
|
|
|
return new ResponseResult<Long, ExpressFormulaDTO>(user).run(getSalaryFormulaWrapper(user)::detail, formulaId);
|
2022-04-14 20:46:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@POST
|
|
|
|
|
@Path("/save")
|
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
public String save(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody SalaryFormulaSaveParam param) {
|
|
|
|
|
User user = HrmUserVarify.getUser(request, response);
|
2022-04-25 18:06:09 +08:00
|
|
|
return new ResponseResult<SalaryFormulaSaveParam, FormulaPO>(user).run(getSalaryFormulaWrapper(user)::save, param);
|
2022-04-14 20:46:17 +08:00
|
|
|
}
|
|
|
|
|
|
2022-08-03 10:08:43 +08:00
|
|
|
//数据源列表
|
2022-08-03 10:47:26 +08:00
|
|
|
@GET
|
2022-08-03 10:08:43 +08:00
|
|
|
@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);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-13 10:53:43 +08:00
|
|
|
@POST
|
2022-12-07 15:47:35 +08:00
|
|
|
@Path("/checkSql")
|
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
2022-12-13 10:53:43 +08:00
|
|
|
public String checkFormula(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody SalaryFormulaSaveParam param) {
|
2022-12-07 15:47:35 +08:00
|
|
|
User user = HrmUserVarify.getUser(request, response);
|
|
|
|
|
String result = "";
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
String sql = request.getParameter("sql");
|
|
|
|
|
String sqlReturnKey = request.getParameter("sqlReturnKey");
|
|
|
|
|
String datasourceId = request.getParameter("datasourceId");
|
|
|
|
|
RecordSetDataSource rs = new RecordSetDataSource(datasourceId);
|
|
|
|
|
log.info("sql run{},datasourceId:{},sqlReturnKey:{}", sql, datasourceId, sqlReturnKey);
|
2022-12-13 10:53:43 +08:00
|
|
|
map.put("sql", sql);
|
|
|
|
|
map.put("sqlReturnKey", sqlReturnKey);
|
|
|
|
|
map.put("datasourceId", datasourceId);
|
2022-12-07 15:47:35 +08:00
|
|
|
if (rs.executeSql(sql)) {
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
result = rs.getString(sqlReturnKey);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-13 10:53:43 +08:00
|
|
|
map.put("result", result);
|
2022-12-07 15:47:35 +08:00
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("sql error", e);
|
|
|
|
|
Map<String, Object> apidatas = new HashMap<>();
|
|
|
|
|
apidatas.put("status", false);
|
|
|
|
|
apidatas.put("errormsg", e.getMessage());
|
|
|
|
|
return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, Object> apidatas = new HashMap<>();
|
|
|
|
|
apidatas.put("status", true);
|
|
|
|
|
apidatas.put("data", map);
|
|
|
|
|
return getJsonString(apidatas);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String getJsonString(Object apidatas) {
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
try {
|
|
|
|
|
return mapper.writeValueAsString(apidatas);
|
|
|
|
|
} catch (JsonProcessingException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
2022-04-14 20:46:17 +08:00
|
|
|
|
|
|
|
|
}
|