people-同步用户部门定时任务
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
|||||||
|
package com.jero.modules.system.controller;
|
||||||
|
|
||||||
|
import com.jero.common.api.vo.Result;
|
||||||
|
import com.jero.modules.system.service.ISyncDataService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: liyawei
|
||||||
|
* @Description:
|
||||||
|
* @Date: Created in 15:50 2022/5/24
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/sys/people")
|
||||||
|
@Api(tags="people同步")
|
||||||
|
@Slf4j
|
||||||
|
public class SyncDataController {
|
||||||
|
@Autowired
|
||||||
|
private ISyncDataService syncDataService;
|
||||||
|
|
||||||
|
@ApiOperation(value = "通过people同步部门信息")
|
||||||
|
@GetMapping("/syncDepartInfo")
|
||||||
|
public Result<?> syncDepartInfo() throws Exception {
|
||||||
|
syncDataService.synchronPPDepartInfo();
|
||||||
|
return Result.OK("开始同步部门信息");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation(value = "通过people同步用户信息")
|
||||||
|
@GetMapping("/syncUserInfo")
|
||||||
|
public Result<?> syncUserInfo() throws Exception {
|
||||||
|
syncDataService.synchronPPUserInfo();
|
||||||
|
return Result.OK("开始同步用户信息");
|
||||||
|
}
|
||||||
|
}
|
||||||
+83
@@ -0,0 +1,83 @@
|
|||||||
|
package com.jero.modules.system.entity;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||||
|
import com.jero.common.aspect.annotation.Dict;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 同步时间记录表
|
||||||
|
* @Author: jero-boot
|
||||||
|
* @Date: 2022-05-25
|
||||||
|
* @Version: V1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("ot_sync_info")
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@ApiModel(value="ot_sync_info对象", description="同步时间记录表")
|
||||||
|
public class OtSyncInfoEO implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**主键*/
|
||||||
|
@TableId(type = IdType.ASSIGN_ID)
|
||||||
|
@ApiModelProperty(value = "主键")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**创建人*/
|
||||||
|
@ApiModelProperty(value = "创建人")
|
||||||
|
private String createBy;
|
||||||
|
|
||||||
|
/**创建日期*/
|
||||||
|
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ApiModelProperty(value = "创建日期")
|
||||||
|
private java.util.Date createTime;
|
||||||
|
|
||||||
|
/**更新人*/
|
||||||
|
@ApiModelProperty(value = "更新人")
|
||||||
|
private String updateBy;
|
||||||
|
|
||||||
|
/**更新日期*/
|
||||||
|
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ApiModelProperty(value = "更新日期")
|
||||||
|
private java.util.Date updateTime;
|
||||||
|
|
||||||
|
/**所属部门*/
|
||||||
|
@ApiModelProperty(value = "所属部门")
|
||||||
|
private String sysOrgCode;
|
||||||
|
|
||||||
|
/**同步时间*/
|
||||||
|
@Excel(name = "同步时间", width = 15, format = "yyyy-MM-dd")
|
||||||
|
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
|
||||||
|
@DateTimeFormat(pattern="yyyy-MM-dd")
|
||||||
|
@ApiModelProperty(value = "同步时间")
|
||||||
|
private java.util.Date syncTime;
|
||||||
|
|
||||||
|
/**上次同步时间*/
|
||||||
|
@Excel(name = "上次同步时间", width = 15, format = "yyyy-MM-dd")
|
||||||
|
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
|
||||||
|
@DateTimeFormat(pattern="yyyy-MM-dd")
|
||||||
|
@ApiModelProperty(value = "上次同步时间")
|
||||||
|
private java.util.Date lastSyncTime;
|
||||||
|
|
||||||
|
/**同步类型*/
|
||||||
|
@Excel(name = "同步类型", width = 15)
|
||||||
|
@ApiModelProperty(value = "同步类型")
|
||||||
|
private String syncType;
|
||||||
|
|
||||||
|
}
|
||||||
+2
-2
@@ -9,10 +9,10 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class PPDepartment {
|
public class PPDepartment {
|
||||||
private String ref_id; //部门ID ----id
|
private String ref_id; //部门ID ----id, org_code(因为org_code不能为空)
|
||||||
private String name_en; //部门英文名 ----depart_name_en
|
private String name_en; //部门英文名 ----depart_name_en
|
||||||
private String name_cn; //部门中文名 ----depart_name
|
private String name_cn; //部门中文名 ----depart_name
|
||||||
private String code; //部门code ----org_code
|
private String code; //部门code ----depart_order
|
||||||
private String manager_id; //部门负责人员工号
|
private String manager_id; //部门负责人员工号
|
||||||
private String manager_wk_uid; //部门负责人域账号
|
private String manager_wk_uid; //部门负责人域账号
|
||||||
private String hr_partner; //部门 HRBP(多个会用";"隔开)
|
private String hr_partner; //部门 HRBP(多个会用";"隔开)
|
||||||
|
|||||||
+27
-11
@@ -11,14 +11,15 @@ import java.util.Date;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class PPEmployee {
|
public class PPEmployee {
|
||||||
|
// people_info
|
||||||
private String data_difference; //数据来源[WORKDAY,XPT,NIOCAPITAL]
|
private String data_difference; //数据来源[WORKDAY,XPT,NIOCAPITAL]
|
||||||
private String employee_difference; // 员工来源[CN, EU_US,EU]
|
private String employee_difference; // 员工来源[CN, EU_US,EU]
|
||||||
private String employee_id; // 员工编号(员工唯一标识)
|
private String employee_id; // 员工编号(员工唯一标识) ----workNo
|
||||||
private String worker_user_id; //WD帐号创建SSO账号 / AD账户
|
private String worker_user_id; //WD帐号创建SSO账号 / AD账户 ----thirdId
|
||||||
private String user_name; // WD同步到people的域帐号
|
private String user_name; // WD同步到people的域帐号 ----username
|
||||||
private String foreign_employee_id; // 兼职公司对应的员工编号
|
// private String foreign_employee_id; // 兼职公司对应的员工编号
|
||||||
private String name; // 全名
|
private String name; // 全名
|
||||||
private String formatted_name; // 全名-拼音及中文
|
private String formatted_name; // 全名-拼音及中文 ----realname
|
||||||
private String preferred_first_name; // 首选-名
|
private String preferred_first_name; // 首选-名
|
||||||
private String preferred_last_name; // 首选-姓
|
private String preferred_last_name; // 首选-姓
|
||||||
private String first_name; //法定-名-拼音
|
private String first_name; //法定-名-拼音
|
||||||
@@ -28,13 +29,13 @@ public class PPEmployee {
|
|||||||
private String name_in_local_script; // 法定-姓名-中文
|
private String name_in_local_script; // 法定-姓名-中文
|
||||||
private String first_name_in_local_script; // 名-中文
|
private String first_name_in_local_script; // 名-中文
|
||||||
private String last_name_in_local_script; // 姓-中文
|
private String last_name_in_local_script; // 姓-中文
|
||||||
private String delete_flag; // 删除标记[1:存在;0:删除]
|
private String delete_flag; // 删除标记[1:存在;0:删除] ----delFlag
|
||||||
private String delete_time; // 删除时间
|
private String delete_time; // 删除时间
|
||||||
private String delay_flag; // 延期标记(0:延期,1:未延期,2:未操作)
|
private String delay_flag; // 延期标记(0:延期,1:未延期,2:未操作)
|
||||||
private String delay_time; // 延期时间
|
private String delay_time; // 延期时间
|
||||||
private String employee_status; // 员工状态[Active,Terminated]
|
private String employee_status; // 员工状态[Active,Terminated] ----statue
|
||||||
private String outsourcing_type; // 外包形式
|
private String outsourcing_type; // 外包形式
|
||||||
private String worker_type; // 员工种类 Employee,Contingent Worker
|
private String worker_type; // 员工种类 Employee,Contingent Worker ----workerType
|
||||||
private String hire_date; // 员工入职日期
|
private String hire_date; // 员工入职日期
|
||||||
private String original_hire_date; // 员工原始入职日期
|
private String original_hire_date; // 员工原始入职日期
|
||||||
private String rehire; // 重新雇用[1:是;0:否]
|
private String rehire; // 重新雇用[1:是;0:否]
|
||||||
@@ -53,8 +54,23 @@ public class PPEmployee {
|
|||||||
private String domain; // 账号所属域
|
private String domain; // 账号所属域
|
||||||
private String ad_failed; // 创建ad失败原账号
|
private String ad_failed; // 创建ad失败原账号
|
||||||
private String have_employees; // 是否有下属员工
|
private String have_employees; // 是否有下属员工
|
||||||
private String id; // id
|
private String id; // id ----id
|
||||||
private Date creation_time; // 创建时间
|
private Date creation_time; // 创建时间 ----createTime
|
||||||
private Date update_time; // 修改时间
|
private Date update_time; // 修改时间 ----updateTime
|
||||||
|
|
||||||
|
// people_job_info 多个 取第一个
|
||||||
|
private String job_code;
|
||||||
|
private String job_title;
|
||||||
|
private String supervisory_organization_ref_id; // 部门id
|
||||||
|
|
||||||
|
|
||||||
|
// people_contact_email 多个 取第一个WORK邮箱
|
||||||
|
private String email_type; // HOME/WORK
|
||||||
|
private String email_address;
|
||||||
|
|
||||||
|
// people_contact_phone 多个 取第一个Mobile的WORK电话
|
||||||
|
private String phone_type; // HOME/WORK
|
||||||
|
private String phone_device_type; // Mobile/Landline
|
||||||
|
private String formatted_phone_number;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -164,6 +164,7 @@ public class SysUser implements Serializable {
|
|||||||
private String clientId;
|
private String clientId;
|
||||||
|
|
||||||
private String thirdId;//用户域账号
|
private String thirdId;//用户域账号
|
||||||
|
private String thirdType;//用户数据来源
|
||||||
|
|
||||||
@Excel(name = "员工类型", width = 15, dicCode = "worker_type")
|
@Excel(name = "员工类型", width = 15, dicCode = "worker_type")
|
||||||
@Dict(dicCode = "worker_type")
|
@Dict(dicCode = "worker_type")
|
||||||
@@ -182,4 +183,8 @@ public class SysUser implements Serializable {
|
|||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private String cut; //中英文切换标识
|
private String cut; //中英文切换标识
|
||||||
|
|
||||||
|
//新添加的字段
|
||||||
|
private String jobCode;
|
||||||
|
private String jobTitle;
|
||||||
}
|
}
|
||||||
|
|||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package com.jero.modules.system.mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import com.jero.modules.system.entity.OtSyncInfoEO;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 同步时间记录表
|
||||||
|
* @Author: jero-boot
|
||||||
|
* @Date: 2022-05-25
|
||||||
|
* @Version: V1.0
|
||||||
|
*/
|
||||||
|
public interface OtSyncInfoEOMapper extends BaseMapper<OtSyncInfoEO> {
|
||||||
|
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.jero.modules.system.mapper.OtSyncInfoEOMapper">
|
||||||
|
<resultMap id="OtSyncInfoEOResultMap" type="com.jero.modules.system.entity.OtSyncInfoEO">
|
||||||
|
<id column="id" property="id" />
|
||||||
|
<result column="create_by" property="createBy" />
|
||||||
|
<result column="create_time" property="createTime" />
|
||||||
|
<result column="update_by" property="updateBy" />
|
||||||
|
<result column="update_time" property="updateTime" />
|
||||||
|
<result column="sys_org_code" property="sysOrgCode" />
|
||||||
|
<result column="sync_time" property="syncTime" />
|
||||||
|
<result column="last_sync_time" property="lastSyncTime" />
|
||||||
|
<result column="sync_type" property="syncType" />
|
||||||
|
</resultMap>
|
||||||
|
</mapper>
|
||||||
+63
@@ -0,0 +1,63 @@
|
|||||||
|
package com.jero.modules.system.service;
|
||||||
|
|
||||||
|
import com.jero.modules.system.entity.OtSyncInfoEO;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 同步时间记录表
|
||||||
|
* @Author: jero-boot
|
||||||
|
* @Date: 2022-05-25
|
||||||
|
* @Version: V1.0
|
||||||
|
*/
|
||||||
|
public interface IOtSyncInfoEOService extends IService<OtSyncInfoEO> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存
|
||||||
|
*
|
||||||
|
* @param otSyncInfoEO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void add(OtSyncInfoEO otSyncInfoEO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新
|
||||||
|
*
|
||||||
|
* @param otSyncInfoEO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void editById(OtSyncInfoEO otSyncInfoEO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过id删除
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void deleteById(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除
|
||||||
|
*
|
||||||
|
* @param ids
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void deleteByIds(List<String> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过id查询
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
OtSyncInfoEO queryById(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表查询
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<OtSyncInfoEO> queryList();
|
||||||
|
|
||||||
|
OtSyncInfoEO getLastSyncInfo(String syncType);
|
||||||
|
}
|
||||||
+6
-2
@@ -13,6 +13,12 @@ import java.security.NoSuchAlgorithmException;
|
|||||||
* @Date: Created in 15:37 2022/2/28
|
* @Date: Created in 15:37 2022/2/28
|
||||||
*/
|
*/
|
||||||
public interface ISyncDataService {
|
public interface ISyncDataService {
|
||||||
|
|
||||||
|
void synchronPPDepartInfo() throws Exception;
|
||||||
|
|
||||||
|
void synchronPPUserInfo() throws Exception;
|
||||||
|
|
||||||
|
|
||||||
void syncDepartInfo() throws IOException, NoSuchAlgorithmException, InvalidKeyException;
|
void syncDepartInfo() throws IOException, NoSuchAlgorithmException, InvalidKeyException;
|
||||||
|
|
||||||
int insertDepartFromTree(PPOrganization root, int i);
|
int insertDepartFromTree(PPOrganization root, int i);
|
||||||
@@ -22,6 +28,4 @@ public interface ISyncDataService {
|
|||||||
void syncDepartRoleInfo() throws IOException, NoSuchAlgorithmException, InvalidKeyException;
|
void syncDepartRoleInfo() throws IOException, NoSuchAlgorithmException, InvalidKeyException;
|
||||||
|
|
||||||
void syncDepartRoleUserInfo() throws IOException, NoSuchAlgorithmException, InvalidKeyException;
|
void syncDepartRoleUserInfo() throws IOException, NoSuchAlgorithmException, InvalidKeyException;
|
||||||
|
|
||||||
String getResultDataOfGet(String uri, String queryString) throws IOException, NoSuchAlgorithmException, InvalidKeyException;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-1
@@ -140,8 +140,24 @@ public interface ISysDepartService extends IService<SysDepart>{
|
|||||||
*/
|
*/
|
||||||
void updateAllParentId();
|
void updateAllParentId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取从people同步过来的部门列表
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
List<SysDepart> getPPDepartList();
|
List<SysDepart> getPPDepartList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加从people同步过来的部门
|
||||||
|
* @param ppDepartment
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
SysDepart addPPDepart(PPDepartment ppDepartment);
|
SysDepart addPPDepart(PPDepartment ppDepartment);
|
||||||
void updatePPDepart(PPDepartment ppDepartment);
|
|
||||||
|
/**
|
||||||
|
* 修改从people同步过来的部门
|
||||||
|
* @param sysDepart
|
||||||
|
* @param ppDepartment
|
||||||
|
*/
|
||||||
|
void updatePPDepart(SysDepart sysDepart, PPDepartment ppDepartment);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+8
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.jero.common.api.vo.Result;
|
import com.jero.common.api.vo.Result;
|
||||||
import com.jero.common.system.vo.SysUserCacheInfo;
|
import com.jero.common.system.vo.SysUserCacheInfo;
|
||||||
|
import com.jero.modules.system.entity.PPEmployee;
|
||||||
import com.jero.modules.system.entity.SysUser;
|
import com.jero.modules.system.entity.SysUser;
|
||||||
import com.jero.modules.system.model.DepartIdModel;
|
import com.jero.modules.system.model.DepartIdModel;
|
||||||
import com.jero.modules.system.model.SysUserSysDepartModel;
|
import com.jero.modules.system.model.SysUserSysDepartModel;
|
||||||
@@ -254,4 +255,11 @@ public interface ISysUserService extends IService<SysUser> {
|
|||||||
* 根据用户名usernameList查询id
|
* 根据用户名usernameList查询id
|
||||||
*/
|
*/
|
||||||
List<SysUser> queryUserIdListByNameList(List<String> usernameList);
|
List<SysUser> queryUserIdListByNameList(List<String> usernameList);
|
||||||
|
|
||||||
|
List<SysUser> getPPEmployeeList();
|
||||||
|
|
||||||
|
SysUser addPPUserInfo(PPEmployee ppEmployee);
|
||||||
|
|
||||||
|
void updatePPUserInfo(SysUser sysUser, PPEmployee ppEmployee);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+107
@@ -0,0 +1,107 @@
|
|||||||
|
package com.jero.modules.system.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.jero.modules.system.entity.OtSyncInfoEO;
|
||||||
|
import com.jero.modules.system.mapper.OtSyncInfoEOMapper;
|
||||||
|
import com.jero.modules.system.service.IOtSyncInfoEOService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Date;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 同步时间记录表
|
||||||
|
* @Author: jero-boot
|
||||||
|
* @Date: 2022-05-25
|
||||||
|
* @Version: V1.0
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class OtSyncInfoEOServiceImpl extends ServiceImpl<OtSyncInfoEOMapper, OtSyncInfoEO> implements IOtSyncInfoEOService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存
|
||||||
|
*
|
||||||
|
* @param otSyncInfoEO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void add(OtSyncInfoEO otSyncInfoEO) {
|
||||||
|
Date now = new Date();
|
||||||
|
otSyncInfoEO.setCreateTime(now);
|
||||||
|
otSyncInfoEO.setUpdateTime(now);
|
||||||
|
save(otSyncInfoEO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新
|
||||||
|
*
|
||||||
|
* @param otSyncInfoEO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void editById(OtSyncInfoEO otSyncInfoEO) {
|
||||||
|
Date now = new Date();
|
||||||
|
otSyncInfoEO.setUpdateTime(now);
|
||||||
|
saveOrUpdate(otSyncInfoEO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过id删除
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deleteById(String id) {
|
||||||
|
removeById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除
|
||||||
|
*
|
||||||
|
* @param ids
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deleteByIds(List<String> ids) {
|
||||||
|
removeByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过id查询
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public OtSyncInfoEO queryById(String id) {
|
||||||
|
return getById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表查询
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<OtSyncInfoEO> queryList() {
|
||||||
|
return list();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取上一次同步的信息
|
||||||
|
* @param syncType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public OtSyncInfoEO getLastSyncInfo(String syncType){
|
||||||
|
LambdaQueryWrapper<OtSyncInfoEO> queryWrapper = new LambdaQueryWrapper();
|
||||||
|
queryWrapper.eq(OtSyncInfoEO::getSyncType, syncType)
|
||||||
|
.orderByDesc(OtSyncInfoEO::getSyncTime);
|
||||||
|
List<OtSyncInfoEO> syncInfoEOList = list(queryWrapper);
|
||||||
|
if(syncInfoEOList!=null && !syncInfoEOList.isEmpty()){
|
||||||
|
return syncInfoEOList.get(0);
|
||||||
|
}else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+292
-17
@@ -1,6 +1,7 @@
|
|||||||
package com.jero.modules.system.service.impl;
|
package com.jero.modules.system.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.jero.common.constant.CommonConstant;
|
import com.jero.common.constant.CommonConstant;
|
||||||
@@ -8,6 +9,7 @@ import com.jero.common.system.vo.LoginUser;
|
|||||||
import com.jero.common.util.PasswordUtil;
|
import com.jero.common.util.PasswordUtil;
|
||||||
import com.jero.common.util.oConvertUtils;
|
import com.jero.common.util.oConvertUtils;
|
||||||
import com.jero.modules.system.entity.*;
|
import com.jero.modules.system.entity.*;
|
||||||
|
import com.jero.modules.system.enums.PPSyncEnum;
|
||||||
import com.jero.modules.system.service.*;
|
import com.jero.modules.system.service.*;
|
||||||
import com.jero.modules.system.util.HmacSignUtil;
|
import com.jero.modules.system.util.HmacSignUtil;
|
||||||
import com.jero.modules.system.util.HttpRequestUtil;
|
import com.jero.modules.system.util.HttpRequestUtil;
|
||||||
@@ -16,15 +18,15 @@ import org.apache.commons.lang.StringUtils;
|
|||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.Date;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,12 +56,283 @@ public class SyncDataServiceImpl implements ISyncDataService{
|
|||||||
private ISysDepartRoleService sysDepartRoleService;
|
private ISysDepartRoleService sysDepartRoleService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysDepartRoleUserService sysDepartRoleUserService;
|
private ISysDepartRoleUserService sysDepartRoleUserService;
|
||||||
|
@Autowired
|
||||||
|
private IOtSyncInfoEOService otSyncInfoEOService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步部门信息
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Async
|
||||||
|
@Transactional(readOnly = false, rollbackFor = Exception.class)
|
||||||
|
public void synchronPPDepartInfo() throws Exception {
|
||||||
|
Date nowTime = new Date();
|
||||||
|
// 本地组织机构MAP
|
||||||
|
Map<String, SysDepart> localDepartMap = new HashMap<String, SysDepart>();
|
||||||
|
// 获取上次同步状态
|
||||||
|
OtSyncInfoEO lastSyncInfo = otSyncInfoEOService.getLastSyncInfo(PPSyncEnum.PP_DEPART.getValue());
|
||||||
|
//首先获取系统内的所有PP组织机构
|
||||||
|
List<SysDepart> sysDepartList = sysDepartService.getPPDepartList();
|
||||||
|
//将List转化成Map结构
|
||||||
|
if (sysDepartList != null && !sysDepartList.isEmpty()) {
|
||||||
|
for (SysDepart eo : sysDepartList) {
|
||||||
|
localDepartMap.put(eo.getId(), eo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 取PP数据
|
||||||
|
String path = "/people/v1/base/department/list";
|
||||||
|
String queryStr = "app_id=" + appId +"&hash_type=sha256&offset=0&limit=100";
|
||||||
|
String response = getResultDataOfGet(path, queryStr);
|
||||||
|
JSONObject myJson = JSONObject.parseObject(response);
|
||||||
|
log.debug(myJson.toJSONString());
|
||||||
|
if (!myJson.get("result_code").toString().equals("success")) {
|
||||||
|
log.error("请求出现异常:" + myJson.get("message") + " " + myJson);
|
||||||
|
} else {
|
||||||
|
log.debug("打印输出本次同步信息返回结果:" + myJson.get("data").toString());
|
||||||
|
JSONObject resultJson = (JSONObject) myJson.get("data");
|
||||||
|
List<PPDepartment> ppDepartList = JSONObject.parseArray(resultJson.get("list").toString(), PPDepartment.class);
|
||||||
|
//获取总记录数
|
||||||
|
int total = (int) resultJson.get("amount");
|
||||||
|
if (total > 100) {
|
||||||
|
int pageSum = total / 100; // 总页数
|
||||||
|
if ((total % 100) > 0) {
|
||||||
|
pageSum += 1;
|
||||||
|
}
|
||||||
|
//循环查询统一认证系统所有账户信息(从第二页开始)
|
||||||
|
for (int page = 1; page < pageSum; page++) {
|
||||||
|
path = "/people/v1/base/department/list";
|
||||||
|
queryStr = "app_id=" + appId +"&hash_type=sha256&limit=100&offset=" + (page*100);
|
||||||
|
response = getResultDataOfGet(path, queryStr);
|
||||||
|
myJson = JSONObject.parseObject(response.toString());
|
||||||
|
resultJson = (JSONObject) myJson.get("data");
|
||||||
|
log.debug("打印输出本次同步信息返回结果:" + myJson.get("data").toString());
|
||||||
|
List<PPDepartment> currentPPDepartList = JSONObject.parseArray(resultJson.get("list").toString(), PPDepartment.class);
|
||||||
|
ppDepartList.addAll(currentPPDepartList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//开始循环遍历数据
|
||||||
|
/***
|
||||||
|
* 判断PP数据是否存在,不存在:插入,存在:更新
|
||||||
|
*/
|
||||||
|
if (ppDepartList != null && !ppDepartList.isEmpty()) {
|
||||||
|
for (PPDepartment ppDepart : ppDepartList) {
|
||||||
|
try {
|
||||||
|
// 判断当前SSO组织机构是否在本地存在 不存在先将数据添加到数据中
|
||||||
|
if (!localDepartMap.containsKey(ppDepart.getRef_id())) {
|
||||||
|
if (StringUtils.isNotBlank(ppDepart.getRef_id())) { // 排除ref_id为空的情况
|
||||||
|
SysDepart sysDepart = sysDepartService.addPPDepart(ppDepart);
|
||||||
|
localDepartMap.put(ppDepart.getRef_id(), sysDepart);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SysDepart sysDepart = localDepartMap.get(ppDepart.getRef_id());
|
||||||
|
sysDepartService.updatePPDepart(sysDepart, ppDepart);
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("同步部门数据出现异常,异常信息为:"+e.getMessage(), e);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//记录同步规则
|
||||||
|
// 写入本次同步记录
|
||||||
|
OtSyncInfoEO syncInfoEO = new OtSyncInfoEO();
|
||||||
|
syncInfoEO.setSyncTime(nowTime);
|
||||||
|
syncInfoEO.setSyncType(PPSyncEnum.PP_DEPART.getValue());
|
||||||
|
syncInfoEO.setLastSyncTime(lastSyncInfo != null ? lastSyncInfo.getSyncTime() : null);
|
||||||
|
otSyncInfoEOService.save(syncInfoEO);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步用户信息
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Async
|
||||||
|
@Transactional(readOnly = false, rollbackFor = Exception.class)
|
||||||
|
public void synchronPPUserInfo() throws Exception {
|
||||||
|
// 获取当前时间
|
||||||
|
Date nowTime = new Date();
|
||||||
|
// 获取上次更新时间
|
||||||
|
OtSyncInfoEO lastSyncInfo = otSyncInfoEOService.getLastSyncInfo(PPSyncEnum.PP_USER.getValue());
|
||||||
|
//本地用户信息Map
|
||||||
|
Map<String, SysUser> localUserMap=new HashMap<String,SysUser>();
|
||||||
|
//people获取用户信息Map
|
||||||
|
Map<String, PPEmployee> PPEmployeeMap=new HashMap<String,PPEmployee>();
|
||||||
|
|
||||||
|
String path = "/people/v1/employee/all-info";
|
||||||
|
String queryStr = "app_id=" + appId + "&hash_type=sha256&offset=0&limit=100";
|
||||||
|
String response = getResultDataOfGet(path, queryStr);
|
||||||
|
JSONObject myJson = JSONObject.parseObject(response);
|
||||||
|
log.debug(myJson.toJSONString());
|
||||||
|
if(!myJson.get("result_code").toString().equals("success")){
|
||||||
|
log.error("请求出现异常:"+myJson.get("message")+" "+myJson);
|
||||||
|
}else{
|
||||||
|
log.debug("打印输出本次同步信息返回结果:"+myJson.get("data").toString());
|
||||||
|
JSONObject resultJson = (JSONObject) myJson.get("data");
|
||||||
|
//将第一页的账户信息转换为本地dto集合
|
||||||
|
List<JSONObject> userList = JSONObject.parseArray(resultJson.get("list").toString(), JSONObject.class);
|
||||||
|
List<PPEmployee> ppEmployeeList = getPPEmployeeList(userList);
|
||||||
|
|
||||||
|
//获取总记录数
|
||||||
|
int total = (int) resultJson.get("amount");
|
||||||
|
if(total > 100){
|
||||||
|
int pageSum = total / 100; // 总页数
|
||||||
|
if((total % 100) > 0){
|
||||||
|
pageSum += 1;
|
||||||
|
}
|
||||||
|
//循环查询统一认证系统所有账户信息(从第二页开始)
|
||||||
|
for(int page = 1; page < pageSum; page++){
|
||||||
|
path = "/people/v1/employee/all-info";
|
||||||
|
queryStr = "app_id=" + appId + "&hash_type=sha256&limit=100&offset=" + (page*100);
|
||||||
|
response = getResultDataOfGet(path, queryStr);
|
||||||
|
myJson = JSONObject.parseObject(response);
|
||||||
|
log.debug("打印输出本次同步信息返回结果:"+myJson.get("data").toString());
|
||||||
|
resultJson = (JSONObject) myJson.get("data");
|
||||||
|
userList = JSONObject.parseArray(resultJson.get("list").toString(), JSONObject.class);
|
||||||
|
List<PPEmployee> currentPPEmployeeList = getPPEmployeeList(userList);
|
||||||
|
ppEmployeeList.addAll(currentPPEmployeeList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//此处获取全部pp用户信息
|
||||||
|
List<SysUser> sysUserList = sysUserService.getPPEmployeeList();
|
||||||
|
// log.info("查询到的用户信息结果集为:"+JSONObject.toJSONString(userEOList));
|
||||||
|
for(SysUser user:sysUserList){
|
||||||
|
localUserMap.put(user.getId(),user);
|
||||||
|
}
|
||||||
|
// log.info("将用户信息集合转换为的用户MAP为:"+JSONObject.toJSONString(localUserMap));
|
||||||
|
log.info("开始更新数据库信息");
|
||||||
|
for(PPEmployee ppEmployee:ppEmployeeList){
|
||||||
|
try {
|
||||||
|
PPEmployeeMap.put(ppEmployee.getId(), ppEmployee);
|
||||||
|
//1.判断当前账号是否已添加到用户中
|
||||||
|
if (!localUserMap.containsKey(ppEmployee.getId())) {
|
||||||
|
//删除数据库中与该账户相同的数据
|
||||||
|
if(StringUtils.isNotBlank(ppEmployee.getId())) {
|
||||||
|
sysUserService.removeById(ppEmployee.getId());
|
||||||
|
log.info("需要新增的用户信息为:" + JSONObject.toJSONString(ppEmployee));
|
||||||
|
SysUser newUser = sysUserService.addPPUserInfo(ppEmployee);
|
||||||
|
localUserMap.put(ppEmployee.getId(), newUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
SysUser userEO = localUserMap.get(ppEmployee.getId());
|
||||||
|
log.info("需要更新的用户信息为:" + JSONObject.toJSONString(userEO) + " " + JSONObject.toJSONString(ppEmployee));
|
||||||
|
if(userEO != null) {
|
||||||
|
sysUserService.updatePPUserInfo(userEO, ppEmployee);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
log.error("同步用户数据出现异常,异常信息为:"+e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info("更新数据结束");
|
||||||
|
// 写入本次同步记录
|
||||||
|
OtSyncInfoEO syncInfoEO = new OtSyncInfoEO();
|
||||||
|
syncInfoEO.setSyncTime(nowTime);
|
||||||
|
syncInfoEO.setSyncType(PPSyncEnum.PP_USER.getValue());
|
||||||
|
syncInfoEO.setLastSyncTime(lastSyncInfo != null ? lastSyncInfo.getSyncTime() : null);
|
||||||
|
try {
|
||||||
|
otSyncInfoEOService.save(syncInfoEO);
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
log.error("出现异常,异常信息为:"+e.getMessage(), e);
|
||||||
|
}
|
||||||
|
log.info("写入同步记录结束");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static List<PPEmployee> getPPEmployeeList(List<JSONObject> userList) {
|
||||||
|
List<PPEmployee> ppEmployeeList = new ArrayList<>();
|
||||||
|
for (JSONObject user : userList) {
|
||||||
|
PPEmployee userMainInfo = JSONObject.parseObject(user.get("people_info").toString(), PPEmployee.class);
|
||||||
|
|
||||||
|
List<PPEmployee> userJobInfoList = JSONObject.parseArray(user.get("people_job_info").toString(), PPEmployee.class);
|
||||||
|
if (CollectionUtil.isNotEmpty(userJobInfoList)) {
|
||||||
|
userMainInfo.setJob_code(userJobInfoList.get(0).getJob_code());
|
||||||
|
userMainInfo.setJob_title(userJobInfoList.get(0).getJob_title());
|
||||||
|
userMainInfo.setSupervisory_organization_ref_id(userJobInfoList.get(0).getSupervisory_organization_ref_id());
|
||||||
|
}
|
||||||
|
List<PPEmployee> userEmailInfoList = JSONObject.parseArray(user.get("people_contact_email").toString(), PPEmployee.class);
|
||||||
|
if (CollectionUtil.isNotEmpty(userEmailInfoList)) {
|
||||||
|
PPEmployee userEmailInfo = userEmailInfoList.stream().filter(e->"WORK".equals(e.getEmail_type())).collect(Collectors.toList()).get(0);
|
||||||
|
if (ObjectUtil.isNotEmpty(userEmailInfo)) {
|
||||||
|
userMainInfo.setEmail_address(userEmailInfo.getEmail_address());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<PPEmployee> userPhoneInfoList = JSONObject.parseArray(user.get("people_contact_phone").toString(), PPEmployee.class);
|
||||||
|
if (CollectionUtil.isNotEmpty(userPhoneInfoList)) {
|
||||||
|
PPEmployee userPhoneInfo = userPhoneInfoList.stream().filter(e->"WORK".equals(e.getPhone_type()) && "Mobile".equals(e.getPhone_device_type())).collect(Collectors.toList()).get(0);
|
||||||
|
if (ObjectUtil.isNotEmpty(userPhoneInfo)) {
|
||||||
|
userMainInfo.setFormatted_phone_number(userPhoneInfo.getFormatted_phone_number());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ppEmployeeList.add(userMainInfo);
|
||||||
|
}
|
||||||
|
return ppEmployeeList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送请求,获取同步数据
|
||||||
|
* @param uri
|
||||||
|
* @param queryString
|
||||||
|
* @return
|
||||||
|
* @throws IOException
|
||||||
|
* @throws NoSuchAlgorithmException
|
||||||
|
* @throws InvalidKeyException
|
||||||
|
*/
|
||||||
|
private String getResultDataOfGet(String uri, String queryString) throws IOException, NoSuchAlgorithmException, InvalidKeyException {
|
||||||
|
// 获取签名
|
||||||
|
String method ="GET";
|
||||||
|
String path = uri;
|
||||||
|
String queryStr = queryString;
|
||||||
|
Map<String, String> header = new HashMap<>();
|
||||||
|
String timestamp = HmacSignUtil.getSecondTimestamp(new Date());
|
||||||
|
queryStr += "×tamp=" + timestamp;
|
||||||
|
String sign = HmacSignUtil.getSign(secret,method,path,queryStr,header);
|
||||||
|
String url = host;
|
||||||
|
url += path + "?";
|
||||||
|
url += queryStr;
|
||||||
|
url += "&sign=" + sign;
|
||||||
|
Map<String, String> headerMap = new HashMap<>();
|
||||||
|
String response = HttpRequestUtil.getResponseOfGET(url, headerMap);
|
||||||
|
JSONObject myJson = JSONObject.parseObject(response);
|
||||||
|
|
||||||
|
return myJson.toJSONString();
|
||||||
|
// log.debug(myJson.toJSONString());
|
||||||
|
// if(!myJson.get("result_code").toString().equals("success")) {
|
||||||
|
// log.error("请求出现异常:" + myJson.get("result_code") + " " + myJson);
|
||||||
|
// }
|
||||||
|
// log.debug("打印输出本次同步信息返回结果:"+myJson.get("data").toString());
|
||||||
|
// return myJson.get("data").toString();
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException, NoSuchAlgorithmException, InvalidKeyException {
|
public static void main(String[] args) throws IOException, NoSuchAlgorithmException, InvalidKeyException {
|
||||||
|
|
||||||
|
String path = "/people/v1/employee/all-info";
|
||||||
|
// String path = "/people/v1/base/department/list";
|
||||||
|
// String queryStr = "app_id=100679&hash_type=sha256&employee_id=10438,22705,27785,28617,28617,45143";
|
||||||
|
// String queryStr = "app_id=100679&hash_type=sha256&worker_user_id=ning.chen,shanshan.su,frank.qiang,huaming.liu,charles.wang,songran.liu";
|
||||||
|
String queryStr = "app_id=100679&hash_type=sha256&worker_user_id=abin.ban1";
|
||||||
|
|
||||||
|
String response = getResultDataOfGetTest(path, queryStr);
|
||||||
|
// JSONObject myJson = JSONObject.parseObject(response);
|
||||||
|
// JSONObject resultJson = (JSONObject) myJson.get("data");
|
||||||
|
//将第一页的账户信息转换为本地dto集合
|
||||||
|
// List<JSONObject> userList = JSONObject.parseArray(resultJson.get("list").toString(), JSONObject.class);
|
||||||
|
// List<PPEmployee> ppEmployeeList = getPPEmployeeList(userList);
|
||||||
|
System.out.println("ok");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步组织信息
|
* 同步组织信息
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
@@ -70,7 +343,7 @@ public class SyncDataServiceImpl implements ISyncDataService{
|
|||||||
//查询所有组织列表,children为空
|
//查询所有组织列表,children为空
|
||||||
String path = "/people/v1/organization/list";
|
String path = "/people/v1/organization/list";
|
||||||
String queryStr = "app_id=100679&hash_type=sha256";
|
String queryStr = "app_id=100679&hash_type=sha256";
|
||||||
String resultData = getResultDataOfGet(path, queryStr);
|
String resultData = getResultDataOfGetTest(path, queryStr);
|
||||||
//JSON转实体类
|
//JSON转实体类
|
||||||
List<PPOrganization> organizationList = JSONArray.parseArray(resultData, PPOrganization.class);
|
List<PPOrganization> organizationList = JSONArray.parseArray(resultData, PPOrganization.class);
|
||||||
log.info("需要同步的组织数据总数:" + organizationList.size());
|
log.info("需要同步的组织数据总数:" + organizationList.size());
|
||||||
@@ -146,7 +419,7 @@ public class SyncDataServiceImpl implements ISyncDataService{
|
|||||||
//查询所有角色列表,非树状,children为空
|
//查询所有角色列表,非树状,children为空
|
||||||
String path = "/people/v1/position/list";
|
String path = "/people/v1/position/list";
|
||||||
String queryStr = "app_id=100679&hash_type=sha256";
|
String queryStr = "app_id=100679&hash_type=sha256";
|
||||||
String resultData = getResultDataOfGet(path, queryStr);
|
String resultData = getResultDataOfGetTest(path, queryStr);
|
||||||
//JSON转实体类
|
//JSON转实体类
|
||||||
List<PPPosition> positionList = JSONArray.parseArray(resultData, PPPosition.class);
|
List<PPPosition> positionList = JSONArray.parseArray(resultData, PPPosition.class);
|
||||||
List<String> positionCodeList = positionList.stream().map(PPPosition :: getCode).collect(Collectors.toList());
|
List<String> positionCodeList = positionList.stream().map(PPPosition :: getCode).collect(Collectors.toList());
|
||||||
@@ -155,7 +428,7 @@ public class SyncDataServiceImpl implements ISyncDataService{
|
|||||||
log.info("需要同步的岗位数据总数:" + positionList.size());
|
log.info("需要同步的岗位数据总数:" + positionList.size());
|
||||||
for(String code : positionCodeList){
|
for(String code : positionCodeList){
|
||||||
String queryStrDetail = positionDetailQueryStr + code;
|
String queryStrDetail = positionDetailQueryStr + code;
|
||||||
String result = getResultDataOfGet(positionDetailPath, queryStrDetail);
|
String result = getResultDataOfGetTest(positionDetailPath, queryStrDetail);
|
||||||
PPPosition position = JSONObject.parseObject(result, PPPosition.class);
|
PPPosition position = JSONObject.parseObject(result, PPPosition.class);
|
||||||
SysRole sysRole = new SysRole();
|
SysRole sysRole = new SysRole();
|
||||||
sysRole.setId(position.getId());
|
sysRole.setId(position.getId());
|
||||||
@@ -181,7 +454,7 @@ public class SyncDataServiceImpl implements ISyncDataService{
|
|||||||
public void syncDepartRoleInfo() throws IOException, NoSuchAlgorithmException, InvalidKeyException {
|
public void syncDepartRoleInfo() throws IOException, NoSuchAlgorithmException, InvalidKeyException {
|
||||||
String path = "/people/v1/organization-position/all";
|
String path = "/people/v1/organization-position/all";
|
||||||
String queryStr = "app_id=100679&hash_type=sha256";
|
String queryStr = "app_id=100679&hash_type=sha256";
|
||||||
String resultData = getResultDataOfGet(path, queryStr);
|
String resultData = getResultDataOfGetTest(path, queryStr);
|
||||||
//JSON转实体类
|
//JSON转实体类
|
||||||
List<PPOrganizationPosition> organizationPositionList = JSONArray.parseArray(resultData, PPOrganizationPosition.class);
|
List<PPOrganizationPosition> organizationPositionList = JSONArray.parseArray(resultData, PPOrganizationPosition.class);
|
||||||
log.info("需要同步的组织岗位关系数据总数:" + organizationPositionList.size());
|
log.info("需要同步的组织岗位关系数据总数:" + organizationPositionList.size());
|
||||||
@@ -211,7 +484,7 @@ public class SyncDataServiceImpl implements ISyncDataService{
|
|||||||
//查询所有人员组织岗位
|
//查询所有人员组织岗位
|
||||||
String path = "/people/v1/employee/organization-position/list";
|
String path = "/people/v1/employee/organization-position/list";
|
||||||
String queryStr = "app_id=100679&hash_type=sha256";
|
String queryStr = "app_id=100679&hash_type=sha256";
|
||||||
String resultData = getResultDataOfGet(path, queryStr);
|
String resultData = getResultDataOfGetTest(path, queryStr);
|
||||||
//JSON转实体类
|
//JSON转实体类
|
||||||
List<PPOrgPosEmployee> orgPosEmployeeList = JSONArray.parseArray(resultData, PPOrgPosEmployee.class);
|
List<PPOrgPosEmployee> orgPosEmployeeList = JSONArray.parseArray(resultData, PPOrgPosEmployee.class);
|
||||||
log.info("需要同步的组织岗位人员关系数据总数:" + orgPosEmployeeList.size());
|
log.info("需要同步的组织岗位人员关系数据总数:" + orgPosEmployeeList.size());
|
||||||
@@ -220,7 +493,7 @@ public class SyncDataServiceImpl implements ISyncDataService{
|
|||||||
for(PPOrgPosEmployee ope : orgPosEmployeeList){
|
for(PPOrgPosEmployee ope : orgPosEmployeeList){
|
||||||
//查询人员详情
|
//查询人员详情
|
||||||
String queryStrDetail = employeeDetailQueryStr + ope.getEmployee_id();
|
String queryStrDetail = employeeDetailQueryStr + ope.getEmployee_id();
|
||||||
String result = getResultDataOfGet(employeeDetailPath, queryStrDetail);
|
String result = getResultDataOfGetTest(employeeDetailPath, queryStrDetail);
|
||||||
//JSON转实体类
|
//JSON转实体类
|
||||||
PPEmployee employee = JSONObject.parseObject(result, PPEmployee.class);
|
PPEmployee employee = JSONObject.parseObject(result, PPEmployee.class);
|
||||||
//判断用户信息是否已添加,人员-组织岗位关系为多对多
|
//判断用户信息是否已添加,人员-组织岗位关系为多对多
|
||||||
@@ -273,7 +546,7 @@ public class SyncDataServiceImpl implements ISyncDataService{
|
|||||||
* @throws NoSuchAlgorithmException
|
* @throws NoSuchAlgorithmException
|
||||||
* @throws InvalidKeyException
|
* @throws InvalidKeyException
|
||||||
*/
|
*/
|
||||||
public String getResultDataOfGet(String uri, String queryString) throws IOException, NoSuchAlgorithmException, InvalidKeyException {
|
public static String getResultDataOfGetTest(String uri, String queryString) throws IOException, NoSuchAlgorithmException, InvalidKeyException {
|
||||||
String appId = "100679";
|
String appId = "100679";
|
||||||
// String appSecret = "CDf2D9404C6ac1B0f7c3e3845ae0282a";
|
// String appSecret = "CDf2D9404C6ac1B0f7c3e3845ae0282a";
|
||||||
String appSecret = "7C3F03170E3ea489df04Ce8DEC7Df4f7";
|
String appSecret = "7C3F03170E3ea489df04Ce8DEC7Df4f7";
|
||||||
@@ -290,15 +563,17 @@ public class SyncDataServiceImpl implements ISyncDataService{
|
|||||||
url += path + "?";
|
url += path + "?";
|
||||||
url += queryStr;
|
url += queryStr;
|
||||||
url += "&sign=" + sign;
|
url += "&sign=" + sign;
|
||||||
|
System.out.println(url);
|
||||||
Map<String, String> headerMap = new HashMap<>();
|
Map<String, String> headerMap = new HashMap<>();
|
||||||
String response = HttpRequestUtil.getResponseOfGET(url, headerMap);
|
String response = HttpRequestUtil.getResponseOfGET(url, headerMap);
|
||||||
JSONObject myJson = JSONObject.parseObject(response);
|
JSONObject myJson = JSONObject.parseObject(response);
|
||||||
|
|
||||||
log.debug(myJson.toJSONString());
|
return myJson.toJSONString();
|
||||||
if(!myJson.get("result_code").toString().equals("success")) {
|
// log.debug(myJson.toJSONString());
|
||||||
log.error("请求出现异常:" + myJson.get("result_code") + " " + myJson);
|
// if(!myJson.get("result_code").toString().equals("success")) {
|
||||||
}
|
// log.error("请求出现异常:" + myJson.get("result_code") + " " + myJson);
|
||||||
log.debug("打印输出本次同步信息返回结果:"+myJson.get("data").toString());
|
// }
|
||||||
return myJson.get("data").toString();
|
// log.debug("打印输出本次同步信息返回结果:"+myJson.get("data").toString());
|
||||||
|
// return myJson.get("data").toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -571,8 +571,7 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
|
|||||||
@Override
|
@Override
|
||||||
public List<SysDepart> getPPDepartList() {
|
public List<SysDepart> getPPDepartList() {
|
||||||
LambdaQueryWrapper<SysDepart> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysDepart> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.eq(SysDepart::getDepartSource, PPSyncEnum.PP.getValue())
|
queryWrapper.eq(SysDepart::getDepartSource, PPSyncEnum.PP.getValue());
|
||||||
.eq(SysDepart::getDelFlag, 0);
|
|
||||||
return this.list(queryWrapper);
|
return this.list(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -612,8 +611,8 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePPDepart(PPDepartment ppDepartment) {
|
public void updatePPDepart(SysDepart sysDepart, PPDepartment ppDepartment) {
|
||||||
SysDepart updateDepart = getById(ppDepartment.getRef_id());
|
SysDepart updateDepart = sysDepart;
|
||||||
|
|
||||||
updateDepart.setDepartNameEn(ppDepartment.getName_en());
|
updateDepart.setDepartNameEn(ppDepartment.getName_en());
|
||||||
updateDepart.setDepartName(ppDepartment.getName_cn());
|
updateDepart.setDepartName(ppDepartment.getName_cn());
|
||||||
|
|||||||
+89
@@ -17,12 +17,14 @@ import com.jero.common.util.UUIDGenerator;
|
|||||||
import com.jero.common.util.oConvertUtils;
|
import com.jero.common.util.oConvertUtils;
|
||||||
import com.jero.modules.base.service.BaseCommonService;
|
import com.jero.modules.base.service.BaseCommonService;
|
||||||
import com.jero.modules.system.entity.*;
|
import com.jero.modules.system.entity.*;
|
||||||
|
import com.jero.modules.system.enums.PPSyncEnum;
|
||||||
import com.jero.modules.system.mapper.*;
|
import com.jero.modules.system.mapper.*;
|
||||||
import com.jero.modules.system.model.DepartIdModel;
|
import com.jero.modules.system.model.DepartIdModel;
|
||||||
import com.jero.modules.system.model.SysUserSysDepartModel;
|
import com.jero.modules.system.model.SysUserSysDepartModel;
|
||||||
import com.jero.modules.system.service.ISysUserService;
|
import com.jero.modules.system.service.ISysUserService;
|
||||||
import com.jero.modules.system.vo.SysUserDepVo;
|
import com.jero.modules.system.vo.SysUserDepVo;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -474,4 +476,91 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||||||
List<SysUser> sysUsers = this.baseMapper.selectList(sysUserQueryWrapper);
|
List<SysUser> sysUsers = this.baseMapper.selectList(sysUserQueryWrapper);
|
||||||
return sysUsers;
|
return sysUsers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysUser> getPPEmployeeList() {
|
||||||
|
QueryWrapper<SysUser> sysUserQueryWrapper = new QueryWrapper<>();
|
||||||
|
sysUserQueryWrapper.lambda().eq(SysUser::getThirdType, PPSyncEnum.PP.getValue());
|
||||||
|
return list(sysUserQueryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SysUser addPPUserInfo(PPEmployee ppEmployee) {
|
||||||
|
|
||||||
|
SysUser sysUser = new SysUser();
|
||||||
|
// 基本信息
|
||||||
|
sysUser.setId(ppEmployee.getId());
|
||||||
|
sysUser.setUsername(ppEmployee.getUser_name());
|
||||||
|
sysUser.setRealname(ppEmployee.getFormatted_name());
|
||||||
|
sysUser.setStatus("Active".equals(ppEmployee.getEmployee_status())? CommonConstant.USER_UNFREEZE : CommonConstant.USER_FREEZE);
|
||||||
|
sysUser.setDelFlag("1".equals(ppEmployee.getDelete_flag())? CommonConstant.DEL_FLAG_0 : CommonConstant.DEL_FLAG_1);
|
||||||
|
sysUser.setThirdId(ppEmployee.getWorker_user_id());
|
||||||
|
sysUser.setActivitiSync(CommonConstant.ACT_SYNC_1);
|
||||||
|
sysUser.setWorkNo(ppEmployee.getEmployee_id());
|
||||||
|
sysUser.setWorkerType("Employee".equals(ppEmployee.getWorker_type())? CommonConstant.WORKER_TYPE_1 : CommonConstant.WORKER_TYPE_2);
|
||||||
|
sysUser.setCreateTime(ppEmployee.getCreation_time());
|
||||||
|
sysUser.setUpdateTime(ppEmployee.getUpdate_time());
|
||||||
|
sysUser.setThirdType(PPSyncEnum.PP.getValue());
|
||||||
|
// 工作信息
|
||||||
|
sysUser.setJobCode(ppEmployee.getJob_code());
|
||||||
|
sysUser.setJobTitle(ppEmployee.getJob_title());
|
||||||
|
sysUser.setOrgCode(ppEmployee.getSupervisory_organization_ref_id());
|
||||||
|
// 联系方式
|
||||||
|
sysUser.setEmail(ppEmployee.getEmail_address());
|
||||||
|
sysUser.setTelephone(ppEmployee.getFormatted_phone_number());
|
||||||
|
|
||||||
|
// 设置用户默认密码
|
||||||
|
String username = ppEmployee.getUser_name();
|
||||||
|
String password = "nio.com123"; // 设置默认密码
|
||||||
|
String salt = oConvertUtils.randomGen(8);
|
||||||
|
String passwordEncode = PasswordUtil.encrypt(username, password, salt);
|
||||||
|
sysUser.setPassword(passwordEncode);
|
||||||
|
sysUser.setSalt(salt);
|
||||||
|
|
||||||
|
// 添加用户部门关系
|
||||||
|
SysUserDepart sysUserDepart = new SysUserDepart(ppEmployee.getId(), ppEmployee.getSupervisory_organization_ref_id());
|
||||||
|
sysUserDepartMapper.insert(sysUserDepart);
|
||||||
|
// 添加用户信息
|
||||||
|
save(sysUser);
|
||||||
|
return sysUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePPUserInfo(SysUser sysUser, PPEmployee ppEmployee) {
|
||||||
|
|
||||||
|
// 基本信息
|
||||||
|
sysUser.setUsername(ppEmployee.getUser_name());
|
||||||
|
sysUser.setRealname(ppEmployee.getFormatted_name());
|
||||||
|
sysUser.setStatus("Active".equals(ppEmployee.getEmployee_status())? CommonConstant.USER_UNFREEZE : CommonConstant.USER_FREEZE);
|
||||||
|
sysUser.setDelFlag("1".equals(ppEmployee.getDelete_flag())? CommonConstant.DEL_FLAG_0 : CommonConstant.DEL_FLAG_1);
|
||||||
|
sysUser.setThirdId(ppEmployee.getWorker_user_id());
|
||||||
|
sysUser.setWorkNo(ppEmployee.getEmployee_id());
|
||||||
|
sysUser.setWorkerType("Employee".equals(ppEmployee.getWorker_type())? CommonConstant.WORKER_TYPE_1 : CommonConstant.WORKER_TYPE_2);
|
||||||
|
sysUser.setCreateTime(ppEmployee.getCreation_time());
|
||||||
|
sysUser.setUpdateTime(ppEmployee.getUpdate_time());
|
||||||
|
|
||||||
|
// 工作信息
|
||||||
|
sysUser.setJobCode(ppEmployee.getJob_code());
|
||||||
|
sysUser.setJobTitle(ppEmployee.getJob_title());
|
||||||
|
sysUser.setOrgCode(ppEmployee.getSupervisory_organization_ref_id());
|
||||||
|
// 联系方式
|
||||||
|
sysUser.setEmail(ppEmployee.getEmail_address());
|
||||||
|
sysUser.setTelephone(ppEmployee.getFormatted_phone_number());
|
||||||
|
|
||||||
|
if (!StringUtils.equals(sysUser.getOrgCode(), ppEmployee.getSupervisory_organization_ref_id())) {
|
||||||
|
// 删除原用户部门关系
|
||||||
|
QueryWrapper<SysUserDepart> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.lambda().eq(SysUserDepart::getUserId, sysUser.getId()).eq(SysUserDepart::getDepId,sysUser.getOrgCode());
|
||||||
|
sysUserDepartMapper.delete(queryWrapper);
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(ppEmployee.getSupervisory_organization_ref_id())) {
|
||||||
|
// 添加用户部门关系
|
||||||
|
SysUserDepart sysUserDepart = new SysUserDepart(ppEmployee.getId(), ppEmployee.getSupervisory_organization_ref_id());
|
||||||
|
sysUserDepartMapper.insert(sysUserDepart);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateById(sysUser);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+72
@@ -0,0 +1,72 @@
|
|||||||
|
package com.jero.modules.system.timer;
|
||||||
|
|
||||||
|
import com.jero.modules.system.entity.OtSyncInfoEO;
|
||||||
|
import com.jero.modules.system.service.ISyncDataService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时同步SSO数据至本地
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@EnableScheduling
|
||||||
|
@Slf4j
|
||||||
|
public class PPSyncDataTimer {
|
||||||
|
|
||||||
|
@Value("${people.cronJobIsOpen}")
|
||||||
|
private Boolean isOpen;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISyncDataService syncDataService;
|
||||||
|
|
||||||
|
// @Scheduled(cron = "0 10 0 * * ?") //每天凌晨0点10分执行
|
||||||
|
public void syncDepartInfo() {
|
||||||
|
if (isOpen) {
|
||||||
|
log.info("<======================================启动同步部门信息======================================>");
|
||||||
|
try {
|
||||||
|
log.info("=========================================开始同步部门信息=========================================");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
syncDataService.synchronPPDepartInfo();
|
||||||
|
long endTime = System.currentTimeMillis();
|
||||||
|
log.info("==============同步部门信息结束,同步共用时:"+((endTime-startTime)/1000)+" 秒========================");
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("同步部门信息出现异常,异常信息为:" + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
log.info("<======================================结束同步部门信息=======================================>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Scheduled(cron = "0 10 1 * * ?") //每天凌晨1点10分执行
|
||||||
|
public void syncUserInfo() {
|
||||||
|
log.info("<======================================启动同步用户信息=======================================>");
|
||||||
|
if (isOpen) {
|
||||||
|
try {
|
||||||
|
log.info("=========================================开始同步用户信息=========================================");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
syncDataService.synchronPPUserInfo();
|
||||||
|
long endTime = System.currentTimeMillis();
|
||||||
|
log.info("==============同步用户信息结束,同步共用时:"+((endTime-startTime)/1000)+" 秒========================");
|
||||||
|
|
||||||
|
//删除重复的用户数据
|
||||||
|
/*List<String> repeatUserIdList = userEOService.selectRepeatUserIdList();
|
||||||
|
if(CollectionUtils.isNotEmpty(repeatUserIdList)) {
|
||||||
|
userEOService.delete(repeatUserIdList);
|
||||||
|
}*/
|
||||||
|
} catch (Exception accountException) {
|
||||||
|
log.error("同步用户信息出现异常,异常信息为:" + accountException.getMessage(), accountException);
|
||||||
|
}
|
||||||
|
log.info("<======================================结束同步用户信息=======================================>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -380,14 +380,15 @@ feign:
|
|||||||
people:
|
people:
|
||||||
appId: 100679
|
appId: 100679
|
||||||
# 访问域名 CN TEST版
|
# 访问域名 CN TEST版
|
||||||
host: http://napoleon-fab-test.nioint.com
|
# host: http://napoleon-fab-test.nioint.com
|
||||||
# 访问域名 CN PROD版
|
# 访问域名 CN PROD版
|
||||||
# host: http://napoleon.nioint.com
|
host: http://napoleon.nioint.com
|
||||||
|
|
||||||
# appSecret CN TEST版
|
# appSecret CN TEST版
|
||||||
secret: CDf2D9404C6ac1B0f7c3e3845ae0282a
|
# secret: CDf2D9404C6ac1B0f7c3e3845ae0282a
|
||||||
# appSecret CN PROD版
|
# appSecret CN PROD版
|
||||||
# secret: 7C3F03170E3ea489df04Ce8DEC7Df4f7
|
secret: 7C3F03170E3ea489df04Ce8DEC7Df4f7
|
||||||
|
cronJobIsOpen: true
|
||||||
## Feishu
|
## Feishu
|
||||||
Feishu:
|
Feishu:
|
||||||
# 测试
|
# 测试
|
||||||
@@ -409,7 +410,6 @@ opensso:
|
|||||||
clientSecret: CDf2D9404C6ac1B0f7c3e3845ae0282a
|
clientSecret: CDf2D9404C6ac1B0f7c3e3845ae0282a
|
||||||
redirectUri: http%3A%2F%2F139.9.235.66%3A8010
|
redirectUri: http%3A%2F%2F139.9.235.66%3A8010
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
## space系统
|
## space系统
|
||||||
Space:
|
Space:
|
||||||
|
|||||||
Reference in New Issue
Block a user