diff --git a/src/farm-core/.idea/workspace.xml b/src/farm-core/.idea/workspace.xml
new file mode 100644
index 0000000..81c36ee
--- /dev/null
+++ b/src/farm-core/.idea/workspace.xml
@@ -0,0 +1,75 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {
+ "associatedIndex": 2
+}
+
+
+
+
+
+ {
+ "keyToString": {
+ "Maven.farm-core [clean,install].executor": "Run",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "git-widget-placeholder": "master",
+ "kotlin-language-version-configured": "true",
+ "node.js.detected.package.eslint": "true",
+ "node.js.detected.package.tslint": "true",
+ "node.js.selected.package.eslint": "(autodetect)",
+ "node.js.selected.package.tslint": "(autodetect)",
+ "nodejs_package_manager_path": "npm",
+ "project.structure.last.edited": "模块",
+ "project.structure.proportion": "0.15",
+ "project.structure.side.proportion": "0.2",
+ "settings.editor.selected.configurable": "MavenSettings",
+ "vue.rearranger.settings.migration": "true"
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+ 1741954660473
+
+
+ 1741954660473
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/farm-core/pom.xml b/src/farm-core/pom.xml
new file mode 100644
index 0000000..852c37e
--- /dev/null
+++ b/src/farm-core/pom.xml
@@ -0,0 +1,135 @@
+
+ 4.0.0
+ com.farm
+ farm-core
+ jar
+ ${wcp.version}
+ 核心包
+
+ 3.2.0
+ 4.1.6.RELEASE
+
+ UTF-8
+ UTF-8
+
+ UTF-8
+
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+ net.sf.ehcache
+ ehcache
+ 2.10.4
+
+
+ org.springframework
+ spring-core
+ ${spring.version}
+
+
+ org.springframework
+ spring-web
+ ${spring.version}
+
+
+ org.springframework
+ spring-webmvc
+ ${spring.version}
+
+
+ org.springframework
+ spring-orm
+ ${spring.version}
+
+
+ org.springframework
+ spring-context
+ ${spring.version}
+
+
+ org.springframework
+ spring-tx
+ ${spring.version}
+
+
+ org.springframework
+ spring-aop
+ ${spring.version}
+
+
+ mysql
+ mysql-connector-java
+ 5.1.29
+
+
+ org.hibernate
+ hibernate-entitymanager
+ 4.3.8.Final
+
+
+ log4j
+ log4j
+ 1.2.17
+
+
+ com.sun.commons
+ beanutils
+ 1.6.1-20070314
+
+
+ commons-codec
+ commons-codec
+ 1.9
+
+
+ commons-lang
+ commons-lang
+ 2.6
+
+
+ commons-beanutils
+ commons-beanutils
+ 1.9.2
+
+
+ javax.servlet
+ servlet-api
+ 2.5
+
+
+ javax.servlet.jsp
+ jsp-api
+ 2.2.1-b03
+
+
+
+
+
+ maven-compiler-plugin
+
+ 1.7
+ 1.7
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.1
+
+
+
+ true
+ true
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/farm-core/src/main/java/com/farm/core/AuthorityService.java b/src/farm-core/src/main/java/com/farm/core/AuthorityService.java
new file mode 100644
index 0000000..fbb1367
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/AuthorityService.java
@@ -0,0 +1,92 @@
+package com.farm.core;
+
+import java.util.List;
+import java.util.Set;
+
+import com.farm.core.auth.domain.AuthKey;
+import com.farm.core.auth.domain.LoginUser;
+import com.farm.core.auth.domain.WebMenu;
+import com.farm.core.auth.exception.LoginUserNoExistException;
+
+/**
+ * 权限服务接口
+ *
+ * @author wangdong
+ * @version 2014-12
+ *
+ */
+public interface AuthorityService {
+
+ /**
+ * 验证用户是否合法
+ *
+ * @param loginName
+ * 用户登录名
+ * @param password
+ * 用户密码
+ * @return
+ */
+ public boolean isLegality(String loginName, String password)
+ throws LoginUserNoExistException;
+
+ /**
+ * 获得用户对象
+ *
+ * @param loginName
+ * @return
+ */
+ public LoginUser getUserByLoginName(String loginName);
+
+
+ /**获得用户岗位(用于工作流等应用中的对应KEY)
+ * @param userId
+ * @return
+ */
+ public List getUserPostKeys(String userId);
+
+ /**获得用户组织机构KEY
+ * @param userId
+ * @return
+ */
+ public String getUserOrgKey(String userId);
+
+ /**
+ * 获得用户对象
+ *
+ * @param userId
+ * @return
+ */
+ public LoginUser getUserById(String userId);
+
+ /**
+ * 获得用户权限关键字
+ *
+ * @param userId
+ * @return
+ */
+ public Set getUserAuthKeys(String userId);
+
+ /**
+ * 获得key对象(用于检查key权限)
+ *
+ * @param key
+ * @return
+ */
+ public AuthKey getAuthKey(String key);
+
+ /**
+ * 获得用户的菜单
+ *
+ * @param userId
+ * @return
+ */
+ public List getUserMenu(String userId);
+
+ /**
+ * 登录成功时会调用此方法
+ *
+ * @param userId
+ */
+ public void loginHandle(String userId);
+
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/Context.java b/src/farm-core/src/main/java/com/farm/core/Context.java
new file mode 100644
index 0000000..9ca4b5c
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/Context.java
@@ -0,0 +1,7 @@
+package com.farm.core;
+
+public class Context {
+ public static String MK;
+ public static String FK;
+ public static boolean FLAG;
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/FarmUtils.java b/src/farm-core/src/main/java/com/farm/core/FarmUtils.java
new file mode 100644
index 0000000..e532547
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/FarmUtils.java
@@ -0,0 +1,96 @@
+package com.farm.core;
+
+import com.farm.core.auth.util.AuthenticateInter;
+import com.farm.core.auth.util.AuthenticateProvider;
+import com.farm.core.config.PropertiesUtils;
+import com.farm.core.time.TimeTool;
+import com.farm.util.validate.ValidUtils;
+import com.farm.util.web.FarmFormatUnits;
+import com.farm.util.web.FarmproHotnum;
+import com.farm.util.web.WebHotCase;
+import com.farm.util.web.WebVisitBuff;
+
+/**
+ * 平台工具类入口
+ *
+ * @author wangdong
+ *
+ */
+public class FarmUtils {
+ /**获得验证类工具
+ * @return
+ */
+ public static ValidUtils getValidUtils() {
+ return new ValidUtils();
+ }
+
+ /**
+ * 获得加解密类工具
+ *
+ * @return
+ */
+ public static AuthenticateInter getAuthUtils() {
+ return AuthenticateProvider.getInstance();
+ }
+
+ /**
+ * 获得Properties文件工具
+ *
+ * @param fileName
+ * 如jdbc.properties
+ * @return
+ */
+ public static PropertiesUtils getPropertiesUtils(String fileName) {
+ return new PropertiesUtils(fileName);
+ }
+
+ /**
+ * 获得时间类工具
+ *
+ * @return
+ */
+ public static TimeTool getTimeTools() {
+ return new TimeTool();
+ }
+
+ /**
+ * 获得格式化工具(友好的时间格式化,文件大小格式化)
+ *
+ * @return
+ */
+ public static FarmFormatUnits getFormatUtils() {
+ return new FarmFormatUnits();
+ }
+
+ /**
+ * 访问热度计算工具
+ *
+ * @return
+ */
+ public static FarmproHotnum getHotUtils() {
+ return new FarmproHotnum();
+ }
+
+ /**
+ * 计算热词(如搜索关键字的统计)
+ *
+ * @return
+ */
+ public static WebHotCase getHotWordUtils() {
+ return new WebHotCase();
+ }
+
+ /**
+ * 判断用户在一定时间内是否访问的工具,用来计算一个KEY在一定时间内是否已经被标记(如控制相同用户不重复计算文章的访问量)
+ *
+ * @param domain
+ * 统计域,不同域被分隔开控制(相互间不受影响)
+ * @param maxNum
+ * 每个域中允许缓存的key数据量(超出后域被刷新)
+ * @return
+ */
+ public static WebVisitBuff getWebVisitBuff(String domain, int maxNum) {
+ return WebVisitBuff.getInstance(domain, maxNum);
+ }
+
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/LogService.java b/src/farm-core/src/main/java/com/farm/core/LogService.java
new file mode 100644
index 0000000..ee0d5f4
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/LogService.java
@@ -0,0 +1,31 @@
+package com.farm.core;
+
+/**
+ * 参数服务接口
+ *
+ * @author wangdong
+ * @version 2014-12
+ *
+ */
+public interface LogService {
+
+ /**
+ * 记录日志
+ *
+ * @param message
+ * 信息
+ * @param loginUserId
+ * 用户id
+ * @param level
+ * 日志级别
+ * @param methodName
+ * 程序方法名称
+ * @param className
+ * 程序类名
+ * @param ip
+ * 用户IP
+ */
+ public void log(String info, String loginUserId, String level,
+ String methodName, String className, String ip);
+
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/ParameterService.java b/src/farm-core/src/main/java/com/farm/core/ParameterService.java
new file mode 100644
index 0000000..b55d609
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/ParameterService.java
@@ -0,0 +1,55 @@
+package com.farm.core;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * 参数服务接口
+ *
+ * @author wangdong
+ * @version 2014-12
+ *
+ */
+public interface ParameterService {
+
+ /**
+ * 获得系统参数值(可以获得系统中各种参数:如系统参数、properties参数、系统常量)
+ *
+ * @return
+ */
+ public String getParameter(String key);
+
+ /**
+ * 获得系统参数值(可以获得系统中各种参数:如用户个性化参数、系统参数、properties参数、系统常量)
+ *
+ * @return
+ */
+ public String getParameter(String key, String userId);
+
+ /**
+ * 获得字典列表
+ *
+ * @param index
+ * @return
+ */
+ public List> getDictionaryList(String index);
+
+ /**
+ * 获得字典
+ *
+ * @param key
+ * @return
+ */
+ public Map getDictionary(String key);
+
+ public int getParameterInt(String string);
+
+ /**
+ * 获得系统参数值(可以获得系统中各种参数:如系统参数、properties参数、系统常量)
+ *
+ * @param string
+ * @return
+ */
+ public boolean getParameterBoolean(String key);
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/SequenceService.java b/src/farm-core/src/main/java/com/farm/core/SequenceService.java
new file mode 100644
index 0000000..2fb0f45
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/SequenceService.java
@@ -0,0 +1,113 @@
+package com.farm.core;
+
+import java.net.NetworkInterface;
+import java.util.Enumeration;
+
+import com.farm.core.auth.util.MD5;
+
+/**
+ * 机器码生成的通用服务
+ *
+ * @author 杨尚川
+ */
+public class SequenceService {
+ /**
+ * 对一段String生成MD5摘要信息
+ *
+ * @param message
+ * 要摘要的String
+ * @return 生成的MD5摘要信息
+ */
+ protected static String getMD5(String message) {
+ String md5 = new MD5().getMD5ofStr(message);
+ return getSplitString(md5);
+ }
+
+ public static String InitKey() {
+ return getMD5(getSigarSequence());
+ }
+
+ /**
+ * 将很长的字符串以固定的位数分割开,以便于人类阅读
+ *
+ * @param str
+ * @return
+ */
+ protected static String getSplitString(String str) {
+
+ return getSplitString(str.substring(0, 16), "-", 4);
+ }
+
+ /**
+ * 将很长的字符串以固定的位数分割开,以便于人类阅读 如将 71F5DA7F495E7F706D47F3E63DC6349A
+ * 以-,每4个一组,则分割为 71F5-DA7F-495E-7F70-6D47-F3E6-3DC6-349A
+ *
+ * @param str
+ * 字符串
+ * @param split
+ * 分隔符
+ * @param length
+ * 长度
+ * @return
+ */
+ protected static String getSplitString(String str, String split, int length) {
+ int len = str.length();
+ StringBuilder temp = new StringBuilder();
+ for (int i = 0; i < len; i++) {
+ if (i % length == 0 && i > 0) {
+ temp.append(split);
+ }
+ temp.append(str.charAt(i));
+ }
+ String[] attrs = temp.toString().split(split);
+ StringBuilder finalMachineCode = new StringBuilder();
+ for (String attr : attrs) {
+ if (attr.length() == length) {
+ finalMachineCode.append(attr).append(split);
+ }
+ }
+ String result = finalMachineCode.toString().substring(0, finalMachineCode.toString().length() - 1);
+ return result;
+ }
+
+ /**
+ * 利用sigar来生成机器码,当然这个实现不是很好,无法获得CPU ID,希望有兴趣的朋友来改进这个实现
+ *
+ * @param osName
+ * 操作系统类型
+ * @return 机器码
+ */
+ protected static String getSigarSequence() {
+ return "asdf";
+ }
+ /**
+ * 按照"XX-XX-XX-XX-XX-XX"格式,获取本机MAC地址
+ * @return
+ * @throws Exception
+ */
+ public static String getMacAddress() throws Exception{
+ Enumeration ni = NetworkInterface.getNetworkInterfaces();
+
+ while(ni.hasMoreElements()){
+ NetworkInterface netI = ni.nextElement();
+
+ byte[] bytes = netI.getHardwareAddress();
+ if(netI.isUp() && netI != null && bytes != null && bytes.length == 6){
+ StringBuffer sb = new StringBuffer();
+ for(byte b:bytes){
+ //与11110000作按位与运算以便读取当前字节高4位
+ sb.append(Integer.toHexString((b&240)>>4));
+ //与00001111作按位与运算以便读取当前字节低4位
+ sb.append(Integer.toHexString(b&15));
+ sb.append("-");
+ }
+ sb.deleteCharAt(sb.length()-1);
+ return sb.toString().toUpperCase();
+ }
+ }
+ return null;
+ }
+ public static void main(String[] args) {
+ System.out.println(SequenceService.InitKey());
+ }
+}
\ No newline at end of file
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/domain/AuthKey.java b/src/farm-core/src/main/java/com/farm/core/auth/domain/AuthKey.java
new file mode 100644
index 0000000..45229bc
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/domain/AuthKey.java
@@ -0,0 +1,31 @@
+package com.farm.core.auth.domain;
+
+public interface AuthKey {
+ /**
+ * 是否需要用户登录使用
+ *
+ * @return
+ */
+ public boolean isLogin();
+
+ /**
+ * 是否需要检查用户权限
+ *
+ * @return
+ */
+ public boolean isCheck();
+
+ /**
+ * 是否可用
+ *
+ * @return
+ */
+ public boolean isUseAble();
+
+ /**
+ * 获得名称
+ *
+ * @return
+ */
+ public String getTitle();
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/domain/LoginUser.java b/src/farm-core/src/main/java/com/farm/core/auth/domain/LoginUser.java
new file mode 100644
index 0000000..80511af
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/domain/LoginUser.java
@@ -0,0 +1,11 @@
+package com.farm.core.auth.domain;
+
+public interface LoginUser {
+
+ public String getId();
+
+ public String getName();
+
+ public String getLoginname();
+
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/domain/WebMenu.java b/src/farm-core/src/main/java/com/farm/core/auth/domain/WebMenu.java
new file mode 100644
index 0000000..78ad95f
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/domain/WebMenu.java
@@ -0,0 +1,15 @@
+package com.farm.core.auth.domain;
+
+public interface WebMenu {
+ public String getParams();
+
+ public String getIcon();
+
+ public String getUrl();
+
+ public String getName();
+
+ public String getParentid();
+
+ public String getId();
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/exception/LoginUserNoExistException.java b/src/farm-core/src/main/java/com/farm/core/auth/exception/LoginUserNoExistException.java
new file mode 100644
index 0000000..0a04325
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/exception/LoginUserNoExistException.java
@@ -0,0 +1,12 @@
+package com.farm.core.auth.exception;
+
+public class LoginUserNoExistException extends Exception {
+ public LoginUserNoExistException(String message) {
+ super(message);
+ }
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6482296763929242398L;
+
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/impl/AuthTestImpl.java b/src/farm-core/src/main/java/com/farm/core/auth/impl/AuthTestImpl.java
new file mode 100644
index 0000000..250fb5e
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/impl/AuthTestImpl.java
@@ -0,0 +1,145 @@
+package com.farm.core.auth.impl; // 定义包名,表示该类位于 com.farm.core.auth.impl 包中
+
+import java.util.ArrayList; // 导入 ArrayList 类
+import java.util.HashSet; // 导入 HashSet 类
+import java.util.List; // 导入 List 接口
+import java.util.Set; // 导入 Set 接口
+
+import org.springframework.stereotype.Service; // 导入 Spring 的 @Service 注解
+
+import com.farm.core.AuthorityService; // 导入 AuthorityService 接口
+import com.farm.core.auth.domain.AuthKey; // 导入 AuthKey 类
+import com.farm.core.auth.domain.LoginUser; // 导入 LoginUser 类
+import com.farm.core.auth.domain.WebMenu; // 导入 WebMenu 类
+import com.farm.core.auth.exception.LoginUserNoExistException; // 导入 LoginUserNoExistException 异常类
+package com.example.versionmanagement;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+
+//启动类
+package com.example.versionmanagement;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class VersionManagementApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(VersionManagementApplication.class, args);
+ }
+}
+@Service // 标注该类为 Spring 的服务组件
+public class AuthTestImpl implements AuthorityService { // 定义 AuthTestImpl 类,实现 AuthorityService 接口
+
+ @Override // 重写 AuthorityService 接口中的 loginHandle 方法
+ public void loginHandle(String userId) {
+ System.out.println("登录成功"); // 打印登录成功信息
+ }
+
+ @Override // 重写 AuthorityService 接口中的 getUserAuthKeys 方法
+ public Set getUserAuthKeys(String userId) {
+ Set map = new HashSet(); // 创建一个 HashSet 对象
+ map.add("AUTHKEY"); // 向集合中添加一个权限键
+ return map; // 返回包含权限键的集合
+ }
+
+ @Override // 重写 AuthorityService 接口中的 getUserById 方法
+ public LoginUser getUserById(String userId) {
+ // 创建一个匿名内部类实现 LoginUser 接口
+ LoginUser user = new LoginUser() {
+ @Override // 重写 getName 方法
+ public String getName() {
+ return "userName"; // 返回用户名
+ }
+
+ @Override // 重写 getLoginname 方法
+ public String getLoginname() {
+ return "loginName"; // 返回登录名
+ }
+
+ @Override // 重写 getId 方法
+ public String getId() {
+ return "userId"; // 返回用户ID
+ }
+ };
+ return user; // 返回创建的 LoginUser 对象
+ }
+
+ @Override // 重写 AuthorityService 接口中的 getUserByLoginName 方法
+ public LoginUser getUserByLoginName(String loginName) {
+ // 创建一个匿名内部类实现 LoginUser 接口
+ LoginUser user = new LoginUser() {
+ @Override // 重写 getName 方法
+ public String getName() {
+ return "userName"; // 返回用户名
+ }
+
+ @Override // 重写 getLoginname 方法
+ public String getLoginname() {
+ return "loginName"; // 返回登录名
+ }
+
+ @Override // 重写 getId 方法
+ public String getId() {
+ return "userId"; // 返回用户ID
+ }
+ };
+ return user; // 返回创建的 LoginUser 对象
+ }
+
+ @Override // 重写 AuthorityService 接口中的 getUserMenu 方法
+ public List getUserMenu(String userId) {
+ List list = new ArrayList(); // 创建一个 ArrayList 对象
+ return list; // 返回用户菜单列表
+ }
+
+ @Override // 重写 AuthorityService 接口中的 isLegality 方法
+ public boolean isLegality(String loginName, String password)
+ throws LoginUserNoExistException {
+ return true; // 返回 true,表示用户名和密码合法
+ }
+
+ @Override // 重写 AuthorityService 接口中的 getAuthKey 方法
+ public AuthKey getAuthKey(String key) {
+ // 创建一个匿名内部类实现 AuthKey 接口
+ return new AuthKey() {
+ @Override // 重写 isLogin 方法
+ public boolean isLogin() {
+ return false; // 返回 false,表示未登录
+ }
+
+ @Override // 重写 isCheck 方法
+ public boolean isCheck() {
+ return false; // 返回 false,表示未检查
+ }
+
+ @Override // 重写 isUseAble 方法
+ public boolean isUseAble() {
+ return true; // 返回 true,表示可用
+ }
+
+ @Override // 重写 getTitle 方法
+ public String getTitle() {
+ return "权限名称(测试)"; // 返回权限标题
+ }
+ };
+ }
+
+ @Override // 重写 AuthorityService 接口中的 getUserPostKeys 方法
+ public List getUserPostKeys(String userId) {
+ List list = new ArrayList(); // 创建一个 ArrayList 对象
+ list.add("POSTID"); // 向列表中添加一个岗位ID
+ return list; // 返回用户岗位键列表
+ }
+
+ @Override // 重写 AuthorityService 接口中的 getUserOrgKey 方法
+ public String getUserOrgKey(String userId) {
+ return "ORGID"; // 返回用户组织键
+ }
+
+} // AuthTestImpl 类结束
+
+
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/impl/VersionController.java b/src/farm-core/src/main/java/com/farm/core/auth/impl/VersionController.java
new file mode 100644
index 0000000..a792d04
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/impl/VersionController.java
@@ -0,0 +1,29 @@
+package com.example.versionmanagement;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 版本控制器类,用于处理与版本信息相关的HTTP请求。
+ */
+@RestController
+public class VersionController {
+
+ /**
+ * 自动注入版本信息对象,该对象包含了版本相关的数据。
+ */
+ @Autowired
+ private VersionInfo versionInfo;
+
+ /**
+ * 处理GET请求,返回版本信息。
+ * 当访问"/version"端点时,此方法将被调用。
+ *
+ * @return VersionInfo 返回包含版本信息的对象。
+ */
+ @GetMapping("/version")
+ public VersionInfo getVersionInfo() {
+ return versionInfo;
+ }
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/impl/VersionInfo.java b/src/farm-core/src/main/java/com/farm/core/auth/impl/VersionInfo.java
new file mode 100644
index 0000000..8334782
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/impl/VersionInfo.java
@@ -0,0 +1,33 @@
+//创建一个类来存储版本信息
+@Configuration
+@ConfigurationProperties(prefix = "app.version")
+public class VersionInfo {
+ private String name;
+ private String version;
+ private String description;
+
+ // getters and setters
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+}
\ No newline at end of file
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.gitignore b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.gitignore
new file mode 100644
index 0000000..5ff6309
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.gitignore
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
\ No newline at end of file
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.idea/.gitignore b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.idea/.gitignore
new file mode 100644
index 0000000..35410ca
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.idea/.gitignore
@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.idea/dataSources.xml b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.idea/dataSources.xml
new file mode 100644
index 0000000..08036ef
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.idea/dataSources.xml
@@ -0,0 +1,17 @@
+
+
+
+
+ mysql_aurora_aws
+ true
+ software.aws.rds.jdbc.mysql.Driver
+ jdbc:mysql:aws://localhost:3306
+
+
+
+
+
+ $ProjectFileDir$
+
+
+
\ No newline at end of file
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.idea/encodings.xml b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.idea/encodings.xml
new file mode 100644
index 0000000..aa00ffa
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.idea/encodings.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.idea/misc.xml b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.idea/misc.xml
new file mode 100644
index 0000000..132404b
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.idea/sqldialects.xml b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.idea/sqldialects.xml
new file mode 100644
index 0000000..9cb6728
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.idea/sqldialects.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.idea/uiDesigner.xml b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/lib/mysql-connector-java-5.1.48.jar b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/lib/mysql-connector-java-5.1.48.jar
new file mode 100644
index 0000000..bd1c4bb
Binary files /dev/null and b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/lib/mysql-connector-java-5.1.48.jar differ
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/pom.xml b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/pom.xml
new file mode 100644
index 0000000..c65f009
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/pom.xml
@@ -0,0 +1,67 @@
+
+ 4.0.0
+ com.maven_javaprogram
+ mybatis_demo
+ war
+ 1.0-SNAPSHOT
+ mybatis_demo Maven Webapp
+ http://maven.apache.org
+
+
+ junit
+ junit
+ 3.8.1
+ provided
+
+
+
+ org.mybatis
+ mybatis
+ 3.5.5
+
+
+
+ mysql
+ mysql-connector-java
+ 5.1.48
+
+
+ org.junit.jupiter
+ junit-jupiter
+ RELEASE
+ compile
+
+
+
+
+ mybatis_demo
+
+
+ src/main/resources
+
+ **/*.xml
+ **/*.properties
+
+
+
+
+
+
+ true
+
+
+ src/main/java
+
+ **/*.properties
+ **/*.xml
+
+
+
+
+
+
+
+
+
+
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/java/com/kuang/dao/UseMapper.java b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/java/com/kuang/dao/UseMapper.java
new file mode 100644
index 0000000..60eae55
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/java/com/kuang/dao/UseMapper.java
@@ -0,0 +1,17 @@
+package com.kuang.dao;
+
+import com.kuang.pojo.User;
+
+import java.util.List;
+import java.util.Map;
+
+public interface UseMapper {
+ List getUserList();
+ int addUser(User user);
+ User selectId(int a);
+ int updateUser();
+ int deleteUser(int i);
+ int insertUserByMap(Map map);
+ List likeSelectUser(String a);
+}
+
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/java/com/kuang/mybatisUtils/mybatisUtils.java b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/java/com/kuang/mybatisUtils/mybatisUtils.java
new file mode 100644
index 0000000..b364762
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/java/com/kuang/mybatisUtils/mybatisUtils.java
@@ -0,0 +1,28 @@
+package com.kuang.mybatisUtils;
+
+import org.apache.ibatis.io.Resources;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class mybatisUtils {
+ private static SqlSessionFactory sqlSessionFactory;
+ static{
+ String resource = "mybatis-config.xml";
+ InputStream inputStream;
+ {
+ try {
+ inputStream = Resources.getResourceAsStream(resource);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
+ }
+ public static SqlSession getSqlSession(){
+ return sqlSessionFactory.openSession();
+ }
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/java/com/kuang/pojo/User.java b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/java/com/kuang/pojo/User.java
new file mode 100644
index 0000000..6328292
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/java/com/kuang/pojo/User.java
@@ -0,0 +1,46 @@
+package com.kuang.pojo;
+
+import org.apache.ibatis.type.Alias;
+
+@Alias("user")
+public class User {
+ private int id;
+ private String name;
+ private int numId;
+ public User(int id, String name, int numId) {
+ this.id = id;
+ this.name = name;
+ this.numId = numId;
+ }
+ public int getNumId() {
+ return numId;
+ }
+
+ public void setNumId(int numId) {
+ this.numId = numId;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return "com.kuang.pojo.User{" +
+ "id=" + id +
+ ", name='" + name+", " +"numId"+numId+
+ '}';
+ }
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/java/com/kuang/test/mybatisDemo.java b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/java/com/kuang/test/mybatisDemo.java
new file mode 100644
index 0000000..9f4eef9
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/java/com/kuang/test/mybatisDemo.java
@@ -0,0 +1,100 @@
+package com.kuang.test;
+
+import com.kuang.dao.UseMapper;
+import com.kuang.mybatisUtils.mybatisUtils;
+import com.kuang.pojo.User;
+import org.apache.ibatis.session.SqlSession;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.List;
+
+public class mybatisDemo {
+ @Test
+ public void test() {
+ SqlSession sqlSession = mybatisUtils.getSqlSession();
+ UseMapper mapper = sqlSession.getMapper(UseMapper.class);
+ List userList = mapper.getUserList();
+ for (User user : userList) {
+ System.out.println(user);
+ }
+ sqlSession.close();
+ }
+ @Test
+ public void test1(){
+ SqlSession sqlSession = mybatisUtils.getSqlSession();
+ UseMapper mapper = sqlSession.getMapper(UseMapper.class);
+ int i = mapper.addUser(new User(5,"quqiCake",5));
+ if(i>0){
+ System.out.println("参数加入成功");
+ sqlSession.commit();
+ }else{
+ System.out.println("加入失败");
+ }
+ sqlSession.close();
+
+ }
+ @Test
+ public void test2(){
+ SqlSession sqlSession = mybatisUtils.getSqlSession();
+ UseMapper mapper = sqlSession.getMapper(UseMapper.class);
+ User user = mapper.selectId(1);
+ System.out.println(user);
+ }
+ @Test
+ public void test3(){
+ SqlSession sqlSession = mybatisUtils.getSqlSession();
+ UseMapper mapper = sqlSession.getMapper(UseMapper.class);
+ int a = mapper.updateUser();
+ if(a>0){
+ System.out.println("提交成功");
+ sqlSession.commit();
+ }
+ sqlSession.close();
+ }
+ @Test
+ public void test4(){
+ SqlSession sqlSession = mybatisUtils.getSqlSession();
+ UseMapper mapper = sqlSession.getMapper(UseMapper.class);
+ int a = mapper.deleteUser(5);
+ if(a>0){
+ System.out.println("删除成功");
+ sqlSession.commit();
+ }
+ sqlSession.close();
+ }
+ @Test
+ public void test5(){
+ SqlSession sqlSession = mybatisUtils.getSqlSession();
+ UseMapper mapper = sqlSession.getMapper(UseMapper.class);
+ HashMap map = new HashMap<>();
+ map.put("id",5);
+ map.put("name","quqiCake");
+ map.put("numId",5);
+ int a = mapper.insertUserByMap(map);
+ if(a>0){
+ System.out.println("添加成功");
+ sqlSession.commit();
+ }
+
+ }
+ @Test
+ public void test6(){
+ SqlSession sqlSession = mybatisUtils.getSqlSession();
+ //获得sql
+ UseMapper mapper = sqlSession.getMapper(UseMapper.class);
+ List users = mapper.likeSelectUser("h%");
+ for (User user : users) {
+ System.out.println(user);
+ }
+ }
+ @Test
+ public void test7(){
+ SqlSession sqlSession = mybatisUtils.getSqlSession();
+ //获得sql 参数是一个映射的语句
+ String s="com.kuang.dao.UseMapper.selectId";
+ List objects = sqlSession.selectList(s);
+ System.out.println(objects);
+ }
+
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/resources/UserMapper.xml b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/resources/UserMapper.xml
new file mode 100644
index 0000000..c3bb61e
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/resources/UserMapper.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ insert into cakeinfo.cakeinfo(id, name, numId) value (#{id},#{name},#{numId});
+
+
+
+ update cakeinfo.cakeinfo set name='xiaoqiqu' where id=5;
+
+
+ delete from cakeinfo.cakeinfo where id=#{id};
+
+
+ insert into cakeinfo.cakeinfo (id, name, numId)
+ values (#{id},#{name},#{numId});
+
+
+
\ No newline at end of file
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/resources/mybatis-config.xml b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/resources/mybatis-config.xml
new file mode 100644
index 0000000..c322acc
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/resources/mybatis-config.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/webapp/WEB-INF/web.xml b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..9f88c1f
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,7 @@
+
+
+
+ Archetype Created Web Application
+
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/webapp/index.jsp b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/webapp/index.jsp
new file mode 100644
index 0000000..c38169b
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/impl/mybatis_demo/src/main/webapp/index.jsp
@@ -0,0 +1,5 @@
+
+
+Hello World!
+
+
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/util/AuthenticateInter.java b/src/farm-core/src/main/java/com/farm/core/auth/util/AuthenticateInter.java
new file mode 100644
index 0000000..20998f9
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/util/AuthenticateInter.java
@@ -0,0 +1,54 @@
+package com.farm.core.auth.util;
+
+/**
+ * 密码编码解码类
+ *
+ * @author 王东
+ *
+ */
+public interface AuthenticateInter {
+ /**
+ * 将明文加密
+ *
+ * @param password
+ * 传人明文
+ * @return
+ */
+ public String encodeMacpro(String password);
+
+ /**
+ * 将密文解密
+ *
+ * @param password
+ * 传人密文
+ * @return
+ * @throws Exception
+ * 解码异常
+ */
+ public String decodeMacpro(String password) throws Exception;
+
+ /**
+ * md5不可逆的编码
+ *
+ * @param password
+ * 传人明文
+ * @return
+ */
+ public String encodeMd5(String password);
+
+ /**
+ * 判断是否是MD5密码
+ *
+ * @param password
+ * @return
+ */
+ public boolean isMd5code(String password);
+
+ /**
+ * 加密用户密码MD5(password+loginname)
+ *
+ * @param password
+ * @return
+ */
+ public String encodeLoginPasswordOnMd5(String password, String loginName);
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/util/AuthenticateProvider.java b/src/farm-core/src/main/java/com/farm/core/auth/util/AuthenticateProvider.java
new file mode 100644
index 0000000..b98e697
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/util/AuthenticateProvider.java
@@ -0,0 +1,50 @@
+package com.farm.core.auth.util; // 定义包名,表示该类位于 com.farm.core.auth.util 包中
+
+import org.apache.commons.codec.binary.Base64; // 导入 Apache Commons Codec 库的 Base64 类用于编码和解码
+
+public class AuthenticateProvider implements AuthenticateInter { // 定义 AuthenticateProvider 类,实现 AuthenticateInter 接口
+
+ private AuthenticateProvider() { // 私有构造函数,防止外部直接创建实例
+ }
+
+ public static AuthenticateInter getInstance() { // 提供一个公有的静态方法获取实例,实现单例模式
+ return new AuthenticateProvider();
+ }
+
+ public String decodeMacpro(String password) throws Exception { // 解码 Macpro 密码
+ byte[] fpass = Base64.decodeBase64(password.getBytes()); // 使用 Base64 解码密码字符串
+ String str = new String(fpass); // 将解码后的字节数组转换为字符串
+ return str; // 返回解码后的字符串
+ }
+
+ public String encodeMacpro(String password) { // 编码 Macpro 密码
+ byte[] cpass = Base64.encodeBase64(password.getBytes()); // 使用 Base64 编码密码字符串
+ String temp = new String(cpass); // 将编码后的字节数组转换为字符串
+ return temp; // 返回编码后的字符串
+ }
+
+ @Override // 重写接口中的 encodeMd5 方法
+ public String encodeMd5(String password) { // 对密码进行 MD5 编码
+ if (this.isMd5code(password)) { // 如果密码已经是 MD5 编码,直接返回
+ return password;
+ } else { // 否则,使用 MD5 算法对密码进行编码
+ return new MD5().getMD5ofStr(password);
+ }
+ }
+
+ @Override // 重写接口中的 isMd5code 方法
+ public boolean isMd5code(String password) { // 检查字符串是否为 MD5 编码
+ if (password.trim().length() == 32) // MD5 编码的长度为 32 位
+ return true; // 如果长度为 32,认为是 MD5 编码
+ else
+ return false; // 否则,不是 MD5 编码
+ }
+
+ @Override // 重写接口中的 encodeLoginPasswordOnMd5 方法
+ public String encodeLoginPasswordOnMd5(String password, String loginName) { // 根据密码和登录名生成 MD5 编码的登录密码
+ return encodeMd5(password + loginName); // 将密码和登录名拼接后进行 MD5 编码
+ }
+} // AuthenticateProvider 类结束
+
+// 注意:代码中的 MD5 类没有在当前代码片段中定义,应该是在其他地方定义的。此外,单例模式的实现方式较为简单,没有考虑线程安全问题。
+
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/util/KeyUtil.java b/src/farm-core/src/main/java/com/farm/core/auth/util/KeyUtil.java
new file mode 100644
index 0000000..f2f607d
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/util/KeyUtil.java
@@ -0,0 +1,22 @@
+package com.farm.core.auth.util; // 定义包名,表示该类位于 com.farm.core.auth.util 包中
+
+public class KeyUtil { // 定义 KeyUtil 类,用于处理与密钥相关的工具方法
+
+ @SuppressWarnings("unused") // 抑制未使用变量的警告
+ private static String errorkey = "ERROR"; // 定义一个静态变量,用于表示错误密钥,但目前未使用
+
+ @SuppressWarnings("unused") // 抑制未使用变量的警告
+ private static String CODE_C = "SADFSEV"; // 定义一个静态变量,可能用于编码或加密的常量,但目前未使用
+
+ public static String getFkey(String mkey) { // 定义一个公共静态方法,用于获取某种密钥
+ return "NONE"; // 目前该方法直接返回 "NONE",表示没有有效的密钥
+ }
+
+ public static String getMKey() { // 定义一个公共静态方法,用于获取主密钥
+ return "NONE"; // 目前该方法直接返回 "NONE",表示没有有效的主密钥
+ }
+
+} // KeyUtil 类结束
+
+// 注意:这个类中的方法目前只是返回了 "NONE",这可能是一个占位符或者表示某种默认行为。实际应用中,这些方法应该被实现为返回有效的密钥值。同时,类中定义了两个未使用的静态变量,可能是在未来版本中会使用到。
+
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/util/MD5.java b/src/farm-core/src/main/java/com/farm/core/auth/util/MD5.java
new file mode 100644
index 0000000..46228d3
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/util/MD5.java
@@ -0,0 +1,358 @@
+package com.farm.core.auth.util;
+
+/*************************************************
+md5 类实现了RSA Data Security, Inc.在提交给IETF
+的RFC1321中的MD5 message-digest 算法。
+*************************************************/
+
+public class MD5 {
+ /* 下面这些S11-S44实际上是一个4*4的矩阵,在原始的C实现中是用#define 实现的,
+ 这里把它们实现成为static final是表示了只读,切能在同一个进程空间内的多个
+ Instance间共享*/
+ static final int S11 = 7;
+ static final int S12 = 12;
+ static final int S13 = 17;
+ static final int S14 = 22;
+
+ static final int S21 = 5;
+ static final int S22 = 9;
+ static final int S23 = 14;
+ static final int S24 = 20;
+
+ static final int S31 = 4;
+ static final int S32 = 11;
+ static final int S33 = 16;
+ static final int S34 = 23;
+
+ static final int S41 = 6;
+ static final int S42 = 10;
+ static final int S43 = 15;
+ static final int S44 = 21;
+
+ static final byte[] PADDING = { -128, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ /* 下面的三个成员是MD5计算过程中用到的3个核心数据,在原始的C实现中
+ 被定义到MD5_CTX结构中
+
+ */
+ private long[] state = new long[4]; // state (ABCD)
+ private long[] count = new long[2]; // number of bits, modulo 2^64 (lsb first)
+ private byte[] buffer = new byte[64]; // input buffer
+
+ /* digestHexStr是MD5的唯一一个公共成员,是最新一次计算结果的
+ 16进制ASCII表示.
+ */
+ public String digestHexStr;
+
+ /* digest,是最新一次计算结果的2进制内部表示,表示128bit的MD5值.
+ */
+ private byte[] digest = new byte[16];
+
+ /*
+ getMD5ofStr是类MD5最主要的公共方法,入口参数是你想要进行MD5变换的字符串
+ 返回的是变换完的结果,这个结果是从公共成员digestHexStr取得的.
+ */
+ public String getMD5ofStr(String inbuf) {
+ md5Init();
+ md5Update(inbuf.getBytes(), inbuf.length());
+ md5Final();
+ digestHexStr = "";
+ for (int i = 0; i < 16; i++) {
+ digestHexStr += byteHEX(digest[i]);
+ }
+ return digestHexStr;
+
+ }
+ // 这是MD5这个类的标准构造函数,JavaBean要求有一个public的并且没有参数的构造函数
+ public MD5() {
+ md5Init();
+
+ return;
+ }
+
+
+
+ /* md5Init是一个初始化函数,初始化核心变量,装入标准的幻数 */
+ private void md5Init() {
+ count[0] = 0L;
+ count[1] = 0L;
+ ///* Load magic initialization constants.
+
+ state[0] = 0x67452301L;
+ state[1] = 0xefcdab89L;
+ state[2] = 0x98badcfeL;
+ state[3] = 0x10325476L;
+
+ return;
+ }
+ /* F, G, H ,I 是4个基本的MD5函数,在原始的MD5的C实现中,由于它们是
+ 简单的位运算,可能出于效率的考虑把它们实现成了宏,在java中,我们把它们
+ 实现成了private方法,名字保持了原来C中的。 */
+
+ private long F(long x, long y, long z) {
+ return (x & y) | ((~x) & z);
+
+ }
+ private long G(long x, long y, long z) {
+ return (x & z) | (y & (~z));
+
+ }
+ private long H(long x, long y, long z) {
+ return x ^ y ^ z;
+ }
+
+ private long I(long x, long y, long z) {
+ return y ^ (x | (~z));
+ }
+
+ /*
+ FF,GG,HH和II将调用F,G,H,I进行近一步变换
+ FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
+ Rotation is separate from addition to prevent recomputation.
+ */
+
+ private long FF(long a, long b, long c, long d, long x, long s,
+ long ac) {
+ a += F (b, c, d) + x + ac;
+ a = ((int) a << s) | ((int) a >>> (32 - s));
+ a += b;
+ return a;
+ }
+
+ private long GG(long a, long b, long c, long d, long x, long s,
+ long ac) {
+ a += G (b, c, d) + x + ac;
+ a = ((int) a << s) | ((int) a >>> (32 - s));
+ a += b;
+ return a;
+ }
+ private long HH(long a, long b, long c, long d, long x, long s,
+ long ac) {
+ a += H (b, c, d) + x + ac;
+ a = ((int) a << s) | ((int) a >>> (32 - s));
+ a += b;
+ return a;
+ }
+ private long II(long a, long b, long c, long d, long x, long s,
+ long ac) {
+ a += I (b, c, d) + x + ac;
+ a = ((int) a << s) | ((int) a >>> (32 - s));
+ a += b;
+ return a;
+ }
+ /*
+ md5Update是MD5的主计算过程,inbuf是要变换的字节串,inputlen是长度,这个
+ 函数由getMD5ofStr调用,调用之前需要调用md5init,因此把它设计成private的
+ */
+ private void md5Update(byte[] inbuf, int inputLen) {
+
+ int i, index, partLen;
+ byte[] block = new byte[64];
+ index = (int)(count[0] >>> 3) & 0x3F;
+ // /* Update number of bits */
+ if ((count[0] += (inputLen << 3)) < (inputLen << 3))
+ count[1]++;
+ count[1] += (inputLen >>> 29);
+
+ partLen = 64 - index;
+
+ // Transform as many times as possible.
+ if (inputLen >= partLen) {
+ md5Memcpy(buffer, inbuf, index, 0, partLen);
+ md5Transform(buffer);
+
+ for (i = partLen; i + 63 < inputLen; i += 64) {
+
+ md5Memcpy(block, inbuf, 0, i, 64);
+ md5Transform (block);
+ }
+ index = 0;
+
+ } else
+
+ i = 0;
+
+ ///* Buffer remaining input */
+ md5Memcpy(buffer, inbuf, index, i, inputLen - i);
+
+ }
+
+ /*
+ md5Final整理和填写输出结果
+ */
+ private void md5Final () {
+ byte[] bits = new byte[8];
+ int index, padLen;
+
+ ///* Save number of bits */
+ Encode (bits, count, 8);
+
+ ///* Pad out to 56 mod 64.
+ index = (int)(count[0] >>> 3) & 0x3f;
+ padLen = (index < 56) ? (56 - index) : (120 - index);
+ md5Update (PADDING, padLen);
+
+ ///* Append length (before padding) */
+ md5Update(bits, 8);
+
+ ///* Store state in digest */
+ Encode (digest, state, 16);
+
+ }
+
+ /* md5Memcpy是一个内部使用的byte数组的块拷贝函数,从input的inpos开始把len长度的
+ 字节拷贝到output的outpos位置开始
+ */
+
+ private void md5Memcpy (byte[] output, byte[] input,
+ int outpos, int inpos, int len)
+ {
+ int i;
+
+ for (i = 0; i < len; i++)
+ output[outpos + i] = input[inpos + i];
+ }
+
+ /*
+ md5Transform是MD5核心变换程序,有md5Update调用,block是分块的原始字节
+ */
+ private void md5Transform (byte block[]) {
+ long a = state[0], b = state[1], c = state[2], d = state[3];
+ long[] x = new long[16];
+
+ Decode (x, block, 64);
+
+ /* Round 1 */
+ a = FF (a, b, c, d, x[0], S11, 0xd76aa478L); /* 1 */
+ d = FF (d, a, b, c, x[1], S12, 0xe8c7b756L); /* 2 */
+ c = FF (c, d, a, b, x[2], S13, 0x242070dbL); /* 3 */
+ b = FF (b, c, d, a, x[3], S14, 0xc1bdceeeL); /* 4 */
+ a = FF (a, b, c, d, x[4], S11, 0xf57c0fafL); /* 5 */
+ d = FF (d, a, b, c, x[5], S12, 0x4787c62aL); /* 6 */
+ c = FF (c, d, a, b, x[6], S13, 0xa8304613L); /* 7 */
+ b = FF (b, c, d, a, x[7], S14, 0xfd469501L); /* 8 */
+ a = FF (a, b, c, d, x[8], S11, 0x698098d8L); /* 9 */
+ d = FF (d, a, b, c, x[9], S12, 0x8b44f7afL); /* 10 */
+ c = FF (c, d, a, b, x[10], S13, 0xffff5bb1L); /* 11 */
+ b = FF (b, c, d, a, x[11], S14, 0x895cd7beL); /* 12 */
+ a = FF (a, b, c, d, x[12], S11, 0x6b901122L); /* 13 */
+ d = FF (d, a, b, c, x[13], S12, 0xfd987193L); /* 14 */
+ c = FF (c, d, a, b, x[14], S13, 0xa679438eL); /* 15 */
+ b = FF (b, c, d, a, x[15], S14, 0x49b40821L); /* 16 */
+
+ /* Round 2 */
+ a = GG (a, b, c, d, x[1], S21, 0xf61e2562L); /* 17 */
+ d = GG (d, a, b, c, x[6], S22, 0xc040b340L); /* 18 */
+ c = GG (c, d, a, b, x[11], S23, 0x265e5a51L); /* 19 */
+ b = GG (b, c, d, a, x[0], S24, 0xe9b6c7aaL); /* 20 */
+ a = GG (a, b, c, d, x[5], S21, 0xd62f105dL); /* 21 */
+ d = GG (d, a, b, c, x[10], S22, 0x2441453L); /* 22 */
+ c = GG (c, d, a, b, x[15], S23, 0xd8a1e681L); /* 23 */
+ b = GG (b, c, d, a, x[4], S24, 0xe7d3fbc8L); /* 24 */
+ a = GG (a, b, c, d, x[9], S21, 0x21e1cde6L); /* 25 */
+ d = GG (d, a, b, c, x[14], S22, 0xc33707d6L); /* 26 */
+ c = GG (c, d, a, b, x[3], S23, 0xf4d50d87L); /* 27 */
+ b = GG (b, c, d, a, x[8], S24, 0x455a14edL); /* 28 */
+ a = GG (a, b, c, d, x[13], S21, 0xa9e3e905L); /* 29 */
+ d = GG (d, a, b, c, x[2], S22, 0xfcefa3f8L); /* 30 */
+ c = GG (c, d, a, b, x[7], S23, 0x676f02d9L); /* 31 */
+ b = GG (b, c, d, a, x[12], S24, 0x8d2a4c8aL); /* 32 */
+
+ /* Round 3 */
+ a = HH (a, b, c, d, x[5], S31, 0xfffa3942L); /* 33 */
+ d = HH (d, a, b, c, x[8], S32, 0x8771f681L); /* 34 */
+ c = HH (c, d, a, b, x[11], S33, 0x6d9d6122L); /* 35 */
+ b = HH (b, c, d, a, x[14], S34, 0xfde5380cL); /* 36 */
+ a = HH (a, b, c, d, x[1], S31, 0xa4beea44L); /* 37 */
+ d = HH (d, a, b, c, x[4], S32, 0x4bdecfa9L); /* 38 */
+ c = HH (c, d, a, b, x[7], S33, 0xf6bb4b60L); /* 39 */
+ b = HH (b, c, d, a, x[10], S34, 0xbebfbc70L); /* 40 */
+ a = HH (a, b, c, d, x[13], S31, 0x289b7ec6L); /* 41 */
+ d = HH (d, a, b, c, x[0], S32, 0xeaa127faL); /* 42 */
+ c = HH (c, d, a, b, x[3], S33, 0xd4ef3085L); /* 43 */
+ b = HH (b, c, d, a, x[6], S34, 0x4881d05L); /* 44 */
+ a = HH (a, b, c, d, x[9], S31, 0xd9d4d039L); /* 45 */
+ d = HH (d, a, b, c, x[12], S32, 0xe6db99e5L); /* 46 */
+ c = HH (c, d, a, b, x[15], S33, 0x1fa27cf8L); /* 47 */
+ b = HH (b, c, d, a, x[2], S34, 0xc4ac5665L); /* 48 */
+
+ /* Round 4 */
+ a = II (a, b, c, d, x[0], S41, 0xf4292244L); /* 49 */
+ d = II (d, a, b, c, x[7], S42, 0x432aff97L); /* 50 */
+ c = II (c, d, a, b, x[14], S43, 0xab9423a7L); /* 51 */
+ b = II (b, c, d, a, x[5], S44, 0xfc93a039L); /* 52 */
+ a = II (a, b, c, d, x[12], S41, 0x655b59c3L); /* 53 */
+ d = II (d, a, b, c, x[3], S42, 0x8f0ccc92L); /* 54 */
+ c = II (c, d, a, b, x[10], S43, 0xffeff47dL); /* 55 */
+ b = II (b, c, d, a, x[1], S44, 0x85845dd1L); /* 56 */
+ a = II (a, b, c, d, x[8], S41, 0x6fa87e4fL); /* 57 */
+ d = II (d, a, b, c, x[15], S42, 0xfe2ce6e0L); /* 58 */
+ c = II (c, d, a, b, x[6], S43, 0xa3014314L); /* 59 */
+ b = II (b, c, d, a, x[13], S44, 0x4e0811a1L); /* 60 */
+ a = II (a, b, c, d, x[4], S41, 0xf7537e82L); /* 61 */
+ d = II (d, a, b, c, x[11], S42, 0xbd3af235L); /* 62 */
+ c = II (c, d, a, b, x[2], S43, 0x2ad7d2bbL); /* 63 */
+ b = II (b, c, d, a, x[9], S44, 0xeb86d391L); /* 64 */
+
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+
+ }
+
+ /*Encode把long数组按顺序拆成byte数组,因为java的long类型是64bit的,
+ 只拆低32bit,以适应原始C实现的用途
+ */
+ private void Encode (byte[] output, long[] input, int len) {
+ int i, j;
+
+ for (i = 0, j = 0; j < len; i++, j += 4) {
+ output[j] = (byte)(input[i] & 0xffL);
+ output[j + 1] = (byte)((input[i] >>> 8) & 0xffL);
+ output[j + 2] = (byte)((input[i] >>> 16) & 0xffL);
+ output[j + 3] = (byte)((input[i] >>> 24) & 0xffL);
+ }
+ }
+
+ /*Decode把byte数组按顺序合成成long数组,因为java的long类型是64bit的,
+ 只合成低32bit,高32bit清零,以适应原始C实现的用途
+ */
+ private void Decode (long[] output, byte[] input, int len) {
+ int i, j;
+
+
+ for (i = 0, j = 0; j < len; i++, j += 4)
+ output[i] = b2iu(input[j]) |
+ (b2iu(input[j + 1]) << 8) |
+ (b2iu(input[j + 2]) << 16) |
+ (b2iu(input[j + 3]) << 24);
+
+ return;
+ }
+
+ /*
+ b2iu是我写的一个把byte按照不考虑正负号的原则的"升位"程序,因为java没有unsigned运算
+ */
+ public static long b2iu(byte b) {
+ return b < 0 ? b & 0x7F + 128 : b;
+ }
+
+ /*byteHEX(),用来把一个byte类型的数转换成十六进制的ASCII表示,
+ 因为java中的byte的toString无法实现这一点,我们又没有C语言中的
+ sprintf(outbuf,"%02X",ib)
+ */
+ public static String byteHEX(byte ib) {
+ char[] Digit = { '0','1','2','3','4','5','6','7','8','9',
+ 'A','B','C','D','E','F' };
+ char [] ob = new char[2];
+ ob[0] = Digit[(ib >>> 4) & 0X0F];
+ ob[1] = Digit[ib & 0X0F];
+ String s = new String(ob);
+ return s;
+ }
+
+}
+
diff --git a/src/farm-core/src/main/java/com/farm/core/auth/util/Urls.java b/src/farm-core/src/main/java/com/farm/core/auth/util/Urls.java
new file mode 100644
index 0000000..a5eab38
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/auth/util/Urls.java
@@ -0,0 +1,192 @@
+package com.farm.core.auth.util; // 定义包名,表示该类位于 com.farm.core.auth.util 包中
+
+import java.util.Map; // 导入 Map 接口
+import java.util.Map.Entry; // 导入 Map.Entry 接口,用于遍历 Map 中的键值对
+import java.util.Set; // 导入 Set 接口
+
+import javax.servlet.http.HttpServletRequest; // 导入 HttpServletRequest 接口,用于处理 HTTP 请求
+
+/**
+ * 权限验证帮助类
+ *
+ * @author WangDong
+ * @date Mar 14, 2010
+ *
+ */
+public class Urls {
+
+ /**
+ * 验证权限是否符合系统验证
+ *
+ * @param actionMap 全部监控权限
+ * @param useraction 用户拥有权限
+ * @param url 当前URL
+ * @return 是否符合验证
+ */
+ @SuppressWarnings("unused") // 抑制未使用变量的警告
+ private boolean checkpopedom(Map actionMap, Map> useraction,
+ String url) {
+ // 查看是否是受控权限
+ if (actionMap == null) {
+ return false; // 如果全部监控权限为空,则返回false
+ }
+ if (actionMap.get(url) != null) {
+ // 是受检权限,看用户是否拥有该权限
+ if (useraction == null) {
+ return false; // 如果用户拥有权限为空,则返回false
+ }
+ if (useraction.get(url) != null) {
+ return true; // 如果用户拥有该URL的权限,则返回true
+ } else {
+ return false; // 如果用户没有该URL的权限,则返回false
+ }
+ } else {
+ // 不是受检权限
+ return true; // 如果当前URL不在监控权限中,则默认有权限,返回true
+ }
+ }
+
+ // struts2的请求处理方法
+
+ /**
+ * 将url解析为系统可识别的url transact Url to Url(Admin/Xxxx.do)
+ *
+ * @param requestUrl 原始url
+ * @param basePath 应用基础路径
+ * @return 解析后的url,如果返回null则表示url错误
+ */
+ public static String formatUrl(String requestUrl, String basePath) {
+ // 去掉basepath
+ requestUrl = requestUrl.replace(basePath, "");
+ // 截去url参数
+ int num = requestUrl.indexOf("?");
+ if (num > 0) {
+ requestUrl = requestUrl.substring(0, num);
+ }
+ // 截去url前缀
+ // int num2 = requestUrl.replace("\\", "/").lastIndexOf("/");
+ // requestUrl = requestUrl.substring(num2);
+ return requestUrl; // 返回处理后的URL
+ }
+
+ /**
+ * 判断是否是actionURL
+ *
+ * @param _Url URL字符串
+ * @param _postfix 后缀
+ * @return 是否是actionURL
+ */
+ public static boolean isActionByUrl(String _Url, String _postfix) {
+ if (_Url.indexOf(".") < 0) {
+ return false; // 如果URL中没有点,则不是actionURL
+ }
+ _Url = _Url.trim();
+ String postfix = _Url.substring(_Url.lastIndexOf(".") + 1);
+ if (postfix.toUpperCase().equals(_postfix.toUpperCase())) {
+ return true; // 如果后缀匹配,则是actionURL
+ }
+ return false; // 否则不是actionURL
+ }
+
+ /**
+ * 获得URLIndex,将格式化后的URL转换为URLIndex形式
+ *
+ * @param formatUrl 格式化后的URL
+ * @return URLIndex
+ */
+ public static String getActionKey(String formatUrl) {
+ String name = formatUrl.substring(0, formatUrl.lastIndexOf("."));
+ // if (name.lastIndexOf("/") >= 0) {
+ // name = name.substring(name.lastIndexOf("/") + 1);
+ // }
+ // if (name.lastIndexOf("\\") >= 0) {
+ // name = name.substring(name.lastIndexOf("\\") + 1);
+ // }
+ return name; // 返回URLIndex
+ }
+
+ /**
+ * 获得URL的子键,即URL中的最后一部分
+ *
+ * @param actionkey URLIndex
+ * @return URL的子键
+ */
+ public static String getActionSubKey(String actionkey) {
+ // 将actionkey中的反斜杠替换为正斜杠,以统一路径分隔符
+ int num2 = actionkey.replace("\\", "/").lastIndexOf("/");
+ // 如果找到了正斜杠,说明存在路径
+ if (num2 >= 0) {
+ // 截取最后一个正斜杠之后的部分,即URL的子键
+ actionkey = actionkey.substring(num2);
+ }
+ // 返回处理后的URL子键,如果未找到正斜杠,则返回原actionkey
+ return actionkey;
+ }
+
+
+ /**
+ * 获得当前连接的IP地址
+ *
+ * @param request 请求对象
+ * @return IP地址
+ */
+ public static String getIpAddr(HttpServletRequest request) {
+ // 尝试从HTTP头部x-forwarded-for获取IP地址,这个头部通常由代理服务器设置
+ String ip = request.getHeader("x-forwarded-for");
+ // 如果IP地址为空、长度为0或者为"unknown",则尝试从Proxy-Client-IP头部获取IP地址
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("Proxy-Client-IP");
+ }
+ // 如果IP地址仍然为空、长度为0或者为"unknown",则尝试从WL-Proxy-Client-IP头部获取IP地址
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("WL-Proxy-Client-IP");
+ }
+ // 如果IP地址仍然为空、长度为0或者为"unknown",则从远程地址(即直接连接到服务器的客户端IP)获取IP地址
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getRemoteAddr();
+ }
+ // 返回获取到的IP地址
+ return ip;
+ }
+
+
+ /**
+ * 获得所有request的参数并拼接成GET参数字符串
+ *
+ * @param request 请求对象
+ * @return GET参数字符串
+ */
+ public static String getUrlParameters(HttpServletRequest request) {
+ // 抑制unchecked警告,因为getParameterMap()返回的是Map,而Entry是unchecked类型
+ @SuppressWarnings("unchecked")
+ Set> entrySet = request.getParameterMap().entrySet();
+ // 创建StringBuffer用于拼接URL参数
+ StringBuffer urlp = new StringBuffer();
+ // 遍历所有请求参数的键值对
+ for (Entry node : entrySet) {
+ // 检查参数值是否存在且至少有一个元素
+ if (node.getValue() != null && node.getValue().length > 0) {
+ // 如果已经拼接了参数,则在添加新参数前添加'&'分隔符
+ if (urlp.length() > 0) {
+ urlp.append("&");
+ }
+ // 拼接参数名和第一个参数值,格式为"key=value"
+ urlp.append(node.getKey() + "=" + node.getValue()[0]);
+ }
+ }
+ // 返回拼接后的GET参数字符串
+ return urlp.toString();
+ }
+
+
+ /**
+ * 验证用户是否拥有权限
+ *
+ * @param URL_index actionIndex,URl关键字不包括后缀和前缀
+ * @param userUrl 用户权限集合《URL_index,URL_Id》
+ * @return 是否有权限
+ */
+ public boolean isHavePop(String URL_index, Map userUrl) {
+ return false; // 当前方法未实现,直接返回false
+ }
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/config/AppConfig.java b/src/farm-core/src/main/java/com/farm/core/config/AppConfig.java
new file mode 100644
index 0000000..3be02c2
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/config/AppConfig.java
@@ -0,0 +1,48 @@
+package com.farm.core.config;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import org.apache.log4j.Logger;
+
+/**
+ * 应用参数工具类,获得config中定义的参数
+ *
+ * @author wangdong
+ *
+ */
+public class AppConfig {
+ private static final String BUNDLE_NAME = "config"; //$NON-NLS-1$
+ private static final Logger log = Logger.getLogger(AppConfig.class);
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
+
+ private AppConfig() {
+ // 私有构造函数,防止外部创建AppConfig实例
+ }
+
+ /**
+ * 从properties文件中获得配置值
+ *
+ * @param key 配置文件的key
+ * @return 配置值
+ */
+ public static String getString(String key) {
+ // 如果key是"PRO",则直接返回"PRO"(可能是特殊处理或默认值)
+ if (key.equals("PRO")) {
+ return "PRO";
+ }
+ try {
+ // 从资源束中获取key对应的字符串值
+ String messager = RESOURCE_BUNDLE.getString(key);
+ return messager;
+ } catch (MissingResourceException e) {
+ // 如果在资源束中找不到key,构建错误消息
+ String messager = "不能在配置文件" + BUNDLE_NAME + "中发现参数:" + '!' + key + '!';
+ // 记录错误日志
+ log.error(messager);
+ // 抛出运行时异常,通知调用者配置值未找到
+ throw new RuntimeException(messager);
+ }
+ }
+// AppConfig类结束
+
diff --git a/src/farm-core/src/main/java/com/farm/core/config/PropertiesUtils.java b/src/farm-core/src/main/java/com/farm/core/config/PropertiesUtils.java
new file mode 100644
index 0000000..84b69d0
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/config/PropertiesUtils.java
@@ -0,0 +1,116 @@
+package com.farm.core.config;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+
+
+public class PropertiesUtils {
+ private String PROPERTY_FILE; // 属性文件路径
+ private static final Logger log = Logger.getLogger(PropertiesUtils.class); // 日志记录器
+
+ /**
+ * 构造函数,用于初始化PropertiesUtils实例并设置属性文件路径。
+ * @param fileName 属性文件名,例如jdbc.properties
+ */
+ public PropertiesUtils(String fileName) {
+ // 获取类路径下的资源路径,并拼接文件名以设置完整的属性文件路径
+ PROPERTY_FILE = PropertiesUtils.class.getResource("/").getPath()
+ .toString()
+ + fileName;
+ }
+ // 类的其他部分...
+}
+
+
+ /**
+ * 根据Key 读取Value
+ */
+ public String getData(String key) {
+ // 创建Properties对象,用于加载和读取属性文件中的键值对
+ Properties props = new Properties();
+ try {
+ // 创建InputStream对象,用于读取属性文件
+ // 使用BufferedInputStream包装FileInputStream以提供缓冲功能,提高读取效率
+ InputStream in = new BufferedInputStream(new FileInputStream(
+ PROPERTY_FILE));
+ // 加载属性文件中的键值对到Properties对象中
+ props.load(in);
+ // 关闭输入流
+ in.close();
+ // 根据键获取对应的值
+ String value = props.getProperty(key);
+ // 返回获取到的值
+ return value;
+ } catch (Exception e) {
+ // 如果在读取过程中发生异常,记录错误日志
+ log.error(e.getMessage());
+ // 返回null,表示没有获取到对应的值
+ return null;
+ }
+ }
+
+
+/**
+ * 修改或添加键值对 如果key存在,修改 反之,添加。
+ */
+public void setData(String key, String value) {
+ // 创建Properties对象,用于存储和修改属性键值对
+ Properties prop = new Properties();
+ // 定义OutputStream变量,用于写入属性文件
+ OutputStream fos = null;
+ // 定义InputStream变量,用于读取属性文件
+ InputStream fis = null;
+ try {
+ // 创建File对象,指向属性文件
+ File file = new File(PROPERTY_FILE);
+ // 如果属性文件不存在,则创建一个新的文件
+ if (!file.exists())
+ file.createNewFile();
+ // 初始化FileInputStream,用于读取属性文件
+ fis = new FileInputStream(file);
+ // 加载属性文件中的键值对到Properties对象中
+ prop.load(fis);
+ } catch (IOException e) {
+ // 如果读取属性文件时发生IOException,打印错误信息
+ System.err.println("Visit " + PROPERTY_FILE + " for updating "
+ + value + " value error");
+ } finally {
+ try {
+ // 关闭FileInputStream,释放资源
+ fis.close();// 一定要在修改值之前关闭fis
+ } catch (IOException e) {
+ // 关闭FileInputStream时可能发生的IOException,此处忽略
+ }
+ }
+ try {
+ // 初始化FileOutputStream,用于写入修改后的属性文件
+ fos = new FileOutputStream(PROPERTY_FILE);
+ // 设置Properties对象的键值对
+ prop.setProperty(key, value);
+ // 将修改后的键值对存储到属性文件中,并添加注释
+ prop.store(fos, "Update '" + key + "' value");
+ // 重复存储操作,可能是为了测试或记录额外信息,但通常不需要
+ prop.store(fos, "just for test");
+ } catch (IOException e) {
+ // 如果写入属性文件时发生IOException,打印错误信息
+ System.err.println("Visit " + PROPERTY_FILE + " for updating "
+ + value + " value error");
+ } finally {
+ try {
+ // 关闭FileOutputStream,释放资源
+ fos.close();
+ } catch (IOException e) {
+ // 关闭FileOutputStream时可能发生的IOException,此处忽略
+ }
+ }
+}
+// 类结束
+
diff --git a/src/farm-core/src/main/java/com/farm/core/config/ReadKey.java b/src/farm-core/src/main/java/com/farm/core/config/ReadKey.java
new file mode 100644
index 0000000..859c17b
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/config/ReadKey.java
@@ -0,0 +1,60 @@
+package com.farm.core.config;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+
+import com.farm.core.Context;
+import com.farm.core.auth.util.KeyUtil;
+
+/**
+ * 读取licence
+ *
+ * @author macplus
+ *
+ */
+public class ReadKey {
+ private static boolean isOk = false; // 静态标志变量,用于指示是否已成功读取licence文件
+
+ public static void read(String path) {
+ try {
+ // 检查是否已经读取过licence文件,如果没有,则进行读取操作
+ if (isOk == false) {
+ // 读取licence文件内容,并设置到Context的FK字段
+ Context.FK = readTxtFile(path + File.separator + "licence");
+ // 比较licence文件内容与通过KeyUtil获取的Fkey是否相等,结果设置到Context的FLAG字段
+ Context.FLAG = KeyUtil.getFkey(KeyUtil.getMKey()).equals(Context.FK);
+ // 设置isOk为true,表示已成功读取licence文件
+ isOk = true;
+ }
+ } catch (Exception e) {
+ // 如果在读取过程中发生异常,将Context的FK字段设置为"NONE1"
+ Context.FK = "NONE1";
+ }
+ }
+
+ public static String readTxtFile(String filePath) {
+ try {
+ // 创建File对象,指向指定的文件路径
+ File file = new File(filePath);
+ // 检查文件是否存在且是一个文件
+ if (file.isFile() && file.exists()) {
+ // 创建InputStreamReader对象,指定文件输入流和编码格式为utf-8
+ InputStreamReader read = new InputStreamReader(new FileInputStream(file), "utf-8");
+ // 创建BufferedReader对象,用于读取文件内容
+ BufferedReader bufferedReader = new BufferedReader(read);
+ String lineTxt = null;
+ // 读取文件的第一行内容
+ while ((lineTxt = bufferedReader.readLine()) != null) {
+ return lineTxt; // 返回读取到的第一行内容
+ }
+ read.close(); // 关闭读取流
+ }
+ } catch (Exception e) {
+ // 异常处理,此处为空,实际应用中应添加适当的异常处理逻辑
+ }
+ return "none"; // 如果文件不存在或读取过程中发生异常,返回"none"
+ }
+}
+
diff --git a/src/farm-core/src/main/java/com/farm/core/page/OperateType.java b/src/farm-core/src/main/java/com/farm/core/page/OperateType.java
new file mode 100644
index 0000000..2093f6e
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/page/OperateType.java
@@ -0,0 +1,49 @@
+package com.farm.core.page;
+
+/**
+ * 页面类型
+ *
+ * @author wangdong
+ *
+ */
+public enum OperateType {
+ /**
+ * 展示
+ */
+ SHOW(0), /**
+ * 新增
+ */
+ ADD(1), /**
+ * 修改
+ */
+ UPDATE(2),
+ /**
+ * 删除
+ */
+ DEL(4),
+ /**
+ * 其他
+ */
+ OTHER(3);
+ public int value;
+
+ private OperateType(int var) {
+ value = var;
+ }
+
+ /**根据数值获得页面类型枚举对象
+ * @param type
+ * @return
+ */
+ public static OperateType getEnum(int type) {
+ // 方法开始,定义一个静态方法getEnum,它接受一个整型参数type
+ if (type == 0)
+ return OperateType.SHOW; // 检查type是否为0,如果是,则返回OperateType.SHOW,表示显示操作
+ if (type == 1)
+ return OperateType.ADD; // 检查type是否为1,如果是,则返回OperateType.ADD,表示添加操作
+ if (type == 2)
+ return OperateType.UPDATE; // 检查type是否为2,如果是,则返回OperateType.UPDATE,表示更新操作
+ return null; // 如果type不是0、1或2,表示传入的type不匹配任何预定义的操作类型,返回null
+ } // 方法结束,返回一个OperateType枚举类型或者null
+
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/page/RequestMode.java b/src/farm-core/src/main/java/com/farm/core/page/RequestMode.java
new file mode 100644
index 0000000..6e33111
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/page/RequestMode.java
@@ -0,0 +1,198 @@
+package com.farm.core.page; // 定义包名,表示该类属于com.farm.core.page包
+
+import java.util.HashMap; // 导入HashMap类
+import java.util.Map; // 导入Map接口
+
+import javax.servlet.http.HttpSession; // 导入HttpSession接口
+
+import org.apache.log4j.Logger; // 导入Logger类
+
+import com.farm.core.auth.domain.LoginUser; // 导入LoginUser类
+
+/**
+ * 封装一次页面请求的状态
+ *
+ * @author wangdong
+ *
+ */
+public class RequestMode implements java.io.Serializable { // 定义RequestMode类,实现Serializable接口
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L; // 定义序列化版本UID
+ static final Logger log = Logger.getLogger(RequestMode.class); // 获取Logger实例
+ private Map data; // 定义数据存储Map
+ /**
+ * 页面类型
+ */
+ private int operateType; // 定义操作类型变量
+ /**
+ * 消息
+ */
+ private String message = ""; // 定义消息字符串,默认为空
+ /**
+ * 记录集id集合
+ */
+ private String ids; // 定义记录集ID集合字符串
+ /**
+ * 当前实体id
+ */
+ private String currentKeyid; // 定义当前实体ID字符串
+
+ // ------------------------------------------------------------------------------
+
+ /**
+ * 当前主键
+ *
+ * @return
+ */
+ public String getCurrentKeyid() { // 获取当前主键的方法
+ return currentKeyid; // 返回当前主键
+ }
+
+ /**
+ * 设置参数
+ *
+ * @return
+ */
+ public void putParameters(String key, String val) { // 设置参数的方法
+ if (this.data == null) { // 如果data为null
+ this.data = new HashMap(); // 初始化data
+ }
+ this.data.put(key, val); // 向data中添加键值对
+ }
+
+ /**
+ * 获得参数
+ *
+ * @param key
+ * @return
+ */
+ public String getParameters(String key) { // 获取参数的方法
+ return this.data.get(key); // 返回指定键的值
+ }
+
+ /**
+ * 获得当前业务id
+ *
+ * @param currentKeyid
+ */
+ public void setCurrentKeyid(String currentKeyid) { // 设置当前业务ID的方法
+ this.currentKeyid = currentKeyid; // 设置当前业务ID
+ }
+
+ public RequestMode() { // 默认构造函数
+ }
+
+ public RequestMode(OperateType operate) { // 带操作类型的构造函数
+ operateType = operate.value; // 设置操作类型
+ }
+
+ public RequestMode(OperateType operate, String message) { // 带操作类型和消息的构造函数
+ operateType = operate.value; // 设置操作类型
+ this.message = message; // 设置消息
+ }
+
+ /**
+ * 设置一个PageSet 而且PageSet可以为空
+ *
+ * @param pageSet 页面状态对象
+ * @param pageType 页面类型
+ * @param commitType 提交状态
+ * @param e 异常
+ * @return pageSet 页面状态对象
+ */
+ public static RequestMode initPageSet(RequestMode pageSet,
+ OperateType operateType, Exception e) { // 初始化页面状态的方法
+ if (pageSet == null) { // 如果页面状态对象为null
+ pageSet = new RequestMode(OperateType.OTHER); // 创建一个新的页面状态对象
+ }
+ if (e != null) { // 如果异常不为null
+ pageSet.setMessage(e.getMessage()); // 设置消息为异常信息
+ log.error(pageSet.getMessage()); // 记录错误日志
+ }
+ if (operateType != null) { // 如果操作类型不为null
+ pageSet.setOperateType(operateType.value); // 设置操作类型
+ }
+ return pageSet; // 返回页面状态对象
+ }
+
+ /**
+ * 设置状态
+ *
+ * @param pageType 页面类型对象
+ * @param commitType 提交状态对象
+ */
+ public void SetVar(OperateType operateType) { // 设置状态的方法
+ if (operateType != null) // 如果操作类型不为null
+ this.operateType = operateType.value; // 设置操作类型
+ }
+
+ /**
+ * 设置状态
+ *
+ * @param pageType 页面类型对象
+ * @param commitType 提交状态对象
+ * @param message 消息内容
+ */
+ public void SetVar(OperateType operateType,
+ String message) { // 设置状态和消息的方法
+ if (operateType != null) // 如果操作类型不为null
+ this.operateType = operateType.value; // 设置操作类型
+ if (message != null) // 如果消息不为null
+ this.message = message; // 设置消息
+ }
+
+ /**
+ * 获得消息
+ *
+ * @return
+ */
+ public String getMessage() { // 获取消息的方法
+ return message; // 返回消息
+ }
+
+ /**
+ * 设置消息内容
+ *
+ * @param message
+ */
+ public void setMessage(String message) { // 设置消息内容的方法
+ this.message = message; // 设置消息
+ }
+
+ public int getOperateType() { // 获取操作类型的方法
+ return operateType; // 返回操作类型
+ }
+
+ public void setOperateType(int operateType) { // 设置操作类型的方法
+ this.operateType = operateType; // 设置操作类型
+ }
+
+ /**
+ * 获得id集合
+ *
+ * @return
+ */
+ public String getIds() { // 获取ID集合的方法
+ return ids; // 返回ID集合
+ }
+
+ /**
+ * 设置id集合
+ *
+ * @param ids
+ */
+ public void setIds(String ids) { // 设置ID集合的方法
+ this.ids = ids; // 设置ID集合
+ }
+
+ public Map getData() { // 获取数据的方法
+ return data; // 返回数据
+ }
+
+ public void setData(Map data) { // 设置数据的方法
+ this.data = data; // 设置数据
+ }
+
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/page/StateType.java b/src/farm-core/src/main/java/com/farm/core/page/StateType.java
new file mode 100644
index 0000000..97d0002
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/page/StateType.java
@@ -0,0 +1,22 @@
+package com.farm.core.page;
+
+/**
+ * 提交状态,用来标志操作是否成功,多用于页面对后台操作的判断
+ *
+ * @author wangdong
+ *
+ */
+public enum StateType {
+ /**
+ * 成功
+ */
+ SUCCESS(0), /**
+ * 失败
+ */
+ ERROR(1);
+ public int value;
+
+ private StateType(int var) {
+ value = var;
+ }
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/page/ViewMode.java b/src/farm-core/src/main/java/com/farm/core/page/ViewMode.java
new file mode 100644
index 0000000..5907f0c
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/page/ViewMode.java
@@ -0,0 +1,74 @@
+package com.farm.core.page; // 定义包名,表示该类属于com.farm.core.page包
+
+import java.util.HashMap; // 导入HashMap类
+import java.util.List; // 导入List接口
+import java.util.Map; // 导入Map接口
+
+import org.apache.log4j.Logger; // 导入Logger类
+import org.springframework.web.servlet.ModelAndView; // 导入ModelAndView类
+
+/**
+ * ajax请求时的json模型
+ *
+ * @author wangdong
+ *
+ */
+public class ViewMode {
+ private final static Logger log = Logger.getLogger(ViewMode.class); // 获取Logger实例
+ private Map attrs = new HashMap(); // 存储属性键值对的Map
+
+ // 获取ViewMode的实例,并初始化状态和操作类型
+ public static ViewMode getInstance() {
+ ViewMode obj = new ViewMode();
+ obj.attrs.put("STATE", StateType.SUCCESS.value); // 设置默认状态为成功
+ obj.attrs.put("OPERATE", OperateType.OTHER.value); // 设置默认操作类型为其他
+ return obj;
+ }
+
+ /**
+ * 装入json返回值
+ *
+ * @param key 键
+ * @param value 值
+ * @return 当前ViewMode实例
+ */
+ public ViewMode putAttr(String key, String value) {
+ attrs.put(key, value); // 添加字符串类型的键值对
+ return this;
+ }
+
+ // 重载putAttr方法,支持Object类型的值
+ public ViewMode putAttr(String key, Object value) {
+ attrs.put(key, value); // 添加Object类型的键值对
+ return this;
+ }
+
+ // 添加多个键值对到attrs中
+ public ViewMode putAttrs(Map map) {
+ attrs.putAll(map); // 合并Map到attrs中
+ return this;
+ }
+
+ /**
+ * 装入错误
+ *
+ * @param message 错误消息
+ * @return 当前ViewMode实例
+ */
+ public ViewMode setError(String message) {
+ attrs.put("MESSAGE", message); // 设置错误消息
+ attrs.put("STATE", StateType.ERROR.value); // 设置状态为错误
+ log.error(message); // 记录错误日志
+ return this;
+ }
+
+ // 设置操作类型
+ public ViewMode setOperate(OperateType type) {
+ attrs.put("OPERATE", type.value); // 设置操作类型
+ return this;
+ }
+
+/**
+ * 返回map格式json
+ *
+ * @return at
\ No newline at end of file
diff --git a/src/farm-core/src/main/java/com/farm/core/para/impl/ParaTestImpl.java b/src/farm-core/src/main/java/com/farm/core/para/impl/ParaTestImpl.java
new file mode 100644
index 0000000..69fa363
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/para/impl/ParaTestImpl.java
@@ -0,0 +1,46 @@
+package com.farm.core.para.impl;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import com.farm.core.ParameterService;
+
+public class ParaTestImpl implements ParameterService {
+
+ @Override
+ public Map getDictionary(String key) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List> getDictionaryList(String index) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getParameter(String key) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getParameter(String key, String userId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int getParameterInt(String key) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public boolean getParameterBoolean(String key) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/sql/query/CoreHandle.java b/src/farm-core/src/main/java/com/farm/core/sql/query/CoreHandle.java
new file mode 100644
index 0000000..0e88483
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/sql/query/CoreHandle.java
@@ -0,0 +1,22 @@
+package com.farm.core.sql.query;
+
+import com.farm.core.Context;
+import com.farm.core.auth.util.KeyUtil;
+
+public class CoreHandle {
+ // 定义核心处理类
+
+ /**
+ * 运行LCE逻辑。
+ * 此方法用于执行某些核心的LCE(可能是某种逻辑、计算或初始化)操作。
+ * 它首先从KeyUtil工具类获取主键(MKey),然后将其设置到Context的MK属性中。
+ * 目前,无论操作结果如何,该方法总是返回true。
+ *
+ * @return 总是返回true,表示操作成功。
+ */
+ public static boolean runLce() {
+ Context.MK = KeyUtil.getMKey(); // 获取并设置主键
+ return true; // 返回操作成功标志
+ }
+}
+
diff --git a/src/farm-core/src/main/java/com/farm/core/sql/query/DBRule.java b/src/farm-core/src/main/java/com/farm/core/sql/query/DBRule.java
new file mode 100644
index 0000000..7bd6e8d
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/sql/query/DBRule.java
@@ -0,0 +1,228 @@
+package com.farm.core.sql.query;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 查询条件的封装类,配合DataQuery使用
+ *
+ * @author 王东
+ * @date 2012-12-30
+ */
+public class DBRule {
+ private String key;// where key
+ private Object value;// where value
+ private String comparaSign;// like,}��% = > < >= <=
+ private List rules = new ArrayList();
+
+ /**
+ * 将一个条件对象添加到条件序列中
+ *
+ * @param ruleList
+ * @param key
+ * @param value
+ * @param comString
+ * @return
+ */
+ public static List addRule(List ruleList, String key,
+ String value, String comString) {
+ DBRule cRule = new DBRule(key, value, comString);
+ ruleList.add(cRule);
+ return ruleList;
+ }
+
+ /**
+ * 将一个条件对象添加到条件序列中
+ *
+ * @param key
+ * @param value
+ * @param comString
+ * @return
+ */
+ public DBRule addRule(String key, String value, String comString) {
+ DBRule cRule = new DBRule(key, value, comString);
+ rules.add(cRule);
+ return this;
+ }
+
+ /**
+ * 获得条件序列
+ *
+ * @return
+ */
+ public List getDBRules() {
+ return rules;
+ }
+
+ /**
+ * 将条件序列转义为条件字符串
+ *
+ * @param ruleList
+ * 条件序列
+ * @return
+ */
+ public static String makeWhereStr(List ruleList) {
+ StringBuffer str = new StringBuffer();
+ for (DBRule node : ruleList) {
+ str.append(node.getThisLimit());
+ }
+ return str.toString();
+ }
+
+ /**
+ * 构造一个查询条件
+ *
+ * @param key
+ * 字段名
+ * @param value
+ * 字段值
+ * @param comString
+ * 匹配类型 like(-like坐标自由匹配) IS NOT = > < >= <=
+ */
+ public DBRule(String key, Object value, String comString) {
+ // 对键进行SQL注入防护
+ DataQuerys.wipeVirus(key);
+ // 对值进行SQL注入防护,先将Object类型的值转换为字符串
+ DataQuerys.wipeVirus(value.toString());
+ // 对比较符进行SQL注入防护
+ DataQuerys.wipeVirus(comString);
+
+ // 去除键的首尾空格并转换为大写
+ this.key = key.trim().toUpperCase();
+ // 设置规则值
+ this.value = value;
+ // 去除比较符的首尾空格并转换为大写
+ this.comparaSign = comString.trim().toUpperCase();
+
+ // 将当前DBRule对象添加到规则列表中
+ this.rules.add(this);
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getValue() {
+ return value.toString();
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getComparaSign() {
+ return comparaSign;
+ }
+
+ public void setComparaSign(String comparaSign) {
+ this.comparaSign = comparaSign;
+ }
+
+ public String getThisLimit() {
+ // 初始化StringBuffer用于构建限制条件
+ StringBuffer where_ = new StringBuffer();
+ // 将比较符转换为大写
+ comparaSign = comparaSign.toUpperCase();
+ // 检查键、值和比较符是否非空
+ if (key != null && value != null && comparaSign != null) {
+ // 添加AND关键字和键
+ where_.append(" AND ");
+ where_.append(key);
+ // 根据比较符是否包含"LIKE"来决定添加LIKE还是其他比较符
+ if (comparaSign.indexOf("LIKE") >= 0) {
+ where_.append(" ");
+ where_.append("LIKE");
+ } else {
+ where_.append(" ");
+ where_.append(comparaSign);
+ }
+ // 添加处理后的值
+ where_.append(expendVal());
+ where_.append(" ");
+ }
+ // 返回构建好的限制条件字符串
+ return where_.toString();
+ }
+
+ private String expendVal() {
+ // 创建一个新的StringBuffer对象用于构建扩展后的值字符串
+ StringBuffer valStr = new StringBuffer();
+
+ // 检查比较符是否为"LIKE",如果是,则进行模糊匹配处理
+ if (comparaSign.equals("LIKE")) {
+ // 为LIKE查询添加前百分号和单引号
+ valStr.append(" '%");
+ // 添加值本身
+ valStr.append(value.toString());
+ // 为LIKE查询添加后百分号和单引号
+ valStr.append("%'");
+ } else if (comparaSign.equals("-LIKE")) {
+ // 为-LIKE查询添加前百分号和单引号(不添加后百分号)
+ valStr.append(" '%");
+ // 添加值本身
+ valStr.append(value.toString());
+ // 为-LIKE查询添加单引号
+ valStr.append("'");
+ } else if (comparaSign.equals("LIKE-")) {
+ // 为LIKE-查询添加单引号和后百分号(不添加前百分号)
+ valStr.append(" '");
+ // 添加值本身
+ valStr.append(value.toString());
+ // 为LIKE-查询添加后百分号和单引号
+ valStr.append("%'");
+ } else if (comparaSign.equals("IS NOT")) {
+ // 为IS NOT查询添加空格
+ valStr.append(" ");
+ // 添加值本身
+ valStr.append(value.toString());
+ // 为IS NOT查询添加空格
+ valStr.append(" ");
+ } else if (comparaSign.equals("IS")) {
+ // 为IS查询添加空格
+ valStr.append(" ");
+ // 添加值本身
+ valStr.append(value.toString());
+ // 为IS查询添加空格
+ valStr.append(" ");
+ } else if (comparaSign.equals("IN")) {
+ // 为IN查询添加左括号
+ valStr.append("(");
+ // 添加值本身,通常是一个逗号分隔的列表
+ valStr.append(value.toString());
+ // 为IN查询添加右括号
+ valStr.append(")");
+ } else {
+ // 对于其他类型的比较符,根据值的类型进行处理
+ if (value instanceof String) {
+ // 如果值是字符串,添加单引号以区分SQL关键字
+ valStr.append(" '");
+ // 添加值本身
+ valStr.append(value.toString());
+ // 添加单引号
+ valStr.append("'");
+ } else if (value instanceof BigDecimal) {
+ // 如果值是BigDecimal,直接添加值(数字不需要单引号)
+ valStr.append(" ");
+ // 添加值本身
+ valStr.append(value.toString());
+ // 不需要额外的符号
+ valStr.append("");
+ } else {
+ // 对于其他类型的值,直接添加值
+ valStr.append(" ");
+ // 添加值本身
+ valStr.append(value.toString());
+ // 不需要额外的符号
+ valStr.append("");
+ }
+ }
+
+ // 将构建好的StringBuffer对象转换为字符串并返回
+ return valStr.toString();
+ }
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/sql/query/DBRuleList.java b/src/farm-core/src/main/java/com/farm/core/sql/query/DBRuleList.java
new file mode 100644
index 0000000..8772780
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/sql/query/DBRuleList.java
@@ -0,0 +1,40 @@
+package com.farm.core.sql.query;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 查询条件的封装类
+ *
+ * @author 王东
+ * @date 2015-01-28
+ */
+public class DBRuleList {
+ // 使用@SuppressWarnings注解来抑制未使用变量的警告
+ @SuppressWarnings("unused")
+ // 定义一个序列化版本ID,用于对象的序列化和反序列化
+ private static final long serialVersionUID = 1L;
+ // 初始化一个列表来存储DBRule对象
+ private List list = new ArrayList();
+
+ // 默认构造函数,用于创建DBRuleList实例
+ public DBRuleList() {
+ }
+
+ // 获取DBRuleList的实例,返回一个新的DBRuleList对象
+ public static DBRuleList getInstance() {
+ return new DBRuleList();
+ }
+
+ // 向列表中添加一个DBRule对象,并返回当前DBRuleList实例以支持链式调用
+ public DBRuleList add(DBRule rule) {
+ list.add(rule);
+ return this;
+ }
+
+ // 将内部的DBRule列表转换为List并返回,以便外部使用
+ public List toList() {
+ return list;
+ }
+}
+
diff --git a/src/farm-core/src/main/java/com/farm/core/sql/query/DBSort.java b/src/farm-core/src/main/java/com/farm/core/sql/query/DBSort.java
new file mode 100644
index 0000000..1a72a2d
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/sql/query/DBSort.java
@@ -0,0 +1,106 @@
+package com.farm.core.sql.query;
+
+/**
+ * 排序方式的封装类,配合DataQuery使用
+ *
+ * @author 王东
+ * @date 2012-12-30
+ */
+public class DBSort {
+ private String sortTitleText; // 排序字段,用于存储数据库中需要排序的列的名称
+ private String sortTypeText; // 排序类型,用于存储排序的方式,可以是"ASC"(升序)或"DESC"(降序)
+ private String isValidate; // 验证标志,用于指示是否对排序字段和排序类型进行数据验证
+
+ @SuppressWarnings("unused")
+ private DBSort() {
+ // 私有构造函数,防止外部直接创建DBSort实例,可能用于内部逻辑或继承时使用
+ }
+
+ /**
+ * 构造一个排序方式
+ *
+ * @param title 排序字段,必须是非空的字符串,表示数据库中要排序的列名
+ * @param type 排序类型,必须是非空的字符串,且为"ASC"或"DESC",表示升序或降序
+ */
+ public DBSort(String title, String type) {
+ DataQuerys.wipeVirus(type); // 对排序类型进行防SQL注入处理
+ DataQuerys.wipeVirus(title); // 对排序字段进行防SQL注入处理
+ sortTitleText = title; // 设置排序字段
+ sortTypeText = type; // 设置排序类型
+ }
+
+ /**
+ * 构造一个排序方式,并指定是否进行数据验证
+ *
+ * @param title 排序字段,必须是非空的字符串,表示数据库中要排序的列名
+ * @param type 排序类型,必须是非空的字符串,且为"ASC"或"DESC",表示升序或降序
+ * @param isValidate 验证标志,布尔值,表示是否对传入的参数进行数据验证
+ */
+ public DBSort(String title, String type, boolean isValidate) {
+ if (isValidate) {
+ DataQuerys.wipeVirus(type); // 如果需要进行验证,对排序类型进行防SQL注入处理
+ DataQuerys.wipeVirus(title); // 如果需要进行验证,对排序字段进行防SQL注入处理
+ }
+ sortTitleText = title; // 设置排序字段
+ sortTypeText = type; // 设置排序类型
+ }
+
+ /**
+ * 设置排序字段
+ *
+ * @param sortTitleText 排序字段,必须是非空的字符串,表示数据库中要排序的列名
+ */
+ public void setSortTitleText(String sortTitleText) {
+ this.sortTitleText = sortTitleText; // 更新排序字段
+ }
+
+ /**
+ * 获取排序字段,确保返回的排序字段不包含下划线,因为数据库中的字段不能带下划线
+ *
+ * @return 排序字段,如果为空或为"NULL"(不区分大小写),则返回null,否则返回替换下划线为点后的字符串
+ */
+ public String getSortTitleText() {
+ if (sortTitleText == null
+ || sortTitleText.trim().toUpperCase().equals("NULL")) {
+ return null; // 如果排序字段为空或为"NULL",则返回null
+ }
+ return sortTitleText.replace("_", "."); // 替换排序字段中的下划线为点
+ }
+
+ /**
+ * 获取排序类型
+ *
+ * @return 排序类型,字符串,表示升序或降序
+ */
+ public String getSortTypeText() {
+ return sortTypeText; // 返回排序类型
+ }
+
+ /**
+ * 设置排序类型
+ *
+ * @param sortTypeText 排序类型,必须是非空的字符串,且为"ASC"或"DESC",表示升序或降序
+ */
+ public void setSortTypeText(String sortTypeText) {
+ this.sortTypeText = sortTypeText; // 更新排序类型
+ }
+
+ /**
+ * 获取验证标志
+ *
+ * @return 验证标志,字符串,表示是否进行了数据验证
+ */
+ public String getIsValidate() {
+ return isValidate; // 返回验证标志
+ }
+
+ /**
+ * 设置验证标志
+ *
+ * @param isValidate 验证标志,字符串,用于指示是否进行了数据验证
+ */
+ public void setIsValidate(String isValidate) {
+ this.isValidate = isValidate; // 更新验证标志
+ }
+}
+
diff --git a/src/farm-core/src/main/java/com/farm/core/sql/query/DataQuery.java b/src/farm-core/src/main/java/com/farm/core/sql/query/DataQuery.java
new file mode 100644
index 0000000..a4d0c95
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/sql/query/DataQuery.java
@@ -0,0 +1,849 @@
+package com.farm.core.sql.query;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.hibernate.Session;
+
+import com.farm.core.auth.util.AuthenticateInter;
+import com.farm.core.auth.util.AuthenticateProvider;
+import com.farm.core.sql.result.DataResult;
+import com.farm.core.sql.result.DataResults;
+import com.farm.util.spring.HibernateSessionFactory;
+
+/**
+ * 数据库查询封装类
+ *
+ * @author 王东
+ * @version 2012
+ * @version 2014-10-29 重构:1.缓存带分页2.重构代码3.缓存更新时使用线程
+ *
+ */
+public class DataQuery {
+ // 定义日志记录器,用于记录DataQuery类的日志信息
+ static final Logger log = Logger.getLogger(DataQuery.class);
+ // 定义缓存的最大容量
+ private final static int CACHE_MAX_SIZE = 1000;
+
+ /**
+ * 缓存器单位枚举值
+ * 用于定义缓存过期时间的单位
+ *
+ * @author Administrator
+ *
+ */
+ public enum CACHE_UNIT {
+ /**
+ * 毫秒单位
+ */
+ Millisecond(1),
+ /**
+ * 秒单位
+ */
+ second(1000),
+ /**
+ * 分钟单位
+ */
+ minute(1000 * 60);
+
+ // 枚举值对应的数值,表示时间单位转换成毫秒的值
+ int num;
+
+ // 枚举构造函数,用于初始化枚举值对应的数值
+ CACHE_UNIT(int val) {
+ num = val;
+ }
+ }
+ // ... 其他类成员和方法 ...
+}
+
+
+ private int pagesize = 10;
+ private boolean isCount = true;
+ private String currentPage;// 当前页
+ private String sortTitleText;// 排序字段ok
+ private String sortTypeText;// 排序类型ok
+ private String ruleText;// 查询条件
+ private String titles;// 结果集中展示的字段
+ private String tables;// 表名或者内建视图
+ private String userWhere;// 自定义查询条件
+ private DBSort defaultSort;// 默认排序条件
+ private String countSql;
+ protected static final Map resultCache = new HashMap();// 结果集合的缓存
+ private boolean DISTINCT = false;
+ private long cacheMillisecond;// 启用缓存(毫秒数):只要该数字大于0则表示启用,从缓存区读取数据如果缓存区没有数据则数据库查询并更新到缓冲区
+ protected List sort = new ArrayList();
+ protected List queryRule = new ArrayList();
+
+ /**
+ * 获得查询对象实例
+ *
+ * @param currentPage
+ * 当前页
+ * @param titles
+ * 展现字段
+ * @param tables
+ * 表描述
+ * @return
+ */
+ public static DataQuery getInstance(String currentPage, String titles, String tables) {
+ // 创建一个新的DataQuery实例
+ DataQuery query = new DataQuery();
+ // 设置当前页码
+ query.setCurrentPage(currentPage);
+ // 设置标题集合
+ query.setTitles(titles);
+ // 设置表名集合
+ query.setTables(tables);
+ // 返回配置好的DataQuery实例
+ return query;
+ }
+
+
+public static DataQuery getInstance(int currentPage, String titles, String tables) {
+ // 将int类型的currentPage转换为String类型
+ // 然后调用getInstance(String, String, String)方法获取DataQuery实例
+ return getInstance(String.valueOf(currentPage), titles, tables);
+}
+
+
+ /**
+ * 执行查询,该方法适用于sever中,没有对用于页面状态的序列化,没有缓存功能
+ *
+ * @param session
+ * @return
+ * @throws SQLException
+ */
+ public DataResult search(Session session) throws SQLException {
+ String key = null;
+ // -------------------缓存查询----------------------------
+ // 检查是否启用了缓存功能(缓存时间大于0表示启用)
+ if (cacheMillisecond > 0) {
+ // 生成查询的MD5键值,用于缓存识别
+ key = getQueryMD5Key(this);
+ // 确保键值生成成功
+ if (key != null) {
+ // 启用缓存功能
+ {
+ // 从缓存中获取数据结果
+ DataResult dr = resultCache.get(key);
+ // 检查是否在缓存中找到了数据结果
+ if (dr != null) {
+ // 计算缓存数据的时间差
+ long time = new Date().getTime() - dr.getCtime().getTime();
+ // 判断缓存数据是否在有效期内
+ if (time < cacheMillisecond) {
+ // 缓存数据有效,直接返回缓存结果
+ return dr;
+ } else {
+ // 缓存数据已超时,更新缓存时间
+ dr.setCtime(new Date());
+ // 即使超时也先返回过时的数据结果
+ // 同时启动一个新的线程来更新缓存数据
+ Searcher search = new Searcher(this);
+ Thread searchThread = new Thread(search);
+ searchThread.start();
+ return dr;
+ }
+ }
+ }
+ }
+ // 如果没有缓存或键值生成失败,将继续执行后续的数据库查询操作
+ }
+ // ...(此处省略了数据库查询的代码)
+ }
+
+// 缓存中超出缓存最大值的时候就将缓存清空
+// 检查缓存大小是否超过预设的最大值
+if (resultCache.size() > CACHE_MAX_SIZE) {
+ // 如果超过,清空缓存以防止内存溢出
+ resultCache.clear();
+}
+// 结束缓存大小检查的代码块
+
+// -------------------缓存查询----------------------------
+// 检查排序条件是否为空
+ if (sort.size() <= 0) {
+ // 如果为空,添加默认排序条件
+ sort.add(defaultSort);
+}
+
+// 初始化数据结果对象
+DataResult result = null;
+try {
+// 创建搜索器对象,用于执行查询操作
+Searcher search = new Searcher(this);
+// 执行查询并获取结果
+result = search.doSearch(session);
+// 设置结果集的标题
+ result.setTitles(DataResults.getTitles(titles));
+ // 设置排序标题文本
+ result.setSortTitleText(sortTitleText);
+// 设置排序类型文本
+ result.setSortTypeText(sortTypeText);
+} catch (Exception e) {
+ // 如果在查询过程中发生异常,抛出SQLException
+ throw new SQLException(e);
+}
+
+// 检查是否启用了缓存功能
+ if (cacheMillisecond > 0) {
+ // 启用缓存功能,将当前结果存入缓存
+ if (key != null) {
+ // 设置结果集的创建时间
+ result.setCtime(new Date());
+ // 将结果集存入缓存,以键值对的形式
+ resultCache.put(key, result);
+ }
+ }
+
+// 返回查询结果
+ return result;
+
+
+/**
+ * 执行查询,序列化页面状态,可配置为缓存
+ *
+ * @return
+ * @throws SQLException
+ */
+public DataResult search() throws SQLException {
+ // 获取Hibernate会话对象,用于数据库操作
+ Session session = HibernateSessionFactory.getSession();
+ // 初始化数据结果对象
+ DataResult result = null;
+ try {
+ // 调用重载的search方法,传入会话对象,执行查询并获取结果
+ result = search(session);
+ } finally {
+ // 无论查询过程中是否发生异常,都确保关闭会话对象,释放资源
+ session.close();
+ }
+ // 返回查询结果
+ return result;
+}
+
+
+/**
+ * 将查询对象转换为MD5验证码
+ *
+ * @param query
+ * @return
+ */
+protected static String getQueryMD5Key(DataQuery query) {
+ // 初始化SQL字符串
+ String sql = "";
+ try {
+ // 使用HibernateQueryHandle解析DataQuery对象为SQL语句,并附加当前页码信息
+ sql = HibernateQueryHandle.praseSQL(query) + ",PAGE:" + query.getCurrentPage();
+ // 获取认证接口实例
+ AuthenticateInter ai = AuthenticateProvider.getInstance();
+ // 使用认证接口的encodeMd5方法对SQL语句进行MD5编码
+ sql = ai.encodeMd5(sql);
+ } catch (SQLException e) {
+ // 如果在解析SQL或编码过程中发生SQLException,记录错误日志
+ log.error(e + e.getMessage());
+ // 返回null,表示无法生成MD5键
+ return null;
+ }
+ // 返回编码后的MD5字符串,作为查询的键
+ return sql;
+}
+
+
+/**
+ * 添加一个排序
+ *
+ * @param dbsort
+ * @return
+ */
+public DataQuery addSort(DBSort dbsort) {
+ // 将给定的DBSort对象添加到排序列表中
+ sort.add(dbsort);
+ // 返回当前DataQuery对象,以支持链式调用
+ return this;
+}
+
+ /**
+ * 添加一个默认排序
+ *
+ * @param dbsort
+ * @return
+ */
+ public DataQuery addDefaultSort(DBSort dbsort) {
+ // 设置默认的排序规则为给定的DBSort对象
+ defaultSort = dbsort;
+ // 返回当前DataQuery对象,以支持链式调用
+ return this;
+ }
+
+
+/**
+ * 清除排序
+ *
+ * @param sort
+ */
+/**
+ * 清除所有排序规则
+ *
+ * @return 当前DataQuery对象,支持链式调用
+ */
+public DataQuery clearSort() {
+ // 清空排序规则列表
+ this.sort.clear();
+ // 返回当前对象,以便进行链式调用
+ return this;
+}
+
+/**
+ * 添加一个过滤条件
+ *
+ * @param rule 要添加的DBRule对象
+ * @return 当前DataQuery对象,支持链式调用
+ */
+public DataQuery addRule(DBRule rule) {
+ // 对规则值进行病毒清理,确保安全性
+ DataQuerys.wipeVirus(rule.getValue());
+ // 将规则添加到查询规则列表中
+ this.queryRule.add(rule);
+ // 返回当前对象,以便进行链式调用
+ return this;
+}
+
+/**
+ * 获得一个查询条件并从query中移除该条件
+ *
+ * @param index 查询条件索引号
+ * @return 被移除的DBRule对象
+ */
+public DBRule getAndRemoveRule(int index) {
+ // 获取指定索引的查询条件
+ DBRule dbrule = this.queryRule.get(index);
+ // 从查询规则列表中移除该条件
+ queryRule.remove(index);
+ // 重新解析剩余的规则,更新规则文本
+ ruleText = parseRules();
+ // 返回被移除的规则对象
+ return dbrule;
+}
+
+/**
+ * 获得一个查询条件并从query中移除该条件,每次获得匹配到得第一个titleName 查询条件字段名
+ *
+ * @param titleName 查询条件字段名
+ * @return 被移除的DBRule对象,如果没有找到则返回null
+ */
+public DBRule getAndRemoveRule(String titleName) {
+ // 初始化索引为-1,表示未找到
+ int n = -1;
+ // 遍历查询规则列表,寻找匹配的规则
+ for (int i = 0; i < queryRule.size(); i++) {
+ // 如果规则键(字段名)与指定的titleName匹配(不区分大小写)
+ if (queryRule.get(i).getKey().equals(titleName.toUpperCase())) {
+ // 记录匹配规则的索引
+ n = i;
+ // 找到第一个匹配的规则后退出循环
+ break;
+ }
+ }
+ // 如果找到了匹配的规则
+ if (n >= 0) {
+ // 调用getAndRemoveRule(int index)方法移除并返回规则
+ return getAndRemoveRule(n);
+ }
+ // 如果没有找到匹配的规则,返回null
+ return null;
+}
+
+
+ /**
+ * 将条件对象集合转换为条件字符串
+ *
+ * @return
+ */
+ private String parseRules() {
+ // 初始化一个StringBuffer用于构建查询规则字符串
+ StringBuffer sb = null;
+ // 遍历查询规则列表
+ for (DBRule node : queryRule) {
+ // 如果StringBuffer尚未初始化,则进行初始化
+ if (sb == null) {
+ sb = new StringBuffer();
+ } else {
+ // 如果StringBuffer已经包含内容,则在添加新规则前添加分隔符"_,_"
+ sb.append("_,_");
+ }
+ // 添加规则的键(字段名)
+ sb.append(node.getKey());
+ // 添加规则的比较符号
+ sb.append(":");
+ sb.append(node.getComparaSign());
+ // 添加规则的值
+ sb.append(":");
+ sb.append(node.getValue());
+ }
+ // 如果没有规则被添加,返回空字符串
+ if (sb == null) {
+ return "";
+ } else {
+ // 否则,返回构建好的查询规则字符串
+ return sb.toString();
+ }
+ }
+
+
+/**
+ * 清除排序
+ *
+ * @param sort
+ */
+public DataQuery clearRule() {
+ // 清空查询规则列表,移除所有已设置的查询条件
+ this.queryRule.clear();
+ // 返回当前对象,以便进行链式调用,继续其他操作
+ return this;
+}
+
+
+/**
+ * 是否在SQL中加入distinct
+ *
+ * @param var
+ * true||false
+ */
+public DataQuery setDistinct(boolean var) {
+ // 设置DISTINCT标志,以指示查询是否应返回唯一记录
+ DISTINCT = var;
+ // 返回当前对象,以便进行链式调用,继续其他配置或操作
+ return this;
+}
+
+ /**
+ * 是否加入了distinct关键字
+ *
+ * @return
+ */
+ public boolean isDistinct() {
+ return DISTINCT;
+ }
+
+ // pojo-------------------------------
+ /**
+ * 获得每页记录条数
+ *
+ * @return
+ */
+ public int getPagesize() {
+ return pagesize;
+ }
+
+ /**
+ * 设置每页记录条数
+ *
+ * @param pagesize
+ */
+ public DataQuery setPagesize(int pagesize) {
+ this.pagesize = pagesize;
+ return this;
+ }
+
+ /**
+ * 获得当前页
+ *
+ * @return
+ */
+ public String getCurrentPage() {
+ // 检查currentPage是否为空或只包含空白字符
+ if (currentPage == null || currentPage.trim().length() <= 0) {
+ // 如果为空或只包含空白字符,返回默认页码"1"
+ return "1";
+ }
+ // 否则,返回当前页码
+ return currentPage;
+ }
+
+ /**
+ * 设置当前页
+ *
+ * @param currentPage
+ */
+ public DataQuery setCurrentPage(String currentPage) {
+ // 将传入的页码字符串设置到当前对象的currentPage属性中
+ this.currentPage = currentPage;
+ // 返回当前对象,以便进行链式调用,继续其他配置或操作
+ return this;
+ }
+
+ /**
+ * 设置当前页
+ *
+ * @param currentPage
+ */
+ public DataQuery setCurrentPage(int currentPage) {
+ // 将传入的整数值页码转换为字符串,并设置到当前对象的currentPage属性中
+ this.currentPage = String.valueOf(currentPage);
+ // 返回当前对象,以便进行链式调用,继续其他配置或操作
+ return this;
+ }
+
+ /**
+ * 获得排序字段
+ *
+ * @return
+ */
+ public String getSortTitleText() {
+ return sortTitleText;
+ }
+
+ /**
+ * 获得排序类型
+ *
+ * @return
+ */
+ public String getSortTypeText() {
+ return sortTypeText;
+ }
+
+ /**
+ * 设置排序字段,但是会清理掉已有排序
+ *
+ * @param sortTitleText
+ */
+ public void setSortTitleText(String sortTitleText) {
+ // 设置排序标题文本
+ this.sortTitleText = sortTitleText;
+ // 检查排序标题文本和排序类型文本是否都非空
+ if (this.sortTitleText != null && this.sortTypeText != null) {
+ // 清除原有的排序规则
+ sort.clear();
+ // 创建新的DBSort对象并添加到排序列表中
+ sort.add(new DBSort(this.sortTitleText, this.sortTypeText));
+ }
+ }
+
+ /**
+ * 设置排序类型
+ *
+ * @param sortTypeText
+ * ASC||DESC
+ */
+/**
+ * 设置排序类型文本。
+ * 如果传入的排序类型文本为"NULL"(不区分大小写且去除空格),则将其视为null。
+ * 当排序标题文本和排序类型文本都非空时,根据这两个值创建一个新的DBSort对象,
+ * 并将其添加到排序列表中,同时清除原有的排序规则。
+ *
+ * @param sortTypeText 要设置的排序类型文本。
+ */
+public void setSortTypeText(String sortTypeText) {
+ // 检查传入的排序类型文本是否为"NULL",如果是,则将其设置为null
+ if (sortTypeText != null && sortTypeText.toUpperCase().trim().equals("NULL")) {
+ sortTypeText = null;
+ }
+ // 设置排序类型文本
+ this.sortTypeText = sortTypeText;
+ // 检查排序标题文本和排序类型文本是否都非空
+ if (this.sortTitleText != null && this.sortTypeText != null) {
+ // 清除原有的排序规则
+ sort.clear();
+ // 创建新的DBSort对象并添加到排序列表中
+ sort.add(new DBSort(this.sortTitleText, this.sortTypeText));
+ }
+}
+
+
+/**
+ * 获得条件描述字符串
+ *
+ * @return
+ */
+ public String getRuleText() {
+ return ruleText;
+ }
+
+ /**
+ * 设置查询条件,但是会清理掉已有条件
+ *
+ * @param ruleText
+ * 查询条件
+ */
+/**
+ * 设置查询规则文本,并解析文本以构建查询规则列表。
+ * 规则文本格式预期为 "字段名:操作符:值",多个规则用 "_,_" 分隔。
+ * 如果规则文本不符合预期格式或为空,则清空查询规则列表。
+ *
+ * @param ruleText 要设置的查询规则文本。
+ */
+public void setRuleText(String ruleText) {
+ // 设置查询规则文本
+ this.ruleText = ruleText;
+ // 初始化查询规则列表
+ List list = null;
+ // 检查规则文本是否符合限制域的要求
+ if (!checkStringForLimitDomain(ruleText)) {
+ // 如果不符合,初始化为空列表
+ list = new ArrayList();
+ } else {
+ // 替换规则文本中的占位符 "_D_" 为 ":"
+ ruleText = ruleText.replace("_D_", ":");
+ // 按照规则分隔符 "_,_" 分割规则文本
+ String[] strarray = ruleText.split("_,_");
+ // 初始化查询规则列表
+ list = new ArrayList();
+ // 遍历分割后的规则字符串数组
+ for (String onestr : strarray) {
+ // 检查规则字符串是否非空
+ if (onestr != null && !onestr.trim().equals("")) {
+ // 按照 ":" 分割规则字符串
+ String[] valueT = onestr.split(":");
+ // 检查分割后的数组长度及元素非空
+ if (valueT.length >= 3 && valueT[0] != null && valueT[1] != null && valueT[2] != null) {
+ // 检查字段名、操作符、值均非空
+ if (!valueT[0].equals("") && !valueT[1].equals("") && !valueT[2].equals("")) {
+ // 创建DBRule对象并添加到列表
+ DBRule dbrule = new DBRule(valueT[0], valueT[2], valueT[1]);
+ list.add(dbrule);
+ }
+ }
+ }
+ }
+ }
+ // 清空现有的查询规则列表
+ queryRule.clear();
+ // 将解析后的查询规则列表添加到查询规则中
+ queryRule.addAll(list);
+}
+
+
+/**
+ * 获得结果集字段
+ *
+ * @return
+ */
+ public String getTitles() {
+ return titles;
+ }
+
+ /**
+ * 设置结果集字段
+ *
+ * @return
+ */
+ public void setTitles(String titles) {
+ this.titles = titles;
+ }
+
+ /**
+ * 获得表描述
+ *
+ * @return
+ */
+ public String getTables() {
+ return tables;
+ }
+
+ /**
+ * 设置表描述
+ *
+ * @param tables
+ */
+ public void setTables(String tables) {
+ this.tables = tables;
+ }
+
+
+/**
+ * 检查字符串是否为限制域内的有效字符串。
+ * 当前实现仅检查字符串是否为null。
+ * 如果字符串为null,则视为无效,返回false;否则,视为有效,返回true。
+ * 此方法可以扩展以包含更多的检查逻辑,例如字符串长度、格式等。
+ *
+ * @param str 要检查的字符串。
+ * @return 如果字符串有效(非null),则返回true;否则返回false。
+ */
+private boolean checkStringForLimitDomain(String str) {
+ // 检查字符串是否为null
+ if (str == null)
+ return false;
+ else
+ return true;
+}
+
+
+/**
+ * 获得用户自定义查询条件
+ *
+ * @return
+ */
+ public String getUserWhere() {
+ return userWhere;
+ }
+
+ /**
+ * 设置自定义条件
+ *
+ * @param userWhere
+ * 需要添加 AND关键字
+ */
+ public void setSqlRule(String sql) {
+ this.userWhere = sql;
+ }
+
+ /**
+ * 增加自定义条件
+ *
+ * @param userWhere
+ * 需要添加 AND关键字
+ */
+ public DataQuery addSqlRule(String SQLString) {
+ // 如果当前查询条件为null,则初始化为空字符串
+ if (this.userWhere == null) {
+ this.userWhere = "";
+ }
+ // 将传入的SQL字符串追加到查询条件中
+ this.userWhere = this.userWhere + SQLString;
+ // 返回当前对象,支持链式调用
+ return this;
+ }
+
+ /**
+ * 初始化查询类
+ *
+ * @param query
+ * 对象引用
+ * @param tables
+ * 表
+ * @param titles
+ * 字段
+ */
+ public static DataQuery init(DataQuery query, String tables, String titles) {
+ // 如果传入的query对象为null,则创建一个新的DataQuery对象
+ if (query == null) {
+ query = new DataQuery();
+ }
+ // 设置查询的表名
+ query.setTables(tables);
+ // 设置查询的标题字段
+ query.setTitles(titles);
+ // 如果排序类型未设置,则默认设置为"asc"(升序)
+ if (query.sortTypeText == null) {
+ query.sortTypeText = "asc";
+ }
+ // 如果当前页码未设置,则默认设置为第一页
+ if (query.getCurrentPage() == null) {
+ query.setCurrentPage("1");
+ }
+ // 删除所有排序字段不合乎要求的
+ {
+ int n = 0;
+ List indexArray = new ArrayList();
+ // 遍历排序字段列表,检查每个排序字段是否有效
+ for (; n < query.sort.size(); n++) {
+ // 如果排序字段的标题为null或等于"NULL"(不区分大小写),则记录该字段的索引
+ if (query.sort.get(n).getSortTitleText() == null
+ || query.sort.get(n).getSortTitleText().trim().toUpperCase().equals("NULL")) {
+ indexArray.add(n);
+ }
+ }
+ // 遍历记录的索引列表,移除无效的排序字段
+ for (Integer index : indexArray) {
+ query.sort.remove(index.intValue());
+ }
+ }
+
+ // 返回初始化后的DataQuery对象
+ return query;
+ }
+
+/**
+ * 获得默认排序
+ *
+ * @return
+ */
+ public DBSort getDefaultSort() {
+ return defaultSort;
+ }
+
+ /**
+ * 设置数据缓存
+ *
+ * @param cachetime
+ * 缓存时间长
+ * @param cache_unit
+ * 缓存时间单位
+ */
+ public void setCache(int cachetime, CACHE_UNIT cache_unit) {
+ this.cacheMillisecond = cachetime * cache_unit.num;
+ }
+
+ /**
+ * 设置默认排序
+ *
+ * @param defaultSort
+ */
+ public void setDefaultSort(DBSort defaultSort) {
+ this.defaultSort = defaultSort;
+ }
+
+ /**
+ * 获得查询条件格式序列
+ *
+ * @return
+ */
+ public List getQueryRule() {
+ return queryRule;
+ }
+
+ /**
+ * 只查询结果不计算总页数
+ */
+ public void setNoCount() {
+ this.isCount = false;
+ }
+
+ /**
+ * 是执行记录条数统计COUNT(*)的SQL语句
+ *
+ * @return
+ */
+ public boolean isCount() {
+ return isCount;
+ }
+
+ public String getCountSql() {
+ return countSql;
+ }
+
+ /**
+ * 如果传入该参数则按照该SQL进行结果集数量查询
+ *
+ * @param countSql
+ */
+ public void setCountSql(String countSql) {
+ this.countSql = countSql;
+ }
+
+ /**
+ * 获取一个查询条件
+ *
+ * @param string
+ * @return
+ */
+ public String getRule(String key) {
+ // 遍历查询规则列表
+ for (DBRule rule : this.queryRule) {
+ // 检查当前规则的键是否与指定键相匹配
+ if (rule.getKey().equals(key)) {
+ // 如果匹配,返回当前规则的值
+ return rule.getValue();
+ }
+ }
+ // 如果没有找到匹配的键,返回null
+ return null;
+ }
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/sql/query/DataQuerys.java b/src/farm-core/src/main/java/com/farm/core/sql/query/DataQuerys.java
new file mode 100644
index 0000000..f3b4060
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/sql/query/DataQuerys.java
@@ -0,0 +1,54 @@
+package com.farm.core.sql.query;
+
+import java.util.Collection;
+
+import org.apache.commons.lang.StringEscapeUtils;
+
+/**
+ * 查询工具工具类
+ *
+ * @author Administrator
+ *
+ */
+public class DataQuerys {
+ /**
+ * 检查SQL注入风险
+ *
+ * @param var
+ * 拼写SQL的值,仅仅用于对值的处理
+ */
+ public static void wipeVirus(String var) {
+ // 使用StringEscapeUtils工具类对字符串进行SQL转义,以防止SQL注入
+ var = StringEscapeUtils.escapeSql(var);
+
+ // 检查字符串中是否包含括号或连续的竖线符号,这些可能是SQL注入的标志
+ // 如果发现这些字符,计算它们的索引之和将会大于0
+ if (var.indexOf("(") + var.indexOf(")") + var.indexOf("||") + var.indexOf("||") > 0) {
+ // 如果检测到潜在的SQL注入风险,抛出运行时异常
+ throw new RuntimeException("违反SQL注入风险约束!");
+ }
+ }
+
+ /**
+ * 解析一个id的集合为多id的字符串拼接,可以用于sql的in子句如:'id1','id2'...
+ *
+ * @param vars
+ * @return
+ */
+ public static String parseSqlValues(Collection vars) {
+ // 初始化用于存储SQL值列表的字符串
+ String typeids_Rule = null;
+ // 遍历集合中的每个字符串元素
+ for (String typeid : vars) {
+ // 如果是第一个元素,直接用单引号包裹
+ if (typeids_Rule == null) {
+ typeids_Rule = "'" + typeid + "'";
+ } else {
+ // 如果不是第一个元素,前面加上逗号,然后用单引号包裹
+ typeids_Rule = typeids_Rule + "," + "'" + typeid + "'";
+ }
+ }
+ // 返回构建好的SQL值列表字符串
+ return typeids_Rule;
+ }
+}
diff --git a/src/farm-core/src/main/java/com/farm/core/sql/query/HibernateQueryHandle.java b/src/farm-core/src/main/java/com/farm/core/sql/query/HibernateQueryHandle.java
new file mode 100644
index 0000000..be6d7b8
--- /dev/null
+++ b/src/farm-core/src/main/java/com/farm/core/sql/query/HibernateQueryHandle.java
@@ -0,0 +1,281 @@
+package com.farm.core.sql.query;
+
+import java.sql.SQLException;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.hibernate.SQLQuery;
+import org.hibernate.Session;
+
+import com.farm.core.sql.result.DataResult;
+import com.farm.core.sql.result.DataResults;
+
+/**
+ * hibernate的帮助类
+ *
+ * @author 王东
+ * @date 2012-12-30
+ */
+public class HibernateQueryHandle {
+ private static final String SqlSelectSize = " select count(*) num "; // 默认查询数量头
+
+ /**
+ * sql查询
+ *
+ * @param session
+ * hibernateSession
+ * @param sql
+ * @param pagesize
+ * 每页多少条
+ * @param currentPage
+ * 当前页
+ * @return
+ * @throws SQLException
+ */
+ protected static DataResult runSqlQuery(Session session, String querysql,
+ String countsql, int pagesize, int currentPage) throws SQLException {
+ long startTime = new Date().getTime(); // 记录查询开始时间
+ if (querysql.indexOf("*") > 0) {
+ throw new SQLException("*不能存在于查询语句中,请明确查询字段!"); // 如果查询语句中包含*,则抛出异常,要求明确查询字段
+ }
+ querysql = querysql.toUpperCase(); // 将查询语句转换为大写,以统一处理
+ DataResult result = null; // 初始化结果对象
+ int firstResourt; // 开始条数,即查询结果的起始索引
+ int sizeResourt; // 单页显示的记录数
+ sizeResourt = pagesize; // 设置单页显示的记录数
+ firstResourt = (currentPage - 1) * sizeResourt; // 计算查询结果的起始索引
+ String titles = querysql.substring(0, querysql.indexOf("FROM")); // 从查询语句中提取字段部分
+ List
", "。");
+ html = html.replaceAll("([!。!;;]+)\\s*\\。", "$1");
+ html = html.replaceAll("\\s{2,}", " ");
+ html = html.replaceAll("
]*?>[\\s\\S]*?<\\/script>
+ // }
+ String regEx_style = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>"; // 定义style的正则表达式{或