diff --git a/center.manager/src/main/java/com/lyms/cm/controller/sys/SysRemoteController.java b/center.manager/src/main/java/com/lyms/cm/controller/sys/SysRemoteController.java index 5c7bf49..bfbbd35 100644 --- a/center.manager/src/main/java/com/lyms/cm/controller/sys/SysRemoteController.java +++ b/center.manager/src/main/java/com/lyms/cm/controller/sys/SysRemoteController.java @@ -4,31 +4,29 @@ import java.io.IOException; import javax.servlet.http.HttpServletRequest; +import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; -import com.lyms.cm.entity.sys.SysUsers; +import com.lyms.synch.ParamsHandler; +import com.lyms.synch.SycnHandler; import com.lyms.synch.SyncUtils; -import com.lyms.synch.entity.AckObj; -import com.lyms.synch.entity.SyncnModel; +import com.lyms.synch.entity.ChannelData; import com.lyms.web.controller.BaseController; @Controller @RequestMapping("/remote") +@Deprecated public class SysRemoteController extends BaseController { - @RequestMapping(value = "/push") + @RequestMapping(value = "/sycn", produces = { MediaType.APPLICATION_JSON_VALUE }) @ResponseBody - public String push(HttpServletRequest request) throws ClassNotFoundException, IOException { - SyncnModel model = SyncUtils.conver(request); - if (model.isAck()) { - AckObj ack = SyncUtils.converDataToAck(model); - System.out.println("回执信息: " + ack.getData()); - } else { - SysUsers user = SyncUtils.converData(model, SysUsers.class); - System.out.println("user: " + user.getName()); - } - return "OK"; + public Object push(HttpServletRequest request) throws ClassNotFoundException, IOException { + ChannelData model = SyncUtils.conver(request); + Object object = SycnHandler.handler(model); + model.setData(ParamsHandler.builder().push(object).toJsonString()); + model.setAck(true); + return model; } } diff --git a/center.manager/src/main/java/com/lyms/cm/dao/sys/SysRegionsMapper.xml b/center.manager/src/main/java/com/lyms/cm/dao/sys/SysRegionsMapper.xml index c949c49..bf1fa0a 100644 --- a/center.manager/src/main/java/com/lyms/cm/dao/sys/SysRegionsMapper.xml +++ b/center.manager/src/main/java/com/lyms/cm/dao/sys/SysRegionsMapper.xml @@ -30,5 +30,5 @@ re.PARENT_ID=#{id} - + diff --git a/center.manager/src/main/java/com/lyms/cm/job/SycnFixJob.java b/center.manager/src/main/java/com/lyms/cm/job/SycnFixJob.java new file mode 100644 index 0000000..d31c4cb --- /dev/null +++ b/center.manager/src/main/java/com/lyms/cm/job/SycnFixJob.java @@ -0,0 +1,75 @@ +package com.lyms.cm.job; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +import com.lyms.synch.ParamsHandler; +import com.lyms.synch.SycnHandler; +import com.lyms.synch.SyncCallback; +import com.lyms.synch.SyncnCenter; +import com.lyms.synch.SyncnCenter.Work; +import com.lyms.synch.entity.ChannelData; +import com.lyms.util.HttpUtils; +import com.lyms.util.JsonUtils; + +/** + *
- * 跟 {@link #ackGet(Map)} {@link #ackPost(Map)} 的区别是,后两者需要自己设定callback - * 地址跟参数,可以指定任意地址 + * 该方法只有跟 {@link #pullFix(SyncCallback)} {@link #pullTmp(SyncCallback)} + * 才有意义 *
- * 使用方式 pull(type,callBack).ackGet(); - *
- * 目前该方法对PULL 的消息回执才有实际的意义 - *
- * TODO - *
- * 使用方式 push(model,callBack).validata(); - *
- * {@link ModelType#GET} 该参数将会获取固定任务列表中的数据{@link ModelType} 其他参数将会获取临时列表中数据 *
null
*
- * @param str 被转换的字符串
+ * @param str
+ * 被转换的字符串
* @return 转换后的字符串
*/
public static String emptyToNull(String str) {
@@ -193,7 +206,8 @@ public class StrUtils {
/**
* 是否包含空字符串
*
- * @param strs 字符串列表
+ * @param strs
+ * 字符串列表
* @return 是否包含空字符串
*/
public static boolean hasEmpty(String... strs) {
@@ -212,7 +226,8 @@ public class StrUtils {
/**
* 是否全部为空字符串
*
- * @param strs 字符串列表
+ * @param strs
+ * 字符串列表
* @return 是否全部为空字符串
*/
public static boolean isAllEmpty(String... strs) {
@@ -228,12 +243,14 @@ public class StrUtils {
return true;
}
- // ------------------------------------------------------------------------ Trim
+ // ------------------------------------------------------------------------
+ // Trim
/**
* 除去字符串头尾部的空白,如果字符串是null,依然返回null。
*
*
- * 注意,和String.trim不同,此方法使用Character.isWhitespace 来判定空白, 因而可以除去英文字符集之外的其它空白,如中文空格。
+ * 注意,和String.trim不同,此方法使用Character.isWhitespace
+ * 来判定空白, 因而可以除去英文字符集之外的其它空白,如中文空格。
*
*
* trim(null) = null
@@ -245,7 +262,8 @@ public class StrUtils {
*
*
*
- * @param str 要处理的字符串
+ * @param str
+ * 要处理的字符串
*
* @return 除去空白的字符串,如果原字串为null,则返回null
*/
@@ -256,7 +274,8 @@ public class StrUtils {
/**
* 给定字符串数组全部做去首尾空格
*
- * @param strs 字符串数组
+ * @param strs
+ * 字符串数组
*/
public static void trim(String[] strs) {
if (null == strs) {
@@ -275,7 +294,8 @@ public class StrUtils {
* 除去字符串头部的空白,如果字符串是null,则返回null。
*
*
- * 注意,和String.trim不同,此方法使用Character.isWhitespace 来判定空白, 因而可以除去英文字符集之外的其它空白,如中文空格。
+ * 注意,和String.trim不同,此方法使用Character.isWhitespace
+ * 来判定空白, 因而可以除去英文字符集之外的其它空白,如中文空格。
*
*
* trimStart(null) = null
@@ -288,9 +308,11 @@ public class StrUtils {
*
*
*
- * @param str 要处理的字符串
+ * @param str
+ * 要处理的字符串
*
- * @return 除去空白的字符串,如果原字串为null或结果字符串为"",则返回 null
+ * @return 除去空白的字符串,如果原字串为null或结果字符串为"",则返回
+ * null
*/
public static String trimStart(String str) {
return trim(str, -1);
@@ -300,7 +322,8 @@ public class StrUtils {
* 除去字符串尾部的空白,如果字符串是null,则返回null。
*
*
- * 注意,和String.trim不同,此方法使用Character.isWhitespace 来判定空白, 因而可以除去英文字符集之外的其它空白,如中文空格。
+ * 注意,和String.trim不同,此方法使用Character.isWhitespace
+ * 来判定空白, 因而可以除去英文字符集之外的其它空白,如中文空格。
*
*
* trimEnd(null) = null
@@ -313,9 +336,11 @@ public class StrUtils {
*
*
*
- * @param str 要处理的字符串
+ * @param str
+ * 要处理的字符串
*
- * @return 除去空白的字符串,如果原字串为null或结果字符串为"",则返回 null
+ * @return 除去空白的字符串,如果原字串为null或结果字符串为"",则返回
+ * null
*/
public static String trimEnd(String str) {
return trim(str, 1);
@@ -324,8 +349,11 @@ public class StrUtils {
/**
* 除去字符串头尾部的空白符,如果字符串是null,依然返回null。
*
- * @param str 要处理的字符串
- * @param mode -1表示trimStart,0表示trim全部, 1表示trimEnd
+ * @param str
+ * 要处理的字符串
+ * @param mode
+ * -1表示trimStart,0表示trim全部,
+ * 1表示trimEnd
*
* @return 除去指定字符后的的字符串,如果原字串为null,则返回null
*/
@@ -358,46 +386,57 @@ public class StrUtils {
return str;
}
-
+
/**
* 是否以指定字符串开头
- * @param str 被监测字符串
- * @param prefix 开头字符串
- * @param isIgnoreCase 是否忽略大小写
+ *
+ * @param str
+ * 被监测字符串
+ * @param prefix
+ * 开头字符串
+ * @param isIgnoreCase
+ * 是否忽略大小写
* @return 是否以指定字符串开头
*/
- public static boolean startWith(String str, String prefix, boolean isIgnoreCase){
- if(isIgnoreCase){
+ public static boolean startWith(String str, String prefix, boolean isIgnoreCase) {
+ if (isIgnoreCase) {
return str.toLowerCase().startsWith(prefix.toLowerCase());
- }else{
+ } else {
return str.startsWith(prefix);
}
}
-
+
/**
* 是否以指定字符串结尾
- * @param str 被监测字符串
- * @param suffix 结尾字符串
- * @param isIgnoreCase 是否忽略大小写
+ *
+ * @param str
+ * 被监测字符串
+ * @param suffix
+ * 结尾字符串
+ * @param isIgnoreCase
+ * 是否忽略大小写
* @return 是否以指定字符串结尾
*/
- public static boolean endWith(String str, String suffix, boolean isIgnoreCase){
- if(isIgnoreCase){
+ public static boolean endWith(String str, String suffix, boolean isIgnoreCase) {
+ if (isIgnoreCase) {
return str.toLowerCase().endsWith(suffix.toLowerCase());
- }else{
+ } else {
return str.endsWith(suffix);
}
}
-
+
/**
* 是否包含特定字符,忽略大小写,如果给定两个参数都为null,返回true
- * @param str 被检测字符串
- * @param testStr 被测试是否包含的字符串
+ *
+ * @param str
+ * 被检测字符串
+ * @param testStr
+ * 被测试是否包含的字符串
* @return 是否包含
*/
- public static boolean containsIgnoreCase(String str, String testStr){
- if(null == str){
- //如果被监测字符串和
+ public static boolean containsIgnoreCase(String str, String testStr) {
+ if (null == str) {
+ // 如果被监测字符串和
return null == testStr;
}
return str.toLowerCase().contains(testStr.toLowerCase());
@@ -421,7 +460,8 @@ public class StrUtils {
* 生成set方法名
* 例如:name 返回 setName
*
- * @param fieldName 属性名
+ * @param fieldName
+ * 属性名
* @return setXxx
*/
public static String genSetter(String fieldName) {
@@ -431,7 +471,8 @@ public class StrUtils {
/**
* 生成get方法名
*
- * @param fieldName 属性名
+ * @param fieldName
+ * 属性名
* @return getXxx
*/
public static String genGetter(String fieldName) {
@@ -442,8 +483,10 @@ public class StrUtils {
* 去掉首部指定长度的字符串并将剩余字符串首字母小写
* 例如:str=setName, preLength=3 -> return name
*
- * @param str 被处理的字符串
- * @param preLength 去掉的长度
+ * @param str
+ * 被处理的字符串
+ * @param preLength
+ * 去掉的长度
* @return 处理后的字符串,不符合规范返回null
*/
public static String cutPreAndLowerFirst(String str, int preLength) {
@@ -463,8 +506,10 @@ public class StrUtils {
/**
* 原字符串首字母大写并在其首部添加指定字符串 例如:str=name, preString=get -> return getName
*
- * @param str 被处理的字符串
- * @param preString 添加的首部
+ * @param str
+ * 被处理的字符串
+ * @param preString
+ * 添加的首部
* @return 处理后的字符串
*/
public static String upperFirstAndAddPre(String str, String preString) {
@@ -478,7 +523,8 @@ public class StrUtils {
* 大写首字母
* 例如:str = name, return Name
*
- * @param str 字符串
+ * @param str
+ * 字符串
* @return 字符串
*/
public static String upperFirst(String str) {
@@ -489,11 +535,12 @@ public class StrUtils {
* 小写首字母
* 例如:str = Name, return name
*
- * @param str 字符串
+ * @param str
+ * 字符串
* @return 字符串
*/
public static String lowerFirst(String str) {
- if(isBlank(str)){
+ if (isBlank(str)) {
return str;
}
return Character.toLowerCase(str.charAt(0)) + str.substring(1);
@@ -502,15 +549,17 @@ public class StrUtils {
/**
* 去掉指定前缀
*
- * @param str 字符串
- * @param prefix 前缀
+ * @param str
+ * 字符串
+ * @param prefix
+ * 前缀
* @return 切掉后的字符串,若前缀不是 preffix, 返回原字符串
*/
public static String removePrefix(String str, String prefix) {
- if(isEmpty(str) || isEmpty(prefix)){
+ if (isEmpty(str) || isEmpty(prefix)) {
return str;
}
-
+
if (str.startsWith(prefix)) {
return str.substring(prefix.length());
}
@@ -520,15 +569,17 @@ public class StrUtils {
/**
* 忽略大小写去掉指定前缀
*
- * @param str 字符串
- * @param prefix 前缀
+ * @param str
+ * 字符串
+ * @param prefix
+ * 前缀
* @return 切掉后的字符串,若前缀不是 prefix, 返回原字符串
*/
public static String removePrefixIgnoreCase(String str, String prefix) {
- if(isEmpty(str) || isEmpty(prefix)){
+ if (isEmpty(str) || isEmpty(prefix)) {
return str;
}
-
+
if (str.toLowerCase().startsWith(prefix.toLowerCase())) {
return str.substring(prefix.length());
}
@@ -538,15 +589,17 @@ public class StrUtils {
/**
* 去掉指定后缀
*
- * @param str 字符串
- * @param suffix 后缀
+ * @param str
+ * 字符串
+ * @param suffix
+ * 后缀
* @return 切掉后的字符串,若后缀不是 suffix, 返回原字符串
*/
public static String removeSuffix(String str, String suffix) {
- if(isEmpty(str) || isEmpty(suffix)){
+ if (isEmpty(str) || isEmpty(suffix)) {
return str;
}
-
+
if (str.endsWith(suffix)) {
return str.substring(0, str.length() - suffix.length());
}
@@ -556,48 +609,56 @@ public class StrUtils {
/**
* 忽略大小写去掉指定后缀
*
- * @param str 字符串
- * @param suffix 后缀
+ * @param str
+ * 字符串
+ * @param suffix
+ * 后缀
* @return 切掉后的字符串,若后缀不是 suffix, 返回原字符串
*/
public static String removeSuffixIgnoreCase(String str, String suffix) {
- if(isEmpty(str) || isEmpty(suffix)){
+ if (isEmpty(str) || isEmpty(suffix)) {
return str;
}
-
+
if (str.toLowerCase().endsWith(suffix.toLowerCase())) {
return str.substring(0, str.length() - suffix.length());
}
return str;
}
-
+
/**
* 如果给定字符串不是以prefix开头的,在开头补充 prefix
- * @param str 字符串
- * @param prefix 前缀
+ *
+ * @param str
+ * 字符串
+ * @param prefix
+ * 前缀
* @return 补充后的字符串
*/
- public static String addPrefixIfNot(String str, String prefix){
- if(isEmpty(str) || isEmpty(prefix)){
+ public static String addPrefixIfNot(String str, String prefix) {
+ if (isEmpty(str) || isEmpty(prefix)) {
return str;
}
- if(false == str.startsWith(prefix)){
+ if (false == str.startsWith(prefix)) {
str = prefix + str;
}
return str;
}
-
+
/**
* 如果给定字符串不是以suffix结尾的,在尾部补充 suffix
- * @param str 字符串
- * @param suffix 后缀
+ *
+ * @param str
+ * 字符串
+ * @param suffix
+ * 后缀
* @return 补充后的字符串
*/
- public static String addSuffixIfNot(String str, String suffix){
- if(isEmpty(str) || isEmpty(suffix)){
+ public static String addSuffixIfNot(String str, String suffix) {
+ if (isEmpty(str) || isEmpty(suffix)) {
return str;
}
- if(false == str.endsWith(suffix)){
+ if (false == str.endsWith(suffix)) {
str += suffix;
}
return str;
@@ -606,7 +667,8 @@ public class StrUtils {
/**
* 清理空白字符
*
- * @param str 被清理的字符串
+ * @param str
+ * 被清理的字符串
* @return 清理后的字符串
*/
public static String cleanBlank(String str) {
@@ -622,8 +684,10 @@ public class StrUtils {
* a#b#c -> [a,b,c]
* a##b#c -> [a,"",b,c]
*
- * @param str 被切分的字符串
- * @param separator 分隔符字符
+ * @param str
+ * 被切分的字符串
+ * @param separator
+ * 分隔符字符
* @return 切分后的集合
*/
public static List split(String str, char separator) {
@@ -633,9 +697,12 @@ public class StrUtils {
/**
* 切分字符串
*
- * @param str 被切分的字符串
- * @param separator 分隔符字符
- * @param limit 限制分片数
+ * @param str
+ * 被切分的字符串
+ * @param separator
+ * 分隔符字符
+ * @param limit
+ * 限制分片数
* @return 切分后的集合
*/
public static List split(String str, char separator, int limit) {
@@ -674,8 +741,10 @@ public class StrUtils {
* 切分字符串
* from jodd
*
- * @param str 被切分的字符串
- * @param delimiter 分隔符
+ * @param str
+ * 被切分的字符串
+ * @param delimiter
+ * 分隔符
* @return 字符串
*/
public static String[] split(String str, String delimiter) {
@@ -714,9 +783,12 @@ public class StrUtils {
* index从0开始计算,最后一个字符为-1
* 如果from和to位置一样,返回 "" example: abcdefgh 2 3 -> c abcdefgh 2 -3 -> cde
*
- * @param string String
- * @param fromIndex 开始的index(包括)
- * @param toIndex 结束的index(不包括)
+ * @param string
+ * String
+ * @param fromIndex
+ * 开始的index(包括)
+ * @param toIndex
+ * 结束的index(不包括)
* @return 字串
*/
public static String sub(String string, int fromIndex, int toIndex) {
@@ -752,8 +824,10 @@ public class StrUtils {
/**
* 切割前部分
*
- * @param string 字符串
- * @param toIndex 切割到的位置(不包括)
+ * @param string
+ * 字符串
+ * @param toIndex
+ * 切割到的位置(不包括)
* @return 切割后的字符串
*/
public static String subPre(String string, int toIndex) {
@@ -763,8 +837,10 @@ public class StrUtils {
/**
* 切割后部分
*
- * @param string 字符串
- * @param fromIndex 切割开始的位置(包括)
+ * @param string
+ * 字符串
+ * @param fromIndex
+ * 切割开始的位置(包括)
* @return 切割后的字符串
*/
public static String subSuf(String string, int fromIndex) {
@@ -777,9 +853,12 @@ public class StrUtils {
/**
* 给定字符串是否被字符包围
*
- * @param str 字符串
- * @param prefix 前缀
- * @param suffix 后缀
+ * @param str
+ * 字符串
+ * @param prefix
+ * 前缀
+ * @param suffix
+ * 后缀
* @return 是否包围,空串不包围
*/
public static boolean isSurround(String str, String prefix, String suffix) {
@@ -796,9 +875,12 @@ public class StrUtils {
/**
* 给定字符串是否被字符包围
*
- * @param str 字符串
- * @param prefix 前缀
- * @param suffix 后缀
+ * @param str
+ * 字符串
+ * @param prefix
+ * 前缀
+ * @param suffix
+ * 后缀
* @return 是否包围,空串不包围
*/
public static boolean isSurround(String str, char prefix, char suffix) {
@@ -815,8 +897,10 @@ public class StrUtils {
/**
* 重复某个字符
*
- * @param c 被重复的字符
- * @param count 重复的数目
+ * @param c
+ * 被重复的字符
+ * @param count
+ * 重复的数目
* @return 重复字符字符串
*/
public static String repeat(char c, int count) {
@@ -830,8 +914,10 @@ public class StrUtils {
/**
* 重复某个字符串
*
- * @param str 被重复的字符
- * @param count 重复的数目
+ * @param str
+ * 被重复的字符
+ * @param count
+ * 重复的数目
* @return 重复字符字符串
*/
public static String repeat(String str, int count) {
@@ -865,8 +951,10 @@ public class StrUtils {
* equals("abc", "ABC") = false
*
*
- * @param str1 要比较的字符串1
- * @param str2 要比较的字符串2
+ * @param str1
+ * 要比较的字符串1
+ * @param str2
+ * 要比较的字符串2
*
* @return 如果两个字符串相同,或者都是null,则返回true
*/
@@ -889,8 +977,10 @@ public class StrUtils {
* equalsIgnoreCase("abc", "ABC") = true
*
*
- * @param str1 要比较的字符串1
- * @param str2 要比较的字符串2
+ * @param str1
+ * 要比较的字符串1
+ * @param str2
+ * 要比较的字符串2
*
* @return 如果两个字符串相同,或者都是null,则返回true
*/
@@ -904,10 +994,12 @@ public class StrUtils {
/**
* 格式化文本, {} 表示占位符
- * 例如:format("aaa {} ccc", "bbb") ----> aaa bbb ccc
+ * 例如:format("aaa {} ccc", "bbb") ----> aaa bbb ccc
*
- * @param template 文本模板,被替换的部分用 {} 表示
- * @param values 参数值
+ * @param template
+ * 文本模板,被替换的部分用 {} 表示
+ * @param values
+ * 参数值
* @return 格式化后的文本
*/
public static String format(String template, Object... values) {
@@ -945,11 +1037,13 @@ public class StrUtils {
/**
* 格式化文本,使用 {varName} 占位
- * map = {a: "aValue", b: "bValue"}
- * format("{a} and {b}", map) ----> aValue and bValue
+ * map = {a: "aValue", b: "bValue"} format("{a} and {b}", map) ----> aValue
+ * and bValue
*
- * @param template 文本模板,被替换的部分用 {key} 表示
- * @param map 参数值对
+ * @param template
+ * 文本模板,被替换的部分用 {key} 表示
+ * @param map
+ * 参数值对
* @return 格式化后的文本
*/
public static String format(String template, Map, ?> map) {
@@ -962,12 +1056,14 @@ public class StrUtils {
}
return template;
}
-
+
/**
* 编码字符串
*
- * @param str 字符串
- * @param charset 字符集,如果此字段为空,则解码的结果取决于平台
+ * @param str
+ * 字符串
+ * @param charset
+ * 字符集,如果此字段为空,则解码的结果取决于平台
* @return 编码后的字节码
*/
public static byte[] bytes(String str, String charset) {
@@ -977,8 +1073,10 @@ public class StrUtils {
/**
* 编码字符串
*
- * @param str 字符串
- * @param charset 字符集,如果此字段为空,则解码的结果取决于平台
+ * @param str
+ * 字符串
+ * @param charset
+ * 字符集,如果此字段为空,则解码的结果取决于平台
* @return 编码后的字节码
*/
public static byte[] bytes(String str, Charset charset) {
@@ -991,64 +1089,68 @@ public class StrUtils {
}
return str.getBytes(charset);
}
-
+
/**
* 将对象转为字符串
- * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组
- * 2、对象数组会调用Arrays.toString方法
+ * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
*
- * @param obj 对象
+ * @param obj
+ * 对象
* @return 字符串
*/
- public static String utf8Str(Object obj){
+ public static String utf8Str(Object obj) {
return str(obj, CharsetUtils.CHARSET_UTF_8);
}
-
+
/**
* 将对象转为字符串
- * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组
- * 2、对象数组会调用Arrays.toString方法
+ * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
*
- * @param obj 对象
- * @param charsetName 字符集
+ * @param obj
+ * 对象
+ * @param charsetName
+ * 字符集
* @return 字符串
*/
- public static String str(Object obj, String charsetName){
+ public static String str(Object obj, String charsetName) {
return str(obj, Charset.forName(charsetName));
}
-
+
/**
* 将对象转为字符串
- * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组
- * 2、对象数组会调用Arrays.toString方法
+ * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
*
- * @param obj 对象
- * @param charset 字符集
+ * @param obj
+ * 对象
+ * @param charset
+ * 字符集
* @return 字符串
*/
- public static String str(Object obj, Charset charset){
- if(null == obj){
+ public static String str(Object obj, Charset charset) {
+ if (null == obj) {
return null;
}
-
- if(obj instanceof String) {
- return (String)obj;
- }else if(obj instanceof byte[] || obj instanceof Byte[]){
- return str((Byte[])obj, charset);
- }else if(obj instanceof ByteBuffer){
- return str((ByteBuffer)obj, charset);
- }else if(CollectionUtils.isArray(obj)){
+
+ if (obj instanceof String) {
+ return (String) obj;
+ } else if (obj instanceof byte[] || obj instanceof Byte[]) {
+ return str((Byte[]) obj, charset);
+ } else if (obj instanceof ByteBuffer) {
+ return str((ByteBuffer) obj, charset);
+ } else if (CollectionUtils.isArray(obj)) {
return CollectionUtils.toString(obj);
}
-
+
return obj.toString();
}
-
+
/**
* 将byte数组转为字符串
*
- * @param bytes byte数组
- * @param charset 字符集
+ * @param bytes
+ * byte数组
+ * @param charset
+ * 字符集
* @return 字符串
*/
public static String str(byte[] bytes, String charset) {
@@ -1058,8 +1160,10 @@ public class StrUtils {
/**
* 解码字节码
*
- * @param data 字符串
- * @param charset 字符集,如果此字段为空,则解码的结果取决于平台
+ * @param data
+ * 字符串
+ * @param charset
+ * 字符集,如果此字段为空,则解码的结果取决于平台
* @return 解码后的字符串
*/
public static String str(byte[] data, Charset charset) {
@@ -1072,38 +1176,47 @@ public class StrUtils {
}
return new String(data, charset);
}
-
+
/**
* 将编码的byteBuffer数据转换为字符串
- * @param data 数据
- * @param charset 字符集,如果为空使用当前系统字符集
+ *
+ * @param data
+ * 数据
+ * @param charset
+ * 字符集,如果为空使用当前系统字符集
* @return 字符串
*/
- public static String str(ByteBuffer data, String charset){
- if(data == null) {
+ public static String str(ByteBuffer data, String charset) {
+ if (data == null) {
return null;
}
-
+
return str(data, Charset.forName(charset));
}
-
+
/**
* 将编码的byteBuffer数据转换为字符串
- * @param data 数据
- * @param charset 字符集,如果为空使用当前系统字符集
+ *
+ * @param data
+ * 数据
+ * @param charset
+ * 字符集,如果为空使用当前系统字符集
* @return 字符串
*/
- public static String str(ByteBuffer data, Charset charset){
- if(null == charset) {
+ public static String str(ByteBuffer data, Charset charset) {
+ if (null == charset) {
charset = Charset.defaultCharset();
}
return charset.decode(data).toString();
}
-
+
/**
* 字符串转换为byteBuffer
- * @param str 字符串
- * @param charset 编码
+ *
+ * @param str
+ * 字符串
+ * @param charset
+ * 编码
* @return byteBuffer
*/
public static ByteBuffer byteBuffer(String str, String charset) {
@@ -1113,8 +1226,10 @@ public class StrUtils {
/**
* 以 conjunction 为分隔符将多个对象转换为字符串
*
- * @param conjunction 分隔符
- * @param objs 数组
+ * @param conjunction
+ * 分隔符
+ * @param objs
+ * 数组
* @return 连接后的字符串
*/
public static String join(String conjunction, Object... objs) {
@@ -1130,12 +1245,13 @@ public class StrUtils {
}
return sb.toString();
}
-
+
/**
* 将驼峰式命名的字符串转换为下划线方式。如果转换前的驼峰式命名的字符串为空,则返回空字符串。
* 例如:HelloWorld->hello_world
*
- * @param camelCaseStr 转换前的驼峰式命名的字符串
+ * @param camelCaseStr
+ * 转换前的驼峰式命名的字符串
* @return 转换后下划线大写方式命名的字符串
*/
public static String toUnderlineCase(String camelCaseStr) {
@@ -1155,7 +1271,8 @@ public class StrUtils {
}
if (Character.isUpperCase(c)) {
if (!isPreUpperCase || !isNextUpperCase) {
- if (i > 0) sb.append(UNDERLINE);
+ if (i > 0)
+ sb.append(UNDERLINE);
}
isPreUpperCase = true;
} else {
@@ -1170,7 +1287,8 @@ public class StrUtils {
* 将下划线方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。
* 例如:hello_world->HelloWorld
*
- * @param name 转换前的下划线大写方式命名的字符串
+ * @param name
+ * 转换前的下划线大写方式命名的字符串
* @return 转换后的驼峰式命名的字符串
*/
public static String toCamelCase(String name) {
@@ -1202,9 +1320,12 @@ public class StrUtils {
/**
* 包装指定字符串
*
- * @param str 被包装的字符串
- * @param prefix 前缀
- * @param suffix 后缀
+ * @param str
+ * 被包装的字符串
+ * @param prefix
+ * 前缀
+ * @param suffix
+ * 后缀
* @return 包装后的字符串
*/
public static String wrap(String str, String prefix, String suffix) {
@@ -1214,9 +1335,12 @@ public class StrUtils {
/**
* 指定字符串是否被包装
*
- * @param str 字符串
- * @param prefix 前缀
- * @param suffix 后缀
+ * @param str
+ * 字符串
+ * @param prefix
+ * 前缀
+ * @param suffix
+ * 后缀
* @return 是否被包装
*/
public static boolean isWrap(String str, String prefix, String suffix) {
@@ -1226,8 +1350,10 @@ public class StrUtils {
/**
* 指定字符串是否被同一字符包装(前后都有这些字符串)
*
- * @param str 字符串
- * @param wrapper 包装字符串
+ * @param str
+ * 字符串
+ * @param wrapper
+ * 包装字符串
* @return 是否被包装
*/
public static boolean isWrap(String str, String wrapper) {
@@ -1237,8 +1363,10 @@ public class StrUtils {
/**
* 指定字符串是否被同一字符包装(前后都有这些字符串)
*
- * @param str 字符串
- * @param wrapper 包装字符
+ * @param str
+ * 字符串
+ * @param wrapper
+ * 包装字符
* @return 是否被包装
*/
public static boolean isWrap(String str, char wrapper) {
@@ -1248,9 +1376,12 @@ public class StrUtils {
/**
* 指定字符串是否被包装
*
- * @param str 字符串
- * @param prefixChar 前缀
- * @param suffixChar 后缀
+ * @param str
+ * 字符串
+ * @param prefixChar
+ * 前缀
+ * @param suffixChar
+ * 后缀
* @return 是否被包装
*/
public static boolean isWrap(String str, char prefixChar, char suffixChar) {
@@ -1260,9 +1391,12 @@ public class StrUtils {
/**
* 补充字符串以满足最小长度 StrUtil.padPre("1", 3, '0');//"001"
*
- * @param str 字符串
- * @param minLength 最小长度
- * @param padChar 补充的字符
+ * @param str
+ * 字符串
+ * @param minLength
+ * 最小长度
+ * @param padChar
+ * 补充的字符
* @return 补充后的字符串
*/
public static String padPre(String str, int minLength, char padChar) {
@@ -1280,9 +1414,12 @@ public class StrUtils {
/**
* 补充字符串以满足最小长度 StrUtil.padEnd("1", 3, '0');//"100"
*
- * @param str 字符串
- * @param minLength 最小长度
- * @param padChar 补充的字符
+ * @param str
+ * 字符串
+ * @param minLength
+ * 最小长度
+ * @param padChar
+ * 补充的字符
* @return 补充后的字符串
*/
public static String padEnd(String str, int minLength, char padChar) {
@@ -1331,7 +1468,8 @@ public class StrUtils {
/**
* 获得StringReader
*
- * @param str 字符串
+ * @param str
+ * 字符串
* @return StringReader
*/
public static StringReader getReader(String str) {
@@ -1348,4 +1486,3 @@ public class StrUtils {
}
}
-
diff --git a/core.sdk/src/main/java/com/lyms/util/remote/HttpRemote.java b/core.sdk/src/main/java/com/lyms/util/remote/HttpRemote.java
index 582462b..00e9571 100644
--- a/core.sdk/src/main/java/com/lyms/util/remote/HttpRemote.java
+++ b/core.sdk/src/main/java/com/lyms/util/remote/HttpRemote.java
@@ -11,7 +11,7 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.entity.SerializableEntity;
-import com.lyms.synch.entity.SyncnModel;
+import com.lyms.synch.entity.ChannelData;
/**
* http,https 远程调用
@@ -28,35 +28,25 @@ public class HttpRemote extends AbsRemote {
return new HttpRemote();
}
- public String post(SyncnModel model) {
- if (model == null)
+ public String post(ChannelData data) {
+ if (data == null)
return null;
- String url = model.getRemote();
+ String url = data.getRemote();
HttpClientContext httpContext = HttpClientContext.create();
HttpPost post = new HttpPost(url);
HttpEntity entity = null;
CloseableHttpResponse response = null;
try {
-
- // ContentType content =
- // ContentType.create(MimeTypeUtils.TEXT_PLAIN_VALUE,
- // CharsetUtils.UTF_8);
-
- // entity = new StringEntity(JsonUtils.beanToJson(model), content);
-
- entity = new SerializableEntity(model);
- // post.setHeader("Content-Type", "text/plain; charset=utf-8");
+ entity = new SerializableEntity(data);
post.setEntity(entity);
response = httpclient.execute(post, httpContext);
entity = response.getEntity();
httpContext.getCookieStore().clear();
return responseUTF8(entity);
- } catch (ClientProtocolException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
+ } catch (Exception e) {
+ LOG.error("连接错误: " + e);
} finally {
try {
if (response != null) {
diff --git a/hospital.web/src/main/java/com/lyms/hospital/controller/LoginController.java b/hospital.web/src/main/java/com/lyms/hospital/controller/LoginController.java
index 5f9ceb2..eb97a5d 100644
--- a/hospital.web/src/main/java/com/lyms/hospital/controller/LoginController.java
+++ b/hospital.web/src/main/java/com/lyms/hospital/controller/LoginController.java
@@ -5,7 +5,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.lyms.web.controller.BaseController;
-import com.mysql.fabric.xmlrpc.base.Data;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@@ -13,18 +12,16 @@ import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
@RestController
-@RequestMapping(value="/login",method=RequestMethod.POST)
+@RequestMapping(value = "/login")
@Api(value = "/api", description = "登录的相关操作")
public class LoginController extends BaseController {
- @ApiOperation(value = "测试登录", notes = "测试登录说明")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long"),
- @ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
- })
- @RequestMapping(value="/testLogin",method=RequestMethod.GET)
- public String testLogin(){
- request.getSession().setAttribute("abc", "123");
+ @ApiOperation(value = "测试登录", notes = "测试登录说明")
+ @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long"),
+ @ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User") })
+ @RequestMapping(value = "/testLogin", method = RequestMethod.GET)
+ public String testLogin() {
+ // request.getSession().setAttribute("abc", "123");
return "abc";
}
}
diff --git a/hospital.web/src/main/java/com/lyms/hospital/controller/RouterController.java b/hospital.web/src/main/java/com/lyms/hospital/controller/RouterController.java
new file mode 100644
index 0000000..16155f0
--- /dev/null
+++ b/hospital.web/src/main/java/com/lyms/hospital/controller/RouterController.java
@@ -0,0 +1,43 @@
+package com.lyms.hospital.controller;
+
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.lyms.synch.ParamsHandler;
+import com.lyms.synch.SycnHandler;
+import com.lyms.synch.SyncUtils;
+import com.lyms.synch.entity.ChannelData;
+import com.lyms.web.controller.BaseController;
+
+/**
+ * + * Mapper接口 + *
+ * + * @author maliang + * @since 2017-03-15 + */ +@Repository +public interface SyncDataBasicMapper extends BaseMapper+ * 用户、角色、权限、医院、部门等基础数据同步 + *
+ * + * @author maliang + * @since 2017-03-15 + */ +@TableName("SYNC_DATA_BASIC") +public class SyncDataBasic implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 该ID 一定要与data 中的ID一致 + */ + @TableId(value = "ID") + private String id; + /** + * 数据对象 {@link ChannelData} json 数据格式 + */ + @TableField(value = "DATA") + private String data; + /** + * 创建时间 + */ + @TableField(value = "CREATE_TIME") + private Date createTime; + /** + * 数据上传是否成功 + */ + @TableField(value = "IFSUC") + private Integer ifsuc; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Integer getIfsuc() { + return ifsuc; + } + + public void setIfsuc(Integer ifsuc) { + this.ifsuc = ifsuc; + } + +} diff --git a/hospital.web/src/main/java/com/lyms/hospital/service/sys/SyncDataBasicService.java b/hospital.web/src/main/java/com/lyms/hospital/service/sys/SyncDataBasicService.java new file mode 100644 index 0000000..3766427 --- /dev/null +++ b/hospital.web/src/main/java/com/lyms/hospital/service/sys/SyncDataBasicService.java @@ -0,0 +1,50 @@ +package com.lyms.hospital.service.sys; + +import java.io.Serializable; +import java.util.List; + +import com.lyms.hospital.entity.sys.SyncDataBasic; +import com.lyms.synch.entity.ChannelData; +import com.lyms.web.service.BaseService; + +/** + *+ * 数据同步模块 + *
+ * + * @author maliang + * @since 2017-03-15 + */ +public interface SyncDataBasicService extends BaseService+ * 用户、角色、权限、医院、部门等基础数据同步 服务实现类 + *
+ * + * @author maliang + * @since 2017-03-15 + */ +@Service +public class SyncDataBasicServiceImpl extends ServiceImpl