Example #1
0
  /**
   * 设置关键字高亮
   *
   * @param query 查询对象
   * @param list 设置高亮的内容列表
   * @param subLength 截取长度
   * @param fields 字段名
   */
  public List<T> keywordsHighlight(
      BooleanQuery query, List<T> list, int subLength, String... fields) {
    Analyzer analyzer = new IKAnalyzer();
    Formatter formatter = new SimpleHTMLFormatter("<span class=\"highlight\">", "</span>");
    Highlighter highlighter = new Highlighter(formatter, new QueryScorer(query));
    highlighter.setTextFragmenter(new SimpleFragmenter(subLength));

    for (T entity : list) {
      try {
        for (String field : fields) {
          String text = StringUtils.replaceHtml((String) Reflections.invokeGetter(entity, field));
          // 设置高亮字段
          String description = highlighter.getBestFragment(analyzer, field, text);
          if (description != null) {
            Reflections.invokeSetter(entity, fields[0], description);
            break;
          }
          Reflections.invokeSetter(entity, fields[0], StringUtils.abbr(text, subLength * 2));
        }
      } catch (IOException e) {
        e.printStackTrace();
      } catch (InvalidTokenOffsetsException e) {
        e.printStackTrace();
      }
    }
    return list;
  }
Example #2
0
 /**
  * 获取导入依赖包字符串
  *
  * @return
  */
 public List<String> getImportList() {
   List<String> importList = Lists.newArrayList(); // 引用列表
   for (GenTableColumn column : getColumnList()) {
     if (column.getIsNotBaseField()
         || ("1".equals(column.getIsQuery())
             && "between".equals(column.getQueryType())
             && ("createDate".equals(column.getSimpleJavaField())
                 || "updateDate".equals(column.getSimpleJavaField())))) {
       // 导入类型依赖包, 如果类型中包含“.”,则需要导入引用。
       if (StringUtils.indexOf(column.getJavaType(), ".") != -1
           && !importList.contains(column.getJavaType())) {
         importList.add(column.getJavaType());
       }
     }
     if (column.getIsNotBaseField()) {
       // 导入JSR303、Json等依赖包
       for (String ann : column.getAnnotationList()) {
         if (!importList.contains(StringUtils.substringBeforeLast(ann, "("))) {
           importList.add(StringUtils.substringBeforeLast(ann, "("));
         }
       }
     }
   }
   // 如果有子表,则需要导入List相关引用
   if (getChildList() != null && getChildList().size() > 0) {
     if (!importList.contains("java.util.List")) {
       importList.add("java.util.List");
     }
     if (!importList.contains("com.google.common.collect.Lists")) {
       importList.add("com.google.common.collect.Lists");
     }
   }
   return importList;
 }
Example #3
0
 /**
  * 使用检索标准对象分页查询
  *
  * @param detachedCriteria
  * @param page
  * @return
  */
 @SuppressWarnings("unchecked")
 public Page<T> find(Page<T> page, DetachedCriteria detachedCriteria) {
   // get count
   if (!page.isDisabled() && !page.isNotCount()) {
     page.setCount(count(detachedCriteria));
     if (page.getCount() < 1) {
       return page;
     }
   }
   Criteria criteria = detachedCriteria.getExecutableCriteria(getSession());
   criteria.setResultTransformer(Criteria.ROOT_ENTITY);
   // set page
   if (!page.isDisabled()) {
     criteria.setFirstResult(page.getFirstResult());
     criteria.setMaxResults(page.getMaxResults());
   }
   // order by
   if (StringUtils.isNotBlank(page.getOrderBy())) {
     for (String order : StringUtils.split(page.getOrderBy(), ",")) {
       String[] o = StringUtils.split(order, " ");
       if (o.length >= 1) {
         criteria.addOrder(Order.asc(o[0]));
       } else if (o.length >= 2) {
         if ("DESC".equals(o[1].toUpperCase())) {
           criteria.addOrder(Order.desc(o[0]));
         } else {
           criteria.addOrder(Order.asc(o[0]));
         }
       }
     }
   }
   page.setList(criteria.list());
   return page;
 }
Example #4
0
  public Page<Log> find(Page<Log> page, Map<String, Object> paramMap) {
    DetachedCriteria dc = logDao.createDetachedCriteria();

    Long createById = StringUtils.toLong(paramMap.get("createById"));
    if (createById > 0) {
      dc.add(Restrictions.eq("createBy.id", createById));
    }

    String requestUri = ObjectUtils.toString(paramMap.get("requestUri"));
    if (StringUtils.isNotBlank(requestUri)) {
      dc.add(Restrictions.like("requestUri", "%" + requestUri + "%"));
    }

    String exception = ObjectUtils.toString(paramMap.get("exception"));
    if (StringUtils.isNotBlank(exception)) {
      dc.add(Restrictions.eq("type", Log.TYPE_EXCEPTION));
    }

    Date beginDate = DateUtils.parseDate(paramMap.get("beginDate"));
    if (beginDate == null) {
      beginDate = DateUtils.setDays(new Date(), 1);
      paramMap.put("beginDate", DateUtils.formatDate(beginDate, "yyyy-MM-dd"));
    }
    Date endDate = DateUtils.parseDate(paramMap.get("endDate"));
    if (endDate == null) {
      endDate = DateUtils.addDays(DateUtils.addMonths(beginDate, 1), -1);
      paramMap.put("endDate", DateUtils.formatDate(endDate, "yyyy-MM-dd"));
    }
    dc.add(Restrictions.between("createDate", beginDate, endDate));

    dc.addOrder(Order.desc("id"));
    return logDao.find(page, dc);
  }
  // @RequiresPermissions("funds:tradingAccounts:edit")
  @RequestMapping(value = "save")
  public String save(
      TradingAccounts tradingAccounts, Model model, RedirectAttributes redirectAttributes) {
    String id = tradingAccounts.getId();

    if (!beanValidator(model, tradingAccounts)) {
      return form(tradingAccounts, model, redirectAttributes);
    }

    /* 校验收据编号重复 */
    boolean check = true;
    String receiptNo = "";
    List<String> receiptNoList = new ArrayList<String>();
    if (null != tradingAccounts.getReceiptList()) {
      for (Receipt receipt : tradingAccounts.getReceiptList()) {
        Receipt tmpReceipt = new Receipt();
        tmpReceipt.setReceiptNo(receipt.getReceiptNo());
        tmpReceipt.setDelFlag("0");
        List<Receipt> list = receiptService.findList(tmpReceipt);
        if ((null != list && list.size() > 0)) {
          for (Receipt tReceipt : list) {
            if (receipt.getReceiptNo().equals(tReceipt.getReceiptNo())
                && !tReceipt.getTradingAccounts().getId().equals(tradingAccounts.getId())) {
              receiptNo = receipt.getReceiptNo();
              check = false;
              break;
            }
          }
        }
        if (receiptNoList.contains(receipt.getReceiptNo())) {
          receiptNo = receipt.getReceiptNo();
          check = false;
        }
        if (!check) break;
        receiptNoList.add(receipt.getReceiptNo());
      }
    }

    if (!check) {
      model.addAttribute("message", "收据编号:" + receiptNo + "重复或已存在.");
      model.addAttribute("messageType", ViewMessageTypeEnum.ERROR.getValue());
      if (StringUtils.isEmpty(id)) {
        return form(tradingAccounts, model, redirectAttributes);
      } else {
        return "modules/funds/tradingAccountsForm";
      }
    }

    tradingAccounts.setTradeStatus("0"); // 待审核
    tradingAccountsService.save(tradingAccounts);
    addMessage(redirectAttributes, "保存账务交易成功");
    if (StringUtils.isEmpty(id)) {
      return "redirect:" + Global.getAdminPath() + "/funds/paymentTrans/?repage";
    } else {
      return "redirect:" + Global.getAdminPath() + "/funds/tradingAccounts/?repage";
    }
  }
Example #6
0
 /** 通过编号获取内容标题 */
 public List<Object[]> findByIds(String ids) {
   List<Object[]> list = Lists.newArrayList();
   Long[] idss = (Long[]) ConvertUtils.convert(StringUtils.split(ids, ","), Long.class);
   if (idss.length > 0) {
     List<Link> l = linkDao.findByIdIn(idss);
     for (Link e : l) {
       list.add(new Object[] {e.getId(), StringUtils.abbr(e.getTitle(), 50)});
     }
   }
   return list;
 }
Example #7
0
  /**
   * 获取物理数据表列表
   *
   * @param genTable
   * @return
   */
  public GenTable getTableFormDb(GenTable genTable) {
    // 如果有表名,则获取物理表
    if (StringUtils.isNotBlank(genTable.getName())) {

      List<GenTable> list = genDataBaseDictDao.findTableList(genTable);
      if (list.size() > 0) {

        // 如果是新增,初始化表属性
        if (StringUtils.isBlank(genTable.getId())) {
          genTable = list.get(0);
          // 设置字段说明
          if (StringUtils.isBlank(genTable.getComments())) {
            genTable.setComments(genTable.getName());
          }
          genTable.setClassName(StringUtils.toCapitalizeCamelCase(genTable.getName()));
        }

        // 添加新列
        List<GenTableColumn> columnList = genDataBaseDictDao.findTableColumnList(genTable);
        for (GenTableColumn column : columnList) {
          boolean b = false;
          for (GenTableColumn e : genTable.getColumnList()) {
            if (e.getName().equals(column.getName())) {
              b = true;
            }
          }
          if (!b) {
            genTable.getColumnList().add(column);
          }
        }

        // 删除已删除的列
        for (GenTableColumn e : genTable.getColumnList()) {
          boolean b = false;
          for (GenTableColumn column : columnList) {
            if (column.getName().equals(e.getName())) {
              b = true;
            }
          }
          if (!b) {
            e.setDelFlag(GenTableColumn.DEL_FLAG_DELETE);
          }
        }

        // 获取主键
        genTable.setPkList(genDataBaseDictDao.findTablePK(genTable));

        // 初始化列属性字段
        GenUtils.initColumnField(genTable);
      }
    }
    return genTable;
  }
Example #8
0
 /**
  * SQL 分页查询
  *
  * @param page
  * @param sqlString
  * @param resultClass
  * @param parameter
  * @return
  */
 @SuppressWarnings("unchecked")
 public <E> Page<E> findBySql(
     Page<E> page, String sqlString, Parameter parameter, Class<?> resultClass) {
   // get count
   if (!page.isDisabled() && !page.isNotCount()) {
     String countSqlString = "select count(*) " + removeSelect(removeOrders(sqlString));
     //	        page.setCount(Long.valueOf(createSqlQuery(countSqlString,
     // parameter).uniqueResult().toString()));
     Query query = createSqlQuery(countSqlString, parameter);
     List<Object> list = query.list();
     if (list.size() > 0) {
       page.setCount(Long.valueOf(list.get(0).toString()));
     } else {
       page.setCount(list.size());
     }
     if (page.getCount() < 1) {
       return page;
     }
   }
   // order by
   String sql = sqlString;
   if (StringUtils.isNotBlank(page.getOrderBy())) {
     sql += " order by " + page.getOrderBy();
   }
   SQLQuery query = createSqlQuery(sql, parameter);
   // set page
   if (!page.isDisabled()) {
     query.setFirstResult(page.getFirstResult());
     query.setMaxResults(page.getMaxResults());
   }
   setResultTransformer(query, resultClass);
   page.setList(query.list());
   return page;
 }
Example #9
0
  /** 流程定义列表 */
  public Page<Object[]> processList(Page<Object[]> page, String category) {

    ProcessDefinitionQuery processDefinitionQuery =
        repositoryService
            .createProcessDefinitionQuery()
            .latestVersion()
            .orderByProcessDefinitionKey()
            .asc();

    if (StringUtils.isNotEmpty(category)) {
      processDefinitionQuery.processDefinitionCategory(category);
    }

    page.setCount(processDefinitionQuery.count());

    List<ProcessDefinition> processDefinitionList =
        processDefinitionQuery.listPage(page.getFirstResult(), page.getMaxResults());
    for (ProcessDefinition processDefinition : processDefinitionList) {
      String deploymentId = processDefinition.getDeploymentId();
      Deployment deployment =
          repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
      page.getList().add(new Object[] {processDefinition, deployment});
    }

    return page;
  }
Example #10
0
  /**
   * 读取资源,通过部署ID
   *
   * @param processDefinitionId 流程定义ID
   * @param processInstanceId 流程实例ID
   * @param resourceType 资源类型(xml|image)
   */
  public InputStream resourceRead(String procDefId, String proInsId, String resType)
      throws Exception {

    if (StringUtils.isBlank(procDefId)) {
      ProcessInstance processInstance =
          runtimeService.createProcessInstanceQuery().processInstanceId(proInsId).singleResult();
      procDefId = processInstance.getProcessDefinitionId();
    }
    ProcessDefinition processDefinition =
        repositoryService
            .createProcessDefinitionQuery()
            .processDefinitionId(procDefId)
            .singleResult();

    String resourceName = "";
    if (resType.equals("image")) {
      resourceName = processDefinition.getDiagramResourceName();
    } else if (resType.equals("xml")) {
      resourceName = processDefinition.getResourceName();
    }

    InputStream resourceAsStream =
        repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
    return resourceAsStream;
  }
Example #11
0
 /**
  * 获取工程路径
  *
  * @return
  */
 public static String getProjectPath() {
   // 如果配置了工程路径,则直接返回,否则自动获取。
   String projectPath = Global.getConfig("projectPath");
   if (StringUtils.isNotBlank(projectPath)) {
     return projectPath;
   }
   try {
     File file = new DefaultResourceLoader().getResource("").getFile();
     if (file != null) {
       while (true) {
         File f = new File(file.getPath() + File.separator + "src" + File.separator + "main");
         if (f == null || f.exists()) {
           break;
         }
         if (file.getParentFile() != null) {
           file = file.getParentFile();
         } else {
           break;
         }
       }
       projectPath = file.toString();
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
   return projectPath;
 }
Example #12
0
  /**
   * 启动流程
   *
   * @param entity
   */
  @Transactional(readOnly = false)
  public void save(Leave leave, Map<String, Object> variables) {

    // 保存业务数据
    if (StringUtils.isBlank(leave.getId())) {
      leave.preInsert();
      leaveDao.insert(leave);
    } else {
      leave.preUpdate();
      leaveDao.update(leave);
    }
    logger.debug("save entity: {}", leave);

    // 用来设置启动流程的人员ID,引擎会自动把用户ID保存到activiti:initiator中
    identityService.setAuthenticatedUserId(leave.getCurrentUser().getLoginName());

    // 启动流程
    String businessKey = leave.getId().toString();
    variables.put("type", "leave");
    variables.put("busId", businessKey);
    ProcessInstance processInstance =
        runtimeService.startProcessInstanceByKey(ActUtils.PD_LEAVE[0], businessKey, variables);
    leave.setProcessInstance(processInstance);

    // 更新流程实例ID
    leave.setProcessInstanceId(processInstance.getId());
    leaveDao.updateProcessInstanceId(leave);

    logger.debug(
        "start process of {key={}, bkey={}, pid={}, variables={}}",
        new Object[] {ActUtils.PD_LEAVE[0], businessKey, processInstance.getId(), variables});
  }
Example #13
0
 /** 获取对象值(导入) */
 public static Object getValue(String val) {
   for (Office e : UserUtils.getOfficeList()) {
     if (StringUtils.trimToEmpty(val).equals(e.getName())) {
       return e;
     }
   }
   return null;
 }
Example #14
0
  /** 流程定义列表 */
  public Page<ProcessInstance> runningList(
      Page<ProcessInstance> page, String procInsId, String procDefKey) {

    ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery();

    if (StringUtils.isNotBlank(procInsId)) {
      processInstanceQuery.processInstanceId(procInsId);
    }

    if (StringUtils.isNotBlank(procDefKey)) {
      processInstanceQuery.processDefinitionKey(procDefKey);
    }

    page.setCount(processInstanceQuery.count());
    page.setList(processInstanceQuery.listPage(page.getFirstResult(), page.getMaxResults()));
    return page;
  }
Example #15
0
 @ModelAttribute
 public Article get(@RequestParam(required = false) String id) {
   if (StringUtils.isNotBlank(id)) {
     return articleService.get(id);
   } else {
     return new Article();
   }
 }
Example #16
0
 @Transactional(readOnly = false)
 public Page<Link> find(Page<Link> page, Link link, boolean isDataScopeFilter) {
   // 更新过期的权重,间隔为“6”个小时
   Date updateExpiredWeightDate = (Date) CacheUtils.get("updateExpiredWeightDateByLink");
   if (updateExpiredWeightDate == null
       || (updateExpiredWeightDate != null
           && updateExpiredWeightDate.getTime() < new Date().getTime())) {
     linkDao.updateExpiredWeight();
     CacheUtils.put("updateExpiredWeightDateByLink", DateUtils.addHours(new Date(), 6));
   }
   DetachedCriteria dc = linkDao.createDetachedCriteria();
   dc.createAlias("category", "category");
   dc.createAlias("category.site", "category.site");
   if (link.getCategory() != null
       && StringUtils.isNotBlank(link.getCategory().getId())
       && !Category.isRoot(link.getCategory().getId())) {
     Category category = categoryDao.get(link.getCategory().getId());
     if (category != null) {
       dc.add(
           Restrictions.or(
               Restrictions.eq("category.id", category.getId()),
               Restrictions.like("category.parentIds", "%," + category.getId() + ",%")));
       dc.add(Restrictions.eq("category.site.id", category.getSite().getId()));
       link.setCategory(category);
     } else {
       dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId()));
     }
   } else {
     dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId()));
   }
   if (StringUtils.isNotEmpty(link.getTitle())) {
     dc.add(Restrictions.like("title", "%" + link.getTitle() + "%"));
   }
   if (link.getCreateBy() != null && StringUtils.isNotBlank(link.getCreateBy().getId())) {
     dc.add(Restrictions.eq("createBy.id", link.getCreateBy().getId()));
   }
   if (isDataScopeFilter) {
     dc.createAlias("category.office", "categoryOffice").createAlias("createBy", "createBy");
     dc.add(dataScopeFilter(UserUtils.getUser(), "categoryOffice", "createBy"));
   }
   dc.add(Restrictions.eq(Link.FIELD_DEL_FLAG, link.getDelFlag()));
   dc.addOrder(Order.desc("weight"));
   dc.addOrder(Order.desc("updateDate"));
   return linkDao.find(page, dc);
 }
Example #17
0
 /**
  * 验证表名是否可用,如果已存在,则返回false
  *
  * @param genTable
  * @return
  */
 public boolean checkTableName(String tableName) {
   if (StringUtils.isBlank(tableName)) {
     return true;
   }
   GenTable genTable = new GenTable();
   genTable.setName(tableName);
   List<GenTable> list = genTableDao.findList(genTable);
   return list.size() == 0;
 }
Example #18
0
 @ModelAttribute
 public WuyeJiben get(@RequestParam(required = false) String id) {
   WuyeJiben entity = null;
   if (StringUtils.isNotBlank(id)) {
     entity = wuyeJibenService.get(id);
   }
   if (entity == null) {
     entity = new WuyeJiben();
   }
   return entity;
 }
Example #19
0
 @ModelAttribute
 public RenwuRun get(@RequestParam(required = false) String id) {
   RenwuRun entity = null;
   if (StringUtils.isNotBlank(id)) {
     entity = renwuRunService.get(id);
   }
   if (entity == null) {
     entity = new RenwuRun();
   }
   return entity;
 }
 @ModelAttribute
 public TradingAccounts get(@RequestParam(required = false) String id) {
   TradingAccounts entity = null;
   if (StringUtils.isNotBlank(id)) {
     entity = tradingAccountsService.get(id);
   }
   if (entity == null) {
     entity = new TradingAccounts();
   }
   return entity;
 }
Example #21
0
 @ModelAttribute
 public ZbUser get(@RequestParam(required = false) String id) {
   ZbUser entity = null;
   if (StringUtils.isNotBlank(id)) {
     entity = zbUserService.get(id);
   }
   if (entity == null) {
     entity = new ZbUser();
   }
   return entity;
 }
Example #22
0
 @Transient
 public String getExamineIds() {
   List<String> examineIdsList = Lists.newArrayList();
   if (examineList == null || examineList.size() == 0) {
     return "";
   } else {
     for (Examine examine : examineList) {
       examineIdsList.add(examine.getId());
     }
     return StringUtils.join(examineIdsList, ",");
   }
 }
Example #23
0
 @Transactional(readOnly = false)
 public void save(GenTable genTable) {
   if (StringUtils.isBlank(genTable.getId())) {
     genTable.preInsert();
     genTableDao.insert(genTable);
   } else {
     genTable.preUpdate();
     genTableDao.update(genTable);
   }
   // 保存列
   for (GenTableColumn column : genTable.getColumnList()) {
     column.setGenTable(genTable);
     if (StringUtils.isBlank(column.getId())) {
       column.preInsert();
       genTableColumnDao.insert(column);
     } else {
       column.preUpdate();
       genTableColumnDao.update(column);
     }
   }
 }
Example #24
0
 @RequiresPermissions("cms:article:edit")
 @RequestMapping(value = "save")
 public String save(Article article, Model model, RedirectAttributes redirectAttributes) {
   if (!beanValidator(model, article)) {
     return form(article, model);
   }
   articleService.save(article);
   addMessage(redirectAttributes, "保存文章'" + StringUtils.abbr(article.getTitle(), 50) + "'成功");
   String categoryId = article.getCategory() != null ? article.getCategory().getId() : null;
   return "redirect:"
       + adminPath
       + "/cms/article/?repage&category.id="
       + (categoryId != null ? categoryId : "");
 }
Example #25
0
 @RequiresPermissions("renwu_run:renwuRun:view")
 @RequestMapping(value = "form")
 public String form(RenwuRun renwuRun, Model model) {
   if (renwuRun.getParent() != null && StringUtils.isNotBlank(renwuRun.getParent().getId())) {
     renwuRun.setParent(renwuRunService.get(renwuRun.getParent().getId()));
     // 获取排序号,最末节点排序号+30
     if (StringUtils.isBlank(renwuRun.getId())) {
       RenwuRun renwuRunChild = new RenwuRun();
       renwuRunChild.setParent(new RenwuRun(renwuRun.getParent().getId()));
       List<RenwuRun> list = renwuRunService.findList(renwuRun);
       if (list.size() > 0) {
         renwuRun.setSort(list.get(list.size() - 1).getSort());
         if (renwuRun.getSort() != null) {
           renwuRun.setSort(renwuRun.getSort() + 30);
         }
       }
     }
   }
   if (renwuRun.getSort() == null) {
     renwuRun.setSort(30);
   }
   model.addAttribute("renwuRun", renwuRun);
   return "modules/renwu_run/renwuRunForm";
 }
Example #26
0
 /**
  * 获取全文查询对象
  *
  * @param q 查询关键字
  * @param fields 查询字段
  * @return 全文查询对象
  */
 public BooleanQuery getFullTextQuery(String q, String... fields) {
   Analyzer analyzer = new IKAnalyzer();
   BooleanQuery query = new BooleanQuery();
   try {
     if (StringUtils.isNotBlank(q)) {
       for (String field : fields) {
         QueryParser parser = new QueryParser(Version.LUCENE_36, field, analyzer);
         query.add(parser.parse(q), Occur.SHOULD);
       }
     }
   } catch (ParseException e) {
     e.printStackTrace();
   }
   return query;
 }
Example #27
0
 /**
  * 获取上传文件的根目录
  *
  * @return
  */
 public static String getUserfilesBaseDir() {
   String dir = getConfig("userfiles.basedir");
   if (StringUtils.isBlank(dir)) {
     try {
       dir = ServletContextFactory.getServletContext().getRealPath("/");
     } catch (Exception e) {
       return "";
     }
   }
   if (!dir.endsWith("/")) {
     dir += "/";
   }
   //		System.out.println("userfiles.basedir: " + dir);
   return dir;
 }
Example #28
0
 @Transactional(readOnly = false)
 public void save(Link link) {
   // 如果没有审核权限,则将当前内容改为待审核状态
   if (!SecurityUtils.getSubject().isPermitted("cms:link:audit")) {
     link.setDelFlag(Link.DEL_FLAG_AUDIT);
   }
   // 如果栏目不需要审核,则将该内容设为发布状态
   if (link.getCategory() != null && StringUtils.isNotBlank(link.getCategory().getId())) {
     Category category = categoryDao.get(link.getCategory().getId());
     if (!Article.YES.equals(category.getIsAudit())) {
       link.setDelFlag(Article.DEL_FLAG_NORMAL);
     }
   }
   linkDao.clear();
   linkDao.save(link);
 }
Example #29
0
 /**
  * 保存实体
  *
  * @param entity
  */
 public void save(T entity) {
   try {
     // 获取实体编号
     Object id = null;
     for (Method method : entity.getClass().getMethods()) {
       Id idAnn = method.getAnnotation(Id.class);
       if (idAnn != null) {
         id = method.invoke(entity);
         break;
       }
     }
     // 插入前执行方法
     if (StringUtils.isBlank((String) id)) {
       for (Method method : entity.getClass().getMethods()) {
         PrePersist pp = method.getAnnotation(PrePersist.class);
         if (pp != null) {
           method.invoke(entity);
           break;
         }
       }
     }
     // 更新前执行方法
     else {
       for (Method method : entity.getClass().getMethods()) {
         PreUpdate pu = method.getAnnotation(PreUpdate.class);
         if (pu != null) {
           method.invoke(entity);
           break;
         }
       }
     }
   } catch (IllegalArgumentException e) {
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     e.printStackTrace();
   } catch (InvocationTargetException e) {
     e.printStackTrace();
   }
   getSession().saveOrUpdate(entity);
 }
Example #30
0
 @RequiresPermissions("user")
 @ResponseBody
 @RequestMapping(value = "treeData")
 public List<Map<String, Object>> treeData(
     @RequestParam(required = false) String extId, HttpServletResponse response) {
   List<Map<String, Object>> mapList = Lists.newArrayList();
   List<RenwuRun> list = renwuRunService.findList(new RenwuRun());
   for (int i = 0; i < list.size(); i++) {
     RenwuRun e = list.get(i);
     if (StringUtils.isBlank(extId)
         || (extId != null
             && !extId.equals(e.getId())
             && e.getParentIds().indexOf("," + extId + ",") == -1)) {
       Map<String, Object> map = Maps.newHashMap();
       map.put("id", e.getId());
       map.put("pId", e.getParentId());
       map.put("name", e.getName());
       mapList.add(map);
     }
   }
   return mapList;
 }