18756
2024-08-23 8e8b26ea3b7306fca701fac934e26300b9043fd1
src/main/java/com/product/file/service/DocumentService.java
@@ -1,5 +1,7 @@
package com.product.file.service;
import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.product.common.collect.ListUtils;
import com.product.common.collect.MapUtils;
@@ -467,4 +469,99 @@
        return baseDao.listTable("SELECT CONCAT(b.show_name, a.state) log,a.created_utc_datetime FROM PRODUCT_OA_document_log a LEFT JOIN product_sys_staffs b on a.created_by = b.user_id WHERE document_uuid = ? ORDER BY a.created_utc_datetime DESC",
                new String[]{fieldSetEntity.getString(CmnConst.DOCUMENT_UUID)}, fieldSetEntity.getInteger(CmnConst.PAGESIZE), fieldSetEntity.getInteger(CmnConst.CPAGE));
    }
    @Override
    public DataTableEntity getApplyDocument(FieldSetEntity fse) throws BaseException {
        String document_name = fse.getString("document_name");
        String filter="file_name like '%"+document_name+"'%";
        DataTableEntity product_oa_document = baseDao.listTable("product_oa_document",filter);
        return product_oa_document;
    }
    @Override
    public void addOrUpdateApplyDocument(FieldSetEntity fse) throws BaseException {
        String[] attachment = new String[0];
        if(ObjectUtil.isNotEmpty(fse.getString("uuid"))){
            UUID uuid = UUID.randomUUID();
            fse.setValue("uuid",uuid);
            baseDao.add(fse);
            if(ObjectUtil.isNotEmpty(fse.getString("attachment_uuid"))){
                String attachment_uuid = fse.getString("attachment_uuid");
                attachment= attachment_uuid.split(",");
            }
            for (int i = 0; i < attachment.length; i++) {
                FieldSetEntity fieldSetEntity = new FieldSetEntity();
                fieldSetEntity.setTableName("product_oa_document_borrow_sub");
                fieldSetEntity.setValue("borrow_uuid",uuid);
                fieldSetEntity.setValue("sub_uuid",attachment[i]);
            }
        }else {
            String uuid = fse.getString("uuid");
            String filter="borrow_uuid='"+uuid+"'";
            //删除原来附件信息
            baseDao.delete("product_oa_document_borrow_sub",filter,new Object[]{});
            baseDao.update(fse);
            if(ObjectUtil.isNotEmpty(fse.getString("attachment_uuid"))){
                String attachment_uuid = fse.getString("attachment_uuid");
                attachment= attachment_uuid.split(",");
            }
            //重新跟新附件信息
            for (int i = 0; i < attachment.length; i++) {
                FieldSetEntity fieldSetEntity = new FieldSetEntity();
                fieldSetEntity.setTableName("product_oa_document_borrow_sub");
                fieldSetEntity.setValue("borrow_uuid",uuid);
                fieldSetEntity.setValue("sub_uuid",attachment[i]);
                baseDao.add(fieldSetEntity);
            }
        }
    }
    @Override
    public DataTableEntity getApplayFileSort() throws BaseException {
        StringBuilder sb=new StringBuilder();
        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(" 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(" )b order by  b.applyCount asc");
        DataTableEntity dataTableEntity = baseDao.listTable(sb.toString());
        return dataTableEntity;
    }
    @Override
    public DataTableEntity getApplayUserSort() throws BaseException {
        StringBuilder sb=new StringBuilder();
        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(" count(sub_uuid) as applayFileCount ");
        sb.append(" FROM product_oa_document_borrow  w ");
        sb.append(" JOIN product_oa_document_borrow_sub b");
        sb.append(" on b.borrow_uuid=w.uuid");
        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 w.borrower=s.user_id");
        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());
        return dataTableEntity;
    }
}