xielq %!s(int64=6) %!d(string=hai) anos
achega
f657a4a23b
Modificáronse 100 ficheiros con 8708 adicións e 0 borrados
  1. 3 0
      WebContent/META-INF/MANIFEST.MF
  2. BIN=BIN
      WebContent/WEB-INF/lib/aopalliance.jar
  3. BIN=BIN
      WebContent/WEB-INF/lib/aspectjrt.jar
  4. BIN=BIN
      WebContent/WEB-INF/lib/axis.jar
  5. BIN=BIN
      WebContent/WEB-INF/lib/commons-dbcp.jar
  6. BIN=BIN
      WebContent/WEB-INF/lib/commons-discovery-0.2.jar
  7. BIN=BIN
      WebContent/WEB-INF/lib/commons-fileupload-1.2.2.jar
  8. BIN=BIN
      WebContent/WEB-INF/lib/commons-io-2.0.1.jar
  9. BIN=BIN
      WebContent/WEB-INF/lib/commons-lang.jar
  10. BIN=BIN
      WebContent/WEB-INF/lib/commons-logging.jar
  11. BIN=BIN
      WebContent/WEB-INF/lib/commons-pool.jar
  12. BIN=BIN
      WebContent/WEB-INF/lib/flexjson-2.1.jar
  13. BIN=BIN
      WebContent/WEB-INF/lib/httpclient-4.4.jar
  14. BIN=BIN
      WebContent/WEB-INF/lib/httpcore-4.4.jar
  15. BIN=BIN
      WebContent/WEB-INF/lib/httpmime-4.4.jar
  16. BIN=BIN
      WebContent/WEB-INF/lib/jackson-core-asl-1.4.3.jar
  17. BIN=BIN
      WebContent/WEB-INF/lib/jackson-mapper-asl-1.4.3.jar
  18. BIN=BIN
      WebContent/WEB-INF/lib/jaxrpc.jar
  19. BIN=BIN
      WebContent/WEB-INF/lib/json-lib-2.4-jdk15.jar
  20. BIN=BIN
      WebContent/WEB-INF/lib/log4j-1.2.15.jar
  21. BIN=BIN
      WebContent/WEB-INF/lib/mail.jar
  22. BIN=BIN
      WebContent/WEB-INF/lib/ojdbc6-11.2.0.jar
  23. BIN=BIN
      WebContent/WEB-INF/lib/poi-3.12.jar
  24. BIN=BIN
      WebContent/WEB-INF/lib/saaj.jar
  25. BIN=BIN
      WebContent/WEB-INF/lib/spring-aop-4.0.2.RELEASE.jar
  26. BIN=BIN
      WebContent/WEB-INF/lib/spring-aspects-4.0.2.RELEASE.jar
  27. BIN=BIN
      WebContent/WEB-INF/lib/spring-beans-4.0.2.RELEASE.jar
  28. BIN=BIN
      WebContent/WEB-INF/lib/spring-context-4.0.2.RELEASE.jar
  29. BIN=BIN
      WebContent/WEB-INF/lib/spring-context-support-4.0.2.RELEASE.jar
  30. BIN=BIN
      WebContent/WEB-INF/lib/spring-core-4.0.2.RELEASE.jar
  31. BIN=BIN
      WebContent/WEB-INF/lib/spring-data-redis-1.6.0.RELEASE.jar
  32. BIN=BIN
      WebContent/WEB-INF/lib/spring-expression-4.0.2.RELEASE.jar
  33. BIN=BIN
      WebContent/WEB-INF/lib/spring-jdbc-4.0.2.RELEASE.jar
  34. BIN=BIN
      WebContent/WEB-INF/lib/spring-orm-4.0.2.RELEASE.jar
  35. BIN=BIN
      WebContent/WEB-INF/lib/spring-oxm-3.0.0.M3.jar
  36. BIN=BIN
      WebContent/WEB-INF/lib/spring-tx-4.0.2.RELEASE.jar
  37. BIN=BIN
      WebContent/WEB-INF/lib/spring-web-4.0.2.RELEASE.jar
  38. BIN=BIN
      WebContent/WEB-INF/lib/spring-webmvc-4.0.2.RELEASE.jar
  39. BIN=BIN
      WebContent/WEB-INF/lib/spring-ws-core-2.0.0-M3.jar
  40. BIN=BIN
      WebContent/WEB-INF/lib/spring-xml-2.0.0-M3.jar
  41. BIN=BIN
      WebContent/WEB-INF/lib/tw.com.dsc.www.tiptop.TIPTOPServiceGateWay.jar
  42. BIN=BIN
      WebContent/WEB-INF/lib/wsdl4j.jar
  43. 83 0
      WebContent/WEB-INF/spring/config.xml
  44. 60 0
      WebContent/WEB-INF/spring/db-config.xml
  45. 52 0
      WebContent/WEB-INF/web.xml
  46. 1 0
      WebContent/error404.html
  47. 9 0
      WebContent/error500.html
  48. 1 0
      WebContent/index.html
  49. BIN=BIN
      classes/artifacts/n_barcode/n_barcode.war
  50. 22 0
      n_malatabarcode.iml
  51. 32 0
      src/com/mes/controller/barcode/BarcodeController.java
  52. 84 0
      src/com/mes/controller/barcode/BaseController.java
  53. 349 0
      src/com/mes/core/BaseUtil.java
  54. 308 0
      src/com/mes/core/CollectionUtil.java
  55. 71 0
      src/com/mes/core/Constant.java
  56. 83 0
      src/com/mes/core/ContextUtil.java
  57. 550 0
      src/com/mes/core/DateUtil.java
  58. 61 0
      src/com/mes/core/FlexJsonUtil.java
  59. 693 0
      src/com/mes/core/HttpUtil.java
  60. 84 0
      src/com/mes/core/JSONUtil.java
  61. 95 0
      src/com/mes/core/JacksonUtil.java
  62. 49 0
      src/com/mes/core/LoginFilter.java
  63. 253 0
      src/com/mes/core/NumberUtil.java
  64. 320 0
      src/com/mes/core/PathUtil.java
  65. 1088 0
      src/com/mes/core/SqlUtil.java
  66. 262 0
      src/com/mes/core/StringUtil.java
  67. 31 0
      src/com/mes/core/SystemException.java
  68. 40 0
      src/com/mes/core/encry/Hex.java
  69. 100 0
      src/com/mes/core/encry/HmacEncoder.java
  70. 9 0
      src/com/mes/core/encry/HmacMD5Encoder.java
  71. 9 0
      src/com/mes/core/encry/HmacSHA1Encoder.java
  72. 9 0
      src/com/mes/core/encry/HmacSHA256Encoder.java
  73. 9 0
      src/com/mes/core/encry/HmacSHA384Encoder.java
  74. 9 0
      src/com/mes/core/encry/HmacSHA512Encoder.java
  75. 46 0
      src/com/mes/core/encry/HmacUtils.java
  76. 75 0
      src/com/mes/core/interceptor/DbSourceInterceptor.java
  77. 283 0
      src/com/mes/core/interceptor/ExceptionHandlerAdvice.java
  78. 21 0
      src/com/mes/core/logging/BufferedLogable.java
  79. 156 0
      src/com/mes/core/logging/BufferedLogger.java
  80. 31 0
      src/com/mes/core/logging/BufferedLoggerManager.java
  81. 125 0
      src/com/mes/core/logging/FileBuffer.java
  82. 21 0
      src/com/mes/core/logging/LogService.java
  83. 34 0
      src/com/mes/core/support/MobileSessionContext.java
  84. 98 0
      src/com/mes/core/support/SpringDynamicCronTask.java
  85. 77 0
      src/com/mes/core/support/SystemSession.java
  86. 1727 0
      src/com/mes/dao/BaseDao.java
  87. 71 0
      src/com/mes/dao/Constant.java
  88. 11 0
      src/com/mes/dao/DataListComboDao.java
  89. 7 0
      src/com/mes/dao/DbfindSetDao.java
  90. 10 0
      src/com/mes/dao/DbfindSetGridDao.java
  91. 16 0
      src/com/mes/dao/DbfindSetUiDao.java
  92. 14 0
      src/com/mes/dao/DetailGridDao.java
  93. 39 0
      src/com/mes/dao/EmployeeDao.java
  94. 23 0
      src/com/mes/dao/EnterpriseDao.java
  95. 103 0
      src/com/mes/dao/MessageLog.java
  96. 82 0
      src/com/mes/dao/MultiDataSource.java
  97. 13 0
      src/com/mes/dao/Saveable.java
  98. 27 0
      src/com/mes/dao/SpObserver.java
  99. 387 0
      src/com/mes/dao/SqlMap.java
  100. 382 0
      src/com/mes/dao/SqlRowList.java

+ 3 - 0
WebContent/META-INF/MANIFEST.MF

@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path: 
+

BIN=BIN
WebContent/WEB-INF/lib/aopalliance.jar


BIN=BIN
WebContent/WEB-INF/lib/aspectjrt.jar


BIN=BIN
WebContent/WEB-INF/lib/axis.jar


BIN=BIN
WebContent/WEB-INF/lib/commons-dbcp.jar


BIN=BIN
WebContent/WEB-INF/lib/commons-discovery-0.2.jar


BIN=BIN
WebContent/WEB-INF/lib/commons-fileupload-1.2.2.jar


BIN=BIN
WebContent/WEB-INF/lib/commons-io-2.0.1.jar


BIN=BIN
WebContent/WEB-INF/lib/commons-lang.jar


BIN=BIN
WebContent/WEB-INF/lib/commons-logging.jar


BIN=BIN
WebContent/WEB-INF/lib/commons-pool.jar


BIN=BIN
WebContent/WEB-INF/lib/flexjson-2.1.jar


BIN=BIN
WebContent/WEB-INF/lib/httpclient-4.4.jar


BIN=BIN
WebContent/WEB-INF/lib/httpcore-4.4.jar


BIN=BIN
WebContent/WEB-INF/lib/httpmime-4.4.jar


BIN=BIN
WebContent/WEB-INF/lib/jackson-core-asl-1.4.3.jar


BIN=BIN
WebContent/WEB-INF/lib/jackson-mapper-asl-1.4.3.jar


BIN=BIN
WebContent/WEB-INF/lib/jaxrpc.jar


BIN=BIN
WebContent/WEB-INF/lib/json-lib-2.4-jdk15.jar


BIN=BIN
WebContent/WEB-INF/lib/log4j-1.2.15.jar


BIN=BIN
WebContent/WEB-INF/lib/mail.jar


BIN=BIN
WebContent/WEB-INF/lib/ojdbc6-11.2.0.jar


BIN=BIN
WebContent/WEB-INF/lib/poi-3.12.jar


BIN=BIN
WebContent/WEB-INF/lib/saaj.jar


BIN=BIN
WebContent/WEB-INF/lib/spring-aop-4.0.2.RELEASE.jar


BIN=BIN
WebContent/WEB-INF/lib/spring-aspects-4.0.2.RELEASE.jar


BIN=BIN
WebContent/WEB-INF/lib/spring-beans-4.0.2.RELEASE.jar


BIN=BIN
WebContent/WEB-INF/lib/spring-context-4.0.2.RELEASE.jar


BIN=BIN
WebContent/WEB-INF/lib/spring-context-support-4.0.2.RELEASE.jar


BIN=BIN
WebContent/WEB-INF/lib/spring-core-4.0.2.RELEASE.jar


BIN=BIN
WebContent/WEB-INF/lib/spring-data-redis-1.6.0.RELEASE.jar


BIN=BIN
WebContent/WEB-INF/lib/spring-expression-4.0.2.RELEASE.jar


BIN=BIN
WebContent/WEB-INF/lib/spring-jdbc-4.0.2.RELEASE.jar


BIN=BIN
WebContent/WEB-INF/lib/spring-orm-4.0.2.RELEASE.jar


BIN=BIN
WebContent/WEB-INF/lib/spring-oxm-3.0.0.M3.jar


BIN=BIN
WebContent/WEB-INF/lib/spring-tx-4.0.2.RELEASE.jar


BIN=BIN
WebContent/WEB-INF/lib/spring-web-4.0.2.RELEASE.jar


BIN=BIN
WebContent/WEB-INF/lib/spring-webmvc-4.0.2.RELEASE.jar


BIN=BIN
WebContent/WEB-INF/lib/spring-ws-core-2.0.0-M3.jar


BIN=BIN
WebContent/WEB-INF/lib/spring-xml-2.0.0-M3.jar


BIN=BIN
WebContent/WEB-INF/lib/tw.com.dsc.www.tiptop.TIPTOPServiceGateWay.jar


BIN=BIN
WebContent/WEB-INF/lib/wsdl4j.jar


+ 83 - 0
WebContent/WEB-INF/spring/config.xml

@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
+	xmlns:context="http://www.springframework.org/schema/context"
+	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
+	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
+	xsi:schemaLocation="http://www.springframework.org/schema/beans   
+           http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
+           http://www.springframework.org/schema/context   
+           http://www.springframework.org/schema/context/spring-context-4.0.xsd 
+           http://www.springframework.org/schema/aop
+           http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
+           http://www.springframework.org/schema/mvc  
+           http://www.springframework.org/schema/mvc/spring-mvc.xsd
+           http://www.springframework.org/schema/tx
+           http://www.springframework.org/schema/tx/spring-tx-4.0.xsd 
+           http://www.springframework.org/schema/util 
+           http://www.springframework.org/schema/util/spring-util.xsd"
+	default-autowire="byName">
+	<bean id="baseUtil" class="com.mes.core.BaseUtil"></bean>
+	<util:properties id="about">
+		<prop key="defaultSob">MES</prop><!-- 默认帐套名称 --><!-- 集团中心名称 -->
+		<prop key="task.status">true</prop>
+	</util:properties>
+	<mvc:resources mapping="/resources/**" location="/resources/" />
+	<mvc:default-servlet-handler />
+	<!-- 自动扫描 ,把作了注解的类转换为bean -->
+	<aop:aspectj-autoproxy />
+	<context:property-placeholder location="WEB-INF/spring:*.properties" />
+	<context:component-scan base-package="com" />
+	<!-- 事务 -->
+	<tx:annotation-driven />
+	<bean id="transactionManager"
+		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
+		<property name="dataSource" ref="dataSource" />
+	</bean>
+	<tx:annotation-driven transaction-manager="transactionManager" />
+	<!-- 对模型视图名称的解析,在请求时模型视图名称添加前后缀 -->
+	<bean
+		class="org.springframework.web.servlet.view.InternalResourceViewResolver"
+		p:prefix="/jsps/" p:suffix=".jsp"><!-- 指向的页面在jsps目录下,并且为.jsp文件 -->
+		<property name="order" value="0" />
+	</bean>
+	<bean id="jsonHttpMessageConverter"
+		class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
+	</bean>
+	<bean
+		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
+		<property name="messageConverters">
+			<util:list id="beanList">
+				<ref bean="jsonHttpMessageConverter" /><!-- spring对list自动转成json的机制 -->
+			</util:list>
+		</property>
+	</bean>
+	<!-- 国际化 -->
+	<bean id="messageSource"
+		class="org.springframework.context.support.ResourceBundleMessageSource">
+		<property name="basenames">
+			<list>
+				<value>i18n/messages</value><!-- 找src下i18n目录下文件名为messages*的所有properties文件 -->
+			</list>
+		</property>
+		<property name="useCodeAsDefaultMessage" value="true" />
+	</bean>
+	<!-- Configure the multipart resolver -->
+	<bean id="multipartResolver"
+		class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
+		<!-- one of the properties available; the maximum file size in bytes -->
+		<property name="maxUploadSize" value="104857600" />
+	</bean>
+	
+	<!-- 自定义拦截器 -->
+	<mvc:interceptors>
+		<mvc:interceptor>
+			<mvc:mapping path="/*/**"></mvc:mapping>
+			<bean class="com.mes.core.interceptor.DbSourceInterceptor"></bean><!-- MultiDataSource Interceptor -->
+		</mvc:interceptor>
+	</mvc:interceptors>
+	
+	
+	<mvc:annotation-driven />
+	<import resource="db-config.xml" />
+</beans>

+ 60 - 0
WebContent/WEB-INF/spring/db-config.xml

@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="
+		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
+	<bean id="MES" class="org.apache.commons.dbcp.BasicDataSource"
+		destroy-method="close">
+		<property name="driverClassName">
+			<value>oracle.jdbc.driver.OracleDriver</value>
+		</property>
+		<property name="url">
+			 <value>jdbc:oracle:thin:@117.25.180.218:1521:orcl</value>
+		      <!--<value>jdbc:oracle:thin:@192.168.230.200:1521:orcl</value>  -->
+		</property>
+		<property name="username">
+			<value>MES_TEST</value>
+		</property>
+		<property name="password" value="select!#%*(" />
+	</bean>
+	<bean id="MES_TEST" class="org.apache.commons.dbcp.BasicDataSource"
+		destroy-method="close">
+		<property name="driverClassName">
+			<value>oracle.jdbc.driver.OracleDriver</value>
+		</property>
+		<property name="url">
+			<!-- <value>jdbc:oracle:thin:@117.25.180.218:1521:orcl</value> -->
+			 <value>jdbc:oracle:thin:@192.168.230.200:1521:orcl</value>
+		</property>
+		<property name="username">
+			<value>MES_TEST</value>
+		</property>
+		<property name="password" value="select!#%*(" />
+	</bean>
+	<bean id="MES_ZZ" class="org.apache.commons.dbcp.BasicDataSource"
+		destroy-method="close">
+		<property name="driverClassName">
+			<value>oracle.jdbc.driver.OracleDriver</value>
+		</property>
+		<property name="url">
+			<!-- <value>jdbc:oracle:thin:@117.25.180.218:1521:orcl</value> -->
+			 <value>jdbc:oracle:thin:@192.168.230.200:1521:orcl</value>  
+		</property>
+		<property name="username">
+			<value>MES_ZZ</value>
+		</property>
+		<property name="password" value="select!#%*(" />
+	</bean>
+	
+	<bean id="dataSource" class="com.mes.dao.MultiDataSource">
+		<property name="dataSource">
+			<ref bean="#{about.defaultSob}" />
+		</property>
+		<property name="connectionProperties"
+			value="oracle.net.CONNECT_TIMEOUT=6000;oracle.jdbc.ReadTimeout=6000" />
+	</bean>
+    
+	<bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler"
+		lazy-init="true" />
+	
+</beans>

+ 52 - 0
WebContent/WEB-INF/web.xml

@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
+  <display-name>WebService</display-name>
+  <distributable/>
+  <filter>
+    <filter-name>encodingFilter</filter-name>
+    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
+    <init-param>
+      <param-name>encoding</param-name>
+      <param-value>UTF-8</param-value>
+    </init-param>
+    <init-param>
+      <param-name>forceEncoding</param-name>
+      <param-value>true</param-value>
+    </init-param>
+  </filter>
+  <filter-mapping>
+    <filter-name>encodingFilter</filter-name>
+    <url-pattern>*</url-pattern>
+  </filter-mapping>
+  <servlet>
+    <servlet-name>Spring</servlet-name>
+    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
+    <init-param>
+      <param-name>contextConfigLocation</param-name>
+      <param-value>
+				/WEB-INF/spring/config.xml
+		</param-value>
+    </init-param>
+    <load-on-startup>1</load-on-startup>
+  </servlet>
+  <servlet-mapping>
+    <servlet-name>Spring</servlet-name>
+    <url-pattern>*.action</url-pattern>
+    <url-pattern>*.xls</url-pattern>
+    <url-pattern>*.pdf</url-pattern>
+  </servlet-mapping>
+  <error-page>
+    <error-code>404</error-code>
+    <location>/error404.html</location>
+  </error-page>
+  <error-page>
+    <error-code>500</error-code>
+    <location>/error500.html</location>
+  </error-page>
+  <welcome-file-list>
+    <welcome-file>index.html</welcome-file>
+  </welcome-file-list>
+  <session-config>
+    <session-timeout>600</session-timeout>
+  </session-config>
+</web-app>

+ 1 - 0
WebContent/error404.html

@@ -0,0 +1 @@
+404

+ 9 - 0
WebContent/error500.html

@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+</head>
+<body>
+500,请先登录ERP再进行相关操作
+</body>
+</html>

+ 1 - 0
WebContent/index.html

@@ -0,0 +1 @@
+Hello WebService!

BIN=BIN
classes/artifacts/n_barcode/n_barcode.war


+ 22 - 0
n_malatabarcode.iml

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="EclipseModuleManager">
+    <conelement value="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0" />
+    <conelement value="org.eclipse.jst.j2ee.internal.web.container" />
+    <conelement value="org.eclipse.jst.j2ee.internal.module.container" />
+    <src_description expected_position="0">
+      <src_folder value="file://$MODULE_DIR$/src" expected_position="0" />
+    </src_description>
+  </component>
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
+    <output url="file://$MODULE_DIR$/build/classes" />
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+    </content>
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="jdk" jdkName="1.7" jdkType="JavaSDK" />
+    <orderEntry type="library" exported="" name="lib" level="project" />
+    <orderEntry type="library" exported="" scope="PROVIDED" name="Tomcat 8.5.24-4" level="application_server_libraries" />
+  </component>
+</module>

+ 32 - 0
src/com/mes/controller/barcode/BarcodeController.java

@@ -0,0 +1,32 @@
+package com.mes.controller.barcode;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import com.mes.service.barcode.BarcodeService;
+
+@Controller
+public class BarcodeController{
+	
+	@Autowired
+	private BarcodeService barcodeService; 
+	
+	/**
+	 获取条码信息
+	 */
+	@RequestMapping(value="/getBarcodeData.action",method = RequestMethod.GET)
+	@ResponseBody
+	public Map<String, Object> getBarcodeData (String UID){	
+		Map<String, Object> modelMap = new HashMap<String, Object >();
+		
+		modelMap = barcodeService.getBarcodeData(UID);
+		
+		return  modelMap;
+	}	
+}

+ 84 - 0
src/com/mes/controller/barcode/BaseController.java

@@ -0,0 +1,84 @@
+package com.mes.controller.barcode;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.ui.ModelMap;
+
+/**
+ * 规范controller返回参数格式
+ * 
+ * @date 2016年11月7日下午2:54:15
+ * @author yingp
+ *
+ */
+public class BaseController {
+	/**
+	 * extjs传回的参数为unicode编码格式时,spring的mvc不能转换过来???貌似因为utf-8为unicode的子格式??? 通过此方法手动将形如\u5800\u5800的字符串转换为汉字
+	 * 
+	 * @add by yingp 或者前台js用unescape解析成汉字也可以
+	 */
+	protected String decodeUnicodeString(String param) {
+		try {
+			return new String(param.getBytes("utf-8"), defultCharset);
+		} catch (UnsupportedEncodingException e) {
+			return param;
+		}
+	}
+
+	protected static final String defultCharset = "UTF-8";
+
+	private static final String SUCCESS = "success";
+
+	private static final String ERROR = "error";
+
+	private static final String ERROR_CODE = "errCode";
+
+	private static final String CONTENT = "content";
+
+	private static final String ERROR_MESSAGE = "exceptionInfo";// 与异常处理的exceptionInfo一致
+
+	protected ModelMap success() {
+		return new ModelMap(SUCCESS, true);
+	}
+
+	protected ModelMap success(Object content) {
+		return success().addAttribute(CONTENT, content);
+	}
+
+	protected ModelMap error() {
+		return new ModelMap(ERROR, true);
+	}
+
+	protected ModelMap error(String errMsg) {
+		return error().addAttribute(ERROR_MESSAGE, errMsg);
+	}
+
+	protected ModelMap error(int errCode, String errMsg) {
+		return error(errMsg).addAttribute(ERROR_CODE, errCode);
+	}
+
+	/**
+	 * 输出流
+	 * 
+	 * @param fileName
+	 *            文件名
+	 * @param bytes
+	 * @throws IOException
+	 */
+	protected ResponseEntity<byte[]> outputStream(String fileName, byte[] bytes) {
+		HttpHeaders headers = new HttpHeaders();
+		headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
+		try {
+			headers.setContentDispositionFormData("attachment", URLEncoder.encode(fileName, defultCharset));
+		} catch (UnsupportedEncodingException e) {
+		}
+		return new ResponseEntity<byte[]>(bytes, headers, HttpStatus.CREATED);
+	}
+
+}

+ 349 - 0
src/com/mes/core/BaseUtil.java

@@ -0,0 +1,349 @@
+package com.mes.core;
+
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.mail.internet.MimeUtility;
+import javax.servlet.http.HttpServletRequest;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+import org.apache.commons.dbcp.BasicDataSource;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.springframework.beans.factory.support.DefaultListableBeanFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.ConfigurableApplicationContext;
+
+import com.mes.core.support.SystemSession;
+import com.mes.dao.EnterpriseDao;
+import com.mes.dao.SpObserver;
+import com.mes.model.Master;
+
+public class BaseUtil implements ApplicationContextAware {
+
+	private static Map<String, Object> setting;
+
+	@Override
+	public void setApplicationContext(ApplicationContext context) throws BeansException {
+		ContextUtil.setApplicationContext(context);
+		// 创建数据源
+		createDataSource();
+	}
+
+	/**
+	 * 取系统根路径
+	 * 
+	 * @param request
+	 * @return
+	 */
+	public static String getBasePath(HttpServletRequest request) {
+		return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
+	}
+
+	/**
+	 * 将formStore解析成一个map
+	 * 
+	 * @param formStore
+	 *            字符串形式的表单数据
+	 * @return map形式的表单数据
+	 */
+	public static Map<Object, Object> parseFormStoreToMap(String formStore) {
+		try {
+			return FlexJsonUtil.fromJson(formStore);
+		} catch (Exception e) {
+			return JSONUtil.toMap(formStore);
+		}
+	}
+
+	/**
+	 * 将gridStore解析成maps
+	 * 
+	 * @param gridStore
+	 *            字符串形式的grid数据
+	 * @return map形式的grid数据
+	 */
+	public static List<Map<Object, Object>> parseGridStoreToMaps(String gridStore) {
+		List<Map<Object, Object>> list = new ArrayList<Map<Object, Object>>();
+		try {
+			if (!gridStore.startsWith("[")) {
+				gridStore = "[" + gridStore + "]";
+			}
+			if (gridStore.length() > 409600) {
+				list = JacksonUtil.fromJsonArray(gridStore);
+			} else {
+				list = FlexJsonUtil.fromJsonArray(gridStore, HashMap.class);
+			}
+		} catch (Exception e) {
+			list = JSONUtil.toMapList(gridStore);
+		}
+		return list;
+	}
+
+	public static String parseGridStore2Str(List<Map<String, Object>> list) {
+		return JacksonUtil.toJsonArray(list);
+	}
+	/**
+	 * List集合转化成字符串, null和空字符自动去掉
+	 * 
+	 * @param list
+	 *            待转化集合
+	 * @param ch
+	 *            分割符
+	 * @param repeat
+	 *            是否去重 {true-是、false-否}
+	 */
+	public static String parseList2Str(List<?> list, String ch, boolean repeat) {
+		StringBuffer sb = new StringBuffer();
+		for (Object s : list) {
+			if (s != null && !s.toString().trim().equals("")) {
+				if (repeat) {
+					if (!sb.toString().contains(s + ch)) {
+						sb.append(s);
+						sb.append(ch);
+					}
+				} else {
+					sb.append(s);
+					sb.append(ch);
+				}
+			}
+		}
+		if (sb.length() > 0 && ch.length() > 0) {
+			return sb.substring(0, sb.lastIndexOf(ch));
+		}
+		return sb.toString();
+	}
+	/**
+	 * 数组转化成字符串, null和空字符自动去掉
+	 * 
+	 * @param arr
+	 *            待转化数组
+	 * @param ch
+	 *            分割符
+	 */
+	public static String parseArray2Str(Object[] arr, String ch) {
+		StringBuffer sb = new StringBuffer();
+		for (Object s : arr) {
+			if (s != null && !s.toString().trim().equals("")) {
+				sb.append(s);
+				sb.append(ch);
+			}
+		}
+		if (sb.length() > 0 && ch.length() > 0) {
+			return sb.substring(0, sb.lastIndexOf(ch));
+		}
+		return sb.toString();
+	}
+
+	/**
+	 * 字符串转化成List集合, null和空字符自动去掉
+	 * 
+	 * @param str
+	 *            待转化字段
+	 * @param ch
+	 *            分割符
+	 * @param repeat
+	 *            是否去重 {true-是、false-否}
+	 */
+	public static List<String> parseStr2List(String str, String ch, boolean repeat) {
+		List<String> list = new ArrayList<String>();
+		for (String s : str.split(ch)) {
+			if (s != null && !s.trim().equals("")) {
+				if (repeat) {
+					if (!list.contains(s)) {
+						list.add(s);
+					}
+				} else {
+					list.add(s);
+				}
+			}
+		}
+		return list;
+	}
+	public static JSONArray sortJsonArray(JSONArray array, String property) {
+		JSONObject jObject = null;
+		for (int i = 0; i < array.size(); i++) {
+			Float l = Float.parseFloat(array.getJSONObject(i).get(property).toString());
+			for (int j = i + 1; j < array.size(); j++) {
+				Float nl = Float.parseFloat(array.getJSONObject(j).get(property).toString());
+				if (l < nl) {
+					jObject = array.getJSONObject(j);
+					array.set(j, array.getJSONObject(i));
+					array.set(i, jObject);
+				}
+			}
+		}
+		return array;
+	}
+
+	/**
+	 * 设置下载文件中文件的名称
+	 * 
+	 * @param filename
+	 * @param request
+	 * @return
+	 */
+	public static String encodeFilename(String filename, HttpServletRequest request) {
+		/**
+		 * 获取客户端浏览器和操作系统信息 在IE浏览器中得到的是:User-Agent=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; Alexa Toolbar) 在Firefox中得到的是:User-Agent=Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.7.10) Gecko/20050717 Firefox/1.0.6
+		 */
+		String agent = request.getHeader("USER-AGENT");
+		try {
+			if ((agent != null) && (-1 != agent.indexOf("MSIE"))) {
+				String newFileName = URLEncoder.encode(filename, "UTF-8");
+				newFileName = newFileName.replace("+", "%20");
+				if (newFileName.length() > 150) {
+					newFileName = new String(filename.getBytes("GB2312"), "ISO8859-1");
+					newFileName = newFileName.replace(" ", "%20");
+				}
+				return newFileName;
+			}
+			if ((agent != null) && (-1 != agent.indexOf("Mozilla")))
+				return MimeUtility.encodeText(filename, "UTF-8", "B");
+			return filename;
+		} catch (Exception ex) {
+			return filename;
+		}
+	}
+
+	/**
+	 * 取config.xml中about配置
+	 */
+	@SuppressWarnings("unchecked")
+	public static String getXmlSetting(String key) {
+		if (setting == null) {
+			setting = (Map<String, Object>) ContextUtil.getBean("about");
+		}
+		if (setting != null && setting.containsKey(key)) {
+			return String.valueOf(setting.get(key));
+		}
+		return null;
+	}
+	/**
+	 * 根据语言及对应的消息名称,获得消息内容
+	 */
+	public static String getLocalMessage(String msgName) {
+		return getLocalMessage(msgName, SystemSession.getLang());
+	}
+	/**
+	 * 根据语言及对应的消息名称,获得消息内容
+	 */
+	public static String getLocalMessage(String msgName, String language) {
+		try {
+			// language = language == null ? "zh_CN" : language;
+			language = "zh_CN";
+			return ContextUtil.getApplicationContext().getMessage(msgName, null, Locale.CHINA);
+		} catch (Exception e) {
+			return msgName;
+		}
+	}
+	/**
+	 * 动态创建dataSource
+	 */
+	private final void createDataSource() {
+		String defaultSource = getXmlSetting("defaultSob");
+		ApplicationContext context = ContextUtil.getApplicationContext();
+		if (defaultSource != null && context.containsBean(defaultSource) && context.containsBean("enterpriseDao")) {
+			BasicDataSource dataSource = (BasicDataSource) context.getBean(defaultSource);
+			@SuppressWarnings("resource")
+			ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) context;
+			DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) applicationContext.getBeanFactory();
+			SpObserver.putSp(defaultSource);
+			EnterpriseDao dao = (EnterpriseDao) context.getBean("enterpriseDao");
+			List<Master> masters = dao.getMasters();
+			for (Master master : masters) {
+				// 比较特殊的,请直接在db-config.xml配置bean
+				if (!beanFactory.containsBean(master.getMa_name())) {
+					BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(BasicDataSource.class);
+					bdb.getBeanDefinition().setAttribute("id", master.getMa_name());
+					bdb.getBeanDefinition().setAttribute("destroy-method", "close");
+					// 支持多种类型数据源
+					bdb.addPropertyValue("driverClassName", StringUtil.nvl(master.getMa_driver(), dataSource.getDriverClassName()));
+					bdb.addPropertyValue("url", StringUtil.nvl(master.getMa_url(), dataSource.getUrl()));
+					bdb.addPropertyValue("username", master.getMa_user());
+					bdb.addPropertyValue("password", master.getMs_pwd());
+					beanFactory.registerBeanDefinition(master.getMa_name(), bdb.getBeanDefinition());
+				}
+			}
+		}
+	}
+
+	/**
+	 * 按master记录,动态创建dataSource<br>
+	 * 比如修改master表记录之后
+	 * 
+	 * @param master
+	 */
+	public static void createDataSource(Master master) {
+		String defaultSource = getXmlSetting("defaultSob");
+		ApplicationContext context = ContextUtil.getApplicationContext();
+		BasicDataSource dataSource = (BasicDataSource) context.getBean(defaultSource);
+		@SuppressWarnings("resource")
+		ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) context;
+		DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) applicationContext.getBeanFactory();
+		// 比较特殊的,请直接在db-config.xml配置bean
+		if (!beanFactory.containsBean(master.getMa_name())) {
+			BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(BasicDataSource.class);
+			bdb.getBeanDefinition().setAttribute("id", master.getMa_name());
+			bdb.getBeanDefinition().setAttribute("destroy-method", "close");
+			// 支持多种类型数据源
+			bdb.addPropertyValue("driverClassName", StringUtil.nvl(master.getMa_driver(), dataSource.getDriverClassName()));
+			bdb.addPropertyValue("url", StringUtil.nvl(master.getMa_url(), dataSource.getUrl()));
+			bdb.addPropertyValue("username", master.getMa_user());
+			bdb.addPropertyValue("password", master.getMs_pwd());
+			beanFactory.registerBeanDefinition(master.getMa_name(), bdb.getBeanDefinition());
+		}
+	}
+	/**
+	 * 以抛出异常的方式将信息交给MyExceptionHandler MyExceptionHandler会捕捉信息并传给前台 前台捕捉错误信息,并显示给用户
+	 * 
+	 * @param error
+	 *            要在前台显示的信息
+	 */
+	public static void showError(String error) {
+		if (error != null && error.length() > 0)
+			throw new SystemException(error);
+	}
+	/**
+	 * 字符串转化成数组, null和空字符自动去掉
+	 * 
+	 * @param str
+	 *            待转化字段
+	 * @param ch
+	 *            分割符
+	 */
+	public static String[] parseStr2Array(String str, String ch) {
+		String[] arr = new String[] {};
+		for (String s : str.split(ch)) {
+			if (s != null && !s.trim().equals("")) {
+				arr = Arrays.copyOf(arr, arr.length + 1);
+				arr[arr.length - 1] = s;
+			}
+		}
+		return arr;
+	}
+	
+	public static  <T> Map<Object,List<Map<T,Object>>> groupMap( List<Map<T,Object>> maps, String groupField) {
+		Map<Object,List<Map<T, Object>>> set = new HashMap<Object, List<Map<T,Object>>>();
+		List<Map<T, Object>> list = null;
+		for (Map<T, Object> map : maps) {
+			Object key = map.get(groupField);
+			if (StringUtil.hasText(key) && set.containsKey(key)) {
+				list = set.get(key);
+			} else {
+				list = new ArrayList<Map<T, Object>>();
+			}
+			list.add(map);
+			set.put(key, list);
+		}
+		return set;
+	}
+
+}

+ 308 - 0
src/com/mes/core/CollectionUtil.java

@@ -0,0 +1,308 @@
+package com.mes.core;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.springframework.util.StringUtils;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+public class CollectionUtil {
+
+	public static final int EXCLUDE = 0;
+	public static final int INCLUDE = 1;
+
+	/**
+	 * 取List里面的field的值
+	 */
+	public static Object[] pluck(List<Map<Object, Object>> list, String field) {
+		Object[] d = new Object[list.size()];
+		int index = 0;
+		for (Map<Object, Object> m : list) {
+			if (m.containsKey(field)) {
+				d[index++] = m.get(field);
+			}
+		}
+		return d;
+	}
+
+	public static Object[] pluck(ArrayList<HashMap<Object, Object>> list, String field) {
+		Object[] d = new Object[list.size()];
+		int index = 0;
+		for (Map<Object, Object> m : list) {
+			if (m.containsKey(field)) {
+				d[index++] = m.get(field);
+			}
+		}
+		return d;
+	}
+
+	/**
+	 * 过滤List
+	 */
+	public static List<Map<Object, Object>> filter(List<Map<Object, Object>> list, int type, Object... field) {
+		int i = 1, len = field.length;
+		if (len % 2 != 0) {
+			try {
+				throw new Exception("参数个数有误!");
+			} catch (Exception e) {
+
+			}
+		}
+		List<Map<Object, Object>> d = new ArrayList<Map<Object, Object>>();
+		if (type == CollectionUtil.INCLUDE) {
+			for (Map<Object, Object> m : list) {
+				i = 0;
+				for (Object f : field) {
+					if (i % 2 == 0) {
+						if (field[i + 1] != m.get(f) && !(field[i + 1]).equals(m.get(f))) {
+							break;
+						}
+					}
+					i++;
+					if (i == len) {
+						d.add(m);
+					}
+				}
+			}
+		} else {
+			for (Map<Object, Object> m : list) {
+				i = 0;
+				for (Object f : field) {
+					if (i % 2 == 0) {
+						if (field[i + 1] == m.get(f) || (field[i + 1]).equals(m.get(f))) {
+							break;
+						}
+					}
+					i++;
+					if (i == len) {
+						d.add(m);
+					}
+				}
+			}
+		}
+		return d;
+	}
+
+	public static Map<String, Object> findRecord(List<Map<String, Object>> list, String field, Object value) {
+		if (value != null) {
+			for (Map<String, Object> m : list) {
+				if (value.equals(m.get(field))) {
+					return m;
+				}
+			}
+		}
+		return null;
+	}
+
+	/**
+	 * 字段{field}的值是否重复
+	 * 
+	 * @param list
+	 * @param field
+	 * @return
+	 */
+	public static boolean isUnique(Collection<? extends Map<?, Object>> list, String field) {
+		if (list != null) {
+			Set<Object> objects = new HashSet<Object>();
+			Object object = null;
+			for (Map<?, Object> m : list) {
+				object = m.get(field);
+				if (object != null) {
+					if (objects.contains(object))
+						return false;
+					objects.add(object);
+				}
+			}
+		}
+		return true;
+	}
+
+	/**
+	 * 取字段{field}的重复项
+	 * 
+	 * @param list
+	 * @param field
+	 * @return
+	 */
+	public static String getRepeats(Collection<? extends Map<?, Object>> list, String field) {
+		if (list != null) {
+			Set<Object> objects = new HashSet<Object>();
+			Object object = null;
+			StringBuffer sb = new StringBuffer();
+			for (Map<?, Object> m : list) {
+				object = m.get(field);
+				if (object != null) {
+					if (objects.contains(object))
+						sb.append(object).append(" ");
+					objects.add(object);
+				}
+			}
+			if (sb.length() > 0)
+				return sb.toString();
+		}
+		return null;
+	}
+
+	public static String toString(List<Map<Object, Object>> list) {
+		JSONArray arr = new JSONArray();
+		JSONObject obj = null;
+		for (Map<Object, Object> map : list) {
+			if (map != null) {
+				obj = new JSONObject();
+				for (Object key : map.keySet()) {
+					obj.put(key, map.get(key));
+				}
+				arr.add(obj);
+			}
+		}
+		return arr.toString();
+	}
+
+	public static String toJSONString(Map<String, ?> map) {
+		return JSONObject.fromObject(map).toString();
+	}
+
+	public static String toString(Map<String, ?> map) {
+		Set<String> keys = map.keySet();
+		StringBuffer sb = new StringBuffer();
+		for (String k : keys) {
+			if (sb.length() > 0)
+				sb.append(",");
+			if (StringUtil.hasText(k))
+				sb.append(k).append(":");
+			sb.append(map.get(k));
+		}
+		return sb.toString();
+	}
+
+	public static String toString(Collection<String> paramArray) {
+		return toString(paramArray, ",");
+	}
+
+	public static String toString(String[] strs) {
+		StringBuffer sb = new StringBuffer();
+		for (Object k : strs) {
+			if (sb.length() > 0)
+				sb.append(",");
+			sb.append(k);
+		}
+		return sb.toString();
+	}
+
+	public static String toString(Collection<String> paramArray, String separator) {
+		StringBuffer sb = new StringBuffer();
+		for (String k : paramArray) {
+			if (sb.length() > 0)
+				sb.append(separator);
+			sb.append(k);
+		}
+		return sb.toString();
+	}
+
+	/**
+	 * 用类<T>的变量key的get方法取变量key的值,并用separator连接成字符串
+	 * 
+	 * @param paramArray
+	 * @param key
+	 * @param separator
+	 * @return
+	 */
+	public static <T> String getParamString(Collection<T> paramArray, String key, String separator) {
+		StringBuffer sb = new StringBuffer();
+		if (!isEmpty(paramArray)) {
+			String methodGet = "get" + StringUtils.capitalize(key);
+			Method method = null;
+			for (T param : paramArray) {
+				try {
+					if (method == null)
+						method = param.getClass().getMethod(methodGet, new Class[] {});
+					Object val = method.invoke(param, new Object[] {});
+					if (val != null) {
+						if (sb.length() > 0)
+							sb.append(separator);
+						sb.append(val);
+					}
+				} catch (NoSuchMethodException e) {
+					e.printStackTrace();
+				} catch (SecurityException e) {
+					e.printStackTrace();
+				} catch (IllegalAccessException e) {
+					e.printStackTrace();
+				} catch (IllegalArgumentException e) {
+					e.printStackTrace();
+				} catch (InvocationTargetException e) {
+					e.printStackTrace();
+				}
+			}
+		}
+		return sb.toString();
+	}
+
+	public static String toSqlString(Set<String> strs) {
+		StringBuffer sb = new StringBuffer();
+		for (String k : strs) {
+			if (sb.length() > 0)
+				sb.append(",");
+			sb.append("'").append(k).append("'");
+		}
+		return sb.toString();
+	}
+
+	public static String toSqlString(String[] strs) {
+		StringBuffer sb = new StringBuffer();
+		for (String k : strs) {
+			if (sb.length() > 0)
+				sb.append(",");
+			sb.append("'").append(k).append("'");
+		}
+		return sb.toString();
+	}
+
+	public static String pluckSqlString(Collection<? extends Map<?, Object>> list, String field) {
+		StringBuffer sb = new StringBuffer();
+		for (Map<?, Object> m : list) {
+			if (m.containsKey(field)) {
+				if (sb.length() > 0)
+					sb.append(",");
+				sb.append("'").append(m.get(field)).append("'");
+			}
+		}
+		return sb.toString();
+	}
+
+	/**
+	 * 按给定size切割
+	 * 
+	 * @param paramList
+	 * @param paramSize
+	 * @return
+	 */
+	public static <T> List<List<T>> split(List<T> paramList, int paramSize) {
+		List<List<T>> lists = new ArrayList<List<T>>();
+		for (int j = 0, l = paramList.size(), i = l / paramSize; j <= i; j++) {
+			lists.add(paramList.subList(j * paramSize, Math.min((j + 1) * paramSize, l)));
+		}
+		return lists;
+	}
+
+	public static boolean isEmpty(Collection<?> paramArray) {
+		return (paramArray == null) || (paramArray.size() == 0);
+	}
+	/**
+	 *给list倒序
+	 * */
+	public static <T> List<T> reverse(List<T> lists){
+		Collections.reverse(lists);
+		return lists;
+	}
+}

+ 71 - 0
src/com/mes/core/Constant.java

@@ -0,0 +1,71 @@
+package com.mes.core;
+
+import com.mes.core.BaseUtil;
+
+/**
+ * 系统常量
+ * 
+ * @author yingp
+ * 
+ */
+public class Constant {
+
+	// 日期格式
+
+	public final static String YM = "yyyy-MM";
+
+	public final static String YMD = "yyyy-MM-dd";
+
+	public final static String YMD_HM = "yyyy-MM-dd HH:mm";
+
+	public final static String YMD_HMS = "yyyy-MM-dd HH:mm:ss";
+
+	public final static String ORACLE_YMD = "yyyy-MM-dd";
+
+	public final static String ORACLE_YMD_HMS = "yyyy-MM-dd HH24:mi:ss";
+
+	/**
+	 * 是
+	 */
+	public static final short YES = 1;
+	/**
+	 * 是
+	 */
+	public static final short yes = -1;
+	/**
+	 * 是
+	 */
+	public static final String TRUE = "T";
+	/**
+	 * 否
+	 */
+	public static final short NO = 0;
+	/**
+	 * 否
+	 */
+	public static final String FALSE = "F";
+
+	public static final int ORACLE_MAX_TABLE_SIZE = 999;
+
+	/**
+	 * @return 管理平台地址
+	 */
+	public static String manageHost() {
+		return BaseUtil.getXmlSetting("host.manage");
+	}
+
+	/**
+	 * @return B2B平台地址
+	 */
+	public static String b2bHost() {
+		return BaseUtil.getXmlSetting("host.b2b");
+	}
+
+	/**
+	 * @return B2B平台地址
+	 */
+	public static String b2cHost() {
+		return BaseUtil.getXmlSetting("host.b2c");
+	}
+
+}

+ 83 - 0
src/com/mes/core/ContextUtil.java

@@ -0,0 +1,83 @@
+package com.mes.core;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationEvent;
+
+public class ContextUtil {
+	private static ApplicationContext applicationContext;
+
+	public static void setApplicationContext(ApplicationContext applicationContext) {
+		synchronized (ContextUtil.class) {
+			ContextUtil.applicationContext = applicationContext;
+			ContextUtil.class.notifyAll();
+		}
+	}
+
+	public static ApplicationContext getApplicationContext() {
+		synchronized (ContextUtil.class) {
+			while (applicationContext == null) {
+				try {
+					ContextUtil.class.wait(6000);
+				} catch (InterruptedException ex) {
+				}
+			}
+			return applicationContext;
+		}
+	}
+
+	/**
+	 * 获取bean
+	 * 
+	 * @param name
+	 * @return
+	 */
+	public static Object getBean(String name) {
+		try {
+			return getApplicationContext().getBean(name);
+		} catch (Exception e) {
+			return null;
+		}
+		
+	}
+
+	/**
+	 * 获取bean
+	 * 
+	 * @param cls
+	 * @return
+	 */
+	public static <T> T getBean(Class<T> cls) {
+		return getApplicationContext().getBean(cls);
+	}
+
+	/**
+	 * 动态注册bean
+	 * 
+	 * @param beanName
+	 *            bean组件名称
+	 * @param className
+	 *            类名
+	 */
+	public static void registerBean(String beanName, String className) {
+		try {
+			getApplicationContext().getAutowireCapableBeanFactory().createBean(Class.forName(className));
+		} catch (BeansException e) {
+			throw new SystemException("组件注册失败");
+		} catch (IllegalStateException e) {
+			throw new SystemException("组件注册失败");
+		} catch (ClassNotFoundException e) {
+			throw new SystemException("组件注册失败");
+		}
+	}
+
+	/**
+	 * 触发事件
+	 * 
+	 * @param event
+	 */
+	public static void publishEvent(ApplicationEvent event) {
+		getApplicationContext().publishEvent(event);
+	}
+
+}

+ 550 - 0
src/com/mes/core/DateUtil.java

@@ -0,0 +1,550 @@
+package com.mes.core;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+public class DateUtil {
+	static final SimpleDateFormat ym = new SimpleDateFormat("yyyyMM");
+	static final SimpleDateFormat YM = new SimpleDateFormat("yyyy-MM");
+	static final SimpleDateFormat YMD = new SimpleDateFormat("yyyy-MM-dd");
+	static final SimpleDateFormat YMD_HMS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+	public static String format(Date date, String f) {
+		if (date == null) {
+			date = new Date();
+		}
+		if (f == null) {
+			return YMD.format(date);
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat(f);
+		return sdf.format(date);
+	}
+
+	public static String format(java.sql.Date date, String f) {
+		if (date == null) {
+			return currentDateString(f);
+		} else {
+			if (f == null) {
+				return YMD.format(date);
+			}
+			SimpleDateFormat sdf = new SimpleDateFormat(f);
+			return sdf.format(date);
+		}
+	}
+
+	public static Date parse(String date, String f) {
+		if (date == null) {
+			return new Date();
+		}
+		if (f == null) {
+			try {
+				return date.contains(" ") ? YMD_HMS.parse(date) : YMD.parse(date);
+			} catch (ParseException e) {
+				return new Date();
+			}
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat(f);
+		try {
+			return sdf.parse(date);
+		} catch (ParseException e) {
+			return new Date();
+		}
+	}
+
+	/**
+	 * 获取日期年份
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static int getYear(String date) throws ParseException {
+		date = date == null ? format(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(YMD.parse(date));
+		return calendar.get(Calendar.YEAR);
+	}
+
+	/**
+	 * 获取日期年份
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static int getYear(Date date) throws ParseException {
+		date = date == null ? parse(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		return calendar.get(Calendar.YEAR);
+	}
+
+	/**
+	 * 获取日期月份
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static int getMonth(String date) throws ParseException {
+		date = date == null ? format(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(YMD.parse(date));
+		return (calendar.get(Calendar.MONTH) + 1);
+	}
+
+	/**
+	 * 获取日期月份
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static int getMonth(Date date) throws ParseException {
+		date = date == null ? parse(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		return (calendar.get(Calendar.MONTH) + 1);
+	}
+
+	/**
+	 * 获取日期号
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static int getDay(String date) throws ParseException {
+		date = date == null ? format(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(YMD.parse(date));
+		return calendar.get(Calendar.DAY_OF_MONTH);
+	}
+
+	/**
+	 * 获取日期号
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static int getDay(Date date) throws ParseException {
+		date = date == null ? parse(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		return calendar.get(Calendar.DAY_OF_MONTH);
+	}
+
+	/**
+	 * 获取月份起始日期
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static String getMinMonthDate(String date) {
+		date = date == null ? format(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		try {
+			calendar.setTime(YMD.parse(date));
+		} catch (ParseException e) {
+			calendar.setTime(new Date());
+		}
+		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
+		return YMD.format(calendar.getTime());
+	}
+
+	/**
+	 * 获取月份起始日期
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static String getMinMonthDate(Date date) {
+		date = date == null ? parse(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
+		return YMD.format(calendar.getTime());
+	}
+
+	/**
+	 * 获取月份最后日期
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static String getMaxMonthDate(String date) {
+		date = date == null ? format(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		try {
+			calendar.setTime(YMD.parse(date));
+		} catch (ParseException e) {
+			calendar.setTime(new Date());
+		}
+		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
+		return YMD.format(calendar.getTime());
+	}
+
+	/**
+	 * 获取月份最后日期
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static String getMaxMonthDate(Date date) {
+		date = date == null ? parse(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
+		return YMD.format(calendar.getTime());
+	}
+
+	/**
+	 * 当前时间
+	 * 
+	 * @return <h3>String</h3>
+	 */
+	public static String getCurrentDate() {
+		return format(new Date(), null);
+	}
+
+	/**
+	 * 截取指定日期的年月
+	 * 
+	 * @param date
+	 * @return
+	 */
+	public static Integer getYearmonth(Date date) {
+		if (date == null) {
+			date = new Date();
+		}
+		return Integer.parseInt(ym.format(date));
+	}
+
+	/**
+	 * 截取指定日期的年月
+	 * 
+	 * @param date
+	 * @return
+	 */
+	public static Integer getYearmonth(String date) {
+		return Integer.parseInt(ym.format(parse(date, null)));
+	}
+
+	/**
+	 * 获取当前年月
+	 * 
+	 * @return
+	 */
+	public static Integer getYearmonth() {
+		return Integer.parseInt(ym.format(new Date()));
+	}
+
+	public static int compare(String date1, String date2) {
+		try {
+			Date dt1 = YMD.parse(date1);
+			Date dt2 = YMD.parse(date2);
+			if (dt1.getTime() > dt2.getTime()) {
+				return 1;
+			} else if (dt1.getTime() < dt2.getTime()) {
+				return -1;
+			} else {
+				return 0;
+			}
+		} catch (Exception exception) {
+			exception.printStackTrace();
+		}
+		return 0;
+	}
+
+	/**
+	 * 获取特定日期是星期几
+	 * 
+	 * @return
+	 */
+	public static String getWeekDay(String DateStr) {
+		SimpleDateFormat formatYMD = new SimpleDateFormat("yyyy-MM-dd");// formatYMD表示的是yyyy-MM-dd格式
+		SimpleDateFormat formatD = new SimpleDateFormat("E");// "E"表示"day in week"
+		Date d = null;
+		String weekDay = "";
+		try {
+			d = formatYMD.parse(DateStr);// 将String 转换为符合格式的日期
+			weekDay = formatD.format(d);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		// System.out.println("日期:"+DateStr+" : "+weekDay);
+		return weekDay;
+	}
+
+	public static int getWeekDay1(String DateStr) {// 返回日期对应数字
+		SimpleDateFormat formatYMD = new SimpleDateFormat("yyyy-MM-dd");// formatYMD表示的是yyyy-MM-dd格式
+		Date d = null;
+		int weekDay = 0;
+		try {
+			d = formatYMD.parse(DateStr);// 将String 转换为符合格式的日期
+			Calendar calendar = Calendar.getInstance();
+			calendar.setTime(d);
+			weekDay = calendar.get(Calendar.DAY_OF_WEEK) - 1;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return weekDay;
+	}
+
+	/**
+	 * 获取特定时间段内有哪几日
+	 * 
+	 * @return
+	 */
+	public static List<Object> findDates(String start_time, String end_time) throws ParseException {
+		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+		Date date1 = df.parse(start_time);
+		Date date2 = df.parse(end_time);
+		int s = (int) ((date2.getTime() - date1.getTime()) / (24 * 60 * 60 * 1000));
+		List<Object> objects = new ArrayList<Object>();
+		String value = "";
+		if (s + 1 > 0) {
+			for (int i = 0; i <= s; i++) {
+				long todayDate = date1.getTime() + (long) i * 24 * 60 * 60 * 1000;
+				Date tmDate = new Date(todayDate);
+				value = new SimpleDateFormat("yyyy-MM-dd").format(tmDate);
+				objects.add(value);
+			}
+		}
+		return objects;
+	}
+
+	/**
+	 * 获取特定时间段内有多少天
+	 * 
+	 * @return
+	 */
+	public static int countDates(String start_time, String end_time) throws ParseException {
+		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+		Date date1 = df.parse(start_time);
+		Date date2 = df.parse(end_time);
+		int s = (int) ((date2.getTime() - date1.getTime()) / (24 * 60 * 60 * 1000));
+		return s;
+	}
+
+	/**
+	 * 日期转化成oracle格式to_date('2012-12-12', 'yyyy-MM-dd')
+	 * 
+	 * @param format
+	 *            format type,for example: 'yyyy-MM-dd', 'yyyy-MM-dd HH:mm:ss'
+	 * @param date
+	 *            date{type=java.util.Date}
+	 */
+	public static String parseDateToOracleString(String format, Date date) {
+		if (format == null) {
+			format = Constant.YMD;
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat(format);
+		if (date == null) {
+			date = new Date();
+		}
+		if (Constant.YMD_HMS.toUpperCase().equals(format.toUpperCase())) {
+			format = Constant.ORACLE_YMD_HMS;
+		} else {
+			format = Constant.ORACLE_YMD;
+		}
+		return "to_date('" + sdf.format(date) + "','" + format + "')";
+	}
+
+	/**
+	 * 日期转化成oracle格式to_date('2012-12-12', 'yyyy-MM-dd')
+	 * 
+	 * @param format
+	 *            format type,for example: 'yyyy-MM-dd', 'yyyy-MM-dd HH:mm:ss'
+	 * @param dateString
+	 *            date{type=string}
+	 */
+	public static String parseDateToOracleString(String format, String dateString) {
+		if (format == null) {
+			format = Constant.YMD;
+		}
+		if (dateString == null || "".equals(dateString) || "null".equals(dateString)) {
+			SimpleDateFormat sdf = new SimpleDateFormat(format);
+			dateString = sdf.format(new Date());
+		}
+		if (Constant.YMD_HMS.toUpperCase().equals(format.toUpperCase())) {
+			format = Constant.ORACLE_YMD_HMS;
+		} else {
+			format = Constant.ORACLE_YMD;
+		}
+		return "to_date('" + dateString + "','" + format + "')";
+	}
+
+	/**
+	 * Date转化成字符串格式
+	 * 
+	 * @param f
+	 *            format格式;若为空,则默认为yyyy-MM-dd
+	 */
+	public static String parseDateToString(Date date, String f) {
+		if (f == null) {
+			f = Constant.YMD;
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat(f);
+		if (date == null) {
+			date = new Date();
+		}
+		return sdf.format(date);
+	}
+
+	/**
+	 * 形如{2012-12-21}或{2012-12-21 12:12:12}字符串格式的日期转化成java.util.Date类型
+	 * 
+	 * @param date
+	 *            string日期;若为空或格式错误,则返回当前时间
+	 * @param f
+	 *            format格式;若为空,则默认为yyyy-MM-dd
+	 * @return java.util.Date类型日期
+	 */
+	public static Date parseStringToDate(String date, String f) {
+		if (f == null) {
+			f = Constant.YMD;
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat(f);
+		if (date == null) {
+			return new Date();
+		}
+		try {
+			return sdf.parse(date);
+		} catch (ParseException e) {
+			return new Date();
+		}
+	}
+
+	/**
+	 * 当前时间的字符串格式
+	 * 
+	 * @param f
+	 *            format格式;若为空,则默认为yyyy-MM-dd
+	 */
+	public static String currentDateString(String f) {
+		if (f == null) {
+			f = Constant.YMD;
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat(f);
+		return sdf.format(new Date());
+	}
+
+	/**
+	 * 借贷合同月份处理
+	 */
+	public static int getMonthSpace(Date date1, Date date2) throws ParseException {
+		int iMonth = 0;
+		int flag = 0;
+		try {
+			Calendar objCalendarDate1 = Calendar.getInstance();
+			objCalendarDate1.setTime(date1);
+
+			Calendar objCalendarDate2 = Calendar.getInstance();
+			objCalendarDate2.setTime(date2);
+
+			if (objCalendarDate2.equals(objCalendarDate1))
+				return 0;
+			if (objCalendarDate1.after(objCalendarDate2)) {
+				Calendar temp = objCalendarDate1;
+				objCalendarDate1 = objCalendarDate2;
+				objCalendarDate2 = temp;
+			}
+			if (objCalendarDate2.get(Calendar.DAY_OF_MONTH) > objCalendarDate1.get(Calendar.DAY_OF_MONTH))
+				flag = 1;
+
+			if (objCalendarDate2.get(Calendar.YEAR) > objCalendarDate1.get(Calendar.YEAR)) {
+				iMonth = ((objCalendarDate2.get(Calendar.YEAR) - objCalendarDate1.get(Calendar.YEAR)) * 12
+						+ objCalendarDate2.get(Calendar.MONTH) + flag)
+						- objCalendarDate1.get(Calendar.MONTH);
+			} else {
+				iMonth = objCalendarDate2.get(Calendar.MONTH) + flag - objCalendarDate1.get(Calendar.MONTH);
+			}
+
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return iMonth;
+	}
+
+	/**
+	 * 月份往前或往后n天
+	 */
+	public static Date overDate(Date date, int num) {
+		date = date == null ? new Date() : date;
+		Calendar calendar = new GregorianCalendar();
+		calendar.setTime(date);
+		calendar.add(Calendar.DATE, num);
+		date = calendar.getTime();
+		return date;
+	}
+
+	/**
+	 * 月份加减
+	 * 
+	 * @param date
+	 * @param increase
+	 * @return
+	 */
+	public static Integer addMonth(Date date, int increase) {
+		if (date == null)
+			date = new Date();
+		Calendar calendar = new GregorianCalendar();
+		calendar.setTime(date);
+		calendar.add(Calendar.MONTH, increase);
+		return getYearmonth(calendar.getTime());
+	}
+
+	/**
+	 * 月份加减
+	 * 
+	 * @param month
+	 * @param increase
+	 * @return
+	 */
+	public static Integer addMonth(Integer month, int increase) {
+		Calendar calendar = new GregorianCalendar();
+		try {
+			calendar.setTime(ym.parse(String.valueOf(month)));
+		} catch (ParseException e) {
+			e.printStackTrace();
+		}
+		calendar.add(Calendar.MONTH, increase);
+		return getYearmonth(calendar.getTime());
+	}
+
+	/**
+	 * 时间添加小时数
+	 * */
+	public static Date addHours(Date date, float hours) {
+		Calendar ca = Calendar.getInstance();
+		ca.setTime(date);
+		ca.add(Calendar.MINUTE, (int) (hours * 60));
+		return ca.getTime();
+	}
+
+	/**
+	 * 判断日期是否合法
+	 */
+	public static boolean isValidDate(String dateString, String f) {
+		SimpleDateFormat sdf = new SimpleDateFormat(f);
+		sdf.setLenient(false);
+		try {
+			sdf.parse(dateString);
+		} catch (ParseException e) {
+			e.printStackTrace();
+			return false;
+		}
+		return true;
+	}
+}

+ 61 - 0
src/com/mes/core/FlexJsonUtil.java

@@ -0,0 +1,61 @@
+package com.mes.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import flexjson.JSONDeserializer;
+import flexjson.JSONSerializer;
+
+/**
+ * <h1>flexjson</h1><br>
+ * 1.序列化json字符串时较快,优于jackson<br>
+ * 2.但是数据量较大时,序列化有问题<br>
+ * 3.反序列化较慢
+ * 
+ * @author yingp
+ * 
+ */
+public class FlexJsonUtil {
+
+	public static <T> T fromJson(String json, Class<?> cls) {
+		return new JSONDeserializer<T>().use(null, cls).deserialize(json);
+	}
+
+	public static <K, V> Map<K, V> fromJson(String json) {
+		if (json != null) {
+			Map<K, V> map = new HashMap<K, V>();
+			return new JSONDeserializer<Map<K, V>>().use(null, map.getClass())
+					.deserialize(json);
+		}
+		return null;
+	}
+
+	public String toJson() {
+		return new JSONSerializer().exclude("*.class").serialize(this);
+	}
+
+	public static String toJson(Object obj) {
+		return new JSONSerializer().exclude("*.class").serialize(obj);
+	}
+
+	public static String toJsonDeep(Object obj) {
+		return new JSONSerializer().exclude("*.class").deepSerialize(obj);
+	}
+
+	public static <T> String toJsonArray(Collection<?> collection) {
+		return new JSONSerializer().exclude("*.class").serialize(collection);
+	}
+
+	public static <T> String toJsonArrayDeep(Collection<?> collection) {
+		return new JSONSerializer().exclude("*.class")
+				.deepSerialize(collection);
+	}
+
+	public static <T> List<T> fromJsonArray(String json, Class<?> cls) {
+		return new JSONDeserializer<List<T>>().use(null, ArrayList.class)
+				.use("values", cls).deserialize(json);
+	}
+}

+ 693 - 0
src/com/mes/core/HttpUtil.java

@@ -0,0 +1,693 @@
+package com.mes.core;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.apache.http.Consts;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.entity.mime.MultipartEntityBuilder;
+import org.apache.http.entity.mime.content.FileBody;
+import org.apache.http.entity.mime.content.StringBody;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+import com.mes.core.encry.HmacUtils;
+
+/**
+ * HTTP工具类,封装http请求
+ * 
+ * @author suntg
+ * @date 2015年3月5日14:20:40
+ */
+public class HttpUtil {
+
+	/**
+	 * 发送GET请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendGetRequest(String url, Map<String, String> params) throws Exception {
+		return sendGetRequest(url, params, false, null);
+	}
+
+	/**
+	 * 发送GET请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否发送签名
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendGetRequest(String url, Map<String, String> params, boolean sign, String signKey) throws Exception {
+		return sendRequest(RequestMethod.GET, url, params, sign, signKey);
+	}
+
+	/**
+	 * 发送GET请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否发送签名
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendGetRequest(String url, Map<String, String> params, boolean sign) throws Exception {
+		return sendRequest(RequestMethod.GET, url, params, sign, null);
+	}
+
+	/**
+	 * 发送POST请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendPostRequest(String url, Map<String, String> params) throws Exception {
+		return sendPostRequest(url, params, false, null);
+	}
+
+	/**
+	 * 发送POST请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendPostRequest(String url, List<?> datas) throws Exception {
+		return sendPostRequest(url, datas, false, null);
+	}
+
+	/**
+	 * 发送POST请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否发送签名
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendPostRequest(String url, Map<String, String> params, boolean sign, String signKey) throws Exception {
+		return sendRequest(RequestMethod.POST, url, params, sign, signKey);
+	}
+
+	/**
+	 * 发送POST请求
+	 * 
+	 * @param url
+	 * @param datas
+	 * @param sign
+	 *            是否发送签名
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendPostRequest(String url, List<?> datas, boolean sign, String signKey) throws Exception {
+		return sendRequest(RequestMethod.POST, url, datas, sign, signKey);
+	}
+	
+	/**
+	 * 发送POST请求
+	 * 
+	 * <pre>
+	 * 使用默认密钥
+	 * </pre>
+	 * 
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否发送签名
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendPostRequest(String url, Map<String, String> params, boolean sign) throws Exception {
+		return sendRequest(RequestMethod.POST, url, params, sign, null);
+	}
+
+	/**
+	 * 发送POST请求
+	 * 
+	 * <pre>
+	 * 使用默认密钥
+	 * </pre>
+	 * 
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否发送签名
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendPostRequest(String url, List<?> datas, boolean sign) throws Exception {
+		return sendRequest(RequestMethod.POST, url, datas, sign, null);
+	}
+	/**
+	 * 发送PUT请求
+	 * 
+	 * <pre>
+	 * 使用默认密钥
+	 * </pre>
+	 * 
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否发送签名
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendPutRequest(String url, List<?> datas, boolean sign) throws Exception {
+		return sendRequest(RequestMethod.PUT, url, datas, sign, null);
+	}
+	/**
+	 * 发送PUT请求
+	 * 
+	 * <pre>
+	 * 使用默认密钥
+	 * </pre>
+	 * 
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否发送签名
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendPutRequest(String url, Map<String, String> params, boolean sign) throws Exception {
+		return sendRequest(RequestMethod.PUT, url, params, sign, null);
+	}
+	/**
+	 * 发送PUT请求
+	 * 
+	 * @param url
+	 * @param datas
+	 * @param sign
+	 *            是否发送签名
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendPutRequest(String url, List<?> datas, boolean sign, String signKey) throws Exception {
+		return sendRequest(RequestMethod.PUT, url, datas, sign, signKey);
+	}
+
+	/**
+	 * 发送PUT请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendPutRequest(String url, List<?> datas) throws Exception {
+		return sendPutRequest(url, datas, false, null);
+	}
+
+	/**
+	 * 发送DELETE请求
+	 * 
+	 * @param url
+	 * @param params
+	 * 
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendDeleteRequest(String url, Map<String, String> params) throws Exception {
+		return sendDeleteRequest(url, params, false, null);
+	}
+
+	/**
+	 * 发送DELETE请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否发送签名
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendDeleteRequest(String url, Map<String, String> params, boolean sign, String signKey) throws Exception {
+		return sendRequest(RequestMethod.DELETE, url, params, sign, signKey);
+	}
+
+	/**
+	 * 发送DELETE请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否发送签名
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendDeleteRequest(String url, Map<String, String> params, boolean sign) throws Exception {
+		return sendRequest(RequestMethod.DELETE, url, params, sign, null);
+	}
+
+	/**
+	 * 发起http请求
+	 * 
+	 * @param method
+	 *            请求方法GET、POST、PUT、DELETE
+	 * @param url
+	 *            请求链接
+	 * @param params
+	 *            参数
+	 * @param sign
+	 *            是否签名
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendRequest(RequestMethod method, String url, Map<String, String> params, boolean sign, String signKey)
+			throws Exception {
+		switch (method) {
+		case GET:
+			return sendHttpUriRequest(new HttpGet(getRequestUrl(url, params, sign, signKey)));
+		case POST:
+			return sendHttpEntityEnclosingRequest(new HttpPost(getRequestUrl(url, sign, signKey)), params);
+		case PUT:
+			return sendHttpEntityEnclosingRequest(new HttpPut(getRequestUrl(url, sign, signKey)), params);
+		case DELETE:
+			return sendHttpUriRequest(new HttpDelete(getRequestUrl(url, params, sign, signKey)));
+		default:
+			return sendHttpUriRequest(new HttpGet(getRequestUrl(url, params, sign, signKey)));
+		}
+	}
+
+	/**
+	 * 发起http请求
+	 * 
+	 * @param method
+	 *            请求方法POST、PUT
+	 * @param url
+	 *            请求链接
+	 * @param datas
+	 *            参数
+	 * @param sign
+	 *            是否签名
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendRequest(RequestMethod method, String url, List<?> datas, boolean sign, String signKey) throws Exception {
+		switch (method) {
+		case POST:
+			return sendHttpEntityEnclosingRequest(new HttpPost(getRequestUrl(url, sign, signKey)), datas);
+		case PUT:
+			return sendHttpEntityEnclosingRequest(new HttpPut(getRequestUrl(url, sign, signKey)), datas);
+		default:
+			return sendHttpEntityEnclosingRequest(new HttpPost(getRequestUrl(url, sign, signKey)), datas);
+		}
+	}
+
+	/**
+	 * 发起GET、DELETE请求
+	 * 
+	 * @param request
+	 * @param params 
+	 * @return
+	 * @throws Exception
+	 */
+	private static Response sendHttpUriRequest(HttpRequestBase request) throws Exception {
+		CloseableHttpClient httpClient = HttpClients.createDefault();
+		CloseableHttpResponse response = null;
+		try {	
+			response = httpClient.execute(request);
+			return Response.getResponse(response);
+		} finally {
+			try {
+				httpClient.close();
+			} catch (IOException e) {
+			}
+			if (response != null) {
+				try {
+					response.close();
+				} catch (IOException e) {
+				}
+			}
+		}
+	}
+
+	/**
+	 * 发起POST、PUT请求
+	 * 
+	 * @param request
+	 * @param params
+	 * @return
+	 * @throws Exception
+	 */
+	private static Response sendHttpEntityEnclosingRequest(HttpEntityEnclosingRequestBase request, Map<String, String> params)
+			throws Exception {
+		CloseableHttpClient httpClient = HttpClients.createDefault();
+		CloseableHttpResponse response = null;
+		try {
+			List<NameValuePair> nvps = new ArrayList<NameValuePair>();
+			if (params != null && !params.isEmpty()) {
+				Set<Entry<String, String>> entrys = params.entrySet();
+				for (Map.Entry<String, String> entry : entrys) {
+					nvps.add(new BasicNameValuePair(entry.getKey(), URLEncoder.encode(entry.getValue(), "UTF-8")));
+				}
+			}
+			request.setEntity(new UrlEncodedFormEntity(nvps));
+			response = httpClient.execute(request);
+			return Response.getResponse(response);
+		} finally {
+			request.releaseConnection();
+			try {
+				httpClient.close();
+			} catch (IOException e) {
+			}
+			if (response != null) {
+				try {
+					response.close();
+				} catch (IOException e) {
+				}
+			}
+		}
+	}
+
+	/**
+	 * 发起POST、PUT请求
+	 * 
+	 * @param request
+	 * @param datas
+	 * @return
+	 * @throws Exception
+	 */
+	private static Response sendHttpEntityEnclosingRequest(HttpEntityEnclosingRequestBase request, List<?> datas) throws Exception {
+		CloseableHttpClient httpClient = HttpClients.createDefault();
+		CloseableHttpResponse response = null;
+		try {
+			if (datas != null && !datas.isEmpty()) {
+				request.setEntity(new StringEntity(FlexJsonUtil.toJsonArrayDeep(datas), ContentType.create("text/plain", Consts.UTF_8)));
+			}
+			response = httpClient.execute(request);
+			return Response.getResponse(response);
+		} finally {
+			request.releaseConnection();
+			try {
+				httpClient.close();
+			} catch (IOException e) {
+			}
+			if (response != null) {
+				try {
+					response.close();
+				} catch (IOException e) {
+				}
+			}
+		}
+	}
+
+	/**
+	 * 将请求参数添加到链接中
+	 * 
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否签名
+	 * @return
+	 * @throws UnsupportedEncodingException
+	 */
+	public static String getRequestUrl(String url, Map<String, String> params, boolean sign) throws UnsupportedEncodingException {
+		StringBuilder buf = new StringBuilder(url);
+		if (url.indexOf("?") == -1)
+			buf.append("?");
+		else if (!url.endsWith("&"))
+			buf.append("&");
+		// 如果是GET请求,则请求参数在URL中
+		if (params != null && !params.isEmpty()) {
+			Set<Entry<String, String>> entrys = params.entrySet();
+			for (Map.Entry<String, String> entry : entrys) {
+				buf.append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue(), "UTF-8")).append("&");
+			}
+		}
+		if (sign) {
+			// 加时间戳,保持相同请求每次签名均不一样
+			buf.append("_timestamp=").append(System.currentTimeMillis());
+			String message = buf.toString();
+			// 对请求串进行签名
+			buf.append("&_signature=").append(HmacUtils.encode(message));
+		} else
+			buf.deleteCharAt(buf.length() - 1);
+		return buf.toString();
+	}
+
+	/**
+	 * 将请求参数添加到链接中
+	 * 
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否签名
+	 * @param signKey
+	 *            签名密钥
+	 * @return
+	 * @throws UnsupportedEncodingException
+	 */
+	public static String getRequestUrl(String url, Map<String, String> params, boolean sign, String signKey)
+			throws UnsupportedEncodingException {
+		if (sign && signKey == null)
+			return getRequestUrl(url, params, sign);
+		StringBuilder buf = new StringBuilder(url);
+		if (url.indexOf("?") == -1)
+			buf.append("?");
+		else if (!url.endsWith("&"))
+			buf.append("&");
+		// 如果是GET请求,则请求参数在URL中
+		if (params != null && !params.isEmpty()) {
+			Set<Entry<String, String>> entrys = params.entrySet();
+			for (Map.Entry<String, String> entry : entrys) {
+				buf.append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue(), "UTF-8")).append("&");
+			}
+		}
+		if (sign) {
+			// 加时间戳,保持相同请求每次签名均不一样
+			buf.append("_timestamp=").append(System.currentTimeMillis());
+			String message = buf.toString();
+			// 对请求串进行签名
+			buf.append("&_signature=").append(HmacUtils.encode(message, signKey));
+		} else
+			buf.deleteCharAt(buf.length() - 1);
+		return buf.toString();
+	}
+
+	/**
+	 * 将签名信息添加到链接中
+	 * 
+	 * @param url
+	 * @param sign
+	 *            是否签名
+	 * @return
+	 * @throws UnsupportedEncodingException
+	 */
+	private static String getRequestUrl(String url, boolean sign, String signKey) throws UnsupportedEncodingException {
+		return getRequestUrl(url, null, sign, signKey);
+	}
+
+	/**
+	 * 将输入流转为字节数组
+	 * 
+	 * @param inStream
+	 * @return
+	 * @throws Exception
+	 */
+	public static byte[] read2Byte(InputStream inStream) throws Exception {
+		ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
+		byte[] buffer = new byte[1024];
+		int len = 0;
+		while ((len = inStream.read(buffer)) != -1) {
+			outSteam.write(buffer, 0, len);
+		}
+		outSteam.close();
+		inStream.close();
+		return outSteam.toByteArray();
+	}
+
+	/**
+	 * 将输入流转为字符串
+	 * 
+	 * @param inStream
+	 * @return
+	 * @throws Exception
+	 */
+	public static String read2String(InputStream inStream) throws Exception {
+		ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
+		byte[] buffer = new byte[1024];
+		int len = 0;
+		while ((len = inStream.read(buffer)) != -1) {
+			outSteam.write(buffer, 0, len);
+		}
+		try {
+			outSteam.close();
+			inStream.close();
+		} catch (Exception e) {
+
+		}
+		return new String(outSteam.toByteArray(), "UTF-8");
+	}
+
+	/**
+	 * 发送xml数据
+	 * 
+	 * @param path
+	 *            请求地址
+	 * @param xml
+	 *            xml数据
+	 * @param encoding
+	 *            编码
+	 * @return
+	 * @throws Exception
+	 */
+	public static byte[] postXml(String path, String xml, String encoding) throws Exception {
+		byte[] data = xml.getBytes(encoding);
+		URL url = new URL(path);
+		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+		conn.setRequestMethod("POST");
+		conn.setDoOutput(true);
+		conn.setRequestProperty("Content-Type", "text/xml; charset=" + encoding);
+		conn.setRequestProperty("Content-Length", String.valueOf(data.length));
+		conn.setConnectTimeout(5 * 1000);
+		OutputStream outStream = conn.getOutputStream();
+		outStream.write(data);
+		outStream.flush();
+		outStream.close();
+		if (conn.getResponseCode() == HttpStatus.OK.value()) {
+			return read2Byte(conn.getInputStream());
+		}
+		return null;
+	}
+
+	/**
+	 * http上传文件
+	 * 
+	 * @param postUrl
+	 *            请求地址
+	 * @param filePath
+	 *            附件路径
+	 * @param params
+	 *            参数
+	 * @return
+	 * @throws Exception
+	 * @throws IOException
+	 * @throws IllegalStateException
+	 */
+	public static Response upload(String postUrl, String filePath, Map<String, String> params, boolean sign, String signKey)
+			throws IllegalStateException, IOException, Exception {
+		CloseableHttpClient httpClient = null;
+		CloseableHttpResponse response = null;
+		try {
+			httpClient = HttpClients.createDefault();
+			HttpPost httpPost = new HttpPost(getRequestUrl(postUrl, sign, signKey));
+			FileBody fileBody = new FileBody(new File(filePath));
+			MultipartEntityBuilder builder = MultipartEntityBuilder.create();
+			builder.addPart("file", fileBody);
+			if (params != null) {
+				for (String paramKey : params.keySet()) {
+					StringBody body = new StringBody(params.get(paramKey), ContentType.create("text/plain", Consts.UTF_8));
+					builder.addPart(paramKey, body);
+				}
+			}
+			HttpEntity reqEntity = builder.build();
+			httpPost.setEntity(reqEntity);
+			response = httpClient.execute(httpPost);
+		} finally {
+			try {
+				if (response != null) {
+					response.close();
+				}
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+			try {
+				if (httpClient != null) {
+					httpClient.close();
+				}
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}
+		return Response.getResponse(response);
+	}
+
+	/**
+	 * 下载
+	 * 
+	 * @param postUrl
+	 * @return
+	 * @throws ClientProtocolException
+	 * @throws IOException
+	 */
+	public static InputStream download(String postUrl) throws ClientProtocolException, IOException {
+		CloseableHttpClient httpClient = HttpClients.createDefault();
+		HttpGet httpGet = new HttpGet(postUrl);
+		CloseableHttpResponse response = httpClient.execute(httpGet);
+		return response.getEntity().getContent();
+	}
+
+	public static class Response {
+		private int statusCode;
+		private String responseText;
+
+		public int getStatusCode() {
+			return statusCode;
+		}
+
+		public void setStatusCode(int statusCode) {
+			this.statusCode = statusCode;
+		}
+
+		public String getResponseText() {
+			return responseText;
+		}
+
+		public void setResponseText(String responseText) {
+			this.responseText = responseText;
+		}
+
+		public Response() {
+		}
+
+		public Response(HttpResponse response) throws IllegalStateException, IOException, Exception {
+			this.statusCode = response.getStatusLine().getStatusCode();
+			this.responseText = HttpUtil.read2String(response.getEntity().getContent());
+		}
+
+		public static Response getResponse(HttpResponse response) throws IllegalStateException, IOException, Exception {
+			if (response != null)
+				return new Response(response);
+			return null;
+		}
+	}
+}

+ 84 - 0
src/com/mes/core/JSONUtil.java

@@ -0,0 +1,84 @@
+package com.mes.core;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class JSONUtil {
+
+	static final String Unicode_Pattern = "(\\\\u(\\p{XDigit}{4}))";
+
+	public static String decodeUnicode(String jsonStr) {
+		if (jsonStr != null) {
+			// unicode格式的转化成汉字
+			Pattern pattern = Pattern.compile(Unicode_Pattern);
+			Matcher matcher = pattern.matcher(jsonStr);
+			char ch;
+			while (matcher.find()) {
+				ch = (char) Integer.parseInt(matcher.group(2), 16);
+				jsonStr = jsonStr.replace(matcher.group(1), ch + "");
+			}
+		}
+		return jsonStr;
+	}
+
+	public static Map<Object, Object> toMap(String jsonStr) {
+		jsonStr = decodeUnicode(jsonStr);
+		jsonStr = jsonStr.substring(jsonStr.indexOf("{") + 1, jsonStr.lastIndexOf("}"));
+		String[] strs = jsonStr.split(",\"");
+		String field = null;
+		String value = null;
+		Map<Object, Object> map = new HashMap<Object, Object>();
+		for (String str : strs) {
+			if (str.indexOf(":") > 0) {
+				field = str.substring(0, str.indexOf(":"));
+				if (field != null) {
+					if (field.startsWith("\"")) {
+						field = field.substring(1, field.length());
+					}
+					if (field.endsWith("\"")) {
+						field = field.substring(0, field.lastIndexOf("\""));
+					}
+				}
+				value = str.substring(str.indexOf(":") + 1);
+				if (value != null) {
+					if (value.startsWith("\"")) {
+						value = value.substring(1, value.length());
+					}
+					if (value.endsWith("\"")) {
+						value = value.substring(0, value.lastIndexOf("\""));
+					}
+				}
+				map.put(field, value);
+			}
+		}
+		return map;
+	}
+
+	public static List<Map<Object, Object>> toMapList(String jsonStr) {
+		if (jsonStr != null) {
+			if (jsonStr.startsWith("[")) {
+				jsonStr = jsonStr.substring(1, jsonStr.length());
+			}
+			if (jsonStr.endsWith("]")) {
+				jsonStr = jsonStr.substring(0, jsonStr.lastIndexOf("]"));
+			}
+			List<Map<Object, Object>> list = new ArrayList<Map<Object, Object>>();
+			if (jsonStr.indexOf("},") > -1) {
+				String[] js = jsonStr.split("},");
+				for (String j : js) {
+					if (!j.endsWith("}"))
+						j = j + "}";
+					list.add(toMap(j));
+				}
+			} else if (jsonStr.indexOf("{") > -1 && jsonStr.indexOf("}") > -1) {
+				list.add(toMap(jsonStr));
+			}
+			return list;
+		}
+		return null;
+	}
+}

+ 95 - 0
src/com/mes/core/JacksonUtil.java

@@ -0,0 +1,95 @@
+package com.mes.core;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.JsonParser.Feature;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+
+/**
+ * <h1>jackson</h1><br>
+ * 建议反序列化采用和序列化同一util,不要jackson和flexjson混着用,否则消耗会加大很多
+ * 
+ * @author yingp
+ * 
+ */
+public class JacksonUtil {
+	@SuppressWarnings("unchecked")
+	public static <T> List<T> fromJsonArray(String json) {
+		ObjectMapper mapper = getObjectMapper();
+		try {
+			return mapper.readValue(json, List.class);
+		} catch (JsonParseException e) {
+			e.printStackTrace();
+		} catch (JsonMappingException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	/**
+	 * 字段必须是有引号的,形如{"a":"1","b":2}<br>
+	 * 如果格式是{a:"1",b:2}是无法解析的
+	 * 
+	 * @param json
+	 * @return
+	 */
+	@SuppressWarnings("unchecked")
+	public static <K, V> HashMap<K, V> fromJson(String json) {
+		ObjectMapper mapper = getObjectMapper();
+		try {
+			return mapper.readValue(json, HashMap.class);
+		} catch (JsonParseException e) {
+			e.printStackTrace();
+		} catch (JsonMappingException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	public static String toJson(Map<?, ?> map) {
+		ObjectMapper mapper = getObjectMapper();
+		try {
+			return mapper.writeValueAsString(map);
+		} catch (JsonGenerationException e) {
+			e.printStackTrace();
+		} catch (JsonMappingException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	public static String toJsonArray(Collection<?> collection) {
+		ObjectMapper mapper = getObjectMapper();
+		try {
+			return mapper.writeValueAsString(collection);
+		} catch (JsonGenerationException e) {
+			e.printStackTrace();
+		} catch (JsonMappingException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	private static ObjectMapper getObjectMapper() {
+		ObjectMapper mapper = new ObjectMapper();
+		mapper.configure(Feature.ALLOW_SINGLE_QUOTES, true);
+		mapper.configure(Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
+		return mapper;
+	}
+
+}

+ 49 - 0
src/com/mes/core/LoginFilter.java

@@ -0,0 +1,49 @@
+package com.mes.core;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import org.springframework.http.HttpStatus;
+
+import com.mes.core.HttpUtil.Response;
+import com.mes.model.Employee;
+
+public class LoginFilter implements Filter {  
+	
+    public void init(FilterConfig filterConfig) throws ServletException { 
+    	
+    }  
+  
+    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,  
+                         FilterChain filterChain) throws IOException, ServletException {  
+        HttpServletRequest req = (HttpServletRequest) servletRequest; 
+        String token = req.getParameter("token");
+        if(token != null){  			
+			Map<String,String> map = new HashMap<String,String>();
+			map.put("token",token);
+			Response response = null;
+			try {
+				response = HttpUtil.sendGetRequest("http://192.168.230.200:8090/ERP/common/checkSession.action", map);
+				/* = HttpUtil.sendGetRequest("http://localhost:8080/ERP/common/checkSession.action", map);*/
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+			if(response.getStatusCode() == HttpStatus.OK.value()){
+				if(response.getResponseText() != null){
+				    req.getSession().setAttribute("employee",FlexJsonUtil.fromJson(response.getResponseText(), Employee.class));
+				}
+			}
+		}
+        filterChain.doFilter(servletRequest, servletResponse);  
+    }  
+    public void destroy() {  
+    }  
+}  

+ 253 - 0
src/com/mes/core/NumberUtil.java

@@ -0,0 +1,253 @@
+package com.mes.core;
+
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+
+/**
+ * 数值处理工具
+ * 
+ * @author yingp
+ * 
+ */
+public class NumberUtil {
+
+	/**
+	 * 是否为空、0
+	 * 
+	 * @param numberObj
+	 * @return
+	 */
+	public static boolean isEmpty(Object numberObj) {
+		try {
+			return numberObj == null || "0".equals(String.valueOf(numberObj)) || Integer.parseInt(numberObj.toString()) == 0;
+		} catch (Exception e) {
+			return false;
+		}
+	}
+
+	/**
+	 * format double类型
+	 * 
+	 * @param number
+	 *            需要format的数据
+	 * @param f
+	 *            保留f位的小数
+	 * @return format之后的double类型的数据
+	 */
+	public static double formatDouble(double number, int f) {
+		if (f > 0) {
+			BigDecimal b = new BigDecimal(Double.toString(number));
+			BigDecimal one = new BigDecimal("1");
+			return b.divide(one, f, BigDecimal.ROUND_HALF_UP).doubleValue();
+		} else {
+			return Math.floor(number);
+		}
+	}
+
+	/**
+	 * format double类型
+	 * 
+	 * @param number
+	 *            需要format的数据
+	 * @param f
+	 *            保留f位的小数
+	 * @return format之后的double类型的数据
+	 */
+	public static double formatDouble(String number, int f) {
+		double n = Double.parseDouble(number);
+		if (f > 0) {
+			BigDecimal b = new BigDecimal(number);
+			BigDecimal one = new BigDecimal("1");
+			return b.divide(one, f, BigDecimal.ROUND_HALF_UP).doubleValue();
+		} else {
+			return Math.floor(n);
+		}
+	}
+
+	/**
+	 * 浮点型转成BigDecimal
+	 * 
+	 * @param number
+	 * @return
+	 */
+	public static String parseBigDecimal(double number) {
+		return String.valueOf(BigDecimal.valueOf(number));
+	}
+
+	/**
+	 * 数字格式化
+	 * 
+	 * @param number
+	 * @param f
+	 * @return
+	 */
+	public static String formatNumber(Object number, int f) {
+		if ("0".equals(String.valueOf(number)))
+			return "0";
+		if (number instanceof String)
+			number = Double.parseDouble(number.toString());
+		DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance();
+		df.setGroupingSize(3);
+		int len = number.toString().length();
+		if (number.toString().indexOf(".") > 0)
+			len = number.toString().indexOf(".");
+		String pattern = len > 3 ? "0,000" : "0";
+		for (int i = 0; i < f; i++) {
+			if (i == 0)
+				pattern += ".";
+			pattern += "0";
+		}
+		df.applyPattern(pattern);
+		try {
+			return df.format(number);
+		} catch (Exception e) {
+			return null;
+		}
+	}
+
+	/**
+	 * 设置小数点保留位数
+	 * */
+	public static float subFloat(float f, int length) {
+		String fStr = String.valueOf(f);
+		int i = fStr.indexOf(".");
+		String returnStr = null;
+		if (fStr.length() > i + 1 + length) {
+			returnStr = fStr.substring(0, i + 1 + length);
+		} else
+			returnStr = fStr;
+		float returnf = (Float.valueOf(returnStr)).floatValue();
+		return returnf;
+	}
+
+	/**
+	 * int数组转化成Integer数组
+	 */
+	public static Integer[] toIntegerArray(int[] arr) {
+		int n = arr.length;
+		Integer[] iarr = new Integer[n];
+		for (int i = 0; i < n; i++) {
+			iarr[i] = new Integer(arr[i]);
+		}
+		return iarr;
+	}
+
+	public static Number nvl(Number number, Number ifNullNumber) {
+		return number == null ? ifNullNumber : number;
+	}
+
+	public static int compare(Double paramDouble1, Double paramDouble2) {
+		if (paramDouble1 == null)
+			paramDouble1 = 0.0;
+		if (paramDouble2 == null)
+			paramDouble2 = 0.0;
+		return Double.compare(paramDouble1, paramDouble2);
+	}
+
+	/**
+	 * Double型加法运算
+	 * 
+	 * @param d1
+	 *            第一个加数
+	 * @param ds
+	 *            若干个加数
+	 * @return 相加的结果
+	 * @author suntg
+	 */
+	public static double add(Double d1, Double... ds) {
+		BigDecimal bd = new BigDecimal(Double.toString(d1));
+		for (Double d : ds) {
+			bd = bd.add(new BigDecimal(Double.toString(d)));
+		}
+		return bd.doubleValue();
+	}
+
+	/**
+	 * Double型加法运算
+	 * 
+	 * @param d1
+	 *            第一个加数
+	 * @param ds
+	 *            若干个加数
+	 * @return 相加的结果
+	 * @author suntg
+	 */
+	public static double add(String ds1, String... dss) {
+		BigDecimal bd = new BigDecimal(ds1);
+		for (String ds : dss) {
+			bd = bd.add(new BigDecimal(ds));
+		}
+		return bd.doubleValue();
+	}
+
+	/**
+	 * Double型减法运算
+	 * 
+	 * @param d1
+	 *            被减数
+	 * @param d2
+	 *            减数
+	 * @return 运算结果
+	 * @author suntg
+	 */
+	public static double sub(Double d1, Double d2) {
+		BigDecimal b1 = new BigDecimal(Double.toString(d1));
+		BigDecimal b2 = new BigDecimal(Double.toString(d2));
+		return b1.subtract(b2).doubleValue();
+	}
+
+	/**
+	 * Double 型乘法运算
+	 * 
+	 * @param d1
+	 *            第一个乘数
+	 * @param d2
+	 *            第二个乘数
+	 * @return 运算结果
+	 * @author suntg
+	 */
+	public static double mul(Double d1, Double d2) {
+		BigDecimal b1 = new BigDecimal(Double.toString(d1));
+		BigDecimal b2 = new BigDecimal(Double.toString(d2));
+		return b1.multiply(b2).doubleValue();
+	}
+
+	/**
+	 * Double 型除法运算
+	 * 
+	 * @param d1
+	 *            被除数
+	 * @param d2
+	 *            除数
+	 * @param scale
+	 *            小数点四舍五入精度
+	 * @return 运算结果
+	 * @author suntg
+	 */
+	public static double div(Double d1, Double d2, int scale) {
+		if (scale < 0) {
+			throw new IllegalArgumentException("四舍五入精度必须大于0");
+		}
+		if (d2.equals(0)) {
+			throw new IllegalArgumentException("被除数不能为0");
+		}
+		BigDecimal b1 = new BigDecimal(Double.toString(d1));
+		BigDecimal b2 = new BigDecimal(Double.toString(d2));
+		return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
+	}
+
+	/**
+	 * 默认小数点四舍五入精度为6的Double型除法运算
+	 * 
+	 * @param d1
+	 *            被除数
+	 * @param d2
+	 *            除数
+	 * @return 运算结果
+	 * @author suntg
+	 */
+	public static double div(Double d1, Double d2) {
+		return div(d1, d2, 6);
+	}
+
+}

+ 320 - 0
src/com/mes/core/PathUtil.java

@@ -0,0 +1,320 @@
+package com.mes.core;
+
+import java.io.File;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+
+public class PathUtil {
+
+	// classes文件夹
+	private static String CLASSPATH;
+	// WEB-INF文件夹
+	private static String WEBPATH;
+	// 系统路径//ERP路径
+	private static String SYSPATH;
+	// 自定义逻辑(主要逻辑)存放路径
+	private static String LOGICPATH;
+	// 默认的附件路径,和项目同级目录
+	private static String FILEPATH;
+	// 自定义报表rpt文件
+	private static String RPTPATH;
+	// 补丁包源文件路劲
+	private static String PATCHPATH;
+	// Excel路径
+	private static String EXCELPATH;
+	// 自定义逻辑的java代码目录
+	private static String OPENPATH;
+	// 邮件收发附件存放地,默认为FILEPATH/mail
+	private static String MAILPATH;
+	private static String DOCUMENTPATH;
+	private static String OFFICIALDOCUMENTPATH;
+	private static String TEMPPATH;
+	//帮助文档路径
+	private static String HELPPATH;
+
+	/**
+	 * 系统class类加载路径
+	 */
+	@SuppressWarnings("rawtypes")
+	private static void setClassPath() {
+		try {
+			Class objClass = ContextUtil.getApplicationContext().getClass();
+			String strRealPath = objClass.getClassLoader().getResource("").getFile();
+			try {
+				strRealPath = URLDecoder.decode(strRealPath, "UTF-8");
+			} catch (UnsupportedEncodingException e) {
+				e.printStackTrace();
+			}
+			CLASSPATH = strRealPath;
+			if (CLASSPATH.contains("/")) {
+				CLASSPATH = "/" + CLASSPATH;
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+	/**
+	 * @return classes目录
+	 */
+	public static String getClassPath() {
+		if (CLASSPATH == null) {
+			setClassPath();
+		}
+		return CLASSPATH;
+	}
+
+	/**
+	 * @return web-inf目录
+	 */
+	public static String getPath() {
+		if (WEBPATH == null) {
+			File objFile = new File(getClassPath());
+			WEBPATH = objFile.getParent() + File.separator;
+		}
+		return WEBPATH;
+	}
+
+	/**
+	 * 设置系统路径,
+	 */
+	private static void setSysPath() {
+		File objFile = new File(getPath());
+		SYSPATH = objFile.getParent() + File.separator;
+	}
+
+	/**
+	 * 项目路径
+	 * 
+	 * @return
+	 */
+	public static String getSysPath() {
+		if (SYSPATH == null) {
+			setSysPath();
+		}
+		return SYSPATH;
+	}
+
+	/**
+	 * 设置附件路径, 与项目目录同级
+	 */
+	private static void setFilePath() {
+		String path = BaseUtil.getXmlSetting("filepath");
+		if (path != null) {
+			FILEPATH = path;
+		} else {
+			File objFile = new File(getSysPath());
+			FILEPATH = objFile.getParent() + File.separator;
+		}
+	}
+
+	public static String getFilePath() {
+		if (FILEPATH == null) {
+			setFilePath();
+		}
+		return FILEPATH;
+	}
+
+	/**
+	 * 设置补丁路径, 与项目目录同级
+	 */
+	private static void setPatchPath() {
+		PATCHPATH = getFilePath() + "mypatch";
+		File file = new File(PATCHPATH);
+		if (!file.isDirectory()) {
+			file.mkdir();
+		}
+	}
+
+	public static String getPatchPath() {
+		if (PATCHPATH == null) {
+			setPatchPath();
+		}
+		return PATCHPATH;
+	}
+
+	private static void setTempPath() {
+		TEMPPATH = getSysPath() + "temp";
+		File file = new File(TEMPPATH);
+		if (!file.isDirectory()) {
+			file.mkdir();
+		}
+	}
+
+	public static String getTempPath() {
+		if (TEMPPATH == null) {
+			setTempPath();
+		}
+		return TEMPPATH;
+	}
+	public static String getHelpPath() {
+		if (HELPPATH == null) {
+			setHelpPath();
+		}
+		return HELPPATH;
+	}
+	private static void setHelpPath() {
+		HELPPATH = getFilePath() + "help";
+		File file = new File(HELPPATH);
+		if (!file.isDirectory()) {
+			file.mkdir();
+		}
+	}
+
+	/**
+	 * 自定义报表rept文件路径
+	 */
+	private static void setRptPath() {
+		RPTPATH = getFilePath() + "rpts";
+		File file = new File(RPTPATH);
+		if (!file.isDirectory()) {
+			file.mkdir();
+		}
+	}
+
+	public static String getRptPath() {
+		if (RPTPATH == null) {
+			setRptPath();
+		}
+		return RPTPATH;
+	}
+
+	/**
+	 * 设置自定义逻辑的java代码目录
+	 */
+	private static void setOpenPath() {
+		OPENPATH = getFilePath() + "openservice";
+		File file = new File(OPENPATH);
+		if (!file.isDirectory()) {
+			file.mkdir();
+		}
+	}
+
+	public static String getOpenPath() {
+		if (OPENPATH == null) {
+			setOpenPath();
+		}
+		return OPENPATH;
+	}
+
+	/**
+	 * 设置邮件附件路径
+	 */
+	private static void setMailPath() {
+		MAILPATH = getFilePath() + "mail";
+		File file = new File(MAILPATH);
+		if (!file.isDirectory()) {
+			file.mkdir();
+		}
+	}
+
+	public static String getMailPath() {
+		if (MAILPATH == null) {
+			setMailPath();
+		}
+		return MAILPATH;
+	}
+
+	/**
+	 * 文档路径
+	 */
+	private static void setDocPath() {
+		DOCUMENTPATH = getFilePath() + "document";
+		File file = new File(DOCUMENTPATH);
+		if (!file.isDirectory()) {
+			file.mkdir();
+		}
+	}
+
+	public static String getDocPath() {
+		if (DOCUMENTPATH == null) {
+			setDocPath();
+		}
+		return DOCUMENTPATH;
+	}
+
+	/**
+	 * 文档路径
+	 */
+	private static void setOfficePath() {
+		OFFICIALDOCUMENTPATH = getFilePath() + "officialDocument";
+		File file = new File(OFFICIALDOCUMENTPATH);
+		if (!file.isDirectory()) {
+			file.mkdir();
+		}
+	}
+
+	public static String getOfficePath() {
+		if (OFFICIALDOCUMENTPATH == null) {
+			setOfficePath();
+		}
+		return OFFICIALDOCUMENTPATH;
+	}
+
+	/**
+	 * EXcel 路径
+	 * */
+	private static void setExcelPath() {
+		String str = null;
+		try {
+			str = BaseUtil.class.getResource("").getPath();
+			str = URLDecoder.decode(str, "utf-8");
+			if (str.contains("classes")) {
+				str = str.substring(0, str.lastIndexOf("classes/"));
+			}
+			if (str.contains("/")) {
+				str = "/" + str;
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		String ch = File.separator;
+		if (str.contains("/")) {
+			ch = "/";
+		} else {
+			ch = "\\";
+		}
+		String[] arr = BaseUtil.parseStr2Array(str, ch);
+		StringBuffer sb = new StringBuffer();
+		if (str.contains("/")) {
+			sb.append(ch);
+		}
+		for (int i = 0; i < arr.length; i++) {
+			if (i < arr.length - 1) {// 去掉最后两级目录
+				sb.append(arr[i]);
+				sb.append(File.separator);
+			}
+		}
+		EXCELPATH = sb.toString() + "Excel";
+		File file = new File(EXCELPATH);
+		if (!file.isDirectory()) {
+			file.mkdir();
+		}
+	}
+
+	public static String getExcelPath() {
+		if (EXCELPATH == null) {
+			setExcelPath();
+		}
+		return EXCELPATH;
+	}
+
+	/**
+	 * 自定义逻辑(主要逻辑)路径
+	 */
+	private static void setLogicPath() {
+		LOGICPATH = getFilePath() + "logic";
+		File file = new File(LOGICPATH);
+		if (!file.isDirectory()) {
+			file.mkdir();
+		}
+	}
+
+	public static String getLogicPath() {
+		if (LOGICPATH == null) {
+			setLogicPath();
+		}
+		return LOGICPATH;
+	}
+
+}

+ 1088 - 0
src/com/mes/core/SqlUtil.java

@@ -0,0 +1,1088 @@
+package com.mes.core;
+
+import java.io.Writer;
+import java.lang.reflect.Method;
+import java.sql.Clob;
+import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import oracle.jdbc.OracleConnection;
+
+import com.mes.dao.SqlMap;
+import com.mes.model.DetailGrid;
+import com.mes.model.Employee;
+import com.mes.model.Master;
+
+/**
+ * 处理一些拼sql的工具包
+ * 
+ * @author yingp
+ * @date 2012-08-02 10:22:17
+ * 
+ * @since 2015-11-26
+ *        <p>
+ *        增加对SqlMap的操作方法
+ *        </p>
+ */
+public class SqlUtil {
+
+	public final static String REG_D = "\\d{4}-\\d{2}-\\d{2}";
+	public final static String REG_DT = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}";
+	public final static String REG_TS = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{1}";
+
+	/**
+	 * 根据DetailGrid配置拼Sql查询语句
+	 * 
+	 * @param table
+	 *            表名
+	 */
+	private static String _getQuerySqlByDetailGrid(List<DetailGrid> detailGrids, String table, String condition, String masterName) {
+		StringBuffer sb = new StringBuffer("SELECT ");
+		String orderby = "";
+		String field = null;
+		String logic = null;
+		if (masterName != null) {
+			sb.append("'").append(masterName).append("' CURRENTMASTER,");
+		}
+		for (DetailGrid detailGrid : detailGrids) {
+			field = detailGrid.getDg_field();
+			logic = detailGrid.getDg_logictype();
+			sb.append(field);
+			sb.append(",");
+			if (!condition.toUpperCase().contains("ORDER BY")) {
+				if (field.contains("_detno") || field.contains("_sequence") || (logic != null && "detno".equals(logic))) {
+					orderby = " ORDER BY " + field;
+				}
+			}
+		}
+		String str = sb.substring(0, sb.length() - 1) + " FROM " + table;
+		return condition.equals("") ? str : str + " where " + condition + orderby;
+	}
+
+	/**
+	 * 根据DetailGrid配置拼Sql查询语句
+	 * 
+	 * @param table
+	 *            表名
+	 */
+	private static String _getQuerySqlByDetailGrid(List<DetailGrid> detailGrids, String table, String condition, String masterName,
+			Integer start, Integer end) {
+		if (end == null)
+			return _getQuerySqlByDetailGrid(detailGrids, table, condition, masterName);
+		StringBuffer fieldsStr = new StringBuffer("");
+		String orderby = "";
+		String field = null;
+		String logic = null;
+		if (masterName != null) {
+			fieldsStr.append("'").append(masterName).append("' CURRENTMASTER,");
+		}
+		for (DetailGrid detailGrid : detailGrids) {
+			field = detailGrid.getDg_field();
+			logic = detailGrid.getDg_logictype();
+			fieldsStr.append(field);
+			fieldsStr.append(",");
+			if (!condition.toUpperCase().contains("ORDER BY")) {
+				if (field.contains("_detno") || field.contains("_sequence") || (logic != null && "detno".equals(logic))) {
+					orderby = " ORDER BY " + field;
+				}
+			}
+		}
+		condition = "".equals(condition) ? "" : " WHERE " + condition;
+		String longFieldsStr = fieldsStr.substring(0, fieldsStr.length() - 1);
+		StringBuffer sb = new StringBuffer("select * from (select TT.*, ROWNUM rn from (select ");
+		sb.append(longFieldsStr);
+		sb.append(" from ");
+		sb.append(table);
+		sb.append(" ");
+		sb.append(condition);
+		sb.append(" ");
+		sb.append(orderby);
+		sb.append(" )TT where ROWNUM <= ");
+		sb.append(end);
+		sb.append(") where rn >= ");
+		sb.append(start);
+		return sb.toString();
+	}
+
+	public static String getQuerySqlByDetailGrid(List<DetailGrid> detailGrids, String table, String condition, Employee employee,
+			Integer start, Integer end) {
+		Master master = employee == null ? null : employee.getCurrentMaster();
+		if (master == null || master.getMa_type() == 3 || master.getMa_soncode() == null) {
+			return _getQuerySqlByDetailGrid(detailGrids, table, condition, null, start, end);
+		}
+		String caller = detailGrids.get(0).getDg_caller();
+		// 集团中心,取资料中心数据
+		if (master.getMa_type() == 0
+				&& ("Product".equals(caller) || "Vendor".equals(caller) || "Customer".equals(caller) || "Customer!Base".equals(caller))) {
+			table = getFullTableName(table, BaseUtil.getXmlSetting("dataSob"));
+			return _getQuerySqlByDetailGrid(detailGrids, table, condition, null, start, end);
+		}
+		String[] sonCodes = master.getMa_soncode().split(",");
+		String masters = employee.getEm_masters();
+		masters = masters == null ? employee.getEm_master() : masters;
+		List<String> usedCodes = BaseUtil.parseStr2List(masters, ",", false);
+		boolean admin = "admin".equals(employee.getEm_type());
+		StringBuffer sb = new StringBuffer();
+		String tabName = table;
+		for (String s : sonCodes) {
+			if (!admin && !usedCodes.contains(s)) {
+				continue;
+			}
+			tabName = getFullTableName(table, s);
+			if (sb.length() > 0)
+				sb.append(" UNION ALL ");
+			sb.append(_getQuerySqlByDetailGrid(detailGrids, tabName, condition, s, start, end));
+		}
+		return sb.toString();
+	}
+
+	public static String getFullTableName(String tabName, String masterCode) {
+		String[] strs = tabName.split("left join ");
+		StringBuffer sb = new StringBuffer();
+		for (int i = 0, len = strs.length; i < len; i++) {
+			sb.append(masterCode).append(".").append(strs[i]);
+			if (i != len - 1)
+				sb.append("left join ");
+		}
+		return sb.toString();
+	}
+
+	/**
+	 * @param formStore
+	 *            form数据
+	 */
+	@Deprecated
+	public static String getInsertSqlByFormStore(String formStore, String table, String[] otherFields, Object[] otherValues) {
+		StringBuffer sb1 = new StringBuffer("INSERT into " + table + " (");
+		StringBuffer sb2 = new StringBuffer(" ");
+		Map<Object, Object> map = BaseUtil.parseFormStoreToMap(formStore);
+		Set<Object> keys = map.keySet();
+		for (Object key : keys) {
+			String field = (String) key;
+			Object value = map.get(key);
+			if (otherFields != null) {
+				for (int i = 0, len = otherFields.length; i < len; i++) {
+					if (field.equals(otherFields[i])) {// 字段重复了哦
+						value = otherValues[i];// 优先选用传递过来的value
+					}
+				}
+			}
+			sb1.append(field);
+			sb1.append(",");
+			if (value != null) {
+				String val = value.toString();
+				if (val.matches(REG_D)) {// 判断是否是形如yyyy-mm-dd格式的日期类型数据
+					sb2.append(DateUtil.parseDateToOracleString(Constant.YMD, val));
+				} else if (val.matches(REG_DT)) {
+					sb2.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val));
+				} else if (val.matches(REG_TS)) {
+					sb2.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val.substring(0, val.lastIndexOf("."))));
+				} else if ("null".equals(val)) {
+					sb2.append("null");
+				} else if ("".equals(val.trim())) {
+					sb2.append("''");
+				} else if (val.contains("%n")) {
+					sb2.append("'" + val.replaceAll("%n", "\n") + "'");
+				} else if (val.contains("'")) {
+					sb2.append("'" + value.toString().replaceAll("'", "''") + "'");
+				} else {
+					sb2.append("'" + value + "'");
+				}
+			} else {
+				sb2.append("null");
+			}
+			sb2.append(",");
+		}
+		if (otherFields != null) {
+			for (int i = 0, len = otherFields.length; i < len; i++) {
+				if (!sb1.toString().contains(otherFields[i])) {
+					sb1.append(otherFields[i]);
+					sb1.append(",");
+					sb2.append("'" + otherValues[i] + "'");
+					sb2.append(",");
+				}
+			}
+		}
+		return sb1.substring(0, sb1.length() - 1) + ") VALUES (" + sb2.substring(0, sb2.length() - 1) + ")";
+	}
+
+	/**
+	 * @param map
+	 *            formStore解析成的map
+	 */
+	public static String getInsertSqlByFormStore(Map<?, Object> map, String table, String[] otherFields, Object[] otherValues) {
+		StringBuffer sb1 = new StringBuffer("INSERT into " + table + " (");
+		StringBuffer sb2 = new StringBuffer(" ");
+		Set<?> keys = map.keySet();
+		for (Object key : keys) {
+			String field = (String) key;
+			Object value = map.get(key);
+			for (int i = 0; i < otherFields.length; i++) {
+				if (field.equals(otherFields[i])) {// 字段重复了哦
+					value = otherValues[i];// 优先选用传递过来的value
+				}
+			}
+			sb1.append(field);
+			sb1.append(",");
+			if (value != null) {
+				String val = value.toString();
+				if (value.toString().matches(REG_D)) {// 判断是否是形如yyyy-mm-dd格式的日期类型数据
+					sb2.append(DateUtil.parseDateToOracleString(Constant.YMD, val));
+				} else if (value.toString().matches(REG_DT)) {
+					sb2.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val));
+				} else if (value.toString().matches(REG_TS)) {
+					sb2.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val.substring(0, val.lastIndexOf("."))));
+				} else if (value.toString().equals("null")) {
+					sb2.append("null");
+				} else if (val.contains("%n")) {
+					sb2.append("'" + val.replaceAll("%n", "\n") + "'");
+				} else if (val.contains("'")) {
+					sb2.append("'" + value.toString().replaceAll("'", "''") + "'");
+				} else {
+					sb2.append("'" + value + "'");
+				}
+			} else {
+				sb2.append("null");
+			}
+			sb2.append(",");
+		}
+		for (int i = 0; i < otherFields.length; i++) {
+			if (!sb1.toString().contains(otherFields[i])) {
+				sb1.append(otherFields[i]);
+				sb1.append(",");
+				sb2.append("'" + otherValues[i] + "'");
+				sb2.append(",");
+			}
+		}
+		return sb1.substring(0, sb1.length() - 1) + ") VALUES (" + sb2.substring(0, sb2.length() - 1) + ")";
+	}
+
+	/**
+	 * 将grid数据从字符串形式拼成sql, 一般情况下还要加一些条件,比如,新增采购单时,加入pd_puid=?
+	 * 
+	 * @param
+	 */
+	public static List<String> getInsertSqlbyGridStore(String gridStore, String table, String otherField, Object[] otherValues) {
+		List<String> sqls = new ArrayList<String>();
+		List<Map<Object, Object>> maps = BaseUtil.parseGridStoreToMaps(gridStore);
+		int count = 0;
+		StringBuffer sb1 = null;
+		StringBuffer sb2 = null;
+		for (Map<Object, Object> map : maps) {
+			Set<Object> keys = map.keySet();
+			sb1 = new StringBuffer("INSERT into " + table + " (");
+			sb2 = new StringBuffer(" ");
+			for (Object key : keys) {
+				String field = (String) key;
+				Object value = map.get(key);
+				if (field.equals(otherField)) {// 字段重复了哦
+					value = otherValues[count++];// 优先选用传递过来的value
+				}
+				sb1.append(field);
+				sb1.append(",");
+				if (value != null) {
+					String val = value.toString();
+					if (val.matches(REG_D)) {// 判断是否是形如yyyy-mm-dd格式的日期类型数据
+						sb2.append(DateUtil.parseDateToOracleString(Constant.YMD, val));
+					} else if (val.matches(REG_DT)) {
+						sb2.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val));
+					} else if (val.matches(REG_TS)) {
+						sb2.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val.substring(0, val.lastIndexOf("."))));
+					} else if (value.toString().equals("null")) {
+						sb2.append("null");
+					} else if (val.contains("%n")) {
+						sb2.append("'" + val.replaceAll("%n", "\n") + "'");
+					} else {
+						sb2.append("'" + value + "'");
+					}
+				} else {
+					sb2.append("null");
+				}
+				sb2.append(",");
+			}
+			if (!otherField.equals("") && !sb1.toString().contains(otherField)) {
+				sb1.append(otherField);
+				sb1.append(",");
+				sb2.append("'" + otherValues[count++] + "'");
+				sb2.append(",");
+			}
+			sqls.add(sb1.substring(0, sb1.length() - 1) + ") VALUES (" + sb2.substring(0, sb2.length() - 1) + ")");
+		}
+		return sqls;
+	}
+
+	public static List<String> getInsertSqlbyGridStore(List<Map<Object, Object>> maps, String table) {
+		List<String> sqls = new ArrayList<String>();
+		StringBuffer sb1 = null;
+		StringBuffer sb2 = null;
+		for (Map<Object, Object> map : maps) {
+			Set<Object> keys = map.keySet();
+			sb1 = new StringBuffer("INSERT into " + table + " (");
+			sb2 = new StringBuffer(" ");
+			for (Object key : keys) {
+				String field = (String) key;
+				Object value = map.get(key);
+				sb1.append(field);
+				sb1.append(",");
+				if (value != null) {
+					String val = value.toString();
+					if (val.matches(REG_D)) {// 判断是否是形如yyyy-mm-dd格式的日期类型数据
+						sb2.append(DateUtil.parseDateToOracleString(Constant.YMD, val));
+					} else if (val.matches(REG_DT)) {
+						sb2.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val));
+					} else if (val.matches(REG_TS)) {
+						sb2.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val.substring(0, val.lastIndexOf("."))));
+					} else if (value.toString().equals("null")) {
+						sb2.append("null");
+					} else if (val.contains("%n")) {
+						sb2.append("'" + val.replaceAll("%n", "\n") + "'");
+					} else if (val.contains("'")) {
+						sb2.append("'" + value.toString().replaceAll("'", "''") + "'");
+					} else {
+						sb2.append("'" + value + "'");
+					}
+				} else {
+					sb2.append("null");
+				}
+				sb2.append(",");
+			}
+			sqls.add(sb1.substring(0, sb1.length() - 1) + ") VALUES (" + sb2.substring(0, sb2.length() - 1) + ")");
+		}
+		return sqls;
+	}
+
+	public static List<String> getInsertSqlbyGridStoreWithoutDate(List<Map<Object, Object>> maps, String table) {
+		List<String> sqls = new ArrayList<String>();
+		StringBuffer sb1 = null;
+		StringBuffer sb2 = null;
+		for (Map<Object, Object> map : maps) {
+			Set<Object> keys = map.keySet();
+			sb1 = new StringBuffer("INSERT into " + table + " (");
+			sb2 = new StringBuffer(" ");
+			for (Object key : keys) {
+				String field = (String) key;
+				Object value = map.get(key);
+				sb1.append(field);
+				sb1.append(",");
+				if (value != null) {
+					if (value.toString().equals("null")) {
+						sb2.append("null");
+					} else {
+						sb2.append("'" + value + "'");
+					}
+				} else {
+					sb2.append("null");
+				}
+				sb2.append(",");
+			}
+			sqls.add(sb1.substring(0, sb1.length() - 1) + ") VALUES (" + sb2.substring(0, sb2.length() - 1) + ")");
+		}
+		return sqls;
+	}
+
+	public static List<String> getInsertSqlbyList(List<Map<Object, Object>> maps, String table, String prif) {
+		List<String> sqls = new ArrayList<String>();
+		if (maps != null) {
+			for (Map<Object, Object> map : maps) {
+				sqls.add(getInsertSql(map, table, prif));
+			}
+		}
+		return sqls;
+	}
+
+	/**
+	 * 从map集合格式的数据中解析出insert语句
+	 */
+	public static String getInsertSqlByMap(Map<?, Object> map, String table, String[] otherFields, Object[] otherValues) {
+		StringBuffer sb1 = new StringBuffer("INSERT into " + table + " (");
+		StringBuffer sb2 = new StringBuffer(" ");
+		Object value = null;
+		for (Object field : map.keySet()) {
+			value = map.get(field);
+			if (otherFields != null) {
+				for (int i = 0; i < otherFields.length; i++) {
+					if (field.equals(otherFields[i])) {// 字段重复了哦
+						value = otherValues[i];// 优先选用传递过来的value
+					}
+				}
+			}
+			sb1.append(field);
+			sb1.append(",");
+			if (value != null) {
+				String val = value.toString();
+				if (val.matches(REG_D)) {// 判断是否是形如yyyy-mm-dd格式的日期类型数据
+					sb2.append(DateUtil.parseDateToOracleString(Constant.YMD, val));
+				} else if (val.matches(REG_DT)) {
+					sb2.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val));
+				} else if (val.matches(REG_TS)) {
+					sb2.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val.substring(0, val.lastIndexOf("."))));
+				} else if (val.equals("null")) {
+					sb2.append("null");
+				} else if (val.contains("%n")) {
+					sb2.append("'" + val.replaceAll("%n", "\n") + "'");
+				} else if (val.contains("'")) {
+					sb2.append("'" + val.replaceAll("'", "''") + "'");
+				} else {
+					sb2.append("'" + value + "'");
+				}
+			} else {
+				sb2.append("null");
+			}
+			sb2.append(",");
+		}
+		if (otherFields != null) {
+			for (int i = 0; i < otherFields.length; i++) {
+				if (!sb1.toString().contains(otherFields[i])) {
+					sb1.append(otherFields[i]);
+					sb1.append(",");
+					sb2.append("'" + otherValues[i] + "'");
+					sb2.append(",");
+				}
+			}
+		}
+		return sb1.substring(0, sb1.length() - 1) + ") VALUES (" + sb2.substring(0, sb2.length() - 1) + ")";
+	}
+
+	public static String getInsertSqlByMap(Map<?, Object> map, String table) {
+		StringBuffer sb1 = new StringBuffer("INSERT into ");
+		sb1.append(table);
+		sb1.append(" (");
+		StringBuffer sb2 = new StringBuffer(" ");
+		Object value = null;
+		for (Object field : map.keySet()) {
+			value = map.get(field);
+			sb1.append(field);
+			sb1.append(",");
+			if (value != null) {
+				String val = value.toString();
+				if (val.matches(REG_D)) {// 判断是否是形如yyyy-mm-dd格式的日期类型数据
+					sb2.append(DateUtil.parseDateToOracleString(Constant.YMD, val));
+				} else if (val.matches(REG_DT)) {
+					sb2.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val));
+				} else if (val.matches(REG_TS)) {
+					sb2.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val.substring(0, val.lastIndexOf("."))));
+				} else if (val.equals("null")) {
+					sb2.append("null");
+				} else {
+					if (val.contains("'")) {
+						val = val.replaceAll("'", "''");
+					} else if (val.contains("%n")) {
+						val = val.replaceAll("%n", "\n");
+					}
+					// 针对较长字段,比如clob类型,防止ORA-01704的简单处理:切割成多个字符串连接起来
+					if (val.length() > 2000) {
+						sb2.append(StringUtil.splitAndConcat(val, 1333, "'", "'", "||"));
+					} else {
+						sb2.append("'" + val + "'");
+					}
+				}
+			} else {
+				sb2.append("null");
+			}
+			sb2.append(",");
+		}
+		return sb1.substring(0, sb1.length() - 1) + ") VALUES (" + sb2.substring(0, sb2.length() - 1) + ")";
+	}
+
+	public static String getInsertSql(Map<?, Object> map, String table, String keyField) {
+		StringBuffer sb1 = new StringBuffer("INSERT into ");
+		sb1.append(table);
+		sb1.append(" (");
+		StringBuffer sb2 = new StringBuffer(" ");
+		Object value = null;
+		for (Object field : map.keySet()) {
+			value = map.get(field);
+			sb1.append(field);
+			sb1.append(",");
+			if (field.equals(keyField)) {
+				sb2.append(table).append("_seq.nextval,");
+				continue;
+			}
+			if (value != null) {
+				String val = value.toString();
+				if (val.matches(REG_D)) {// 判断是否是形如yyyy-mm-dd格式的日期类型数据
+					sb2.append(DateUtil.parseDateToOracleString(Constant.YMD, val));
+				} else if (val.matches(REG_DT)) {
+					sb2.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val));
+				} else if (val.matches(REG_TS)) {
+					sb2.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val.substring(0, val.lastIndexOf("."))));
+				} else if (value.toString().equals("null")) {
+					sb2.append("null");
+				} else if (val.contains("'")) {
+					sb2.append("'" + value.toString().replaceAll("'", "''") + "'");
+				} else if (val.contains("%n")) {
+					sb2.append("'" + val.replaceAll("%n", "\n") + "'");
+				} else {
+					sb2.append("'" + value + "'");
+				}
+			} else {
+				sb2.append("null");
+			}
+			sb2.append(",");
+		}
+		return sb1.substring(0, sb1.length() - 1) + ") VALUES (" + sb2.substring(0, sb2.length() - 1) + ")";
+	}
+
+	public static String getDeleteSql(String tablename, String condition) {
+		StringBuffer sb = new StringBuffer("DELETE FROM ");
+		sb.append(tablename);
+		if (condition != null) {
+			sb.append(" WHERE ");
+			sb.append(condition);
+		}
+		return sb.toString();
+	}
+
+	/**
+	 * 修改form数据的sql语句
+	 * 
+	 * @param formStore
+	 *            form数据
+	 * @param table
+	 *            待修改的表名
+	 * @param keyField
+	 *            条件语句的字段
+	 */
+	@Deprecated
+	public static String getUpdateSqlByFormStore(String formStore, String table, String keyField) {
+		Map<Object, Object> map = BaseUtil.parseFormStoreToMap(formStore);
+		Set<Object> keys = map.keySet();
+		StringBuffer sb1 = new StringBuffer("UPDATE " + table + " SET ");
+		Object keyValue = "";
+		for (Object key : keys) {
+			String field = (String) key;
+			Object value = map.get(key);
+			if (field.equals(keyField)) {// 找到了需要的字段哦
+				keyValue = value;
+			}
+			sb1.append(field);
+			sb1.append("=");
+			if (value != null) {
+				String val = value.toString();
+				if (val.matches(REG_D)) {// 判断是否是形如yyyy-mm-dd格式的日期类型数据
+					sb1.append(DateUtil.parseDateToOracleString(Constant.YMD, val));
+				} else if (val.matches(REG_DT)) {
+					sb1.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val));
+				} else if (val.matches(REG_TS)) {
+					sb1.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val.substring(0, val.lastIndexOf("."))));
+				} else if (value.toString().equals("null")) {
+					sb1.append("null");
+				} else if (val.contains("'")) {
+					sb1.append("'" + value.toString().replaceAll("'", "''") + "'");
+				} else if (val.contains("%n")) {
+					sb1.append("'" + val.replaceAll("%n", "\n") + "'");
+				} else {
+					sb1.append("'" + value + "'");
+				}
+			} else {
+				sb1.append("null");
+			}
+			sb1.append(",");
+		}
+		return sb1.substring(0, sb1.length() - 1) + " WHERE " + keyField + "='" + keyValue + "'";
+	}
+
+	public static String getUpdateSqlByFormStore(Map<Object, Object> map, String table, String keyField) {
+		Set<Object> keys = map.keySet();
+		StringBuffer sb1 = new StringBuffer("UPDATE " + table + " SET ");
+		Object keyValue = "";
+		for (Object key : keys) {
+			String field = (String) key;
+			Object value = map.get(key);
+			if (field.equals(keyField)) {// 找到了需要的字段哦
+				keyValue = value;
+			}
+			sb1.append(field);
+			sb1.append("=");
+			if (value != null) {
+				String val = value.toString();
+				if (val.matches(REG_D)) {// 判断是否是形如yyyy-mm-dd格式的日期类型数据
+					sb1.append(DateUtil.parseDateToOracleString(Constant.YMD, val));
+				} else if (val.matches(REG_DT)) {
+					sb1.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val));
+				} else if (val.matches(REG_TS)) {
+					sb1.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val.substring(0, val.lastIndexOf("."))));
+				} else if (val.equals("null")) {
+					sb1.append("null");
+				} else {
+					if (val.contains("'")) {
+						val = val.replaceAll("'", "''");
+					} else if (val.contains("%n")) {
+						val = val.replaceAll("%n", "\n");
+					}
+					// 针对较长字段,比如clob类型,防止ORA-01704的简单处理:切割成多个字符串连接起来
+					if (val.length() > 2000) {
+						sb1.append(StringUtil.splitAndConcat(val, 666, "'", "'", "||"));
+					} else {
+						sb1.append("'" + val + "'");
+					}
+				}
+			} else {
+				sb1.append("null");
+			}
+			sb1.append(",");
+		}
+		return sb1.substring(0, sb1.length() - 1) + " WHERE " + keyField + "='" + keyValue + "'";
+	}
+
+	/**
+	 * 将HashMap的字段及值,转到SqlMap
+	 * 
+	 * @param sql
+	 * @param map
+	 */
+	private static void getSqlMap(SqlMap sql, Map<Object, Object> map) {
+		Object value = null;
+		for (Object field : map.keySet()) {
+			String key = field.toString();
+			value = map.get(field);
+			if (value != null) {
+				String val = value.toString();
+				if (val.matches(REG_D)) {// 判断是否是形如yyyy-mm-dd格式的日期类型数据
+					sql.setDate(key, val, Constant.YMD);
+				} else if (val.matches(REG_DT)) {
+					sql.setDate(key, val);
+				} else if (val.matches(REG_TS)) {
+					sql.setDate(key, val.substring(0, val.lastIndexOf(".")));
+				} else if (val.equals("null")) {
+					sql.setNull(key);
+				} else {
+					if (val.contains("'")) {
+						val = val.replaceAll("'", "''");
+					} else if (val.contains("%n")) {
+						val = val.replaceAll("%n", "\n");
+					}
+					sql.set(key, val);
+				}
+			} else {
+				sql.setNull(key);
+			}
+		}
+	}
+
+	/**
+	 * 多类型sql新增操作
+	 * 
+	 * @param map
+	 * @param table
+	 * @return
+	 */
+	public static SqlMap getSqlMap(Map<Object, Object> map, String table) {
+		SqlMap sql = new SqlMap(table);
+		getSqlMap(sql, map);
+		return sql;
+	}
+
+	/**
+	 * 多类型sql更新操作
+	 * 
+	 * @param map
+	 * @param table
+	 * @param keyField
+	 * @return
+	 */
+	public static SqlMap getSqlMap(Map<Object, Object> map, String table, String keyField) {
+		SqlMap sql = new SqlMap(table, keyField);
+		getSqlMap(sql, map);
+		return sql;
+	}
+
+	/**
+	 * 修改detail数据 将grid数据从字符串形式拼成sql,
+	 * 
+	 * @param
+	 */
+	public static List<String> getUpdateSqlbyGridStore(String gridStore, String table, String keyField) {
+		List<Map<Object, Object>> maps = BaseUtil.parseGridStoreToMaps(gridStore);
+		List<String> sqls = new ArrayList<String>();
+		for (Map<Object, Object> map : maps) {
+			Set<Object> keys = map.keySet();
+			StringBuffer sb1 = new StringBuffer("UPDATE " + table + " SET ");
+			Object keyValue = "";
+			for (Object key : keys) {
+				String field = (String) key;
+				Object value = map.get(key);
+				if (field.equals(keyField)) {
+					// value不为空,即为已存在数据
+					if (value != null && !value.equals("") && !value.equals("null")) {
+						keyValue = value;
+					} else {// 否则,为新添加的数据
+						sb1 = null;
+						break;
+					}
+				}
+				sb1.append(field);
+				sb1.append("=");
+				if (value != null) {
+					String val = value.toString();
+					if (val.matches(REG_D)) {// 判断是否是形如yyyy-mm-dd格式的日期类型数据
+						sb1.append(DateUtil.parseDateToOracleString(Constant.YMD, val));
+					} else if (val.matches(REG_DT)) {
+						sb1.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val));
+					} else if (val.matches(REG_TS)) {
+						sb1.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val.substring(0, val.lastIndexOf("."))));
+					} else if (value.toString().equals("null")) {
+						sb1.append("null");
+					} else if (val.contains("%n")) {
+						sb1.append("'" + val.replaceAll("%n", "\n") + "'");
+					} else {
+						sb1.append("'" + value + "'");
+					}
+				} else {
+					sb1.append("null");
+				}
+				sb1.append(",");
+			}
+			if (sb1 != null)
+				sqls.add(sb1.substring(0, sb1.length() - 1) + " WHERE " + keyField + "='" + keyValue + "'");
+		}
+		
+		return CollectionUtil.reverse(sqls);
+	}
+
+	/**
+	 * get update_sql by GridStore
+	 * 
+	 * @param maps
+	 * @param table
+	 * @param keyField
+	 * @return
+	 */
+	public static List<String> getUpdateSqlbyGridStore(List<Map<Object, Object>> maps, String table, String keyField) {
+		List<String> sqls = new ArrayList<String>();
+		for (Map<Object, Object> map : maps) {
+			Set<Object> keys = map.keySet();
+			StringBuffer sb1 = new StringBuffer("UPDATE " + table + " SET ");
+			Object keyValue = "";
+			for (Object key : keys) {
+				String field = (String) key;
+				Object value = map.get(key);
+				if (field.equals(keyField)) {
+					// value不为空,即为已存在数据
+					if (value != null && !value.equals("") && !value.equals("null") && Integer.parseInt(value.toString()) > 0) {
+						keyValue = value;
+					} else {// 否则,为新添加的数据
+						sb1 = null;
+						break;
+					}
+				}
+				sb1.append(field);
+				sb1.append("=");
+				if (value != null) {
+					String val = value.toString();
+					if (val.matches(REG_D)) {// 判断是否是形如yyyy-mm-dd格式的日期类型数据
+						sb1.append(DateUtil.parseDateToOracleString(Constant.YMD, val));
+					} else if (val.matches(REG_DT)) {
+						sb1.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val));
+					} else if (val.matches(REG_TS)) {
+						sb1.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val.substring(0, val.lastIndexOf("."))));
+					} else if (value.toString().equals("null")) {
+						sb1.append("null");
+					} else if (val.contains("%n")) {
+						sb1.append("'" + val.replaceAll("%n", "\n") + "'");
+					} else if (val.contains("'")) {
+						sb1.append("'" + value.toString().replaceAll("'", "''") + "'");
+					} else {
+						sb1.append("'" + value + "'");
+					}
+				} else {
+					sb1.append("null");
+				}
+				sb1.append(",");
+			}
+			if (sb1 != null) {
+				sqls.add(sb1.substring(0, sb1.length() - 1) + " WHERE " + keyField + "='" + keyValue + "'");
+			}
+		}
+		return CollectionUtil.reverse(sqls);
+	}
+
+	/**
+	 * get update_sql by GridStore
+	 * 
+	 * @param maps
+	 * @param table
+	 * @param keyField
+	 * @return
+	 */
+	public static List<String> getUpdateSqlbyGridStoreWithoutDate(List<Map<Object, Object>> maps, String table, String keyField) {
+		List<String> sqls = new ArrayList<String>();
+		for (Map<Object, Object> map : maps) {
+			Set<Object> keys = map.keySet();
+			StringBuffer sb1 = new StringBuffer("UPDATE " + table + " SET ");
+			Object keyValue = "";
+			for (Object key : keys) {
+				String field = (String) key;
+				Object value = map.get(key);
+				if (field.equals(keyField)) {
+					// value不为空,即为已存在数据
+					if (value != null && !value.equals("") && !value.equals("null") && Integer.parseInt(value.toString()) > 0) {
+						keyValue = value;
+					} else {// 否则,为新添加的数据
+						sb1 = null;
+						break;
+					}
+				}
+				sb1.append(field);
+				sb1.append("=");
+				if (value != null) {
+					String val = value.toString();
+					if (value.toString().equals("null")) {
+						sb1.append("null");
+					} else if (val.contains("%n")) {
+						sb1.append("'" + val.replaceAll("%n", "\n") + "'");
+					} else if (val.contains("'")) {
+						sb1.append("'" + value.toString().replaceAll("'", "''") + "'");
+					} else {
+						sb1.append("'" + value + "'");
+					}
+				} else {
+					sb1.append("null");
+				}
+				sb1.append(",");
+			}
+			if (sb1 != null) {
+				sqls.add(sb1.substring(0, sb1.length() - 1) + " WHERE " + keyField + "='" + keyValue + "'");
+			}
+		}
+		return CollectionUtil.reverse(sqls);
+	}
+
+	/**
+	 * notice that trigger must be defined
+	 * 
+	 * @param maps
+	 * @param table
+	 * @param keyField
+	 * @return
+	 */
+	public static List<String> getInsertOrUpdateSqlbyGridStore(List<Map<Object, Object>> maps, String table, String keyField) {
+		List<String> sqls = new ArrayList<String>();
+		for (Map<Object, Object> map : maps) {
+			if (map.get(keyField) == null || "".equals(map.get(keyField)) || "null".equals(map.get(keyField))
+					|| Integer.parseInt(String.valueOf(map.get(keyField))) <= 0) {
+				sqls.add(getInsertSql(map, table, keyField));
+				continue;
+			}
+			Set<Object> keys = map.keySet();
+			StringBuffer sb1 = new StringBuffer("UPDATE " + table + " SET ");
+			Object keyValue = "";
+			for (Object key : keys) {
+				String field = (String) key;
+				Object value = map.get(key);
+				if (field.equals(keyField)) {
+					// value不为空,即为已存在数据
+					if (value != null && !value.equals("") && !value.equals("null") && Integer.parseInt(value.toString()) > 0) {
+						keyValue = value;
+					} else {// 否则,为新添加的数据
+						sb1 = null;
+						break;
+					}
+				}
+				sb1.append(field);
+				sb1.append("=");
+				if (value != null) {
+					String val = value.toString();
+					if (val.matches(REG_D)) {// 判断是否是形如yyyy-mm-dd格式的日期类型数据
+						sb1.append(DateUtil.parseDateToOracleString(Constant.YMD, val));
+					} else if (val.matches(REG_DT)) {
+						sb1.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val));
+					} else if (val.matches(REG_TS)) {
+						sb1.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val.substring(0, val.lastIndexOf("."))));
+					} else if (value.toString().equals("null")) {
+						sb1.append("null");
+					} else if (val.contains("%n")) {
+						sb1.append("'" + val.replaceAll("%n", "\n") + "'");
+					} else if (val.contains("'")) {
+						sb1.append("'" + value.toString().replaceAll("'", "''") + "'");
+					} else {
+						sb1.append("'" + value + "'");
+					}
+				} else {
+					sb1.append("null");
+				}
+				sb1.append(",");
+			}
+			if (sb1 != null)
+				sqls.add(sb1.substring(0, sb1.length() - 1) + " WHERE " + keyField + "='" + keyValue + "'");
+		}
+		return sqls;
+	}
+
+	public static List<String> getInsertOrUpdateSql(List<Map<Object, Object>> maps, String table, String keyField) {
+		List<String> sqls = new ArrayList<String>();
+		for (Map<Object, Object> map : maps) {
+			if (map.get(keyField) == null || "".equals(map.get(keyField)) || "null".equals(map.get(keyField))
+					|| Integer.parseInt(String.valueOf(map.get(keyField))) <= 0) {
+				sqls.add(getInsertSql(map, table, keyField));
+				continue;
+			}
+			Set<Object> keys = map.keySet();
+			StringBuffer sb1 = new StringBuffer("UPDATE " + table + " SET ");
+			Object keyValue = "";
+			for (Object key : keys) {
+				String field = (String) key;
+				Object value = map.get(key);
+				if (field.equals(keyField)) {
+					// value不为空,即为已存在数据
+					if (value != null && !value.equals("") && !value.equals("null") && Integer.parseInt(value.toString()) > 0) {
+						keyValue = value;
+					} else {// 否则,为新添加的数据
+						sb1 = null;
+						break;
+					}
+				}
+				sb1.append(field);
+				sb1.append("=");
+				if (value != null) {
+					String val = value.toString();
+					if (val.matches(REG_D)) {// 判断是否是形如yyyy-mm-dd格式的日期类型数据
+						sb1.append(DateUtil.parseDateToOracleString(Constant.YMD, val));
+					} else if (val.matches(REG_DT)) {
+						sb1.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val));
+					} else if (val.matches(REG_TS)) {
+						sb1.append(DateUtil.parseDateToOracleString(Constant.YMD_HMS, val.substring(0, val.lastIndexOf("."))));
+					} else if (value.toString().equals("null")) {
+						sb1.append("null");
+					} else if (val.contains("'")) {
+						sb1.append("'" + val.replaceAll("'", "''") + "'");
+					} else if (val.contains("%n")) {
+						sb1.append("'" + val.replaceAll("%n", "\n") + "'");
+					} else {
+						sb1.append("'" + value + "'");
+					}
+				} else {
+					sb1.append("null");
+				}
+				sb1.append(",");
+			}
+			if (sb1 != null)
+				sqls.add(sb1.substring(0, sb1.length() - 1) + " WHERE " + keyField + "='" + keyValue + "'");
+		}
+		return sqls;
+	}
+
+	public static Object createOracleLob(OracleConnection conn, String lobClassName) throws Exception {
+		@SuppressWarnings("rawtypes")
+		Class lobClass = conn.getClass().getClassLoader().loadClass(lobClassName);
+		final Integer DURATION_SESSION = new Integer(lobClass.getField("DURATION_SESSION").getInt(null));
+		final Integer MODE_READWRITE = new Integer(lobClass.getField("MODE_READWRITE").getInt(null));
+		@SuppressWarnings("unchecked")
+		Method createTemporary = lobClass.getMethod("createTemporary", new Class[] { Connection.class, boolean.class, int.class });
+		Object lob = createTemporary.invoke(null, new Object[] { conn, false, DURATION_SESSION });
+		@SuppressWarnings("unchecked")
+		Method open = lobClass.getMethod("open", new Class[] { int.class });
+		open.invoke(lob, new Object[] { MODE_READWRITE });
+		return lob;
+	}
+
+	public static String oracleClob2Str(Clob clob) throws Exception {
+		return (clob != null ? clob.getSubString(1, (int) clob.length()) : null);
+	}
+
+	public static Clob oracleStr2Clob(String str, Clob lob) throws Exception {
+		Method methodToInvoke = lob.getClass().getMethod("getCharacterOutputStream", (Class[]) null);
+		Writer writer = (Writer) methodToInvoke.invoke(lob, (Object[]) null);
+		writer.write(str);
+		writer.close();
+		return lob;
+	}
+
+	public static Map<String, String> splitCondition(String condition, String... fields) {
+		if (condition != null && condition.length() > 0) {
+			String[] strs = condition.toUpperCase().split(" AND ");
+			Map<String, String> ns = new HashMap<String, String>();
+			int i = 0;
+			int j = 0;
+			int len = condition.length();
+			for (String s : strs) {
+				i = j;
+				j += s.length();
+				if (i > 0 && j < len) {
+					i += 5;
+					j += 5;
+				}
+				if (s.trim().length() > 0) {
+					for (String field : fields) {
+						if (s.contains(field.toUpperCase()) && s.contains("=")) {
+							String[] su = condition.substring(i, j).split("=");
+							ns.put(field, su[1]);
+							break;
+						}
+					}
+				}
+			}
+			return ns;
+		}
+		return null;
+	}
+
+	/**
+	 * 拆分condition 拆出来的条件还是带单引号的
+	 * 
+	 * @param condition
+	 * @return
+	 */
+	public static Map<String, String> splitCondition(String condition) {
+		if (condition != null && condition.length() > 0) {
+			String[] strs = condition.toUpperCase().split(" AND ");
+			Map<String, String> ns = new HashMap<String, String>();
+			int i = 0;
+			int j = 0;
+			int len = condition.length();
+			for (String s : strs) {
+				i = j;
+				j += s.length();
+				if (i > 0 && j < len) {
+					i += 5;
+					j += 5;
+				}
+				if (s.trim().length() > 0) {
+					if (s.contains("=")) {
+						String[] su = condition.substring(i, j).split("=");
+						ns.put(su[0], su[1]);
+					}
+				}
+			}
+			return ns;
+		}
+		return null;
+	}
+
+	/**
+	 * 字符串按逗号分隔,每个元素加单引号
+	 * 
+	 * @param str
+	 * @return
+	 */
+	public static String splitToSqlString(String str) {
+		return splitToSqlString(str, ",");
+	}
+
+	/**
+	 * 字符串按逗号分隔,每个元素加单引号
+	 * 
+	 * @param str
+	 * @param separ
+	 *            分隔符
+	 * @return
+	 */
+	public static String splitToSqlString(String str, String separ) {
+		if (str != null) {
+			String[] strs = str.split(separ);
+			StringBuffer sb = new StringBuffer();
+			for (String k : strs) {
+				if (sb.length() > 0)
+					sb.append(",");
+				sb.append("'").append(k).append("'");
+			}
+			return sb.toString();
+		}
+		return null;
+	}
+
+}

+ 262 - 0
src/com/mes/core/StringUtil.java

@@ -0,0 +1,262 @@
+package com.mes.core;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.HashSet;
+import java.util.Random;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import org.springframework.util.StringUtils;
+
+/**
+ * 字符串操作工具
+ * 
+ * @author yingp
+ * 
+ */
+public class StringUtil {
+	/**
+	 * 前台使用escepe之后,java里面解析
+	 * 
+	 * @param escapeStr
+	 * @return
+	 */
+	public static String unescape(String escapeStr) {
+		if (escapeStr != null) {
+			return JSONUtil.decodeUnicode(escapeStr.replace("%", "\\"));
+		}
+		return null;
+	}
+
+	/**
+	 * 查找字符串重复项
+	 * 
+	 * @param str
+	 * @param ch
+	 * @return
+	 */
+	public static String getRepeats(String str, String ch) {
+		Set<String> set = new HashSet<String>();
+		String[] datas = str.split(ch);
+		StringBuffer repeat = new StringBuffer();
+		for (String s : datas) {
+			if (s != null && !s.trim().equals("")) {
+				if (!set.contains(s)) {
+					set.add(s);
+				} else {
+					if (repeat.length() > 0) {
+						repeat.append(",");
+					}
+					repeat.append(s);
+				}
+			}
+		}
+		return repeat.toString();
+	}
+
+	/**
+	 * 去掉字符串重复项
+	 * 
+	 * @param str
+	 * @param ch
+	 * @return
+	 */
+	public static String deleteRepeats(String str, String ch) {
+		Set<String> set = new HashSet<String>();
+		String[] datas = str.split(ch);
+		StringBuffer repeat = new StringBuffer();
+		for (String s : datas) {
+			if (s != null && !s.trim().equals("")) {
+				if (!set.contains(s)) {
+					set.add(s);
+					repeat.append(s + ch);
+				}
+			}
+		}
+		return repeat.toString().substring(0, repeat.toString().length() - 1);
+	}
+
+	/**
+	 * InputStream转成字符串
+	 * 
+	 * @param in
+	 * @return
+	 */
+	public static String parserInputStream(InputStream in) {
+		BufferedReader br = new BufferedReader(new InputStreamReader(in));
+		StringBuffer buffer = new StringBuffer();
+		String line = null;
+		try {
+			while ((line = br.readLine()) != null) {
+				buffer.append(line);
+			}
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return buffer.toString();
+	}
+
+	/**
+	 * 字符串是否在数组里面
+	 */
+	public static boolean isInArray(String[] objs, String str) {
+		boolean bool = false;
+		for (String obj : objs) {
+			if (obj.equals(str)) {
+				bool = true;
+				break;
+			}
+		}
+		return bool;
+	}
+
+	/**
+	 * 判断参数是否为空、空字符串、空白格
+	 * 
+	 * @param object
+	 * @return
+	 */
+	public static boolean hasText(Object object) {
+		return object == null ? false : StringUtils.hasText(object.toString());
+	}
+
+	/**
+	 * @param object
+	 * @return 字符串
+	 */
+	public static String valueOf(Object object) {
+		return (object == null) ? null : object.toString();
+	}
+
+	/**
+	 * 当object为空时,返回nvlValue,否则返回object
+	 * 
+	 * @param object
+	 * @param nvlValue
+	 * @return
+	 */
+	public static String nvl(Object object, String nvlValue) {
+		return !hasText(object) ? nvlValue : object.toString();
+	}
+
+	/**
+	 * 类似于String.format的逆运算
+	 * 
+	 * @param paramString
+	 *            待解析字符串
+	 * @param pattern
+	 *            表达式
+	 * @return
+	 */
+	public static String[] parse(String paramString, String pattern) {
+		String[] patternArray = pattern.split("%s");
+		int i = 0;
+		int strLen = paramString.length();
+		int len = patternArray.length;
+		int startIndex = 0;
+		int endIndex = 0;
+		String macher = null;
+		String temp = paramString;
+		String[] macherArray = new String[pattern.endsWith("%s") ? len : (len - 1)];
+		for (String patternStr : patternArray) {
+			startIndex += patternStr.length();
+			if (startIndex == strLen)
+				break;
+			temp = paramString.substring(startIndex);
+			if (i < len - 1)
+				endIndex = startIndex + temp.indexOf(patternArray[i + 1]);
+			else
+				endIndex = paramString.length();
+			macher = paramString.substring(startIndex, endIndex);
+			macherArray[i++] = macher;
+			if (i == macherArray.length)
+				break;
+			else
+				startIndex = endIndex;
+		}
+		return macherArray;
+	}
+
+	/**
+	 * 判断是否包含汉字
+	 * 
+	 * @param paramString
+	 * @return
+	 */
+	public static boolean hasChinese(String paramString) {
+		String regExp = "[\\u4e00-\\u9fa5]";
+		Pattern p = Pattern.compile(regExp);
+		return p.matcher(paramString).find();
+	}
+
+	final static char[] numbersAndLettersCharArray = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
+			'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5',
+			'6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
+			'V', 'W', 'X', 'Y', 'Z' };
+
+	/**
+	 * 产生给定长度的随机字符串
+	 * 
+	 * @param length
+	 * @return
+	 */
+	public static String getRandomString(int length) {
+		if (length < 1) {
+			return null;
+		}
+		Random randGen = new Random();
+		char[] randBuffer = new char[length];
+		for (int i = 0; i < randBuffer.length; i++) {
+			randBuffer[i] = numbersAndLettersCharArray[randGen.nextInt(71)];
+		}
+		return new String(randBuffer);
+	}
+
+	/**
+	 * 按长度分割字符串
+	 *
+	 * @param str
+	 *            原字符串
+	 * @param length
+	 */
+	public static String[] split(String str, int length) {
+		int strLen = str.length();
+		int len = (int) Math.ceil((double) strLen / length);
+		String[] strArray = new String[len];
+		for (int i = 0; i < len; i++) {
+			strArray[i] = str.substring(i * length, i < len - 1 ? (i + 1) * length : strLen);
+		}
+		return strArray;
+	}
+
+	/**
+	 * 按长度分割字符串
+	 * 
+	 * @param str
+	 *            原字符串
+	 * @param length
+	 *            切割长度
+	 * @param prevStr
+	 *            前置字符串
+	 * @param subStr
+	 *            后置字符串
+	 * @param concatStr
+	 *            连接字符串
+	 * @return
+	 */
+	public static String splitAndConcat(String str, int length, String prevStr, String subStr, String concatStr) {
+		int strLen = str.length();
+		int len = (int) Math.ceil((double) strLen / length);
+		StringBuffer buffer = new StringBuffer();
+		for (int i = 0; i < len; i++) {
+			if (i > 0)
+				buffer.append(concatStr);
+			buffer.append(prevStr).append(str.substring(i * length, i < len - 1 ? (i + 1) * length : strLen)).append(subStr);
+		}
+		return buffer.toString();
+	}
+
+}

+ 31 - 0
src/com/mes/core/SystemException.java

@@ -0,0 +1,31 @@
+package com.mes.core;
+
+/**
+ * 系统程序执行异常
+ * 
+ * @author yingp
+ * 
+ */
+public class SystemException extends RuntimeException {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 4218425517031998401L;
+
+	public SystemException() {
+	}
+
+	public SystemException(String paramString) {
+		super(paramString);
+	}
+
+	public SystemException(String paramString, Throwable paramThrowable) {
+		super(paramString, paramThrowable);
+	}
+
+	public SystemException(Throwable paramThrowable) {
+		super(paramThrowable);
+	}
+
+}

+ 40 - 0
src/com/mes/core/encry/Hex.java

@@ -0,0 +1,40 @@
+package com.mes.core.encry;
+
+public final class Hex {
+	private static final char[] HEX = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
+
+	public static char[] encode(byte[] bytes) {
+		int nBytes = bytes.length;
+		char[] result = new char[2 * nBytes];
+
+		int j = 0;
+		for (int i = 0; i < nBytes; ++i) {
+			result[(j++)] = HEX[((0xF0 & bytes[i]) >>> 4)];
+
+			result[(j++)] = HEX[(0xF & bytes[i])];
+		}
+
+		return result;
+	}
+
+	public static byte[] decode(CharSequence s) {
+		int nChars = s.length();
+
+		if (nChars % 2 != 0) {
+			throw new IllegalArgumentException("Hex-encoded string must have an even number of characters");
+		}
+
+		byte[] result = new byte[nChars / 2];
+
+		for (int i = 0; i < nChars; i += 2) {
+			int msb = Character.digit(s.charAt(i), 16);
+			int lsb = Character.digit(s.charAt(i + 1), 16);
+
+			if ((msb < 0) || (lsb < 0)) {
+				throw new IllegalArgumentException("Non-hex character in input: " + s);
+			}
+			result[(i / 2)] = (byte) (msb << 4 | lsb);
+		}
+		return result;
+	}
+}

+ 100 - 0
src/com/mes/core/encry/HmacEncoder.java

@@ -0,0 +1,100 @@
+package com.mes.core.encry;
+
+import java.security.InvalidKeyException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+
+import javax.crypto.KeyGenerator;
+import javax.crypto.Mac;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.SecretKeySpec;
+
+/**
+ * Hash-based message authentication code,利用哈希算法,以一个密钥和一个消息为输入,生成一个消息摘要作为输出
+ * 
+ * @author yingp
+ *
+ */
+public class HmacEncoder {
+
+	private final String algorithm;
+
+	public HmacEncoder(String algorithm) {
+		this.algorithm = algorithm;
+	}
+
+	/**
+	 * 根据给定密钥生成算法创建密钥
+	 * 
+	 * @param algorithm
+	 *            密钥算法
+	 * @return 密钥
+	 * @throws RuntimeException
+	 *             当 {@link java.security.NoSuchAlgorithmException} 发生时
+	 */
+	public byte[] getKey() {
+		// 初始化KeyGenerator
+		KeyGenerator keyGenerator = null;
+		try {
+			keyGenerator = KeyGenerator.getInstance(algorithm);
+		} catch (NoSuchAlgorithmException e) {
+			throw new RuntimeException(e.getMessage());
+		}
+		// 产生密钥
+		SecretKey secretKey = keyGenerator.generateKey();
+		// 获得密钥
+		return secretKey.getEncoded();
+	}
+
+	/**
+	 * 转换密钥
+	 * 
+	 * @param key
+	 *            二进制密钥
+	 * @param algorithm
+	 *            密钥算法
+	 * @return 密钥
+	 */
+	private static Key toKey(byte[] key, String algorithm) {
+		// 生成密钥
+		return new SecretKeySpec(key, algorithm);
+	}
+
+	/**
+	 * 使用指定消息摘要算法计算消息摘要
+	 * 
+	 * @param data
+	 *            做消息摘要的数据
+	 * @param key
+	 *            密钥
+	 * @return 消息摘要(长度为16的字节数组)
+	 */
+	public byte[] encode(byte[] data, Key key) {
+		Mac mac = null;
+		try {
+			mac = Mac.getInstance(algorithm);
+			mac.init(key);
+		} catch (NoSuchAlgorithmException e) {
+			e.printStackTrace();
+			return new byte[0];
+		} catch (InvalidKeyException e) {
+			e.printStackTrace();
+			return new byte[0];
+		}
+		return mac.doFinal(data);
+	}
+
+	/**
+	 * 使用指定消息摘要算法计算消息摘要
+	 * 
+	 * @param data
+	 *            做消息摘要的数据
+	 * @param key
+	 *            密钥
+	 * @return 消息摘要(长度为16的字节数组)
+	 */
+	public byte[] encode(byte[] data, byte[] key) {
+		return encode(data, toKey(key, algorithm));
+	}
+
+}

+ 9 - 0
src/com/mes/core/encry/HmacMD5Encoder.java

@@ -0,0 +1,9 @@
+package com.mes.core.encry;
+
+public class HmacMD5Encoder extends HmacEncoder {
+
+	public HmacMD5Encoder() {
+		super("HmacMD5");
+	}
+
+}

+ 9 - 0
src/com/mes/core/encry/HmacSHA1Encoder.java

@@ -0,0 +1,9 @@
+package com.mes.core.encry;
+
+public class HmacSHA1Encoder extends HmacEncoder {
+
+	public HmacSHA1Encoder() {
+		super("HmacSHA1");
+	}
+
+}

+ 9 - 0
src/com/mes/core/encry/HmacSHA256Encoder.java

@@ -0,0 +1,9 @@
+package com.mes.core.encry;
+
+public class HmacSHA256Encoder extends HmacEncoder {
+
+	public HmacSHA256Encoder() {
+		super("HmacSHA256");
+	}
+
+}

+ 9 - 0
src/com/mes/core/encry/HmacSHA384Encoder.java

@@ -0,0 +1,9 @@
+package com.mes.core.encry;
+
+public class HmacSHA384Encoder extends HmacEncoder {
+
+	public HmacSHA384Encoder() {
+		super("HmacSHA384");
+	}
+
+}

+ 9 - 0
src/com/mes/core/encry/HmacSHA512Encoder.java

@@ -0,0 +1,9 @@
+package com.mes.core.encry;
+
+public class HmacSHA512Encoder extends HmacEncoder {
+
+	public HmacSHA512Encoder() {
+		super("HmacSHA512");
+	}
+
+}

+ 46 - 0
src/com/mes/core/encry/HmacUtils.java

@@ -0,0 +1,46 @@
+package com.mes.core.encry;
+
+/**
+ * Hmac加密工具
+ * 
+ * @author yingp
+ *
+ */
+public class HmacUtils {
+
+	private static HmacEncoder hmacEncoder;
+
+	// 默认约定密钥
+	private final static byte[] key = { 104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 117, 98, 116, 111, 98, 46, 99, 111, 109, 47,
+			101, 114, 112, 47, 115, 97, 108, 101, 47, 111, 114, 100, 101, 114, 115, 63, 115, 111, 109, 101, 116, 104, 105, 110, 103 };
+
+	static {
+		// default algorithm: HmacSHA256
+		hmacEncoder = new HmacSHA256Encoder();
+	}
+
+	/**
+	 * 
+	 * @param message
+	 *            明文
+	 * @return 16进制密文
+	 */
+	public static String encode(Object message) {
+		byte[] encodeData = hmacEncoder.encode(String.valueOf(message).getBytes(), key);
+		return new String(Hex.encode(encodeData));
+	}
+
+	/**
+	 * 
+	 * @param message
+	 *            明文
+	 * @param key
+	 *            密钥
+	 * @return 16进制密文
+	 */
+	public static String encode(Object message, String key) {
+		byte[] encodeData = hmacEncoder.encode(String.valueOf(message).getBytes(), key.getBytes());
+		return new String(Hex.encode(encodeData));
+	}
+
+}

+ 75 - 0
src/com/mes/core/interceptor/DbSourceInterceptor.java

@@ -0,0 +1,75 @@
+package com.mes.core.interceptor;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.web.servlet.ModelAndView;
+import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
+
+import com.mes.core.BaseUtil;
+import com.mes.core.support.MobileSessionContext;
+import com.mes.core.support.SystemSession;
+import com.mes.dao.SpObserver;
+import com.mes.model.Employee;
+
+/**
+ * 自定义拦截器 每次请求之前根据session里面的账套信息切换数据源
+ * 
+ * @author yingp
+ */
+public class DbSourceInterceptor extends HandlerInterceptorAdapter {
+
+	/**
+	 * 处理前台请求之前执行
+	 */
+	@Override
+	public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {		
+		Object obj = req.getSession().getAttribute("employee");				
+		String sessionId = req.getParameter("sessionId");
+		if (obj == null && sessionId != null){
+			if (MobileSessionContext.getInstance().getSessionById(sessionId) != null) {
+				req.getSession().setAttribute("employee",
+						MobileSessionContext.getInstance().getSessionById(sessionId).getAttribute("employee"));
+				return true;
+			} else {
+				BaseUtil.showError("ERR_NETWORK_SESSIONOUT");
+				return false;
+			}
+		}
+		if (obj != null) {
+			Employee employee = (Employee) obj;
+			// 记录到当前线程里面
+			SystemSession.setUser(employee);
+			SystemSession.setLang(req.getSession().getAttribute("language"));
+			String db = employee.getEm_master();
+			Object master = req.getParameter("master");
+			if (master != null && !master.equals("")) {
+				SpObserver.putSp(master.toString());
+			} else if (db != null && db.length() > 0) {
+				SpObserver.putSp(db);
+			}
+		} else{
+			/*BaseUtil.showError("请先登录ERP再进行相关操作");
+			return false;*/
+		}
+		return true;
+	}
+
+	/**
+	 * 处理完前台请求之后执行
+	 */
+	@Override
+	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
+			throws Exception {
+	}
+
+	/**
+	 * 所有请求处理完成之后执行
+	 */
+	@Override
+	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
+		SystemSession.clear();
+		SpObserver.clear();
+	}
+
+}

+ 283 - 0
src/com/mes/core/interceptor/ExceptionHandlerAdvice.java

@@ -0,0 +1,283 @@
+package com.mes.core.interceptor;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.sql.SQLRecoverableException;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DuplicateKeyException;
+import org.springframework.http.HttpStatus;
+import org.springframework.jdbc.BadSqlGrammarException;
+import org.springframework.jdbc.UncategorizedSQLException;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+import com.mes.core.BaseUtil;
+import com.mes.core.StringUtil;
+import com.mes.core.SystemException;
+import com.mes.core.logging.BufferedLoggerManager;
+import com.mes.dao.BaseDao;
+import com.mes.service.common.impl.DebugBufferedLogger;
+
+/**
+ * <p>
+ * 基于Application的异常处理,以AOP的形式注册到SpringMVC的处理链
+ * </p>
+ * <p>
+ * 正常的业务流程,只需抛出对应的异常和相关的信息
+ * </P>
+ * <p>
+ * 不同的错误,对应不同的方法来处理
+ * </p>
+ * 
+ * @author yingp
+ * 
+ */
+@ControllerAdvice
+public class ExceptionHandlerAdvice {
+
+	@Autowired
+	private BaseDao baseDao;
+
+	private final static Logger logger = Logger.getLogger(ExceptionHandlerAdvice.class);
+
+	/**
+	 * 异步记录debug日志的工具
+	 */
+	private DebugBufferedLogger debugLogger = BufferedLoggerManager.getLogger(DebugBufferedLogger.class);
+
+	/**
+	 * 处理未被发现处理的运行时抛出异常
+	 * 
+	 * @param ex
+	 * @return
+	 */
+	@ExceptionHandler(RuntimeException.class)
+	@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
+	@ResponseBody
+	public ModelMap handleUnexpectedServerError(RuntimeException ex, HttpServletRequest request) {
+		ModelMap map = new ModelMap();
+		if (!"ERR_NETWORK_SESSIONOUT".equals(ex.getMessage())) {
+			logger.error(ex);
+			ex.printStackTrace();
+			map.put("exceptionInfo", getErrorStack(request, ex, "程序错误"));
+		} else {
+			map.put("exceptionInfo", ex.getMessage());
+		}
+		logErrorDebug(request);
+		return map;
+	}
+
+	/**
+	 * 处理通过BaseUtil.showError抛出的异常
+	 * 
+	 * @param ex
+	 * @return
+	 */
+	@ExceptionHandler(SystemException.class)
+	@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
+	@ResponseBody
+	public ModelMap handleSystemError(SystemException ex, HttpServletRequest request) {
+		ModelMap map = new ModelMap();
+		if (!"ERR_NETWORK_SESSIONOUT".equals(ex.getMessage())) {
+			logger.error(ex);
+		}
+		map.put("exceptionInfo", ex.getMessage());
+		logErrorDebug(request);
+		return map;
+	}
+
+	/**
+	 * 处理thread.interrupt抛出的异常
+	 * 
+	 * @param ex
+	 * @return
+	 */
+	@ExceptionHandler(InterruptedException.class)
+	@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
+	@ResponseBody
+	public ModelMap handleInterruptedExceptionError(InterruptedException ex, HttpServletRequest request) {
+		ModelMap map = new ModelMap();
+		map.put("exceptionInfo", "处理超时");
+		logTimeoutDebug(request);
+		return map;
+	}
+
+	/**
+	 * 处理连接池的连接失效抛出异常
+	 * 
+	 * @see SQLRecoverableException
+	 * @param ex
+	 * @return
+	 */
+	@ExceptionHandler(SQLRecoverableException.class)
+	@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
+	@ResponseBody
+	public ModelMap handleSQLRecoverableExceptionError(SQLRecoverableException ex, HttpServletRequest request) {
+		ModelMap map = new ModelMap();
+		map.put("exceptionInfo", getErrorStack(request, ex, "连接异常"));
+		logErrorDebug(request);
+		return map;
+	}
+
+	/**
+	 * 违反唯一约束条件抛出异常
+	 * 
+	 * @see DuplicateKeyException
+	 * @param ex
+	 * @return
+	 */
+	@ExceptionHandler(DuplicateKeyException.class)
+	@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
+	@ResponseBody
+	public ModelMap handleDuplicateKeyExceptionError(DuplicateKeyException ex, HttpServletRequest request) {
+		// 取得唯一约束条件
+		String cause = ex.getCause().toString();
+		String causeIndex = cause.substring(cause.lastIndexOf("(") + 1, cause.lastIndexOf(")"));
+		if (causeIndex.contains("."))
+			causeIndex = causeIndex.substring(causeIndex.indexOf(".") + 1);
+		String desc = baseDao
+				.getJdbcTemplate()
+				.queryForObject(
+						"select wm_concat(comments) from user_ind_columns a left join user_col_comments b on a.table_name=b.table_name and a.column_name=b.column_name where index_name=? ",
+						String.class, causeIndex);
+		if (desc == null) {
+			desc = baseDao
+					.getJdbcTemplate()
+					.queryForObject(
+							"select wm_concat(comments) from user_cons_columns a left join user_col_comments b on a.table_name=b.table_name and a.column_name=b.column_name where constraint_name=? ",
+						String.class, causeIndex);
+		}
+		if (desc == null)
+			desc = "违反唯一约束条件";
+		else
+			desc = "(" + desc + ") 重复";
+		ModelMap map = new ModelMap();
+		ex.printStackTrace();
+		map.put("exceptionInfo", desc);
+		logErrorDebug(request);
+		return map;
+	}
+
+	/**
+	 * 处理参数错误抛出异常
+	 * 
+	 * @see IllegalArgumentException
+	 * @param ex
+	 * @return
+	 */
+	@ExceptionHandler(IllegalArgumentException.class)
+	@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
+	@ResponseBody
+	public ModelMap handleIllegalArgumentExceptionError(IllegalArgumentException ex, HttpServletRequest request) {
+		logger.error(ex.getCause());
+		ex.printStackTrace();
+		ModelMap map = new ModelMap();
+		map.put("exceptionInfo", getErrorStack(request, ex, "参数错误"));
+		logErrorDebug(request);
+		return map;
+	}
+
+	/**
+	 * SQL语法错误
+	 * 
+	 * @param ex
+	 * @return
+	 */
+	@ExceptionHandler(BadSqlGrammarException.class)
+	@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
+	@ResponseBody
+	public ModelMap handleBadSqlGrammarExceptionError(BadSqlGrammarException ex, HttpServletRequest request) {
+		logger.error(ex);
+		ModelMap map = new ModelMap();
+		ex.printStackTrace();
+		map.put("exceptionInfo", getErrorStack(request, ex, "程序错误"));
+		logErrorDebug(request);
+		return map;
+	}
+
+	static final String VALUE_TOO_LARGE_CAUSE_CN = "java.sql.SQLException: ORA-12899: 列 \"%s\".\"%s\".\"%s\" 的值太大 (实际值: %s, 最大值: %s)";
+
+	static final String VALUE_TOO_LARGE_CAUSE_EN = "java.sql.SQLException: ORA-12899: value too large for column \"%s\".\"%s\".\"%s\" (actual: %s, maximum: %s)";
+
+	/**
+	 * SQL查询语句异常
+	 * 
+	 * @param ex
+	 * @return
+	 */
+	@ExceptionHandler(UncategorizedSQLException.class)
+	@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
+	@ResponseBody
+	public ModelMap handleUncategorizedSQLExceptionError(UncategorizedSQLException ex, HttpServletRequest request) {
+		logger.error(ex);
+		ex.printStackTrace();
+		int errorCode = ex.getSQLException().getErrorCode();
+		String exInfo = getErrorStack(request, ex, "程序错误");
+		// 值太大
+		if (errorCode == 12899) {
+			String cause = ex.getCause().toString();
+			String[] params = StringUtil.parse(cause, StringUtil.hasChinese(cause) ? VALUE_TOO_LARGE_CAUSE_CN : VALUE_TOO_LARGE_CAUSE_EN);
+			String desc = baseDao.getJdbcTemplate().queryForObject(
+					"select nvl(b.comments,a.column_name)  from User_Tab_Columns a left join  User_Col_Comments b on A.Table_Name=B.Table_Name and A.Column_Name=B.column_name where a.table_name=? and a.column_name=?",
+					String.class, params[1], params[2]);
+			exInfo = String.format("您填写的数据<u> %s </u>值太大,当前长度: %s,允许最大长度: %s", desc, params[3], params[4]);
+		}
+		ModelMap map = new ModelMap();
+		map.put("exceptionInfo", exInfo);
+		logErrorDebug(request);
+		return map;
+	}
+
+	/**
+	 * debug日志里面状态改为执行失败
+	 * 
+	 * @param request
+	 */
+	private void logErrorDebug(HttpServletRequest request) {
+		if ("true".equals(BaseUtil.getXmlSetting("debug"))) {
+			Object debugId = request.getAttribute(DebugBufferedLogger.debugAttribute);
+			if (debugId != null)
+				debugLogger.failure(request, debugId.toString());
+		}
+	}
+	
+	/**
+	 * debug日志里面状态改为执行超时
+	 * 
+	 * @param request
+	 */
+	private void logTimeoutDebug(HttpServletRequest request) {
+		if ("true".equals(BaseUtil.getXmlSetting("debug"))) {
+			Object debugId = request.getAttribute(DebugBufferedLogger.debugAttribute);
+			if (debugId != null)
+				debugLogger.timeout(request, debugId.toString());
+		}
+	}
+
+	/**
+	 * 封装错误信息,按用户设置是否显示栈信息
+	 * 
+	 * @param e
+	 * @param defaultText
+	 * @return
+	 */
+	private String getErrorStack(HttpServletRequest request, Exception e, String defaultText) {
+		Object debug = request.getSession().getAttribute("user.setting.debug");
+		if (debug != null && Boolean.valueOf(debug.toString())) {
+			StringWriter writer = new StringWriter();
+			e.printStackTrace(new PrintWriter(writer));
+			return "<div class=\"error-container\">"
+					+ "<a class=\"error-toggle\" onclick=\"document.getElementById('_error_stack').style.display='block';\">" + defaultText
+					+ "</a>" + "<div id=\"_error_stack\" class=\"error-body\" style=\"display:none;\">" + writer.toString() + "</div>"
+					+ "</div>";
+		}
+		return defaultText;
+	}
+}

+ 21 - 0
src/com/mes/core/logging/BufferedLogable.java

@@ -0,0 +1,21 @@
+package com.mes.core.logging;
+
+public abstract class BufferedLogable {
+
+	protected static final String separator = "#";
+
+	/**
+	 * 日志实体转化为字符串
+	 * 
+	 * @return
+	 */
+	public abstract String bufferedMessage();
+
+	/**
+	 * 字符串转化为日志实体
+	 * 
+	 * @param bufferedMessage
+	 */
+	public abstract void bufferedLog(String bufferedMessage);
+
+}

+ 156 - 0
src/com/mes/core/logging/BufferedLogger.java

@@ -0,0 +1,156 @@
+package com.mes.core.logging;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * 支持异步日志记录的工具类<br>
+ * 写日志时,会尝试将日志消息快速写到本地文件,失败的情况下直接写入到持久层
+ * 
+ * @author yingp
+ *
+ */
+public abstract class BufferedLogger<T extends BufferedLogable> {
+
+	/**
+	 * 日志文件夹路径
+	 */
+	private String logPath;
+
+	/**
+	 * 日志文件名
+	 */
+	private String currentLogFile;
+
+	private Class<T> logClass;
+
+	/**
+	 * 日志文件工具
+	 */
+	private FileBuffer fileBuffer;
+
+	/**
+	 * 日志持久化service
+	 */
+	private LogService<T> logService;
+
+	public BufferedLogger() {
+	}
+
+	/**
+	 * @param basePath
+	 *            日志文件根路径
+	 * @param logFile
+	 *            日志文件名
+	 * @param logService
+	 *            持久化工具
+	 */
+	public BufferedLogger(String basePath, Class<T> logClass, LogService<T> logService) {
+		this.logPath = basePath + File.separator + "buff_log" + File.separator + logClass.getName();
+		this.logClass = logClass;
+		this.fileBuffer = new FileBuffer(logPath, getFileName());
+		this.logService = logService;
+		// 检查是否有遗留日志未持久化的
+		leaveOver();
+	}
+
+	/**
+	 * 写日志操作
+	 * 
+	 * @param bufferedLogable
+	 */
+	public void log(T bufferedLogable) {
+		// 先尝试写到日志文件
+		if (!fileBuffer.append(bufferedLogable.bufferedMessage()) && logService != null)
+			// 写入失败的情况下,直接持久化
+			logService.save(bufferedLogable);
+	}
+
+	/**
+	 * 读日志
+	 * 
+	 * @param cls
+	 * @return
+	 */
+	protected Set<T> read(FileBuffer buffer) {
+		Set<T> logs = new HashSet<T>();
+		String bufferedMessage = null;
+		while ((bufferedMessage = buffer.readLine()) != null) {
+			try {
+				T instance = logClass.newInstance();
+				instance.bufferedLog(bufferedMessage);
+				logs.add(instance);
+			} catch (InstantiationException e) {
+
+			} catch (IllegalAccessException e) {
+
+			}
+		}
+		return logs;
+	}
+
+	/**
+	 * 日志文件名
+	 * 
+	 * @return
+	 */
+	protected String getFileName() {
+		this.currentLogFile = String.valueOf(System.currentTimeMillis());
+		return this.currentLogFile;
+	}
+
+	/**
+	 * 切换日志文件
+	 * 
+	 * @param newLogFile
+	 */
+	public void switchOver() {
+		FileBuffer oldFileBuffer = this.fileBuffer;
+		if (!oldFileBuffer.isEmpty()) {
+			// 创建新的日志文件,不影响日志的写入
+			this.fileBuffer = new FileBuffer(logPath, getFileName());
+			// 旧日志文件的内容取出,并持久化
+			if (logService != null)
+				logService.save(read(oldFileBuffer));
+			// 删除旧日志文件
+			oldFileBuffer.delete();
+		}
+	}
+
+	/**
+	 * 持久化遗留日志文件
+	 */
+	protected void leaveOver() {
+		if (logService != null) {
+			File folder = new File(logPath);
+			if (folder.isDirectory()) {
+				File[] files = folder.listFiles();
+				if (files != null) {
+					String fileName = null;
+					for (File file : files) {
+						fileName = file.getName();
+						if (!fileName.equals(currentLogFile)) {
+							FileBuffer buffer = new FileBuffer(logPath, fileName);
+							try {
+								logService.save(read(buffer));
+							} catch (Exception e) {
+
+							} finally {
+								buffer.delete();
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+
+	@Override
+	protected void finalize() throws Throwable {
+		super.finalize();
+		if (this.fileBuffer != null)
+			this.fileBuffer.close();
+	}
+
+}

+ 31 - 0
src/com/mes/core/logging/BufferedLoggerManager.java

@@ -0,0 +1,31 @@
+package com.mes.core.logging;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@SuppressWarnings("rawtypes")
+public class BufferedLoggerManager {
+
+	private static Map<String, BufferedLogger> loggers;
+
+	static {
+		loggers = new HashMap<String, BufferedLogger>();
+	}
+
+	@SuppressWarnings("unchecked")
+	public static <T extends BufferedLogger<S>, S extends BufferedLogable> T getLogger(Class<T> cls) {
+		String clsName = cls.getName();
+		if (loggers.containsKey(clsName)) {
+			return (T) loggers.get(clsName);
+		}
+		try {
+			T instance = cls.newInstance();
+			loggers.put(clsName, instance);
+			return instance;
+		} catch (InstantiationException e) {
+		} catch (IllegalAccessException e) {
+		}
+		return null;
+	}
+
+}

+ 125 - 0
src/com/mes/core/logging/FileBuffer.java

@@ -0,0 +1,125 @@
+package com.mes.core.logging;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+public class FileBuffer {
+
+	private String filePath;
+	private BufferedWriter writer;
+	private BufferedReader reader;
+
+	/**
+	 * @param folderPath
+	 *            文件夹目录
+	 * @param fileName
+	 *            文件名
+	 */
+	public FileBuffer(String folderPath, String fileName) {
+		File file = new File(folderPath);
+		if (!file.isDirectory())
+			file.mkdirs();
+		this.filePath = folderPath + File.separator + fileName;
+	}
+
+	/**
+	 * 文件里面追加一行内容
+	 * 
+	 * @param content
+	 * @return
+	 */
+	public synchronized boolean append(String content) {
+		boolean isEmpty = false;
+		if (writer == null)
+			try {
+				File file = new File(filePath);
+				if (!file.exists())
+					file.createNewFile();
+				writer = new BufferedWriter(new FileWriter(file, true));
+				isEmpty = true;
+			} catch (IOException e) {
+				return false;
+			}
+		try {
+			writer.write((isEmpty ? "" : "\r\n") + content);
+			writer.flush();
+		} catch (IOException e) {
+			return false;
+		}
+		return true;
+	}
+
+	public synchronized String readLine() {
+		if (writer != null)
+			close();
+		if (reader == null) {
+			File file = new File(filePath);
+			if (file.exists()) {
+				try {
+					InputStreamReader streamReader = new InputStreamReader(new FileInputStream(file));
+					reader = new BufferedReader(streamReader);
+				} catch (FileNotFoundException e) {
+					return null;
+				}
+			}
+		}
+		if (reader != null)
+			try {
+				return reader.readLine();
+			} catch (IOException e) {
+			}
+		return null;
+	}
+
+	/**
+	 * 关闭文件写入流
+	 */
+	protected synchronized void close() {
+		if (writer != null)
+			try {
+				writer.close();
+			} catch (IOException e) {
+
+			} finally {
+				writer = null;
+			}
+	}
+
+	public synchronized void delete() {
+		if (writer != null)
+			try {
+				writer.close();
+			} catch (IOException e1) {
+			} finally {
+				writer = null;
+			}
+		if (reader != null)
+			try {
+				reader.close();
+			} catch (IOException e) {
+			} finally {
+				reader = null;
+			}
+		File file = new File(filePath);
+		if (file.exists())
+			file.delete();
+	}
+
+	public synchronized boolean isEmpty() {
+		boolean empty = this.writer == null;
+		if (!empty) {
+			File file = new File(filePath);
+			empty = !file.exists();
+			if (!empty)
+				empty = file.length() == 0;
+		}
+		return empty;
+	}
+
+}

+ 21 - 0
src/com/mes/core/logging/LogService.java

@@ -0,0 +1,21 @@
+package com.mes.core.logging;
+
+import java.util.Collection;
+
+public abstract interface LogService<T extends BufferedLogable> {
+
+	/**
+	 * 日志持久化保存
+	 * 
+	 * @param logable
+	 */
+	public void save(T logable);
+
+	/**
+	 * 日志批量持久化保存
+	 * 
+	 * @param logables
+	 */
+	public void save(Collection<T> logables);
+
+}

+ 34 - 0
src/com/mes/core/support/MobileSessionContext.java

@@ -0,0 +1,34 @@
+package com.mes.core.support;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpSession;
+
+/**
+ *@author zhouy
+ *手机登陆 支持离线登陆
+ **/
+public class MobileSessionContext {
+	private static  MobileSessionContext mobileSessionContext;
+	private Map<String,HttpSession> sessionMap;
+	private MobileSessionContext() {     
+		sessionMap = new HashMap<String, HttpSession>();     
+    }     
+	public static MobileSessionContext getInstance(){
+		if(mobileSessionContext==null){
+			mobileSessionContext=new MobileSessionContext();
+		}
+		return mobileSessionContext;
+	}
+	public synchronized void createSession(HttpSession session){
+	   if(session!=null) 
+		 sessionMap.put(session.getId(), session);
+	}
+	public synchronized void destroySession(HttpSession session){
+		if(session!=null)  sessionMap.remove(session.getId());
+	}
+	public synchronized HttpSession getSessionById(String sessionId){
+		return sessionMap.get(sessionId);
+	}
+}

+ 98 - 0
src/com/mes/core/support/SpringDynamicCronTask.java

@@ -0,0 +1,98 @@
+package com.mes.core.support;
+
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.scheduling.Trigger;
+import org.springframework.scheduling.TriggerContext;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.SchedulingConfigurer;
+import org.springframework.scheduling.config.ScheduledTaskRegistrar;
+import org.springframework.scheduling.config.TriggerTask;
+import org.springframework.scheduling.support.CronTrigger;
+import org.springframework.stereotype.Component;
+
+import com.mes.core.BaseUtil;
+import com.mes.core.ContextUtil;
+import com.mes.core.SystemException;
+import com.mes.dao.BaseDao;
+import com.mes.model.ScheduleTask;
+
+@Lazy(false)
+@Component
+@EnableScheduling
+public class SpringDynamicCronTask implements SchedulingConfigurer{
+	
+	@Autowired
+	private BaseDao baseDao;
+
+	private static List<TriggerTask> taskList = new ArrayList<TriggerTask>();
+
+	@Override
+	public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
+		//在数据库中查询定时任务配置列表,得到list
+		try{
+			if ("true".equals(BaseUtil.getXmlSetting("task.status"))) {
+				//task.status 定时任务状态设置:为空或为false默认不启用,通过管理平台发布自动修改为ture
+			/*	initTaskList();*/
+			}
+			/*taskRegistrar.setTriggerTasksList(taskList);*/
+		}catch(Exception e){
+			
+		}
+	}
+	
+	public void initTaskList(){
+		String sql = "SELECT * FROM SYS_SCHEDULETASK WHERE ENABLE_ = -1";
+		List<ScheduleTask> list = baseDao.query(sql, ScheduleTask.class);
+		//遍历taskList,将每个task添加到要处理任务列表中
+		if(list != null && list.size() > 0){
+			for(final ScheduleTask task : list){
+				taskList.add(
+						new TriggerTask(
+								new Runnable(){
+									@Override
+									public void run(){
+										//通过反射执行相应的任务
+										try {
+											baseDao.execute("insert into SYS_SCHEDULETASKLOG(date_,remark_,scheduleid_) values"
+													+ "(sysdate,'执行开始',"+task.getId_()+")");
+											String beanName = task.getBean_();
+											Object bean = ContextUtil.getBean(beanName);
+											if(bean == null){
+												throw new SystemException("当前填写bean错误或不存在!");
+											}else{
+												Method method = bean.getClass().getMethod(task.getFunction_());
+												method.invoke(bean);
+											}
+											//记录操作日志
+											baseDao.execute("insert into SYS_SCHEDULETASKLOG(date_,remark_,scheduleid_) values"
+												+ "(sysdate,'执行结束',"+task.getId_()+")");
+										} catch (Exception e) {
+											if (e.getCause() != null) {
+												baseDao.execute("insert into SYS_SCHEDULETASKLOG(date_,remark_,scheduleid_) values"
+														+ "(sysdate,'执行失败:"+e.getCause().getMessage()+"',"+task.getId_()+")");
+											}else
+												baseDao.execute("insert into SYS_SCHEDULETASKLOG(date_,remark_,scheduleid_) values"
+													+ "(sysdate,'执行失败: "+e.getMessage()+"',"+task.getId_()+")");
+										}
+									}
+								},new Trigger(){
+									public Date nextExecutionTime(TriggerContext triggerContext) {
+										CronTrigger trigger = new CronTrigger(task.getCron_());  
+						                Date nextExec = trigger.nextExecutionTime(triggerContext);  
+						                return nextExec;  
+									}
+								}
+						)
+				);
+			}
+		}
+	}
+	
+}

+ 77 - 0
src/com/mes/core/support/SystemSession.java

@@ -0,0 +1,77 @@
+package com.mes.core.support;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.mes.core.CollectionUtil;
+import com.mes.model.Employee;
+
+/**
+ * 每次请求服务器时,用户信息、语言等存放在本次线程中
+ * 
+ * @author yingp
+ * @see UserInterceptor
+ * 
+ */
+public class SystemSession {
+
+	private static ThreadLocal<Employee> user = new ThreadLocal<Employee>();
+
+	private static ThreadLocal<String> lang = new ThreadLocal<String>();
+
+	private static ThreadLocal<List<String>> errors = new ThreadLocal<List<String>>();
+
+	public static void setUser(Employee employee) {
+		user.set(employee);
+	}
+
+	/**
+	 * @return 当前用户
+	 */
+	public static Employee getUser() {
+		return user.get();
+	}
+
+	public static void setLang(Object language) {
+		lang.set(language == null ? null : language.toString());
+	}
+
+	/**
+	 * @return 当前用户选择的语言
+	 */
+	public static String getLang() {
+		return lang.get();
+	}
+
+	/**
+	 * 针对出错后,暂时不中断程序,而是临时存放error信息,完成所有操作后,再返回给客户端
+	 * 
+	 * @param error
+	 */
+	public static void appendError(String error) {
+		List<String> es = errors.get();
+		if (es == null)
+			es = new ArrayList<String>();
+		es.add(error);
+		errors.set(es);
+	}
+
+	public static String getErrors() {
+		List<String> es = errors.get();
+		if (es != null && es.size() > 0) {
+			return CollectionUtil.toString(es, "\n");
+		}
+		return null;
+	}
+
+	public static void clearErrors() {
+		errors.set(null);
+	}
+
+	public static void clear() {
+		user.set(null);
+		lang.set(null);
+		errors.set(null);
+	}
+
+}

+ 1727 - 0
src/com/mes/dao/BaseDao.java

@@ -0,0 +1,1727 @@
+package com.mes.dao;
+
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import net.sf.json.JSONObject;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataAccessException;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
+import org.springframework.jdbc.core.CallableStatementCallback;
+import org.springframework.jdbc.core.CallableStatementCreator;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
+import org.springframework.jdbc.core.namedparam.SqlParameterSource;
+import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
+import org.springframework.jdbc.core.support.AbstractLobCreatingPreparedStatementCallback;
+import org.springframework.jdbc.core.support.JdbcDaoSupport;
+import org.springframework.jdbc.object.SqlUpdate;
+import org.springframework.jdbc.support.lob.DefaultLobHandler;
+import org.springframework.jdbc.support.lob.LobCreator;
+import org.springframework.jdbc.support.lob.LobHandler;
+import org.springframework.stereotype.Repository;
+
+import com.mes.core.BaseUtil;
+import com.mes.core.DateUtil;
+import com.mes.core.SqlUtil;
+import com.mes.core.SystemException;
+import com.mes.model.DBFindSet;
+import com.mes.model.DBFindSetDetail;
+import com.mes.model.DBFindSetUI;
+import com.mes.model.DetailGrid;
+import com.mes.model.Employee;
+
+/**
+ * @since 2013-1-9
+ *        <p>
+ *        用到SqlRowSet的方法全部用List<Map<String, Object>>代替, 以解决因jdk问题而导致jboss对RowSet的不支持,调取结果集时出现NullPointerException
+ *        </p>
+ * 
+ * 
+ * @author yingp
+ * 
+ * @since 2015-11-26
+ *        <p>
+ *        去掉支持Oracle9i的OracleLobHandler,改为使用{@link DefaultLobHandler},在db-config.xml注入
+ *        </p>
+ */
+@Repository("baseDao")
+public class BaseDao extends JdbcDaoSupport {
+
+	@Autowired
+	protected LobHandler lobHandler;
+
+	static final String SELECT_TABLES = "SELECT count(1) FROM user_tables WHERE table_name=?";// 从数据库查找表
+	static final String SELECT_VIEWS = "SELECT count(1) FROM user_views WHERE view_name=?";// 从数据库查找视图
+	static final String SELECT_DDD = "select  a.table_name,a.column_name,a.data_type,a.data_length,comments from  User_Tab_Columns a "
+			+ "left join user_col_comments  b on  a.table_name=b.table_name and a.column_name=b.column_name  where a.table_name=? order by column_id";// 从数据字典查找表
+	static final String CREATE_SEQ = "CREATE SEQUENCE ?" + // 创建序列
+			" MINVALUE 1 MAXVALUE 99999999999 INCREMENT BY 1 START WITH 3000 CACHE 20 NOORDER NOCYCLE ";
+	static final String FORM_TABLE = "SELECT fo_table FROM form WHERE fo_caller=?";
+	static final String DETAILGRID_TABLE = "SELECT dg_table FROM detailgrid WHERE dg_caller=?";
+
+	/**
+	 * add object
+	 * 
+	 * @param objForSave
+	 * @param tableName
+	 * @param columnAndValue
+	 * @param keyColumns
+	 * @return keyValue
+	 */
+	public Number saveAndReturnKey(Object objForSave, String tableName, String... keyColumns) {
+		SimpleJdbcInsert insertActor = getSimpleJdbcInsert();
+		insertActor.setTableName(tableName);
+		insertActor.usingGeneratedKeyColumns(keyColumns);
+		Number newId = insertActor.executeAndReturnKey(new BeanPropertySqlParameterSource(objForSave));
+		return newId;
+	}
+
+
+	/**
+	 * @param objForSave
+	 * @param tableName
+	 * @return
+	 */
+	public void save(Object objForSave, String tableName) {
+		SimpleJdbcInsert insertActor = getSimpleJdbcInsert();
+		insertActor.setTableName(tableName);
+		insertActor.execute(new BeanPropertySqlParameterSource(objForSave));
+	}
+
+	/**
+	 * 批量保存对象
+	 * 
+	 * @param objsForSave
+	 * @param tableName
+	 * @return
+	 */
+	public <T> void save(Collection<T> objsForSave, String tableName) {
+		SqlParameterSource[] sqlSource = new SqlParameterSource[objsForSave.size()];
+		int i = 0;
+		for (T obj : objsForSave) {
+			sqlSource[i++] = new BeanPropertySqlParameterSource(obj);
+		}
+		SimpleJdbcInsert insertActor = getSimpleJdbcInsert();
+		insertActor.setTableName(tableName);
+		insertActor.executeBatch(sqlSource);
+	}
+
+	/**
+	 * 
+	 * @param objForSave
+	 * @param tableName
+	 * @param keyColumns
+	 * @return
+	 */
+	public void save(Object objForSave, String tableName, String... keyColumns) {
+		SimpleJdbcInsert insertActor = getSimpleJdbcInsert();
+		insertActor.setTableName(tableName);
+		insertActor.execute(new BeanPropertySqlParameterSource(objForSave));
+	}
+
+	/**
+	 * 
+	 * @param objForSave
+	 * @param tableName
+	 * @param columnAndValue
+	 * @param keyColumns
+	 * @return
+	 */
+	public Number saveAndReturnKey(String tableName, Map<String, Object> columnAndValue, String... keyColumns) {
+		SimpleJdbcInsert insertActor = getSimpleJdbcInsert();
+		insertActor.setTableName(tableName);
+		insertActor.usingGeneratedKeyColumns(keyColumns);
+		Number newId = insertActor.executeAndReturnKey(columnAndValue);
+		return newId;
+	}
+
+	public SimpleJdbcInsert getSimpleJdbcInsert() {
+		return new SimpleJdbcInsert(getJdbcTemplate());
+	}
+
+	public SimpleJdbcInsert getSimpleJdbcInsert(String tableName) {
+		return new SimpleJdbcInsert(getJdbcTemplate());
+	}
+
+	/**
+	 * print sql
+	 */
+	public void traceSql(String sql) {
+		System.out.println("JDBC:" + sql);
+	}
+
+	public List<Map<String, Object>> queryForList(String sql) {
+		return this.getJdbcTemplate().queryForList(sql);
+	}
+
+	public <T> List<T> queryForList(String sql, Class<T> elementType) {
+		return this.getJdbcTemplate().queryForList(sql, elementType);
+	}
+
+	public List<Map<String, Object>> queryForList(String sql, Object... args) {
+		return this.getJdbcTemplate().queryForList(sql, args);
+	}
+
+	public <T> List<T> queryForList(String sql, Object[] args, Class<T> elementType) {
+		return this.getJdbcTemplate().queryForList(sql, args, elementType);
+	}
+
+	public <T> List<T> queryForList(String sql, Class<T> elementType, Object... args) {
+		return this.getJdbcTemplate().queryForList(sql, elementType, args);
+	}
+
+	public <T> List<T> query(String sql, Object[] args, Class<T> elementType) {
+		return this.getJdbcTemplate().query(sql, args, new BeanPropertyRowMapper<T>(elementType));
+	}
+
+	public <T> List<T> query(String sql, Class<T> elementType) {
+		return this.getJdbcTemplate().query(sql, new BeanPropertyRowMapper<T>(elementType));
+	}
+
+	public <T> List<T> query(String sql, Class<T> elementType, Object... args) {
+		return this.getJdbcTemplate().query(sql, new BeanPropertyRowMapper<T>(elementType), args);
+	}
+
+	public <T> T queryForObject(String sql, Class<T> elementType, Object... args) {
+		return this.getJdbcTemplate().queryForObject(sql, elementType, args);
+	}
+
+	public void execute(String sql) {
+		getJdbcTemplate().execute(sql);
+	}
+
+	public synchronized boolean execute(String sql, Object... objs) {
+		try {
+			getJdbcTemplate().update(sql, objs);
+			return true;
+		} catch (Exception e) {
+			throw new SystemException(e.getMessage());
+		}
+	}
+
+	public void execute(List<String> sqls) {
+		if (sqls.size() > 0) {
+			StringBuffer sb = new StringBuffer("begin ");
+			for (String sql : sqls) {
+				sb.append("execute immediate '").append(sql.replace("'", "''")).append("';");
+			}
+			sb.append("end;");
+			getJdbcTemplate().execute(sb.toString());
+		}
+	}
+
+	/**
+	 * 执行sql <b>支持lob数据的操作</b>
+	 * 
+	 * @param sql
+	 */
+	public void execute(SqlMap sql) {
+		sql.execute(getJdbcTemplate(), lobHandler);
+	}
+
+	/**
+	 * 批量执行Sql
+	 * 
+	 * @param sqls
+	 * @param callbackSqls
+	 */
+	public void batchExecute(List<SqlMap> sqls, List<String> callbackSqls) {
+		if (sqls.size() > 0) {
+			StringBuffer sb = new StringBuffer("begin ");
+			for (SqlMap sql : sqls) {
+				sb.append("execute immediate '").append(sql.getSql(false).replace("'", "''")).append("';");
+			}
+			for (String sql : callbackSqls) {
+				sb.append("execute immediate '").append(sql.replace("'", "''")).append("';");
+			}
+			sb.append("end;");
+			getJdbcTemplate().execute(sb.toString());
+		}
+	}
+
+	/**
+	 * @param execSqls
+	 *            先执行的sql
+	 * @param updateSqls
+	 *            校验通过之后的更新语句
+	 * @param checkSqls
+	 *            校验语句,出错会回滚并返回异常信息
+	 * @return
+	 */
+	public String executeWithCheck(List<String> execSqls, List<String> updateSqls, String... checkSqls) {
+		if (execSqls.size() > 0) {
+			StringBuffer sb = new StringBuffer("declare v_r varchar2(200);begin ");
+			for (String sql : execSqls) {
+				sb.append("execute immediate '").append(sql.replace("'", "''")).append("';");
+			}
+			for (String checkSql : checkSqls) {
+				sb.append("BEGIN execute immediate '")
+				.append(checkSql.replace("'", "''"))
+				.append("' into v_r;if nvl(v_r,' ')<>' ' then rollback;RAISE_APPLICATION_ERROR(-20001,'ERROR_BEGIN'||v_r||'ERROR_END'); end if;exception when no_data_found then v_r := null;END;");
+			}
+			if (updateSqls != null) {
+				for (String sql : updateSqls) {
+					sb.append("execute immediate '").append(sql.replace("'", "''")).append("';");
+				}
+			}
+			sb.append("end;");
+			try {
+				getJdbcTemplate().execute(sb.toString());
+			} catch (Exception e) {
+				if (e.getCause() instanceof java.sql.SQLException) {
+					String errMsg = e.getCause().getMessage();
+					if (errMsg.contains("ERROR_BEGIN"))
+						return errMsg.substring(errMsg.indexOf("ERROR_BEGIN") + 11, errMsg.lastIndexOf("ERROR_END"));
+				}
+				return e.getMessage();
+			}
+		}
+		return null;
+	}
+
+	public void execute(String[] sqls) {
+		if (sqls.length > 0) {
+			StringBuffer sb = new StringBuffer("begin ");
+			for (String sql : sqls) {
+				sb.append("execute immediate '").append(sql.replace("'", "''")).append("';");
+			}
+			sb.append("end;");
+			getJdbcTemplate().execute(sb.toString());
+		}
+	}
+
+	public void deleteById(Saveable obj, long id) {
+		deleteById(obj.table(), obj.keyColumns()[0], id);
+	}
+
+	public void deleteById(String tablename, String keyField, long id) {
+		deleteByCondition(tablename, keyField + "=" + id);
+	}
+
+	public void deleteByCondition(String tablename, String condition) {
+		StringBuffer sb = new StringBuffer();
+		sb.append("DELETE FROM ");
+		sb.append(tablename);
+		sb.append(" WHERE ");
+		sb.append(condition);
+		execute(sb.toString());
+	}
+
+	public void createTable(String sql) {
+		SqlUpdate su = new SqlUpdate(getDataSource(), sql);
+		su.compile();
+		su.update();
+	}
+
+	/**
+	 * 复制数据库一条或多条数据
+	 * 
+	 * @param fTab
+	 *            Form Table
+	 * @param tTab
+	 *            To Table
+	 * @param condition
+	 * @param diffence
+	 *            有差异的字段及值(注意:值如果为String,需要用单引号,而如果是to_date,sysdate等数据库函数或变量, 则无需用引号)
+	 */
+	public void copyRecord(String fTab, String tTab, String condition, Map<String, Object> diffence) {
+		StringBuffer sb = new StringBuffer("begin ");
+		sb.append("for rs in (select * from ");
+		sb.append(fTab);
+		sb.append(" where ");
+		sb.append(condition);
+		sb.append(") ");
+		sb.append("loop ");
+		Set<String> keys = diffence.keySet();
+		for (String f : keys) {
+			sb.append(" rs.");
+			sb.append(f);
+			sb.append(":=");
+			sb.append(diffence.get(f));
+			sb.append(";");
+		}
+		sb.append(" insert into ");
+		sb.append(tTab);
+		sb.append(" values rs;");
+		sb.append(" end loop; ");
+		sb.append(" end;");
+		getJdbcTemplate().update(sb.toString());
+	}
+
+	@SuppressWarnings({ "unchecked", "rawtypes" })
+	public Object getObjectByColumn(String tableName, String columnName, Object columnValue, Class className) {
+		String sql = "select * from " + tableName + " where " + columnName + "=?";
+		return getJdbcTemplate().queryForObject(sql, new BeanPropertyRowMapper(className), columnValue);
+	}
+
+	@SuppressWarnings({ "unchecked", "rawtypes" })
+	public List<?> getAll(String tableName, Class className) {
+		String sql = "select * from " + tableName;
+		return getJdbcTemplate().query(sql, new BeanPropertyRowMapper(className));
+	}
+
+	public String getTableByFormCaller(String caller) {
+		String sql = FORM_TABLE.replace("?", "'" + caller + "'");
+		SqlRowList rs = queryForRowSet(sql);
+		if (rs.next()) {
+			return rs.getString(1);
+		}
+		return null;
+	}
+
+	/**
+	 * {getDataStringByDbfindSet()}的新方法 支持jboss
+	 */
+	public List<Map<String, Object>> getDbfindSetData(DBFindSet dbFindSet, String condition, String orderby, int page, int pageSize) {
+		List<Map<String, Object>> list = getJdbcTemplate().queryForList(dbFindSet.getSql(condition, orderby, page, pageSize));
+		Iterator<Map<String, Object>> iter = list.iterator();
+		List<Map<String, Object>> datas = new ArrayList<Map<String, Object>>();
+		Map<String, Object> map = null;
+		while (iter.hasNext()) {
+			map = iter.next();
+			for (DBFindSetDetail detail : dbFindSet.getDbFindSetDetails()) {
+				String field = detail.getDd_fieldname();
+				if (field.contains(" ")) {// column有取别名
+					String[] strs = field.split(" ");
+					field = strs[strs.length - 1];
+				}
+				Object value = map.get(field.toUpperCase());
+				value = value == null || value.equals("null") ? "" : value;
+				if (value != null) {
+					String classname = value.getClass().getSimpleName();
+					if (classname.toUpperCase().equals("TIMESTAMP")) {
+						Timestamp time = (Timestamp) value;
+						try {
+							value = DateUtil.parseDateToString(new Date(time.getTime()), Constant.YMD_HMS);
+						} catch (Exception e) {
+							e.printStackTrace();
+						}
+					}
+				}
+				map.remove(field.toUpperCase());
+				map.put(field, value);
+			}
+			datas.add(map);
+		}
+		return datas;
+	}
+
+	public String getDataStringByDbfindSet(DBFindSet dbFindSet, String condition, String orderby, int page, int pageSize) {
+		List<Map<String, Object>> maps = getDbfindSetData(dbFindSet, condition, orderby, page, pageSize);
+		return BaseUtil.parseGridStore2Str(maps);
+	}
+
+	/**
+	 * {getDataStringByDbfindSetUi()}的新方法 支持jboss
+	 */
+	public List<Map<String, Object>> getDbfindSetUiData(DBFindSetUI dbFindSetUI, String condition, int page, int pageSize) {
+		List<Map<String, Object>> list = getJdbcTemplate().queryForList(dbFindSetUI.getSql(condition, page, pageSize));
+		Iterator<Map<String, Object>> iter = list.iterator();
+		List<Map<String, Object>> datas = new ArrayList<Map<String, Object>>();
+		String[] fields = dbFindSetUI.getDs_findtoui().split("#");
+		Map<String, Object> map = null;
+		String ff = null;
+		while (iter.hasNext()) {
+			map = iter.next();
+			for (String field : fields) {
+				field = field.split(",")[0];
+				field = field.replace(".", "_");
+				ff = field;
+				if (ff.contains(" ")) {
+					String[] strs = ff.split(" ");
+					ff = strs[strs.length - 1];
+				} else if (ff.contains("(")) {// sum(..),nvl(..)等带函数名的字段
+					ff = ff.substring(ff.indexOf("(") + 1, ff.indexOf(")"));
+				}
+				Object value = map.get(ff.toUpperCase());
+				value = value == null || value.equals("null") ? "" : value;
+				if (value != null) {
+					String classname = value.getClass().getSimpleName();
+					if (classname.toUpperCase().equals("TIMESTAMP")) {
+						Timestamp time = (Timestamp) value;
+						try {
+							value = DateUtil.parseDateToString(new Date(time.getTime()), Constant.YMD_HMS);
+						} catch (Exception e) {
+							e.printStackTrace();
+						}
+					}
+				}
+				map.remove(field.toUpperCase());
+				if (field.contains(" "))
+					map.put(ff, value);
+				else
+					map.put(field, value);
+			}
+			datas.add(map);
+		}
+		return datas;
+	}
+
+	public String getDataStringByDbfindSetUi(DBFindSetUI dbFindSetUI, String condition, int page, int pageSize) {
+		List<Map<String, Object>> maps = getDbfindSetUiData(dbFindSetUI, condition, page, pageSize);
+		return BaseUtil.parseGridStore2Str(maps);
+	}
+
+	public int getCount(String sql) {
+		SqlRowList rs = queryForRowSet(sql);
+		if (rs.next()) {
+			return rs.getInt(1);
+		}
+		return 0;
+	}
+
+	public int getCountByTable(String tablename) {
+		SqlRowList rs = queryForRowSet("SELECT count(*) FROM " + tablename);
+		if (rs.next()) {
+			return rs.getInt(1);
+		}
+		return 0;
+	}
+
+	public Double getSummaryByField(String tablename, String summaryField, String condition) {
+		SqlRowList rs = queryForRowSet("SELECT sum(nvl(" + summaryField + ",0)) FROM " + tablename + " WHERE " + condition);
+		if (rs.next()) {
+			return rs.getGeneralDouble(1, 6);
+		}
+		return 0.0;
+	}
+
+	public String getTableByDetailGridCaller(String caller) {
+		String sql = DETAILGRID_TABLE.replace("?", "'" + caller + "'");
+		SqlRowList rs = queryForRowSet(sql);
+		if (rs.next()) {
+			return rs.getString(1);
+		}
+		return null;
+	}
+
+	/**
+	 * {getDataStringByDetailGrid()}的新方法 支持jboss
+	 */
+	public List<Map<String, Object>> getDetailGridData(List<DetailGrid> detailGrids, String condition, Employee employee, Integer start,
+			Integer end) {
+		String caller = detailGrids.get(0).getDg_caller();
+		Object[] objs = getFieldsDataByCondition("Form", "fo_detailtable,fo_detailcondition,fo_detailgridorderby", "fo_caller='" + caller
+				+ "'");
+		Object table = detailGrids.get(0).getDg_table();
+		if (objs != null) {// 优先用Form的配置
+			if (objs[0] != null)
+				table = objs[0];
+			if (objs[1] != null) {
+				if ("".equals(condition)) {
+					condition = objs[1].toString();
+				} else {
+					int index = condition.toLowerCase().indexOf("order by");
+					if (index > -1) {
+						condition = condition.substring(0, index) + " AND " + objs[1] + " " + condition.substring(index);
+					} else {
+						condition += " AND " + objs[1];
+					}
+				}
+			}
+			if (objs[2] != null && objs[2].toString().toLowerCase().indexOf("order by") > -1) {
+				int index = condition.toLowerCase().indexOf("order by");
+				if (index > -1) {
+					condition = condition.substring(0, index);
+				}
+				condition += " " + objs[2];
+			}
+		}
+		String sql = SqlUtil.getQuerySqlByDetailGrid(detailGrids, String.valueOf(table), condition, employee, start, end);
+		List<Map<String, Object>> list = getJdbcTemplate(detailGrids.get(0).getDg_table().split(" ")[0]).queryForList(sql);
+		Iterator<Map<String, Object>> iter = list.iterator();
+		List<Map<String, Object>> datas = new ArrayList<Map<String, Object>>();
+		Map<String, Object> map = null;
+		while (iter.hasNext()) {
+			map = iter.next();
+			for (DetailGrid detail : detailGrids) {
+				String field = detail.getDg_field();
+				if (field.contains(" ")) {// column有取别名
+					String[] strs = field.split(" ");
+					field = strs[strs.length - 1];
+				}
+				Object value = map.get(field.toUpperCase());
+				value = value == null || value.equals("null") ? "" : value;
+				if (value != null) {
+					String classname = value.getClass().getSimpleName();
+					if (classname.toUpperCase().equals("TIMESTAMP")) {
+						Timestamp time = (Timestamp) value;
+						try {
+							value = DateUtil.parseDateToString(new Date(time.getTime()), Constant.YMD_HMS);
+						} catch (Exception e) {
+							e.printStackTrace();
+						}
+					}
+					String type = detail.getDg_type();
+					if (type != null && type.matches("^checkcolumn-?\\d{1}$")) {
+						// 数据库里是number类型,在Grid里面作为checkcolumn时,需将number数据按配置转化成true和false
+						if (value == null || "".equals(value))
+							value = false;
+						else
+							value = Integer.parseInt(value.toString()) == Integer.parseInt(type.substring(11).toString());
+					}
+				}
+				map.remove(field.toUpperCase());
+				map.put(field, value);
+			}
+			datas.add(map);
+		}
+		return datas;
+	}
+
+	/**
+	 * 获取序列号
+	 * 
+	 * @param seq
+	 *            指定的序列名
+	 */
+	public int getSeqId(String seq) {
+		try {
+			if ("true".equals(BaseUtil.getXmlSetting("group"))) {
+				boolean isBase = checkIf("basedataset", "upper(bds_sequence)=upper('" + seq + "') and nvl(bds_editable,0)=1");
+				if (isBase) {
+					// 集团版基础资料(客户,供应商...)统一到资料中心取号
+					String dataCenter = BaseUtil.getXmlSetting("dataSob");
+					seq = dataCenter + "." + seq;
+				}
+			}
+			String sql = "select " + seq + ".nextval from dual";
+			SqlRowList rs = queryForRowSet(sql);
+			if (rs.next()) {
+				return rs.getInt(1);
+			} else {// 如果不存在就创建序列
+				int count = getCountByCondition("user_sequences", "Sequence_Name='" + seq.toUpperCase() + "'");
+				if (count == 0)
+					getJdbcTemplate().execute(CREATE_SEQ.replace("?", seq));
+				return getSeqId(seq);
+			}
+		} catch (Exception e) {
+			int count = getCountByCondition("user_sequences", "Sequence_Name='" + seq.toUpperCase() + "'");
+			if (count == 0)
+				getJdbcTemplate().execute(CREATE_SEQ.replace("?", seq));
+			return getSeqId(seq);
+		}
+	}
+
+	public void createTrigger(String tab, String keyField) {
+		tab = tab.toUpperCase();
+		int count = getCountByCondition("DBA_SEQUENCES", "sequence_name='" + tab + "_SEQ'");
+		if (count == 0) {
+			getJdbcTemplate().execute(CREATE_SEQ.replace("?", tab + "_SEQ"));
+		}
+		count = getCountByCondition("DBA_TRIGGERS", "trigger_name='" + tab + "_TRI'");
+		if (count == 0) {
+			StringBuffer sb = new StringBuffer();
+			sb.append("create or replace TRIGGER ");
+			sb.append(tab);
+			sb.append("_TRI before insert on ");
+			sb.append(tab);
+			sb.append(" for each row begin select ");
+			sb.append(tab);
+			sb.append("_SEQ.nextval into:new.");
+			sb.append(keyField);
+			sb.append(" from dual; end;");
+			execute(sb.toString());
+		}
+	}
+
+	public void deleteTrigger(String tab) {
+		tab = tab.toUpperCase();
+		execute("DROP TRIGGER " + tab + "_TRI");
+	}
+
+	/**
+	 * 需要从数据字典的配置更新table时,用到此方法
+	 * 
+	 * @param tablename
+	 *            需要更新的tablename
+	 */
+	public JdbcTemplate getJdbcTemplate(String tablename) {
+		/*
+		 * if(!checkTableName(tablename)){ throw new RuntimeException("表:" + tablename + "未在数据字典定义!"); }
+		 */
+		return getJdbcTemplate();
+	}
+
+	/*	public void checkTable(String tablename) {
+		tablename = tablename.split("!")[0].split(" ")[0].split(",")[0].toUpperCase().trim();
+		if (!checkTableName(tablename)) {// 说明该表不存在
+			List<DataDictionaryDetail> dataDictionaryDetails = getDataDictionaryDetails(tablename);// 拿到对应数据字典
+			if (dataDictionaryDetails.size() > 0) {
+				createTableByName(tablename, dataDictionaryDetails);// 创建表
+				updateDataList(tablename, dataDictionaryDetails);// 修改对应datalist配置
+				updateForm(tablename, dataDictionaryDetails);// 修改对应form配置
+				// ...修改其他一些配置...
+			} else {
+				throw new RuntimeException("表:" + tablename + "未在数据字典定义!");
+			}
+		}
+	}*/
+
+	public boolean checkTableName(String tablename) {
+		String sql = SELECT_TABLES.replace("?", "'" + tablename + "'");
+		if (getCount(sql) == 0) {// 说明该表不存在
+			sql = SELECT_VIEWS.replace("?", "'" + tablename + "'");
+			if (getCount(sql) == 1) {
+				return true;
+			}
+			return false;
+		}
+		return true;
+	}
+
+	/**
+	 * 一个字段,一条结果
+	 * 
+	 * @param tableName
+	 *            对应要查询的表
+	 * @param field
+	 *            要查询的字段
+	 * @param condition
+	 *            查询条件
+	 * @return field对应的数据
+	 */
+	public Object getFieldDataByCondition(String tableName, String field, String condition) {
+		StringBuffer sql = new StringBuffer("SELECT ");
+		sql.append(field);
+		sql.append(" FROM ");
+		sql.append(tableName);
+		sql.append(" WHERE ");
+		sql.append(condition);
+		SqlRowList srs = queryForRowSet(sql.toString());
+		if (srs.next()) {
+			return srs.getObject(1);
+		} else {
+			return null;
+		}
+	}
+
+
+
+	/**
+	 * 一个字段,多条结果
+	 * 
+	 * @param tableName
+	 *            对应要查询的表
+	 * @param field
+	 *            要查询的字段
+	 * @param condition
+	 *            查询条件
+	 * @return field对应的数据
+	 */
+	public List<Object> getFieldDatasByCondition(String tableName, String field, String condition) {
+		StringBuffer sb = new StringBuffer("SELECT ");
+		sb.append(field);
+		sb.append(" FROM ");
+		sb.append(tableName);
+		sb.append(((condition == null || "".equals(condition)) ? "" : (" WHERE " + condition)));
+		SqlRowList srs = queryForRowSet(sb.toString());
+		List<Object> list = new ArrayList<Object>();
+		while (srs.next()) {
+			list.add(srs.getObject(1));
+		}
+		return list;
+	}
+
+	/**
+	 * 多个字段,<=1条结果
+	 * 
+	 * @param tableName
+	 *            对应要查询的表
+	 * @param fields
+	 *            要查询的字段集合
+	 * @param condition
+	 *            查询条件
+	 * @return fields对应的数据
+	 */
+	public Object[] getFieldsDataByCondition(String tableName, String[] fields, String condition) {
+		StringBuffer sql = new StringBuffer("SELECT ");
+		sql.append(BaseUtil.parseArray2Str(fields, ","));
+		sql.append(" FROM ");
+		sql.append(tableName);
+		sql.append(" WHERE ");
+		sql.append(condition);
+		List<Map<String, Object>> list = getJdbcTemplate().queryForList(sql.toString());
+		Iterator<Map<String, Object>> iter = list.iterator();
+		int length = fields.length;
+		Object[] results = new Object[length];
+		Object value = null;
+		if (iter.hasNext()) {
+			Map<String, Object> m = iter.next();
+			for (int i = 0; i < length; i++) {
+				value = m.get(fields[i].toUpperCase());
+				if (value != null && value.getClass().getSimpleName().toUpperCase().equals("TIMESTAMP")) {
+					Timestamp time = (Timestamp) value;
+					try {
+						value = DateUtil.parseDateToString(new Date(time.getTime()), Constant.YMD_HMS);
+					} catch (Exception e) {
+						e.printStackTrace();
+					}
+				}
+				results[i] = value;
+			}
+			return results;
+		}
+		return null;
+	}
+
+
+	/**
+	 * 多个字段,<=1条结果
+	 * 
+	 * @param tableName
+	 *            对应要查询的表
+	 * @param fields
+	 *            要查询的字段,用逗号隔开
+	 * @param condition
+	 *            查询条件
+	 * @return fields对应的数据
+	 */
+	public Object[] getFieldsDataByCondition(String tableName, String fields, String condition) {
+		StringBuffer sql = new StringBuffer("SELECT ");
+		sql.append(fields);
+		sql.append(" FROM ");
+		sql.append(tableName);
+		sql.append(" WHERE ");
+		sql.append(condition);
+		String[] strs = fields.split(",");
+		int length = strs.length;
+		List<Map<String, Object>> list = getJdbcTemplate().queryForList(sql.toString());
+		Iterator<Map<String, Object>> iter = list.iterator();
+		Object[] results = new Object[length];
+		Object value = null;
+		if (iter.hasNext()) {
+			Map<String, Object> m = iter.next();
+			for (int i = 0; i < length; i++) {
+				value = m.get(strs[i].toUpperCase());
+				if (value != null && value.getClass().getSimpleName().toUpperCase().equals("TIMESTAMP")) {
+					Timestamp time = (Timestamp) value;
+					try {
+						value = DateUtil.parseDateToString(new Date(time.getTime()), Constant.YMD_HMS);
+					} catch (Exception e) {
+						e.printStackTrace();
+					}
+				}
+				results[i] = value;
+			}
+			return results;
+		}
+		return null;
+	}
+
+	/**
+	 * 多个字段,多条结果
+	 * 
+	 * @param tableName
+	 *            对应要查询的表
+	 * @param fields
+	 *            要查询的字段集合
+	 * @param condition
+	 *            查询条件
+	 * @return fields对应的数据
+	 */
+	public List<Object[]> getFieldsDatasByCondition(String tableName, String[] fields, String condition) {
+		StringBuffer sql = new StringBuffer("SELECT ");
+		sql.append(BaseUtil.parseArray2Str(fields, ","));
+		sql.append(" FROM ");
+		sql.append(tableName);
+		sql.append(" WHERE ");
+		sql.append(condition);
+		List<Map<String, Object>> list = getJdbcTemplate().queryForList(sql.toString());
+		Iterator<Map<String, Object>> iter = list.iterator();
+		List<Object[]> datas = new ArrayList<Object[]>();
+		Object value = null;
+		Map<String, Object> m = null;
+		Object[] results = null;
+		int length = fields.length;
+		while (iter.hasNext()) {
+			results = new Object[length];
+			m = iter.next();
+			for (int i = 0; i < length; i++) {
+				value = m.get(fields[i].toUpperCase());
+				if (value != null && value.getClass().getSimpleName().toUpperCase().equals("TIMESTAMP")) {
+					Timestamp time = (Timestamp) value;
+					try {
+						value = DateUtil.parseDateToString(new Date(time.getTime()), Constant.YMD_HMS);
+					} catch (Exception e) {
+						e.printStackTrace();
+					}
+				}
+				results[i] = value;
+			}
+			datas.add(results);
+		}
+		return datas;
+	}
+	public List<JSONObject> getFieldsJSONDatasByCondition(String tableName, String[] fields, String condition) {
+		StringBuffer sql = new StringBuffer("SELECT ");
+		sql.append(BaseUtil.parseArray2Str(fields, ","));
+		sql.append(" FROM ");
+		sql.append(tableName);
+		sql.append(" WHERE ");
+		sql.append(condition);
+		List<JSONObject> datas = new ArrayList<JSONObject>();
+		JSONObject obj=null ;
+		Object value=null;
+		SqlRowList sl=queryForRowSet(sql.toString());
+		while(sl.next()){
+			obj=new JSONObject();
+			for(int i=0;i<fields.length;i++){
+				value=sl.getObject(i+1);
+				if (value != null && "TIMESTAMP".equals(value.getClass().getSimpleName().toUpperCase())) {
+					Timestamp time = (Timestamp) value;
+					value = DateUtil.parseDateToString(new Date(time.getTime()), "yyyy-MM-dd HH:mm:ss");
+				}
+				obj.put(fields[i],value);
+			}
+			datas.add(obj);
+		}
+		return datas;
+	}
+	/**
+	 * @param tableName
+	 *            对应要查询的表
+	 * @param condition
+	 *            查询条件
+	 * @return Count
+	 */
+	public int getCountByCondition(String tableName, String condition) {
+		StringBuffer sql = new StringBuffer("SELECT count(1) FROM ");
+		sql.append(tableName);
+		sql.append(" WHERE ");
+		sql.append(condition);
+		SqlRowList srs = queryForRowSet(sql.toString());
+		if (srs.next()) {
+			return srs.getInt(1);
+		} else {
+			try {
+				throw new Exception("Condition:" + condition + " is wrong!");
+			} catch (Exception e) {
+				return -1;
+			}
+		}
+	}
+
+	/**
+	 * if resultSet is null return true
+	 */
+	public boolean checkByCondition(String caller, String condition) {
+		int count = getCountByCondition(caller, condition);
+		if (count == 0) {
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * if resultSet not null return true
+	 */
+	public boolean checkIf(String table, String condition) {
+		int count = getCountByCondition(table, condition);
+		if (count > 0) {
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * 修改操作
+	 * 
+	 * @param tableName
+	 *            表
+	 * @param update
+	 *            修改内容
+	 * @param condition
+	 *            条件语句
+	 */
+	public void updateByCondition(String tableName, String update, String condition) {
+		StringBuffer sb = new StringBuffer("UPDATE ");
+		sb.append(tableName);
+		sb.append(" SET ");
+		sb.append(update);
+		sb.append(" WHERE ");
+		sb.append(condition);
+		execute(sb.toString());
+	}
+
+		public String getformFieldsbyTable(String Table) {
+		String sql = "SELECT fd_field from FormDetail where fd_table='" + Table + "' order by fd_detno";
+		List<Map<String, Object>> list = getJdbcTemplate().queryForList(sql);
+		Iterator<Map<String, Object>> iter = list.iterator();
+		List<String> fields = new ArrayList<String>();
+		Map<String, Object> m = null;
+		while (iter.hasNext()) {
+			m = iter.next();
+			fields.add(m.get("FD_FIELD").toString());
+		}
+		return BaseUtil.parseList2Str(fields, ",", true);
+	}
+
+	/**
+	 * 记录操作
+	 */
+	public void logMessage(MessageLog messageLog) {
+		execute(messageLog.getSql());
+	}
+
+	/**
+	 * 获取编号序列
+	 * 
+	 * @param myTable
+	 *            Caller
+	 * @param thisType
+	 *            2
+	 */
+	public synchronized String sGetMaxNumber(String myTable, int thisType) {
+		if ("true".equals(BaseUtil.getXmlSetting("group"))) {
+			boolean isBase = checkIf("basedataset", "bds_caller='" + myTable + "' and nvl(bds_editable,0)=1");
+			if (isBase) {
+				// 集团版基础资料(客户,供应商...)统一到资料中心取号
+				String dataCenter = BaseUtil.getXmlSetting("dataSob");
+				return callProcedure(dataCenter + ".Sp_GetMaxNumber", new Object[] { myTable, thisType });
+			}
+		}
+		return callProcedure("Sp_GetMaxNumber", new Object[] { myTable, thisType });
+	}
+
+	/**
+	 * 调用存储过程 无返回值
+	 * 
+	 * @param procedureName
+	 *            存储过程名称
+	 * @param args
+	 *            参数
+	 */
+	public void procedure(String procedureName, Object[] args) {
+		try {
+			StringBuffer sb = new StringBuffer("call ");
+			sb.append(procedureName);
+			sb.append("(");
+			int index = 0;
+			for (Object obj : args) {
+				if (index == 0) {
+					sb.append("'");
+					index++;
+				} else {
+					sb.append(", '");
+				}
+				sb.append(obj);
+				sb.append("'");
+			}
+			sb.append(")");
+			getJdbcTemplate().execute(sb.toString());
+		} catch (Exception e) {
+			throw new SystemException("【调用存储过程】错误: " + e.getMessage());
+		}
+
+	}
+
+	/**
+	 * 调用存储过程
+	 * 
+	 * @param procedureName
+	 *            存储过程名称
+	 * @param args
+	 *            参数
+	 * @return varchar类型结果
+	 */
+	public List<String> callProcedureWithOut(final String procedureName, final Object[] args, final Integer[] inIndex,
+			final Integer[] outIndex) {
+
+		StringBuffer sql = new StringBuffer("{call " + procedureName + "(");
+
+		for (int i = 0; i < inIndex.length + outIndex.length; i++) {
+			if (sql.toString().contains("?")) {
+				sql.append(",?");
+			} else {
+				sql.append("?");
+			}
+		}
+		sql.append(")}");
+
+		@SuppressWarnings({ "unchecked", "rawtypes" })
+		List<String> listR = (List<String>) getJdbcTemplate().execute(sql.toString(), new CallableStatementCallback() {
+
+			@Override
+			public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
+				for (int i = 0; i < inIndex.length; i++) {
+					cs.setObject(inIndex[i], args[i]);
+				}
+
+				for (int i = 0; i < outIndex.length; i++) {
+					cs.registerOutParameter(outIndex[i], java.sql.Types.VARCHAR);
+				}
+
+				cs.execute();
+				List<String> list = new ArrayList<String>();
+				for (int i = 0; i < outIndex.length; i++) {
+
+					list.add(cs.getString(outIndex[i]));
+				}
+
+				return list;
+			}
+		});
+		return listR;
+
+	}
+
+	/**
+	 * 调用存储过程
+	 * 
+	 * @param procedureName
+	 *            存储过程名称
+	 * @param args
+	 *            参数
+	 * @return varchar类型结果
+	 */
+	public String callProcedure(final String procedureName, final Object... args) {
+		try {
+			return getJdbcTemplate().execute(new CallableStatementCreator() {
+				@Override
+				public CallableStatement createCallableStatement(Connection conn) throws SQLException {
+					StringBuffer storedProcName = new StringBuffer("{call ");
+					int i = 0;
+					storedProcName.append(procedureName + "(");
+					for (i = 0; i < args.length; i++) {
+						if (storedProcName.toString().contains("?")) {
+							storedProcName.append(",");
+						}
+						storedProcName.append("?");
+					}
+					if (storedProcName.toString().contains("?")) {
+						storedProcName.append(",");
+					}
+					storedProcName.append("?");
+					storedProcName.append(")}");
+					CallableStatement cs = conn.prepareCall(storedProcName.toString());
+					for (i = 0; i < args.length; i++) {
+						cs.setObject(i + 1, args[i]);
+					}
+					cs.registerOutParameter(args.length + 1, java.sql.Types.VARCHAR);
+					return cs;
+				}
+			}, new CallableStatementCallback<String>() {
+				@Override
+				public String doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
+					cs.execute();
+					return cs.getString(args.length + 1);
+				}
+
+			});
+		} catch (Exception e) {
+			throw new SystemException(e.getMessage());
+		}
+	}
+
+	/**
+	 * 调用存储过程
+	 * 
+	 * @param procedureName
+	 *            存储过程名称
+	 * @param cls
+	 *            返回结果java类型
+	 * @param sqlType
+	 *            返回结果的sql类型
+	 * @param args
+	 *            参数
+	 * @return varchar类型结果
+	 */
+	public <T> T callbackProcedure(final String procedureName, final Class<T> cls, final int sqlType, final Object... args) {
+		try {
+			return getJdbcTemplate().execute(new CallableStatementCreator() {
+				@Override
+				public CallableStatement createCallableStatement(Connection conn) throws SQLException {
+					StringBuffer storedProcName = new StringBuffer("{call ");
+					int i = 0;
+					storedProcName.append(procedureName + "(");
+					for (i = 0; i < args.length; i++) {
+						if (storedProcName.toString().contains("?")) {
+							storedProcName.append(",");
+						}
+						storedProcName.append("?");
+					}
+					if (storedProcName.toString().contains("?")) {
+						storedProcName.append(",");
+					}
+					storedProcName.append("?");
+					storedProcName.append(")}");
+					CallableStatement cs = conn.prepareCall(storedProcName.toString());
+					for (i = 0; i < args.length; i++) {
+						cs.setObject(i + 1, args[i]);
+					}
+					cs.registerOutParameter(args.length + 1, sqlType);
+					return cs;
+				}
+			}, new CallableStatementCallback<T>() {
+				@SuppressWarnings("unchecked")
+				@Override
+				public T doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
+					cs.execute();
+					// do not use method: getObject(paramInt, paramClass)
+					return (T) cs.getObject(args.length + 1);
+				}
+
+			});
+		} catch (Exception e) {
+			e.printStackTrace();
+			throw new SystemException(e.getMessage());
+		}
+	}
+
+	/**
+	 * 查询结果集
+	 * 
+	 * @param sql
+	 *            查询语句
+	 */
+	public SqlRowList queryForRowSet(String sql) {
+		SqlRowList rs = new SqlRowList();
+		rs.setResultList(getJdbcTemplate().queryForList(sql));
+		return rs;
+	}
+
+	/**
+	 * 查询结果集
+	 * 
+	 * @param sql
+	 *            查询语句
+	 * @param arg
+	 *            参数
+	 */
+	public SqlRowList queryForRowSet(String sql, Object arg) {
+		SqlRowList rs = new SqlRowList();
+		rs.setResultList(getJdbcTemplate().queryForList(sql, arg));
+		return rs;
+	}
+
+	/**
+	 * 查询结果集
+	 * 
+	 * @param sql
+	 *            查询语句
+	 * @param args
+	 *            参数
+	 */
+	public SqlRowList queryForRowSet(String sql, Object... args) {
+		SqlRowList rs = new SqlRowList();
+		rs.setResultList(getJdbcTemplate().queryForList(sql, args));
+		return rs;
+	}
+
+	/**
+	 * 查询结果集
+	 * 
+	 * @param sql
+	 *            查询语句
+	 * @param args
+	 *            参数
+	 */
+	public SqlRowList queryForRowSet(String sql, List<Object> args) {
+		SqlRowList rs = new SqlRowList();
+		rs.setResultList(getJdbcTemplate().queryForList(sql, args));
+		return rs;
+	}
+
+	private void saveRecycle(final JSONObject recycle) {
+		try {
+			String sql = "INSERT INTO Recycles(re_caller,re_data,re_keyvalue,re_detailvalue,re_emcode,re_emname,re_code)"
+					+ " VALUES(?,?,?,?,?,?,?)";
+			getJdbcTemplate().execute(sql, new AbstractLobCreatingPreparedStatementCallback(lobHandler) {
+				@Override
+				protected void setValues(PreparedStatement ps, LobCreator lob) throws SQLException, DataAccessException {
+					ps.setString(1, recycle.getString("re_caller"));
+					lob.setClobAsString(ps, 2, recycle.getString("re_data"));
+					ps.setObject(3, recycle.get("re_keyvalue"));
+					ps.setObject(4, recycle.get("re_detailvalue"));
+					ps.setObject(5, recycle.get("re_emcode"));
+					ps.setObject(6, recycle.get("re_emname"));
+					ps.setObject(7, recycle.get("re_code"));
+				}
+
+			});
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+	/**
+	 * 删除前 数据存放到回收站 rf_keyvalue和rg_keyvalue均为主表ID值,通过ID值关联
+	 */
+	public void recycleAll(String caller, Integer id, Employee employee) {
+		String emcode = employee.getEm_code();
+		String emname = employee.getEm_name();
+		JSONObject recycle = null;
+		Object[] objs = getFieldsDataByCondition("Form",
+				"fo_table,fo_keyfield,fo_detailtable,fo_detailmainkeyfield,fo_detailkeyfield,fo_codefield", "fo_caller='" + caller + "'");
+		if (objs != null) {
+			// 主表
+			Object fTab = objs[0];
+			Object fKey = objs[1];
+			if (fTab != null && fKey != null) {
+				StringBuffer sql = new StringBuffer("SELECT * FROM ");
+				sql.append(fTab);
+				sql.append(" WHERE ");
+				sql.append(fKey);
+				sql.append("=");
+				sql.append(id);
+				SqlRowList f = queryForRowSet(sql.toString());
+				Object cKey = objs[5];
+				String code = "";
+				if (f.next()) {
+					if (cKey != null) {
+						code = f.getString(cKey.toString());
+					}
+					String j = f.getJSON();
+					recycle = new JSONObject();
+					recycle.put("re_caller", caller);
+					recycle.put("re_data", j);
+					recycle.put("re_keyvalue", id);
+					recycle.put("re_detailvalue", null);
+					recycle.put("re_emcode", emcode);
+					recycle.put("re_emname", emname);
+					recycle.put("re_code", code);
+					saveRecycle(recycle);
+					// 从表
+					fTab = objs[2];
+					fKey = objs[3];
+					String dKey = String.valueOf(objs[4]);
+					if (fTab != null && fKey != null && dKey != null) {
+						sql = new StringBuffer("SELECT * FROM ");
+						sql.append(fTab);
+						sql.append(" WHERE ");
+						sql.append(fKey);
+						sql.append("=");
+						sql.append(id);
+						f = queryForRowSet(sql.toString());
+						while (f.next()) {
+							j = f.getJSON();
+							recycle = new JSONObject();
+							recycle.put("re_caller", caller);
+							recycle.put("re_data", j);
+							recycle.put("re_keyvalue", id);
+							recycle.put("re_detailvalue", f.getInt(dKey));
+							recycle.put("re_emcode", emcode);
+							recycle.put("re_emname", emname);
+							recycle.put("re_code", code);
+							saveRecycle(recycle);
+						}
+					}
+				}
+			}
+		}
+	}
+
+	/**
+	 * 删除明细前数据存放到回收站 在有配置的情况下,rg_keyvalue为主表ID值,否则,为明细ID值
+	 */
+	public void recycle(String caller, Integer id, Employee employee) {
+		String emcode = employee.getEm_code();
+		String emname = employee.getEm_name();
+		JSONObject recycle = null;
+		// 先根据caller,到Form取配置
+		Object[] objs = getFieldsDataByCondition("Form", "fo_detailtable,fo_detailkeyfield,fo_detailmainkeyfield,fo_codefield",
+				"fo_caller='" + caller + "'");
+		if (objs != null) {// 如果有配置
+			Object fTab = objs[0];
+			Object fKey = objs[1];
+			Object mKey = objs[2];
+			String kTab = ""; 
+			if (fTab != null && fKey != null && mKey != null) {
+				Object cKey = objs[3];
+				String code = "";
+				kTab = fTab.toString().split(" ")[0];
+				StringBuffer sql = new StringBuffer("SELECT * FROM ");
+				sql.append(fTab);
+				sql.append(" WHERE ");
+				sql.append(kTab+"."+fKey);
+				sql.append("=");
+				sql.append(id);
+				SqlRowList f = queryForRowSet(sql.toString());
+				if (f.next()) {
+					if (cKey != null) {
+						code = f.getString(cKey.toString());
+					}
+					String j = f.getJSON();
+					int key = f.getInt(mKey.toString());
+					recycle = new JSONObject();
+					recycle.put("re_caller", caller);
+					recycle.put("re_data", j);
+					recycle.put("re_keyvalue", key);
+					recycle.put("re_detailvalue", id);
+					recycle.put("re_emcode", emcode);
+					recycle.put("re_emname", emname);
+					recycle.put("re_code", code);
+					saveRecycle(recycle);
+				}
+			}
+		} else {// 如果Form没有配置,到DetailGrid取对应配置
+			objs = getFieldsDataByCondition("Detailgrid", "dg_table,dg_field", "dg_caller='" + caller + "' AND dg_logictype='keyField'");
+			if (objs != null) {
+				Object fTab = objs[0];
+				Object fKey = objs[1];
+				if (fTab != null && fKey != null) {
+					StringBuffer sql = new StringBuffer("SELECT * FROM ");
+					sql.append(fTab);
+					sql.append(" WHERE ");
+					sql.append(fKey);
+					sql.append("=");
+					sql.append(id);
+					SqlRowList f = queryForRowSet(sql.toString());
+					if (f.next()) {
+						String j = f.getJSON();
+						objs = getFieldsDataByCondition("Detailgrid", "dg_field", "dg_caller='" + caller + "' AND dg_logictype='mainField'");
+						recycle = new JSONObject();
+						recycle.put("re_caller", caller);
+						recycle.put("re_data", j);
+						recycle.put("re_detailvalue", id);
+						recycle.put("re_emcode", emcode);
+						recycle.put("re_emname", emname);
+						recycle.put("re_code", null);
+						if (objs != null && objs[0] != null) {// 如果DetailGrid配置有mainField
+							recycle.put("re_keyvalue", f.getInt(objs[0].toString()));
+						} else {
+							recycle.put("re_keyvalue", null);
+						}
+						saveRecycle(recycle);
+					}
+				}
+			}
+		}
+	}
+
+	/**
+	 * 获取入库单批号
+	 */
+	public String getBatchcode(String caller) {
+		String sql = "select * from getBatchCode";
+		String batchCode = null;
+		StringBuffer newBatcBuffer = new StringBuffer();
+		SqlRowList rs = queryForRowSet("select ds_inorout from DOCUMENTSETUP where ds_table=?", caller);
+		if (rs.next()) {
+			String Code = rs.getObject("ds_inorout").toString();
+			if (Code.equals("IN") || Code.equals("-OUT")) {
+				SqlRowList sqlRowList = queryForRowSet(sql);
+				if (sqlRowList.next()) {
+					batchCode = sqlRowList.getString("gb_batchcode");
+					Calendar c = new GregorianCalendar();
+					int year = c.get(Calendar.YEAR);
+					String month = String.valueOf(c.get(Calendar.MONTH) + 1);
+					month = month.length() == 1 ? "0" + month : month;
+					String day = String.valueOf(c.get(Calendar.DATE));
+					day = day.length() == 1 ? "0" + day : day;
+					String yearStr = String.valueOf(year).substring(2, 4);
+					String numCode;
+					int number = Integer.parseInt(batchCode.substring(7, 11));
+					if (number < 9) {
+						numCode = "0000" + String.valueOf(number + 1);
+					} else if (number < 99) {
+						numCode = "000" + String.valueOf(number + 1);
+					} else if (number < 999) {
+						numCode = "00" + String.valueOf(number + 1);
+					} else {
+						numCode = "0" + String.valueOf(number + 1);
+					}
+					if (!yearStr.equals(batchCode.substring(0, 2))) {
+						newBatcBuffer.append(yearStr);
+					} else {
+						newBatcBuffer.append(batchCode.substring(0, 2));
+					}
+
+					if (!month.equals(batchCode.substring(2, 4))) {
+						newBatcBuffer.append(month);
+					} else {
+						newBatcBuffer.append(batchCode.substring(2, 4));
+					}
+
+					if (!day.equals(batchCode.substring(4, 6))) {
+						newBatcBuffer.append(day + "00001");
+					} else {
+						newBatcBuffer.append(batchCode.substring(4, 6) + numCode);
+					}
+					execute("update getBatchCode set gb_batchcode=? where gb_id=?",
+							new Object[] { newBatcBuffer.toString(), sqlRowList.getObject(1) });
+				} else {
+					newBatcBuffer.append(DateUtil.parseDateToString(null, "yyMMdd"));
+					newBatcBuffer.append("00001");
+					sql = "insert into getBatchCode(gb_id,gb_batchcode)values('1','" + newBatcBuffer.toString() + "')";
+					execute(sql);
+				}
+			}
+		}
+		return newBatcBuffer.toString();
+	}
+
+	/**
+	 * 根据物料中的有效期天数更新有效期止
+	 */
+	public void getEndDate(String caller, Object id) {
+		SqlRowList rs = queryForRowSet("select ds_inorout from DOCUMENTSETUP where ds_table=?", caller);
+		if (rs.next()) {
+			String Code = rs.getObject("ds_inorout").toString();
+			if (Code.equals("IN") || Code.equals("-OUT")) {
+				execute("update prodiodetail set pd_replydate=pd_prodmadedate + (select nvl(pr_validdays,0) from product where  pd_prodcode=pr_code) where pd_piid=? and pd_prodmadedate is not null",
+						id);
+			}
+		}
+	}
+
+	/**
+	 * 调用存储过程
+	 * 
+	 * @param procedureName
+	 *            存储过程名称
+	 * @param args
+	 *            参数
+	 * @param out
+	 *            inout类型参数序号
+	 * @return varchar类型结果
+	 */
+	public synchronized String callProcedure(final String procedureName, final Object[] args, final int out) {
+		try {
+			return getJdbcTemplate().execute(new CallableStatementCreator() {
+				@Override
+				public CallableStatement createCallableStatement(Connection conn) throws SQLException {
+					StringBuffer storedProcName = new StringBuffer("{call ");
+					int i = 0;
+					storedProcName.append(procedureName + "(");
+					for (i = 0; i < args.length; i++) {
+						if (storedProcName.toString().contains("?")) {
+							storedProcName.append(",");
+						}
+						storedProcName.append("?");
+					}
+					storedProcName.append(")}");
+					CallableStatement cs = conn.prepareCall(storedProcName.toString());
+					for (i = 0; i < args.length; i++) {
+						cs.setObject(i + 1, args[i]);
+					}
+					cs.registerOutParameter(out, java.sql.Types.VARCHAR);
+					return cs;
+				}
+			}, new CallableStatementCallback<String>() {
+				@Override
+				public String doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
+					cs.execute();
+					return cs.getString(out);
+				}
+
+			});
+		} catch (Exception e) {
+			throw new SystemException(e.getMessage());
+		}
+	}
+
+	public void saveClob(final String tabName, final String clobField, final String clobStr, final String condition) {
+		try {
+			StringBuffer sb = new StringBuffer("update ").append(tabName).append(" set ").append(clobField).append("=? where ")
+					.append(condition);
+			getJdbcTemplate().execute(sb.toString(), new AbstractLobCreatingPreparedStatementCallback(lobHandler) {
+				@Override
+				protected void setValues(PreparedStatement ps, LobCreator lob) throws SQLException, DataAccessException {
+					lob.setClobAsString(ps, 1, clobStr);
+				}
+			});
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+	/**
+	 * 将数据库里面的defaultvalue转化成实际要显示的值
+	 * 
+	 * @param value
+	 *            formDetail.getFd_defaultvalue()
+	 */
+	public Object decodeDefaultValue(Object value, String language) {
+		if (value != null && !value.equals("null")) {
+			String val = value.toString();
+			if (val.contains("getCurrentDate()")) {
+				return new Date();
+			} else if (val.contains("getLocal(")) {
+				Object obj = BaseUtil.getLocalMessage(val.substring(val.indexOf("(") + 1, val.lastIndexOf(")")), language);
+				return (obj == null) ? "" : obj;
+			}
+			return value;
+		} else {
+			return "";
+		}
+	}
+
+	/**
+	 * checkSQL
+	 * */
+	public boolean checkSQL(String sql) {
+		try {
+			execute(sql);
+			return true;
+		} catch (Exception e) {
+			return false;
+		}
+
+	}
+
+	/**
+	 * 删除、反审核等敏感操作前,关联表数据检查
+	 * 
+	 * @param tableName
+	 *            表名
+	 * @param keyData
+	 *            主键值
+	 * @param cascadeType
+	 *            操作
+	 * @return
+	 */
+	public void relationCheck(String tableName, Object keyData, String cascadeType) {
+		String checkError = callProcedure("tablerelation.relationCheck", new Object[] { tableName, String.valueOf(keyData), cascadeType });
+		if (checkError != null)
+			throw new SystemException("无法完成操作!存在关联的数据:" + checkError);
+	}
+
+	/**
+	 * 删除前,关联表数据检查
+	 * 
+	 * @param tableName
+	 *            表名
+	 * @param keyData
+	 *            主键值
+	 * @return
+	 */
+	public void delCheck(String tableName, Object keyData) {
+		relationCheck(tableName, keyData, "DELETE");
+	}
+
+	/**
+	 * 检测当前日期所在期间是否结账
+	 * 
+	 * @param type
+	 *            期间类型
+	 * @param orderdate
+	 *            单据日期
+	 * @return
+	 */
+	public void checkCloseMonth(String type, Object orderdate) {
+		boolean bool = checkIf("PeriodsDetail", "pd_code='" + type + "' and pd_status=99 and pd_detno=to_char(to_date('" + orderdate
+				+ "','yyyy-mm-dd hh24:mi:ss'), 'yyyymm')");
+		if (bool) {
+			throw new SystemException("单据日期所属期间已结账,不允许进行当前操作!");
+		}
+	}
+
+	/**
+	 * 获取限制权限
+	 * */
+	public String getLimitCondition(String tabSql, Integer emid) {
+		String condition = "", appendSql = "";
+		try {
+			if (checkIf("DataLimit", "USEABLE_=1")) {
+				String tables = getJdbcTemplate()
+						.queryForObject("select tablerelation.getTables('" + tabSql + "') from dual", String.class);
+				tables = tables.replaceAll("TAB", "").trim();
+				tables = tables.replaceAll(",", "','");
+				/*
+				 * SqlRowList sl = queryForRowSet( "SELECT Instanceid_,max(case when table_ in ('" + tables + "') AND COL_DEL_1=CODEFIELD_ THEN CODEFIELD_ WHEN table_ in ('" + tables +
+				 * "') AND COL_DEL_1=NAMEFIELD_ THEN NAMEFIELD_ else col_rel_1 end ),MAX(CASE WHEN COL_DEL_1=CODEFIELD_ THEN 'CODE_' WHEN COL_DEL_1=NAMEFIELD_ THEN 'DESC_' ELSE  'NONE' END ) from Datalimit_Instance LEFT JOIN Datalimit  ON Datalimit.ID_=Datalimit_Instance.Limit_Id_ AND Datalimit_Instance.Empid_=? and Datalimit_Instance.Nolimit_=0 left join Datacascade on Datalimit.table_=Datacascade.table_del where table_rel IN ('" + tables + "') or table_ in ('" + tables +
+				 * "') group by instanceid_ ", new Object[] { emid }); while (sl.next()) { if (!"NONE".equals(sl.getObject(3))) { appendSql = " Exists (select code_ from datalimit_detail where INSTANCEID_=" + sl.getObject(1) + " AND SEE_=1 AND " + sl.getObject(2) + "=" + sl.getObject(3) + ")"; condition += condition.equals("") ? appendSql : (" AND " + appendSql); }
+				 * 
+				 * }
+				 */
+				SqlRowList basesl = queryForRowSet(
+						"select Datalimit_Instance.CONDITION_,Datalimit.Codefield_,Datalimit_Instance.Instanceid_ from Datalimit_Instance Datalimit_Instance left join datalimit on  Datalimit.ID_=Datalimit_Instance.Limit_Id_ "
+								+ "AND Datalimit_Instance.Empid_=? and Datalimit_Instance.Nolimit_=0 where table_ in ('" + tables + "')",
+								new Object[] { emid });
+				while (basesl.next()) {
+					appendSql = basesl.getObject(1) != null ? " " + basesl.getObject(1)
+							: " Exists (select code_ from datalimit_detail where INSTANCEID_=" + basesl.getObject(3)
+							+ " AND SEE_=1 AND CODE_=" + basesl.getObject(2) + ")";
+					condition += condition.equals("") ? appendSql : (" AND " + appendSql);
+				}
+				SqlRowList relativesl = queryForRowSet(
+						"select col_rel_1,Col_Del_1,CASE WHEN Col_Del_1=CODEFIELD_ THEN 'CODE_' WHEN Col_Del_1=NAMEFIELD_ THEN 'DESC_' ELSE 'NONE' END,Datalimit_Instance.CONDITION_,TABLE_,INSTANCEID_ from Datalimit_Instance left join datalimit on  Datalimit.ID_=Datalimit_Instance.Limit_Id_ AND Datalimit_Instance.Empid_=? and "
+								+ "Datalimit_Instance.Nolimit_=0 LEFT JOIN   Datacascade on Datalimit.table_=Datacascade.table_del where table_rel in ('"
+								+ tables + "')", new Object[] { emid });
+				while (relativesl.next()) {
+					if (!"NONE".equals(relativesl.getObject(3))) {
+						appendSql = relativesl.getObject(4) != null ? " Exists (select 1 from " + relativesl.getObject(5) + " where "
+								+ relativesl.getObject(4) + " and (" + relativesl.getObject(2) + "=" + relativesl.getObject(1) + " or "
+								+ relativesl.getObject(1) + " is null))" : " Exists (select 1 from datalimit_detail where INSTANCEID_="
+								+ relativesl.getObject(6) + " AND SEE_=1 AND " + relativesl.getObject(3) + "=" + relativesl.getObject(1)
+								+ ")";
+						condition += condition.equals("") ? appendSql : (" AND " + appendSql);
+					}
+				}
+				return condition;
+			}
+			return condition;
+		} catch (Exception e) {
+			return condition;
+		}
+
+	}
+
+	/***
+	 * 平台传回ERP接收标准方法 content 内容 type 消息类型 noticemans 对应产生的人员名称以#号分隔
+	 * 
+	 * **/
+	public List<String> beatchNotices(String content, String type, String noticemans, String condition, String fromcaller) {
+		List<String> sqls = new ArrayList<String>();
+		int pr_id = getSeqId("PAGINGRELEASE_SEQ");
+		sqls.add("insert into pagingrelease(pr_id,pr_releaser,pr_date,pr_context,PR_FROM,pr_caller,pr_content )values('" + pr_id
+				+ "','系统管理员'," + DateUtil.parseDateToOracleString(Constant.YMD, new Date()) + ",'" + content + "','" + type + "','"
+				+ fromcaller + "','" + condition + "')");
+		String[] mans = (String.valueOf(noticemans)).split("#");
+		for (String man : mans) {
+			Object manid = getFieldDataByCondition("employee", "max(em_id)", "em_name='" + man + "'");
+			int prd_id = getSeqId("PAGINGRELEASEDETAIL_SEQ");
+			sqls.add("insert into pagingreleasedetail(prd_id,prd_prid,PRD_RECIPIENTID,PRD_RECIPIENT) values('" + prd_id + "','" + pr_id
+					+ "','" + manid + "','" + man + "')");
+		}
+		return sqls;
+	}
+	/**
+	 * @param objForSave
+	 * @return
+	 */
+
+	public void save(Saveable objForSave) {
+		SimpleJdbcInsert insertActor = getSimpleJdbcInsert();
+		insertActor.setTableName(objForSave.table());
+		insertActor.execute(new BeanPropertySqlParameterSource(objForSave));
+	}
+
+	/**
+	 * 批量保存
+	 * 
+	 * @param objsForSave
+	 * @return
+	 */
+
+	public void save(Collection<? extends Saveable> objsForSave) {
+		SqlParameterSource[] sqlSource = new SqlParameterSource[objsForSave.size()];
+		int i = 0;
+		String tableName = null;
+		for (Saveable obj : objsForSave) {
+			sqlSource[i++] = new BeanPropertySqlParameterSource(obj);
+			if (tableName == null)
+				tableName = obj.table();
+		}
+		SimpleJdbcInsert insertActor = getSimpleJdbcInsert();
+		insertActor.setTableName(tableName);
+		insertActor.executeBatch(sqlSource);
+	}
+
+}

+ 71 - 0
src/com/mes/dao/Constant.java

@@ -0,0 +1,71 @@
+package com.mes.dao;
+
+import com.mes.core.BaseUtil;
+
+/**
+ * 系统常量
+ * 
+ * @author yingp
+ * 
+ */
+public class Constant {
+
+	// 日期格式
+
+	public final static String YM = "yyyy-MM";
+
+	public final static String YMD = "yyyy-MM-dd";
+
+	public final static String YMD_HM = "yyyy-MM-dd HH:mm";
+
+	public final static String YMD_HMS = "yyyy-MM-dd HH:mm:ss";
+
+	public final static String ORACLE_YMD = "yyyy-MM-dd";
+
+	public final static String ORACLE_YMD_HMS = "yyyy-MM-dd HH24:mi:ss";
+
+	/**
+	 * 是
+	 */
+	public static final short YES = 1;
+	/**
+	 * 是
+	 */
+	public static final short yes = -1;
+	/**
+	 * 是
+	 */
+	public static final String TRUE = "T";
+	/**
+	 * 否
+	 */
+	public static final short NO = 0;
+	/**
+	 * 否
+	 */
+	public static final String FALSE = "F";
+
+	public static final int ORACLE_MAX_TABLE_SIZE = 999;
+
+	/**
+	 * @return 管理平台地址
+	 */
+	public static String manageHost() {
+		return BaseUtil.getXmlSetting("host.manage");
+	}
+
+	/**
+	 * @return B2B平台地址
+	 */
+	public static String b2bHost() {
+		return BaseUtil.getXmlSetting("host.b2b");
+	}
+
+	/**
+	 * @return B2B平台地址
+	 */
+	public static String b2cHost() {
+		return BaseUtil.getXmlSetting("host.b2c");
+	}
+
+}

+ 11 - 0
src/com/mes/dao/DataListComboDao.java

@@ -0,0 +1,11 @@
+package com.mes.dao;
+
+import java.util.List;
+
+import com.mes.model.DataListCombo;
+
+public interface DataListComboDao {
+	List<DataListCombo> getComboxsByCaller(String caller, String sob);
+	List<DataListCombo> getComboxsByCallerAndField(String caller,String Field);
+	List<DataListCombo> getComboxsByCallers(String callers);
+}

+ 7 - 0
src/com/mes/dao/DbfindSetDao.java

@@ -0,0 +1,7 @@
+package com.mes.dao;
+
+import com.mes.model.DBFindSet;
+
+public interface DbfindSetDao {
+	DBFindSet getDbfind(String caller, String sob);
+}

+ 10 - 0
src/com/mes/dao/DbfindSetGridDao.java

@@ -0,0 +1,10 @@
+package com.mes.dao;
+
+import java.util.List;
+
+import com.mes.model.DBFindSetGrid;
+
+public interface DbfindSetGridDao {
+	List<DBFindSetGrid> getDbFindSetGridsByCaller(String caller);
+	void deleteDbFindSetGridById(int id);
+}

+ 16 - 0
src/com/mes/dao/DbfindSetUiDao.java

@@ -0,0 +1,16 @@
+package com.mes.dao;
+
+import com.mes.model.DBFindSetUI;
+
+public interface DbfindSetUiDao {
+	/**
+	 * @param caller
+	 * @param field
+	 * @param sob 帐套信息
+	 * @return
+	 */
+	DBFindSetUI getDbFindSetUIByField(String caller, String field, String sob);
+	DBFindSetUI getDbFindSetUIByCallerAndField(String caller, String field);
+	DBFindSetUI getDbFindSetUIById(int id);
+	void deleteDbFindSetUIById(int id);
+}

+ 14 - 0
src/com/mes/dao/DetailGridDao.java

@@ -0,0 +1,14 @@
+package com.mes.dao;
+
+import java.util.List;
+
+import com.mes.model.DetailGrid;
+
+public interface DetailGridDao {
+	/**
+	 * @param caller
+	 * @param sob 帐套信息
+	 * @return
+	 */
+	List<DetailGrid> getDetailGridsByCaller(String caller, String sob);
+}

+ 39 - 0
src/com/mes/dao/EmployeeDao.java

@@ -0,0 +1,39 @@
+package com.mes.dao;
+
+import java.util.List;
+import java.util.Map;
+
+import com.mes.model.Employee;
+import com.mes.model.Master;
+
+public interface EmployeeDao {
+	Employee getEmployeeByEmCode(String em_code);
+
+	/**
+	 * @param sob
+	 *            帐套信息
+	 * @return
+	 */
+	List<Employee> getEmployees(String sob);
+
+	Employee getEmployeeByEmId(long em_id);
+
+	Employee getEmployeeByEmUu(long em_uu);
+
+	List<Employee> getEmployeesByOrId(int or_id);
+
+	List<Employee> getEmployeesByOrIdWithWDM(int or_id, String caller);
+
+	Employee getEmployeeByConditon(String condition);
+
+	List<Employee> getEmployeesByConditon(String condition);
+
+	Master getMaster(int em_id);
+
+	Employee getEmployeeByEmTel(String username);
+
+	Employee getEmployeeByEmcode(String emcode);
+
+	List<Map<String, Object>> getEmployeedata(String fields, String condition, int page, int pagesize);
+	
+}

+ 23 - 0
src/com/mes/dao/EnterpriseDao.java

@@ -0,0 +1,23 @@
+package com.mes.dao;
+
+import java.util.List;
+
+import com.mes.model.Enterprise;
+import com.mes.model.JSONTree;
+import com.mes.model.Master;
+
+public interface EnterpriseDao {
+	Enterprise getEnterpriseByName(String name);
+
+	Enterprise getEnterpriseByEnUU(int en_uu);
+
+	Enterprise getEnterpriseById(int id);
+	
+	Enterprise getEnterprise();
+
+	List<Master> getMasters();
+	
+	Master getMasterByDomain(String domain);
+
+	List<JSONTree> getMastersTree(Integer pid);
+}

+ 103 - 0
src/com/mes/dao/MessageLog.java

@@ -0,0 +1,103 @@
+package com.mes.dao;
+
+import java.io.Serializable;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class MessageLog implements Serializable {
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+	private int ml_id;
+	private Date ml_date;// 操作日期
+	private String ml_man;// 操作人
+	private String ml_content;// 内容
+	private String ml_result;// 结果
+	private String ml_search;// 用于事后查询单据操作记录时,用于检索的条件
+
+	public int getMl_id() {
+		return ml_id;
+	}
+
+	public void setMl_id(int ml_id) {
+		this.ml_id = ml_id;
+	}
+
+	public Date getMl_date() {
+		return ml_date;
+	}
+
+	public void setMl_date(Date ml_date) {
+		this.ml_date = ml_date;
+	}
+
+	public String getMl_man() {
+		return ml_man;
+	}
+
+	public void setMl_man(String ml_man) {
+		this.ml_man = ml_man;
+	}
+
+	public String getMl_content() {
+		return ml_content;
+	}
+
+	public void setMl_content(String ml_content) {
+		this.ml_content = ml_content;
+	}
+
+	public String getMl_result() {
+		return ml_result;
+	}
+
+	public void setMl_result(String ml_result) {
+		this.ml_result = ml_result;
+	}
+
+	public String getMl_search() {
+		return ml_search;
+	}
+
+	public void setMl_search(String ml_search) {
+		this.ml_search = ml_search;
+	}
+
+	public MessageLog() {
+
+	}
+
+	/**
+	 * @param ml_man
+	 *            操作人
+	 * @param ml_content
+	 *            内容
+	 * @param ml_result
+	 *            结果
+	 * @param ml_search
+	 *            用于事后查询单据操作记录时,用于检索的条件{caller|Key=keyValue}
+	 */
+	public MessageLog(String ml_man, String ml_content, String ml_result, String ml_search) {
+		this.ml_man = ml_man;
+		this.ml_content = ml_content;
+		this.ml_result = ml_result;
+		this.ml_search = ml_search;
+	}
+
+	public String getSql() {
+		return getInsertSql(ml_man, ml_content, ml_result, ml_search);
+	}
+
+	public static String getInsertSql(String man, String content, String result, String search) {
+		StringBuffer sql = new StringBuffer("INSERT INTO MessageLog(ml_date,ml_man,ml_content,ml_result,ml_search) VALUES(");
+		sql.append("to_date('");
+		sql.append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+		sql.append("','yyyy-MM-dd HH24:mi:ss'),'");
+		sql.append(man + "','");
+		sql.append(content + "','");
+		sql.append(result + "','");
+		sql.append(search + "')");
+		return sql.toString();
+	}
+}

+ 82 - 0
src/com/mes/dao/MultiDataSource.java

@@ -0,0 +1,82 @@
+package com.mes.dao;
+
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import javax.sql.DataSource;
+import org.apache.commons.dbcp.BasicDataSource;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+
+public class MultiDataSource extends BasicDataSource implements DataSource, ApplicationContextAware {
+
+	private ApplicationContext applicationContext = null;
+	private DataSource dataSource = null;
+	private Properties connectionProperties = null;
+	public Connection getConnection() throws SQLException {
+		return getDataSource().getConnection();
+	}
+
+	public Connection getConnection(String arg0, String arg1) throws SQLException {
+		return getDataSource().getConnection(arg0, arg1);
+	}
+
+	public PrintWriter getLogWriter() throws SQLException {
+		return getDataSource().getLogWriter();
+	}
+
+	public Properties getConnectionProperties() {
+		return connectionProperties;
+	}
+
+	public void setConnectionProperties(Properties connectionProperties) {
+		this.connectionProperties = connectionProperties;
+	}
+
+	public int getLoginTimeout() throws SQLException {
+		return getDataSource().getLoginTimeout();
+	}
+
+	public void setLogWriter(PrintWriter arg0) throws SQLException {
+		getDataSource().setLogWriter(arg0);
+	}
+
+	public void setLoginTimeout(int arg0) throws SQLException {
+		getDataSource().setLoginTimeout(arg0);
+	}
+
+	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+		this.applicationContext = applicationContext;
+	}
+
+	public DataSource getDataSource(String dataSourceName) {
+		if (dataSourceName == null || dataSourceName.equals("")) {
+			return this.dataSource;
+		}
+		return (DataSource) this.applicationContext.getBean(dataSourceName);
+	}
+
+	public void setDataSource(DataSource dataSource) {
+		this.dataSource = dataSource;
+	}
+
+	public DataSource getDataSource() {
+		String sp = SpObserver.getSp();
+		return getDataSource(sp);
+	}
+
+	@Override
+	public <T> T unwrap(Class<T> iface) throws SQLException {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public boolean isWrapperFor(Class<?> iface) throws SQLException {
+		// TODO Auto-generated method stub
+		return false;
+	}
+}

+ 13 - 0
src/com/mes/dao/Saveable.java

@@ -0,0 +1,13 @@
+package com.mes.dao;
+
+/**
+ * could be inserted into database
+ * @author yingp
+ * @date  2012-7-23 22:55:34
+ */
+public interface Saveable {
+
+	public String table();
+	//key field
+	public String[] keyColumns();
+}

+ 27 - 0
src/com/mes/dao/SpObserver.java

@@ -0,0 +1,27 @@
+package com.mes.dao;
+
+/**
+ * 
+ */
+public class SpObserver {
+	
+	private static ThreadLocal<String> local = new ThreadLocal<String>();
+
+	/**
+	 * 切换数据源
+	 * 
+	 * @param sp
+	 *            dbsource name
+	 */
+	public static void putSp(String sp) {
+		local.set(sp);
+	}
+
+	public static String getSp() {
+		return (String) local.get();
+	}
+	
+	public static void clear() {
+		local.set(null);
+	}
+}

+ 387 - 0
src/com/mes/dao/SqlMap.java

@@ -0,0 +1,387 @@
+package com.mes.dao;
+
+import java.io.Serializable;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.dao.DataAccessException;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.support.AbstractLobCreatingPreparedStatementCallback;
+import org.springframework.jdbc.support.lob.LobCreator;
+import org.springframework.jdbc.support.lob.LobHandler;
+
+import com.mes.core.BaseUtil;
+import com.mes.core.ContextUtil;
+import com.mes.core.DateUtil;
+
+
+/**
+ * 封装sql操作,提供对特殊类型的值的灵活处理
+ * 
+ * @author yingp
+ * 
+ * @since 2015-11-26
+ *        <p>
+ *        增加更新功能,参考构造函数;增加对lob数据的处理
+ *        </p>
+ *
+ */
+public class SqlMap implements Serializable {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 7665440776209042811L;
+
+	/**
+	 * 如果sysdate,getdate()等符合该正则表达式的字符串不需要特殊处理<br>
+	 * 就调用set(String, Object, boolean)方法,第三个参数为false
+	 */
+	private static final String REG_SPECIAL = "(?:sysdate|getdate\\(\\))";
+
+	private static final int longStringBytes = 4000;// 字符串最长字节数,超过了就得使用lob类型
+
+	private String table;
+
+	/**
+	 * 主键
+	 */
+	private String primaryKey;
+	/**
+	 * 主键值
+	 */
+	private Object primaryValue;
+
+	private boolean isNew = true;
+
+	private List<String> fields;
+
+	private Object[] values;
+
+	private Map<String, Object> specials;
+
+	public SqlMap() {
+		fields = new ArrayList<String>();
+		values = new Object[] {};
+		specials = new HashMap<String, Object>();
+	}
+
+	/**
+	 * 新增模式
+	 * 
+	 * @param table
+	 *            待插入的表
+	 */
+	public SqlMap(String table) {
+		this();
+		this.table = table;
+	}
+
+	/**
+	 * 修改模式
+	 * 
+	 * @param table
+	 *            待插入的表
+	 * @param primaryKey
+	 *            主键
+	 */
+	public SqlMap(String table, String primaryKey) {
+		this(table);
+		this.primaryKey = primaryKey;
+		isNew = false;
+	}
+
+	/**
+	 * 修改模式
+	 * 
+	 * @param table
+	 *            待插入的表
+	 * @param primaryKey
+	 *            主键
+	 * @param primaryValue
+	 *            主键值
+	 */
+	public SqlMap(String table, String primaryKey, Object primaryValue) {
+		this(table);
+		this.primaryKey = primaryKey;
+		this.primaryValue = primaryValue;
+		isNew = false;
+	}
+
+	/**
+	 * 添加要插入的字段
+	 * 
+	 * @param field
+	 *            toSql字段
+	 * @param value
+	 *            字段的值
+	 * @param type
+	 *            字段的类型
+	 */
+	public void set(String field, Object value) {
+		if (!isNew && field.equals(primaryKey)) {
+			primaryValue = value;
+		} else {
+			if (isSpecial(value)) {
+				setSpecial(field, value);
+			} else {
+				fields.add(field);
+				values = Arrays.copyOf(values, values.length + 1);
+				values[values.length - 1] = value;
+			}
+		}
+	}
+
+	/**
+	 * 添加要插入的字段
+	 * 
+	 * @param field
+	 *            toSql字段
+	 * @param value
+	 *            字段的值
+	 * @param special
+	 *            是否是特殊字符,比如调用数据库函数,参数等
+	 */
+	public void set(String field, Object value, boolean special) {
+		if (!isNew && field.equals(primaryKey)) {
+			primaryValue = value;
+		} else {
+			if (special) {
+				setSpecial(field, value);
+			} else {
+				fields.add(field);
+				values = Arrays.copyOf(values, values.length + 1);
+				values[values.length - 1] = value;
+			}
+		}
+	}
+
+	/**
+	 * 添加要插入的字段
+	 * 
+	 * @param field
+	 *            toSql字段
+	 * @param value
+	 *            字段的值
+	 */
+	public void setSpecial(String field, Object value) {
+		if (!isNew && field.equals(primaryKey)) {
+			primaryValue = value;
+		} else {
+			fields.add(field);
+			specials.put(field, value);
+		}
+	}
+
+	/**
+	 * 添加要插入的字段 <b>字段值为空</b>
+	 * 
+	 * @param field
+	 *            toSql字段
+	 * @param value
+	 *            字段的值
+	 */
+	public void setNull(String field) {
+		setSpecial(field, "null");
+	}
+
+	/**
+	 * 添加要插入的字段<b>Double型</b>
+	 * 
+	 * @param field
+	 *            toSql字段
+	 * @param value
+	 *            {Double}字段的值
+	 */
+	public void setDouble(String field, Double value) {
+		value = value == null ? 0 : value;
+		setSpecial(field, value);
+	}
+
+	/**
+	 * 添加要插入的字段<b>日期型</b>
+	 * 
+	 * @param to
+	 *            toSql字段
+	 * @param value
+	 *            {Date}字段的值
+	 */
+	public void setDate(String field, Date value) {
+		setDate(field, value, Constant.YMD_HMS);
+	}
+
+	/**
+	 * 添加要插入的字段<b>日期型</b>
+	 * 
+	 * @param to
+	 *            toSql字段
+	 * @param value
+	 *            {Date}字段的值
+	 * @param format
+	 *            格式
+	 */
+	public void setDate(String field, Date value, String format) {
+		if (value == null)
+			setNull(field);
+		else
+			setSpecial(field, DateUtil.parseDateToOracleString(format, value));
+	}
+
+	/**
+	 * 添加要插入的字段<b>日期型</b>
+	 * 
+	 * @param to
+	 *            toSql字段
+	 * @param value
+	 *            {Date}字段的值
+	 */
+	public void setDate(String field, String value) {
+		setDate(field, value, Constant.YMD_HMS);
+	}
+
+	/**
+	 * 添加要插入的字段<b>日期型</b>
+	 * 
+	 * @param to
+	 *            toSql字段
+	 * @param value
+	 *            {Date}字段的值
+	 * @param format
+	 *            格式
+	 */
+	public void setDate(String field, String value, String format) {
+		if (value == null)
+			setNull(field);
+		else
+			setSpecial(field, DateUtil.parseDateToOracleString(format, value));
+	}
+
+	private static boolean isSpecial(Object value) {
+		if (value != null) {
+			return value.toString().matches(REG_SPECIAL);
+		}
+		return false;
+	}
+
+	/**
+	 * 是否lob类型
+	 * 
+	 * @param value
+	 * @return
+	 */
+	private static boolean isLob(Object value) {
+		return value != null && value.toString().getBytes().length > longStringBytes;
+	}
+
+	/**
+	 * insert语句
+	 * 
+	 * @param mark
+	 *            {true: value以参数形式传入}
+	 * @return
+	 */
+	public String getInsertSql(boolean mark) {
+		StringBuffer sb = new StringBuffer();
+		sb.append("INSERT INTO ").append(table).append("(").append(BaseUtil.parseList2Str(fields, ",", true)).append(") VALUES (")
+				.append(getEnd(mark)).append(")");
+		return sb.toString();
+	}
+
+	/**
+	 * update语句
+	 * 
+	 * @param mark
+	 *            {true: value以参数形式传入}
+	 * @return
+	 */
+	public String getUpdateSql(boolean mark) {
+		StringBuffer sb = new StringBuffer();
+		sb.append("UPDATE ").append(table).append(" SET ").append(getEnd(mark));
+		return sb.toString();
+	}
+
+	/**
+	 * insertOrUpdate语句
+	 * 
+	 * @param mark
+	 *            {true: value以参数形式传入}
+	 * @return
+	 */
+	public String getSql(boolean mark) {
+		return isNew ? getInsertSql(mark) : getUpdateSql(mark);
+	}
+
+	/**
+	 * 执行sql
+	 */
+	public void execute() {
+		BaseDao baseDao = (BaseDao) ContextUtil.getBean("baseDao");
+		baseDao.getJdbcTemplate().update(getSql(true), values);
+	}
+
+	/**
+	 * 执行sql
+	 * 
+	 * @param jdbcTemplate
+	 */
+	public void execute(JdbcTemplate jdbcTemplate, LobHandler lobHandler) {
+		jdbcTemplate.execute(getSql(true), new AbstractLobCreatingPreparedStatementCallback(lobHandler) {
+			@Override
+			protected void setValues(PreparedStatement ps, LobCreator lob) throws SQLException, DataAccessException {
+				int i = 0;
+				for (Object value : values) {
+					i++;
+					if (isLob(value))
+						lob.setClobAsString(ps, i, value.toString());
+					else
+						ps.setObject(i, value);
+				}
+			}
+		});
+	}
+
+	/**
+	 * @param mark
+	 *            {true: value以参数形式传入}
+	 * @return
+	 */
+	private String getEnd(boolean mark) {
+		int len = fields.size();
+		StringBuffer sb = new StringBuffer();
+		String field = null;
+		int j = 0;
+		for (int i = 0; i < len; i++) {
+			if (sb.length() > 0)
+				sb.append(",");
+			field = fields.get(i);
+			if (!isNew)
+				sb.append(field).append("=");
+			if (specials.containsKey(field)) {
+				sb.append(specials.get(field));
+			} else {
+				if (mark)
+					sb.append("?");
+				else
+					sb.append("'").append(values[j++]).append("'");
+			}
+		}
+		if (!isNew) {
+			sb.append(" WHERE ").append(primaryKey).append("=");
+			if (mark) {
+				sb.append("?");
+				values = Arrays.copyOf(values, values.length + 1);
+				values[values.length - 1] = primaryValue;
+			} else {
+				sb.append("'").append(primaryValue).append("'");
+			}
+		}
+		return sb.toString();
+	}
+
+}

+ 382 - 0
src/com/mes/dao/SqlRowList.java

@@ -0,0 +1,382 @@
+package com.mes.dao;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import com.mes.core.DateUtil;
+import com.mes.core.NumberUtil;
+
+import net.sf.json.JSONObject;
+
+/**
+ * org.springframework.jdbc.support.rowset.SqlRowSet有jdk版本问题
+ * 
+ * @author yingp 2013-1-10 11:50:08
+ */
+public class SqlRowList {
+
+	private List<Map<String, Object>> resultList;// 结果集
+	private Iterator<Map<String, Object>> iterator;
+	private Map<String, Object> currentMap;// 当前Map
+	private int currentIndex = -1;// 当前index,从0开始
+	private List<String> keys;// 字段名集
+
+	public SqlRowList() {
+		this.resultList = new ArrayList<Map<String, Object>>();
+	}
+
+	public List<Map<String, Object>> getResultList() {
+		return resultList;
+	}
+
+	public int size() {
+		return getResultList().size();
+	}
+
+	public void setResultList(List<Map<String, Object>> resultList) {
+		this.resultList = resultList;
+	}
+
+	public Map<String, Object> getCurrentMap() {
+		return currentMap;
+	}
+
+	public void setCurrentMap(Map<String, Object> currentMap) {
+		this.currentMap = currentMap;
+	}
+
+	public int getCurrentIndex() {
+		return currentIndex;
+	}
+
+	public void setCurrentIndex(int currentIndex) {
+		this.currentIndex = currentIndex;
+	}
+
+	public List<String> getKeys() {
+		if (this.keys == null) {
+			this.keys = new ArrayList<String>();
+			if (this.resultList != null) {
+				Iterator<Map<String, Object>> iterator = resultList.iterator();
+				if (iterator.hasNext()) {
+					Map<String, Object> map = iterator.next();
+					Iterator<String> fields = map.keySet().iterator();
+					while (fields.hasNext()) {
+						this.keys.add(fields.next());
+					}
+				}
+			}
+		}
+		return keys;
+	}
+
+	public void setKeys(List<String> keys) {
+		this.keys = keys;
+	}
+
+	/**
+	 * 取ResultSet的第index条Map
+	 * 
+	 * @param index
+	 * @return
+	 */
+	public Map<String, Object> getAt(int index) {
+		if (this.resultList != null) {
+			Iterator<Map<String, Object>> iterator = resultList.iterator();
+			Map<String, Object> map = null;
+			int idx = 0;
+			while (iterator.hasNext() && (map = iterator.next()) != null) {
+				if (index == idx)
+					return map;
+				idx++;
+			}
+		}
+		return null;
+	}
+	public boolean hasNext() {
+		if (this.resultList != null) {
+			if (this.iterator == null) {
+				this.iterator = resultList.iterator();
+			}
+			if (this.iterator.hasNext()) {
+				return true;
+			}
+		}
+		return false;
+	}
+
+	public boolean next(int count) {
+		for (int i = 0; i < count; i++) {
+			if (!next())
+				return false;
+		}
+		return true;
+	}
+
+	public boolean next() {
+		if (this.resultList != null) {
+			if (this.iterator == null) {
+				this.iterator = resultList.iterator();
+				this.currentIndex = -1;
+			}
+			if (this.iterator.hasNext()) {
+				this.currentMap = iterator.next();
+				this.currentIndex += 1;
+				if (this.keys == null) {
+					this.keys = new ArrayList<String>();
+					Iterator<String> fields = currentMap.keySet().iterator();
+					while (fields.hasNext()) {
+						this.keys.add(fields.next());
+					}
+				}
+				return true;
+			}
+		}
+		return false;
+	}
+
+	public int getInt(int index) {
+		Object obj = getObject(index);
+		return obj == null ? -1 : Integer.parseInt(obj.toString());
+	}
+
+	public int getInt(String field) {
+		Object obj = getObject(field);
+		return obj == null ? -1 : Integer.parseInt(obj.toString());
+	}
+
+	public int getGeneralInt(int index) {
+		Object obj = getObject(index);
+		return obj == null ? 0 : Integer.parseInt(obj.toString());
+	}
+
+	public int getGeneralInt(String field) {
+		Object obj = getObject(field);
+		return obj == null ? 0 : Integer.parseInt(obj.toString());
+	}
+
+	public float getFloat(int index) {
+		Object obj = getObject(index);
+		return obj == null ? -1 : Float.parseFloat(obj.toString());
+	}
+
+	public float getFloat(String field) {
+		Object obj = getObject(field);
+		return obj == null ? -1 : Float.parseFloat(obj.toString());
+	}
+
+	public float getGeneralFloat(int index) {
+		Object obj = getObject(index);
+		return obj == null ? 0 : Float.parseFloat(obj.toString());
+	}
+
+	public float getGeneralFloat(String field) {
+		Object obj = getObject(field);
+		return obj == null ? 0 : Float.parseFloat(obj.toString());
+	}
+
+	public double getDouble(int index) {
+		Object obj = getObject(index);
+		return obj == null ? -1 : Double.parseDouble(obj.toString());
+	}
+
+	public double getDouble(String field) {
+		Object obj = getObject(field);
+		return obj == null ? -1 : Double.parseDouble(obj.toString());
+	}
+
+	public BigDecimal getBigDecimal(int index) {
+		Object obj = getObject(index);
+		return obj == null ? null : BigDecimal.valueOf(Double.parseDouble(obj.toString()));
+	}
+
+	public BigDecimal getBigDecimal(String field) {
+		Object obj = getObject(field);
+		return obj == null ? null : BigDecimal.valueOf(Double.parseDouble(obj.toString()));
+	}
+
+	public double getGeneralDouble(int index) {
+		Object obj = getObject(index);
+		return obj == null ? 0 : Double.parseDouble(obj.toString());
+	}
+
+	/**
+	 * @param index
+	 * @param sub
+	 *            保留小数位数
+	 * @return
+	 */
+	public double getGeneralDouble(int index, int sub) {
+		return NumberUtil.formatDouble(getGeneralDouble(index), sub);
+	}
+
+	public double getGeneralDouble(String field) {
+		Object obj = getObject(field);
+		return obj == null || String.valueOf(obj).trim().equals("") ? 0 : Double.parseDouble(String.valueOf(obj).trim());
+	}
+
+	/**
+	 * @param field
+	 * @param sub
+	 *            保留小数位数
+	 * @return
+	 */
+	public double getGeneralDouble(String field, int sub) {
+		return NumberUtil.formatDouble(getGeneralDouble(field), sub);
+	}
+
+	public BigDecimal getGeneralBigDecimal(int index) {
+		Object obj = getObject(index);
+		return obj == null ? new BigDecimal(0) : BigDecimal.valueOf(Double.parseDouble(obj.toString()));
+	}
+
+	public BigDecimal getGeneralBigDecimal(String field) {
+		Object obj = getObject(field);
+		return obj == null ? new BigDecimal(0) : BigDecimal.valueOf(Double.parseDouble(obj.toString()));
+	}
+
+	public long getLong(int index) {
+		Object obj = getObject(index);
+		return obj == null ? -1 : Long.parseLong(obj.toString());
+	}
+
+	public long getLong(String field) {
+		Object obj = getObject(field);
+		return obj == null ? -1 : Long.parseLong(obj.toString());
+	}
+
+	public long getGeneralLong(int index) {
+		Object obj = getObject(index);
+		return obj == null ? 0 : Long.parseLong(obj.toString());
+	}
+
+	public long getGeneralLong(String field) {
+		Object obj = getObject(field);
+		return obj == null ? 0 : Long.parseLong(obj.toString());
+	}
+
+	public String getString(int index) {
+		Object obj = getObject(index);
+		return obj == null ? null : obj.toString();
+	}
+
+	public String getString(String field) {
+		Object obj = getObject(field);
+		return obj == null ? null : obj.toString();
+	}
+
+	public String getGeneralString(int index) {
+		Object obj = getObject(index);
+		return obj == null ? "" : obj.toString();
+	}
+
+	public String getGeneralString(String field) {
+		Object obj = getObject(field);
+		return obj == null ? "" : obj.toString();
+	}
+
+	public Object getObject(int index) {
+		if (this.iterator == null || this.currentMap == null || this.keys == null || index <= 0 || index > this.keys.size()) {
+			return null;
+		}
+		return this.currentMap.get(this.keys.get(index - 1));
+	}
+
+	public Object getObject(String field) {
+		if (this.iterator == null || this.currentMap == null) {
+			return null;
+		}
+		return this.currentMap.get(field.toUpperCase());
+	}
+
+	/**
+	 * currentMap的JSON格式
+	 */
+	public JSONObject getJSONObject() {
+		if (this.iterator == null || this.currentMap == null) {
+			return null;
+		}
+		JSONObject json = new JSONObject();
+		Object value = null;
+		for (String k : this.keys) {
+			value = this.getObject(k);
+			if (value != null && "TIMESTAMP".equals(value.getClass().getSimpleName().toUpperCase())) {
+				Timestamp time = (Timestamp) value;
+				value = DateUtil.parseDateToString(new Date(time.getTime()), "yyyy-MM-dd HH:mm:ss");
+			}
+			json.put(k, value);
+		}
+		return json;
+	}
+
+	/**
+	 * currentMap的JSONString格式
+	 */
+	public String getJSON() {
+		if (this.iterator == null || this.currentMap == null) {
+			return null;
+		}
+		return getJSONObject().toString();
+	}
+
+	public Date getDate(int index) {
+		Object obj = getObject(index);
+		return obj == null ? null : (Date) obj;
+	}
+
+	public Date getDate(String field) {
+		Object obj = getObject(field);
+		return obj == null ? null : (Date) obj;
+	}
+
+	public Timestamp getTimestamp(int index) {
+		Object obj = getObject(index);
+		return obj == null ? null : (Timestamp) obj;
+	}
+
+	public Timestamp getTimestamp(String field) {
+		Object obj = getObject(field);
+		return obj == null ? null : (Timestamp) obj;
+	}
+
+	public String getGeneralTimestamp(int index) {
+		Timestamp time = getTimestamp(index);
+		if (time != null)
+			return DateUtil.parseDateToString(new Date(time.getTime()), Constant.YMD_HMS);
+		return "";
+	}
+
+	public String getGeneralTimestamp(String field) {
+		Timestamp time = getTimestamp(field);
+		if (time != null)
+			return DateUtil.parseDateToString(new Date(time.getTime()), Constant.YMD_HMS);
+		return "";
+	}
+
+	public double getSummary(String field) {
+		if (hasNext()) {
+			Iterator<Map<String, Object>> iterator = resultList.iterator();
+			Map<String, Object> map = null;
+			double sum = 0;
+			Object obj = null;
+			while ((map = iterator.next()) != null) {
+				obj = map.get(field.toUpperCase());
+				sum += obj == null ? 0 : Double.parseDouble(obj.toString());
+			}
+			return sum;
+		}
+		return 0;
+	}
+
+	public double getSummary(int index) {
+		if (index <= 0 || index > this.getKeys().size()) {
+			return 0;
+		}
+		return getSummary(this.keys.get(index - 1));
+	}
+}

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio