修改从金宏网获取用户的方法,增加自动任务调度功能
This commit is contained in:
parent
ce1bce47c5
commit
d452ddb4fb
|
@ -0,0 +1,28 @@
|
|||
package io.renren.modules.monitor.task;
|
||||
|
||||
import io.renren.modules.job.task.ITask;
|
||||
import io.renren.modules.monitor.service.MonitorService;
|
||||
import io.renren.modules.sys.service.SysUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 定期从金宏网获取并增量修改用户信息,已存在的用户只修改 guid mobile ywMobile
|
||||
* @author ytl
|
||||
* @Date 2022/8/30 18:06
|
||||
**/
|
||||
@Component("getAndUpdateUserFromJhTask")
|
||||
public class GetAndUpdateUserFromJhTask implements ITask {
|
||||
@Autowired
|
||||
private SysUserService userService;
|
||||
|
||||
|
||||
@Override
|
||||
public void run(String params) {
|
||||
//先备份数据库表 sys_user
|
||||
int i = userService.backSysUser();
|
||||
if(i == 0){
|
||||
userService.getUserInfoFromJH();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -176,4 +176,12 @@ public class SysUserController {
|
|||
public Result getUserInfoFromJH() {
|
||||
return sysUserService.getUserInfoFromJH();
|
||||
}
|
||||
|
||||
@GetMapping("backSysUser")
|
||||
public void backSysUser(){
|
||||
int i = sysUserService.backSysUser();
|
||||
if(i ==0){
|
||||
sysUserService.getUserInfoFromJH();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -61,4 +61,6 @@ public interface SysUserService extends BaseService<SysUserEntity> {
|
|||
|
||||
Result getUserInfoFromJH();
|
||||
|
||||
int backSysUser();
|
||||
|
||||
}
|
||||
|
|
|
@ -62,6 +62,15 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntit
|
|||
@Value("${big_date.assignee_role_name}")
|
||||
private String roleName; // 具备审批的角色名称
|
||||
|
||||
@Value("${spring.datasource.druid.url}")
|
||||
private String url;
|
||||
|
||||
@Value("${spring.datasource.druid.username}")
|
||||
private String username;
|
||||
|
||||
@Value("${spring.datasource.druid.password}")
|
||||
private String password;
|
||||
|
||||
@Override
|
||||
public PageData<SysUserDTO> page(Map<String, Object> params) {
|
||||
//转换成like
|
||||
|
@ -471,4 +480,38 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntit
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int backSysUser(){
|
||||
int result = 1;
|
||||
Process process = null;
|
||||
String property = System.getProperty("os.name");
|
||||
System.out.println(property);
|
||||
StringBuilder strBuil = new StringBuilder();
|
||||
//jdbc:mysql://15.72.183.91:3306/share_platform?useUnicode=true&characterEncoding=UTF-8&server
|
||||
String host = url.substring(url.indexOf("mysql"), url.indexOf("3306")).replace(":", "").replace("//", "").replace("mysql", "");
|
||||
|
||||
String dataName = url.substring(url.indexOf("3306"), url.indexOf("?")).replaceAll("/", "").replaceAll("3306", "");
|
||||
strBuil.append("mysqldump -u").append(username).append(" -p").append(password)
|
||||
.append(" -h").append(host).append(" -P3306 ").append(dataName).append(" sys_user > /data/services/sys_user.sql");
|
||||
|
||||
//String newCmdLinux = " mysqldump -uroot -pw@CmM1mBVQkPhdrc -h15.72.183.91 -P3306 share_platform sys_user > /data/services/sys_user.sql";
|
||||
String newCmdLinux = strBuil.toString();
|
||||
String newCmdWin = " cmd /c mysqldump -uroot -proot -h127.0.0.1 -P3306 share_platform sys_user > D:\\sys_user.sql";
|
||||
try{
|
||||
if (property.indexOf("Linux") != -1) {
|
||||
// linux
|
||||
process = Runtime.getRuntime().exec(new String[]{"bash", "-c", newCmdLinux});
|
||||
} else {
|
||||
// 本地win
|
||||
process = Runtime.getRuntime().exec(newCmdWin);
|
||||
}
|
||||
//0 表示线程正常终止。
|
||||
//if (process.waitFor() == 0) {}
|
||||
result = process.waitFor();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue