Commit 5e58b2a8f356db080cba0a736f463dc832ebabe5

Authored by maliang
1 parent f4eaaccca3
Exists in master

修改同步代码

Showing 31 changed files with 1488 additions and 844 deletions

center.manager/src/main/java/com/lyms/cm/controller/sys/SysRemoteController.java View file @ 5e58b2a
... ... @@ -4,32 +4,30 @@
4 4  
5 5 import javax.servlet.http.HttpServletRequest;
6 6  
  7 +import org.springframework.http.MediaType;
7 8 import org.springframework.stereotype.Controller;
8 9 import org.springframework.web.bind.annotation.RequestMapping;
9 10 import org.springframework.web.bind.annotation.ResponseBody;
10 11  
11   -import com.lyms.cm.entity.sys.SysUsers;
  12 +import com.lyms.synch.ParamsHandler;
  13 +import com.lyms.synch.SycnHandler;
12 14 import com.lyms.synch.SyncUtils;
13   -import com.lyms.synch.entity.AckObj;
14   -import com.lyms.synch.entity.SyncnModel;
  15 +import com.lyms.synch.entity.ChannelData;
15 16 import com.lyms.web.controller.BaseController;
16 17  
17 18 @Controller
18 19 @RequestMapping("/remote")
  20 +@Deprecated
19 21 public class SysRemoteController extends BaseController {
20 22  
21   - @RequestMapping(value = "/push")
  23 + @RequestMapping(value = "/sycn", produces = { MediaType.APPLICATION_JSON_VALUE })
22 24 @ResponseBody
23   - public String push(HttpServletRequest request) throws ClassNotFoundException, IOException {
24   - SyncnModel model = SyncUtils.conver(request);
25   - if (model.isAck()) {
26   - AckObj ack = SyncUtils.converDataToAck(model);
27   - System.out.println("回执信息: " + ack.getData());
28   - } else {
29   - SysUsers user = SyncUtils.converData(model, SysUsers.class);
30   - System.out.println("user: " + user.getName());
31   - }
32   - return "OK";
  25 + public Object push(HttpServletRequest request) throws ClassNotFoundException, IOException {
  26 + ChannelData model = SyncUtils.conver(request);
  27 + Object object = SycnHandler.handler(model);
  28 + model.setData(ParamsHandler.builder().push(object).toJsonString());
  29 + model.setAck(true);
  30 + return model;
33 31 }
34 32 }
center.manager/src/main/java/com/lyms/cm/dao/sys/SysRegionsMapper.xml View file @ 5e58b2a
... ... @@ -30,6 +30,6 @@
30 30 re.PARENT_ID=#{id}
31 31 </where>
32 32 </select>
33   -
  33 +
34 34 </mapper>
center.manager/src/main/java/com/lyms/cm/job/SycnFixJob.java View file @ 5e58b2a
  1 +package com.lyms.cm.job;
  2 +
  3 +import org.apache.commons.lang3.StringUtils;
  4 +import org.apache.commons.lang3.builder.ToStringBuilder;
  5 +import org.slf4j.Logger;
  6 +import org.slf4j.LoggerFactory;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +
  9 +import com.lyms.synch.ParamsHandler;
  10 +import com.lyms.synch.SycnHandler;
  11 +import com.lyms.synch.SyncCallback;
  12 +import com.lyms.synch.SyncnCenter;
  13 +import com.lyms.synch.SyncnCenter.Work;
  14 +import com.lyms.synch.entity.ChannelData;
  15 +import com.lyms.util.HttpUtils;
  16 +import com.lyms.util.JsonUtils;
  17 +
  18 +/**
  19 + * <li>@ClassName: SycnJob
  20 + * <li>@Description: 同步任务执行器,依赖spring
  21 + * <li>@author maliang
  22 + * <li>@date 2017年3月14日
  23 + * <li>
  24 + */
  25 +public class SycnFixJob {
  26 + private Logger LOG = LoggerFactory.getLogger(getClass());
  27 +
  28 + @Autowired
  29 + public SyncnCenter center;
  30 +
  31 + public void excute() {
  32 + // 拉取远端数据
  33 + LOG.debug("执行拉取远程数据任务...");
  34 + final Work work = center.buildWork();
  35 + try {
  36 + work.pullFix(new SyncCallback() {
  37 + @Override
  38 + public void callBack(Object object) {
  39 + if (object instanceof ChannelData) {
  40 + ChannelData oldData = (ChannelData) object;
  41 + if (oldData != null && StringUtils.isNotBlank(oldData.getId())) {
  42 + // 任务发送执行
  43 + System.out.println("拉取到本地任务: " + ToStringBuilder.reflectionToString(oldData));
  44 + String result = HttpUtils.REMOTE.post(oldData);
  45 + System.out.println("返回结果: " + result);
  46 + if (StringUtils.isBlank(result))
  47 + return;
  48 + ChannelData data = JsonUtils.jsonToBean(result, ChannelData.class);
  49 + // 处理回执消息
  50 + if (data != null && data.getAck()) {
  51 + // 拉取到数据执行本地方法
  52 + System.out.println("执行: " + ToStringBuilder.reflectionToString(data));
  53 + Object handlResult = SycnHandler.handler(data);
  54 + // 要求处理成功都必须返回true | false;
  55 + Boolean tag = (Boolean) handlResult;
  56 + if (tag) {
  57 + data.setRemote(oldData.getRemote());
  58 + data.setData(ParamsHandler.builder().push(data.getId()).toJsonString());
  59 + data.setAck(true);
  60 + // 处理成功回执消息
  61 + data.setRemoteClazz("com.lyms.hospital.service.sys.impl.SyncDataBasicServiceImpl");
  62 + data.setRemoteMethod("updateBasic");
  63 + work.ack(data);
  64 + }
  65 + }
  66 + }
  67 + }
  68 + }
  69 + });
  70 + } catch (Exception e) {
  71 + LOG.error("同步数据错误 {}", e);
  72 + }
  73 + }
  74 +
  75 +}
center.manager/src/main/java/com/lyms/cm/job/SycnTmpJob.java View file @ 5e58b2a
  1 +package com.lyms.cm.job;
  2 +
  3 +import org.slf4j.Logger;
  4 +import org.slf4j.LoggerFactory;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +
  7 +import com.lyms.synch.SyncCallback;
  8 +import com.lyms.synch.SyncnCenter;
  9 +import com.lyms.synch.SyncnCenter.Work;
  10 +import com.lyms.synch.entity.ChannelData;
  11 +import com.lyms.util.HttpUtils;
  12 +import com.lyms.util.JsonUtils;
  13 +
  14 +/**
  15 + * <li>@ClassName: SycnJob
  16 + * <li>@Description: 同步任务执行器,依赖spring
  17 + * <li>@author maliang
  18 + * <li>@date 2017年3月14日
  19 + * <li>
  20 + */
  21 +public class SycnTmpJob {
  22 +
  23 + private Logger LOG = LoggerFactory.getLogger(getClass());
  24 +
  25 + @Autowired
  26 + public SyncnCenter center;
  27 +
  28 + public void excute() {
  29 + // 拉取远端数据
  30 + LOG.debug("执行推送远程数据任务...");
  31 + final Work work = center.buildWork();
  32 + try {
  33 + work.pullTmp(new SyncCallback() {
  34 + @Override
  35 + public void callBack(Object object) {
  36 + if (object instanceof ChannelData) {
  37 + ChannelData model = (ChannelData) object;
  38 + if (model != null) {
  39 + // 任务发送执行
  40 + String result = HttpUtils.REMOTE.post(model);
  41 + model = JsonUtils.jsonToBean(result, ChannelData.class);
  42 + if (model != null && model.getAck()) {
  43 + work.backPressure();
  44 + }
  45 + }
  46 + }
  47 + }
  48 + });
  49 + } catch (Exception e) {
  50 + LOG.error("同步数据错误 {}", e);
  51 + work.backPressure();
  52 + }
  53 + }
  54 +}
center.manager/src/main/java/com/lyms/cm/job/package-info.java View file @ 5e58b2a
  1 +/**
  2 + * <li>@ClassName: package-info
  3 + * <li>@Description: TODO(类描述)
  4 + * <li>@author maliang
  5 + * <li>@date 2017年3月14日
  6 + * <li>
  7 + */
  8 +package com.lyms.cm.job;
center.manager/src/main/java/com/lyms/cm/service/sys/impl/SysUsersServiceImpl.java View file @ 5e58b2a
... ... @@ -32,166 +32,166 @@
32 32 @Service
33 33 public class SysUsersServiceImpl extends ServiceImpl<SysUsersMapper, SysUsers> implements SysUsersService {
34 34  
35   - @Autowired
36   - private SysUsersMapper userMapper;
  35 + @Autowired
  36 + private SysUsersMapper userMapper;
37 37  
38   - @Autowired
39   - private SysUserRoleMapsService sysUserRoleMapsService;
  38 + @Autowired
  39 + private SysUserRoleMapsService sysUserRoleMapsService;
40 40  
41   - /**
42   - * 系统默认密码
43   - */
44   - private static final String DEFAULT_PWD = "123456";
  41 + /**
  42 + * 系统默认密码
  43 + */
  44 + private static final String DEFAULT_PWD = "123456";
45 45  
46   - // 模块基础操作信息
47   - private boolean empty(SysUsers user) {
48   - return user == null;
49   - }
  46 + // 模块基础操作信息
  47 + private boolean empty(SysUsers user) {
  48 + return user == null;
  49 + }
50 50  
51   - /**
52   - * 初始密码设置
53   - */
54   - private void initPwd(SysUsers user) {
55   - if (empty(user))
56   - return;
57   - String pwd = user.getPwd();
58   - if (StringUtils.isBlank(pwd)) {
59   - pwd = DEFAULT_PWD;
60   - }
61   - String encode = MD5Utils.md5(pwd);
62   - user.setPwd(encode);
63   - }
  51 + /**
  52 + * 初始密码设置
  53 + */
  54 + private void initPwd(SysUsers user) {
  55 + if (empty(user))
  56 + return;
  57 + String pwd = user.getPwd();
  58 + if (StringUtils.isBlank(pwd)) {
  59 + pwd = DEFAULT_PWD;
  60 + }
  61 + String encode = MD5Utils.md5(pwd);
  62 + user.setPwd(encode);
  63 + }
64 64  
65   - @Override
66   - @Transactional
67   - public boolean addUser(SysUsers user, List<SysUserRoleMaps> userRoleMapsList) throws SystemException {
68   - if (empty(user))
69   - return false;
70   - // 设置user ID
71   - user.setIfdel(0);
72   - if (null == user.getType()) {//没有勾选管理,就是用户
73   - user.setType(1);
74   - }
75   - if (null == user.getEnable()) {
76   - user.setEnable(1);
77   - }
78   - // 设置用户密码
79   - this.initPwd(user);
  65 + @Override
  66 + @Transactional
  67 + public boolean addUser(SysUsers user, List<SysUserRoleMaps> userRoleMapsList) throws SystemException {
  68 + if (empty(user))
  69 + return false;
  70 + // 设置user ID
  71 + user.setIfdel(0);
  72 + if (null == user.getType()) {// 没有勾选管理,就是用户
  73 + user.setType(1);
  74 + }
  75 + if (null == user.getEnable()) {
  76 + user.setEnable(1);
  77 + }
  78 + // 设置用户密码
  79 + this.initPwd(user);
80 80  
81   - Integer tag = userMapper.insert(user);
82   - if (!userRoleMapsList.isEmpty()) {
83   - sysUserRoleMapsService.insertBatch(userRoleMapsList);
84   - }
85   - return tag != null && tag >= 1;
86   - }
  81 + Integer tag = userMapper.insert(user);
  82 + if (userRoleMapsList != null && !userRoleMapsList.isEmpty()) {
  83 + sysUserRoleMapsService.insertBatch(userRoleMapsList);
  84 + }
  85 + return tag != null && tag >= 1;
  86 + }
87 87  
88   - @Override
89   - @Transactional
90   - public boolean updateUser(SysUsers user, List<SysUserRoleMaps> userRoleMapsList) throws SystemException {
91   - if (empty(user))
92   - return false;
93   - if (null == user.getType()) {//没有勾选管理,就是用户
94   - user.setType(1);
95   - }
96   - if (null == user.getEnable()) {
97   - user.setEnable(1);
98   - }
99   - if (StrUtils.isNotEmpty(user.getPwd())) {
100   - // 初始密码
101   - this.initPwd(user);
102   - }
  88 + @Override
  89 + @Transactional
  90 + public boolean updateUser(SysUsers user, List<SysUserRoleMaps> userRoleMapsList) throws SystemException {
  91 + if (empty(user))
  92 + return false;
  93 + if (null == user.getType()) {// 没有勾选管理,就是用户
  94 + user.setType(1);
  95 + }
  96 + if (null == user.getEnable()) {
  97 + user.setEnable(1);
  98 + }
  99 + if (StrUtils.isNotEmpty(user.getPwd())) {
  100 + // 初始密码
  101 + this.initPwd(user);
  102 + }
103 103  
104   - Integer tag = userMapper.updateById(user);
105   - EntityWrapper<SysUserRoleMaps> ew = new EntityWrapper<SysUserRoleMaps>();
106   - ew.where("user_id={0}", "'" + user.getId() + "'");
107   - sysUserRoleMapsService.delete(ew);
108   - if (!userRoleMapsList.isEmpty()) {
109   - sysUserRoleMapsService.insertBatch(userRoleMapsList);
110   - }
111   - return tag != null && tag >= 1;
112   - }
  104 + Integer tag = userMapper.updateById(user);
  105 + EntityWrapper<SysUserRoleMaps> ew = new EntityWrapper<SysUserRoleMaps>();
  106 + ew.where("user_id={0}", "'" + user.getId() + "'");
  107 + sysUserRoleMapsService.delete(ew);
  108 + if (!userRoleMapsList.isEmpty()) {
  109 + sysUserRoleMapsService.insertBatch(userRoleMapsList);
  110 + }
  111 + return tag != null && tag >= 1;
  112 + }
113 113  
114   - /*
115   - * @Override public SysUsers getUserById(String userId) throws
116   - * SystemException { if (StringUtils.isBlank(userId)) return null; return
117   - * userMapper.selectById(userId); }
118   - */
  114 + /*
  115 + * @Override public SysUsers getUserById(String userId) throws
  116 + * SystemException { if (StringUtils.isBlank(userId)) return null; return
  117 + * userMapper.selectById(userId); }
  118 + */
119 119  
120   - @Override
121   - @Transactional
122   - public boolean delete(String userId) throws SystemException {
  120 + @Override
  121 + @Transactional
  122 + public boolean delete(String userId) throws SystemException {
123 123  
124   - if (StringUtils.isBlank(userId))
125   - return false;
126   - // TODO 通过sql 修改
127   - SysUsers user = userMapper.selectById(userId);
128   - if (user != null) {
129   - Integer ifDel = user.getIfdel();
130   - if (ifDel == null || ifDel == ValidityEnum.VALIDITY.getValidity()) {
131   - ifDel = ValidityEnum.UNVALIDITY.getValidity();
132   - } else {
133   - ifDel = ValidityEnum.VALIDITY.getValidity();
134   - }
135   - user.setIfdel(ifDel);
136   - Integer tag = userMapper.updateById(user);
137   - return tag != null && tag >= 1;
138   - }
139   - return false;
140   - }
  124 + if (StringUtils.isBlank(userId))
  125 + return false;
  126 + // TODO 通过sql 修改
  127 + SysUsers user = userMapper.selectById(userId);
  128 + if (user != null) {
  129 + Integer ifDel = user.getIfdel();
  130 + if (ifDel == null || ifDel == ValidityEnum.VALIDITY.getValidity()) {
  131 + ifDel = ValidityEnum.UNVALIDITY.getValidity();
  132 + } else {
  133 + ifDel = ValidityEnum.VALIDITY.getValidity();
  134 + }
  135 + user.setIfdel(ifDel);
  136 + Integer tag = userMapper.updateById(user);
  137 + return tag != null && tag >= 1;
  138 + }
  139 + return false;
  140 + }
141 141  
142   - @Override
143   - public Integer deleteLogicById(Serializable id) {
144   - return baseMapper.deleteLogicById(id);
145   - }
  142 + @Override
  143 + public Integer deleteLogicById(Serializable id) {
  144 + return baseMapper.deleteLogicById(id);
  145 + }
146 146  
147   - @Override
148   - public boolean isAllowUpdate(String account, String userid) {
149   - boolean flag = true;
150   - if (StrUtils.isNotEmpty(userid)) {//修改用户
151   - SysUsers oldDbUser = selectById(userid);
152   - if (!oldDbUser.getAccount().equalsIgnoreCase(account)) {//登录账号改变
153   - flag = !isExistAccount(account);
154   - }
155   - } else {//新增
156   - flag = !isExistAccount(account);
157   - }
158   - return flag;
159   - }
  147 + @Override
  148 + public boolean isAllowUpdate(String account, String userid) {
  149 + boolean flag = true;
  150 + if (StrUtils.isNotEmpty(userid)) {// 修改用户
  151 + SysUsers oldDbUser = selectById(userid);
  152 + if (!oldDbUser.getAccount().equalsIgnoreCase(account)) {// 登录账号改变
  153 + flag = !isExistAccount(account);
  154 + }
  155 + } else {// 新增
  156 + flag = !isExistAccount(account);
  157 + }
  158 + return flag;
  159 + }
160 160  
161   - /**
162   - * <li>@Description:是否存在登录名
163   - * <li>@param account
164   - * <li>@return
165   - * <li>创建人:方承
166   - * <li>创建时间:2017年3月9日
167   - * <li>修改人:
168   - * <li>修改时间:
169   - */
170   - private boolean isExistAccount(String account) {
171   - SysUsers entity = selectOne(
172   - new EntityWrapper<SysUsers>().where("account={0}", "'" + account + "'").and("ifDel=0"));
173   - if (null == entity) {
174   - return false;
175   - }
176   - return true;
177   - }
  161 + /**
  162 + * <li>@Description:是否存在登录名
  163 + * <li>@param account
  164 + * <li>@return
  165 + * <li>创建人:方承
  166 + * <li>创建时间:2017年3月9日
  167 + * <li>修改人:
  168 + * <li>修改时间:
  169 + */
  170 + private boolean isExistAccount(String account) {
  171 + SysUsers entity = selectOne(
  172 + new EntityWrapper<SysUsers>().where("account={0}", "'" + account + "'").and("ifDel=0"));
  173 + if (null == entity) {
  174 + return false;
  175 + }
  176 + return true;
  177 + }
178 178  
179   - @Override
180   - public SysUsers getUserByUsername(String name) {
181   - SysUsers user = selectOne(new EntityWrapper<SysUsers>().where("account={0}", name).and("ifDel=0"));
182   - return user;
183   - }
  179 + @Override
  180 + public SysUsers getUserByUsername(String name) {
  181 + SysUsers user = selectOne(new EntityWrapper<SysUsers>().where("account={0}", name).and("ifDel=0"));
  182 + return user;
  183 + }
184 184  
185   - @Override
186   - public List<String> getRoleIdListByUserid(String uid) {
187   - List<SysUserRoleMaps> urList = sysUserRoleMapsService
188   - .selectList(new EntityWrapper<SysUserRoleMaps>().where("user_id={0}", uid));
189   - List<String> roleIdList = InstanceUtils.newArrayList();
190   - for (SysUserRoleMaps ur : urList) {
191   - roleIdList.add(ur.getRoleId());
192   - }
193   - return roleIdList;
194   - }
  185 + @Override
  186 + public List<String> getRoleIdListByUserid(String uid) {
  187 + List<SysUserRoleMaps> urList = sysUserRoleMapsService
  188 + .selectList(new EntityWrapper<SysUserRoleMaps>().where("user_id={0}", uid));
  189 + List<String> roleIdList = InstanceUtils.newArrayList();
  190 + for (SysUserRoleMaps ur : urList) {
  191 + roleIdList.add(ur.getRoleId());
  192 + }
  193 + return roleIdList;
  194 + }
195 195  
196 196 }
center.manager/src/main/resources/app-context.xml View file @ 5e58b2a
... ... @@ -17,6 +17,8 @@
17 17 <!-- 扫描控制器 禁用use-default-filters 不重复扫描@Service,@Repository等..否则将导致事务失效 -->
18 18 <context:component-scan base-package="com.lyms.cm"></context:component-scan>
19 19 <context:component-scan base-package="com.lyms.util"></context:component-scan>
  20 + <!-- context 容器获取扫描 -->
  21 + <context:component-scan base-package="com.lyms.spring" />
20 22 <context:property-placeholder location="classpath:jdbc.properties,classpath:redis.properties"/>
21 23  
22 24 <bean class="com.lyms.web.listener.StartupListener"/>
center.manager/src/main/resources/xml/app-timer.xml View file @ 5e58b2a
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<beans xmlns="http://www.springframework.org/schema/beans"
  3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4 + xmlns:context="http://www.springframework.org/schema/context"
  5 + xmlns:tx="http://www.springframework.org/schema/tx"
  6 + xmlns:task="http://www.springframework.org/schema/task"
  7 + xmlns:aop="http://www.springframework.org/schema/aop"
  8 + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
  9 + http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
  10 + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
  11 + http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
  12 + http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
  13 + ">
  14 +
  15 + <!-- 同步远程数据, 定时任务处理同步任务 -->
  16 + <task:scheduled-tasks>
  17 + <!-- <task:scheduled ref="sycnTmpJob" method="excute" cron="*/10 * * * * ?"/> -->
  18 + <task:scheduled ref="sycnFixJob" method="excute" cron="*/30 * * * * ?"/>
  19 + </task:scheduled-tasks>
  20 +
  21 + <bean class="com.lyms.cm.job.SycnTmpJob" id="sycnTmpJob"/>
  22 + <bean class="com.lyms.cm.job.SycnFixJob" id="sycnFixJob"/>
  23 +</beans>
center.manager/src/test/java/center/manager/test/user/WorkTest.java View file @ 5e58b2a
1 1 package center.manager.test.user;
2 2  
  3 +import org.apache.commons.lang3.builder.ToStringBuilder;
3 4 import org.junit.Test;
4 5 import org.springframework.beans.factory.annotation.Autowired;
5 6  
6   -import com.lyms.cm.entity.sys.SysRoles;
  7 +import com.alibaba.fastjson.JSON;
7 8 import com.lyms.cm.entity.sys.SysUsers;
  9 +import com.lyms.synch.ParamsHandler;
8 10 import com.lyms.synch.SyncCallback;
9 11 import com.lyms.synch.SyncnCenter;
10 12 import com.lyms.synch.SyncnCenter.Work;
11   -import com.lyms.synch.entity.ModelType;
12   -import com.lyms.synch.entity.SyncnModel;
  13 +import com.lyms.synch.entity.ChannelData;
  14 +import com.lyms.util.HttpUtils;
  15 +import com.lyms.util.JsonUtils;
13 16 import com.lyms.util.StrUtils;
14 17  
15 18 /**
16 19  
17 20  
18 21  
19 22  
... ... @@ -24,27 +27,18 @@
24 27 @Autowired
25 28 public SyncnCenter center;
26 29  
  30 + @Test
27 31 public void push() {
28   - SyncnModel model = new SyncnModel();
29   - model.setId(StrUtils.uuid());
30   - model.setModel("user2");
31   - model.setMethod("post");
32   - model.setType(ModelType.ADD.name());
33   - // 推送数据远程地址
34   - model.setRemote("http://127.0.0.1:9090/center.manager/remote/push");
35   - // 对于远程获取数据,回调地址
36   - model.setCallBack("http://www.baidu.com");
37   - model.setTs(System.currentTimeMillis());
  32 + String remote = "http://127.0.0.1:9090/hospital.web/remote/sycn";
  33 + String remoteClazz = "com.lyms.hospital.service.sys.impl.SyncDataBasicServiceImpl";
  34 + String remoteMethod = "selectOne";
  35 + Object data = null;// new Object[] { user, null };
38 36  
39   - SysUsers user = new SysUsers();
40   - user.setName("乱码测试");
41   - model.setData(user);
  37 + boolean loop = true;
42 38  
43   - SysRoles roles = new SysRoles();
44   - roles.setName("roles");
45   - user.setRoles(roles);
  39 + ChannelData push = new ChannelData(remote, remoteClazz, remoteMethod, null, loop);
46 40  
47   - center.buildWork().push(model, new SyncCallback() {
  41 + center.buildWork().push(push, new SyncCallback() {
48 42 @Override
49 43 public void callBack(Object object) {
50 44 System.out.println("push callBack : " + object);
51 45  
... ... @@ -62,19 +56,16 @@
62 56 }
63 57 }).start();
64 58  
65   - new Thread(new Runnable() {
66   - @Override
67   - public void run() {
68   - try {
69   - fix();
70   - } catch (InterruptedException e) {
71   - e.printStackTrace();
72   - }
73   - }
74   - }).start();
  59 + /*
  60 + * new Thread(new Runnable() {
  61 + *
  62 + * @Override public void run() { try { fix(); } catch
  63 + * (InterruptedException e) { e.printStackTrace(); } } }).start();
  64 + */
  65 + //
75 66 while (true) {
76 67 push();
77   - Thread.sleep(10000);
  68 + Thread.sleep(30000);
78 69 }
79 70  
80 71 }
81 72  
82 73  
83 74  
... ... @@ -82,21 +73,35 @@
82 73 @Test
83 74 public void tmp() {
84 75 while (true) {
85   - Work work = center.buildWork();
  76 + final Work work = center.buildWork();
86 77 try {
87 78 // final AckObj ack = new AckObj();
  79 +
88 80 work.pullTmp(new SyncCallback() {
89 81 @Override
90 82 public void callBack(Object object) {
91   - SyncnModel model = (SyncnModel) object;
92   - // String result = HttpUtils.REMOTE.post(model);
93   - // ack.setData(result);
94   - System.out.println("tmp ....");
  83 + if (object == null)
  84 + return;
  85 + if (object instanceof ChannelData) {
  86 + ChannelData model = (ChannelData) object;
  87 + String result = HttpUtils.REMOTE.post(model);
  88 + System.out.println(result);
  89 + model = JsonUtils.jsonToBean(result, ChannelData.class);
  90 + System.out.println("回执: " + ToStringBuilder.reflectionToString(model));
  91 + if (model != null) {
  92 + if (!model.getAck()) {
  93 + work.backPressure();
  94 + } else {
  95 + System.out.println("远程数据处理成功");
  96 + }
  97 + }
  98 + }
95 99 }
96 100 });
97 101 } catch (Exception e) {
98 102 e.printStackTrace();
99 103 // 异常数据反压
  104 + System.out.println("数据反压");
100 105 work.backPressure();
101 106 }
102 107 }
103 108  
104 109  
105 110  
106 111  
107 112  
108 113  
... ... @@ -106,28 +111,57 @@
106 111 public void fix() throws InterruptedException {
107 112 // 获取固定任务队列任务
108 113 // 包含ack 回调方法
109   - while (true) {
110   - Work work2 = center.buildWork();
111   - try {
112   - // final AckObj ack = new AckObj();
113   - work2.pullFix(new SyncCallback() {
114   - @Override
115   - public void callBack(Object object) {
  114 + // while (true) {
  115 + Work work2 = center.buildWork();
  116 + try {
  117 + // final AckObj ack = new AckObj();
  118 + work2.pullFix(new SyncCallback() {
  119 + @Override
  120 + public void callBack(Object object) {
  121 + if (object != null && object instanceof ChannelData) {
116 122 // remote
117   - SyncnModel model = (SyncnModel) object;
  123 + ChannelData model = (ChannelData) object;
118 124 // 处理实际业务
  125 + System.out.println(ToStringBuilder.reflectionToString(model));
119 126 System.out.println(model.getRemote() + "====>fix");
120   -
121   - // String result = HttpUtils.REMOTE.post(model);
122   - // System.out.println(model.getModel());
  127 + String result = HttpUtils.REMOTE.post(model);
  128 + System.out.println(result);
123 129 // ack.setData(model.getData());
124 130 }
125   - });// .ackGet(params);// .ackGet(null)
126   - } catch (Exception e) {
127   - e.printStackTrace();
128   - }
129   - Thread.sleep(15000);
  131 + }
  132 + });// .ackGet(params);// .ackGet(null)
  133 + } catch (Exception e) {
  134 + e.printStackTrace();
130 135 }
  136 + // Thread.sleep(15000);
  137 + // }
131 138 }
  139 +
  140 + public static void buildParams() throws ClassNotFoundException {
  141 + String uid = StrUtils.uuid();
  142 +
  143 + ChannelData data = ChannelData.emtpy();
  144 + data.setId(uid);
  145 + data.setRemote(null);
  146 + data.setRemoteClazz("com.lyms.cm.service.sys.impl.SysUsersServiceImpl");
  147 + data.setRemoteMethod("addUser");
  148 + SysUsers user = new SysUsers();
  149 + user.setId(uid);
  150 + user.setName("测试信息");
  151 + // Object params = new Object[] { user, null };
  152 +
  153 + // 设置参数
  154 + ParamsHandler params = ParamsHandler.builder().push(user).push(null);
  155 + data.setData(params.toJsonString());
  156 +
  157 + String str = JSON.toJSONString(data);
  158 + System.out.println(str);
  159 +
  160 + }
  161 +
  162 + public static void main(String[] args) throws ClassNotFoundException {
  163 + buildParams();
  164 + }
  165 +
132 166 }
core.sdk/src/main/java/com/lyms/spring/SpringContextHolder.java View file @ 5e58b2a
... ... @@ -8,14 +8,14 @@
8 8 import org.springframework.context.ApplicationContextAware;
9 9 import org.springframework.context.ConfigurableApplicationContext;
10 10 import org.springframework.context.annotation.Lazy;
11   -import org.springframework.stereotype.Service;
  11 +import org.springframework.stereotype.Component;
12 12  
13 13 /**
14 14 *
15 15 * 以静态变量保存Spring ApplicationContext, 可在任何代码任何地方任何时候取出ApplicaitonContext.
16 16 *
17 17 */
18   -@Service
  18 +@Component
19 19 @Lazy(false)
20 20 public class SpringContextHolder implements ApplicationContextAware, DisposableBean {
21 21  
... ... @@ -92,7 +92,8 @@
92 92 *
93 93 */
94 94 private static void assertContextInjected() {
95   - Validate.validState(applicationContext != null, "applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder.");
  95 + Validate.validState(applicationContext != null,
  96 + "applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder.");
96 97 }
97 98  
98 99 /**
core.sdk/src/main/java/com/lyms/synch/ParamsHandler.java View file @ 5e58b2a
  1 +package com.lyms.synch;
  2 +
  3 +import java.io.Serializable;
  4 +import java.util.LinkedList;
  5 +import java.util.List;
  6 +
  7 +import com.lyms.util.JsonUtils;
  8 +
  9 +/**
  10 + * <li>@ClassName: ParamsHandler
  11 + * <li>@Description: 参数处理
  12 + * <li>@author maliang
  13 + * <li>@date 2017年3月15日
  14 + * <li>
  15 + */
  16 +public class ParamsHandler implements Serializable {
  17 +
  18 + /**
  19 + */
  20 + private static final long serialVersionUID = 7048461500310029490L;
  21 + private List<Param> params = new LinkedList<>();
  22 +
  23 + public ParamsHandler() {
  24 + }
  25 +
  26 + public static ParamsHandler builder() {
  27 + return new ParamsHandler();
  28 + }
  29 +
  30 + public String toJsonString() {
  31 + return JsonUtils.beanToJson(this);
  32 + }
  33 +
  34 + public ParamsHandler push(Object obj) {
  35 + if (obj == null) {
  36 + params.add(new Param(Object.class.getName(), "null"));
  37 + } else {
  38 + params.add(new Param(obj.getClass().getName(), obj));
  39 + }
  40 + return this;
  41 + }
  42 +
  43 + public static class Param implements Serializable {
  44 + /**
  45 + */
  46 + private static final long serialVersionUID = -1634342674830431814L;
  47 + private String className;
  48 + private Object obj;
  49 +
  50 + public Param() {
  51 + };
  52 +
  53 + public Param(String className, Object obj) {
  54 + this.className = className;
  55 + this.obj = obj;
  56 + }
  57 +
  58 + public String getClassName() {
  59 + return className;
  60 + }
  61 +
  62 + public void setClassName(String className) {
  63 + this.className = className;
  64 + }
  65 +
  66 + public Object getObj() {
  67 + return obj;
  68 + }
  69 +
  70 + public void setObj(Object obj) {
  71 + this.obj = obj;
  72 + }
  73 + }
  74 +
  75 + public List<Param> getParams() {
  76 + return params;
  77 + }
  78 +
  79 + public void setParams(List<Param> params) {
  80 + this.params = params;
  81 + }
  82 +
  83 +}
core.sdk/src/main/java/com/lyms/synch/SycnHandler.java View file @ 5e58b2a
  1 +package com.lyms.synch;
  2 +
  3 +import java.lang.reflect.InvocationTargetException;
  4 +import java.lang.reflect.Method;
  5 +import java.util.List;
  6 +
  7 +import org.apache.commons.lang3.StringUtils;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +
  11 +import com.lyms.spring.SpringContextHolder;
  12 +import com.lyms.synch.ParamsHandler.Param;
  13 +import com.lyms.synch.entity.ChannelData;
  14 +import com.lyms.util.JsonUtils;
  15 +
  16 +/**
  17 + *
  18 + * <li>@ClassName: SyncHandler
  19 + * <li>@Description: 处理器
  20 + * <li>@author maliang
  21 + * <li>@date 2017年3月15日
  22 + * <li>
  23 + */
  24 +public class SycnHandler {
  25 +
  26 + private static Logger LOG = LoggerFactory.getLogger(SycnHandler.class);
  27 +
  28 + public static Object handler(ChannelData data) {
  29 + try {
  30 + return invoke(data);
  31 + } catch (Exception e) {
  32 + LOG.error("执行方法错误: {}", e);
  33 + return false;
  34 + }
  35 + }
  36 +
  37 + private static Object invoke(ChannelData data)
  38 + throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
  39 + if (data == null)
  40 + return null;
  41 +
  42 + Class<?> clazz = getClazz(data.getRemoteClazz());
  43 + if (clazz == null)
  44 + return null;
  45 + Object tagetObject = getObject(clazz);
  46 + Method method = getMethod(clazz, data.getRemoteMethod());
  47 +
  48 + return excute(tagetObject, method, data.getData());
  49 + }
  50 +
  51 + private static Object excute(Object object, Method method, String params)
  52 + throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException {
  53 + if (method == null || object == null)
  54 + return null;
  55 + Object[] objs = null;
  56 + if (StringUtils.isNotBlank(params)) {
  57 + ParamsHandler handler = JsonUtils.jsonToBean(params, ParamsHandler.class);
  58 + if (handler != null) {
  59 + List<Param> ps = handler.getParams();
  60 + objs = new Object[ps.size()];
  61 + if (ps != null && !ps.isEmpty()) {
  62 + int i = 0;
  63 + for (Param p : ps) {
  64 + String clazz = p.getClassName();
  65 + String value = p.getObj().toString();
  66 + if (value.equalsIgnoreCase("null")) {
  67 + objs[i] = null;
  68 + } else {
  69 + // 做数据类型匹配,尽量多的排除基本类型
  70 + // 针对业务出现的数据类型做处理 TODO
  71 + if (clazz.equals(String.class.getName()) || clazz.equals(Integer.class.getName())
  72 + || clazz.equals(Long.class.getName()) || clazz.equals(Boolean.class.getName())) {
  73 + objs[i] = value;
  74 + } else {
  75 + Object tmp = JsonUtils.jsonToBean(value, getClazz(clazz));
  76 + objs[i] = tmp;
  77 + }
  78 +
  79 + }
  80 + i++;
  81 + }
  82 + }
  83 +
  84 + }
  85 + }
  86 + // System.out.println(ToStringBuilder.reflectionToString(objs));
  87 + return method.invoke(object, objs);
  88 +
  89 + }
  90 +
  91 + private static Class<?> getClazz(String clazz) throws ClassNotFoundException {
  92 + if (StringUtils.isNotBlank(clazz)) {
  93 + return Class.forName(clazz);
  94 + }
  95 + return null;
  96 + }
  97 +
  98 + private static Object getObject(Class<?> clazz) {
  99 + return SpringContextHolder.getBean(clazz);
  100 + }
  101 +
  102 + private static Method getMethod(Class<?> clazz, String methodName) {
  103 + for (Method method : clazz.getDeclaredMethods()) {
  104 + if (method.getName().equalsIgnoreCase(methodName)) {
  105 + return method;
  106 + }
  107 + }
  108 + return null;
  109 + }
  110 +
  111 +}
core.sdk/src/main/java/com/lyms/synch/SyncUtils.java View file @ 5e58b2a
1 1 package com.lyms.synch;
2 2  
3   -import java.io.IOException;
4 3 import java.io.ObjectInputStream;
5 4 import java.io.Serializable;
6 5  
7 6 import javax.servlet.http.HttpServletRequest;
8 7  
9   -import com.lyms.synch.entity.AckObj;
10   -import com.lyms.synch.entity.SyncnModel;
  8 +import com.lyms.synch.entity.ChannelData;
11 9  
12 10 /**
13 11 * <li>@ClassName: SyncUtils
... ... @@ -18,10 +16,15 @@
18 16 */
19 17 public class SyncUtils {
20 18  
21   - public static SyncnModel conver(HttpServletRequest request) throws IOException, ClassNotFoundException {
22   - request.setCharacterEncoding("utf-8");
23   - ObjectInputStream dis = new ObjectInputStream(request.getInputStream());
24   - SyncnModel model = (SyncnModel) dis.readObject();
  19 + public static ChannelData conver(HttpServletRequest request) {
  20 + ChannelData model = ChannelData.emtpy();
  21 + try {
  22 + request.setCharacterEncoding("utf-8");
  23 + ObjectInputStream dis = new ObjectInputStream(request.getInputStream());
  24 + model = (ChannelData) dis.readObject();
  25 + } catch (Exception e) {
  26 + e.printStackTrace();
  27 + }
25 28 return model;
26 29 }
27 30  
28 31  
... ... @@ -35,32 +38,13 @@
35 38 * <li>修改时间:
36 39 */
37 40 @SuppressWarnings("unchecked")
38   - public static <T> T converData(SyncnModel model, Class<T> t) {
  41 + public static <T> T converData(ChannelData model, Class<T> t) {
39 42 if (model == null || model.getData() == null)
40 43 return null;
41 44 if (!Serializable.class.isAssignableFrom(t)) {
42 45 return null;
43 46 }
44 47 return (T) model.getData();
45   - }
46   -
47   - /**
48   - * <li>@Description:直接转化为ACK Object
49   - * <li>@param model
50   - * <li>@return
51   - * <li>创建人:maliang
52   - * <li>创建时间:2017年3月14日
53   - * <li>修改人:
54   - * <li>修改时间:
55   - */
56   - public static AckObj converDataToAck(SyncnModel model) {
57   - if (model == null || model.getData() == null)
58   - return null;
59   - if (!(model.getData() instanceof AckObj)) {
60   - return null;
61   - }
62   - return (AckObj) model.getData();
63   - // return converData(model, AckObj.class);
64 48 }
65 49  
66 50 }
core.sdk/src/main/java/com/lyms/synch/SyncnCenter.java View file @ 5e58b2a
1 1 package com.lyms.synch;
2 2  
3   -import java.util.Map;
4 3 import java.util.concurrent.Executors;
5 4 import java.util.concurrent.ScheduledExecutorService;
6 5  
7   -import org.apache.commons.lang3.StringUtils;
8   -
9   -import com.lyms.synch.entity.AckObj;
10   -import com.lyms.synch.entity.ModelType;
11   -import com.lyms.synch.entity.SyncnModel;
  6 +import com.lyms.synch.entity.ChannelData;
12 7 import com.lyms.synch.queue.SyncnQueue;
13 8 import com.lyms.util.HttpUtils;
14   -import com.lyms.util.StrUtils;
15 9  
16 10 /**
17 11 * <li>@ClassName: SyncnCenter
18 12  
... ... @@ -62,13 +56,13 @@
62 56  
63 57 public class Work {
64 58  
65   - public SyncnModel model;
  59 + public ChannelData data;
66 60  
67 61 // public CenterCallback callBack;
68 62  
69   - public Work push(SyncnModel model, SyncCallback callBack) {
70   - this.model = model;
71   - Boolean tag = queue.push(model);
  63 + public Work push(ChannelData data, SyncCallback callBack) {
  64 + // this.model = model;
  65 + Boolean tag = queue.push(data);
72 66 callBack.callBack(tag);
73 67 return this;
74 68 }
... ... @@ -85,9 +79,10 @@
85 79 * <li>修改时间:
86 80 */
87 81 public Work pullFix(SyncCallback callBack) {
88   - SyncnModel model = queue.pull(ModelType.GET);
89   - this.model = model;
90   - callBack.callBack(model);
  82 + // SyncnModel model = queue.pull(ModelType.GET);
  83 + ChannelData data = queue.pull(true);
  84 + this.data = data;
  85 + callBack.callBack(data);
91 86 return this;
92 87 }
93 88  
... ... @@ -103,9 +98,9 @@
103 98 * <li>修改时间:
104 99 */
105 100 public Work pullTmp(SyncCallback callBack) {
106   - SyncnModel model = queue.pull(null);
107   - this.model = model;
108   - callBack.callBack(model);
  101 + ChannelData data = queue.pull(false);
  102 + this.data = data;
  103 + callBack.callBack(data);
109 104 return this;
110 105 }
111 106  
... ... @@ -120,7 +115,9 @@
120 115 * <li>修改时间:
121 116 */
122 117 public void backPressure() {
123   - this.push(model, new SyncCallback() {
  118 + if (data == null)
  119 + return;
  120 + this.push(data, new SyncCallback() {
124 121 boolean tag = false;
125 122  
126 123 @Override
127 124  
128 125  
... ... @@ -137,66 +134,19 @@
137 134 /**
138 135 * <li>@Description:回调方法,调用远端接口
139 136 * <p>
140   - * 跟 {@link #ackGet(Map)} {@link #ackPost(Map)} 的区别是,后两者需要自己设定callback
141   - * 地址跟参数,可以指定任意地址
  137 + * 该方法只有跟 {@link #pullFix(SyncCallback)} {@link #pullTmp(SyncCallback)}
  138 + * 才有意义
142 139 * <li>@return
143 140 * <li>创建人:maliang
144 141 * <li>创建时间:2017年3月14日
145 142 * <li>修改人:
146 143 * <li>修改时间:
147 144 */
148   - public String ack(AckObj ack) {
149   - if (model != null && !model.isAck() && StringUtils.isNotBlank(model.getRemote())) {
150   - model.setId(StrUtils.uuid());
151   - model.setTs(System.currentTimeMillis());
152   - model.setData(ack);
153   - model.setType(ModelType.ACK.name());
154   - ack.setOldType(model.getType());
155   - return HttpUtils.REMOTE.post(model);
  145 + public String ack(ChannelData ackData) {
  146 + if (ackData != null) {
  147 + HttpUtils.REMOTE.post(ackData);
156 148 }
157 149 return null;
158   - }
159   -
160   - /**
161   - * <li>@Description:该方法为回执方法,将会调用目标接口,返回提示对应消息处理成功
162   - * <p>
163   - * 使用方式 pull(type,callBack).ackGet();
164   - * <p>
165   - * 目前该方法对PULL 的消息回执才有实际的意义
166   - * <li>@return
167   - * <li>创建人:maliang
168   - * <li>创建时间:2017年3月13日
169   - * <li>修改人:
170   - * <li>修改时间:
171   - */
172   - public String ackGet(Map<String, String> params) {
173   - if (model != null && StringUtils.isNotBlank(model.getCallBack())) {
174   - return HttpUtils.REMOTE.get(model.getCallBack(), params);
175   - }
176   - return null;
177   - }
178   -
179   - public String ackPost(Map<String, String> params) {
180   - if (model != null && StringUtils.isNotBlank(model.getCallBack())) {
181   - return HttpUtils.REMOTE.post(model.getCallBack(), params);
182   - }
183   - return null;
184   - }
185   -
186   - /**
187   - * <li>@Description:该方法主要检测是否重复执行,对应数据
188   - * <p>
189   - * TODO
190   - * <p>
191   - * 使用方式 push(model,callBack).validata();
192   - * <li>@return
193   - * <li>创建人:maliang
194   - * <li>创建时间:2017年3月13日
195   - * <li>修改人:
196   - * <li>修改时间:
197   - */
198   - public Work validata() {
199   - return this;
200 150 }
201 151  
202 152 }
core.sdk/src/main/java/com/lyms/synch/entity/AckObj.java View file @ 5e58b2a
1   -package com.lyms.synch.entity;
2   -
3   -import java.io.Serializable;
4   -
5   -/**
6   - * <li>@ClassName: AckObj
7   - * <li>@Description: 回调实体,用于封装获取到的数据信息
8   - * <li>@author maliang
9   - * <li>@date 2017年3月14日
10   - * <li>
11   - */
12   -public class AckObj implements Serializable {
13   -
14   - /**
15   - */
16   - private static final long serialVersionUID = -3939046868818014917L;
17   -
18   - /**
19   - * {@link ModelType} 获取数据
20   - */
21   - private String oldType;
22   -
23   - /**
24   - * remote、获取的数据信息,该参数需要自行封装
25   - */
26   - private Object data;
27   -
28   - public String getOldType() {
29   - return oldType;
30   - }
31   -
32   - public void setOldType(String oldType) {
33   - this.oldType = oldType;
34   - }
35   -
36   - public Object getData() {
37   - return data;
38   - }
39   -
40   - public void setData(Object data) {
41   - this.data = data;
42   - }
43   -}
core.sdk/src/main/java/com/lyms/synch/entity/ChannelData.java View file @ 5e58b2a
  1 +package com.lyms.synch.entity;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +import com.lyms.util.JsonUtils;
  6 +import com.lyms.util.StrUtils;
  7 +
  8 +/**
  9 + * <li>@ClassName: ChannelData
  10 + * <li>@Description: 通道实体
  11 + * <li>@author maliang
  12 + * <li>@date 2017年3月15日
  13 + * <li>
  14 + */
  15 +public class ChannelData implements Serializable {
  16 +
  17 + /**
  18 + */
  19 + private static final long serialVersionUID = -4448732709523865922L;
  20 +
  21 + public ChannelData() {
  22 + };
  23 +
  24 + public static ChannelData emtpy() {
  25 + return new ChannelData();
  26 + }
  27 +
  28 + /**
  29 + * 数据传输ID
  30 + */
  31 + private String id;
  32 +
  33 + /**
  34 + * remote address
  35 + */
  36 + private String remote;
  37 +
  38 + /**
  39 + * remote class name
  40 + */
  41 + private String remoteClazz;
  42 +
  43 + /**
  44 + * remote method name
  45 + */
  46 + private String remoteMethod;
  47 +
  48 + /**
  49 + * remote body json
  50 + */
  51 + private String data;
  52 +
  53 + private Boolean loop = Boolean.FALSE;
  54 +
  55 + /**
  56 + * 是否回执信息
  57 + */
  58 + private Boolean ack = Boolean.FALSE;
  59 +
  60 + /**
  61 + * 创建时间
  62 + */
  63 + private Long ts;
  64 +
  65 + public ChannelData(String remote, String remoteClazz, String remoteMethod, String data, boolean loop) {
  66 + this.id = StrUtils.uuid();
  67 + this.remote = remote;
  68 + this.remoteClazz = remoteClazz;
  69 + this.remoteMethod = remoteMethod;
  70 + this.data = data;
  71 + this.ts = System.currentTimeMillis();
  72 + this.loop = loop;
  73 + }
  74 +
  75 + public String getId() {
  76 + return id;
  77 + }
  78 +
  79 + public void setId(String id) {
  80 + this.id = id;
  81 + }
  82 +
  83 + public String getRemote() {
  84 + return remote;
  85 + }
  86 +
  87 + public void setRemote(String remote) {
  88 + this.remote = remote;
  89 + }
  90 +
  91 + public String getRemoteClazz() {
  92 + return remoteClazz;
  93 + }
  94 +
  95 + public void setRemoteClazz(String remoteClazz) {
  96 + this.remoteClazz = remoteClazz;
  97 + }
  98 +
  99 + public String getRemoteMethod() {
  100 + return remoteMethod;
  101 + }
  102 +
  103 + public void setRemoteMethod(String remoteMethod) {
  104 + this.remoteMethod = remoteMethod;
  105 + }
  106 +
  107 + public String getData() {
  108 + return data;
  109 + }
  110 +
  111 + public void setData(String data) {
  112 + this.data = data;
  113 + }
  114 +
  115 + public Long getTs() {
  116 + return ts;
  117 + }
  118 +
  119 + public void setTs(Long ts) {
  120 + this.ts = ts;
  121 + }
  122 +
  123 + public Boolean getLoop() {
  124 + return loop;
  125 + }
  126 +
  127 + public void setLoop(Boolean loop) {
  128 + this.loop = loop;
  129 + }
  130 +
  131 + public Boolean getAck() {
  132 + return ack;
  133 + }
  134 +
  135 + public void setAck(Boolean ack) {
  136 + this.ack = ack;
  137 + }
  138 +
  139 + public String toJsonString() {
  140 + return JsonUtils.beanToJson(this);
  141 + }
  142 +
  143 +}
core.sdk/src/main/java/com/lyms/synch/entity/Model.java View file @ 5e58b2a
1   -package com.lyms.synch.entity;
2   -
3   -/**
4   - * <li>@ClassName: Model
5   - * <li>@Description: 模块信息
6   - * <li>@author maliang
7   - * <li>@date 2017年3月13日
8   - * <li>
9   - */
10   -public enum Model {
11   - USER("用户信息");
12   -
13   - private String des;
14   -
15   - private Model(String des) {
16   - this.des = des;
17   - }
18   -
19   - public String getDes() {
20   - return this.des;
21   - }
22   -}
core.sdk/src/main/java/com/lyms/synch/entity/ModelType.java View file @ 5e58b2a
1   -package com.lyms.synch.entity;
2   -
3   -import java.util.EnumSet;
4   -
5   -/**
6   - * <li>@ClassName: ModelType
7   - * <li>@Description: 数据模型类型
8   - * <li>@author maliang
9   - * <li>@date 2017年3月13日
10   - * <li>
11   - */
12   -public enum ModelType {
13   -
14   - ADD, DEL, UPDATE, GET, ACK;
15   -
16   - public static ModelType exitsType(String typeName) {
17   - for (ModelType modelType : EnumSet.allOf(ModelType.class)) {
18   - if (modelType.name().equalsIgnoreCase(typeName)) {
19   - return modelType;
20   - }
21   - }
22   - return null;
23   - }
24   -
25   - public static boolean isAdd(String type) {
26   - return ADD.equals(exitsType(type));
27   - }
28   -
29   - public static boolean isACK(String type) {
30   - return ACK.equals(exitsType(type));
31   - }
32   -
33   - public static boolean isDel(String type) {
34   - return DEL.equals(exitsType(type));
35   - }
36   -
37   - public static boolean isUpdate(String type) {
38   - return UPDATE.equals(exitsType(type));
39   - }
40   -
41   - public static boolean isGet(String type) {
42   - return GET.equals(exitsType(type));
43   - }
44   -
45   - public static boolean isGet(ModelType type) {
46   - return GET.equals(type);
47   - }
48   -
49   - public static void main(String[] args) {
50   - System.out.println(ModelType.isAdd("add"));
51   - }
52   -
53   -}
core.sdk/src/main/java/com/lyms/synch/entity/SyncnModel.java View file @ 5e58b2a
1   -package com.lyms.synch.entity;
2   -
3   -import java.io.Serializable;
4   -
5   -import com.lyms.util.JsonUtils;
6   -
7   -/**
8   - * <li>@ClassName: SynceModel
9   - * <li>@Description: 数据模型
10   - * <li>@author maliang
11   - * <li>@date 2017年3月13日
12   - * <li>
13   - */
14   -public class SyncnModel implements Serializable {
15   -
16   - /**
17   - */
18   - private static final long serialVersionUID = -5121448640215880284L;
19   -
20   - /**
21   - * 消息模型ID
22   - */
23   - private String id;
24   -
25   - /**
26   - * 远程地址,远程访问的服务地址
27   - */
28   - private String remote;
29   -
30   - /**
31   - * 回调地址,获取数据处理的时候该参数才有实际意义
32   - */
33   - private String callBack;
34   -
35   - /**
36   - * get | post
37   - */
38   - private String method;
39   -
40   - /**
41   - * 操作类型
42   - */
43   - private String type;
44   -
45   - /**
46   - * 模块
47   - */
48   - private String model;
49   -
50   - /**
51   - * 数据信息
52   - */
53   - private Object data;
54   -
55   - /**
56   - * 操作时间
57   - */
58   - private Long ts;
59   -
60   - public String getId() {
61   - return id;
62   - }
63   -
64   - public void setId(String id) {
65   - this.id = id;
66   - }
67   -
68   - public String getType() {
69   - return type;
70   - }
71   -
72   - public void setType(String type) {
73   - this.type = type;
74   - }
75   -
76   - public String getModel() {
77   - return model;
78   - }
79   -
80   - public void setModel(String model) {
81   - this.model = model;
82   - }
83   -
84   - public Object getData() {
85   - return data;
86   - }
87   -
88   - public void setData(Object data) {
89   - this.data = data;
90   - }
91   -
92   - public Long getTs() {
93   - return ts;
94   - }
95   -
96   - public void setTs(Long ts) {
97   - this.ts = ts;
98   - }
99   -
100   - public String getRemote() {
101   - return remote;
102   - }
103   -
104   - public void setRemote(String remote) {
105   - this.remote = remote;
106   - }
107   -
108   - public String getCallBack() {
109   - return callBack;
110   - }
111   -
112   - public void setCallBack(String callBack) {
113   - this.callBack = callBack;
114   - }
115   -
116   - public String getMethod() {
117   - return method;
118   - }
119   -
120   - public void setMethod(String method) {
121   - this.method = method;
122   - }
123   -
124   - public static SyncnModel conver(String body) {
125   - return JsonUtils.jsonToBean(body, SyncnModel.class);
126   - }
127   -
128   - public boolean isAck() {
129   - return ModelType.isACK(getType());
130   - }
131   -
132   -}
core.sdk/src/main/java/com/lyms/synch/queue/SyncnQueue.java View file @ 5e58b2a
... ... @@ -5,8 +5,7 @@
5 5 import org.springframework.data.redis.core.RedisTemplate;
6 6  
7 7 import com.lyms.spring.redis.operation.RedisLock;
8   -import com.lyms.synch.entity.ModelType;
9   -import com.lyms.synch.entity.SyncnModel;
  8 +import com.lyms.synch.entity.ChannelData;
10 9  
11 10 /**
12 11 * <li>@ClassName: SyncnQueue
13 12  
14 13  
15 14  
... ... @@ -73,25 +72,24 @@
73 72 * <li>修改人:
74 73 * <li>修改时间:
75 74 */
76   - private Boolean pushFixationWork(SyncnModel model) {
77   - Long tag = template.opsForList().leftPush(FIXATION_WORK, model);
  75 + private Boolean pushFixationWork(ChannelData data) {
  76 + Long tag = template.opsForList().leftPush(FIXATION_WORK, data);
78 77 return tag >= 1;
79 78 }
80 79  
81   - private SyncnModel pullFixationModel() {
  80 + private ChannelData pullFixationData() {
82 81 // 添加锁
83 82 try {
84   - if (Tmp_Lock.acquireLock(LOCK_FIXATION_NAME, WAIT_LOCK_TIME)) {
85   - SyncnModel obj = (SyncnModel) template.opsForList().rightPopAndLeftPush(FIXATION_WORK, FIXATION_WORK);
86   - // this.pushFixationWork(obj);
  83 + if (Fix_Lock.acquireLock(LOCK_FIXATION_NAME, WAIT_LOCK_TIME)) {
  84 + ChannelData obj = (ChannelData) template.opsForList().rightPopAndLeftPush(FIXATION_WORK, FIXATION_WORK);
87 85 return obj;
88 86 }
89 87 } catch (Exception e) {
90 88 e.printStackTrace();
91 89 } finally {
92 90 try {
93   - if (Tmp_Lock != null) {
94   - Tmp_Lock.releaseLock();
  91 + if (Fix_Lock != null) {
  92 + Fix_Lock.releaseLock();
95 93 }
96 94 } catch (Exception e) {
97 95 e.printStackTrace();
... ... @@ -112,8 +110,8 @@
112 110 * <li>修改人:
113 111 * <li>修改时间:
114 112 */
115   - private boolean pushTempWork(SyncnModel model) {
116   - Long tag = template.opsForList().leftPush(TMP_WORK, model);
  113 + private boolean pushTempWork(ChannelData data) {
  114 + Long tag = template.opsForList().leftPush(TMP_WORK, data);
117 115 return tag >= 1;
118 116 }
119 117  
120 118  
... ... @@ -125,12 +123,12 @@
125 123 * <li>修改人:
126 124 * <li>修改时间:
127 125 */
128   - private SyncnModel pullTempModel() {
  126 + private ChannelData pullTempData() {
129 127  
130 128 try {
131 129 if (Tmp_Lock.acquireLock(LOCK_TMP_NAME, WAIT_LOCK_TIME)) {
132 130 Serializable object = template.opsForList().rightPop(TMP_WORK);
133   - return object != null ? (SyncnModel) object : null;
  131 + return object != null ? (ChannelData) object : null;
134 132 }
135 133 } catch (Exception e) {
136 134 e.printStackTrace();
137 135  
138 136  
... ... @@ -156,23 +154,23 @@
156 154 * <li>修改人:
157 155 * <li>修改时间:
158 156 */
159   - public Boolean push(SyncnModel model) {
160   - if (template == null || model == null)
  157 + public Boolean push(ChannelData data) {
  158 + if (template == null || data == null)
161 159 return Boolean.FALSE;
162 160 // 设置任务添加时间
163   - model.setTs(System.currentTimeMillis());
164   - String modelType = model.getType();
165   - if (ModelType.isGet(modelType)) {
166   - return this.pushFixationWork(model);
167   - } else {
168   - return this.pushTempWork(model);
169   - }
  161 + /*
  162 + * model.setTs(System.currentTimeMillis()); String modelType =
  163 + * model.getType(); if (ModelType.isGet(modelType)) { return
  164 + * this.pushFixationWork(model); } else { return
  165 + * this.pushTempWork(model); }
  166 + */
  167 + boolean loop = data.getLoop();
  168 + return loop ? this.pushFixationWork(data) : this.pushTempWork(data);
170 169 }
171 170  
172 171 /**
173 172 * <li>@Description:获取队列中的数据
174 173 * <p>
175   - * {@link ModelType#GET} 该参数将会获取固定任务列表中的数据{@link ModelType} 其他参数将会获取临时列表中数据
176 174 * <li>@param type
177 175 * <li>@return
178 176 * <li>创建人:maliang
... ... @@ -180,12 +178,13 @@
180 178 * <li>修改人:
181 179 * <li>修改时间:
182 180 */
183   - public SyncnModel pull(ModelType type) {
184   - if (ModelType.isGet(type)) {
185   - return this.pullFixationModel();
186   - } else {
187   - return this.pullTempModel();
188   - }
  181 + public ChannelData pull(boolean loop) {
  182 + // boolean loop = data != null && data.getLoop();
  183 + return loop ? this.pullFixationData() : this.pullTempData();
  184 + /*
  185 + * if (ModelType.isGet(type)) { return this.pullFixationModel(); } else
  186 + * { return this.pullTempModel(); }
  187 + */
189 188 }
190 189  
191 190 public RedisTemplate<Serializable, Serializable> getTemplate() {
core.sdk/src/main/java/com/lyms/util/StrUtils.java View file @ 5e58b2a
Diff suppressed. Click to show
... ... @@ -8,13 +8,14 @@
8 8 import java.util.Arrays;
9 9 import java.util.List;
10 10 import java.util.Map;
11   -import java.util.UUID;
12 11 import java.util.Map.Entry;
13   -/**
14   - * <li>ClassName:StrUtils <br/>
  12 +import java.util.UUID;
  13 +
  14 +/**
  15 + * <li>ClassName:StrUtils <br/>
15 16 * <li>@Description: TODO(类描述)
16   - * <li>@Date: 2016年9月22日 <br/>
17   - * <li>@author 方承
  17 + * <li>@Date: 2016年9月22日 <br/>
  18 + * <li>@author 方承
18 19 */
19 20 public class StrUtils {
20 21  
21 22  
22 23  
23 24  
... ... @@ -36,27 +37,29 @@
36 37  
37 38 public static final String EMPTY_JSON = "{}";
38 39  
39   - // ------------------------------------------------------------------------ Blank
40   -
41   - /**
  40 + // ------------------------------------------------------------------------
  41 + // Blank
  42 +
  43 + /**
42 44 * <li>@Description: 生成32位全大写uuid
43 45 * <li>@return
44 46 * <li>创建人:方承
45 47 * <li>创建时间:2016年1月5日
46 48 * <li>修改人:
47 49 * <li>修改时间:
48   - */
  50 + */
49 51 public static String uuid() {
50 52 return UUID.randomUUID().toString().replace("-", "").toUpperCase();
51 53 }
52   -
  54 +
53 55 /**
54 56 * 字符串是否为空白 空白的定义如下: <br>
55 57 * 1、为null <br>
56 58 * 2、为不可见字符(如空格)<br>
57 59 * 3、""<br>
58 60 *
59   - * @param str 被检测的字符串
  61 + * @param str
  62 + * 被检测的字符串
60 63 * @return 是否为空
61 64 */
62 65 public static boolean isBlank(String str) {
... ... @@ -82,7 +85,8 @@
82 85 * 2、不为不可见字符(如空格)<br>
83 86 * 3、不为""<br>
84 87 *
85   - * @param str 被检测的字符串
  88 + * @param str
  89 + * 被检测的字符串
86 90 * @return 是否为非空
87 91 */
88 92 public static boolean isNotBlank(String str) {
... ... @@ -92,7 +96,8 @@
92 96 /**
93 97 * 是否包含空字符串
94 98 *
95   - * @param strs 字符串列表
  99 + * @param strs
  100 + * 字符串列表
96 101 * @return 是否包含空字符串
97 102 */
98 103 public static boolean hasBlank(String... strs) {
... ... @@ -111,7 +116,8 @@
111 116 /**
112 117 * 给定所有字符串是否为空白
113 118 *
114   - * @param strs 字符串
  119 + * @param strs
  120 + * 字符串
115 121 * @return 所有字符串是否为空白
116 122 */
117 123 public static boolean isAllBlank(String... strs) {
118 124  
... ... @@ -127,12 +133,14 @@
127 133 return true;
128 134 }
129 135  
130   - // ------------------------------------------------------------------------ Empty
  136 + // ------------------------------------------------------------------------
  137 + // Empty
131 138 /**
132 139 * 字符串是否为空,空的定义如下 1、为null <br>
133 140 * 2、为""<br>
134 141 *
135   - * @param str 被检测的字符串
  142 + * @param str
  143 + * 被检测的字符串
136 144 * @return 是否为空
137 145 */
138 146 public static boolean isEmpty(String str) {
... ... @@ -144,7 +152,8 @@
144 152 * 1、不为null <br>
145 153 * 2、不为""<br>
146 154 *
147   - * @param str 被检测的字符串
  155 + * @param str
  156 + * 被检测的字符串
148 157 * @return 是否为非空
149 158 */
150 159 public static boolean isNotEmpty(String str) {
... ... @@ -154,7 +163,8 @@
154 163 /**
155 164 * 当给定字符串为null时,转换为Empty
156 165 *
157   - * @param str 被转换的字符串
  166 + * @param str
  167 + * 被转换的字符串
158 168 * @return 转换后的字符串
159 169 */
160 170 public static String nullToEmpty(String str) {
... ... @@ -171,8 +181,10 @@
171 181 * nullToDefault(&quot;bat&quot;, &quot;default&quot;) = &quot;bat&quot;
172 182 * </pre>
173 183 *
174   - * @param str 要转换的字符串
175   - * @param defaultStr 默认字符串
  184 + * @param str
  185 + * 要转换的字符串
  186 + * @param defaultStr
  187 + * 默认字符串
176 188 *
177 189 * @return 字符串本身或指定的默认字符串
178 190 */
... ... @@ -183,7 +195,8 @@
183 195 /**
184 196 * 当给定字符串为空字符串时,转换为<code>null</code>
185 197 *
186   - * @param str 被转换的字符串
  198 + * @param str
  199 + * 被转换的字符串
187 200 * @return 转换后的字符串
188 201 */
189 202 public static String emptyToNull(String str) {
... ... @@ -193,7 +206,8 @@
193 206 /**
194 207 * 是否包含空字符串
195 208 *
196   - * @param strs 字符串列表
  209 + * @param strs
  210 + * 字符串列表
197 211 * @return 是否包含空字符串
198 212 */
199 213 public static boolean hasEmpty(String... strs) {
... ... @@ -212,7 +226,8 @@
212 226 /**
213 227 * 是否全部为空字符串
214 228 *
215   - * @param strs 字符串列表
  229 + * @param strs
  230 + * 字符串列表
216 231 * @return 是否全部为空字符串
217 232 */
218 233 public static boolean isAllEmpty(String... strs) {
219 234  
... ... @@ -228,12 +243,14 @@
228 243 return true;
229 244 }
230 245  
231   - // ------------------------------------------------------------------------ Trim
  246 + // ------------------------------------------------------------------------
  247 + // Trim
232 248 /**
233 249 * 除去字符串头尾部的空白,如果字符串是<code>null</code>,依然返回<code>null</code>。
234 250 *
235 251 * <p>
236   - * 注意,和<code>String.trim</code>不同,此方法使用<code>Character.isWhitespace</code> 来判定空白, 因而可以除去英文字符集之外的其它空白,如中文空格。
  252 + * 注意,和<code>String.trim</code>不同,此方法使用<code>Character.isWhitespace</code>
  253 + * 来判定空白, 因而可以除去英文字符集之外的其它空白,如中文空格。
237 254 *
238 255 * <pre>
239 256 * trim(null) = null
... ... @@ -245,7 +262,8 @@
245 262 *
246 263 * </p>
247 264 *
248   - * @param str 要处理的字符串
  265 + * @param str
  266 + * 要处理的字符串
249 267 *
250 268 * @return 除去空白的字符串,如果原字串为<code>null</code>,则返回<code>null</code>
251 269 */
... ... @@ -256,7 +274,8 @@
256 274 /**
257 275 * 给定字符串数组全部做去首尾空格
258 276 *
259   - * @param strs 字符串数组
  277 + * @param strs
  278 + * 字符串数组
260 279 */
261 280 public static void trim(String[] strs) {
262 281 if (null == strs) {
... ... @@ -275,7 +294,8 @@
275 294 * 除去字符串头部的空白,如果字符串是<code>null</code>,则返回<code>null</code>。
276 295 *
277 296 * <p>
278   - * 注意,和<code>String.trim</code>不同,此方法使用<code>Character.isWhitespace</code> 来判定空白, 因而可以除去英文字符集之外的其它空白,如中文空格。
  297 + * 注意,和<code>String.trim</code>不同,此方法使用<code>Character.isWhitespace</code>
  298 + * 来判定空白, 因而可以除去英文字符集之外的其它空白,如中文空格。
279 299 *
280 300 * <pre>
281 301 * trimStart(null) = null
282 302  
... ... @@ -288,9 +308,11 @@
288 308 *
289 309 * </p>
290 310 *
291   - * @param str 要处理的字符串
  311 + * @param str
  312 + * 要处理的字符串
292 313 *
293   - * @return 除去空白的字符串,如果原字串为<code>null</code>或结果字符串为<code>""</code>,则返回 <code>null</code>
  314 + * @return 除去空白的字符串,如果原字串为<code>null</code>或结果字符串为<code>""</code>,则返回
  315 + * <code>null</code>
294 316 */
295 317 public static String trimStart(String str) {
296 318 return trim(str, -1);
... ... @@ -300,7 +322,8 @@
300 322 * 除去字符串尾部的空白,如果字符串是<code>null</code>,则返回<code>null</code>。
301 323 *
302 324 * <p>
303   - * 注意,和<code>String.trim</code>不同,此方法使用<code>Character.isWhitespace</code> 来判定空白, 因而可以除去英文字符集之外的其它空白,如中文空格。
  325 + * 注意,和<code>String.trim</code>不同,此方法使用<code>Character.isWhitespace</code>
  326 + * 来判定空白, 因而可以除去英文字符集之外的其它空白,如中文空格。
304 327 *
305 328 * <pre>
306 329 * trimEnd(null) = null
307 330  
... ... @@ -313,9 +336,11 @@
313 336 *
314 337 * </p>
315 338 *
316   - * @param str 要处理的字符串
  339 + * @param str
  340 + * 要处理的字符串
317 341 *
318   - * @return 除去空白的字符串,如果原字串为<code>null</code>或结果字符串为<code>""</code>,则返回 <code>null</code>
  342 + * @return 除去空白的字符串,如果原字串为<code>null</code>或结果字符串为<code>""</code>,则返回
  343 + * <code>null</code>
319 344 */
320 345 public static String trimEnd(String str) {
321 346 return trim(str, 1);
... ... @@ -324,8 +349,11 @@
324 349 /**
325 350 * 除去字符串头尾部的空白符,如果字符串是<code>null</code>,依然返回<code>null</code>。
326 351 *
327   - * @param str 要处理的字符串
328   - * @param mode <code>-1</code>表示trimStart,<code>0</code>表示trim全部, <code>1</code>表示trimEnd
  352 + * @param str
  353 + * 要处理的字符串
  354 + * @param mode
  355 + * <code>-1</code>表示trimStart,<code>0</code>表示trim全部,
  356 + * <code>1</code>表示trimEnd
329 357 *
330 358 * @return 除去指定字符后的的字符串,如果原字串为<code>null</code>,则返回<code>null</code>
331 359 */
332 360  
333 361  
334 362  
335 363  
336 364  
337 365  
338 366  
339 367  
340 368  
341 369  
... ... @@ -358,46 +386,57 @@
358 386  
359 387 return str;
360 388 }
361   -
  389 +
362 390 /**
363 391 * 是否以指定字符串开头
364   - * @param str 被监测字符串
365   - * @param prefix 开头字符串
366   - * @param isIgnoreCase 是否忽略大小写
  392 + *
  393 + * @param str
  394 + * 被监测字符串
  395 + * @param prefix
  396 + * 开头字符串
  397 + * @param isIgnoreCase
  398 + * 是否忽略大小写
367 399 * @return 是否以指定字符串开头
368 400 */
369   - public static boolean startWith(String str, String prefix, boolean isIgnoreCase){
370   - if(isIgnoreCase){
  401 + public static boolean startWith(String str, String prefix, boolean isIgnoreCase) {
  402 + if (isIgnoreCase) {
371 403 return str.toLowerCase().startsWith(prefix.toLowerCase());
372   - }else{
  404 + } else {
373 405 return str.startsWith(prefix);
374 406 }
375 407 }
376   -
  408 +
377 409 /**
378 410 * 是否以指定字符串结尾
379   - * @param str 被监测字符串
380   - * @param suffix 结尾字符串
381   - * @param isIgnoreCase 是否忽略大小写
  411 + *
  412 + * @param str
  413 + * 被监测字符串
  414 + * @param suffix
  415 + * 结尾字符串
  416 + * @param isIgnoreCase
  417 + * 是否忽略大小写
382 418 * @return 是否以指定字符串结尾
383 419 */
384   - public static boolean endWith(String str, String suffix, boolean isIgnoreCase){
385   - if(isIgnoreCase){
  420 + public static boolean endWith(String str, String suffix, boolean isIgnoreCase) {
  421 + if (isIgnoreCase) {
386 422 return str.toLowerCase().endsWith(suffix.toLowerCase());
387   - }else{
  423 + } else {
388 424 return str.endsWith(suffix);
389 425 }
390 426 }
391   -
  427 +
392 428 /**
393 429 * 是否包含特定字符,忽略大小写,如果给定两个参数都为<code>null</code>,返回true
394   - * @param str 被检测字符串
395   - * @param testStr 被测试是否包含的字符串
  430 + *
  431 + * @param str
  432 + * 被检测字符串
  433 + * @param testStr
  434 + * 被测试是否包含的字符串
396 435 * @return 是否包含
397 436 */
398   - public static boolean containsIgnoreCase(String str, String testStr){
399   - if(null == str){
400   - //如果被监测字符串和
  437 + public static boolean containsIgnoreCase(String str, String testStr) {
  438 + if (null == str) {
  439 + // 如果被监测字符串和
401 440 return null == testStr;
402 441 }
403 442 return str.toLowerCase().contains(testStr.toLowerCase());
... ... @@ -421,7 +460,8 @@
421 460 * 生成set方法名<br/>
422 461 * 例如:name 返回 setName
423 462 *
424   - * @param fieldName 属性名
  463 + * @param fieldName
  464 + * 属性名
425 465 * @return setXxx
426 466 */
427 467 public static String genSetter(String fieldName) {
... ... @@ -431,7 +471,8 @@
431 471 /**
432 472 * 生成get方法名
433 473 *
434   - * @param fieldName 属性名
  474 + * @param fieldName
  475 + * 属性名
435 476 * @return getXxx
436 477 */
437 478 public static String genGetter(String fieldName) {
... ... @@ -442,8 +483,10 @@
442 483 * 去掉首部指定长度的字符串并将剩余字符串首字母小写<br/>
443 484 * 例如:str=setName, preLength=3 -> return name
444 485 *
445   - * @param str 被处理的字符串
446   - * @param preLength 去掉的长度
  486 + * @param str
  487 + * 被处理的字符串
  488 + * @param preLength
  489 + * 去掉的长度
447 490 * @return 处理后的字符串,不符合规范返回null
448 491 */
449 492 public static String cutPreAndLowerFirst(String str, int preLength) {
... ... @@ -463,8 +506,10 @@
463 506 /**
464 507 * 原字符串首字母大写并在其首部添加指定字符串 例如:str=name, preString=get -> return getName
465 508 *
466   - * @param str 被处理的字符串
467   - * @param preString 添加的首部
  509 + * @param str
  510 + * 被处理的字符串
  511 + * @param preString
  512 + * 添加的首部
468 513 * @return 处理后的字符串
469 514 */
470 515 public static String upperFirstAndAddPre(String str, String preString) {
... ... @@ -478,7 +523,8 @@
478 523 * 大写首字母<br>
479 524 * 例如:str = name, return Name
480 525 *
481   - * @param str 字符串
  526 + * @param str
  527 + * 字符串
482 528 * @return 字符串
483 529 */
484 530 public static String upperFirst(String str) {
485 531  
... ... @@ -489,11 +535,12 @@
489 535 * 小写首字母<br>
490 536 * 例如:str = Name, return name
491 537 *
492   - * @param str 字符串
  538 + * @param str
  539 + * 字符串
493 540 * @return 字符串
494 541 */
495 542 public static String lowerFirst(String str) {
496   - if(isBlank(str)){
  543 + if (isBlank(str)) {
497 544 return str;
498 545 }
499 546 return Character.toLowerCase(str.charAt(0)) + str.substring(1);
500 547  
501 548  
... ... @@ -502,15 +549,17 @@
502 549 /**
503 550 * 去掉指定前缀
504 551 *
505   - * @param str 字符串
506   - * @param prefix 前缀
  552 + * @param str
  553 + * 字符串
  554 + * @param prefix
  555 + * 前缀
507 556 * @return 切掉后的字符串,若前缀不是 preffix, 返回原字符串
508 557 */
509 558 public static String removePrefix(String str, String prefix) {
510   - if(isEmpty(str) || isEmpty(prefix)){
  559 + if (isEmpty(str) || isEmpty(prefix)) {
511 560 return str;
512 561 }
513   -
  562 +
514 563 if (str.startsWith(prefix)) {
515 564 return str.substring(prefix.length());
516 565 }
517 566  
518 567  
... ... @@ -520,15 +569,17 @@
520 569 /**
521 570 * 忽略大小写去掉指定前缀
522 571 *
523   - * @param str 字符串
524   - * @param prefix 前缀
  572 + * @param str
  573 + * 字符串
  574 + * @param prefix
  575 + * 前缀
525 576 * @return 切掉后的字符串,若前缀不是 prefix, 返回原字符串
526 577 */
527 578 public static String removePrefixIgnoreCase(String str, String prefix) {
528   - if(isEmpty(str) || isEmpty(prefix)){
  579 + if (isEmpty(str) || isEmpty(prefix)) {
529 580 return str;
530 581 }
531   -
  582 +
532 583 if (str.toLowerCase().startsWith(prefix.toLowerCase())) {
533 584 return str.substring(prefix.length());
534 585 }
535 586  
536 587  
... ... @@ -538,15 +589,17 @@
538 589 /**
539 590 * 去掉指定后缀
540 591 *
541   - * @param str 字符串
542   - * @param suffix 后缀
  592 + * @param str
  593 + * 字符串
  594 + * @param suffix
  595 + * 后缀
543 596 * @return 切掉后的字符串,若后缀不是 suffix, 返回原字符串
544 597 */
545 598 public static String removeSuffix(String str, String suffix) {
546   - if(isEmpty(str) || isEmpty(suffix)){
  599 + if (isEmpty(str) || isEmpty(suffix)) {
547 600 return str;
548 601 }
549   -
  602 +
550 603 if (str.endsWith(suffix)) {
551 604 return str.substring(0, str.length() - suffix.length());
552 605 }
553 606  
554 607  
555 608  
556 609  
557 610  
558 611  
559 612  
560 613  
561 614  
562 615  
... ... @@ -556,48 +609,56 @@
556 609 /**
557 610 * 忽略大小写去掉指定后缀
558 611 *
559   - * @param str 字符串
560   - * @param suffix 后缀
  612 + * @param str
  613 + * 字符串
  614 + * @param suffix
  615 + * 后缀
561 616 * @return 切掉后的字符串,若后缀不是 suffix, 返回原字符串
562 617 */
563 618 public static String removeSuffixIgnoreCase(String str, String suffix) {
564   - if(isEmpty(str) || isEmpty(suffix)){
  619 + if (isEmpty(str) || isEmpty(suffix)) {
565 620 return str;
566 621 }
567   -
  622 +
568 623 if (str.toLowerCase().endsWith(suffix.toLowerCase())) {
569 624 return str.substring(0, str.length() - suffix.length());
570 625 }
571 626 return str;
572 627 }
573   -
  628 +
574 629 /**
575 630 * 如果给定字符串不是以prefix开头的,在开头补充 prefix
576   - * @param str 字符串
577   - * @param prefix 前缀
  631 + *
  632 + * @param str
  633 + * 字符串
  634 + * @param prefix
  635 + * 前缀
578 636 * @return 补充后的字符串
579 637 */
580   - public static String addPrefixIfNot(String str, String prefix){
581   - if(isEmpty(str) || isEmpty(prefix)){
  638 + public static String addPrefixIfNot(String str, String prefix) {
  639 + if (isEmpty(str) || isEmpty(prefix)) {
582 640 return str;
583 641 }
584   - if(false == str.startsWith(prefix)){
  642 + if (false == str.startsWith(prefix)) {
585 643 str = prefix + str;
586 644 }
587 645 return str;
588 646 }
589   -
  647 +
590 648 /**
591 649 * 如果给定字符串不是以suffix结尾的,在尾部补充 suffix
592   - * @param str 字符串
593   - * @param suffix 后缀
  650 + *
  651 + * @param str
  652 + * 字符串
  653 + * @param suffix
  654 + * 后缀
594 655 * @return 补充后的字符串
595 656 */
596   - public static String addSuffixIfNot(String str, String suffix){
597   - if(isEmpty(str) || isEmpty(suffix)){
  657 + public static String addSuffixIfNot(String str, String suffix) {
  658 + if (isEmpty(str) || isEmpty(suffix)) {
598 659 return str;
599 660 }
600   - if(false == str.endsWith(suffix)){
  661 + if (false == str.endsWith(suffix)) {
601 662 str += suffix;
602 663 }
603 664 return str;
... ... @@ -606,7 +667,8 @@
606 667 /**
607 668 * 清理空白字符
608 669 *
609   - * @param str 被清理的字符串
  670 + * @param str
  671 + * 被清理的字符串
610 672 * @return 清理后的字符串
611 673 */
612 674 public static String cleanBlank(String str) {
... ... @@ -622,8 +684,10 @@
622 684 * a#b#c -> [a,b,c] <br>
623 685 * a##b#c -> [a,"",b,c]
624 686 *
625   - * @param str 被切分的字符串
626   - * @param separator 分隔符字符
  687 + * @param str
  688 + * 被切分的字符串
  689 + * @param separator
  690 + * 分隔符字符
627 691 * @return 切分后的集合
628 692 */
629 693 public static List<String> split(String str, char separator) {
... ... @@ -633,9 +697,12 @@
633 697 /**
634 698 * 切分字符串
635 699 *
636   - * @param str 被切分的字符串
637   - * @param separator 分隔符字符
638   - * @param limit 限制分片数
  700 + * @param str
  701 + * 被切分的字符串
  702 + * @param separator
  703 + * 分隔符字符
  704 + * @param limit
  705 + * 限制分片数
639 706 * @return 切分后的集合
640 707 */
641 708 public static List<String> split(String str, char separator, int limit) {
... ... @@ -674,8 +741,10 @@
674 741 * 切分字符串<br>
675 742 * from jodd
676 743 *
677   - * @param str 被切分的字符串
678   - * @param delimiter 分隔符
  744 + * @param str
  745 + * 被切分的字符串
  746 + * @param delimiter
  747 + * 分隔符
679 748 * @return 字符串
680 749 */
681 750 public static String[] split(String str, String delimiter) {
... ... @@ -714,9 +783,12 @@
714 783 * index从0开始计算,最后一个字符为-1<br>
715 784 * 如果from和to位置一样,返回 "" example: abcdefgh 2 3 -> c abcdefgh 2 -3 -> cde
716 785 *
717   - * @param string String
718   - * @param fromIndex 开始的index(包括)
719   - * @param toIndex 结束的index(不包括)
  786 + * @param string
  787 + * String
  788 + * @param fromIndex
  789 + * 开始的index(包括)
  790 + * @param toIndex
  791 + * 结束的index(不包括)
720 792 * @return 字串
721 793 */
722 794 public static String sub(String string, int fromIndex, int toIndex) {
... ... @@ -752,8 +824,10 @@
752 824 /**
753 825 * 切割前部分
754 826 *
755   - * @param string 字符串
756   - * @param toIndex 切割到的位置(不包括)
  827 + * @param string
  828 + * 字符串
  829 + * @param toIndex
  830 + * 切割到的位置(不包括)
757 831 * @return 切割后的字符串
758 832 */
759 833 public static String subPre(String string, int toIndex) {
... ... @@ -763,8 +837,10 @@
763 837 /**
764 838 * 切割后部分
765 839 *
766   - * @param string 字符串
767   - * @param fromIndex 切割开始的位置(包括)
  840 + * @param string
  841 + * 字符串
  842 + * @param fromIndex
  843 + * 切割开始的位置(包括)
768 844 * @return 切割后的字符串
769 845 */
770 846 public static String subSuf(String string, int fromIndex) {
... ... @@ -777,9 +853,12 @@
777 853 /**
778 854 * 给定字符串是否被字符包围
779 855 *
780   - * @param str 字符串
781   - * @param prefix 前缀
782   - * @param suffix 后缀
  856 + * @param str
  857 + * 字符串
  858 + * @param prefix
  859 + * 前缀
  860 + * @param suffix
  861 + * 后缀
783 862 * @return 是否包围,空串不包围
784 863 */
785 864 public static boolean isSurround(String str, String prefix, String suffix) {
... ... @@ -796,9 +875,12 @@
796 875 /**
797 876 * 给定字符串是否被字符包围
798 877 *
799   - * @param str 字符串
800   - * @param prefix 前缀
801   - * @param suffix 后缀
  878 + * @param str
  879 + * 字符串
  880 + * @param prefix
  881 + * 前缀
  882 + * @param suffix
  883 + * 后缀
802 884 * @return 是否包围,空串不包围
803 885 */
804 886 public static boolean isSurround(String str, char prefix, char suffix) {
... ... @@ -815,8 +897,10 @@
815 897 /**
816 898 * 重复某个字符
817 899 *
818   - * @param c 被重复的字符
819   - * @param count 重复的数目
  900 + * @param c
  901 + * 被重复的字符
  902 + * @param count
  903 + * 重复的数目
820 904 * @return 重复字符字符串
821 905 */
822 906 public static String repeat(char c, int count) {
... ... @@ -830,8 +914,10 @@
830 914 /**
831 915 * 重复某个字符串
832 916 *
833   - * @param str 被重复的字符
834   - * @param count 重复的数目
  917 + * @param str
  918 + * 被重复的字符
  919 + * @param count
  920 + * 重复的数目
835 921 * @return 重复字符字符串
836 922 */
837 923 public static String repeat(String str, int count) {
... ... @@ -865,8 +951,10 @@
865 951 * equals(&quot;abc&quot;, &quot;ABC&quot;) = false
866 952 * </pre>
867 953 *
868   - * @param str1 要比较的字符串1
869   - * @param str2 要比较的字符串2
  954 + * @param str1
  955 + * 要比较的字符串1
  956 + * @param str2
  957 + * 要比较的字符串2
870 958 *
871 959 * @return 如果两个字符串相同,或者都是<code>null</code>,则返回<code>true</code>
872 960 */
... ... @@ -889,8 +977,10 @@
889 977 * equalsIgnoreCase(&quot;abc&quot;, &quot;ABC&quot;) = true
890 978 * </pre>
891 979 *
892   - * @param str1 要比较的字符串1
893   - * @param str2 要比较的字符串2
  980 + * @param str1
  981 + * 要比较的字符串1
  982 + * @param str2
  983 + * 要比较的字符串2
894 984 *
895 985 * @return 如果两个字符串相同,或者都是<code>null</code>,则返回<code>true</code>
896 986 */
897 987  
... ... @@ -904,10 +994,12 @@
904 994  
905 995 /**
906 996 * 格式化文本, {} 表示占位符<br>
907   - * 例如:format("aaa {} ccc", "bbb") ----> aaa bbb ccc
  997 + * 例如:format("aaa {} ccc", "bbb") ----> aaa bbb ccc
908 998 *
909   - * @param template 文本模板,被替换的部分用 {} 表示
910   - * @param values 参数值
  999 + * @param template
  1000 + * 文本模板,被替换的部分用 {} 表示
  1001 + * @param values
  1002 + * 参数值
911 1003 * @return 格式化后的文本
912 1004 */
913 1005 public static String format(String template, Object... values) {
914 1006  
... ... @@ -945,11 +1037,13 @@
945 1037  
946 1038 /**
947 1039 * 格式化文本,使用 {varName} 占位<br>
948   - * map = {a: "aValue", b: "bValue"}
949   - * format("{a} and {b}", map) ----> aValue and bValue
  1040 + * map = {a: "aValue", b: "bValue"} format("{a} and {b}", map) ----> aValue
  1041 + * and bValue
950 1042 *
951   - * @param template 文本模板,被替换的部分用 {key} 表示
952   - * @param map 参数值对
  1043 + * @param template
  1044 + * 文本模板,被替换的部分用 {key} 表示
  1045 + * @param map
  1046 + * 参数值对
953 1047 * @return 格式化后的文本
954 1048 */
955 1049 public static String format(String template, Map<?, ?> map) {
956 1050  
... ... @@ -962,12 +1056,14 @@
962 1056 }
963 1057 return template;
964 1058 }
965   -
  1059 +
966 1060 /**
967 1061 * 编码字符串
968 1062 *
969   - * @param str 字符串
970   - * @param charset 字符集,如果此字段为空,则解码的结果取决于平台
  1063 + * @param str
  1064 + * 字符串
  1065 + * @param charset
  1066 + * 字符集,如果此字段为空,则解码的结果取决于平台
971 1067 * @return 编码后的字节码
972 1068 */
973 1069 public static byte[] bytes(String str, String charset) {
... ... @@ -977,8 +1073,10 @@
977 1073 /**
978 1074 * 编码字符串
979 1075 *
980   - * @param str 字符串
981   - * @param charset 字符集,如果此字段为空,则解码的结果取决于平台
  1076 + * @param str
  1077 + * 字符串
  1078 + * @param charset
  1079 + * 字符集,如果此字段为空,则解码的结果取决于平台
982 1080 * @return 编码后的字节码
983 1081 */
984 1082 public static byte[] bytes(String str, Charset charset) {
985 1083  
986 1084  
987 1085  
988 1086  
989 1087  
990 1088  
991 1089  
992 1090  
993 1091  
994 1092  
995 1093  
996 1094  
997 1095  
998 1096  
999 1097  
... ... @@ -991,64 +1089,68 @@
991 1089 }
992 1090 return str.getBytes(charset);
993 1091 }
994   -
  1092 +
995 1093 /**
996 1094 * 将对象转为字符串<br>
997   - * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组
998   - * 2、对象数组会调用Arrays.toString方法
  1095 + * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
999 1096 *
1000   - * @param obj 对象
  1097 + * @param obj
  1098 + * 对象
1001 1099 * @return 字符串
1002 1100 */
1003   - public static String utf8Str(Object obj){
  1101 + public static String utf8Str(Object obj) {
1004 1102 return str(obj, CharsetUtils.CHARSET_UTF_8);
1005 1103 }
1006   -
  1104 +
1007 1105 /**
1008 1106 * 将对象转为字符串<br>
1009   - * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组
1010   - * 2、对象数组会调用Arrays.toString方法
  1107 + * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
1011 1108 *
1012   - * @param obj 对象
1013   - * @param charsetName 字符集
  1109 + * @param obj
  1110 + * 对象
  1111 + * @param charsetName
  1112 + * 字符集
1014 1113 * @return 字符串
1015 1114 */
1016   - public static String str(Object obj, String charsetName){
  1115 + public static String str(Object obj, String charsetName) {
1017 1116 return str(obj, Charset.forName(charsetName));
1018 1117 }
1019   -
  1118 +
1020 1119 /**
1021 1120 * 将对象转为字符串<br>
1022   - * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组
1023   - * 2、对象数组会调用Arrays.toString方法
  1121 + * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
1024 1122 *
1025   - * @param obj 对象
1026   - * @param charset 字符集
  1123 + * @param obj
  1124 + * 对象
  1125 + * @param charset
  1126 + * 字符集
1027 1127 * @return 字符串
1028 1128 */
1029   - public static String str(Object obj, Charset charset){
1030   - if(null == obj){
  1129 + public static String str(Object obj, Charset charset) {
  1130 + if (null == obj) {
1031 1131 return null;
1032 1132 }
1033   -
1034   - if(obj instanceof String) {
1035   - return (String)obj;
1036   - }else if(obj instanceof byte[] || obj instanceof Byte[]){
1037   - return str((Byte[])obj, charset);
1038   - }else if(obj instanceof ByteBuffer){
1039   - return str((ByteBuffer)obj, charset);
1040   - }else if(CollectionUtils.isArray(obj)){
  1133 +
  1134 + if (obj instanceof String) {
  1135 + return (String) obj;
  1136 + } else if (obj instanceof byte[] || obj instanceof Byte[]) {
  1137 + return str((Byte[]) obj, charset);
  1138 + } else if (obj instanceof ByteBuffer) {
  1139 + return str((ByteBuffer) obj, charset);
  1140 + } else if (CollectionUtils.isArray(obj)) {
1041 1141 return CollectionUtils.toString(obj);
1042 1142 }
1043   -
  1143 +
1044 1144 return obj.toString();
1045 1145 }
1046   -
  1146 +
1047 1147 /**
1048 1148 * 将byte数组转为字符串
1049 1149 *
1050   - * @param bytes byte数组
1051   - * @param charset 字符集
  1150 + * @param bytes
  1151 + * byte数组
  1152 + * @param charset
  1153 + * 字符集
1052 1154 * @return 字符串
1053 1155 */
1054 1156 public static String str(byte[] bytes, String charset) {
... ... @@ -1058,8 +1160,10 @@
1058 1160 /**
1059 1161 * 解码字节码
1060 1162 *
1061   - * @param data 字符串
1062   - * @param charset 字符集,如果此字段为空,则解码的结果取决于平台
  1163 + * @param data
  1164 + * 字符串
  1165 + * @param charset
  1166 + * 字符集,如果此字段为空,则解码的结果取决于平台
1063 1167 * @return 解码后的字符串
1064 1168 */
1065 1169 public static String str(byte[] data, Charset charset) {
1066 1170  
1067 1171  
1068 1172  
1069 1173  
1070 1174  
1071 1175  
1072 1176  
1073 1177  
... ... @@ -1072,38 +1176,47 @@
1072 1176 }
1073 1177 return new String(data, charset);
1074 1178 }
1075   -
  1179 +
1076 1180 /**
1077 1181 * 将编码的byteBuffer数据转换为字符串
1078   - * @param data 数据
1079   - * @param charset 字符集,如果为空使用当前系统字符集
  1182 + *
  1183 + * @param data
  1184 + * 数据
  1185 + * @param charset
  1186 + * 字符集,如果为空使用当前系统字符集
1080 1187 * @return 字符串
1081 1188 */
1082   - public static String str(ByteBuffer data, String charset){
1083   - if(data == null) {
  1189 + public static String str(ByteBuffer data, String charset) {
  1190 + if (data == null) {
1084 1191 return null;
1085 1192 }
1086   -
  1193 +
1087 1194 return str(data, Charset.forName(charset));
1088 1195 }
1089   -
  1196 +
1090 1197 /**
1091 1198 * 将编码的byteBuffer数据转换为字符串
1092   - * @param data 数据
1093   - * @param charset 字符集,如果为空使用当前系统字符集
  1199 + *
  1200 + * @param data
  1201 + * 数据
  1202 + * @param charset
  1203 + * 字符集,如果为空使用当前系统字符集
1094 1204 * @return 字符串
1095 1205 */
1096   - public static String str(ByteBuffer data, Charset charset){
1097   - if(null == charset) {
  1206 + public static String str(ByteBuffer data, Charset charset) {
  1207 + if (null == charset) {
1098 1208 charset = Charset.defaultCharset();
1099 1209 }
1100 1210 return charset.decode(data).toString();
1101 1211 }
1102   -
  1212 +
1103 1213 /**
1104 1214 * 字符串转换为byteBuffer
1105   - * @param str 字符串
1106   - * @param charset 编码
  1215 + *
  1216 + * @param str
  1217 + * 字符串
  1218 + * @param charset
  1219 + * 编码
1107 1220 * @return byteBuffer
1108 1221 */
1109 1222 public static ByteBuffer byteBuffer(String str, String charset) {
... ... @@ -1113,8 +1226,10 @@
1113 1226 /**
1114 1227 * 以 conjunction 为分隔符将多个对象转换为字符串
1115 1228 *
1116   - * @param conjunction 分隔符
1117   - * @param objs 数组
  1229 + * @param conjunction
  1230 + * 分隔符
  1231 + * @param objs
  1232 + * 数组
1118 1233 * @return 连接后的字符串
1119 1234 */
1120 1235 public static String join(String conjunction, Object... objs) {
1121 1236  
... ... @@ -1130,12 +1245,13 @@
1130 1245 }
1131 1246 return sb.toString();
1132 1247 }
1133   -
  1248 +
1134 1249 /**
1135 1250 * 将驼峰式命名的字符串转换为下划线方式。如果转换前的驼峰式命名的字符串为空,则返回空字符串。</br>
1136 1251 * 例如:HelloWorld->hello_world
1137 1252 *
1138   - * @param camelCaseStr 转换前的驼峰式命名的字符串
  1253 + * @param camelCaseStr
  1254 + * 转换前的驼峰式命名的字符串
1139 1255 * @return 转换后下划线大写方式命名的字符串
1140 1256 */
1141 1257 public static String toUnderlineCase(String camelCaseStr) {
... ... @@ -1155,7 +1271,8 @@
1155 1271 }
1156 1272 if (Character.isUpperCase(c)) {
1157 1273 if (!isPreUpperCase || !isNextUpperCase) {
1158   - if (i > 0) sb.append(UNDERLINE);
  1274 + if (i > 0)
  1275 + sb.append(UNDERLINE);
1159 1276 }
1160 1277 isPreUpperCase = true;
1161 1278 } else {
... ... @@ -1170,7 +1287,8 @@
1170 1287 * 将下划线方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。</br>
1171 1288 * 例如:hello_world->HelloWorld
1172 1289 *
1173   - * @param name 转换前的下划线大写方式命名的字符串
  1290 + * @param name
  1291 + * 转换前的下划线大写方式命名的字符串
1174 1292 * @return 转换后的驼峰式命名的字符串
1175 1293 */
1176 1294 public static String toCamelCase(String name) {
... ... @@ -1202,9 +1320,12 @@
1202 1320 /**
1203 1321 * 包装指定字符串
1204 1322 *
1205   - * @param str 被包装的字符串
1206   - * @param prefix 前缀
1207   - * @param suffix 后缀
  1323 + * @param str
  1324 + * 被包装的字符串
  1325 + * @param prefix
  1326 + * 前缀
  1327 + * @param suffix
  1328 + * 后缀
1208 1329 * @return 包装后的字符串
1209 1330 */
1210 1331 public static String wrap(String str, String prefix, String suffix) {
... ... @@ -1214,9 +1335,12 @@
1214 1335 /**
1215 1336 * 指定字符串是否被包装
1216 1337 *
1217   - * @param str 字符串
1218   - * @param prefix 前缀
1219   - * @param suffix 后缀
  1338 + * @param str
  1339 + * 字符串
  1340 + * @param prefix
  1341 + * 前缀
  1342 + * @param suffix
  1343 + * 后缀
1220 1344 * @return 是否被包装
1221 1345 */
1222 1346 public static boolean isWrap(String str, String prefix, String suffix) {
... ... @@ -1226,8 +1350,10 @@
1226 1350 /**
1227 1351 * 指定字符串是否被同一字符包装(前后都有这些字符串)
1228 1352 *
1229   - * @param str 字符串
1230   - * @param wrapper 包装字符串
  1353 + * @param str
  1354 + * 字符串
  1355 + * @param wrapper
  1356 + * 包装字符串
1231 1357 * @return 是否被包装
1232 1358 */
1233 1359 public static boolean isWrap(String str, String wrapper) {
... ... @@ -1237,8 +1363,10 @@
1237 1363 /**
1238 1364 * 指定字符串是否被同一字符包装(前后都有这些字符串)
1239 1365 *
1240   - * @param str 字符串
1241   - * @param wrapper 包装字符
  1366 + * @param str
  1367 + * 字符串
  1368 + * @param wrapper
  1369 + * 包装字符
1242 1370 * @return 是否被包装
1243 1371 */
1244 1372 public static boolean isWrap(String str, char wrapper) {
... ... @@ -1248,9 +1376,12 @@
1248 1376 /**
1249 1377 * 指定字符串是否被包装
1250 1378 *
1251   - * @param str 字符串
1252   - * @param prefixChar 前缀
1253   - * @param suffixChar 后缀
  1379 + * @param str
  1380 + * 字符串
  1381 + * @param prefixChar
  1382 + * 前缀
  1383 + * @param suffixChar
  1384 + * 后缀
1254 1385 * @return 是否被包装
1255 1386 */
1256 1387 public static boolean isWrap(String str, char prefixChar, char suffixChar) {
... ... @@ -1260,9 +1391,12 @@
1260 1391 /**
1261 1392 * 补充字符串以满足最小长度 StrUtil.padPre("1", 3, '0');//"001"
1262 1393 *
1263   - * @param str 字符串
1264   - * @param minLength 最小长度
1265   - * @param padChar 补充的字符
  1394 + * @param str
  1395 + * 字符串
  1396 + * @param minLength
  1397 + * 最小长度
  1398 + * @param padChar
  1399 + * 补充的字符
1266 1400 * @return 补充后的字符串
1267 1401 */
1268 1402 public static String padPre(String str, int minLength, char padChar) {
... ... @@ -1280,9 +1414,12 @@
1280 1414 /**
1281 1415 * 补充字符串以满足最小长度 StrUtil.padEnd("1", 3, '0');//"100"
1282 1416 *
1283   - * @param str 字符串
1284   - * @param minLength 最小长度
1285   - * @param padChar 补充的字符
  1417 + * @param str
  1418 + * 字符串
  1419 + * @param minLength
  1420 + * 最小长度
  1421 + * @param padChar
  1422 + * 补充的字符
1286 1423 * @return 补充后的字符串
1287 1424 */
1288 1425 public static String padEnd(String str, int minLength, char padChar) {
... ... @@ -1331,7 +1468,8 @@
1331 1468 /**
1332 1469 * 获得StringReader
1333 1470 *
1334   - * @param str 字符串
  1471 + * @param str
  1472 + * 字符串
1335 1473 * @return StringReader
1336 1474 */
1337 1475 public static StringReader getReader(String str) {
core.sdk/src/main/java/com/lyms/util/remote/HttpRemote.java View file @ 5e58b2a
... ... @@ -11,7 +11,7 @@
11 11 import org.apache.http.client.protocol.HttpClientContext;
12 12 import org.apache.http.entity.SerializableEntity;
13 13  
14   -import com.lyms.synch.entity.SyncnModel;
  14 +import com.lyms.synch.entity.ChannelData;
15 15  
16 16 /**
17 17 * http,https 远程调用
18 18  
19 19  
20 20  
21 21  
... ... @@ -28,35 +28,25 @@
28 28 return new HttpRemote();
29 29 }
30 30  
31   - public String post(SyncnModel model) {
32   - if (model == null)
  31 + public String post(ChannelData data) {
  32 + if (data == null)
33 33 return null;
34 34  
35   - String url = model.getRemote();
  35 + String url = data.getRemote();
36 36 HttpClientContext httpContext = HttpClientContext.create();
37 37 HttpPost post = new HttpPost(url);
38 38 HttpEntity entity = null;
39 39 CloseableHttpResponse response = null;
40 40 try {
  41 + entity = new SerializableEntity(data);
41 42  
42   - // ContentType content =
43   - // ContentType.create(MimeTypeUtils.TEXT_PLAIN_VALUE,
44   - // CharsetUtils.UTF_8);
45   -
46   - // entity = new StringEntity(JsonUtils.beanToJson(model), content);
47   -
48   - entity = new SerializableEntity(model);
49   - // post.setHeader("Content-Type", "text/plain; charset=utf-8");
50   -
51 43 post.setEntity(entity);
52 44 response = httpclient.execute(post, httpContext);
53 45 entity = response.getEntity();
54 46 httpContext.getCookieStore().clear();
55 47 return responseUTF8(entity);
56   - } catch (ClientProtocolException e) {
57   - e.printStackTrace();
58   - } catch (IOException e) {
59   - e.printStackTrace();
  48 + } catch (Exception e) {
  49 + LOG.error("连接错误: " + e);
60 50 } finally {
61 51 try {
62 52 if (response != null) {
hospital.web/src/main/java/com/lyms/hospital/controller/LoginController.java View file @ 5e58b2a
... ... @@ -5,7 +5,6 @@
5 5 import org.springframework.web.bind.annotation.RestController;
6 6  
7 7 import com.lyms.web.controller.BaseController;
8   -import com.mysql.fabric.xmlrpc.base.Data;
9 8  
10 9 import io.swagger.annotations.Api;
11 10 import io.swagger.annotations.ApiImplicitParam;
12 11  
... ... @@ -13,18 +12,16 @@
13 12 import io.swagger.annotations.ApiOperation;
14 13  
15 14 @RestController
16   -@RequestMapping(value="/login",method=RequestMethod.POST)
  15 +@RequestMapping(value = "/login")
17 16 @Api(value = "/api", description = "登录的相关操作")
18 17 public class LoginController extends BaseController {
19 18  
20   - @ApiOperation(value = "测试登录", notes = "测试登录说明")
21   - @ApiImplicitParams({
22   - @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long"),
23   - @ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
24   - })
25   - @RequestMapping(value="/testLogin",method=RequestMethod.GET)
26   - public String testLogin(){
27   - request.getSession().setAttribute("abc", "123");
  19 + @ApiOperation(value = "测试登录", notes = "测试登录说明")
  20 + @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long"),
  21 + @ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User") })
  22 + @RequestMapping(value = "/testLogin", method = RequestMethod.GET)
  23 + public String testLogin() {
  24 + // request.getSession().setAttribute("abc", "123");
28 25 return "abc";
29 26 }
30 27 }
hospital.web/src/main/java/com/lyms/hospital/controller/RouterController.java View file @ 5e58b2a
  1 +package com.lyms.hospital.controller;
  2 +
  3 +import java.io.IOException;
  4 +
  5 +import javax.servlet.http.HttpServletRequest;
  6 +
  7 +import org.apache.commons.lang3.builder.ToStringBuilder;
  8 +import org.springframework.http.MediaType;
  9 +import org.springframework.web.bind.annotation.RequestMapping;
  10 +import org.springframework.web.bind.annotation.RestController;
  11 +
  12 +import com.lyms.synch.ParamsHandler;
  13 +import com.lyms.synch.SycnHandler;
  14 +import com.lyms.synch.SyncUtils;
  15 +import com.lyms.synch.entity.ChannelData;
  16 +import com.lyms.web.controller.BaseController;
  17 +
  18 +/**
  19 + * <li>@ClassName: RouterController
  20 + * <li>@Description: 远程接口调用数据处理分发
  21 + * <li>@author maliang
  22 + * <li>@date 2017年3月14日
  23 + * <li>
  24 + */
  25 +@RestController
  26 +@RequestMapping("/remote")
  27 +public class RouterController extends BaseController {
  28 +
  29 + @RequestMapping(value = "/sycn", produces = { MediaType.APPLICATION_JSON_VALUE })
  30 + public Object remote(HttpServletRequest request) throws ClassNotFoundException, IOException {
  31 + ChannelData data = SyncUtils.conver(request);
  32 + System.out.println("接受到数据: " + ToStringBuilder.reflectionToString(data));
  33 + Object handResult = SycnHandler.handler(data);
  34 + if (data.getLoop()) {
  35 + data = (ChannelData) handResult;
  36 + } else {
  37 + data.setData(ParamsHandler.builder().push(handResult).toJsonString());
  38 + }
  39 + data.setAck(true);
  40 + return data;
  41 + }
  42 +
  43 +}
hospital.web/src/main/java/com/lyms/hospital/dao/sys/SyncDataBasicMapper.java View file @ 5e58b2a
  1 +package com.lyms.hospital.dao.sys;
  2 +
  3 +import java.io.Serializable;
  4 +import java.util.List;
  5 +
  6 +import org.springframework.stereotype.Repository;
  7 +
  8 +import com.baomidou.mybatisplus.mapper.BaseMapper;
  9 +import com.lyms.hospital.entity.sys.SyncDataBasic;
  10 +
  11 +/**
  12 + * <p>
  13 + * Mapper接口
  14 + * </p>
  15 + *
  16 + * @author maliang
  17 + * @since 2017-03-15
  18 + */
  19 +@Repository
  20 +public interface SyncDataBasicMapper extends BaseMapper<SyncDataBasic> {
  21 +
  22 + public Integer deleteLogicById(Serializable id);
  23 +
  24 + /**
  25 + * <li>@Description: 批量更新
  26 + * <li>@param ids
  27 + * <li>@return
  28 + * <li>创建人:maliang
  29 + * <li>创建时间:2017年3月15日
  30 + * <li>修改人:
  31 + * <li>修改时间:
  32 + */
  33 + public Integer updateBatchByIds(List<Serializable> ids);
  34 +
  35 +}
hospital.web/src/main/java/com/lyms/hospital/dao/sys/SyncDataBasicMapper.xml View file @ 5e58b2a
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3 +"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4 +<mapper namespace="com.lyms.hospital.dao.sys.SyncDataBasicMapper">
  5 +
  6 + <!-- 通用查询映射结果 -->
  7 + <resultMap id="BaseResultMap" type="com.lyms.hospital.entity.sys.SyncDataBasic">
  8 + <id column="ID" property="id" />
  9 + <result column="DATA" property="data" />
  10 + <result column="CREATE_TIME" property="createTime" />
  11 + <result column="IFSUC" property="ifsuc" />
  12 + </resultMap>
  13 +
  14 + <!-- 通用查询结果列 -->
  15 + <sql id="Base_Column_List">
  16 + ID AS id, DATA AS data, CREATE_TIME AS createTime, IFSUC AS ifsuc
  17 + </sql>
  18 +
  19 + <sql id="Base_table">
  20 + SYNC_DATA_BASIC
  21 + </sql>
  22 +
  23 +
  24 + <update id="updateBatchByIds" parameterType="list">
  25 + update from <include refid="Base_table" /> as sb set sb.ifsuc=1
  26 + where sb.id in
  27 + <foreach item="item" collection="ids" open="(" close=")" separator=",">
  28 + #{item}
  29 + </foreach>
  30 + </update>
  31 +
  32 +</mapper>
hospital.web/src/main/java/com/lyms/hospital/entity/sys/SyncDataBasic.java View file @ 5e58b2a
  1 +package com.lyms.hospital.entity.sys;
  2 +
  3 +import java.io.Serializable;
  4 +import java.util.Date;
  5 +
  6 +import com.baomidou.mybatisplus.annotations.TableField;
  7 +import com.baomidou.mybatisplus.annotations.TableId;
  8 +import com.baomidou.mybatisplus.annotations.TableName;
  9 +import com.lyms.synch.entity.ChannelData;
  10 +
  11 +/**
  12 + *
  13 + * <p>
  14 + * 用户、角色、权限、医院、部门等基础数据同步
  15 + * </p>
  16 + *
  17 + * @author maliang
  18 + * @since 2017-03-15
  19 + */
  20 +@TableName("SYNC_DATA_BASIC")
  21 +public class SyncDataBasic implements Serializable {
  22 +
  23 + private static final long serialVersionUID = 1L;
  24 +
  25 + /**
  26 + * 该ID 一定要与data 中的ID一致
  27 + */
  28 + @TableId(value = "ID")
  29 + private String id;
  30 + /**
  31 + * 数据对象 {@link ChannelData} json 数据格式
  32 + */
  33 + @TableField(value = "DATA")
  34 + private String data;
  35 + /**
  36 + * 创建时间
  37 + */
  38 + @TableField(value = "CREATE_TIME")
  39 + private Date createTime;
  40 + /**
  41 + * 数据上传是否成功
  42 + */
  43 + @TableField(value = "IFSUC")
  44 + private Integer ifsuc;
  45 +
  46 + public String getId() {
  47 + return id;
  48 + }
  49 +
  50 + public void setId(String id) {
  51 + this.id = id;
  52 + }
  53 +
  54 + public String getData() {
  55 + return data;
  56 + }
  57 +
  58 + public void setData(String data) {
  59 + this.data = data;
  60 + }
  61 +
  62 + public Date getCreateTime() {
  63 + return createTime;
  64 + }
  65 +
  66 + public void setCreateTime(Date createTime) {
  67 + this.createTime = createTime;
  68 + }
  69 +
  70 + public Integer getIfsuc() {
  71 + return ifsuc;
  72 + }
  73 +
  74 + public void setIfsuc(Integer ifsuc) {
  75 + this.ifsuc = ifsuc;
  76 + }
  77 +
  78 +}
hospital.web/src/main/java/com/lyms/hospital/service/sys/SyncDataBasicService.java View file @ 5e58b2a
  1 +package com.lyms.hospital.service.sys;
  2 +
  3 +import java.io.Serializable;
  4 +import java.util.List;
  5 +
  6 +import com.lyms.hospital.entity.sys.SyncDataBasic;
  7 +import com.lyms.synch.entity.ChannelData;
  8 +import com.lyms.web.service.BaseService;
  9 +
  10 +/**
  11 + * <p>
  12 + * 数据同步模块
  13 + * </p>
  14 + *
  15 + * @author maliang
  16 + * @since 2017-03-15
  17 + */
  18 +public interface SyncDataBasicService extends BaseService<SyncDataBasic> {
  19 +
  20 + /**
  21 + * <li>@Description:逻辑删除,ifDel = 1 为删除,否则为没有删除
  22 + * <li>@param id 删除主键id
  23 + * <li>@return 大于0修改成功,否则为失败
  24 + */
  25 + public Integer deleteLogicById(Serializable id);
  26 +
  27 + /**
  28 + * <li>@Description:更新同步成功的数据
  29 + * <li>@param ids
  30 + * <li>@return
  31 + * <li>创建人:maliang
  32 + * <li>创建时间:2017年3月15日
  33 + * <li>修改人:
  34 + * <li>修改时间:
  35 + */
  36 + public Boolean updateBasic(List<Serializable> ids);
  37 +
  38 + /**
  39 + * 获取一条数据
  40 + * <li>@Description:TODO(方法描述)
  41 + * <li>@return
  42 + * <li>创建人:maliang
  43 + * <li>创建时间:2017年3月15日
  44 + * <li>修改人:
  45 + * <li>修改时间:
  46 + */
  47 + public ChannelData selectOne();
  48 +
  49 + public Boolean updateBasic(Serializable id);
  50 +}
hospital.web/src/main/java/com/lyms/hospital/service/sys/impl/SyncDataBasicServiceImpl.java View file @ 5e58b2a
  1 +package com.lyms.hospital.service.sys.impl;
  2 +
  3 +import java.io.Serializable;
  4 +import java.util.List;
  5 +
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.stereotype.Service;
  8 +import org.springframework.transaction.annotation.Transactional;
  9 +
  10 +import com.baomidou.mybatisplus.mapper.EntityWrapper;
  11 +import com.baomidou.mybatisplus.service.impl.ServiceImpl;
  12 +import com.lyms.hospital.dao.sys.SyncDataBasicMapper;
  13 +import com.lyms.hospital.entity.sys.SyncDataBasic;
  14 +import com.lyms.hospital.service.sys.SyncDataBasicService;
  15 +import com.lyms.synch.entity.ChannelData;
  16 +import com.lyms.util.JsonUtils;
  17 +
  18 +/**
  19 + * <p>
  20 + * 用户、角色、权限、医院、部门等基础数据同步 服务实现类
  21 + * </p>
  22 + *
  23 + * @author maliang
  24 + * @since 2017-03-15
  25 + */
  26 +@Service
  27 +public class SyncDataBasicServiceImpl extends ServiceImpl<SyncDataBasicMapper, SyncDataBasic>
  28 + implements SyncDataBasicService {
  29 +
  30 + @Autowired
  31 + private SyncDataBasicMapper basicMapper;
  32 +
  33 + public Integer deleteLogicById(Serializable id) {
  34 + return baseMapper.deleteLogicById(id);
  35 + }
  36 +
  37 + @Override
  38 + @Transactional
  39 + public Boolean updateBasic(List<Serializable> ids) {
  40 + Integer tag = basicMapper.updateBatchByIds(ids);
  41 + return tag >= 1 ? Boolean.TRUE : Boolean.FALSE;
  42 + }
  43 +
  44 + @Override
  45 + public Boolean updateBasic(Serializable id) {
  46 + SyncDataBasic dataBasic = baseMapper.selectById(id);
  47 + dataBasic.setIfsuc(1);
  48 + Integer tag = baseMapper.updateById(dataBasic);
  49 + return tag >= 1;
  50 + }
  51 +
  52 + @Override
  53 + public ChannelData selectOne() {
  54 + EntityWrapper<SyncDataBasic> ew = new EntityWrapper<SyncDataBasic>();
  55 + ew.where("ifsuc=0");
  56 + List<SyncDataBasic> datas = baseMapper.selectList(ew);
  57 +
  58 + // 单条同步,避免过于复杂的消息回执
  59 + SyncDataBasic basic = datas != null && datas.size() > 0 ? datas.get(0) : null;
  60 + if (basic != null) {
  61 + ChannelData data = JsonUtils.jsonToBean(basic.getData(), ChannelData.class);
  62 + return data;
  63 + }
  64 + return ChannelData.emtpy();
  65 + }
  66 +
  67 +}
hospital.web/src/main/resources/app-context.xml View file @ 5e58b2a
... ... @@ -23,7 +23,7 @@
23 23 </bean>
24 24  
25 25 <context:component-scan base-package="com.lyms.hospital"></context:component-scan>
26   -
  26 + <context:component-scan base-package="com.lyms.spring" />
27 27 <!-- <mvc:default-servlet-handler /> -->
28 28  
29 29 <!-- 配置静态资源,直接映射到对应的文件夹,DispatcherServlet 不处理 -->
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/generator/MysqlGenerator.java View file @ 5e58b2a
... ... @@ -45,7 +45,7 @@
45 45 gc.setAuthor("maliang");
46 46 // strategy.setInclude(new String[] {
47 47 // "SYS_USERS","SYS_USER_ROLE_MAPS","SYS_ROLES" }); // 需要生成的表
48   - strategy.setInclude(new String[] { "SYS_ORGAN_GROUP" }); // 需要生成的表
  48 + strategy.setInclude(new String[] { "SYNC_DATA_BASIC" }); // 需要生成的表
49 49 // pc.setParent("com.lyms.hospital");
50 50 pc.setParent("com.lyms.cm");
51 51  
52 52  
... ... @@ -100,9 +100,9 @@
100 100 DataSourceConfig dsc = new DataSourceConfig();
101 101 dsc.setDbType(DbType.MYSQL);
102 102 dsc.setDriverName("com.mysql.jdbc.Driver");
103   - dsc.setUsername("center");
  103 + dsc.setUsername("hospital");
104 104 dsc.setPassword("lyms2015");
105   - dsc.setUrl("jdbc:mysql://119.90.57.26:3306/center?characterEncoding=utf8");
  105 + dsc.setUrl("jdbc:mysql://119.90.57.26:3306/hospital?characterEncoding=utf8");
106 106 mpg.setDataSource(dsc);
107 107  
108 108 // 策略配置