| | |
| | | package com.product.file.service; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.beust.jcommander.internal.Lists; |
| | | import com.beust.jcommander.internal.Sets; |
| | | import com.product.common.collect.ListUtils; |
| | | import com.product.core.cache.DataPoolCacheImpl; |
| | | import com.product.core.config.CoreConst; |
| | |
| | | import com.product.quartz.service.impl.SysJobService; |
| | | import com.product.tool.table.enums.FieldType; |
| | | import com.product.util.BaseUtil; |
| | | import com.product.util.SystemParamReplace; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | fse.setValue("created_utc_datetime", new Date()); |
| | | fse.setValue("status", 1); |
| | | fse.setValue("is_conceal", 1); |
| | | fse.setValue("open_transaction", 1); |
| | | if (!com.product.common.lang.StringUtils.isEmpty(timeTaskUuid)) { |
| | | sysJobService.updateJob(fse); |
| | | } else { |
| | |
| | | */ |
| | | @Transactional |
| | | public void fileTime(String uuid) { |
| | | try { |
| | | FieldSetEntity fs = baseDao.getFieldSet(CmnConst.PRODUCT_AO_FILING_CONFIG, uuid, false); |
| | | FieldSetEntity function = BaseUtil.getSingleInfoByCache("所有功能", new String[]{fs.getString("function_uuid"), fs.getString(CmnConst.FUNCTION_UUID)}); |
| | | FieldSetEntity function = BaseUtil.getSingleInfoByCache("所有功能", new String[]{fs.getString(CmnConst.FUNCTION_UUID)}); |
| | | |
| | | DataTableEntity tableFields = DataPoolCacheImpl.getInstance().getCacheData("所有字段信息并按表分组", new String[]{function.getString("table_uuid")}); |
| | | if (DataTableEntity.isEmpty(tableFields)) { |
| | |
| | | } |
| | | StringBuilder sql = new StringBuilder(); |
| | | int pageSize = 1000; |
| | | String sub_folder = fs.getString("sub_folder"); |
| | | List<String> businessValueField = Lists.newArrayList(); |
| | | if (!map.containsKey(fs.getString("field_title"))) { |
| | | throw new BaseException(FileCode.ARCHIVE_FILE_TITLE_FIELD_NO_EXIST); |
| | | } |
| | | businessValueField.add(fs.getString("field_title")); |
| | | if (!StringUtils.isEmpty(sub_folder)) { |
| | | String[] split = sub_folder.split("/"); |
| | | for (int i = 0; i < split.length; i++) { |
| | | String name = split[i]; |
| | | if (StringUtils.startsWith(name, "{#") && StringUtils.endsWith(name, "#}")) { |
| | | name = split[i].replace("{#", "").replace("#}", ""); |
| | | if (map.containsKey(name)) { |
| | | businessValueField.add(name); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | sub_folder = "{#" + fs.getString("field_title") + "#}"; |
| | | } |
| | | |
| | | //查询业务数据 |
| | | sql.append("SELECT\n"); |
| | | // sql.append("\tT1.").append(fs.getString("field_title")).append(" as title"); |
| | | for (int i = 0; i < businessValueField.size(); i++) { |
| | | sql.append("\tT1." + businessValueField.get(i) + " as val_").append(i).append("\n,"); |
| | | // for (int i = 0; i < businessValueField.size(); i++) { |
| | | // sql.append("\tT1." + businessValueField.get(i) + " as val_").append(i).append("\n,"); |
| | | // } |
| | | sql.append("\tT4.record_uuid,T4.title flow_title,\n"); |
| | | for (String field : fileField) { |
| | | sql.append("\tT1.").append(field).append(","); |
| | | } |
| | | sql.append("\tT2.uuid,T2.attachment_size,T2.file_name,T3.dict_label file_type,T4.record_uuid\n"); |
| | | sql.append("FROM\n"); |
| | | sql.append("\tGROUP_CONCAT(flow_attachment) flow_attachments\n"); |
| | | sql.append("\t\nFROM\n"); |
| | | sql.append("\t").append(tableInfo.getString(CoreConst.FIELD_TABLE_NAME)).append(" T1\n"); |
| | | sql.append("\tJOIN product_sys_flow_detail T4 ON T1.uuid=T4.record_uuid\n"); |
| | | sql.append("\tJOIN product_sys_attachments T2 ON T1.attachment = T2.uuid or T1.attachment_meeting=T2.uuid\n"); |
| | | sql.append("\tJOIN product_sys_dict T3 ON T2.attachment_type_uuid=T3.uuid\n"); |
| | | // sql.append("\tJOIN product_sys_attachments T2 ON T1.attachment = T2.uuid or T1.attachment_meeting=T2.uuid\n"); |
| | | // sql.append("\tJOIN product_sys_dict T3 ON T2.attachment_type_uuid=T3.uuid\n"); |
| | | sql.append("WHERE\n"); |
| | | sql.append("\tT1.flow_flag =2\n"); |
| | | sql.append("\tAND T1.").append(archiveFlagField).append(" is null or ").append(archiveFlagField).append("!=1\n"); |
| | | sql.append("\tT1.").append(flowSignField).append("=2\n"); |
| | | sql.append("\tAND (T1.").append(archiveFlagField).append(" is null or T1.").append(archiveFlagField).append("!=1)\n"); |
| | | sql.append("\tAND T4.table_name='").append(tableInfo.getString(CoreConst.FIELD_TABLE_NAME)).append("'\n"); |
| | | sql.append("\tGROUP BY 1,2,3,4,5 limit ").append(pageSize); |
| | | sql.append("\t GROUP BY 1"); |
| | | for (int i = 0; i < fileField.size(); i++) { |
| | | sql.append(",").append(i + 2); |
| | | } |
| | | sql.append(" limit ").append(pageSize); |
| | | |
| | | DataTableEntity files = null; |
| | | DataTableEntity files; |
| | | String filing_catalog = fs.getString("filing_catalog"); |
| | | FieldSetEntity parentDir = baseDao.getFieldSetByFilter(CmnConst.PRODUCT_OA_DIRECTORY, "tricode=?", new String[]{filing_catalog}, false); |
| | | if (FieldSetEntity.isEmpty(parentDir)) { |
| | | throw new BaseException(FileCode.ARCHIVE_FILE_PARENT_DIRECTORY_NO_EXIST); |
| | | } |
| | | // baseDao.listTable(CmnConst.PRODUCT_SYS_ATTACHMENTS,BaseUtil.buildQuestionMarkFilter("uuid",),) |
| | | do { |
| | | |
| | | files = baseDao.listTable(sql.toString(), new Object[]{}); |
| | |
| | | break; |
| | | } |
| | | for (int i = 0; i < files.getRows(); i++) { |
| | | String sub_folder = fs.getString("sub_folder"); |
| | | if (StringUtils.isEmpty(sub_folder)) { |
| | | sub_folder = "{#" + fs.getString("field_title") + "#}"; |
| | | } |
| | | FieldSetEntity file = files.getFieldSetEntity(i); |
| | | for (int i1 = 0; i1 < businessValueField.size(); i1++) { |
| | | String value = file.getString("val_" + i1); |
| | | if (StringUtils.isEmpty(value)) { |
| | | // 查询记录 |
| | | FieldSetEntity record = baseDao.getFieldSet(tableInfo.getString(CoreConst.FIELD_TABLE_NAME), file.getString("record_uuid"), false); |
| | | baseDao.loadPromptData(record); |
| | | sub_folder = SystemParamReplace.formParamsReplace(sub_folder, record); |
| | | Set<String> attachments = Sets.newHashSet(); |
| | | for (String field : fileField) { |
| | | if (StringUtils.isEmpty(files.getString(i, field))) { |
| | | continue; |
| | | } |
| | | sub_folder = sub_folder.replace("{#" + businessValueField.get(i1) + "#}", value); |
| | | attachments.addAll(Arrays.asList(files.getString(i, field).split(","))); |
| | | } |
| | | String flowAttachments = files.getString(i, "flow_attachments"); |
| | | if (!StringUtils.isEmpty(flowAttachments)) { |
| | | attachments.addAll(Arrays.asList(flowAttachments.split(","))); |
| | | } |
| | | if (attachments.isEmpty()) { |
| | | baseDao.executeUpdate(" update " + tableInfo.getString("table_name") + " set " + archiveFlagField + "= '1' where uuid=?", new Object[]{file.getString("record_uuid")}); |
| | | continue; |
| | | } |
| | | String[] dirs = sub_folder.split("/"); |
| | | //递归查询父级目录 |
| | | FieldSetEntity parent = parentDir; |
| | | for (int j = 0; j < dirs.length; j++) { |
| | | String dir = dirs[j]; |
| | | FieldSetEntity temp = baseDao.getFieldSetByFilter(CmnConst.PRODUCT_OA_DIRECTORY, "tricode_parent=? and directory_name=", new String[]{parent.getString("tricode"), dir}, false); |
| | | FieldSetEntity temp = baseDao.getFieldSetByFilter(CmnConst.PRODUCT_OA_DIRECTORY, "tricode_parent=? and directory_name=?", new String[]{parent.getString("tricode"), dir}, false); |
| | | if (FieldSetEntity.isEmpty(temp)) { |
| | | //创建文件夹 |
| | | parent = addDirectory(dir, BaseUtil.createCode(CmnConst.PRODUCT_OA_DIRECTORY, |
| | | CmnConst.TRICODE, |
| | | parent.getString("tricode")), parent.getString(CmnConst.TRICODE), parent.getInteger("directory_tier") + 1, fs.getUUID(), tableInfo.getString(CoreConst.FIELD_TABLE_NAME)); |
| | | } else { |
| | | parent = temp; |
| | | } |
| | | } |
| | | |
| | | DataTableEntity documents = new DataTableEntity(); |
| | | Set<String> uuids = attachments; |
| | | DataTableEntity attachmentInfos = baseDao.listTable(CmnConst.PRODUCT_SYS_ATTACHMENTS, BaseUtil.buildQuestionMarkFilter("uuid", uuids.size(), true), uuids.toArray()); |
| | | DataTableEntity types = DataPoolCacheImpl.getInstance().getCacheData("数据字典配置信息", new String[]{"upload_file_format"}); |
| | | if (!DataTableEntity.isEmpty(attachmentInfos)) { |
| | | for (int k = 0; k < attachmentInfos.getRows(); k++) { |
| | | FieldSetEntity document = new FieldSetEntity(); |
| | | FieldSetEntity attachment = attachmentInfos.getFieldSetEntity(k); |
| | | document.setTableName(CmnConst.PRODUCT_OA_DOCUMENT); |
| | | document.setValue("directory_uuid", parent.getUUID()); |
| | | document.setValue("file_name", attachment.getString("file_name")); |
| | | document.setValue("attachments_uuid", attachment.getUUID()); |
| | | if (CollectionUtil.isEmpty(types.getFieldSetEntity(attachment.getString(CmnConst.ATTACHMENT_TYPE_UUID)))) { |
| | | document.setValue("file_type", attachment.getString("attachment_type_uuid")); |
| | | } else { |
| | | document.setValue("file_type", types.getFieldSetEntity(attachment.getString(CmnConst.ATTACHMENT_TYPE_UUID)).get(0).getString("dict_label")); |
| | | } |
| | | |
| | | document.setValue("created_by", 1); |
| | | document.setValue("created_utc_datetime", new Date()); |
| | | document.setValue("file_size", attachment.getString("attachment_size")); |
| | | document.setValue("turn_button", null); |
| | | documents.addFieldSetEntity(document); |
| | | } |
| | | } |
| | | FieldSetEntity document = new FieldSetEntity(); |
| | | document.setTableName(CmnConst.PRODUCT_OA_DOCUMENT); |
| | | document.setValue("directory_uuid", parent.getUUID()); |
| | | document.setValue("file_name", file.getString("file_name")); |
| | | document.setValue("attachments_uuid", file.getUUID()); |
| | | document.setValue("file_type", file.getString("file_type")); |
| | | document.setValue("file_name", file.getString("flow_title")); |
| | | document.setValue("created_by", 1); |
| | | document.setValue("created_utc_datetime", new Date()); |
| | | document.setValue("file_size", file.getString("attachment_size")); |
| | | baseDao.saveFieldSetEntity(document); |
| | | document.setValue("turn_button", fs.getString("turn_button")); |
| | | document.setValue("file_size", 0); |
| | | document.setValue("file_type", "虚拟文档"); |
| | | documents.addFieldSetEntity(document); |
| | | baseDao.add(documents); |
| | | baseDao.executeUpdate(" update " + tableInfo.getString("table_name") + " set " + archiveFlagField + "= '1' where uuid=?", new Object[]{file.getString("record_uuid")}); |
| | | } |
| | | } while (!DataTableEntity.isEmpty(files)); |
| | | } while (!DataTableEntity.isEmpty(files) && files.getRows() == pageSize); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw e; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param sql |
| | | * @param field_title 标题字段 |
| | | * @param filing_catalog 父级归档目录 |
| | |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param field_title 目录标题 |
| | | * @param tricode 编号 |
| | | * @param tricode_parent 父级编号 |