新增同步Ecology人员信息。
将sys_user表自增长改为从10000000开始 ALTER TABLE sys_user AUTO_INCREMENT = 10000000
This commit is contained in:
parent
6da42f4b11
commit
917b74d795
|
|
@ -4,17 +4,16 @@ package com.ruoyi.test.conrtroller;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||
import com.ruoyi.system.mapper.SysDeptMapper;
|
||||
import com.ruoyi.common.utils.http.HttpUtils;
|
||||
import com.ruoyi.system.domain.EcologyDept;
|
||||
import com.ruoyi.system.mapper.SysDeptMapper;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -22,16 +21,30 @@ import java.util.Map;
|
|||
public class GetEcologyInfoTestController extends BaseController {
|
||||
@Autowired
|
||||
private SysDeptMapper deptMapper;
|
||||
@Autowired
|
||||
private ISysUserService userService;
|
||||
|
||||
@RequestMapping("/anon/getEcologyDept")
|
||||
public String getEcologyDept() throws Exception {
|
||||
String url="http://192.168.2.85:90/api/hrm/resful/getHrmdepartmentWithPage";
|
||||
String params="{\"params\":{\"pagesize\":1000}}";
|
||||
//return sendPost(url,params);
|
||||
return deptSync(sendPostWithRest(url,params));
|
||||
return deptSync(HttpUtils.sendPostWithRest(url,params));
|
||||
|
||||
}
|
||||
|
||||
public Map<String,String> sendPostWithRest(String url,String params){
|
||||
@RequestMapping("/anon/getEcologyUser")
|
||||
public String getEcologyUser(){
|
||||
String url="http://192.168.2.85:90/api/hrm/resful/getHrmUserInfoWithPage";
|
||||
String params="{\"params\":{\"pagesize\":999999}}";
|
||||
int result = userService.syncEcologyUser(url,params);
|
||||
if(result==200){
|
||||
return "同步成功";
|
||||
}
|
||||
return "同步失败";
|
||||
}
|
||||
|
||||
/*public Map<String,String> sendPostWithRest(String url,String params){
|
||||
RestTemplate restTemplate=new RestTemplate();
|
||||
ResponseEntity<String> result=null;
|
||||
int statusCode=0;
|
||||
|
|
@ -50,7 +63,7 @@ public class GetEcologyInfoTestController extends BaseController {
|
|||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
public String deptSync(Map<String,String> mapResult){
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ public class SysDeptController extends BaseController
|
|||
* Ecology部门信息同步
|
||||
*/
|
||||
@Log(title = "部门管理", businessType = BusinessType.UPDATE)
|
||||
@RequiresPermissions("system:dept:edit")
|
||||
@RequiresPermissions("system:dept:sync")
|
||||
@PostMapping("/syncDept")
|
||||
@ResponseBody
|
||||
public AjaxResult syncDept()
|
||||
|
|
@ -218,8 +218,8 @@ public class SysDeptController extends BaseController
|
|||
String params="{\"params\":{\"pagesize\":1000}}";
|
||||
int result = deptService.syncEcologyDept(url,params);
|
||||
if(result==200){
|
||||
return AjaxResult.success("部门同步成功,返回状态码:"+result);
|
||||
return AjaxResult.success("同步Ecology部门成功,返回状态码:"+result);
|
||||
}
|
||||
return AjaxResult.error("同步失败,返回状态码:"+result);
|
||||
return AjaxResult.error("同步Ecology部门失败,返回状态码:"+result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -285,4 +285,22 @@ public class SysUserController extends BaseController
|
|||
userService.checkUserAllowed(user);
|
||||
return toAjax(userService.changeStatus(user));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ecology部门信息同步
|
||||
*/
|
||||
@Log(title = "部门管理", businessType = BusinessType.UPDATE)
|
||||
@RequiresPermissions("system:user:sync")
|
||||
@PostMapping("/syncUser")
|
||||
@ResponseBody
|
||||
public AjaxResult syncDept()
|
||||
{
|
||||
String url="http://192.168.2.85:90/api/hrm/resful/getHrmUserInfoWithPage";
|
||||
String params="{\"params\":{\"pagesize\":999999}}";
|
||||
int result = userService.syncEcologyUser(url,params);
|
||||
if(result==200){
|
||||
return AjaxResult.success("Ecology人员同步成功,返回状态码:"+result);
|
||||
}
|
||||
return AjaxResult.error("Ecology人员同步失败,返回状态码:"+result);
|
||||
}
|
||||
}
|
||||
|
|
@ -62,6 +62,9 @@
|
|||
</div>
|
||||
|
||||
<div class="btn-group-sm" id="toolbar" role="group">
|
||||
<a class="btn btn-success" onclick="syncUser()" shiro:hasPermission="system:user:sync">
|
||||
<i class="fa fa-plus"></i> 同步
|
||||
</a>
|
||||
<a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="system:user:add">
|
||||
<i class="fa fa-plus"></i> 新增
|
||||
</a>
|
||||
|
|
@ -262,6 +265,19 @@
|
|||
$.operate.post(prefix + "/changeStatus", { "userId": userId, "status": 0 });
|
||||
})
|
||||
}
|
||||
|
||||
function syncUser() {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: ctx + "system/user/syncUser",
|
||||
data: JSON.stringify(""),
|
||||
contentType: "application/json",
|
||||
dataType: "json",
|
||||
success: function (message) {
|
||||
alert(JSON.stringify(message)); //将JSON对象转换为字符串
|
||||
}
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
<!-- 导入区域 -->
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import java.net.SocketTimeoutException;
|
|||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
|
@ -19,6 +21,9 @@ import javax.net.ssl.X509TrustManager;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* 通用http发送方法
|
||||
|
|
@ -259,4 +264,32 @@ public class HttpUtils
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 向指定 Restful接口 发送POST方法的请求
|
||||
*
|
||||
* @param url 发送请求的 URL
|
||||
* @param params 请求参数,请求参数为json的形式。例:params="{\"params\":{\"pagesize\":1000}}"
|
||||
* @return 返回Map, Key="statusCode",接口访问返回状态, key="result":接口返回接果
|
||||
*/
|
||||
public static Map<String,String> sendPostWithRest(String url, String params){
|
||||
RestTemplate restTemplate=new RestTemplate();
|
||||
ResponseEntity<String> result=null;
|
||||
int statusCode=0;
|
||||
try{
|
||||
result=restTemplate.postForEntity(url,params,String.class);
|
||||
statusCode=result.getStatusCode().value();
|
||||
}catch (RestClientException e){
|
||||
System.out.println("POST Request uri: "+url+", params:"+params+" error:"+e.getMessage());
|
||||
}
|
||||
Map<String,String> map=new HashMap<>();
|
||||
map.put("statusCode",String.valueOf(statusCode));
|
||||
if(statusCode== 200){
|
||||
map.put("result",result.getBody());
|
||||
} else{
|
||||
map.put("result",String.valueOf(statusCode));
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
package com.ruoyi.system.domain;
|
||||
|
||||
public class EcologyUser {
|
||||
String subcompanyid1;
|
||||
String password;
|
||||
String id;
|
||||
String loginid;
|
||||
String lastname;
|
||||
String departmentid;
|
||||
String mobile;
|
||||
String email;
|
||||
String sex;
|
||||
String Status;
|
||||
|
||||
public String getSubcompanyid1() {
|
||||
return subcompanyid1;
|
||||
}
|
||||
|
||||
public void setSubcompanyid1(String subcompanyid1) {
|
||||
this.subcompanyid1 = subcompanyid1;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLoginid() {
|
||||
return loginid;
|
||||
}
|
||||
|
||||
public void setLoginid(String loginid) {
|
||||
this.loginid = loginid;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
public void setLastname(String lastname) {
|
||||
this.lastname = lastname;
|
||||
}
|
||||
|
||||
public String getDepartmentid() {
|
||||
return departmentid;
|
||||
}
|
||||
|
||||
public void setDepartmentid(String departmentid) {
|
||||
this.departmentid = departmentid;
|
||||
}
|
||||
|
||||
public String getMobile() {
|
||||
return mobile;
|
||||
}
|
||||
|
||||
public void setMobile(String mobile) {
|
||||
this.mobile = mobile;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getSex() {
|
||||
return sex;
|
||||
}
|
||||
|
||||
public void setSex(String sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return Status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
Status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EcologyUser{" +
|
||||
"subcompanyid1='" + subcompanyid1 + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
", id='" + id + '\'' +
|
||||
", loginid='" + loginid + '\'' +
|
||||
", lastname='" + lastname + '\'' +
|
||||
", departmentid='" + departmentid + '\'' +
|
||||
", mobile='" + mobile + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", sex='" + sex + '\'' +
|
||||
", Status='" + Status + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
@ -121,4 +121,9 @@ public interface SysUserMapper
|
|||
* @return 结果
|
||||
*/
|
||||
public SysUser checkEmailUnique(String email);
|
||||
|
||||
/**
|
||||
* 删除Ecology同步过来的用户
|
||||
*/
|
||||
public void deleteEcologySyncUser();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -204,4 +204,9 @@ public interface ISysUserService
|
|||
* @return 结果
|
||||
*/
|
||||
public int changeStatus(SysUser user);
|
||||
|
||||
/**
|
||||
* Ecology人员信息同步
|
||||
*/
|
||||
public int syncEcologyUser(String url,String params);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@ import java.util.*;
|
|||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.ruoyi.common.utils.http.HttpUtils;
|
||||
import com.ruoyi.system.domain.EcologyDept;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
|
|
@ -28,7 +30,7 @@ import org.springframework.web.client.RestTemplate;
|
|||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
@Service("sysDeptServiceImpl")
|
||||
public class SysDeptServiceImpl implements ISysDeptService
|
||||
{
|
||||
@Autowired
|
||||
|
|
@ -319,11 +321,11 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||
*/
|
||||
@Override
|
||||
public int syncEcologyDept(String url,String params) {
|
||||
int result= deptSync(sendPostWithRest(url,params));
|
||||
int result= deptSync(HttpUtils.sendPostWithRest(url,params));
|
||||
return result;
|
||||
|
||||
}
|
||||
public Map<String,String> sendPostWithRest(String url, String params){
|
||||
/* public Map<String,String> sendPostWithRest(String url, String params){
|
||||
RestTemplate restTemplate=new RestTemplate();
|
||||
ResponseEntity<String> result=null;
|
||||
int statusCode=0;
|
||||
|
|
@ -342,8 +344,7 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
public int deptSync(Map<String,String> mapResult){
|
||||
//如果接口返回状态码不为200,则不做同步处理
|
||||
|
|
|
|||
|
|
@ -1,12 +1,7 @@
|
|||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||
|
|
@ -14,24 +9,31 @@ import com.ruoyi.common.core.domain.entity.SysUser;
|
|||
import com.ruoyi.common.core.text.Convert;
|
||||
import com.ruoyi.common.exception.BusinessException;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.http.HttpUtils;
|
||||
import com.ruoyi.common.utils.security.Md5Utils;
|
||||
import com.ruoyi.system.domain.EcologyUser;
|
||||
import com.ruoyi.system.domain.SysPost;
|
||||
import com.ruoyi.system.domain.SysUserPost;
|
||||
import com.ruoyi.system.domain.SysUserRole;
|
||||
import com.ruoyi.system.mapper.SysPostMapper;
|
||||
import com.ruoyi.system.mapper.SysRoleMapper;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import com.ruoyi.system.mapper.SysUserPostMapper;
|
||||
import com.ruoyi.system.mapper.SysUserRoleMapper;
|
||||
import com.ruoyi.system.mapper.*;
|
||||
import com.ruoyi.system.service.ISysConfigService;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户 业务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
@Service("sysUserServiceImpl")
|
||||
public class SysUserServiceImpl implements ISysUserService
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class);
|
||||
|
|
@ -525,4 +527,51 @@ public class SysUserServiceImpl implements ISysUserService
|
|||
{
|
||||
return userMapper.updateUser(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ecology人员信息同步
|
||||
*
|
||||
* @param url
|
||||
* @param params
|
||||
*/
|
||||
@Override
|
||||
public int syncEcologyUser(String url, String params) {
|
||||
int result= userSync(HttpUtils.sendPostWithRest(url,params));
|
||||
return result;
|
||||
}
|
||||
|
||||
public int userSync(Map<String,String> mapResult){
|
||||
//如果接口返回状态码不为200,则不做同步处理
|
||||
String statusCode=mapResult.get("statusCode");
|
||||
String result= mapResult.get("result");
|
||||
if(!statusCode.equals("200"))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
//取Ecology返回信息中的部门信息
|
||||
Map<String,Object> map = (Map) JSON.parse(result);
|
||||
Map<String,Object> o= (Map<String, Object>) map.get("data");
|
||||
JSONArray json = (JSONArray) o.get("dataList");
|
||||
List<EcologyUser> ecologyUserList = JSONArray.parseArray(json.toJSONString(), EcologyUser.class);
|
||||
|
||||
userMapper.deleteEcologySyncUser();
|
||||
SysUser user = new SysUser();
|
||||
//同步Ecology部门信息
|
||||
for(EcologyUser ecologyuser:ecologyUserList){
|
||||
if(ecologyuser.getSubcompanyid1().equals("1") && StringUtils.isNotEmpty(ecologyuser.getLoginid())) { //只取分部ID为“1”的员工
|
||||
user.setUserId(Long.parseLong(ecologyuser.getId()));
|
||||
user.setDeptId(Long.parseLong(ecologyuser.getDepartmentid()));
|
||||
user.setLoginName(ecologyuser.getLoginid());
|
||||
user.setUserName(ecologyuser.getLastname());
|
||||
user.setUserType("02");
|
||||
user.setEmail(ecologyuser.getEmail());
|
||||
user.setSex(ecologyuser.getSex());
|
||||
user.setPhonenumber(ecologyuser.getMobile());
|
||||
user.setStatus(ecologyuser.getStatus().equals("5")?"1":"0"); //Ecology为离职状态5,则无效
|
||||
user.setDelFlag("0");
|
||||
userMapper.insertUser(user);
|
||||
}
|
||||
}
|
||||
return 200;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -223,5 +223,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
sysdate()
|
||||
)
|
||||
</insert>
|
||||
|
||||
<delete id="deleteEcologySyncUser" >
|
||||
delete from sys_user where user_type ='02'
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue