| | |
| | | import com.product.common.collect.ListUtils; |
| | | import com.product.common.collect.MapUtils; |
| | | import com.product.common.lang.DateUtils; |
| | | import com.product.core.config.Global; |
| | | import com.product.core.dao.BaseDao; |
| | | import com.product.core.entity.DataTableEntity; |
| | | import com.product.core.entity.FieldMetaEntity; |
| | |
| | | import com.product.core.spring.context.SpringMVCContextHolder; |
| | | import com.product.core.transfer.Transactional; |
| | | import com.product.file.config.CmnConst; |
| | | import com.product.file.config.DocumentCode; |
| | | import com.product.file.service.ide.IDocumentService; |
| | | import com.product.module.sys.entity.SystemUser; |
| | | import com.product.util.BaseUtil; |
| | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public String addDocument(FieldSetEntity fieldSetEntity) throws BaseException { |
| | | //文件附件表uuid |
| | | String uuIds = fieldSetEntity.getString(CmnConst.ATTACHMENTS_UUID); |
| | | String directory_uuid = fieldSetEntity.getString(CmnConst.DIRECTORY_UUID); |
| | | String[] uuid = uuIds.split(","); |
| | | public String addDocument(FieldSetEntity fse) throws BaseException { |
| | | //获取附件目录和附件uuid |
| | | String directory_uuid = fse.getString(CmnConst.DIRECTORY_UUID); |
| | | String fileUUIDs = fse.getString(CmnConst.ATTACHMENTS_UUID); |
| | | String[] fileUUIDArray = fileUUIDs.split(","); |
| | | //获取附件信息 |
| | | DataTableEntity attachments = baseDao.listTable(CmnConst.PRODUCT_SYS_ATTACHMENTS, BaseUtil.buildQuestionMarkFilter(CmnConst.UUID, uuid.length, true), uuid); |
| | | DataTableEntity attachments = baseDao.listTable(CmnConst.PRODUCT_SYS_ATTACHMENTS, BaseUtil.buildQuestionMarkFilter(CmnConst.UUID, fileUUIDArray, true)); |
| | | List<String> uuidList = ListUtils.newArrayList(); |
| | | List<String> fileNameList = ListUtils.newArrayList(); |
| | | //循环附件信息,生成文档信息 |
| | | for (int i = 0, length = attachments.getRows(); i < length; i++) { |
| | | FieldSetEntity fieldSet = new FieldSetEntity(); |
| | | fieldSet.setTableName(CmnConst.PRODUCT_OA_DOCUMENT); |
| | | FieldSetEntity fse = attachments.getFieldSetEntity(i); |
| | | //文件目录uuid |
| | | fieldSet.setValue(CmnConst.DIRECTORY_UUID, directory_uuid); |
| | | //文件大小 |
| | | fieldSet.setValue(CmnConst.FILE_SIZE, fse.getString(CmnConst.ATTACHMENT_SIZE)); |
| | | FieldSetEntity attachment = attachments.getFieldSetEntity(i); |
| | | //创建文档数据容器 |
| | | FieldSetEntity fseDocument = new FieldSetEntity(CmnConst.PRODUCT_OA_DOCUMENT); |
| | | fseDocument.setValue(CmnConst.ATTACHMENTS_UUID, attachment.getUUID()); |
| | | fseDocument.setValue(CmnConst.DIRECTORY_UUID, directory_uuid); |
| | | fseDocument.setValue(CmnConst.FILE_SIZE, attachment.getString(CmnConst.ATTACHMENT_SIZE)); |
| | | fseDocument.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id()); |
| | | fseDocument.setValue(CmnConst.CREATED_UTC_DATETIME, DateUtils.getDateTime()); |
| | | //文件名称 |
| | | String file_name = fse.getString(CmnConst.FILE_NAME); |
| | | fieldSet.setValue(CmnConst.FILE_NAME, file_name); |
| | | String file_name = attachment.getString(CmnConst.FILE_NAME); |
| | | fseDocument.setValue(CmnConst.FILE_NAME, file_name); |
| | | //文件类型 |
| | | String file_type = file_name.substring(file_name.lastIndexOf(".") + 1); |
| | | fieldSet.setValue(CmnConst.FILE_TYPE, file_type); |
| | | //附件uuid |
| | | fieldSet.setValue(CmnConst.ATTACHMENTS_UUID, fse.getString(CmnConst.UUID)); |
| | | fieldSet.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());// 创建人 |
| | | fieldSet.setValue(CmnConst.CREATED_UTC_DATETIME, DateUtils.getDateTime());// 创建时间 |
| | | String file_uuid = baseDao.add(fieldSet); |
| | | uuidList.add(file_uuid); |
| | | fseDocument.setValue(CmnConst.FILE_TYPE, file_type); |
| | | //保存数据 |
| | | String documentUUID = baseDao.add(fseDocument); |
| | | |
| | | //创建文档版本数据容器 |
| | | FieldSetEntity fseDocumentHistory = new FieldSetEntity(CmnConst.PRODUCT_OA_DOCUMENT_HISTORY); |
| | | BaseUtil.createCreatorAndCreationTime(fseDocumentHistory); |
| | | fseDocumentHistory.setValue("document_uuid", documentUUID); |
| | | fseDocumentHistory.setValue("attachment_uuid", attachment.getUUID()); |
| | | fseDocumentHistory.setValue("version_number", "v1"); |
| | | baseDao.add(fseDocumentHistory); |
| | | |
| | | uuidList.add(documentUUID); |
| | | fileNameList.add(file_name); |
| | | } |
| | | this.documentation(uuidList.toArray(), "新增", fileNameList.toArray(), null); |
| | |
| | | queryFilter = " AND " + queryFilter; |
| | | } |
| | | StringBuffer sql = new StringBuffer(); |
| | | sql.append(" SELECT ") |
| | | .append(" a.*,CONCAT(CONVERT(a.file_size / 1024, decimal(10,2)), 'KB') file_size_kb,b.show_name name") |
| | | // .append(" concat(c.attachment_domain,'/',c.attachment_container,'/',c.module_uuid,'/',c.attachment_title,?) path ") |
| | | .append(" FROM ") |
| | | .append(" (SELECT * FROM PRODUCT_OA_document WHERE directory_uuid = ? ") |
| | | .append(queryFilter) |
| | | .append(" ) a LEFT JOIN product_sys_staffs b ON a.created_by = b.user_id ") |
| | | .append(" LEFT JOIN product_sys_attachments c ON b.staff_avatar=c.uuid "); |
| | | String sostoken = Global.getSystemConfig("upload.key", ""); |
| | | DataTableEntity documentData = baseDao.listTable(sql.toString(), new String[]{directory_uuid}, fieldSetEntity.getInteger(CmnConst.PAGESIZE), fieldSetEntity.getInteger(CmnConst.CPAGE)); |
| | | sql.append("SELECT \n"); |
| | | sql.append(" A.*,B.show_name name, \n"); |
| | | sql.append(" CONCAT(CONVERT(a.file_size / 1024, decimal(10,2)), 'KB') file_size_kb, \n"); |
| | | sql.append(" CASE WHEN D.document_uuid IS NOT NULL THEN '1' ELSE '0' END AS is_collection \n"); |
| | | sql.append("FROM( \n"); |
| | | sql.append(" SELECT * FROM product_oa_document \n"); |
| | | sql.append(" WHERE directory_uuid = ? \n"); |
| | | sql.append(queryFilter); |
| | | sql.append(")A \n"); |
| | | sql.append("LEFT JOIN product_sys_staffs B ON B.user_id = A.created_by \n"); |
| | | sql.append("LEFT JOIN product_sys_attachments C ON C.uuid = B.staff_avatar \n"); |
| | | sql.append("LEFT JOIN product_oa_document_collection D ON D.document_uuid = A.uuid AND D.created_by = ?"); |
| | | DataTableEntity documentData = baseDao.listTable(sql.toString(), new String[]{directory_uuid, SpringMVCContextHolder.getCurrentUserId()}, |
| | | fieldSetEntity.getInteger(CmnConst.PAGESIZE), fieldSetEntity.getInteger(CmnConst.CPAGE)); |
| | | baseDao.listInternationDataTable(documentData, null); |
| | | return documentData; |
| | | } |
| | |
| | | sql.append(" and tricode_parent = ? "); |
| | | //加载文件路径 |
| | | DataTableEntity dataTableEntity = documentDirectoryService.getDirectoryStructure(fse); |
| | | object.put("PRODUCT_OA_directory_path", BaseUtil.dataTableEntityToJson(dataTableEntity)); |
| | | object.put("product_oa_directory_path", BaseUtil.dataTableEntityToJson(dataTableEntity)); |
| | | } |
| | | //sql.append(" GROUP BY tricode,tricode_parent,directory_name"); |
| | | DataTableEntity data = baseDao.listTable(sql.toString(), param.toArray()); |
| | | |
| | | object.put("PRODUCT_OA_directory_sub", BaseUtil.dataTableEntityToJson(data)); |
| | | object.put("product_oa_directory_sub", BaseUtil.dataTableEntityToJson(data)); |
| | | baseDao.listInternationDataTable(data, null); |
| | | |
| | | return object; |
| | |
| | | new String[]{fieldSetEntity.getString(CmnConst.DOCUMENT_UUID)}, fieldSetEntity.getInteger(CmnConst.PAGESIZE), fieldSetEntity.getInteger(CmnConst.CPAGE)); |
| | | } |
| | | |
| | | /** |
| | | * 文档收藏 |
| | | * @param fse |
| | | * @return |
| | | */ |
| | | public String documentCollection(FieldSetEntity fse) { |
| | | BaseUtil.createCreatorAndCreationTime(fse); |
| | | fse.setValue("document_collector", SpringMVCContextHolder.getCurrentUserId()); |
| | | return baseDao.add(fse); |
| | | } |
| | | |
| | | /** |
| | | * 文档取消收藏 |
| | | * @param documentUUID |
| | | * @return |
| | | */ |
| | | public boolean documentCancelCollection(String documentUUID) { |
| | | return baseDao.delete(CmnConst.PRODUCT_OA_DOCUMENT_COLLECTION, "document_uuid = ? AND document_collector = ?", new Object[] {documentUUID, SpringMVCContextHolder.getCurrentUserId()}); |
| | | } |
| | | |
| | | /** |
| | | * 查询文档历史版本 |
| | | * @param documentUUID |
| | | * @return |
| | | */ |
| | | public DataTableEntity findDocumentHistory(String documentUUID) { |
| | | StringBuilder sql = new StringBuilder(); |
| | | sql.append("SELECT A.*,B.file_name"); |
| | | sql.append("FROM product_oa_document_history A \n"); |
| | | sql.append("LEFT JOIN product_oa_document_history B ON B.uuid = A.document_uuid \n"); |
| | | sql.append("WHERE A.document_uuid = ?"); |
| | | sql.append("ORDER BY A.version_number"); |
| | | return baseDao.listTable(sql.toString(), new Object[] {documentUUID}); |
| | | } |
| | | |
| | | /** |
| | | * 文档最新版本保存 |
| | | * @param fse |
| | | * @return |
| | | */ |
| | | @Transactional |
| | | public boolean documentSaveNewVersion(FieldSetEntity fse) { |
| | | // 获取文档数据和最大编号 |
| | | StringBuilder sql = new StringBuilder(); |
| | | sql.append("SELECT A.*, IFNULL(B.max_version_number, 'v0')AS max_version_number \n"); |
| | | sql.append("FROM product_oa_document A \n"); |
| | | sql.append("LEFT JOIN ( \n"); |
| | | sql.append(" SELECT document_uuid, MAX(version_number) AS max_version_number \n"); |
| | | sql.append(" FROM product_oa_document_history B \n"); |
| | | sql.append(" WHERE document_uuid = ? \n"); |
| | | sql.append(" GROUP BY document_uuid \n"); |
| | | sql.append(") B ON B.document_uuid = A.uuid \n"); |
| | | sql.append("WHERE uuid = ? \n"); |
| | | FieldSetEntity fseDocument = baseDao.getFieldSetEntityBySQL(sql.toString(), new Object[] {fse.getString("document_uuid"),fse.getString("document_uuid")}, false); |
| | | if(fseDocument == null) { |
| | | throw new BaseException(DocumentCode.DOCUMENT_DATA_NO_EXIST.getValue(), DocumentCode.DOCUMENT_DATA_NO_EXIST.getText()); |
| | | } |
| | | fseDocument.setValue("attachments_uuid", fse.getString("attachment_uuid")); |
| | | baseDao.saveFieldSetEntity(fseDocument); |
| | | |
| | | fse.setValue("version_number", versionNUmberAddne(fseDocument.getString("max_version_number"))); |
| | | return baseDao.saveFieldSetEntity(fse); |
| | | } |
| | | |
| | | /** |
| | | * 文档版本+1 |
| | | * @param originNumber |
| | | * @return |
| | | */ |
| | | public String versionNUmberAddne(String originNumber) { |
| | | String numberStr = originNumber.substring(1); // 去掉前缀"v" |
| | | int number = Integer.parseInt(numberStr); // 将字符串转 |
| | | // 数字加一 |
| | | number += 1; |
| | | |
| | | // 重新构建字符串(这里我们假设前缀总是"v") |
| | | return "v" + number; |
| | | } |
| | | |
| | | @Override |
| | | public DataTableEntity getApplyDocument() throws BaseException { |
| | | public DataTableEntity getApplyDocument(FieldSetEntity fse) throws BaseException { |
| | | |
| | | DataTableEntity product_oa_document = baseDao.listTable("product_oa_document"); |
| | | DataTableEntity product_oa_document = new DataTableEntity(); |
| | | StringBuilder sb=new StringBuilder(); |
| | | sb.append(" select d.*,f.show_name "); |
| | | sb.append(" from product_oa_document d "); |
| | | sb.append(" left join product_sys_staffs f "); |
| | | sb.append(" on d.created_by=f.user_id "); |
| | | List<String> param=new ArrayList<>(); |
| | | if(!ObjectUtil.isNotEmpty(fse.getString("document_name"))){ |
| | | product_oa_document = baseDao.listTable(sb.toString(),param.toArray()); |
| | | |
| | | return product_oa_document; |
| | | }else { |
| | | String document_name = fse.getString("document_name"); |
| | | sb.append(" where d.file_name like '%"+document_name+"%'"); |
| | | product_oa_document = baseDao.listTable(sb.toString(),param.toArray()); |
| | | |
| | | |
| | | } |
| | | return product_oa_document; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public DataTableEntity getApplayFileSort() throws BaseException { |
| | | public DataTableEntity getApplyFileSort() throws BaseException { |
| | | StringBuilder sb=new StringBuilder(); |
| | | List<String> param=new ArrayList<>(); |
| | | sb.append(" SELECT b.* FROM ("); |
| | | sb.append(" SELECT t.uuid,t.file_name,s.show_name,t.created_utc_datetime,count(t.uuid) as applyCount"); |
| | | sb.append(" SELECT t.uuid,t.file_name,t.file_size,s.show_name,t.created_utc_datetime,count(t.uuid) as applyCount"); |
| | | sb.append(" FROM product_oa_document_borrow_sub b"); |
| | | sb.append(" JOIN product_oa_document t"); |
| | | sb.append(" on b.sub_uuid=t.uuid"); |
| | | sb.append(" JOIN product_sys_staffs s "); |
| | | sb.append(" on t.created_by=s.user_id"); |
| | | sb.append(" group by t.file_name,t.uuid,s.show_name,t.created_utc_datetime"); |
| | | sb.append(" group by t.file_name,t.uuid,s.show_name,t.created_utc_datetime,t.file_size"); |
| | | sb.append(" )b order by b.applyCount asc"); |
| | | DataTableEntity dataTableEntity = baseDao.listTable(sb.toString()); |
| | | DataTableEntity dataTableEntity = baseDao.listTable(sb.toString(),param.toArray()); |
| | | return dataTableEntity; |
| | | } |
| | | |
| | | @Override |
| | | public DataTableEntity getApplayUserSort() throws BaseException { |
| | | public DataTableEntity getApplyUserSort() throws BaseException { |
| | | StringBuilder sb=new StringBuilder(); |
| | | List<String> param=new ArrayList<>(); |
| | | sb.append(" SELECT a.borrower,a.show_name,a.applayCount,a.applayFileCount "); |
| | | sb.append(" FROM ("); |
| | | sb.append(" SELECT w.borrower,"); |
| | | sb.append(" (select count(borrower) from product_oa_document_borrow group by borrower ) as applayCount,"); |
| | | sb.append(" SELECT w.borrower,s.show_name,"); |
| | | sb.append(" count( borrower ) AS applayCount,"); |
| | | sb.append(" count(sub_uuid) as applayFileCount "); |
| | | sb.append(" FROM product_oa_document_borrow w "); |
| | | sb.append(" JOIN product_oa_document_borrow_sub b"); |
| | |
| | | sb.append(" GROUP BY w.borrower,s.show_name"); |
| | | sb.append(" )a"); |
| | | sb.append(" order by a.applayCount,a.applayFileCount asc"); |
| | | DataTableEntity dataTableEntity = baseDao.listTable(sb.toString()); |
| | | DataTableEntity dataTableEntity = baseDao.listTable(sb.toString(),param.toArray()); |
| | | return dataTableEntity; |
| | | } |
| | | |
| | | @Override |
| | | public FieldSetEntity getApplyInfo(FieldSetEntity fes) throws BaseException { |
| | | String uuid = fes.getString("uuid"); |
| | | FieldSetEntity product_oa_document_borrow = baseDao.getFieldSetEntity("product_oa_document_borrow", uuid, false); |
| | | return product_oa_document_borrow; |
| | | } |
| | | } |