Initial commit

This commit is contained in:
dxfeng 2025-02-26 14:23:00 +08:00
parent 95e30c8d9b
commit 98f184c802
7 changed files with 329 additions and 0 deletions

View File

@ -0,0 +1,8 @@
package com.api.xxx.web;
import javax.ws.rs.Path;
@Path("/jcl/xxx/demand")
public class RecruitDemandController extends com.engine.xxx.web.RecruitDemandController{
}

View File

@ -0,0 +1,22 @@
package com.engine.xxx.exception;
/**
* @Author weaver_cl
* @Description:
* @Date 2023/2/21
* @Version V1.0
**/
public class CustomizeRunTimeException extends RuntimeException{
public CustomizeRunTimeException(String message) {
super(message);
}
public CustomizeRunTimeException(Throwable cause) {
super(cause);
}
public CustomizeRunTimeException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -0,0 +1,13 @@
package com.engine.xxx.service;
import java.util.Map;
/**
* @author:dxfeng
* @createTime: 2024/08/29
* @version: 1.0
*/
public interface RecruitDemandService {
Map<String, Object> getStaffNum(Map<String, Object> param);
}

View File

@ -0,0 +1,35 @@
package com.engine.xxx.service.impl;
import com.engine.core.impl.Service;
import com.engine.xxx.service.RecruitDemandService;
import weaver.conn.RecordSet;
import weaver.general.Util;
import java.util.HashMap;
import java.util.Map;
/**
* @author:dxfeng
* @createTime: 2024/08/29
* @version: 1.0
*/
public class RecruitDemandServiceImpl extends Service implements RecruitDemandService {
@Override
public Map<String, Object> getStaffNum(Map<String, Object> param) {
Map<String, Object> returnMap = new HashMap<>();
RecordSet rs = new RecordSet();
String sqbm = Util.null2String(param.get("sqbm"));
String xqgw = Util.null2String(param.get("xqgw"));
rs.executeQuery("select a.staff_num, a.permanent_num from jcl_org_staff a inner join JCL_ORG_STAFFPLAN b on a.plan_id = b.id and b.forbidden_tag = 0 and b.delete_type = 0 where a.delete_type = 0 and a.ec_department = ? and a.job_id = ? order by a.id desc", sqbm, xqgw);
if(rs.next()) {
String staffNum = rs.getString("staff_num");
String permanentNum = rs.getString("permanent_num");
returnMap.put("staffNum", staffNum);
returnMap.put("permanentNum", permanentNum);
}
return returnMap;
}
}

View File

@ -0,0 +1,20 @@
package com.engine.xxx.util;
/**
* @Author weaver_cl
* @Description:
* @Date 2023/2/21
* @Version V1.0
**/
public class ExceptionUtil {
public static String getRealMessage(Throwable e) {
while (e != null) {
Throwable cause = e.getCause();
if (cause == null) {
return e.getMessage();
}
e = cause;
}
return "";
}
}

View File

@ -0,0 +1,192 @@
package com.engine.xxx.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.engine.core.exception.ECException;
import com.engine.xxx.exception.CustomizeRunTimeException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import weaver.general.BaseBean;
import weaver.hrm.User;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* 请求执行器
* <p>Copyright: Copyright (c) 2022</p>
* <p>Company: 泛微软件</p>
*
* @author qiantao
* @version 1.0
**/
@Slf4j
public class ResponseResult<T, R> {
private static final long serialVersionUID = 1L;
private final User user;
private final BaseBean baseBean = new BaseBean();
private final Boolean isLog = "true".equals(baseBean.getPropValue("hrmSalary", "log"));
public ResponseResult(User user) {
this.user = user;
}
/**
* 统一返回方法(自定义返回格式)
*/
public String customRun(Function<T, R> f, T t) {
try {
if (isLog) {
log.info("run api , param {}", t);
}
return getJsonString(f.apply(t));
} catch (com.engine.xxx.exception.CustomizeRunTimeException e) {
log.error("api run fail", e);
return Error(e.getMessage());
} catch (ECException e) {
log.error("api run fail", e);
Throwable cause = e.getCause();
return Error(cause.getMessage());
} catch (Exception e) {
log.error("api run fail", e);
return Error("系统异常!");
}
}
/**
* 统一返回方法
*/
public String run(Function<T, R> f, T t) {
try {
if (isLog) {
log.info("run api , param {}", t);
}
return Ok(f.apply(t));
} catch (com.engine.xxx.exception.CustomizeRunTimeException e) {
log.error("api run fail", e);
return Error(e.getMessage());
} catch (ECException e) {
log.error("api run fail", e);
Throwable cause = e.getCause();
return Error(cause.getMessage());
} catch (Exception e) {
log.error("api run fail", e);
return Error("系统异常!");
}
}
/**
* 统一返回方法有参无返回
*/
public String run(Consumer<T> f, T t) {
try {
if (isLog) {
log.info("run api , param {}", t);
}
f.accept(t);
return Ok();
} catch (com.engine.xxx.exception.CustomizeRunTimeException e) {
log.error("api run fail", e);
return Error(e.getMessage());
} catch (ECException e) {
log.error("api run fail", e);
return Error(ExceptionUtil.getRealMessage(e));
} catch (Exception e) {
log.error("api run fail", e);
return Error("系统异常!", e);
}
}
/**
* 统一返回方法无参有返回
*/
public String run(Supplier<R> f) {
try {
if (isLog) {
log.info("run api");
}
return Ok(f.get());
} catch (CustomizeRunTimeException e) {
log.error("api run fail", e);
return Error(e.getMessage());
} catch (ECException e) {
log.error("api run fail", e);
Throwable cause = e.getCause();
return Error(cause.getMessage());
} catch (Exception e) {
log.error("api run fail", e);
return Error("系统异常!", e);
}
}
private static String getJsonString(Object apidatas) {
ObjectMapper mapper = new ObjectMapper();
try {
return mapper.writeValueAsString(apidatas);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return "";
}
/**
* 成功返回
*/
private String Ok() {
Map<String, Object> apidatas = new HashMap<>();
apidatas.put("api_status", true);
return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
}
/**
* 成功返回
*/
private String Ok(R r) {
Map<String, Object> apidatas = new HashMap<>();
apidatas.put("api_status", true);
apidatas.put("data", r);
String success = JSON.toJSONString(apidatas);
if (isLog) {
log.info("run salary api success return {}", success);
}
return success;
}
/**
* 失败返回
*/
private static String Error(String message) {
Map<String, Object> apidatas = new HashMap<>();
apidatas.put("api_status", false);
apidatas.put("errormsg", message);
return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
}
/**
* 系统异常失败返回
*/
private static String Error(String message, Exception e) {
Map<String, Object> apidatas = new HashMap<>();
apidatas.put("api_status", false);
apidatas.put("errormsg", message);
apidatas.put("error", e.getMessage());
return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
}
}

View File

@ -0,0 +1,39 @@
package com.engine.xxx.web;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.xxx.service.RecruitDemandService;
import com.engine.xxx.service.impl.RecruitDemandServiceImpl;
import com.engine.xxx.util.ResponseResult;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.Map;
/**
* @author:dxfeng
* @createTime: 2024/08/29
* @version: 1.0
*/
public class RecruitDemandController {
public RecruitDemandService getService(User user) {
return ServiceUtil.getService(RecruitDemandServiceImpl.class, user);
}
@GET
@Path("/getStaffNum")
@Produces(MediaType.APPLICATION_JSON)
public String getStaffNum(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
Map<String, Object> params = ParamUtil.request2Map(request);
return new ResponseResult<Map<String, Object>, Map<String, Object>>(user).run(getService(user)::getStaffNum, params);
}
}