Пример #1
0
 /**
  * 根据主键获得条记录
  *
  * @param tableName
  * @param colName
  * @param colValue
  * @return
  */
 @SuppressWarnings("unchecked")
 public Map get(String idValue) {
   if (StringUtils.isNotBlank(getTableName())
       && StringUtils.isNotBlank(getIdName())
       && StringUtils.isNotBlank(idValue)) {
     StringBuffer sql = new StringBuffer("select * from ");
     sql.append(getTableName()).append(" where ").append(getIdName());
     sql.append(" = ?");
     Connection conn = null;
     PreparedStatement stat = null;
     ResultSet rs = null;
     try {
       conn = getConnection();
       stat = conn.prepareStatement(sql.toString());
       stat.setString(1, idValue);
       rs = stat.executeQuery();
       if (rs.next()) {
         return ResultSetUtil.toMap(rs, rs.getMetaData());
       }
     } catch (SQLException e) {
       e.printStackTrace();
     } finally {
       close(rs, stat, conn);
     }
   }
   return Collections.EMPTY_MAP;
 }
Пример #2
0
  public void execute() {
    // 短信
    try {
      List<User> users = userManager.getNotifiedSmsUser();
      for (User user : users) {
        String mobile = user.getMobile();
        if (!StringUtils.isNumeric(mobile)) continue;

        // 待办
        /*                List<FlowNode> todoList = flowNodeManager.getAllPendingNodes(user);
        for (FlowNode todo : todoList) {
            messageManager.buildSms(mobile,todo.getFlow().getTitle());
            todo.setNotified("true");
            flowNodeManager.save(todo);
        }*/
        // 系统消息
        List<Message> allUnSms = messageManager.getAllUnSms(user);
        for (Message msg : allUnSms) {
          if (msg.getNotified().equals("3")) messageManager.buildSms(mobile, msg.getContent());
          else messageManager.buildSms(mobile, msg.getTitle());
          msg.setNotified(MsgConstants.NOTIFIED);
          messageManager.save(msg);
        }
      }
    } catch (Exception e) {
      logger.debug(e.getMessage());
    }

    // 邮件
    try {
      List<User> users = userManager.getNotifiedUsers();
      messages = new ArrayList<MimeMessage>();
      from = userManager.getAdmin().getEmail();

      for (User user : users) {
        List<FlowNode> todoList = flowNodeManager.getAllPendingNodes(user);
        String to = user.getEmail();
        if (StringUtils.isBlank(to)) continue;
        for (FlowNode todo : todoList) {
          buildEmail(to, todo);
          todo.setNotified("true");
          flowNodeManager.save(todo);
        }
      }
      mailSender.send(messages.toArray(new MimeMessage[messages.size()]));
    } catch (MailException e) {
      logger.debug(e.getMessage());
    }
  }
Пример #3
0
  private void setGoingToURL(Map<String, Object> session, ActionInvocation invocation) {
    String url = "";

    String namespace = invocation.getProxy().getNamespace();
    if (StringUtils.isNotBlank(namespace) && !namespace.equals("/")) {
      url += namespace;
    }

    String actionName = invocation.getProxy().getActionName();
    if (StringUtils.isNotBlank(actionName)) {
      url += "/" + actionName + ".action";
    }

    session.put(GOING_TO_URL_KEY, url);
  }
Пример #4
0
  /* 入库单查询 */
  public String indexDraw() {
    page = PageUtil.getPage(getPageNo(), getPageSize());
    StringBuffer sql = new StringBuffer("from InStock i where 1=1");
    List<Object> args = new ArrayList<Object>();

    if (StringUtils.isNotBlank(getModel().getStockNo())) { // 按单号查询
      sql.append(" and i.stockNo = ?");
      args.add(getModel().getStockNo());
    }

    if (getModel().getGoods() != null
        && StringUtils.isNotBlank(getModel().getGoods().getName())) { // 按物品名称查询
      sql.append(" and i.goods.name like ?");
      args.add(MatchMode.ANYWHERE.toMatchString(getModel().getGoods().getName()));
    }

    if (StringUtils.isNotBlank(cDate)) { // 按入库日期查询
      sql.append(" and i.inDate = ?");
      try {
        args.add(DateUtil.firstSecondOfDate(DateUtil.convertStringToDate("yyyy-MM-dd", cDate)));
      } catch (ParseException e) {
      }
    }

    sql.append(" order by i.inDate desc");
    page = getManager().pageQuery(page, sql.toString(), args.toArray());
    restorePageData(page);

    List<InStock> list = page.getData();
    if (list != null && list.size() > 0) {
      // 统计总入库数量
      int totalInCounts = 0;
      // 统计总价钱
      double totalAmount = 0;
      for (InStock i : list) {
        // 入库数
        Integer inCounts = i.getInCounts() == null ? 0 : i.getInCounts();
        // 此单库存价钱
        Double amount = i.getAmount() == null ? 0d : i.getAmount();
        totalInCounts += inCounts;
        totalAmount += amount;
      }
      getRequest().setAttribute("totalAmount", totalAmount);
      getRequest().setAttribute("totalInCounts", totalInCounts);
    }

    return "indexDraw";
  }
Пример #5
0
 public String saveBook() {
   bookList = bookService.list();
   for (Book b : bookList) {
     if (!b.getId().equals(book.getId()) && StringUtils.equals(book.getName(), b.getName())) {
       msg = "error";
       return SUCCESS;
     }
   }
   bookService.saveOrUpdate(book);
   msg = "success";
   return SUCCESS;
 }
Пример #6
0
  /**
   * 根据主键删除一条记录
   *
   * @param idValue 主键值
   */
  public void remove(String idValue) {
    if (StringUtils.isNotBlank(getTableName())
        && StringUtils.isNotBlank(getIdName())
        && StringUtils.isNotBlank(idValue)) {

      StringBuffer sql = new StringBuffer("delete from ");
      sql.append(getTableName()).append(" where ").append(getIdName());
      sql.append(" = ?");

      Connection conn = null;
      PreparedStatement stat = null;
      try {
        conn = getConnection();
        stat = conn.prepareStatement(sql.toString());
        stat.setString(1, idValue);
        stat.executeUpdate();
      } catch (SQLException e) {
        e.printStackTrace();
      } finally {
        close(stat, conn);
      }
    }
  }
Пример #7
0
  public String index() {
    StringBuffer hql = new StringBuffer(" from AddressBookType a where 1 = 1");
    List<Object> args = new ArrayList<Object>();

    if (StringUtils.isNotBlank(getModel().getName())) {
      hql.append(" and a.name like ? ");
      args.add(MatchMode.ANYWHERE.toMatchString(getModel().getName()));
    }

    page = PageUtil.getPage(getPageNo(), getPageSize());
    page = getManager().pageQuery(page, hql.toString(), args.toArray());
    restorePageData(page);

    return INDEX;
  }
Пример #8
0
  /* (non-Javadoc)
   * @see com.opensymphony.xwork2.interceptor.AbstractInterceptor#intercept(com.opensymphony.xwork2.ActionInvocation)
   */
  @SuppressWarnings("unchecked")
  @Override
  public String intercept(ActionInvocation invocation) throws Exception {
    // TODO Auto-generated method stub
    String name = invocation.getInvocationContext().getName();

    if (name.equals("LoginIn")) {
      return invocation.invoke();
    } else {
      ActionContext ac = invocation.getInvocationContext();
      HttpServletRequest request = (HttpServletRequest) ac.get(StrutsStatics.HTTP_REQUEST);
      Map<String, Object> session = (Map<String, Object>) ac.get(ServletActionContext.SESSION);

      if (session != null && session.get(USER_SESSION_KEY) != null) {
        return invocation.invoke();
      }

      Cookie[] cookies = request.getCookies();
      if (cookies != null) {
        for (Cookie cookie : cookies) {
          if (USER_COOKIE_KEY.equals(cookie.getName())) {
            String value = cookie.getValue();
            if (StringUtils.isNotBlank(value)) {
              String[] split = value.split("==");
              String username = split[0];
              String password = split[1];

              if (mUserService.validateUser(username, password) == 1) {
                session.put(USER_SESSION_KEY, username);
              }
            } else {
              setGoingToURL(session, invocation);
              return "login";
            }

            return invocation.invoke();
          }
        }
      }

      setGoingToURL(session, invocation);
      return "login";
    }
  }
Пример #9
0
  private void addEntity(
      String pkg, Element entityElement, Object parentEntity, String callString) {
    try {

      // 根据包名和类名,得到全路径类名
      String clz = pkg + "." + entityElement.attributeValue("class");

      // 根据全路径类名,创建实体对象
      Object entity = Class.forName(clz).newInstance();

      // 给entity对象赋值
      // 即提取出当前Element中的所有属性,并用反射机制给entity对象赋值
      Iterator iterator = entityElement.attributeIterator();
      while (iterator.hasNext()) {
        Attribute attribute = (Attribute) iterator.next();
        String propertyName = attribute.getName();
        if (!propertyName.equals("class")
            && !propertyName.equals("call")
            && !propertyName.equals("parentName")) {
          String propertyValue = attribute.getValue();
          // 给entity相应的属性赋值,这里使用的是apache-commons-beanutils工具包,所以需要加入这个依赖包
          BeanUtils.copyProperty(entity, propertyName, propertyValue);
        }
      }

      /**
       * 提取出当前Element下面所有的非entity元素,这些元素也当作是本Entity属性的一部分 举个例子: <entity class="Form" name="请假单"
       * content="这里是请假单的内容" ...></entity> 像上面这样定义当然是可以的,但是有些属性的值可能会包含特殊字符,或者内容比较庞大,所以,可能
       * 像下面这样来定义更加合理,如: <entity class="Form" name="请假单" ...> <content> <![CDATA[
       *
       * <p>这是一个请假单 请假者姓名:<input type="text" name="leaverName" > .... ]]> </content> </entity>
       * 这样,比较复杂的文本属性,也可以定义
       */
      // 查找本元素下所有名称不是entity的元素
      List subPropertyElements = entityElement.selectNodes("*[name()!='entity']");
      if (subPropertyElements != null && !subPropertyElements.isEmpty())
        for (Iterator iterator2 = subPropertyElements.iterator(); iterator2.hasNext(); ) {
          Element e = (Element) iterator2.next();
          String propertyName = e.getName();
          String propertyValue = e.getText();
          BeanUtils.copyProperty(entity, propertyName, propertyValue);
        }

      // 判断parentEntity是否为空,如果不是空,则给parent对象赋值
      if (parentEntity != null) {
        String parentName = entityElement.attributeValue("parentName");
        if (parentName == null) { // 如果不配置父属性的名称,默认为parent
          parentName = "parent";
        }
        parentName = StringUtils.capitalize(parentName); // 首字母变成大写

        String setParentName = "set" + parentName;

        Method[] ms = entity.getClass().getMethods();
        for (Method m : ms) {
          if (m.getName().equals(setParentName)) {
            m.invoke(entity, parentEntity);
          }
        }
      }

      // 要调用哪个服务对象的哪个方法
      String call = entityElement.attributeValue("call");
      if (call != null) {
        callString = call;
      }

      if (callString == null) {
        throw new RuntimeException("没有找到call属性,无法获知要调用哪个服务对象的哪个方法!请配置call属性!");
      }

      // 得到服务对象的ID
      String serviceId = callString.substring(0, callString.indexOf("."));
      // 得到要调用的方法名称
      String methodName = callString.substring(callString.indexOf(".") + 1);

      // 通过BeanFactory得到服务对象
      Object service = factory.getBean(serviceId);

      // 得到service对象的所有方法
      Method[] ms = service.getClass().getMethods();
      for (Method m : ms) {
        if (m.getName().equals(methodName)) {
          // 调用其中我们想要调用的方法
          m.invoke(service, entity);
        }
      }

      // 判断当前entity下面是否还有其他的entity元素
      List subEntityElements = entityElement.elements("entity");
      for (Iterator iterator2 = subEntityElements.iterator(); iterator2.hasNext(); ) {
        Element e = (Element) iterator2.next();
        // 递归插入本entity元素下面的其它entity对象
        addEntity(pkg, e, entity, callString);
      }

    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }
  }
Пример #10
0
 /**
  * 格式化频道路径,使其同同数据库中路径匹配。
  *
  * @param path
  * @return
  */
 public static String formatChannelPath(String path) {
   String[] s = StringUtils.split(path, "/");
   return StringUtils.join(s, "/");
 }