diff --git a/src/weaver/interfaces/job/ESiginsCronJob.java b/src/weaver/interfaces/job/ESiginsCronJob.java index 165cc360..6ec4a126 100644 --- a/src/weaver/interfaces/job/ESiginsCronJob.java +++ b/src/weaver/interfaces/job/ESiginsCronJob.java @@ -11,7 +11,6 @@ import weaver.docs.docs.ImageFileIdUpdate; import weaver.general.BaseBean; import weaver.general.TimeUtil; import weaver.general.Util; -import weaver.interfaces.filter.HttpRequestUtil; import weaver.interfaces.schedule.BaseCronJob; import java.io.*; @@ -41,7 +40,7 @@ public class ESiginsCronJob extends BaseCronJob { List> list = new ArrayList>(); Map map = null; - String hrmsql = " select id,loginid,subcompanyid1,workcode from hrmresource where status = 1 and departmentid in(29,30) " ; + String hrmsql = " select id,loginid,subcompanyid1,workcode from hrmresource where status = 1 " ; bb.writeLog("hrmsql:"+hrmsql); rs.executeQuery(hrmsql); while (rs.next()){ @@ -68,9 +67,13 @@ public class ESiginsCronJob extends BaseCronJob { bb.writeLog("list:"+list.size()); ImageFileIdUpdate im = new ImageFileIdUpdate(); - HttpRequestUtil HttpRequestUtil = new HttpRequestUtil(); String esignImage = "" ; + // data:image/gif;base64,base64编码的gif图片数据 +// data:image/png;base64,base64编码的png图片数据 +// data:image/jpeg;base64,base64编码的图片数据 +// data:image/x-icon;base64,base64编码的icon图片数据 + for(int i=0;i dataMap = list.get(i); @@ -78,123 +81,104 @@ public class ESiginsCronJob extends BaseCronJob { String sysUserCode = dataMap.get("loginid"); String subcompanyid1 = dataMap.get("subcompanyid1"); String workcode = dataMap.get("workcode"); - - esiginsUrl += "/"+workcode+"/esigns"; - + String url = esiginsUrl+ "/"+workcode+"/esigns"; String auth = username + ":" + passwd; - String msg = doPostByAuth(esiginsUrl,"",auth); - bb.writeLog("msg2 ==" + msg); + try{ + String msg = doPostByAuth(url,"",auth); + bb.writeLog("msg2 ==" + msg); + if(StringUtils.isNotEmpty(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"; + } -// data:image/gif;base64,base64编码的gif图片数据 -// data:image/png;base64,base64编码的png图片数据 -// data:image/jpeg;base64,base64编码的图片数据 -// data:image/x-icon;base64,base64编码的icon图片数据 + String filepath = ecology_app_root+"/filesystem/dzyz/"+sysUserCode ; + bb.writeLog("filepath:"+filepath); + File file = new File(filepath); + if(!file.exists()){ + file.mkdirs(); + } - 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"; - } + long currentTime = System.currentTimeMillis(); + String imagefilename = DigestUtils.md5Hex(sysUserCode); //MD5加密 + //String imageFilePath = filepath+"/"+imagefilename+Util.null2String(currentTime); + String imageFilePath = filepath+"/"+imagefilename; + String image_File_Path = saveImageFile(esignImage,imageFilePath,imagetype); + bb.writeLog("image_File_Path:"+image_File_Path); - 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 = ecology_app_root+"/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()) + if(!"".equals(image_File_Path)) { - 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{ - 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}); + 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); + + String imagefileid = "" ; + String oldfilerealpath = "" ; + String markid = "" ; + String sql =" select t.markid,t.imagefileid,k.filerealpath\n" + + " from DocSignature t\n" + + " left join imagefile k on k.imagefileid = t.imagefileid\n" + + " where t.isdefault = 1 and t.hrmresid= ?" ; + bb.writeLog("userid:"+userid); + rs.executeQuery(sql,new Object[]{userid}); 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}); + if(rs.next()){ + oldfilerealpath = Util.null2String(rs.getString("filerealpath")); + imagefileid = Util.null2String(rs.getString("imagefileid")); + markid = Util.null2String(rs.getString("markid")); + } + bb.writeLog("oldfilerealpath:"+oldfilerealpath); + if(StringUtils.isNotEmpty(markid) && StringUtils.isNotEmpty(imagefileid) && StringUtils.isNotEmpty(oldfilerealpath)){ + String markdate = TimeUtil.getCurrentTimeString(); + sql = " update DocSignature set MARKDATE = ? where MARKID= ?" ; bb.writeLog("sql:"+sql); + rs.executeUpdate(sql,new Object[]{markdate,markid}); + }else{ + updateSignature(sysUserCode,imagetype,image_File_Zip_Path,filesize,image_File_Path,subcompanyid1,userid); } +// if(StringUtils.isEmpty(oldfilerealpath) || StringUtils.isEmpty(imagefileid)) +// { +//// File oldFileZip = new File(oldfilerealpath); +//// if(oldFileZip.exists()){ +//// long oldfilesize = oldFileZip.length(); +//// bb.writeLog("oldfilesize:"+oldfilesize); +//// +//// if(oldfilesize != filesize) +//// { +//// updateSignature(sysUserCode,imagetype,image_File_Zip_Path,filesize,image_File_Path,subcompanyid1,userid); +//// } +//// }else{ +//// updateSignature(sysUserCode,imagetype,image_File_Zip_Path,filesize,image_File_Path,subcompanyid1,userid); +//// } +// } } } } @@ -204,8 +188,68 @@ public class ESiginsCronJob extends BaseCronJob { } } } + }catch (Exception e){ + bb.writeLog("e:"+e); + } + } + } + +// int imagefileid = im.getImageFileNewId(); +// 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); +// } +// } + + public void updateSignature(String sysUserCode,String imagetype,String image_File_Zip_Path,long filesize,String image_File_Path,String subcompanyid1,String userid){ + + 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"; + + ImageFileIdUpdate im = new ImageFileIdUpdate(); + RecordSet rs = new RecordSet(); + BaseBean bb = new BaseBean(); + + 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); } } + } @@ -245,6 +289,9 @@ public class ESiginsCronJob extends BaseCronJob { } + + + /*** * * @param imagefilepath @@ -338,11 +385,14 @@ public class ESiginsCronJob extends BaseCronJob { try { Response response = client.newCall(request).execute(); bb.writeLog("response.code():"+response.code()); - bb.writeLog("response.body():"+response.body().string()); + //bb.writeLog("response.body():"+response.body().string()); msgData = response.body().string(); } catch (IOException e) { e.printStackTrace(); + bb.writeLog("e2:"+e); } + + bb.writeLog("msgData:"+msgData); return msgData; }