zm
2024-09-04 d538a62999e202ce4c5a10429402a82d95494755
文件归档定时任务
已修改6个文件
301 ■■■■■ 文件已修改
src/main/java/com/product/file/config/CmnConst.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/file/config/DocumentCode.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/file/controller/DocumentDirectoryController.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/file/service/DocumentDirectoryService.java 242 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/file/service/DocumentService.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/file/service/ide/IDocumentDirectoryService.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/file/config/CmnConst.java
@@ -53,6 +53,11 @@
    public static final String ATTACHMENT_URL = "attachment_url";
    public static final String ENCRPT_SIGN = "encrypt_sign";
    public static final String ATTACHMENT_TYPE_UUID = "attachment_type_uuid";
    public static final String PRODUCT_SYS_FUNCTIONS = "product_sys_functions";
    public static final String PRODUCT_SYS_DATAMODEL_FIELD = "product_sys_datamodel_field";
    public static final String PRODUCT_SYS_DATAMODEL_TABLE = "product_sys_datamodel_table";
        public static final String PRODUCT_AO_FILING_CONFIG = "product_oa_filing_config";
    public static final String OPT_FLAT = "opt_flat";
    public static final String UPLOAD_SIGN = "upload_sign";
src/main/java/com/product/file/config/DocumentCode.java
@@ -41,6 +41,7 @@
//    该文件未进行授权,如需查看请借阅
    DOCUMENT_NO_AUTHORIZATION("该文件未进行授权,如需查看请借阅", ModuleEnum.FILE.getValue() + "017"),
    CRATED_TIMED_TASK_FAIL("创建数据同步定时任务失败", ModuleEnum.FILE.getValue() + "018"),
    ;
src/main/java/com/product/file/controller/DocumentDirectoryController.java
@@ -336,4 +336,32 @@
                    DocumentCode.DOCUMENT_CATALOG_GET_FAIL.getText());
        }
    }
    /**
     * 保存文档归档配置
     * @param request
     * @return
     */
    @RequestMapping(value = "/save-file-config/{version}", method = RequestMethod.POST)
    @ApiVersion(1)
    public String saveFileConfig(HttpServletRequest request) {
        try {
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request);
            IDocumentDirectoryService service = (IDocumentDirectoryService) getProxyInstance(documentDirectoryService);
            if(service.saveFileConfig(fse)) {
                return OK();
            }
            return error(DocumentCode.DOCUMENT_CATALOG_SAVE_FAIL.getValue(),
                    DocumentCode.DOCUMENT_CATALOG_SAVE_FAIL.getText());
        } catch (BaseException e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            return this.error(e);
        } catch (Exception e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            return error(DocumentCode.DOCUMENT_CATALOG_SAVE_FAIL.getValue(),
                    DocumentCode.DOCUMENT_CATALOG_SAVE_FAIL.getText());
        }
    }
}
src/main/java/com/product/file/service/DocumentDirectoryService.java
@@ -17,11 +17,14 @@
import com.product.file.config.DocumentCode;
import com.product.file.service.ide.IDocumentDirectoryService;
import com.product.module.sys.entity.SystemUser;
import com.product.quartz.service.impl.SysJobService;
import com.product.util.BaseUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@@ -40,7 +43,8 @@
    public BaseDao baseDao;
    @Autowired
    public DocumentDirectoryService documentDirectoryService;
    @Autowired
    SysJobService sysJobService;
    /**
     * 单位文件夹树
     *
@@ -100,6 +104,238 @@
        fse.setValue(CmnConst.DIRECTORY_TIER, tricode.split("-").length);
        return baseDao.saveFieldSetEntity(fse);
    }
    @Transactional
    @Override
    public boolean saveFileConfig(FieldSetEntity fse) {
        //获取功能表名
        FieldSetEntity functionUuid = baseDao.getFieldSet(CmnConst.PRODUCT_SYS_FUNCTIONS, fse.getString("function_uuid"), false);
        DataTableEntity field = baseDao.listTable(CmnConst.PRODUCT_SYS_DATAMODEL_FIELD, "table_uuid=? and field_name=?", new String[]{functionUuid.getString("table_uuid"), "archive_flag"});
        if (field.getRows()==0){
            FieldSetEntity fs = new FieldSetEntity();
            fs.setTableName(CmnConst.PRODUCT_SYS_DATAMODEL_FIELD);
            fs.setValue("table_uuid",functionUuid.getString("table_uuid"));
            fs.setValue("field_name","archive_flag");
            fs.setValue("field_type","int");
            fs.setValue("field_show_name","归档标识");
            fs.setValue("field_description","归档标识");
            fs.setValue("field_length",10);
            fs.setValue("field_unit",0);
            fs.setValue("is_required",0);
            fs.setValue("is_unique",0);
            fs.setValue("is_filter",0);
            fs.setValue("field_sequence",0);
            fs.setValue("created_by",SpringMVCContextHolder.getCurrentUser().getUser_id());
            fs.setValue("created_utc_datetime",new Date());
            baseDao.saveFieldSetEntity(fs);
            FieldSetEntity table = baseDao.getFieldSet(CmnConst.PRODUCT_SYS_DATAMODEL_TABLE, functionUuid.getString("table_uuid"), false);
            baseDao.executeUpdate("ALTER TABLE "+table.getString("table_name")+" ADD COLUMN archive_flag INT(4) COMMENT '归档标识';");
        }
        FieldSetEntity timedTask = baseDao.getFieldSetByFilter("product_sys_timed_task", "job_name=? and invoke_target like concat('%',?,'%') ", new String[]{fse.getString("filing_name") + "定时", fse.getString("uuid")}, false);
        String timeTaskUuid=null;
        if (!FieldSetEntity.isEmpty(timedTask)){
            timeTaskUuid=timedTask.getUUID();
        }
        boolean re = baseDao.saveFieldSetEntity(fse);
        createdTimeTask(fse.getString("filing_name"),fse.getString("cron"),fse.getUUID(),timeTaskUuid);
        return re;
    }
    private FieldSetEntity createdTimeTask(String target_table, String execute_time, String task_uuid, String timeTaskUuid) throws BaseException {
        //
        FieldSetEntity fse = new FieldSetEntity();
        try {
            fse.setTableName("product_sys_timed_task");
            fse.setValue("uuid", timeTaskUuid);
            fse.setValue("job_name", target_table + "定时");//任务名称
            fse.setValue("job_group", "system");//分组
            fse.setValue("invoke_target", "documentDirectoryService.fileTime('" + task_uuid + "')");//调用目标字符串
            fse.setValue("cron_expression", execute_time);//cron表达式
            fse.setValue("misfire_policy", "3");//错误执行策略  只执行一次
            fse.setValue("concurrent", 0);//不允许并发执行
            fse.setValue("remark", target_table + "定时");
            fse.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
            fse.setValue("created_utc_datetime", new Date());
            fse.setValue("status", 1);
            fse.setValue("is_conceal", 1);
            if (!com.product.common.lang.StringUtils.isEmpty(timeTaskUuid)) {
                sysJobService.updateJob(fse);
            } else {
                sysJobService.insertJob(fse);
            }
            return fse;
        } catch (Exception e) {
            e.printStackTrace();
            throw new BaseException(DocumentCode.CRATED_TIMED_TASK_FAIL);
        }
//
    }
    /**
     * 归档定时任务
     */
    @Transactional
    public void fileTime(String uuid){
        FieldSetEntity fs = baseDao.getFieldSet(CmnConst.PRODUCT_AO_FILING_CONFIG,uuid,false);
        FieldSetEntity functionUuid = baseDao.getFieldSet(CmnConst.PRODUCT_SYS_FUNCTIONS, fs.getString("function_uuid"), false);
        DataTableEntity fieldTable = baseDao.listTable(CmnConst.PRODUCT_SYS_DATAMODEL_FIELD, "table_uuid=? and (field_type='file' or field_name='flow_flag')", new String[]{functionUuid.getString("table_uuid")}," field_type ");
        FieldSetEntity table = baseDao.getFieldSet(CmnConst.PRODUCT_SYS_DATAMODEL_TABLE, functionUuid.getString("table_uuid"), false);
        StringBuilder sb = new StringBuilder();
        sb.append("select  concat(");
        String flow_flag="";
            for (int i = 0; i <fieldTable.getRows() ; i++) {
                if (i==0&&!fieldTable.getString(i, "field_name").equals("flow_flag")){
                    sb.append("a.").append(fieldTable.getString(i, "field_name"));
                }else if (i!=0&&!fieldTable.getString(i, "field_name").equals("flow_flag")){
                    sb.append(",',',").append("a.").append(fieldTable.getString(i, "field_name"));
                }else if (fieldTable.getString(i,"field_name").equals("flow_flag")){
                    flow_flag=" and a.flow_flag=2";
                }
            }
        sb.append(") file,a.uuid,b.uuid directory_uuid,");
        sb.append("a.").append(fs.getString("field_title"));
        sb.append(",a.").append(fs.getString("field_send_time")).append(" send_time");
        sb.append(",c.user_name ");
        sb.append(" from ");
        sb.append(table.getString("table_name")).append(" a ");
        sb.append(" LEFT JOIN (SELECT max(uuid) uuid,directory_name FROM product_oa_directory where tricode_parent='").append(fs.getString("filing_catalog")).append("' GROUP BY directory_name)  b ");
        sb.append("on a.").append(fs.getString("field_title")).append("=b.directory_name ");
        sb.append(" LEFT JOIN  product_sys_users c on a.").append(fs.getString("field_send_user")).append("=c.user_id");
        sb.append(" where (a.archive_flag!=1 or a.archive_flag is null) ");
        sb.append(flow_flag);
        sb.append(" ORDER BY a.id LIMIT 1000 ");
        //获取流程里面的附件sql
        StringBuffer nodeSal = new StringBuffer();
        nodeSal.append(" select  a.uuid,b.flow_attachment  from ");
        nodeSal.append(table.getString("table_name")).append(" a ");
        nodeSal.append(" LEFT JOIN product_sys_flow_detail b on a.uuid=b.record_uuid ");
        nodeSal.append(" where (a.archive_flag!=1 or a.archive_flag is null) and b.flow_attachment is not null");
        nodeSal.append(flow_flag);
        nodeSal.append(" ORDER BY a.id LIMIT 1000 ");
        fieldLimit(sb.toString(),nodeSal.toString(),fs.getString("field_title"),fs.getString("filing_catalog"),fs.getString("turn_button"),table.getString("table_name"));
    }
    /**
     *
     * @param sql
     * @param field_title 标题字段
     * @param filing_catalog 父级归档目录
     */
    private void  fieldLimit(String sql,String nodeSal,String field_title,String filing_catalog,String turn_button,String table){
        //获取父类文档信息
        FieldSetEntity parentDirectory = baseDao.getFieldSetByFilter(CmnConst.PRODUCT_OA_DIRECTORY, "tricode=?", new String[]{filing_catalog}, false);
        DataTableEntity fieldDt = baseDao.listTable(sql, new String[]{});
        //获取流程附件并加入到file里
        DataTableEntity nodeDt = baseDao.listTable(nodeSal, new String[]{});
        for (int i = 0; i <nodeDt.getRows() ; i++) {
            FieldSetEntity fieldfs = fieldDt.getFieldSetEntity(nodeDt.getString(i, "uuid")).get(0);
            if (FieldSetEntity.isEmpty(fieldfs)){
                if (StringUtils.isEmpty(fieldfs.getString("file"))){
                    fieldfs.setValue("file",nodeDt.getString(i,"flow_attachment"));
                }else {
                    fieldfs.setValue("file",fieldfs.getString("file")+","+nodeDt.getString(i,"flow_attachment"));
                }
            }
        }
        ArrayList<String> fileList = new ArrayList<>();
        for (int i = 0; i <fieldDt.getRows() ; i++) {
            String file = fieldDt.getString(i, "file");
            if (!StringUtils.isEmpty(file)){
                for (int j = 0; j < file.split(",").length; j++) {
                    fileList.add(file.split(",")[j]);
                }
            }
        }
        DataTableEntity attachments = baseDao.listTable(CmnConst.PRODUCT_SYS_ATTACHMENTS, BaseUtil.buildQuestionMarkFilter("uuid", fileList.size(), true), fileList.toArray(new String[0]));
        if (fieldDt.getRows()>0) {
            for (int i = 0; i < fieldDt.getRows(); i++) {
                FieldSetEntity fs = fieldDt.getFieldSetEntity(i);
                String directoryUUID=null;
                if (StringUtils.isEmpty(fs.getString("directory_uuid"))){
                        //根据上级目录获取目录编号
                        String tricode = CodeUtil.getNewCodeByTemp(CmnConst.PRODUCT_OA_DIRECTORY, CmnConst.TRICODE, filing_catalog);
                        //获取目录名称
                        String title = fs.getString(field_title);
                        directoryUUID = addDirectory(title, tricode, filing_catalog, parentDirectory.getInteger("directory_tier") + 1);
                }else {
                    directoryUUID=fs.getString("directory_uuid");
                }
                String file = fs.getString("file");
                if (!StringUtils.isEmpty(file)){
                    for (int j = 0; j <file.split(",").length ; j++) {
                        //创建文件
                        String f = file.split(",")[j];
                        if (StringUtils.isEmpty(file.split(",")[j])||DataTableEntity.isEmpty(attachments)){
                            continue;
                        }
                        FieldSetEntity attachmentsFs = attachments.getFieldSetEntity(f).get(0);
                        FieldSetEntity document = new FieldSetEntity();
                        document.setTableName(CmnConst.PRODUCT_OA_DOCUMENT);
                        document.setValue("directory_uuid",directoryUUID);
                        document.setValue("file_name",attachmentsFs.getString("file_name"));
                        document.setValue("attachments_uuid",f);
                        String[] type = f.split("\\.");
                        document.setValue("file_type",type[type.length-1]);
                        document.setValue("created_by", 1);
                        document.setValue("created_utc_datetime", new Date());
                        document.setValue("file_size", attachmentsFs.getString("attachment_size"));
                        baseDao.saveFieldSetEntity(document);
                    }
                }
                FieldSetEntity document = new FieldSetEntity();
                document.setTableName(CmnConst.PRODUCT_OA_DOCUMENT);
                document.setValue("directory_uuid",directoryUUID);
                document.setValue("file_name",fs.getString(field_title)+" "+fs.getString("user_name")+" "+fs.getString("send_time"));
                document.setValue("created_by", 1);
                document.setValue("created_utc_datetime", new Date());
                document.setValue("turn_button", turn_button);
                document.setValue("file_size", 0);
                document.setValue("file_type","虚拟文档");
                baseDao.saveFieldSetEntity(document);
                baseDao.executeUpdate("UPDATE "+table+" set archive_flag =1 where uuid=?",new String[]{fs.getUUID()});
            }
            fieldLimit(sql,nodeSal,field_title,filing_catalog,turn_button,table);
        }
    }
    /**
     *
     * @param field_title 目录标题
     * @param tricode  编号
     * @param tricode_parent 父级编号
     * @param directory_tier 目录层级
     */
    private String addDirectory(String field_title,String tricode,String tricode_parent,Integer directory_tier){
        //新建目录
        FieldSetEntity fsDirectory = new FieldSetEntity();
        fsDirectory.setTableName(CmnConst.PRODUCT_OA_DIRECTORY);
        fsDirectory.setValue("created_by", 1);
        fsDirectory.setValue("created_utc_datetime", new Date());
        fsDirectory.setValue("org_level_uuid", "00000000-0000-0000-0000-000000000000");
        fsDirectory.setValue("directory_name", field_title);
        fsDirectory.setValue("directory_tier", directory_tier);
        fsDirectory.setValue("directory_type", 1);
        fsDirectory.setValue("tricode", tricode);
        fsDirectory.setValue("tricode_parent", tricode_parent);
        baseDao.saveFieldSetEntity(fsDirectory);
        return fsDirectory.getUUID();
    }
    @Override
@@ -199,7 +435,9 @@
        JSONArray menus = this.encapsulationTree(data);
        // 获取当前公司
        JSONObject orgLevelInfo = new JSONObject();
        orgLevelInfo.put("directory_name", user.getOrg_level_name());
        String orgLevelName = user.getOrg_level_name();
        orgLevelInfo.put("directory_name", orgLevelName);
        orgLevelInfo.put("tricode", "");
        orgLevelInfo.put("org_level_uuid", user.getOrg_level_uuid());
        orgLevelInfo.put("children", menus);
src/main/java/com/product/file/service/DocumentService.java
@@ -337,13 +337,14 @@
            String directory_uuid = fieldSetEntity.getString(CmnConst.DIRECTORY_UUID);
            //String key = "%,140,%";
            DataTableEntity dataTableEntity = new DataTableEntity();
            FieldSetEntity org = baseDao.getFieldSetByFilter(CmnConst.PRODUCT_OA_DIRECTORY_RIGHTS, "directory_uuid=?", new String[]{directory_uuid}, false);
            FieldSetEntity org = recursionRole(directory_uuid);
            if (verifyOrgExist(org.getString("storage_uuid"))) {
                StringBuffer sql = new StringBuffer();
                sql.append(" SELECT  substring_index(substring_index(a.rigths,',',b.help_topic_id+1),',',-1) fun FROM  PRODUCT_OA_directory_rights a ")
                        .append(" INNER join   mysql.help_topic b on b.help_topic_id < (length(a.rigths) - length(replace(a.rigths,',',''))+1) ")
                        .append(" WHERE a.directory_uuid = ? ");
                dataTableEntity = baseDao.listTable(sql.toString(), new String[]{directory_uuid});
                dataTableEntity = baseDao.listTable(sql.toString(), new String[]{org.getString("directory_uuid")});
            }
            StringBuffer button = new StringBuffer();
            if (!BaseUtil.dataTableIsEmpty(dataTableEntity)) {
@@ -393,6 +394,21 @@
        return fse;
    }
    /**
     * 递归获取权限如果当前文档未配置权限就去递归查询父级权限
     * @param directory_uuid
     * @return
     */
    private FieldSetEntity recursionRole(String directory_uuid){
        FieldSetEntity org = baseDao.getFieldSetByFilter(CmnConst.PRODUCT_OA_DIRECTORY_RIGHTS, "directory_uuid=?", new String[]{directory_uuid}, false);
        if (FieldSetEntity.isEmpty(org)){
            FieldSetEntity directoryFs = baseDao.getFieldSet(CmnConst.PRODUCT_OA_DIRECTORY, directory_uuid,false);
            FieldSetEntity parentFs = baseDao.getFieldSetByFilter(CmnConst.PRODUCT_OA_DIRECTORY, "tricode=?",new String[]{directoryFs.getString("tricode_parent")},false);
            org=recursionRole(parentFs.getUUID());
        }
        return org;
    }
    @Override
    public JSONObject popBoxGetFileDirectory(FieldSetEntity fse) throws BaseException {
        //文件目录uuid
src/main/java/com/product/file/service/ide/IDocumentDirectoryService.java
@@ -23,8 +23,9 @@
     * @return
     */
    boolean saveDocumentDireactory(FieldSetEntity fse);
  /**
    boolean saveFileConfig(FieldSetEntity fse);
    /**
   * 删除文档目录
   * @param
   * @return