杜洪波
2024-08-22 305dc0c57b588f15dd53e5c6c01c3210292a3e9d
src/main/java/com/product/file/service/DocumentDirectoryService.java
@@ -40,11 +40,26 @@
  @Autowired
  public DocumentDirectoryService documentDirectoryService;
   /**
    *    单位文件夹树
    * @return
    */
   public DataTableEntity allDirectoryTree() {
      DataTableEntity dtTree = baseDao.listTable(CmnConst.PRODUCT_OA_DIRECTORY, "directory_type = 1");
      if (!BaseUtil.dataTableIsEmpty(dtTree)) {
         return BaseUtil.dataTableToTreeTable(dtTree, CmnConst.TRICODE, CmnConst.TRICODE_PARENT, null);
      }
      return dtTree;
   }
  @Override
  @Transactional
  public String addDocumentDirectory(FieldSetEntity fieldSetEntity) throws BaseException {
    String triCode = CodeUtil.getNewCodeByTemp(CmnConst.product_oa_DIRECTORY,CmnConst.TRICODE,!StringUtils.isEmpty(fieldSetEntity.getString(CmnConst.TRICODE_PARENT))?fieldSetEntity.getString(CmnConst.TRICODE_PARENT):"");
      String triCode = CodeUtil.getNewCodeByTemp(CmnConst.PRODUCT_OA_DIRECTORY, CmnConst.TRICODE,
            !StringUtils.isEmpty(fieldSetEntity.getString(CmnConst.TRICODE_PARENT))
                  ? fieldSetEntity.getString(CmnConst.TRICODE_PARENT)
                  : "");
    fieldSetEntity.setValue(CmnConst.TRICODE,triCode);
    String[] codes = triCode.split("-");
    String org_level_uuid = SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid();
@@ -59,15 +74,17 @@
  @Transactional
  public boolean upDocumentDirectory(FieldSetEntity fieldSetEntity) throws BaseException {
    String uuid = fieldSetEntity.getString(CmnConst.UUID);
    FieldSetEntity fieldSet = baseDao.getFieldSetEntity(CmnConst.product_oa_DIRECTORY, uuid, false);
      FieldSetEntity fieldSet = baseDao.getFieldSetEntity(CmnConst.PRODUCT_OA_DIRECTORY, uuid, false);
    String tricode_parent1 = fieldSetEntity.getString(CmnConst.TRICODE_PARENT);
    String tricode_parent2 = fieldSet.getString(CmnConst.TRICODE_PARENT);
    boolean flag;
      //上级目录tricode如果不相等
    if(!StringUtils.isEmpty(tricode_parent1) || !StringUtils.isEmpty(tricode_parent2)) {
      if (!StringUtils.isEmpty(tricode_parent1) && !StringUtils.isEmpty(tricode_parent2) && !tricode_parent1.equals(tricode_parent2)) {
         if (!StringUtils.isEmpty(tricode_parent1) && !StringUtils.isEmpty(tricode_parent2)
               && !tricode_parent1.equals(tricode_parent2)) {
        flag = true;
      }else if(!StringUtils.isEmpty(tricode_parent1) && !StringUtils.isEmpty(tricode_parent2) && tricode_parent1.equals(tricode_parent2)){
         } else if (!StringUtils.isEmpty(tricode_parent1) && !StringUtils.isEmpty(tricode_parent2)
               && tricode_parent1.equals(tricode_parent2)) {
        flag = false;
      }else if(!StringUtils.isEmpty(tricode_parent1) && StringUtils.isEmpty(tricode_parent2)){
        tricode_parent2 = "";
@@ -84,21 +101,13 @@
    if(flag){
      StringBuffer sql=new StringBuffer()   ;
      sql.append(" update product_oa_directory set tricode=replace(");
         sql.append(" update PRODUCT_OA_directory set tricode=replace(");
      sql.append(" tricode,concat(?,'-'),concat(?,'-')),");
      sql.append(" tricode_parent=(case when tricode_parent=? then replace(tricode_parent,?,?) else ");
      sql.append(" replace (tricode_parent,concat(?,'-'),concat(?,'-')) end )");
      sql.append("  where  tricode like ?");
      baseDao.executeUpdate(sql.toString(), new String[]{
          tricode_parent1,
          tricode_parent2,
          tricode_parent1,
          tricode_parent1,
          tricode_parent2,
          tricode_parent1,
          tricode_parent2,
          tricode_parent1+"-%",
      });
         baseDao.executeUpdate(sql.toString(), new String[] { tricode_parent1, tricode_parent2, tricode_parent1,
               tricode_parent1, tricode_parent2, tricode_parent1, tricode_parent2, tricode_parent1 + "-%", });
    }
    fieldSetEntity.setValue(CmnConst.UPDATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());// 获取登录帐号
@@ -115,18 +124,23 @@
    if("2".equals(directory_type)){
      filter = " AND " +  "created_by = " + SpringMVCContextHolder.getCurrentUserId();
    }
    DataTableEntity dataTableEntity = baseDao.listTable("SELECT * FROM product_oa_directory WHERE directory_type = ? AND tricode_parent = (SELECT tricode FROM product_oa_directory where uuid = ?)" + filter,
      DataTableEntity dataTableEntity = baseDao.listTable(
            "SELECT * FROM PRODUCT_OA_directory WHERE directory_type = ? AND tricode_parent = (SELECT tricode FROM PRODUCT_OA_directory where uuid = ?)"
                  + filter,
    new String[]{directory_type,uuid});
    if(BaseUtil.dataTableIsEmpty(dataTableEntity)){
                baseDao.delete(CmnConst.product_oa_DOCUMENT, "directory_uuid = ?", new String[]{uuid});
        return baseDao.delete(CmnConst.product_oa_DIRECTORY, new String[]{uuid});
         baseDao.delete(CmnConst.PRODUCT_OA_DOCUMENT, "directory_uuid = ?", new String[] { uuid });
         return baseDao.delete(CmnConst.PRODUCT_OA_DIRECTORY, new String[] { uuid });
    }else {
      throw new BaseException(DocumentCode.DOCUMENT_CATALOG_DELETE_FAIL.getValue(), DocumentCode.DOCUMENT_CATALOG_DELETE_FAIL.getText(), this.getClass(),"public boolean delDocumentDirectory(FieldSetEntity fieldSetEntity) throws BaseException");
         throw new BaseException(DocumentCode.DOCUMENT_CATALOG_DELETE_FAIL.getValue(),
               DocumentCode.DOCUMENT_CATALOG_DELETE_FAIL.getText(), this.getClass(),
               "public boolean delDocumentDirectory(FieldSetEntity fieldSetEntity) throws BaseException");
    }
  }
  /**
   * 获取当前文件路径
    *
   * @param fieldSetEntity
   * @return
   * @throws BaseException
@@ -134,7 +148,7 @@
  @Override
  public DataTableEntity getDirectoryStructure(FieldSetEntity fieldSetEntity) throws BaseException {
    String uuid = fieldSetEntity.getString(CmnConst.DIRECTORY_UUID);
    fieldSetEntity = baseDao.getFieldSetEntity(CmnConst.product_oa_DIRECTORY, uuid, false);
      fieldSetEntity = baseDao.getFieldSetEntity(CmnConst.PRODUCT_OA_DIRECTORY, uuid, false);
    String triCode = fieldSetEntity.getString(CmnConst.TRICODE);
    String type = fieldSetEntity.getString(CmnConst.DIRECTORY_TYPE);
    List<String> codeList = ListUtils.newArrayList();
@@ -153,16 +167,21 @@
  //单位文件夹
  if("1".equals(type)){
    codeList.add(0,user.getOrg_level_uuid());
    dataTableEntity = baseDao.listTable(CmnConst.product_oa_DIRECTORY,"directory_type = 1 AND org_level_uuid = ? AND "+BaseUtil.buildQuestionMarkFilter(CmnConst.TRICODE,codeList.size()-1,true),codeList.toArray(),"tricode");
         dataTableEntity = baseDao.listTable(CmnConst.PRODUCT_OA_DIRECTORY,
               "directory_type = 1 AND org_level_uuid = ? AND "
                     + BaseUtil.buildQuestionMarkFilter(CmnConst.TRICODE, codeList.size() - 1, true),
               codeList.toArray(), "tricode");
   //个人文件夹
  }else {
    codeList.add(0,String.valueOf(user.getUser_id()));
    dataTableEntity = baseDao.listTable(CmnConst.product_oa_DIRECTORY,"directory_type = 2 AND created_by = ? AND "+BaseUtil.buildQuestionMarkFilter(CmnConst.TRICODE,codeList.size()-1,true),codeList.toArray(),"tricode");
         dataTableEntity = baseDao.listTable(CmnConst.PRODUCT_OA_DIRECTORY,
               "directory_type = 2 AND created_by = ? AND "
                     + BaseUtil.buildQuestionMarkFilter(CmnConst.TRICODE, codeList.size() - 1, true),
               codeList.toArray(), "tricode");
  }
    baseDao.listInternationDataTable(dataTableEntity, null);
    return dataTableEntity;
  }
  @Override
  public JSONArray treeListAll(FieldSetEntity fieldSetEntity) throws BaseException {
@@ -172,21 +191,22 @@
    DataTableEntity data;
    SystemUser user = SpringMVCContextHolder.getCurrentUser();
    StringBuffer sql = new StringBuffer();
    sql.append("SELECT a.*,ifnull(b.number,0) number FROM product_oa_directory a LEFT JOIN ");
    sql.append("(SELECT COUNT(*) number,directory_uuid FROM product_oa_document GROUP BY directory_uuid)  b on a.uuid=b.directory_uuid ");
      sql.append("SELECT a.*,ifnull(b.number,0) number FROM PRODUCT_OA_directory a LEFT JOIN ");
      sql.append(
            "(SELECT COUNT(*) number,directory_uuid FROM PRODUCT_OA_document GROUP BY directory_uuid)  b on a.uuid=b.directory_uuid ");
    if("1".equals(directory_type)){
      String org_level_uuid = user.getOrg_level_uuid();
      sql.append("where directory_type = 1 AND org_level_uuid = ? ");
      data = baseDao.listTable(sql.toString(), new Object[]{org_level_uuid});
//      data = baseDao.listTable(CmnConst.product_oa_DIRECTORY, " directory_type = 1 AND org_level_uuid = ?", new String[]{org_level_uuid}, "tricode");
//      data = baseDao.listTable(CmnConst.PRODUCT_OA_DIRECTORY, " directory_type = 1 AND org_level_uuid = ?", new String[]{org_level_uuid}, "tricode");
    //个人文件夹
    }else {
      Integer userId = user.getUser_id();
      sql.append("where directory_type = 2 AND created_by = ? ");
      data = baseDao.listTable(sql.toString(), new Object[]{userId});
//      data = baseDao.listTable(CmnConst.product_oa_DIRECTORY, " directory_type = 2 AND created_by = ?", new Object[]{userId}, "tricode");
//      data = baseDao.listTable(CmnConst.PRODUCT_OA_DIRECTORY, " directory_type = 2 AND created_by = ?", new Object[]{userId}, "tricode");
    }
    baseDao.listInternationDataTable(data, null);
    JSONArray menus = this.encapsulationTree(data);
@@ -200,8 +220,10 @@
    array.add(orgLevelInfo);
    return array;
  }
  /**
   * 封装树方法
    *
   * @param
   * @return
   * @throws BaseException
@@ -238,12 +260,12 @@
  @Override
  public FieldSetEntity documentDirectoryInfo(FieldSetEntity fieldSetEntity) throws BaseException {
    String uuid = fieldSetEntity.getString(CmnConst.UUID);
    return baseDao.getFieldSetEntity(CmnConst.product_oa_DIRECTORY, uuid, true);
      return baseDao.getFieldSetEntity(CmnConst.PRODUCT_OA_DIRECTORY, uuid, true);
  }
  /**
   * 移动到目录列表(根据当前用户过滤展示目录列表)
   * 获取用户有新增(上传)权限的列表
    * 移动到目录列表(根据当前用户过滤展示目录列表) 获取用户有新增(上传)权限的列表
    *
   * @param
   * @return
   * @throws BaseException
@@ -257,14 +279,13 @@
    //1为单位文件夹
    if("1".equals(type)) {
      param.append("%").append(userId).append("%");
      sql.append("SELECT a.* FROM "+CmnConst.product_oa_DIRECTORY+" a LEFT JOIN ")
              .append(" product_oa_directory_rights b ON a.uuid = b.directory_uuid ")
         sql.append("SELECT a.* FROM " + CmnConst.PRODUCT_OA_DIRECTORY + " a LEFT JOIN ")
               .append(" PRODUCT_OA_directory_rights b ON a.uuid = b.directory_uuid ")
              .append(" LEFT JOIN product_sys_organizational_structure_storage c on b.storage_uuid = c.uuid ")
              .append(" WHERE a.directory_type = 1 AND b.rigths like '%3%' AND c.staff_ids like ? GROUP BY a.tricode ");
    }else {
      param.append(userId);
      sql.append("SELECT * FROM product_oa_directory ")
              .append(" WHERE directory_type = 2 AND created_by = ? ");
         sql.append("SELECT * FROM PRODUCT_OA_directory ").append(" WHERE directory_type = 2 AND created_by = ? ");
    }
    DataTableEntity dataTableEntity = baseDao.listTable(sql.toString(), new String[]{param.toString()});
    baseDao.listInternationDataTable(dataTableEntity, null);
@@ -276,7 +297,7 @@
  public boolean upDocumentDirectoryName(FieldSetEntity fse) throws BaseException {
    String uuid = fse.getString(CmnConst.UUID);
    String directoryName = fse.getString(CmnConst.DIRECTORY_NAME);
    FieldSetEntity docField = baseDao.getFieldSetEntity(CmnConst.product_oa_DIRECTORY, uuid, false);
      FieldSetEntity docField = baseDao.getFieldSetEntity(CmnConst.PRODUCT_OA_DIRECTORY, uuid, false);
    docField.setValue(CmnConst.DIRECTORY_NAME, directoryName);
    return baseDao.update(docField);
  }