diff --git a/src/weaver/interfaces/job/ESiginsCronJob.java b/src/weaver/interfaces/job/ESiginsCronJob.java index 12debd37..739763e1 100644 --- a/src/weaver/interfaces/job/ESiginsCronJob.java +++ b/src/weaver/interfaces/job/ESiginsCronJob.java @@ -1,6 +1,8 @@ package weaver.interfaces.job; import com.alibaba.fastjson.JSONObject; +import com.sun.jersey.core.util.Base64; +import okhttp3.*; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang.StringUtils; import sun.misc.BASE64Decoder; @@ -24,31 +26,40 @@ public class ESiginsCronJob extends BaseCronJob { @Override public void execute() { + } public void updateHrmSiginData(){ - - BaseBean bb = new BaseBean(); RecordSet rs = new RecordSet(); + BaseBean bb = new BaseBean(); + +// String esiginsUrl = "http://172.16.25.133/portal-web/v1/esign/"+sysUserCode+"/esigns" ; + String esiginsUrl = bb.getPropValue("PORTAL_INFO","esiginsUrl"); + String username = bb.getPropValue("PORTAL_INFO","username"); + String passwd = bb.getPropValue("PORTAL_INFO","passwd"); + List> list = new ArrayList>(); Map map = null; - String hrmsql = " select id,loginid,subcompanyid1 from hrmresource where status = 1 and departmentid in(29,30) " ; + String hrmsql = " select id,loginid,subcompanyid1,workcode from hrmresource where status = 1 and departmentid in(29,30) " ; bb.writeLog("hrmsql:"+hrmsql); rs.executeQuery(hrmsql); while (rs.next()){ String userid = Util.null2String(rs.getString("id")); String loginid = Util.null2String(rs.getString("loginid")); String subcompanyid1 = Util.null2String(rs.getString("subcompanyid1")); + String workcode = Util.null2String(rs.getString("workcode")); bb.writeLog("userid:"+userid); bb.writeLog("loginid:"+loginid); bb.writeLog("subcompanyid1:"+subcompanyid1); + bb.writeLog("workcode:"+workcode); if(!"".equals(userid) && !"".equals(loginid)){ map = new HashMap(); map.put("userid",userid); map.put("loginid",loginid); map.put("subcompanyid1",subcompanyid1); + map.put("workcode",workcode); list.add(map); } } @@ -58,157 +69,131 @@ public class ESiginsCronJob extends BaseCronJob { ImageFileIdUpdate im = new ImageFileIdUpdate(); HttpRequestUtil HttpRequestUtil = new HttpRequestUtil(); String esignImage = "" ; - String uid = "" ; - String cookies = "" ;//request.getHeader("cookie"); - bb.writeLog("cookies:"+cookies); - if(!"".equals(cookies)) - { - String[] cookievals = cookies.split(";"); - for(int i=0;i dataMap = list.get(i); - String userid = dataMap.get("userid"); - String sysUserCode = dataMap.get("loginid"); - String subcompanyid1 = dataMap.get("subcompanyid1"); + Map dataMap = list.get(i); + String userid = dataMap.get("userid"); + String sysUserCode = dataMap.get("loginid"); + String subcompanyid1 = dataMap.get("subcompanyid1"); + String workcode = dataMap.get("workcode"); - String url = "http://172.16.25.133/portal-web/v1/esign/"+sysUserCode+"/esigns" ; + esiginsUrl += "/"+workcode+"/esigns"; - Map headMap = new HashMap(); - headMap.put("Cookie","SESSION="+uid); - String msg = HttpRequestUtil.httpGet2(url,headMap,"UTF-8"); - bb.writeLog("msg2 ==" + msg); + String auth = username + ":" + passwd; + String msg = doPostByAuth(esiginsUrl,"",auth); + bb.writeLog("msg2 ==" + msg); // data:image/gif;base64,base64编码的gif图片数据 // data:image/png;base64,base64编码的png图片数据 // data:image/jpeg;base64,base64编码的图片数据 // data:image/x-icon;base64,base64编码的icon图片数据 - if(!"".equals(msg)) - { - JSONObject jsonObject = JSONObject.parseObject(msg); - String resultCode = jsonObject.getString("resultCode"); - if("1".equals(resultCode)){ - - if(jsonObject.containsKey("resultObject")){ - JSONObject resultObject = jsonObject.getJSONObject("resultObject"); - if(resultObject.containsKey("esignImage")){ - esignImage = resultObject.getString("esignImage"); - - if(!"".equals(esignImage)){ - String imagetype = "" ; - if(esignImage.contains("image/gif")){ - imagetype = "gif"; - }else if(esignImage.contains("image/png")){ - imagetype = "png"; - }else if(esignImage.contains("image/jpeg")){ - imagetype = "jpeg"; - }else if(esignImage.contains("image/x-icon")){ - imagetype = "ico"; - } - + if(!"".equals(msg)) + { + JSONObject jsonObject = JSONObject.parseObject(msg); + String resultCode = jsonObject.getString("resultCode"); + if("1".equals(resultCode)){ + + if(jsonObject.containsKey("resultObject")){ + JSONObject resultObject = jsonObject.getJSONObject("resultObject"); + if(resultObject.containsKey("esignImage")){ + esignImage = resultObject.getString("esignImage"); + + if(!"".equals(esignImage)){ + String imagetype = "" ; + if(esignImage.contains("image/gif")){ + imagetype = "gif"; + }else if(esignImage.contains("image/png")){ + imagetype = "png"; + }else if(esignImage.contains("image/jpeg")){ + imagetype = "jpeg"; + }else if(esignImage.contains("image/x-icon")){ + imagetype = "ico"; + } - String imageFileType = "application/octet-stream"; - String imageName = sysUserCode+"."+imagetype; - String imagefileused = "1"; - String iszip = "1"; - String secretLevel = "4"; - String mainimagefile = "0"; - int downloads = 0; - String ftpconfigid = "0"; - String isaesencrypt = "0"; - String comefrom = sysUserCode; - String marksize = "0"; - String markdate = TimeUtil.getCurrentTimeString(); - String sealtype = "1" ; - String isdefault = "1"; - - - String filepath = "/app/weaver/ecology/filesystem/dzyz/"+sysUserCode ; - bb.writeLog("filepath:"+filepath); - File file = new File(filepath); - if(!file.exists()){ - file.mkdirs(); - } - String imagefilename = DigestUtils.md5Hex(sysUserCode); //MD5加密 - String imageFilePath = filepath+"/"+imagefilename; - String image_File_Path = saveImageFile(esignImage,imageFilePath,imagetype); - bb.writeLog("image_File_Path:"+image_File_Path); - - if(!"".equals(image_File_Path)){ - File imageFile = new File(image_File_Path); - if(imageFile.exists()) - { - String imagefilezippath = filepath+"/"+imagefilename + ".zip"; - String image_File_Zip_Path = saveImageFileZip(image_File_Path,imagefilezippath,imagefilename); - bb.writeLog("image_File_Zip_Path:"+image_File_Zip_Path); - if(!"".equals(image_File_Zip_Path)){ - - File imageFileZip = new File(image_File_Zip_Path); - if(imageFileZip.exists()){ - long filesize = imageFileZip.length(); - bb.writeLog("filesize:"+filesize); - long d_filesize = 0 ; - String image_file_id = "" ; - String imgsql = " select imagefileid,filesize from imagefile where filerealpath = ?" ; - rs.executeQuery(imgsql,new Object[]{image_File_Path}); - if(rs.next()){ - image_file_id = Util.null2String(rs.getString("imagefileid")); - d_filesize = Long.parseLong(Util.null2String(rs.getString("imagefileid"))); - } - bb.writeLog("d_filesize:"+d_filesize); - if(!"".equals(image_file_id)){ - if(d_filesize != filesize) - { - int imagefileid = im.getImageFileNewId(); - String sql = " INSERT INTO imagefile (IMAGEFILEID,IMAGEFILENAME, IMAGEFILETYPE, IMAGEFILEUSED, FILEREALPATH, ISZIP, FILESIZE, DOWNLOADS, FTPCONFIGID, ISAESENCRYPT, COMEFROM, mainimagefile, secretLevel) VALUES " + - " (?,?,?,?,?,?,?,?,?,?,?,?,?)" ; - - boolean flag = rs.executeUpdate(sql,new Object[]{imagefileid,imageName,imageFileType,imagefileused,image_File_Zip_Path,iszip,filesize,downloads,ftpconfigid,isaesencrypt,comefrom,mainimagefile,secretLevel}); - bb.writeLog("sql:"+sql); - if(flag){ - sql = " update DocSignature set isdefault = 0 where hrmresid= ?" ; - boolean isUp = rs.executeUpdate(sql,new Object[]{userid}); - bb.writeLog("sql:"+sql); - if(isUp){ - sql = " insert into DocSignature(hrmresid, markname, marktype, markpath, marksize, markdate, subcompanyid, sealtype, isdefault, imagefileid)\n" + - " values(?,?,?,?,?,?,?,?,?,?)" ; - rs.executeUpdate(sql,new Object[]{userid,sysUserCode,"."+imagetype,image_File_Path,marksize,markdate,subcompanyid1,sealtype,isdefault,imagefileid}); - bb.writeLog("sql:"+sql); - } - } - } - }else{ + String imageFileType = "application/octet-stream"; + String imageName = sysUserCode+"."+imagetype; + String imagefileused = "1"; + String iszip = "1"; + String secretLevel = "4"; + String mainimagefile = "0"; + int downloads = 0; + String ftpconfigid = "0"; + String isaesencrypt = "0"; + String comefrom = sysUserCode; + String marksize = "0"; + String markdate = TimeUtil.getCurrentTimeString(); + String sealtype = "1" ; + String isdefault = "1"; + + String filepath = "/app/weaver/ecology/filesystem/dzyz/"+sysUserCode ; + bb.writeLog("filepath:"+filepath); + File file = new File(filepath); + if(!file.exists()){ + file.mkdirs(); + } + String imagefilename = DigestUtils.md5Hex(sysUserCode); //MD5加密 + String imageFilePath = filepath+"/"+imagefilename; + String image_File_Path = saveImageFile(esignImage,imageFilePath,imagetype); + bb.writeLog("image_File_Path:"+image_File_Path); + + if(!"".equals(image_File_Path)){ + File imageFile = new File(image_File_Path); + if(imageFile.exists()) + { + String imagefilezippath = filepath+"/"+imagefilename + ".zip"; + String image_File_Zip_Path = saveImageFileZip(image_File_Path,imagefilezippath,imagefilename); + bb.writeLog("image_File_Zip_Path:"+image_File_Zip_Path); + if(!"".equals(image_File_Zip_Path)){ + + File imageFileZip = new File(image_File_Zip_Path); + if(imageFileZip.exists()){ + long filesize = imageFileZip.length(); + bb.writeLog("filesize:"+filesize); + long d_filesize = 0 ; + String image_file_id = "" ; + String imgsql = " select imagefileid,filesize from imagefile where filerealpath = ?" ; + rs.executeQuery(imgsql,new Object[]{image_File_Path}); + if(rs.next()){ + image_file_id = Util.null2String(rs.getString("imagefileid")); + d_filesize = Long.parseLong(Util.null2String(rs.getString("imagefileid"))); + } + bb.writeLog("d_filesize:"+d_filesize); + if(!"".equals(image_file_id)){ + if(d_filesize != filesize) + { int imagefileid = im.getImageFileNewId(); String sql = " INSERT INTO imagefile (IMAGEFILEID,IMAGEFILENAME, IMAGEFILETYPE, IMAGEFILEUSED, FILEREALPATH, ISZIP, FILESIZE, DOWNLOADS, FTPCONFIGID, ISAESENCRYPT, COMEFROM, mainimagefile, secretLevel) VALUES " + " (?,?,?,?,?,?,?,?,?,?,?,?,?)" ; + boolean flag = rs.executeUpdate(sql,new Object[]{imagefileid,imageName,imageFileType,imagefileused,image_File_Zip_Path,iszip,filesize,downloads,ftpconfigid,isaesencrypt,comefrom,mainimagefile,secretLevel}); bb.writeLog("sql:"+sql); if(flag){ - sql = " insert into DocSignature(hrmresid, markname, marktype, markpath, marksize, markdate, subcompanyid, sealtype, isdefault, imagefileid)\n" + - " values(?,?,?,?,?,?,?,?,?,?)" ; - rs.executeUpdate(sql,new Object[]{userid,sysUserCode,"."+imagetype,image_File_Path,marksize,markdate,subcompanyid1,sealtype,isdefault,imagefileid}); - + sql = " update DocSignature set isdefault = 0 where hrmresid= ?" ; + boolean isUp = rs.executeUpdate(sql,new Object[]{userid}); bb.writeLog("sql:"+sql); + if(isUp){ + sql = " insert into DocSignature(hrmresid, markname, marktype, markpath, marksize, markdate, subcompanyid, sealtype, isdefault, imagefileid)\n" + + " values(?,?,?,?,?,?,?,?,?,?)" ; + rs.executeUpdate(sql,new Object[]{userid,sysUserCode,"."+imagetype,image_File_Path,marksize,markdate,subcompanyid1,sealtype,isdefault,imagefileid}); + bb.writeLog("sql:"+sql); + } } } + }else{ + int imagefileid = im.getImageFileNewId(); + String sql = " INSERT INTO imagefile (IMAGEFILEID,IMAGEFILENAME, IMAGEFILETYPE, IMAGEFILEUSED, FILEREALPATH, ISZIP, FILESIZE, DOWNLOADS, FTPCONFIGID, ISAESENCRYPT, COMEFROM, mainimagefile, secretLevel) VALUES " + + " (?,?,?,?,?,?,?,?,?,?,?,?,?)" ; + boolean flag = rs.executeUpdate(sql,new Object[]{imagefileid,imageName,imageFileType,imagefileused,image_File_Zip_Path,iszip,filesize,downloads,ftpconfigid,isaesencrypt,comefrom,mainimagefile,secretLevel}); + bb.writeLog("sql:"+sql); + if(flag){ + sql = " insert into DocSignature(hrmresid, markname, marktype, markpath, marksize, markdate, subcompanyid, sealtype, isdefault, imagefileid)\n" + + " values(?,?,?,?,?,?,?,?,?,?)" ; + rs.executeUpdate(sql,new Object[]{userid,sysUserCode,"."+imagetype,image_File_Path,marksize,markdate,subcompanyid1,sealtype,isdefault,imagefileid}); + + bb.writeLog("sql:"+sql); + } } } } @@ -220,7 +205,6 @@ public class ESiginsCronJob extends BaseCronJob { } } } - } @@ -328,4 +312,72 @@ public class ESiginsCronJob extends BaseCronJob { } + /*** + * + * @param dataJson + * @return + */ + public static String doPostByAuth(String esiginsUrl, String dataJson, String auth){ + BaseBean bb = new BaseBean(); + + String authorization = "Basic "+new String(Base64.encode(auth)); + bb.writeLog("authorization:"+authorization); + bb.writeLog("esiginsUrl:"+esiginsUrl); + + String msgData = "" ; + OkHttpClient client = new OkHttpClient().newBuilder().build(); + MediaType mediaType = MediaType.parse("text/plain"); + Request request = new Request.Builder() + .url(esiginsUrl) + .method("GET", null) + .addHeader("Authorization", authorization) + .addHeader("Content-Type", "application/json") + .build(); + + try { + Response response = client.newCall(request).execute(); + bb.writeLog("response.code():"+response.code()); + bb.writeLog("response.body():"+response.body().string()); + msgData = response.body().string(); + } catch (IOException e) { + e.printStackTrace(); + } + return msgData; + } + + public static void main(String[] args) { + + String username = "admin"; + String passwd = "Uportal_123"; + String esiginsUrl = "http://172.16.25.133/portal-web/v1/esign/Forest/esigns" ; + String auth = username + ":" + passwd; + String msg = doPostByAuth(esiginsUrl,"",auth); + System.out.println(msg); + + } + + + public static void ttttt(){ + OkHttpClient client = new OkHttpClient().newBuilder() + .build(); + MediaType mediaType = MediaType.parse("text/plain"); + RequestBody body = RequestBody.create(mediaType, ""); + Request request = new Request.Builder() + .url("http://172.16.25.133/portal-web/v1/esign/Forest/esigns") + .method("GET", body) + .addHeader("Authorization", "Basic YWRtaW46VXBvcnRhbF8xMjM=") + .addHeader("Cookie", "SESSION=27a4896a-dcf7-493b-82fd-91832fc034a3") + .build(); + try { + Response response = client.newCall(request).execute(); + System.out.println("response.code():"+response.code()); + System.out.println("response.body():"+response.body().string()); + String msgData = response.body().string(); + System.out.println("msgData:"+msgData); + } catch (IOException e) { + e.printStackTrace(); + } + } + + }