You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

338 lines
14 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.api.sfj.DA;
import com.api.sfj.DA.util.CreatXML;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.zip.ZipOutputStream;
import static com.api.sfj.DA.util.JY_action.filename;
import static com.api.sfj.DA.util.JY_action.fjFilename;
import static com.api.sfj.DA.util.ZipFile.zipu;
/**
* 政府收文单
* 2020-10-14
*/
public class ZFSW_Action implements Action {
public static String getFileNameNoEx(String filename) {
if ((filename != null) && (filename.length() > 0)) {
int dot = filename.lastIndexOf('.');
if ((dot >-1) && (dot < (filename.length()))) {
return filename.substring(0, dot);
}
}
return filename;
}
@Override
public String execute(RequestInfo requestinfo) {
BaseBean bb = new BaseBean();
RecordSet rs = new RecordSet();
//=====================================================================读取主表数据
bb.writeLog("====政府收文单========START="+requestinfo.getRequestid());
String requestid = requestinfo.getRequestid(); //请求ID
String src = requestinfo.getRequestManager().getSrc();
bb.writeLog("====政府收文单=====src="+src);
//当前操作类型 submit:提交/reject:退回
String workflowid = requestinfo.getWorkflowid(); //流程ID
String tablename = requestinfo.getRequestManager().getBillTableName();//表单名称
String sql = "select * from "+tablename+" where requestid = "+requestid;
rs.execute(sql);
rs.writeLog(sql);
HashMap map = new HashMap(); // 依据说明
HashMap mapList = new HashMap(); // 归档文件
SimpleDateFormat fomat = new SimpleDateFormat("yyyyMMddHHmmss");
String time = fomat.format(new Date());
bb.writeLog(time);
UUID uuid = UUID.randomUUID();
bb.writeLog(uuid);
String str = uuid.toString().replaceAll("-","");
String fj ="";
String ofdwj ="";
String wjbt="";
while (rs.next()){
String ljdjid = rs.getString("ljdjid"); // 来件登记id
String swbh = rs.getString("swbh"); // 收文编号
String swrq = rs.getString("swrq"); // 收文日期
String lwjg = rs.getString("lwjg");// 来文机关
String lwbh = rs.getString("lwbh"); // 来文编号
String jzsj = rs.getString("jzsj"); // 截至时间
wjbt = rs.getString("wjbt"); //文件标题
String zsdw = rs.getString("zsdw"); //主送单位
String csdw = rs.getString("csdw"); //抄送单位
int mj = rs.getInt("mj"); //密级
String hj = rs.getString("hj"); // 缓急
String zw = rs.getString("zw"); // 正文
ofdwj = rs.getString("ofdwj"); // ofd文件
fj =rs.getString("xgfj"); //附件
String xzcs = rs.getString("xzcs"); // 选择处室
String xzqtcs = rs.getString("xzqtcs"); //选择其他处室
String xzblry = rs.getString("xzblry");//选择办理人员
String mjstr="";
if(mj==0){
mjstr="非涉密";
}else if(mj==1){
mjstr="机密";
}else if(mj==2){
mjstr="秘密";
}
// Date date = new Date();
// String da = new SimpleDateFormat("yyyy-MM-dd").format(date).replaceAll("-","");
map.put("dh",time+"-"+requestid); //档号,归档存储文件文件夹名称
map.put("bt",wjbt); //标题
map.put("bh",lwbh);//文号
// map.put("zrz",lwjg); //责任者
map.put("rq",swrq.replaceAll("-","")); //日期
map.put("ys",1);
mapList.put("dh",str); //UUID档号
mapList.put("bt",wjbt); //文件标题
String depName="select departmentname from hrmdepartment where id="+48;
String zrzName ="";
try {
rs.execute(depName);
rs.writeLog(depName);
rs.next();
zrzName = rs.getString("departmentname");
}catch (Exception e){
bb.writeLog(""+e);
}
String createrId="SELECT CREATER FROM workflow_requestbase WHERE REQUESTID="+requestid;
String jgryid ="";
try {
rs.execute(createrId);
rs.writeLog(createrId);
rs.next();
jgryid = rs.getString("CREATER");
}catch (Exception e){
bb.writeLog(""+e);
}
String createrName="SELECT LASTNAME FROM hrmresource WHERE id=(SELECT CREATER FROM workflow_requestbase WHERE REQUESTID="+requestid+")";
String jgryName ="";
try {
rs.execute(createrName);
rs.writeLog(createrName);
rs.next();
jgryName = rs.getString("LASTNAME");
}catch (Exception e){
bb.writeLog(""+e);
}
String createrDepName="SELECT b.DEPARTMENTNAME FROM hrmresource a,hrmdepartment b WHERE a.departmentid = b.id AND a.ID=(SELECT CREATER FROM workflow_requestbase WHERE REQUESTID="+requestid+")";
String jgryBmName ="";
try {
rs.execute(createrDepName);
rs.writeLog(createrDepName);
rs.next();
jgryBmName = rs.getString("DEPARTMENTNAME");
}catch (Exception e){
bb.writeLog(""+e);
}
String nodeInfoSql="SELECT a.id,b.nodename,a.lastname,a.departmentname,a.receivedate,a.receivetime,a.operatedate,a.operatetime FROM (SELECT a.nodeid,a.receivedate,a.receivetime,a.operatedate,a.operatetime,c.lastname,a.requestid,c.id,c.departmentid,d.departmentname FROM workflow_currentoperator a,workflow_nodebase b,hrmresource c,hrmdepartment d" +
" WHERE a.nodeid=b.id AND a.processuser=c.id AND d.id=c.departmentid and a.requestid="+requestid+") a right JOIN (SELECT id ,nodename FROM workflow_nodebase WHERE id in(SELECT nodeid FROM workflow_currentoperator WHERE requestid="+requestid+")) b ON a.nodeid=b.id order by nodeid";
List<Map<String, Object>> nodeInfoList = new ArrayList<>();
try {
RecordSet recordSet = new RecordSet();
recordSet.execute(nodeInfoSql);
bb.writeLog("开始查询节点流程");
while (recordSet.next()){
Map<String,Object> nodeInfo = new HashMap<>();
nodeInfo.put("id",recordSet.getString("id"));
nodeInfo.put("nodename",recordSet.getString("nodename"));
nodeInfo.put("lastname",recordSet.getString("lastname"));
nodeInfo.put("departmentname",recordSet.getString("departmentname"));
nodeInfo.put("receivedate",recordSet.getString("receivedate"));
nodeInfo.put("receivetime",recordSet.getString("receivetime"));
nodeInfo.put("operatedate",recordSet.getString("operatedate"));
nodeInfo.put("operatetime",recordSet.getString("operatetime"));
nodeInfoList.add(nodeInfo);
}
bb.writeLog("查询节点流程");
}catch (Exception e){
e.printStackTrace();
}
bb.writeLog("节点信息-->"+nodeInfoList);
bb.writeLog("查询出的附件-->"+fj);
String[] arr = fj.split(",");
List<Map<String, Object>> fjList = new ArrayList<>();
for (int i = 0; i < arr.length; i++) {
//附件
String fjSQL="SELECT filerealpath,imagefilename FROM imagefile WHERE imagefileid ="+ arr[i];
try {
RecordSet recordSet = new RecordSet();
recordSet.execute(fjSQL);
bb.writeLog("开始附件列表");
while (recordSet.next()){
Map<String,Object> fjMap = new HashMap<>();
String filerealpath = recordSet.getString("filerealpath");
String imagefilename = recordSet.getString("imagefilename");
int index = filerealpath.lastIndexOf("/");
int index2 = imagefilename.lastIndexOf(".");
String zipPath = filerealpath.substring(index + 1); //压缩文件名
String newname = imagefilename.substring(0, index2);
String fileNameNoEx = getFileNameNoEx(zipPath);
fjMap.put("filerealpath",filerealpath);
fjMap.put("imagefilename",imagefilename);
fjMap.put("fjUUID",fileNameNoEx);
fjList.add(fjMap);
}
bb.writeLog("查询附件结束 fjList.size()==="+fjList.size());
}catch (Exception e){
bb.writeLog("查询附件异常==="+e);
}
}
// mapList.put("zrz","天津市司法局"); //责任者
map.put("zrz",zrzName);
mapList.put("zrz",zrzName);
mapList.put("jgryName",jgryName); //机构人员中文
mapList.put("jgryBmName",jgryBmName); //机构人员部门名称
mapList.put("jgryid",jgryid); //机构人员id
mapList.put("rq",swrq.replaceAll("-","")); //日期
mapList.put("kzbs","控制"); // 控制标识
mapList.put("zw",ofdwj); // 正文
mapList.put("nodeInfoList",nodeInfoList);
if(fj!=null && fj!=""){
mapList.put("fj",fj); //附件
}else{
mapList.put("fj","0"); //附件
}
if(fj!=null && fj!=""){
mapList.put("fjList",fjList); //附件
}else{
mapList.put("fjList","0"); //附件
}
// mapList.put("cld",ofdwj); //处理单
mapList.put("wz","收文"); //文种
mapList.put("mj",mjstr);
bb.writeLog("====政府收文单==内部=444=map="+map.toString());
bb.writeLog("====政府收文单==内部=444=maplist="+mapList.toString());
}
bb.writeLog("time-->"+time);
String filerealpath = "";
String YJnewPath = "/home/WEAVER/oadata792/DAGD/ZFSW/"+str; //归档文件依据说明文件夹
String GDnewPath = "/home/WEAVER/oadata792/DAGD/ZFSW/"+str+"/"+time+"-"+requestid; //归档文件正文附件文件夹
String zipname =str+".zip";
String zippath = YJnewPath+".zip";//压缩包路径
// 根据系统的实际情况选择目录分隔符baiwindows下是dulinux下是/
// linux下只认正斜杠为了保证跨平台性不建议使用反斜杠在java程序中是转义字符用\来表示反斜杠)
// 在内存中创建一个文件对象,注意:此时还没有在硬盘对应目录下创建实实在在的文件
// File f = new File(YJnewPath);
// if(f.exists()) {
//// 文件已经存在,输出文件的相关信息
// System.out.println(f.getAbsolutePath());
// System.out.println(f.getName());
// System.out.println(f.length());
// } else {
//// 先创建文件所在的目录
// f.getParentFile().mkdirs();
//
// }
File f2 = new File(GDnewPath+"/ww");
if(f2.exists()) {
bb.writeLog("if(f2.exists()) {---->");
bb.writeLog("f2.getAbsolutePath()-->"+f2.getAbsolutePath());
bb.writeLog("f2.getName()-->"+f2.getName());
bb.writeLog("f2.length()-->"+f2.length());
} else {
// 先创建文件所在的目录
boolean su =f2.getParentFile().mkdirs();
if(su==true){
if(fj.length()>0){
fjFilename(fj,GDnewPath);
}
if(ofdwj.length()>0){
String filename = filename(ofdwj, GDnewPath);
mapList.put("cld",filename);
}
}
}
//先创建文件夹,之后存放文件,再传递建模进行记录
//先创建文件夹,之后存放文件,再传递建模进行记录
CreatXML creatXML = new CreatXML();
try {
creatXML.createYJSMXml(YJnewPath,map);
} catch (Exception e) {
e.printStackTrace();
bb.writeLog("政府收文单----依据说明:" + e);
}
try {
creatXML.createGDWJXml(GDnewPath,mapList);
} catch (Exception e) {
e.printStackTrace();
bb.writeLog("政府收文单=====归档文件:" + e);
}
File f1=null;
ZipOutputStream out=null;
String zip = YJnewPath+".zip";
// try {
// f1= new File(YJnewPath);
// out = new ZipOutputStream(new FileOutputStream(
// YJnewPath+".zip"));
// zip(out,f1,null);
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// } catch (Exception e) {
// e.printStackTrace();
// }
// try {
// ZipUtil zipUtil = new ZipUtil();
// zipUtil.zip(YJnewPath,zippath);
// } catch (Exception e) {
// e.printStackTrace();
// }
zipu(YJnewPath,zippath);
Date date = new Date();
String day = new SimpleDateFormat("yyyy-MM-dd").format(date);
String daytime = new SimpleDateFormat("hh:mm").format(date);
//文件路径收发文类别文件夹名称归档状态流程id
// String insertsql = "insert into uf_dagd(wjlj,sfwlb,wjjmc,gdzt,lcid,lcgdrq,lcgdsj,gdlcm) values('"+zippath+"','"+0+"','"+zipname+"','"+0+"','"+requestid+"','"+day+"','"+daytime+"','"+wjbt+"')";
String insertsql = "insert into uf_dagd(wjlj,sfwlb,wjjmc,gdzt,lcid,lcgdrq,lcgdsj,ssbm,gdlcm) values('"+zippath+"','"+0+"','"+zipname+"','"+0+"','"+requestid+"','"+day+"','"+daytime+"','"+48+"','"+wjbt+"')";
RecordSet recordSet = new RecordSet();
recordSet.execute(insertsql);
recordSet.writeLog("建模台账添加数据"+insertsql);
//
return Action.SUCCESS;
}
}