Commit 3328ba2c5e2c8a030e7dbe7716c310a179ec8a0b
1 parent
40110feb70
Exists in
master
固定拉取节点任务修改
Showing 12 changed files with 353 additions and 298 deletions
- parent/base.common/src/main/java/com/lyms/base/common/conf/SyncConf.java
- parent/base.common/src/main/java/com/lyms/base/common/enums/SyncParamConf.java
- parent/base.common/src/main/java/com/lyms/base/common/enums/SyncParamEnum.java
- parent/base.common/src/main/java/com/lyms/base/common/service/user/impl/UsersServiceImpl.java
- parent/base.common/src/main/java/com/lyms/base/common/utils/SyncComponent.java
- parent/center.manager/src/main/java/com/lyms/cm/job/SyncFixJob.java
- parent/center.manager/src/main/java/com/lyms/cm/util/SyncComponent.java
- parent/center.manager/src/test/java/center/manager/test/user/SyncTest.java
- parent/core.sdk/src/main/java/com/lyms/sync/queue/SyncQueue.java
- parent/hospital.web/src/main/java/com/lyms/hospital/service/sys/SyncDataBasicService.java
- parent/hospital.web/src/main/java/com/lyms/hospital/service/sys/impl/SyncDataBasicServiceImpl.java
- parent/hospital.web/src/test/java/test/hospital/sync/SyncTest.java
parent/base.common/src/main/java/com/lyms/base/common/conf/SyncConf.java
View file @
3328ba2
1 | +package com.lyms.base.common.conf; | |
2 | + | |
3 | +import com.lyms.spring.PropertiesUtil; | |
4 | + | |
5 | +public interface SyncConf { | |
6 | + | |
7 | + /** | |
8 | + * 中心的操作需要同步数据到节点 | |
9 | + */ | |
10 | + public static final boolean isCenterOperateSyncToNode = PropertiesUtil.getString("isCenterOperateSyncToNode") == null ? false | |
11 | + : Boolean.valueOf(PropertiesUtil.getString("isCenterOperateSyncToNode").trim()); | |
12 | + | |
13 | +} |
parent/base.common/src/main/java/com/lyms/base/common/enums/SyncParamConf.java
View file @
3328ba2
1 | -package com.lyms.base.common.enums; | |
2 | - | |
3 | -public enum SyncParamConf { | |
4 | - | |
5 | - | |
6 | - | |
7 | - | |
8 | - USER_INSERT(com.lyms.base.common.service.user.impl.UsersServiceImpl.class.getName(),"addUser"), | |
9 | - USER_UPDATE(com.lyms.base.common.service.user.impl.UsersServiceImpl.class.getName(),"updateUser"), | |
10 | - USER_DELETE(com.lyms.base.common.service.user.impl.UsersServiceImpl.class.getName(),"delete"); | |
11 | - | |
12 | - | |
13 | - private String remoteClazz; | |
14 | - | |
15 | - public String getRemoteClazz() { | |
16 | - return remoteClazz; | |
17 | - } | |
18 | - | |
19 | - public void setRemoteClazz(String remoteClazz) { | |
20 | - this.remoteClazz = remoteClazz; | |
21 | - } | |
22 | - | |
23 | - public String getRemoteMethod() { | |
24 | - return remoteMethod; | |
25 | - } | |
26 | - | |
27 | - public void setRemoteMethod(String remoteMethod) { | |
28 | - this.remoteMethod = remoteMethod; | |
29 | - } | |
30 | - | |
31 | - private String remoteMethod; | |
32 | - | |
33 | - private SyncParamConf(String remoteClazz,String remoteMethod) { | |
34 | - this.remoteClazz = remoteClazz; | |
35 | - this.remoteMethod = remoteMethod; | |
36 | - } | |
37 | - | |
38 | - | |
39 | -} |
parent/base.common/src/main/java/com/lyms/base/common/enums/SyncParamEnum.java
View file @
3328ba2
1 | +package com.lyms.base.common.enums; | |
2 | + | |
3 | +public enum SyncParamEnum { | |
4 | + | |
5 | + | |
6 | + | |
7 | + | |
8 | + USER_INSERT(com.lyms.base.common.service.user.impl.UsersServiceImpl.class.getName(),"addUser"), | |
9 | + USER_UPDATE(com.lyms.base.common.service.user.impl.UsersServiceImpl.class.getName(),"updateUser"), | |
10 | + USER_DELETE(com.lyms.base.common.service.user.impl.UsersServiceImpl.class.getName(),"delete"); | |
11 | + | |
12 | + | |
13 | + private String remoteClazz; | |
14 | + | |
15 | + public String getRemoteClazz() { | |
16 | + return remoteClazz; | |
17 | + } | |
18 | + | |
19 | + public void setRemoteClazz(String remoteClazz) { | |
20 | + this.remoteClazz = remoteClazz; | |
21 | + } | |
22 | + | |
23 | + public String getRemoteMethod() { | |
24 | + return remoteMethod; | |
25 | + } | |
26 | + | |
27 | + public void setRemoteMethod(String remoteMethod) { | |
28 | + this.remoteMethod = remoteMethod; | |
29 | + } | |
30 | + | |
31 | + private String remoteMethod; | |
32 | + | |
33 | + private SyncParamEnum(String remoteClazz,String remoteMethod) { | |
34 | + this.remoteClazz = remoteClazz; | |
35 | + this.remoteMethod = remoteMethod; | |
36 | + } | |
37 | + | |
38 | + | |
39 | +} |
parent/base.common/src/main/java/com/lyms/base/common/service/user/impl/UsersServiceImpl.java
View file @
3328ba2
... | ... | @@ -6,20 +6,20 @@ |
6 | 6 | import org.apache.commons.lang3.StringUtils; |
7 | 7 | import org.springframework.beans.factory.annotation.Autowired; |
8 | 8 | import org.springframework.stereotype.Service; |
9 | -import org.springframework.transaction.annotation.Propagation; | |
10 | 9 | import org.springframework.transaction.annotation.Transactional; |
11 | 10 | |
12 | 11 | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
13 | 12 | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
14 | -import com.lyms.annotation.DataSourceChange; | |
15 | 13 | import com.lyms.base.common.dao.user.SysUserDataPermissionsMapper; |
16 | 14 | import com.lyms.base.common.dao.user.UsersMapper; |
17 | 15 | import com.lyms.base.common.entity.role.UserRoleMaps; |
18 | 16 | import com.lyms.base.common.entity.user.SysUserDataPermissions; |
19 | 17 | import com.lyms.base.common.entity.user.Users; |
18 | +import com.lyms.base.common.enums.SyncParamEnum; | |
20 | 19 | import com.lyms.base.common.enums.ValidityEnum; |
21 | 20 | import com.lyms.base.common.service.role.UserRoleMapsService; |
22 | 21 | import com.lyms.base.common.service.user.UsersService; |
22 | +import com.lyms.base.common.utils.SyncComponent; | |
23 | 23 | import com.lyms.exception.SystemException; |
24 | 24 | import com.lyms.util.InstanceUtils; |
25 | 25 | import com.lyms.util.MD5Utils; |
26 | 26 | |
27 | 27 | |
28 | 28 | |
29 | 29 | |
30 | 30 | |
31 | 31 | |
32 | 32 | |
33 | 33 | |
... | ... | @@ -36,94 +36,98 @@ |
36 | 36 | @Service |
37 | 37 | public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements UsersService { |
38 | 38 | |
39 | - @Autowired | |
40 | - private UsersMapper userMapper; | |
41 | - @Autowired | |
42 | - private SysUserDataPermissionsMapper sysUserDataPermissionsMapper; | |
39 | + @Autowired | |
40 | + private UsersMapper userMapper; | |
41 | + @Autowired | |
42 | + private SysUserDataPermissionsMapper sysUserDataPermissionsMapper; | |
43 | 43 | |
44 | - @Autowired | |
45 | - private UserRoleMapsService sysUserRoleMapsService; | |
44 | + @Autowired | |
45 | + private UserRoleMapsService sysUserRoleMapsService; | |
46 | + @Autowired | |
47 | + private SyncComponent syncComponent; | |
46 | 48 | |
47 | - /** | |
48 | - * 系统默认密码 | |
49 | - */ | |
50 | - private static final String DEFAULT_PWD = "123456"; | |
49 | + /** | |
50 | + * 系统默认密码 | |
51 | + */ | |
52 | + private static final String DEFAULT_PWD = "123456"; | |
51 | 53 | |
52 | - // 模块基础操作信息 | |
53 | - private boolean empty(Users user) { | |
54 | - return user == null; | |
55 | - } | |
54 | + // 模块基础操作信息 | |
55 | + private boolean empty(Users user) { | |
56 | + return user == null; | |
57 | + } | |
56 | 58 | |
57 | - /** | |
58 | - * 初始密码设置 | |
59 | - */ | |
60 | - private void initPwd(Users user) { | |
61 | - if (empty(user)) | |
62 | - return; | |
63 | - String pwd = user.getPwd(); | |
64 | - if (StringUtils.isBlank(pwd)) { | |
65 | - pwd = DEFAULT_PWD; | |
66 | - } | |
67 | - String encode = MD5Utils.md5(pwd); | |
68 | - user.setPwd(encode); | |
69 | - } | |
59 | + /** | |
60 | + * 初始密码设置 | |
61 | + */ | |
62 | + private void initPwd(Users user) { | |
63 | + if (empty(user)) | |
64 | + return; | |
65 | + String pwd = user.getPwd(); | |
66 | + if (StringUtils.isBlank(pwd)) { | |
67 | + pwd = DEFAULT_PWD; | |
68 | + } | |
69 | + String encode = MD5Utils.md5(pwd); | |
70 | + user.setPwd(encode); | |
71 | + } | |
70 | 72 | |
71 | - @Override | |
72 | - @Transactional | |
73 | - public boolean addUser(Users user, List<UserRoleMaps> userRoleMapsList) throws SystemException { | |
74 | - if (empty(user)) | |
75 | - return false; | |
76 | - // 设置user ID | |
77 | - user.setIfdel(0); | |
78 | - if (null == user.getType()) {// 没有勾选管理,就是用户 | |
79 | - user.setType(1); | |
80 | - } | |
81 | - if (null == user.getEnable()) { | |
82 | - user.setEnable(1); | |
83 | - } | |
84 | - // 设置用户密码 | |
85 | - this.initPwd(user); | |
73 | + @Override | |
74 | + @Transactional | |
75 | + public boolean addUser(Users user, List<UserRoleMaps> userRoleMapsList) throws SystemException { | |
76 | + if (empty(user)) | |
77 | + return false; | |
78 | + // 设置user ID | |
79 | + user.setIfdel(0); | |
80 | + if (null == user.getType()) {// 没有勾选管理,就是用户 | |
81 | + user.setType(1); | |
82 | + } | |
83 | + if (null == user.getEnable()) { | |
84 | + user.setEnable(1); | |
85 | + } | |
86 | + // 设置用户密码 | |
87 | + this.initPwd(user); | |
86 | 88 | |
87 | - Integer tag = userMapper.insert(user); | |
88 | - | |
89 | - String[] dataPermissionArray = user.getDataOrgIds().split(","); | |
90 | - if(dataPermissionArray != null && dataPermissionArray.length > 0){ | |
91 | - for(String orgid : dataPermissionArray ){ | |
92 | - SysUserDataPermissions dataEntity = new SysUserDataPermissions(); | |
93 | - dataEntity.setId(StrUtils.uuid()); | |
94 | - dataEntity.setOrgId(orgid); | |
95 | - dataEntity.setUserId(user.getId()); | |
96 | - sysUserDataPermissionsMapper.insert(dataEntity); | |
97 | - } | |
98 | - } | |
99 | - if (userRoleMapsList != null && !userRoleMapsList.isEmpty()) { | |
100 | - sysUserRoleMapsService.insertBatch(userRoleMapsList); | |
101 | - } | |
102 | - return tag != null && tag >= 1; | |
103 | - } | |
89 | + Integer tag = userMapper.insert(user); | |
104 | 90 | |
105 | - @Override | |
106 | - @Transactional | |
107 | - public boolean updateUser(Users user, List<UserRoleMaps> userRoleMapsList) throws SystemException { | |
108 | - if (empty(user)) | |
109 | - return false; | |
110 | - if (null == user.getType()) {// 没有勾选管理,就是用户 | |
111 | - user.setType(1); | |
112 | - } | |
113 | - if (null == user.getEnable()) { | |
114 | - user.setEnable(1); | |
115 | - } | |
116 | - if (StrUtils.isNotEmpty(user.getPwd())) { | |
117 | - // 初始密码 | |
118 | - this.initPwd(user); | |
119 | - } | |
91 | + String[] dataPermissionArray = user.getDataOrgIds().split(","); | |
92 | + if (dataPermissionArray != null && dataPermissionArray.length > 0) { | |
93 | + for (String orgid : dataPermissionArray) { | |
94 | + SysUserDataPermissions dataEntity = new SysUserDataPermissions(); | |
95 | + dataEntity.setId(StrUtils.uuid()); | |
96 | + dataEntity.setOrgId(orgid); | |
97 | + dataEntity.setUserId(user.getId()); | |
98 | + sysUserDataPermissionsMapper.insert(dataEntity); | |
99 | + } | |
100 | + } | |
101 | + if (userRoleMapsList != null && !userRoleMapsList.isEmpty()) { | |
102 | + sysUserRoleMapsService.insertBatch(userRoleMapsList); | |
103 | + } | |
104 | + syncComponent.addPushSyncOperation(SyncParamEnum.USER_INSERT, user,userRoleMapsList); | |
105 | + return tag != null && tag >= 1; | |
106 | + } | |
120 | 107 | |
121 | - Integer tag = userMapper.updateById(user); | |
122 | - | |
123 | - sysUserDataPermissionsMapper.delete(new EntityWrapper<SysUserDataPermissions>().where("USER_ID={0}", user.getId())); | |
124 | - String[] dataPermissionArray = user.getDataOrgIds().split(","); | |
125 | - if(dataPermissionArray != null && dataPermissionArray.length > 0){ | |
126 | - for(String orgid : dataPermissionArray ){ | |
108 | + @Override | |
109 | + @Transactional | |
110 | + public boolean updateUser(Users user, List<UserRoleMaps> userRoleMapsList) throws SystemException { | |
111 | + if (empty(user)) | |
112 | + return false; | |
113 | + if (null == user.getType()) {// 没有勾选管理,就是用户 | |
114 | + user.setType(1); | |
115 | + } | |
116 | + if (null == user.getEnable()) { | |
117 | + user.setEnable(1); | |
118 | + } | |
119 | + if (StrUtils.isNotEmpty(user.getPwd())) { | |
120 | + // 初始密码 | |
121 | + this.initPwd(user); | |
122 | + } | |
123 | + | |
124 | + Integer tag = userMapper.updateById(user); | |
125 | + | |
126 | + sysUserDataPermissionsMapper | |
127 | + .delete(new EntityWrapper<SysUserDataPermissions>().where("USER_ID={0}", user.getId())); | |
128 | + String[] dataPermissionArray = user.getDataOrgIds().split(","); | |
129 | + if (dataPermissionArray != null && dataPermissionArray.length > 0) { | |
130 | + for (String orgid : dataPermissionArray) { | |
127 | 131 | SysUserDataPermissions dataEntity = new SysUserDataPermissions(); |
128 | 132 | dataEntity.setId(StrUtils.uuid()); |
129 | 133 | dataEntity.setOrgId(orgid); |
130 | 134 | |
131 | 135 | |
132 | 136 | |
133 | 137 | |
134 | 138 | |
135 | 139 | |
136 | 140 | |
137 | 141 | |
... | ... | @@ -131,96 +135,96 @@ |
131 | 135 | sysUserDataPermissionsMapper.insert(dataEntity); |
132 | 136 | } |
133 | 137 | } |
134 | - | |
135 | - EntityWrapper<UserRoleMaps> ew = new EntityWrapper<UserRoleMaps>(); | |
136 | - ew.where("user_id={0}", user.getId()); | |
137 | - sysUserRoleMapsService.delete(ew); | |
138 | - if (!userRoleMapsList.isEmpty()) { | |
139 | - sysUserRoleMapsService.insertBatch(userRoleMapsList); | |
140 | - } | |
141 | - return tag != null && tag >= 1; | |
142 | - } | |
143 | 138 | |
144 | - /* | |
145 | - * @Override public SysUsers getUserById(String userId) throws | |
146 | - * SystemException { if (StringUtils.isBlank(userId)) return null; return | |
147 | - * userMapper.selectById(userId); } | |
148 | - */ | |
139 | + EntityWrapper<UserRoleMaps> ew = new EntityWrapper<UserRoleMaps>(); | |
140 | + ew.where("user_id={0}", user.getId()); | |
141 | + sysUserRoleMapsService.delete(ew); | |
142 | + if (!userRoleMapsList.isEmpty()) { | |
143 | + sysUserRoleMapsService.insertBatch(userRoleMapsList); | |
144 | + } | |
145 | + return tag != null && tag >= 1; | |
146 | + } | |
149 | 147 | |
150 | - @Override | |
151 | - @Transactional | |
152 | - public boolean delete(String userId) throws SystemException { | |
148 | + /* | |
149 | + * @Override public SysUsers getUserById(String userId) throws | |
150 | + * SystemException { if (StringUtils.isBlank(userId)) return null; return | |
151 | + * userMapper.selectById(userId); } | |
152 | + */ | |
153 | 153 | |
154 | - if (StringUtils.isBlank(userId)) | |
155 | - return false; | |
156 | - // TODO 通过sql 修改 | |
157 | - Users user = userMapper.selectById(userId); | |
158 | - if (user != null) { | |
159 | - Integer ifDel = user.getIfdel(); | |
160 | - if (ifDel == null || ifDel == ValidityEnum.VALIDITY.getValidity()) { | |
161 | - ifDel = ValidityEnum.UNVALIDITY.getValidity(); | |
162 | - } else { | |
163 | - ifDel = ValidityEnum.VALIDITY.getValidity(); | |
164 | - } | |
165 | - user.setIfdel(ifDel); | |
166 | - Integer tag = userMapper.updateById(user); | |
167 | - return tag != null && tag >= 1; | |
168 | - } | |
169 | - return false; | |
170 | - } | |
154 | + @Override | |
155 | + @Transactional | |
156 | + public boolean delete(String userId) throws SystemException { | |
171 | 157 | |
172 | - @Override | |
173 | - public Integer deleteLogicById(Serializable id) { | |
174 | - return baseMapper.deleteLogicById(id); | |
175 | - } | |
158 | + if (StringUtils.isBlank(userId)) | |
159 | + return false; | |
160 | + // TODO 通过sql 修改 | |
161 | + Users user = userMapper.selectById(userId); | |
162 | + if (user != null) { | |
163 | + Integer ifDel = user.getIfdel(); | |
164 | + if (ifDel == null || ifDel == ValidityEnum.VALIDITY.getValidity()) { | |
165 | + ifDel = ValidityEnum.UNVALIDITY.getValidity(); | |
166 | + } else { | |
167 | + ifDel = ValidityEnum.VALIDITY.getValidity(); | |
168 | + } | |
169 | + user.setIfdel(ifDel); | |
170 | + Integer tag = userMapper.updateById(user); | |
171 | + return tag != null && tag >= 1; | |
172 | + } | |
173 | + return false; | |
174 | + } | |
176 | 175 | |
177 | - @Override | |
178 | - public boolean isAllowUpdate(String account, String userid) { | |
179 | - boolean flag = true; | |
180 | - if (StrUtils.isNotEmpty(userid)) {// 修改用户 | |
181 | - Users oldDbUser = selectById(userid); | |
182 | - if (!oldDbUser.getAccount().equalsIgnoreCase(account)) {// 登录账号改变 | |
183 | - flag = !isExistAccount(account); | |
184 | - } | |
185 | - } else {// 新增 | |
186 | - flag = !isExistAccount(account); | |
187 | - } | |
188 | - return flag; | |
189 | - } | |
176 | + @Override | |
177 | + public Integer deleteLogicById(Serializable id) { | |
178 | + return baseMapper.deleteLogicById(id); | |
179 | + } | |
190 | 180 | |
191 | - /** | |
192 | - * <li>@Description:是否存在登录名 | |
193 | - * <li>@param account | |
194 | - * <li>@return | |
195 | - * <li>创建人:方承 | |
196 | - * <li>创建时间:2017年3月9日 | |
197 | - * <li>修改人: | |
198 | - * <li>修改时间: | |
199 | - */ | |
200 | - private boolean isExistAccount(String account) { | |
201 | - Users entity = selectOne(new EntityWrapper<Users>().where("account={0}", account).and("ifDel=0")); | |
202 | - if (null == entity) { | |
203 | - return false; | |
204 | - } | |
205 | - return true; | |
206 | - } | |
181 | + @Override | |
182 | + public boolean isAllowUpdate(String account, String userid) { | |
183 | + boolean flag = true; | |
184 | + if (StrUtils.isNotEmpty(userid)) {// 修改用户 | |
185 | + Users oldDbUser = selectById(userid); | |
186 | + if (!oldDbUser.getAccount().equalsIgnoreCase(account)) {// 登录账号改变 | |
187 | + flag = !isExistAccount(account); | |
188 | + } | |
189 | + } else {// 新增 | |
190 | + flag = !isExistAccount(account); | |
191 | + } | |
192 | + return flag; | |
193 | + } | |
207 | 194 | |
208 | - @Override | |
209 | - public Users getUserByUsername(String name) { | |
210 | - Users user = selectOne(new EntityWrapper<Users>().where("account={0}", name).and("ifDel=0")); | |
211 | - return user; | |
212 | - } | |
195 | + /** | |
196 | + * <li>@Description:是否存在登录名 | |
197 | + * <li>@param account | |
198 | + * <li>@return | |
199 | + * <li>创建人:方承 | |
200 | + * <li>创建时间:2017年3月9日 | |
201 | + * <li>修改人: | |
202 | + * <li>修改时间: | |
203 | + */ | |
204 | + private boolean isExistAccount(String account) { | |
205 | + Users entity = selectOne(new EntityWrapper<Users>().where("account={0}", account).and("ifDel=0")); | |
206 | + if (null == entity) { | |
207 | + return false; | |
208 | + } | |
209 | + return true; | |
210 | + } | |
213 | 211 | |
214 | - @Override | |
215 | - public List<String> getRoleIdListByUserid(String uid) { | |
216 | - List<UserRoleMaps> urList = sysUserRoleMapsService | |
217 | - .selectList(new EntityWrapper<UserRoleMaps>().where("user_id={0}", uid)); | |
218 | - List<String> roleIdList = InstanceUtils.newArrayList(); | |
219 | - for (UserRoleMaps ur : urList) { | |
220 | - roleIdList.add(ur.getRoleId()); | |
221 | - } | |
222 | - return roleIdList; | |
223 | - } | |
212 | + @Override | |
213 | + public Users getUserByUsername(String name) { | |
214 | + Users user = selectOne(new EntityWrapper<Users>().where("account={0}", name).and("ifDel=0")); | |
215 | + return user; | |
216 | + } | |
217 | + | |
218 | + @Override | |
219 | + public List<String> getRoleIdListByUserid(String uid) { | |
220 | + List<UserRoleMaps> urList = sysUserRoleMapsService | |
221 | + .selectList(new EntityWrapper<UserRoleMaps>().where("user_id={0}", uid)); | |
222 | + List<String> roleIdList = InstanceUtils.newArrayList(); | |
223 | + for (UserRoleMaps ur : urList) { | |
224 | + roleIdList.add(ur.getRoleId()); | |
225 | + } | |
226 | + return roleIdList; | |
227 | + } | |
224 | 228 | |
225 | 229 | @Override |
226 | 230 | public List<Users> getUsersByOrgId(Serializable orgid) { |
parent/base.common/src/main/java/com/lyms/base/common/utils/SyncComponent.java
View file @
3328ba2
1 | +package com.lyms.base.common.utils; | |
2 | + | |
3 | +import java.util.List; | |
4 | + | |
5 | +import org.springframework.beans.factory.annotation.Autowired; | |
6 | +import org.springframework.stereotype.Component; | |
7 | + | |
8 | +import com.baomidou.mybatisplus.mapper.EntityWrapper; | |
9 | +import com.lyms.base.common.conf.SyncConf; | |
10 | +import com.lyms.base.common.entity.organ.OrganGroup; | |
11 | +import com.lyms.base.common.enums.SyncParamEnum; | |
12 | +import com.lyms.base.common.service.organ.OrganGroupService; | |
13 | +import com.lyms.sync.ParamsAdpter; | |
14 | +import com.lyms.sync.SyncCenter; | |
15 | +import com.lyms.util.CollectionUtils; | |
16 | +import com.lyms.util.InstanceUtils; | |
17 | +import com.lyms.util.StrUtils; | |
18 | + | |
19 | +@Component | |
20 | +public class SyncComponent { | |
21 | + | |
22 | + @Autowired | |
23 | + public SyncCenter center; | |
24 | + | |
25 | + @Autowired | |
26 | + private OrganGroupService organGroupService; | |
27 | + | |
28 | + private List<String> getAllGroupIpList() { | |
29 | + List<String> ipList = InstanceUtils.newArrayList(); | |
30 | + List<OrganGroup> list = organGroupService.selectList(new EntityWrapper<OrganGroup>().where("ifDel=0")); | |
31 | + if (CollectionUtils.isNotEmpty(list)) { | |
32 | + for (OrganGroup group : list) { | |
33 | + if (StrUtils.isNotEmpty(group.getPushaddress())) { | |
34 | + ipList.add(group.getPushaddress()); | |
35 | + } | |
36 | + } | |
37 | + } | |
38 | + return ipList; | |
39 | + } | |
40 | + | |
41 | + /** | |
42 | + * <li>@Description:添加一个推送同步操作 | |
43 | + * <li>@param syncParamConf | |
44 | + * <li>@param data data和对应方法参数个数和类型一致 | |
45 | + * <li>@return | |
46 | + * <li>创建人:方承 | |
47 | + * <li>创建时间:2017年4月11日 | |
48 | + * <li>修改人: | |
49 | + * <li>修改时间: | |
50 | + */ | |
51 | + public boolean addPushSyncOperation(SyncParamEnum syncParamConf, Object... data) { | |
52 | + if(SyncConf.isCenterOperateSyncToNode){ | |
53 | + List<String> ipList = getAllGroupIpList(); | |
54 | + ParamsAdpter adpter = null; | |
55 | + if (data != null && data.length > 0) { | |
56 | + adpter = ParamsAdpter.builder(); | |
57 | + for (int i = 0; i < data.length; i++) { | |
58 | + adpter.push(data[i]); | |
59 | + } | |
60 | + } | |
61 | + for (String ip : ipList) { | |
62 | + String id = StrUtils.uuid(); | |
63 | + center.pushTmp(id, ip, syncParamConf.getRemoteClazz(), syncParamConf.getRemoteMethod(), adpter); | |
64 | + } | |
65 | + return true; | |
66 | + } | |
67 | + return false; | |
68 | + } | |
69 | + | |
70 | +} |
parent/center.manager/src/main/java/com/lyms/cm/job/SyncFixJob.java
View file @
3328ba2
1 | 1 | package com.lyms.cm.job; |
2 | 2 | |
3 | +import java.io.Serializable; | |
4 | +import java.util.List; | |
3 | 5 | import java.util.concurrent.atomic.AtomicBoolean; |
4 | 6 | |
5 | 7 | import org.apache.commons.lang3.StringUtils; |
6 | 8 | |
7 | 9 | |
8 | 10 | |
... | ... | @@ -7,14 +9,20 @@ |
7 | 9 | import org.slf4j.Logger; |
8 | 10 | import org.slf4j.LoggerFactory; |
9 | 11 | import org.springframework.beans.factory.annotation.Autowired; |
12 | +import org.springframework.data.redis.core.RedisTemplate; | |
10 | 13 | |
14 | +import com.baomidou.mybatisplus.mapper.EntityWrapper; | |
15 | +import com.lyms.base.common.entity.organ.OrganGroup; | |
16 | +import com.lyms.base.common.service.organ.OrganGroupService; | |
11 | 17 | import com.lyms.sync.ParamsAdpter; |
12 | 18 | import com.lyms.sync.SyncCallback; |
13 | 19 | import com.lyms.sync.SyncCenter; |
14 | 20 | import com.lyms.sync.SyncCenter.Work; |
15 | 21 | import com.lyms.sync.SyncHandler; |
16 | 22 | import com.lyms.sync.channel.ChannelData; |
23 | +import com.lyms.sync.queue.SyncQueue; | |
17 | 24 | import com.lyms.util.HttpUtils; |
25 | +import com.lyms.util.InstanceUtils; | |
18 | 26 | import com.lyms.util.JsonUtils; |
19 | 27 | import com.lyms.util.StrUtils; |
20 | 28 | |
21 | 29 | |
... | ... | @@ -30,10 +38,36 @@ |
30 | 38 | |
31 | 39 | @Autowired |
32 | 40 | public SyncCenter center; |
41 | + | |
42 | + @Autowired | |
43 | + public OrganGroupService organGroupService; | |
44 | + @Autowired | |
45 | + public RedisTemplate<Serializable, Serializable> template; | |
46 | + | |
47 | + private static List<String> pullUrlList = null; | |
48 | + | |
49 | + private static String remoteClazz = "com.lyms.hospital.service.sys.impl.SyncDataBasicServiceImpl"; | |
50 | + private static String remoteMethod = "selectOne"; | |
33 | 51 | |
34 | 52 | private final AtomicBoolean reset = new AtomicBoolean(false); |
35 | 53 | |
36 | 54 | public void excute() { |
55 | + if( pullUrlList == null ){ | |
56 | + LOG.info("初始化固定拉取远程任务"); | |
57 | + template.delete(SyncQueue.FIXATION_WORK); | |
58 | + LOG.info("清空固定拉取远程任务"); | |
59 | + List<OrganGroup> groupList = organGroupService.selectList(new EntityWrapper<OrganGroup>().where("IFDEL=0")); | |
60 | + pullUrlList = InstanceUtils.newArrayList(); | |
61 | + for(OrganGroup entity : groupList){ | |
62 | + if(StrUtils.isNotEmpty(entity.getPulladdress()) && entity.getPulladdress().startsWith("http")){ | |
63 | + LOG.info("添加固定拉取远程任务:pullAddress={}",entity.getPulladdress()); | |
64 | + if( !pullUrlList.contains(entity.getPulladdress().trim()) ){ | |
65 | + pullUrlList.add(entity.getPulladdress().trim()); | |
66 | + center.pushFix(StrUtils.uuid(), entity.getPulladdress().trim(), remoteClazz, remoteMethod, null); | |
67 | + } | |
68 | + } | |
69 | + } | |
70 | + } | |
37 | 71 | if (reset.get()) { |
38 | 72 | return; |
39 | 73 | } |
40 | 74 | |
... | ... | @@ -49,9 +83,9 @@ |
49 | 83 | ChannelData oldData = (ChannelData) object; |
50 | 84 | if (oldData != null && StringUtils.isNotBlank(oldData.getId())) { |
51 | 85 | // 任务发送执行 |
52 | - System.out.println("拉取到本地任务: " + ToStringBuilder.reflectionToString(oldData)); | |
86 | + LOG.info("拉取到本地任务: " + ToStringBuilder.reflectionToString(oldData)); | |
53 | 87 | String result = HttpUtils.REMOTE.post(oldData); |
54 | - System.out.println("返回结果: " + result); | |
88 | + LOG.info("返回结果: " + result); | |
55 | 89 | if (StringUtils.isBlank(result)) |
56 | 90 | return; |
57 | 91 | ChannelData data = JsonUtils.jsonToBean(result, ChannelData.class); |
parent/center.manager/src/main/java/com/lyms/cm/util/SyncComponent.java
View file @
3328ba2
1 | -package com.lyms.cm.util; | |
2 | - | |
3 | -import java.util.List; | |
4 | - | |
5 | -import org.springframework.beans.factory.annotation.Autowired; | |
6 | -import org.springframework.stereotype.Component; | |
7 | - | |
8 | -import com.baomidou.mybatisplus.mapper.EntityWrapper; | |
9 | -import com.lyms.base.common.entity.organ.OrganGroup; | |
10 | -import com.lyms.base.common.enums.SyncParamConf; | |
11 | -import com.lyms.base.common.service.organ.OrganGroupService; | |
12 | -import com.lyms.sync.ParamsAdpter; | |
13 | -import com.lyms.sync.SyncCenter; | |
14 | -import com.lyms.util.CollectionUtils; | |
15 | -import com.lyms.util.InstanceUtils; | |
16 | -import com.lyms.util.StrUtils; | |
17 | - | |
18 | -@Component | |
19 | -public class SyncComponent { | |
20 | - | |
21 | - @Autowired | |
22 | - public SyncCenter center; | |
23 | - | |
24 | - @Autowired | |
25 | - private OrganGroupService organGroupService; | |
26 | - | |
27 | - private List<String> getAllGroupIpList() { | |
28 | - List<String> ipList = InstanceUtils.newArrayList(); | |
29 | - List<OrganGroup> list = organGroupService.selectList(new EntityWrapper<OrganGroup>().where("ifDel=0")); | |
30 | - if (CollectionUtils.isNotEmpty(list)) { | |
31 | - for (OrganGroup group : list) { | |
32 | - if (StrUtils.isNotEmpty(group.getPushaddress())) { | |
33 | - ipList.add(group.getPushaddress()); | |
34 | - } | |
35 | - } | |
36 | - } | |
37 | - return ipList; | |
38 | - } | |
39 | - | |
40 | - /** | |
41 | - * <li>@Description:添加一个推送同步操作 | |
42 | - * <li>@param syncParamConf | |
43 | - * <li>@param data data和对应方法参数个数和类型一致 | |
44 | - * <li>@return | |
45 | - * <li>创建人:方承 | |
46 | - * <li>创建时间:2017年4月11日 | |
47 | - * <li>修改人: | |
48 | - * <li>修改时间: | |
49 | - */ | |
50 | - public boolean addPushSyncOperation(SyncParamConf syncParamConf, Object... data) { | |
51 | - List<String> ipList = getAllGroupIpList(); | |
52 | - ParamsAdpter adpter = null; | |
53 | - if (data != null && data.length > 0) { | |
54 | - adpter = ParamsAdpter.builder(); | |
55 | - for (int i = 0; i < data.length; i++) { | |
56 | - adpter.push(data[i]); | |
57 | - } | |
58 | - } | |
59 | - for (String ip : ipList) { | |
60 | - String id = StrUtils.uuid(); | |
61 | - center.pushTmp(id, ip, syncParamConf.getRemoteClazz(), syncParamConf.getRemoteMethod(), adpter); | |
62 | - } | |
63 | - return true; | |
64 | - } | |
65 | - | |
66 | -} |
parent/center.manager/src/test/java/center/manager/test/user/SyncTest.java
View file @
3328ba2
... | ... | @@ -4,8 +4,8 @@ |
4 | 4 | import org.springframework.beans.factory.annotation.Autowired; |
5 | 5 | |
6 | 6 | import com.lyms.base.common.entity.user.Users; |
7 | -import com.lyms.base.common.enums.SyncParamConf; | |
8 | -import com.lyms.cm.util.SyncComponent; | |
7 | +import com.lyms.base.common.enums.SyncParamEnum; | |
8 | +import com.lyms.base.common.utils.SyncComponent; | |
9 | 9 | |
10 | 10 | public class SyncTest extends BaseTest { |
11 | 11 | |
... | ... | @@ -19,7 +19,7 @@ |
19 | 19 | entity.setId(name); |
20 | 20 | entity.setAccount(name); |
21 | 21 | entity.setName(name); |
22 | - syncComponent.addPushSyncOperation(SyncParamConf.USER_INSERT, entity,null); | |
22 | + syncComponent.addPushSyncOperation(SyncParamEnum.USER_INSERT, entity,null); | |
23 | 23 | } |
24 | 24 | |
25 | 25 | } |
parent/core.sdk/src/main/java/com/lyms/sync/queue/SyncQueue.java
View file @
3328ba2
... | ... | @@ -42,12 +42,12 @@ |
42 | 42 | /** |
43 | 43 | * 固定任务 |
44 | 44 | */ |
45 | - private static final String FIXATION_WORK = "FIXATION_WORK"; | |
45 | + public static final String FIXATION_WORK = "FIXATION_WORK"; | |
46 | 46 | |
47 | 47 | /** |
48 | 48 | * 临时任务 |
49 | 49 | */ |
50 | - private static final String TMP_WORK = "TMP_WORK"; | |
50 | + public static final String TMP_WORK = "TMP_WORK"; | |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * 回执消息任务 |
parent/hospital.web/src/main/java/com/lyms/hospital/service/sys/SyncDataBasicService.java
View file @
3328ba2
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | import java.io.Serializable; |
4 | 4 | import java.util.List; |
5 | 5 | |
6 | -import com.lyms.base.common.enums.SyncParamConf; | |
6 | +import com.lyms.base.common.enums.SyncParamEnum; | |
7 | 7 | import com.lyms.hospital.entity.sys.SyncDataBasic; |
8 | 8 | import com.lyms.sync.channel.ChannelData; |
9 | 9 | import com.lyms.web.service.BaseService; |
... | ... | @@ -58,7 +58,7 @@ |
58 | 58 | * <li>修改人: |
59 | 59 | * <li>修改时间: |
60 | 60 | */ |
61 | - public boolean addSyncData(SyncParamConf syncParamConf,Object ...dataObjects); | |
61 | + public boolean addSyncData(SyncParamEnum syncParamConf,Object ...dataObjects); | |
62 | 62 | |
63 | 63 | } |
parent/hospital.web/src/main/java/com/lyms/hospital/service/sys/impl/SyncDataBasicServiceImpl.java
View file @
3328ba2
... | ... | @@ -10,7 +10,7 @@ |
10 | 10 | |
11 | 11 | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
12 | 12 | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
13 | -import com.lyms.base.common.enums.SyncParamConf; | |
13 | +import com.lyms.base.common.enums.SyncParamEnum; | |
14 | 14 | import com.lyms.hospital.dao.sys.SyncDataBasicMapper; |
15 | 15 | import com.lyms.hospital.entity.sys.SyncDataBasic; |
16 | 16 | import com.lyms.hospital.service.sys.SyncDataBasicService; |
... | ... | @@ -69,7 +69,7 @@ |
69 | 69 | } |
70 | 70 | |
71 | 71 | @Override |
72 | - public boolean addSyncData(SyncParamConf syncParamConf, Object... dataObjects) { | |
72 | + public boolean addSyncData(SyncParamEnum syncParamConf, Object... dataObjects) { | |
73 | 73 | SyncDataBasic entity = new SyncDataBasic(); |
74 | 74 | String uid = StrUtils.uuid(); |
75 | 75 | entity.setId(uid); |
parent/hospital.web/src/test/java/test/hospital/sync/SyncTest.java
View file @
3328ba2
... | ... | @@ -4,7 +4,7 @@ |
4 | 4 | import org.springframework.beans.factory.annotation.Autowired; |
5 | 5 | |
6 | 6 | import com.lyms.base.common.entity.user.Users; |
7 | -import com.lyms.base.common.enums.SyncParamConf; | |
7 | +import com.lyms.base.common.enums.SyncParamEnum; | |
8 | 8 | import com.lyms.hospital.service.sys.SyncDataBasicService; |
9 | 9 | import com.lyms.util.DateTimeUtils; |
10 | 10 | |
... | ... | @@ -22,7 +22,7 @@ |
22 | 22 | u.setId(uid); |
23 | 23 | u.setAccount(uid); |
24 | 24 | u.setName(uid); |
25 | - syncDataBasicService.addSyncData(SyncParamConf.USER_INSERT, u,null); | |
25 | + syncDataBasicService.addSyncData(SyncParamEnum.USER_INSERT, u,null); | |
26 | 26 | } |
27 | 27 | |
28 | 28 | } |