From ed4baca120df9b3d4503b9eeb70cbd50181291fb Mon Sep 17 00:00:00 2001 From: howec <> Date: Tue, 21 Nov 2023 10:32:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=8E=E5=BA=B7:=E8=8E=B7=E5=8F=96=E4=BA=BA?= =?UTF-8?q?=E5=91=98=E4=BF=A1=E6=81=AF=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/haikangwh/hrm/web/UserInfoDetailIAction.java | 9 + .../haikangwh/hrm/web/UserInfoDetailAction.java | 208 ++++++++++++++++++ 2 files changed, 217 insertions(+) create mode 100644 e9海康人员列表接口/src/com/api/haikangwh/hrm/web/UserInfoDetailIAction.java create mode 100644 e9海康人员列表接口/src/com/engine/haikangwh/hrm/web/UserInfoDetailAction.java diff --git a/e9海康人员列表接口/src/com/api/haikangwh/hrm/web/UserInfoDetailIAction.java b/e9海康人员列表接口/src/com/api/haikangwh/hrm/web/UserInfoDetailIAction.java new file mode 100644 index 0000000..83db62e --- /dev/null +++ b/e9海康人员列表接口/src/com/api/haikangwh/hrm/web/UserInfoDetailIAction.java @@ -0,0 +1,9 @@ +package com.api.haikangwh.hrm.web; + +import com.engine.haikangwh.hrm.web.UserInfoDetailAction; + +import javax.ws.rs.Path; + +@Path("/haikang/user") +public class UserInfoDetailIAction extends UserInfoDetailAction { +} diff --git a/e9海康人员列表接口/src/com/engine/haikangwh/hrm/web/UserInfoDetailAction.java b/e9海康人员列表接口/src/com/engine/haikangwh/hrm/web/UserInfoDetailAction.java new file mode 100644 index 0000000..25346c9 --- /dev/null +++ b/e9海康人员列表接口/src/com/engine/haikangwh/hrm/web/UserInfoDetailAction.java @@ -0,0 +1,208 @@ +package com.engine.haikangwh.hrm.web; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import weaver.conn.RecordSet; +import weaver.file.ImageFileManager; +import weaver.general.Util; +import weaver.integration.logging.Logger; +import weaver.integration.logging.LoggerFactory; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import java.io.*; + +import static com.weaverboot.tools.logTools.LogTools.writeLog; + +public class UserInfoDetailAction { + private final Logger log = LoggerFactory.getLogger(UserInfoDetailAction.class); + + //测试 +// private final static String CompanyID1 = "1521"; +// private final static String photofieldName="field22"; + + //生产 + private final static String CompanyID1 = "2021,521"; //外部,深圳骏友 不参与 + private final static String photofieldName="field33"; //1寸白底照片 字段id + + + @POST + @Path("/getHrmUserInfoWithPage") + @Produces(MediaType.APPLICATION_JSON) + public JSONObject getHrmUserInfoWithPage(@Context HttpServletRequest request, @RequestBody JSONObject reqObj) { + JSONObject result = new JSONObject(); + int curpage = 1; + int pagesize = 20; + int totalSize = 0; + + if(reqObj.getString("curpage").length() > 0) { + + curpage = Integer.parseInt(reqObj.getString("curpage")); + } + if(reqObj.getString("pagesize").length() > 0) { + + pagesize = Integer.parseInt(reqObj.getString("pagesize")); + } + String workcode1 = ""; + if(reqObj.getString("workcode").length() > 0) { + workcode1 = reqObj.getString("workcode"); + } + + int begin = (curpage-1)*pagesize; + + String sqlcount = ""; + RecordSet rs = new RecordSet(); + RecordSet rscount = new RecordSet(); + if(workcode1.length() > 0) { + sqlcount = "SELECT count(a.id) as sums FROM HRMRESOURCE a LEFT JOIN HrmStatusHistory b ON a.ID = b.RESOURCEID LEFT JOIN cus_fielddata c ON a.ID = c.ID AND c.scopeid = 3 WHERE" + + " 1 =1 and a.workcode = '"+workcode1+"' and a.subcompanyid1 not in ("+CompanyID1+")"; + }else { + sqlcount = "SELECT count(a.id) as sums FROM HRMRESOURCE a LEFT JOIN HrmStatusHistory b ON a.ID = b.RESOURCEID LEFT JOIN cus_fielddata c ON a.ID = c.ID AND c.scopeid = 3 WHERE" + + " 1 =1 and a.subcompanyid1 not in ("+CompanyID1+")"; + } + log.error(sqlcount); + rscount.executeQuery(sqlcount); + if(rscount.next()){ + totalSize = rscount.getInt("sums"); + log.error("sqlcount:"+totalSize); + } + + JSONArray datalist = new JSONArray(); + String sql = ""; + if(workcode1.length() > 0) { + sql ="SELECT a.workcode, a.lastname, a.sex, a.departmentid, a.subcompanyid1, a.workstartdate, b.changedate, c."+photofieldName+", a.id aid, ROWNUM AS rn FROM HRMRESOURCE a LEFT JOIN HrmStatusHistory b ON a.ID = b.RESOURCEID LEFT JOIN cus_fielddata c ON a.ID = c.ID AND c.scopeid = 3 WHERE" + + " 1 = 1 and a.subcompanyid1 not in ("+CompanyID1+") and a.workcode = '"+workcode1+"' OFFSET "+begin+" ROWS FETCH NEXT "+pagesize+" ROWS ONLY"; + }else { + sql ="SELECT a.workcode, a.lastname, a.sex, a.departmentid, a.subcompanyid1, a.workstartdate, b.changedate, c."+photofieldName+", a.id aid, ROWNUM AS rn FROM HRMRESOURCE a LEFT JOIN HrmStatusHistory b ON a.ID = b.RESOURCEID LEFT JOIN cus_fielddata c ON a.ID = c.ID AND c.scopeid = 3 WHERE" + + " 1 = 1 and a.subcompanyid1 not in ("+CompanyID1+") OFFSET "+begin+" ROWS FETCH NEXT "+pagesize+" ROWS ONLY"; + } + log.error(sql); + rs.executeQuery(sql); + while (rs.next()) { + String workcode = Util.null2String(rs.getString("workcode")); + String lastname = Util.null2String(rs.getString("lastname")); + String sex = Util.null2String(rs.getString("sex")); + String departmentid = Util.null2String(rs.getString("departmentid")); + String subcompanyid1 = Util.null2String(rs.getString("subcompanyid1")); + String workstartdate = Util.null2String(rs.getString("workstartdate")); + String changedate = Util.null2String(rs.getString("changedate")); + String photofieldname1 = Util.null2String(rs.getString(photofieldName)); + JSONObject dataobject = new JSONObject(); + dataobject.put("workcode",workcode); + dataobject.put("lastname",lastname); + dataobject.put("sex",sex); + dataobject.put("departmentid",departmentid); + dataobject.put("subcompanyid1",subcompanyid1); + dataobject.put("workstartdate",workstartdate); + dataobject.put("changedate",changedate); + JSONArray imagelist = new JSONArray(); + if(photofieldname1.length() > 0) { + RecordSet recordSet3 = new RecordSet(); + String sql_3 = "select d.imagefilename,d.imagefileid,i.filesize,d.isextfile from docimagefile d left join imagefile i on " + + " i.imagefileid=d.imagefileid where docid in (" + photofieldname1 + ") " + + " and d.imagefileid in (select max(d.imagefileid) from DocImageFile d where docid in (" + photofieldname1 + ") group by d.docid,d.imagefilename)"; + recordSet3.execute(sql_3); + log.info(sql_3); + + while (recordSet3.next()) { + + InputStream inputStream = ImageFileManager.getInputStreamById(recordSet3.getInt("imagefileid"));// 根据文件的图片id获取未加密的输入流 + String base64FromInputStream = getBase64FromInputStream(inputStream); + JSONObject imageobj = new JSONObject(); + imageobj.put("FILENAME",recordSet3.getString("imagefilename")); + imageobj.put("FILESIZE",recordSet3.getInt("filesize")); + imageobj.put("BASE64",base64FromInputStream); + if(recordSet3.getString("isextfile").equals("1")){ + imageobj.put("TYPE","附件"); + }else{ + imageobj.put("TYPE","正文"); + } + imagelist.add(imageobj); + } + } + dataobject.put("photo",imagelist); + datalist.add(dataobject); + } + JSONObject data = new JSONObject(); + data.put("totalSize",totalSize); + data.put("dataList",datalist); + data.put("pageSize",pagesize); + data.put("curpage",curpage); + + result.put("code",1); + result.put("data",data); + return result; + } + + + + public String getBase64FromInputStream(InputStream in) { + // 将图片文件转化为字节数组字符串,并对其进行Base64编码处理 + byte[] data = null; + // 读取图片字节数组 + try { + ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); + byte[] buff = new byte[100]; + int rc = 0; + while ((rc = in.read(buff, 0, 100)) > 0) { + swapStream.write(buff, 0, rc); + } + data = swapStream.toByteArray(); + + } catch (IOException e) { + return ""; + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException e) { + } + } + } + if(data == null) { + return ""; + } + return new String(org.apache.commons.codec.binary.Base64.encodeBase64(data)); + } + + //调用获取人员列表接口 + public static String doJsonPost(String json) { + String url = "/api/hrm/resful/getHrmUserInfoWithPage"; + writeLog("查询人员列表接口"+url+",推送报文:>>>>>>>>>>>>>>>>>>>>>>"+json); + CloseableHttpClient client = HttpClients.createDefault(); + HttpPost post = new HttpPost(url); + post.setHeader("Content-Type", "application/json;charset=utf-8"); + String result=""; + try { + StringEntity s = new StringEntity(json,"UTF-8"); + s.setContentEncoding("utf-8"); + s.setContentType("application/json"); + post.setEntity(s); + // 发送请求 + HttpResponse httpResponse = client.execute(post); + // 获取响应输入流 + InputStream inStream = httpResponse.getEntity().getContent(); + BufferedReader reader = new BufferedReader(new InputStreamReader( + inStream,"utf-8")); + StringBuilder strber = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) + strber.append(line + "\n"); + inStream.close(); + result = strber.toString(); + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } +}