Commit c7a4184c by zhoupeng

提交导入组织架构openapi接口

parent 01502fdc
package com.rome.order.api.controller;
import com.rome.arch.core.clientobject.Response;
import com.rome.order.domain.service.SyncEmployeCdpService;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Author: zhoupeng
* @createTime: 2023年08月29日 11:13:23
* @version: 1.0
* @Description:
* @copyright:
*/
@Slf4j
@RestController
@Api(value = "新Cdp同步员工(基础信息)", tags = "新Cdp同步员工(基础信息)")
@RequestMapping(value = "/api/synEmp")
public class SyncEmployeCdpController {
@Autowired
private SyncEmployeCdpService syncEmployeCdpService;
@PostMapping("/synAllEmpCdpBase")
@ApiOperation(value = "新Cdp同步查询员工(基础信息)")
public Response<Boolean> synAllEmpCdpBase(Integer pageNum) {
return Response.builderSuccess(syncEmployeCdpService.synAllEmpCdpBase(pageNum));
}
}
......@@ -12,4 +12,11 @@ public class RedisConstant {
*/
public static String QIDIAN_TENCENT_ACCESS_TOKEN = "qidian_tencent_access_token";
/**
* 组织架构
*/
public static final String DEPARTMENT_ORGANIZATION ="beidou_cdp_department_organization";
}
package com.rome.order.domain.service;
import com.rome.order.infrastructure.remote.dto.res.OrgDTO;
import java.util.List;
/**
* @Author: zhoupeng
* @createTime: 2023年08月29日 17:31:40
* @version: 1.0
* @Description:
* @copyright:
*/
public interface OrganizationRedisService {
/**
* 批量添加组织机构信息并进行缓存
*
* @return
*/
Boolean synAllOrgRedis();
/**
* 从redis中获取组织机构
* @return
*/
List<OrgDTO> getAllOrgRedis();
}
package com.rome.order.domain.service;
/**
* @Author: zhoupeng
* @createTime: 2023年08月29日 11:16:36
* @version: 1.0
* @Description:
* @copyright:
*/
public interface SyncEmployeCdpService {
/**
* 同步查询员工(基础信息) -(工单系统等)
*/
Boolean synAllEmpCdpBase(Integer pageNum);
}
package com.rome.order.domain.service.impl;
import com.alibaba.fastjson.JSON;
import com.rome.order.domain.constant.BaseConstant;
import com.rome.order.domain.constant.RedisConstant;
import com.rome.order.domain.service.OrganizationRedisService;
import com.rome.order.domain.util.PageInfo;
import com.rome.order.domain.util.RedisService;
import com.rome.order.infrastructure.remote.dto.res.OrgDTO;
import com.rome.order.infrastructure.remote.facade.OrganizationFacade;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* @Author: zhoupeng
* @createTime: 2023年08月29日 17:32:32
* @version: 1.0
* @Description:
* @copyright:
*/
@Service
@Slf4j
public class OrganizationRedisServiceImpl implements OrganizationRedisService {
@Autowired
private RedisService redisService;
@Resource
private OrganizationFacade organizationFacade;
@Override
public Boolean synAllOrgRedis() {
Object object = redisService.getValue(RedisConstant.DEPARTMENT_ORGANIZATION);
if(object!=null){
//先从redis进行删除
redisService.delete(RedisConstant.DEPARTMENT_ORGANIZATION);
}
List<OrgDTO> orgDTOList = this.getRemoteOrgCdpList();
if(!CollectionUtils.isEmpty(orgDTOList)){
// 组织机构存缓存(1天)
redisService.setValue(RedisConstant.DEPARTMENT_ORGANIZATION, JSON.toJSONString(orgDTOList),86400L);
}
return true;
}
@Override
public List<OrgDTO> getAllOrgRedis() {
List<OrgDTO> organizationRedisDTOS = new ArrayList<>();
Object cacheObject = redisService.getValue(RedisConstant.DEPARTMENT_ORGANIZATION);
if (Objects.nonNull(cacheObject)) {
organizationRedisDTOS = JSON.parseArray(cacheObject.toString(), OrgDTO.class);
}else{
organizationRedisDTOS = this.getRemoteOrgCdpList();
if(!CollectionUtils.isEmpty(organizationRedisDTOS)){
// 组织机构存缓存(1天)
redisService.setValue(RedisConstant.DEPARTMENT_ORGANIZATION, JSON.toJSONString(organizationRedisDTOS),86400L);
}
return organizationRedisDTOS;
}
return organizationRedisDTOS;
}
/**
* 远程-获取到所有组织架构信息
*/
public List<OrgDTO> getRemoteOrgCdpList() {
// 分页获取全量数据
int pageNum = BaseConstant.ONE;
int pageSize = BaseConstant.PAGE_SIZE;
List<OrgDTO> allList = new ArrayList<>();
log.info("------synAllOrg()------getRemoteOrgList全量同步开始-------");
while (true) {
PageInfo<OrgDTO> pageList = organizationFacade.getOrgPageList(pageNum, pageSize);
if (pageList == null) {
log.info("------synAllOrg()----getRemoteOrgList全量同步结束-------");
break;
}
List<OrgDTO> orgList = pageList.getList();
if (CollectionUtils.isEmpty(orgList)) {
log.info("-----synAllOrg()------getRemoteOrgList全量同步结束-------");
break;
} else {
// 处理同步的公司信息
allList.addAll(orgList);
if (orgList.size() < pageSize) {
log.info("-------synAllOrg()-------getRemoteOrgList全量同步结束-------");
break;
}
}
pageNum++;
}
return allList;
}
}
......@@ -61,6 +61,26 @@ public class HttpUtil {
}
}
public static String httpPost(String url, String jsonStr,Map<String, String> headers) {
try {
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader(HTTP.CONTENT_TYPE, CONTENT_TYPE_VAL);
for (String key : headers.keySet()) {
httpPost.setHeader(key, headers.get(key));
}
StringEntity stringEntity = new StringEntity(jsonStr, UTF_8);
httpPost.setEntity(stringEntity);
HttpResponse response = httpClient.execute(httpPost);
return EntityUtils.toString(response.getEntity());
} catch (Exception e) {
log.error("http POST请求异常:", e);
throw new TradeException(RomeExceptionEnum.HTTP_ERROR);
}
}
public static String httpPost(String url) {
try {
HttpClient httpClient = HttpClientBuilder.create().build();
......
package com.rome.order.infrastructure.dataobject;
import lombok.Data;
import java.util.Date;
/**
* @Author: zhoupeng
* @createTime: 2023年08月29日 10:38:02
* @version: 1.0
* @Description: 新的同步员工基础信息
* @copyright:
*/
@Data
public class SyncEmployeeCdpDO {
/**
* 主键id
*/
private Long id;
/**
* 同步来伊份用户id
*/
private Long userId;
/**
* 员工状态字段
*/
private String erPersonStatus;
/**
* 员工工号
*/
private String employeeNumber;
/**
* 员工类型
*/
private String employeeType;
/**
* 员工姓名
*/
private String name;
/**
* 性别:1-男,2-女
*/
private Integer gender;
/**
* 部门编码
*/
private String departmentCode;
/**
* 部门名称
*/
private String departmentName;
/**
* 手机号
*/
private String mobile;
/**
* 电话号
*/
private String phone;
/**
* 公司编码
*/
private String companyCode;
/**
* 公司名称
*/
private String companyName;
/**
* 公司邮箱
*/
private String companyEmail;
/**
* 是否同步创建员工 0-失败 1-成功
*/
private Integer isSyncEmployee;
/**
* 是否停用员工 0-企点正常激活 1-企点停用
*/
private Integer isDisable;
/**
* 错误信息
*/
private String errorMsg;
/**
* 创建人
*/
private Integer creator;
/**
* 创建人名称
*/
private String creatorName;
/**
* 修改时间
*/
private Date updateTime;
/**
* 修改人
*/
private Integer updater;
/**
* 修改人名称
*/
private String updaterName;
/**
* 删除标记 0-否 1是
*/
private Integer isDelete;
/**
* 重试次数(最多重试3次)
*/
private Integer resentNumber;
}
package com.rome.order.infrastructure.mapper;
import com.rome.order.infrastructure.dataobject.SyncEmployeeCdpDO;
import com.rome.order.infrastructure.remote.dto.res.EmpMainDataResDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @Author: zhoupeng
* @createTime: 2023年08月29日 11:18:25
* @version: 1.0
* @Description:
* @copyright:
*/
@Mapper
public interface SyncEmployeeCdpMapper {
/**
* 批量添加同步员工信息
*
* @return
*/
int batchSaveEmpCdp(@Param("empList") List<EmpMainDataResDTO> empList);
/**
* 根据同步的员工号获取员工信息
*
* @param userIds
* @return
*/
List<SyncEmployeeCdpDO> findEmployeeCdpListByUserIds(@Param("userIds") List<Long> userIds);
}
package com.rome.order.infrastructure.remote.constant;
/**
* @Author: zhoupeng
* @createTime: 2023年08月29日 16:04:12
* @version: 1.0
* @Description:
* @copyright:
*/
public class QiDianOpenApiRemoteConstant {
/**
* 导入组织架构openapi接口
*/
public static String ORG_SYNC_URL = "/api/dataauth/authserver/openapi/org/sync";
}
......@@ -149,4 +149,10 @@ public class RemoteConstant {
* 为空
*/
public static final String EMP = "";
/*
1-表示成功
*/
public static final String CODE="1";
}
package com.rome.order.infrastructure.remote.dto.req;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @Author: zhoupeng
* @createTime: 2023年08月29日 16:15:32
* @version: 1.0
* @Description:
* @copyright:
*/
@Data
public class EmpMainStaffsReqDTO {
@ApiModelProperty(value = "用户id")
private String accountId;
@ApiModelProperty(value = "用户名称")
private String accountName;
@ApiModelProperty(value = "部门名称")
private String fullDeptName;
@ApiModelProperty(value = "邮件")
private String email;
private String avatar;
}
......@@ -115,7 +115,7 @@ public class EmpMainDataResDTO {
private String staffType;
@ApiModelProperty(value = "用户id(B端)")
private Integer userId;
private Long userId;
@ApiModelProperty(value = "是否同步创建员工 0-失败 1-成功")
......@@ -154,4 +154,5 @@ public class EmpMainDataResDTO {
private Integer isDisable;
}
<?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.rome.order.infrastructure.mapper.SyncEmployeeCdpMapper">
<!-- 批量添加同步员工信息 -->
<insert id="batchSaveEmpCdp">
insert into sync_employee_cdp(
`user_id`,
`er_person_status`,
`employee_number`,
`employee_type`,
`name`,
`gender`,
`department_code`,
`department_name`,
`mobile`,
`phone`,
`company_code`,
`company_name`,
`company_email`,
`is_sync_employee`,
`is_disable`,
`error_msg`,
`creator`,
`creator_name`,
`updator`,
`updator_name`
) values
<foreach collection="empList" item="item" index="index" separator=",">
(
#{item.userId},
#{item.erPersonStatus},
#{item.employeeNumber},
#{item.employeeType},
#{item.name},
#{item.gender},
#{item.departmentCode},
#{item.departmentName},
#{item.mobile},
#{item.phone},
#{item.companyCode},
#{item.companyName},
#{item.companyEmail},
#{item.isSyncEmployee},
#{item.isDisable},
#{item.errorMsg},
#{item.creator},
#{item.creatorName},
#{item.updator},
#{item.updatorName}
)
</foreach>
</insert>
<!-- 根据同步的员工号获取员工信息 -->
<select id="findEmployeeCdpListByUserIds" parameterType="java.util.List" resultType="com.rome.order.infrastructure.dataobject.SyncEmployeeCdpDO">
SELECT
se.id,
se.user_id,
se.er_person_status,
se.employee_number,
se.employee_type,
se.name,
se.gender,
se.department_code,
se.department_name,
se.mobile,
se.phone,
se.company_code,
se.company_name,
se.company_email,
se.is_sync_employee,
se.is_disable,
se.is_sync_employee,
se.is_disable,
se.creator,
se.creator_name,
se.updator,
se.updator_name,
se.create_time,
se.update_time
FROM sync_employee_cdp se
where se.is_delete = 0
<if test="userIds != null and userIds.size() ">
and se.user_id in
<foreach collection="userIds" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment