/**
  * 获取值的数据库值
  *
  * @param value
  * @return
  */
 public static String toDbValue(Object value) {
   if (value == null) {
     return null;
   }
   Class<?> valueType = value.getClass();
   if (valueType.isEnum()) {
     for (Field field : valueType.getDeclaredFields()) {
       Annotation annotation = field.getAnnotation(DbValue.class);
       if (annotation != null) {
         DbValue dbValue = (DbValue) annotation;
         if (field.getName().equals(value.toString())) {
           return dbValue.value();
         }
       }
     }
   } else if (valueType == DateTime.class) {
     // 日期类型的,最小值认为是空
     DateTime dateTime = (DateTime) value;
     if (dateTime.equals(DateTime.getMinValue())) {
       return null;
     }
   } else if (valueType == Decimal.class) {
     Decimal decimal = (Decimal) value;
     return Decimal.round(decimal, Decimal.RESERVED_DECIMAL_PLACES_STORAGE).toString();
   }
   return value.toString();
 }
  @POST
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_JSON)
  @Path("/fetchSalesOrder")
  public OperationResult<SalesOrder> fetchSalesOrder(
      Criteria criteria, @QueryParam("token") String token) {
    System.out.println(String.format("fetch by %s.", token));
    System.out.println(criteria.toString("xml"));

    OperationResult<SalesOrder> operationResult = new OperationResult<SalesOrder>();
    SalesOrder order = new SalesOrder();
    order.setDocEntry(1);
    order.setCustomerCode("C00001");
    order.setDeliveryDate(DateTime.getToday());
    order.setDocumentStatus(emDocumentStatus.Released);
    order.setDocumentTotal(new Decimal("99.99"));
    order.setCycle(new Time(1.05, emTimeUnit.hour));

    order.getUserFields().addUserField("U_OrderType", DbFieldType.db_Alphanumeric);
    order.getUserFields().addUserField("U_OrderId", DbFieldType.db_Numeric);
    order.getUserFields().addUserField("U_OrderDate", DbFieldType.db_Date);
    order.getUserFields().addUserField("U_OrderTotal", DbFieldType.db_Decimal);
    order.getUserFields().setValue("U_OrderType", "S0000");
    order.getUserFields().setValue("U_OrderId", 5768);
    order.getUserFields().setValue("U_OrderDate", DateTime.getToday());
    order.getUserFields().setValue("U_OrderTotal", new Decimal("999.888"));

    ISalesOrderItem orderItem = order.getSalesOrderItems().create();
    orderItem.setItemCode("A00001");
    orderItem.setQuantity(new Decimal(10));
    orderItem.setPrice(new Decimal(99.99));
    orderItem = order.getSalesOrderItems().create();
    orderItem.setItemCode("A00002");
    orderItem.setQuantity(10);
    orderItem.setPrice(199.99);

    // order.setDocumentUser(new User());
    // 此处json序列化存在问题,可能是jersey导致
    // order.setTeamUsers(new User[] { new User(), new User() });
    operationResult.addResultObjects(order);
    return operationResult;
  }