From d187233edd5459174f7f84887c9d8ae18878c720 Mon Sep 17 00:00:00 2001 From: liujiaji Date: Tue, 21 Aug 2018 15:04:21 +0800 Subject: [PATCH] =?UTF-8?q?customer=20=E7=A9=BA=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=20=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tenwa/doc/action/DocListInitAction.java | 425 ++++++++++-------- 1 file changed, 248 insertions(+), 177 deletions(-) diff --git a/src_core/com/tenwa/doc/action/DocListInitAction.java b/src_core/com/tenwa/doc/action/DocListInitAction.java index 3a2ca6fa7..ee2a24e84 100644 --- a/src_core/com/tenwa/doc/action/DocListInitAction.java +++ b/src_core/com/tenwa/doc/action/DocListInitAction.java @@ -19,6 +19,7 @@ import jbo.app.tenwa.doc.LB_DOCLIBRARY; import jbo.app.tenwa.doc.LB_DOCRELATIVE; import jbo.com.tenwa.entity.comm.flow.FLOW_BUSSINESS_OBJECT; +import com.amarsoft.are.ARE; import com.amarsoft.are.jbo.BizObject; import com.amarsoft.are.jbo.BizObjectManager; import com.amarsoft.are.jbo.JBOException; @@ -29,247 +30,317 @@ import com.tenwa.officetempalte.util.FileOperatorUtil; public class DocListInitAction { /** * - * @param param LB_DOCRELATIVE 表里的字段参数 - * @param docno 资料清单编号 单个:001001 多个: 001001,002001 + * @param param + * LB_DOCRELATIVE 表里的字段参数 + * @param docno + * 资料清单编号 单个:001001 多个: 001001,002001 * @param curConfig - * @throws Exception + * @throws Exception */ @SuppressWarnings("unchecked") - public static void initDocList(Map param,Map other,String docno,Configure curConfig) throws Exception{ + public static void initDocList(Map param, + Map other, String docno, Configure curConfig) + throws Exception { String CustomerType = other.get("CustomerType"); - String[] itemnos=docno.split(","); - String s=""; - for(int i=0;i0){ - s=s.substring(0, s.length()-1); - } - docno=s; - BizObjectManager relaBm=JBOFactory.getBizObjectManager(LB_DOCRELATIVE.CLASS_NAME); - BizObjectManager libBm=JBOFactory.getBizObjectManager(LB_DOCLIBRARY.CLASS_NAME); - BizObjectManager configBm=JBOFactory.getBizObjectManager(LB_DOCCONFIG.CLASS_NAME); - if("".equals(docno)){ + String[] itemnos = docno.split(","); + String s = ""; + for (int i = 0; i < itemnos.length; i++) { + if ("03".equals(CustomerType)) + if (itemnos[i].startsWith("006")) + continue; + else + ARE.getLog().debug(itemnos[i]); + else if ("01".equals(CustomerType)) + if (itemnos[i].startsWith("003")) + continue; + else + ARE.getLog().debug(itemnos[i]); + else + continue; + + s += "'" + itemnos[i] + "',"; + } + if (s.length() > 0) { + s = s.substring(0, s.length() - 1); + } + docno = s; + BizObjectManager relaBm = JBOFactory + .getBizObjectManager(LB_DOCRELATIVE.CLASS_NAME); + BizObjectManager libBm = JBOFactory + .getBizObjectManager(LB_DOCLIBRARY.CLASS_NAME); + BizObjectManager configBm = JBOFactory + .getBizObjectManager(LB_DOCCONFIG.CLASS_NAME); + if ("".equals(docno)) { return; } - String sql=getDocSQL(param,docno); - BizObject rela=relaBm.createQuery(sql).getSingleResult(true); - String relativeid=""; - String libid=""; - if(rela==null){ - rela=relaBm.newObject(); + String sql = getDocSQL(param, docno); + BizObject rela = relaBm.createQuery(sql).getSingleResult(true); + String relativeid = ""; + String libid = ""; + if (rela == null) { + rela = relaBm.newObject(); rela.setAttributesValue(param); relaBm.saveObject(rela); } - relativeid=rela.getAttribute("id").getString(); - - List configList=configBm.createQuery("doc_Class_Itemno in ("+docno+")").getResultList(false); - for(BizObject config:configList){ - BizObject lib=libBm.createQuery("Relative_Id=:relaid and config_id=:configid").setParameter("relaid", relativeid).setParameter("configid",config.getAttribute("id").getString()).getSingleResult(true); - if(lib==null){ - lib=libBm.newObject(); + relativeid = rela.getAttribute("id").getString(); + + List configList = configBm.createQuery( + "doc_Class_Itemno in (" + docno + ")").getResultList(false); + for (BizObject config : configList) { + BizObject lib = libBm + .createQuery("Relative_Id=:relaid and config_id=:configid") + .setParameter("relaid", relativeid) + .setParameter("configid", + config.getAttribute("id").getString()) + .getSingleResult(true); + if (lib == null) { + lib = libBm.newObject(); DataOperatorUtil.coptyJBOPropertyNoKey(config, lib); lib.setAttributeValue("relative_id", relativeid); - lib.setAttributeValue("BUSINESS_CHECK","DocCheck_2"); - lib.setAttributeValue("REVIEW_CHECK","DocCheck_2"); - lib.setAttributeValue("config_id",config.getAttribute("id").getString()); - lib.setAttributeValue("IS_INIT","1"); - if("used_car".equals(other.get("carAttributes"))&&"车辆照片".equals(lib.getAttribute("DOC_NAME").getString())){ + lib.setAttributeValue("BUSINESS_CHECK", "DocCheck_2"); + lib.setAttributeValue("REVIEW_CHECK", "DocCheck_2"); + lib.setAttributeValue("config_id", config.getAttribute("id") + .getString()); + lib.setAttributeValue("IS_INIT", "1"); + if ("used_car".equals(other.get("carAttributes")) + && "车辆照片".equals(lib.getAttribute("DOC_NAME") + .getString())) { lib.setAttributeValue("DOC_NATURE", "01"); } libBm.saveObject(lib); - }else{ - if(lib.getAttribute("IS_INIT").getString().equals("1")){ + } else { + if (lib.getAttribute("IS_INIT").getString().equals("1")) { continue; } - lib.setAttributeValue("IS_INIT","1"); + lib.setAttributeValue("IS_INIT", "1"); libBm.saveObject(lib); } - libid=lib.getAttribute("id").getString(); - sql=getRelaSQL(param); - if(sql.length()==0){ + libid = lib.getAttribute("id").getString(); + sql = getRelaSQL(param); + if (sql.length() == 0) { continue; - }else{ - //关联其它文件清单 - String[] docRelas=config.getAttribute("DOC_RELATION_ID").getString().split(","); - Boolean flag=false; - for(int i=0;i libList=libBm.createQuery(sql).setParameter("configid", docRelas[i]).getResultList(false); - for(BizObject li:libList) - { - Boolean flag2= copyDocAttr(li,libid,curConfig.getConfigure("FileSaveMode")); - if(flag2){ - flag=true; + } else { + // 关联其它文件清单 + String[] docRelas = config.getAttribute("DOC_RELATION_ID") + .getString().split(","); + Boolean flag = false; + for (int i = 0; i < docRelas.length; i++) { + List libList = libBm.createQuery(sql) + .setParameter("configid", docRelas[i]) + .getResultList(false); + for (BizObject li : libList) { + Boolean flag2 = copyDocAttr(li, libid, + curConfig.getConfigure("FileSaveMode")); + if (flag2) { + flag = true; } } } - if(flag){ - lib.setAttributeValue("BUSINESS_CHECK","DocCheck_0"); + if (flag) { + lib.setAttributeValue("BUSINESS_CHECK", "DocCheck_0"); libBm.saveObject(lib); } } } - - + } + /** * 获取关联的sql + * * @param param * @param docno * @return - * @throws Exception + * @throws Exception */ - public static String getDocSQL(Map param,String docno) throws Exception{ - String sql="select id from O left join jbo.app.tenwa.doc.LB_DOCLIBRARY lib on O.id=lib.Relative_Id where lib.doc_Class_Itemno in ("+docno+") "; - if("Customer".equals(param.get("ObjectType"))){ - sql+=" and O.cust_id='"+param.get("cust_id")+"' and O.objecttype='Customer' "; - }else{ - BizObject flow=JBOFactory.createBizObjectQuery(FLOW_BUSSINESS_OBJECT.CLASS_NAME,"flow_unid=:flowunid").setParameter("flowunid",param.get("flow_unid")).getSingleResult(false); - String otherWhere=getFlowWhere(flow,"","O"); - sql+=otherWhere; - if(param.containsKey("cust_id")&¶m.get("cust_id").length()>0){ - sql+=" and O.cust_id='"+param.get("cust_id")+"'"; + public static String getDocSQL(Map param, String docno) + throws Exception { + String sql = "select id from O left join jbo.app.tenwa.doc.LB_DOCLIBRARY lib on O.id=lib.Relative_Id where lib.doc_Class_Itemno in (" + + docno + ") "; + if ("Customer".equals(param.get("ObjectType"))) { + sql += " and O.cust_id='" + param.get("cust_id") + + "' and O.objecttype='Customer' "; + } else { + BizObject flow = JBOFactory + .createBizObjectQuery(FLOW_BUSSINESS_OBJECT.CLASS_NAME, + "flow_unid=:flowunid") + .setParameter("flowunid", param.get("flow_unid")) + .getSingleResult(false); + String otherWhere = getFlowWhere(flow, "", "O"); + sql += otherWhere; + if (param.containsKey("cust_id") + && param.get("cust_id").length() > 0) { + sql += " and O.cust_id='" + param.get("cust_id") + "'"; } } return sql; - } + } + /** - * 获取要复制的附件 sql + * 获取要复制的附件 sql + * * @param param * @return */ - public static String getRelaSQL(Map param){ - String sql=""; - if("ProjectApprovalFlow".equals(param.get("ObjectType"))||"ProjectChangeFlow".equals(param.get("ObjectType"))||"ProjectCreditFlow".equals(param.get("ObjectType"))||"ProjectRecreditFlow".equals(param.get("ObjectType"))){ - sql="select * from O left join jbo.app.tenwa.doc.LB_DOCRELATIVE rela on O.RELATIVE_ID=rela.id where config_id=:configid and rela.cust_id='"+param.get("cust_id")+"' and rela.ObjectType='Customer'"; - }else if("ContractHandoverFlow".equals(param.get("ObjectType"))||"BContractApproveFlow".equals(param.get("ObjectType"))||"BContractChangeFlow".equals(param.get("ObjectType"))||"BContractCancelFlow".equals(param.get("ObjectType"))||"BContractHandoverFlow".equals(param.get("ObjectType"))||"BContractSupportFlow".equals(param.get("ObjectType"))||"FundPaymentCarFlow".equals(param.get("ObjectType"))||"BusinessCancelFlow".equals(param.get("ObjectType"))){ - sql="select * from O left join jbo.app.tenwa.doc.LB_DOCRELATIVE rela on O.RELATIVE_ID=rela.id where config_id=:configid and rela.proj_id='"+param.get("proj_id")+"'"; + public static String getRelaSQL(Map param) { + String sql = ""; + if ("ProjectApprovalFlow".equals(param.get("ObjectType")) + || "ProjectChangeFlow".equals(param.get("ObjectType")) + || "ProjectCreditFlow".equals(param.get("ObjectType")) + || "ProjectRecreditFlow".equals(param.get("ObjectType"))) { + sql = "select * from O left join jbo.app.tenwa.doc.LB_DOCRELATIVE rela on O.RELATIVE_ID=rela.id where config_id=:configid and rela.cust_id='" + + param.get("cust_id") + "' and rela.ObjectType='Customer'"; + } else if ("ContractHandoverFlow".equals(param.get("ObjectType")) + || "BContractApproveFlow".equals(param.get("ObjectType")) + || "BContractChangeFlow".equals(param.get("ObjectType")) + || "BContractCancelFlow".equals(param.get("ObjectType")) + || "BContractHandoverFlow".equals(param.get("ObjectType")) + || "BContractSupportFlow".equals(param.get("ObjectType")) + || "FundPaymentCarFlow".equals(param.get("ObjectType")) + || "BusinessCancelFlow".equals(param.get("ObjectType"))) { + sql = "select * from O left join jbo.app.tenwa.doc.LB_DOCRELATIVE rela on O.RELATIVE_ID=rela.id where config_id=:configid and rela.proj_id='" + + param.get("proj_id") + "'"; } return sql; } + /** * - * @param lib 关联这个对象下的附件 - * @param libid 新复制的附件要挂的分类 - * @throws Exception + * @param lib + * 关联这个对象下的附件 + * @param libid + * 新复制的附件要挂的分类 + * @throws Exception */ - public static Boolean copyDocAttr(BizObject lib,String libid,String path) throws Exception{ - - BizObjectManager bm=JBOFactory.getBizObjectManager(LB_DOCATTRIBUTE.CLASS_NAME); - + public static Boolean copyDocAttr(BizObject lib, String libid, String path) + throws Exception { + + BizObjectManager bm = JBOFactory + .getBizObjectManager(LB_DOCATTRIBUTE.CLASS_NAME); + @SuppressWarnings("unchecked") - List attrs=bm.createQuery("LIBRARY_ID=:LIBRARYID").setParameter("LIBRARYID", lib.getAttribute("id").getString()).getResultList(false); - BizObject attrNew=null; - for(int i=0;i attrs = bm.createQuery("LIBRARY_ID=:LIBRARYID") + .setParameter("LIBRARYID", lib.getAttribute("id").getString()) + .getResultList(false); + BizObject attrNew = null; + for (int i = 0; i < attrs.size(); i++) { + attrNew = bm.newObject(); DataOperatorUtil.coptyJBOPropertyNoKey(attrs.get(i), attrNew); - String oldFullPath=attrNew.getAttribute("fullPath").getString(); - String fileName=attrNew.getAttribute("filename").getString(); - String uuid=UUID.randomUUID().toString().replaceAll("-", ""); - String fullPath=FileOperatorUtil.getuploadFileDir(path) +uuid+"_"+fileName; - String filePath=fullPath.replace(path, ""); + String oldFullPath = attrNew.getAttribute("fullPath").getString(); + String fileName = attrNew.getAttribute("filename").getString(); + String uuid = UUID.randomUUID().toString().replaceAll("-", ""); + String fullPath = FileOperatorUtil.getuploadFileDir(path) + uuid + + "_" + fileName; + String filePath = fullPath.replace(path, ""); attrNew.setAttributeValue("FilePath", filePath); attrNew.setAttributeValue("FullPath", fullPath); - attrNew.setAttributeValue("LIBRARY_ID",libid); - copyFile(oldFullPath,fullPath); + attrNew.setAttributeValue("LIBRARY_ID", libid); + copyFile(oldFullPath, fullPath); bm.saveObject(attrNew); } - Boolean flag=attrs.size()>0?true:false; + Boolean flag = attrs.size() > 0 ? true : false; return flag; } - - /** - * 复制单个文件 - * @param oldPath String 原文件路径 如:c:/fqf.txt - * @param newPath String 复制后路径 如:f:/fqf.txt - * @return boolean - */ - public static void copyFile(String oldPath, String newPath) { - try { - int byteread = 0; - File oldfile = new File(oldPath); - if (oldfile.exists()) { //文件存在时 - InputStream inStream = new FileInputStream(oldPath); //读入原文件 + + /** + * 复制单个文件 + * + * @param oldPath + * String 原文件路径 如:c:/fqf.txt + * @param newPath + * String 复制后路径 如:f:/fqf.txt + * @return boolean + */ + public static void copyFile(String oldPath, String newPath) { + try { + int byteread = 0; + File oldfile = new File(oldPath); + if (oldfile.exists()) { // 文件存在时 + InputStream inStream = new FileInputStream(oldPath); // 读入原文件 @SuppressWarnings("resource") - FileOutputStream fs = new FileOutputStream(newPath); - byte[] buffer = new byte[1444]; - while ( (byteread = inStream.read(buffer)) != -1) { - fs.write(buffer, 0, byteread); - } - inStream.close(); - } - } - catch (Exception e) { - System.out.println("复制单个文件操作出错"); - e.printStackTrace(); - } - } - - public static String getFlowWhere(BizObject flow,String idlst,String value) throws Exception{ - - String table=""; - if(value.length()>0){ - table=value+"."; + FileOutputStream fs = new FileOutputStream(newPath); + byte[] buffer = new byte[1444]; + while ((byteread = inStream.read(buffer)) != -1) { + fs.write(buffer, 0, byteread); + } + inStream.close(); + } + } catch (Exception e) { + System.out.println("复制单个文件操作出错"); + e.printStackTrace(); } - - String FlowName=flow.getAttribute("flow_name").getString(); - String proj_id=flow.getAttribute("proj_id").getString(); - - String contract_id=flow.getAttribute("contract_id").getString(); - - String flowunid=flow.getAttribute("flow_unid").getString(); - - String otherWhere=""; - if(idlst.length()>0){ - otherWhere=" and O.id in("+idlst+")"; - }else if(contract_id.length()>0&&!"flow".equals(getDocType(FlowName))){ - otherWhere=" and "+table+"proj_id='"+proj_id+"' and ("+table+"contract_id='' or "+table+"contract_id is null or "+table+"contract_id='"+contract_id+"') "; - }else if(proj_id.length()>0&&!"flow".equals(getDocType(FlowName))){ - otherWhere=" and "+table+"proj_id='"+proj_id+"' and "+table+"objecttype='"+getDocType(FlowName)+"'"; - }else{ - otherWhere=" and "+table+"flow_unid='"+flowunid+"'"; + } + + public static String getFlowWhere(BizObject flow, String idlst, String value) + throws Exception { + + String table = ""; + if (value.length() > 0) { + table = value + "."; } - + + String FlowName = flow.getAttribute("flow_name").getString(); + String proj_id = flow.getAttribute("proj_id").getString(); + + String contract_id = flow.getAttribute("contract_id").getString(); + + String flowunid = flow.getAttribute("flow_unid").getString(); + + String otherWhere = ""; + if (idlst.length() > 0) { + otherWhere = " and O.id in(" + idlst + ")"; + } else if (contract_id.length() > 0 + && !"flow".equals(getDocType(FlowName))) { + otherWhere = " and " + table + "proj_id='" + proj_id + "' and (" + + table + "contract_id='' or " + table + + "contract_id is null or " + table + "contract_id='" + + contract_id + "') "; + } else if (proj_id.length() > 0 && !"flow".equals(getDocType(FlowName))) { + otherWhere = " and " + table + "proj_id='" + proj_id + "' and " + + table + "objecttype='" + getDocType(FlowName) + "'"; + } else { + otherWhere = " and " + table + "flow_unid='" + flowunid + "'"; + } + return otherWhere; } + /** - * 校验附件一览类型 - * 附件一览分2种可上传类型, - * 1与项目或合同绑定的附件,多次发起流程将会累计附件 - * 2与流程本身绑定,仅在本次流程中可见 + * 校验附件一览类型 附件一览分2种可上传类型, 1与项目或合同绑定的附件,多次发起流程将会累计附件 2与流程本身绑定,仅在本次流程中可见 * 3与流程与项目合同都绑定,在流程中只能看见本次上传的附件。其它次附件在别处根据项目编号可查看 - * @return - * @throws Exception - * @throws JBOException + * + * @return + * @throws Exception + * @throws JBOException */ - public static String getDocType(String flowName) throws Exception{ - String sql ="SELECT FLOWNO FROM flow_catalog WHERE flowname='"+flowName+"'"; - List> ds = DataOperatorUtil.getDataBySql(JBOFactory.createJBOTransaction(), sql, null); - String flowno = GetValueByKey("docpreview.properties",ds.get(0).get("FLOWNO")); - //根据要求拖车申请是 - if(flowno!=null){ + public static String getDocType(String flowName) throws Exception { + String sql = "SELECT FLOWNO FROM flow_catalog WHERE flowname='" + + flowName + "'"; + List> ds = DataOperatorUtil.getDataBySql( + JBOFactory.createJBOTransaction(), sql, null); + String flowno = GetValueByKey("docpreview.properties", + ds.get(0).get("FLOWNO")); + // 根据要求拖车申请是 + if (flowno != null) { return "flow"; } return ds.get(0).get("FLOWNO"); } - //根据Key读取Value - public static String GetValueByKey(String filePath, String key) { - Properties pps = new Properties(); - try { - InputStream in = DocListInitAction.class.getClassLoader().getResourceAsStream(filePath); - pps.load(in); - String value = pps.getProperty(key); - System.out.println(key + " = " + value); - return value; - - }catch (IOException e) { - e.printStackTrace(); - return null; - } - } + + // 根据Key读取Value + public static String GetValueByKey(String filePath, String key) { + Properties pps = new Properties(); + try { + InputStream in = DocListInitAction.class.getClassLoader() + .getResourceAsStream(filePath); + pps.load(in); + String value = pps.getProperty(key); + System.out.println(key + " = " + value); + return value; + + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } }