[+]增加部门推动消息功能

This commit is contained in:
maimaishu
2026-01-02 17:27:53 +08:00
parent 7bd44ffca9
commit 2e761d1867
8 changed files with 62 additions and 165 deletions

View File

@@ -1,18 +1,15 @@
package com.zt.plat.module.system.api.esp;
import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.framework.common.util.collection.CollectionUtils;
import com.zt.plat.module.system.api.dept.dto.*;
import com.zt.plat.module.system.api.esp.dto.EspDto;
import com.zt.plat.module.system.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
@FeignClient(name = ApiConstants.NAME)
@Tag(name = "RPC 服务 - 部门")
@@ -20,75 +17,8 @@ public interface EspApi {
String PREFIX = ApiConstants.PREFIX + "/dept";
// === 以下为补全的接口方法 ===
@PostMapping(PREFIX + "/create")
@Operation(summary = "新增部门")
CommonResult<Long> createDept(@RequestBody DeptSaveReqDTO createReqVO);
@PutMapping(PREFIX + "/update")
@Operation(summary = "修改部门")
CommonResult<Boolean> updateDept(@RequestBody DeptSaveReqDTO updateReqVO);
@DeleteMapping(PREFIX + "/delete")
@Operation(summary = "删除部门")
CommonResult<Boolean> deleteDept(@RequestParam("id") Long id);
@PostMapping(PREFIX + "/list-all")
@Operation(summary = "获得部门列表")
CommonResult<List<DeptDetailRespDTO>> getDeptList(@RequestBody DeptListReqDTO reqVO);
@GetMapping(PREFIX + "/simple-list")
@Operation(summary = "获得部门精简信息列表")
CommonResult<List<DeptSimpleRespDTO>> getSimpleDeptList();
@GetMapping(PREFIX + "/simple-company-list")
@Operation(summary = "获得公司精简信息列表")
CommonResult<List<DeptSimpleRespDTO>> getSimpleCompanyList();
@GetMapping(PREFIX + "/all-company-list")
@Operation(summary = "获得所有公司精简信息列表")
CommonResult<List<DeptSimpleRespDTO>> getAllCompanyList();
@GetMapping(PREFIX + "/get")
@Operation(summary = "获得部门信息")
@Parameter(name = "id", description = "部门编号", example = "1024", required = true)
CommonResult<DeptRespDTO> getDept(@RequestParam("id") Long id);
@GetMapping(PREFIX + "/list")
@Operation(summary = "获得部门信息数组")
@Parameter(name = "ids", description = "部门编号数组", example = "1,2", required = true)
CommonResult<List<DeptRespDTO>> getDeptList(@RequestParam("ids") Collection<Long> ids);
@GetMapping(PREFIX + "/valid")
@Operation(summary = "校验部门是否合法")
@Parameter(name = "ids", description = "部门编号数组", example = "1,2", required = true)
CommonResult<Boolean> validateDeptList(@RequestParam("ids") Collection<Long> ids);
/**
* 获得指定编号的部门 Map
*
* @param ids 部门编号数组
* @return 部门 Map
*/
default Map<Long, DeptRespDTO> getDeptMap(Collection<Long> ids) {
List<DeptRespDTO> list = getDeptList(ids).getCheckedData();
return CollectionUtils.convertMap(list, DeptRespDTO::getId);
}
@GetMapping(PREFIX + "/list-child")
@Operation(summary = "获得指定部门的所有子部门")
@Parameter(name = "id", description = "部门编号", example = "1024", required = true)
CommonResult<List<DeptRespDTO>> getChildDeptList(@RequestParam("id") Long id);
@GetMapping(PREFIX + "/company-dept-info")
@Operation(summary = "获得指定用户的公司部门信息")
@Parameter(name = "userId", description = "用户编号", example = "1", required = true)
CommonResult<Set<CompanyDeptInfoRespDTO>> getCompanyDeptInfoListByUserId(@RequestParam("userId") Long userId);
// ========== 数据同步专用接口 ==========
@PostMapping(PREFIX + "/sync")
@Operation(summary = "同步部门")
CommonResult<Boolean> syncDept(@RequestBody DeptSaveReqDTO syncReqDTO);
@PostMapping(PREFIX + "/pushMsg")
@Operation(summary = "推送消息")
CommonResult<List<EspDto>> pushMsg(@RequestBody DeptSaveReqDTO syncReqDTO);
}

View File

@@ -13,7 +13,6 @@ import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;

View File

@@ -0,0 +1,25 @@
package com.zt.plat.module.system.api.esp;
import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.module.system.api.dept.dto.DeptSaveReqDTO;
import com.zt.plat.module.system.api.esp.dto.EspDto;
import com.zt.plat.module.system.service.dept.IEspService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@Validated
public class EspApiImpl implements EspApi {
@Resource
private IEspService deptService;
@Override
public CommonResult<List<EspDto>> pushMsg(DeptSaveReqDTO syncReqDTO)
{
return CommonResult.success(deptService.pushMsg(syncReqDTO));
}
}

View File

@@ -25,4 +25,7 @@ public class EspSaveRespVo extends DeptExternalCodeBaseVO {
@Schema(description = "最后更新时间")
private LocalDateTime updateTime;
@Schema(description = "是否发送消息")
private Integer isSendMsg;
}

View File

@@ -55,4 +55,9 @@ public class DeptPushMsgDO extends TenantBaseDO {
*/
private String remark;
/**
* 是否发送消息
*/
private Integer isSendMsg;
}

View File

@@ -3,10 +3,12 @@ package com.zt.plat.module.system.dal.mysql.dept;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.module.system.api.dept.dto.DeptSaveReqDTO;
import com.zt.plat.module.system.controller.admin.dept.vo.depexternalcode.EspPageReqVO;
import com.zt.plat.module.system.controller.admin.dept.vo.depexternalcode.EspSaveRespVo;
import com.zt.plat.module.system.dal.dataobject.dept.DeptPushMsgDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* 部门推送消息接口Mapper
@@ -54,4 +56,10 @@ public interface EspMapper extends BaseMapperX<DeptPushMsgDO> {
return selectList(DeptPushMsgDO::getSystemCode, systemCode);
}
@Select("SELECT ID,DEPT_ID, SYSTEM_CODE,EXTERNAL_DEPT_CODE,EXTERNAL_DEPT_NAME,STATUS,REMARK,TENANT_ID,CREATOR,CREATE_TIME,UPDATER,UPDATE_TIME\n" +
"FROM \n" +
"\t\tSYSTEM_DEPT_PUSH_MSG\n" +
"WHERE\n" +
" IS_SEND_MSG = '0' AND DELETED = '0' ")
List<DeptPushMsgDO> selectpushMsg(@Param("syncReqDTO") DeptSaveReqDTO syncReqDTO);
}

View File

@@ -4,6 +4,8 @@ import cn.hutool.core.util.StrUtil;
import com.zt.plat.framework.common.enums.CommonStatusEnum;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.module.system.api.dept.dto.DeptSaveReqDTO;
import com.zt.plat.module.system.api.esp.dto.EspDto;
import com.zt.plat.module.system.controller.admin.dept.vo.depexternalcode.EspPageReqVO;
import com.zt.plat.module.system.controller.admin.dept.vo.depexternalcode.EspSaveRespVo;
import com.zt.plat.module.system.dal.dataobject.dept.DeptDO;
@@ -12,6 +14,8 @@ import com.zt.plat.module.system.dal.mysql.dept.DeptMapper;
import com.zt.plat.module.system.dal.mysql.dept.EspMapper;
import com.zt.plat.module.system.dal.redis.RedisKeyConstants;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.seata.common.result.Result;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
@@ -51,6 +55,7 @@ public class EspServiceImpl implements IEspService {
if (entity.getStatus() == null) {
entity.setStatus(CommonStatusEnum.ENABLE.getStatus());
}
entity.setIsSendMsg(0);
espMapper.insert(entity);
return entity.getId();
}
@@ -68,6 +73,7 @@ public class EspServiceImpl implements IEspService {
if (updateObj.getStatus() == null) {
updateObj.setStatus(exists.getStatus() == null ? CommonStatusEnum.ENABLE.getStatus() : exists.getStatus());
}
updateObj.setIsSendMsg(updateReqVO.getIsSendMsg());
espMapper.updateById(updateObj);
evictCacheSafely(exists.getDeptId());
evictCacheSafely(updateObj.getDeptId());
@@ -97,68 +103,11 @@ public class EspServiceImpl implements IEspService {
return espMapper.selectListByDeptId(deptId);
}
/* @Override
public DeptExternalCodeDO getBySystemCodeAndExternalCode(String systemCode, String externalDeptCode) {
if (StrUtil.hasEmpty(systemCode, externalDeptCode)) {
return null;
}
return espMapper.selectBySystemCodeAndExternalCode(systemCode.trim(), externalDeptCode.trim());
}*/
@Override
public List<EspDto> pushMsg(DeptSaveReqDTO syncReqDTO) {
/* @Override
public DeptExternalCodeDO getBySystemCodeAndDeptId(String systemCode, Long deptId) {
if (StrUtil.isBlank(systemCode) || deptId == null) {
return null;
}
return espMapper.selectBySystemCodeAndDeptId(systemCode.trim(), deptId);
}*/
/* @Override
public Long getDeptPushMsgDetails(Long deptId, String systemCode, String externalDeptCode,
String externalDeptName, Integer status) {
if (StrUtil.hasEmpty(systemCode, externalDeptCode) || deptId == null) {
return null;
}
String normalizedSystemCode = systemCode.trim();
String normalizedExternalCode = externalDeptCode.trim();
String normalizedExternalName = StrUtil.blankToDefault(StrUtil.trimToNull(externalDeptName), null);
disableActiveMappingIfConflict(deptId, normalizedSystemCode, normalizedExternalCode);
// 如果存在则更新,否则创建
DeptExternalCodeDO exists = espMapper.selectBySystemCodeAndDeptId(normalizedSystemCode, deptId);
if (exists != null) {
DeptExternalCodeSaveReqVO updateReqVO = new DeptExternalCodeSaveReqVO();
updateReqVO.setId(exists.getId());
updateReqVO.setDeptId(deptId);
updateReqVO.setSystemCode(normalizedSystemCode);
updateReqVO.setExternalDeptCode(normalizedExternalCode);
updateReqVO.setExternalDeptName(normalizedExternalName);
updateReqVO.setStatus(status == null ? exists.getStatus() : status);
//TODO
//getDeptPushMsgDetails(updateReqVO);
return exists.getId();
}
DeptExternalCodeSaveReqVO createReqVO = new DeptExternalCodeSaveReqVO();
createReqVO.setDeptId(deptId);
createReqVO.setSystemCode(normalizedSystemCode);
createReqVO.setExternalDeptCode(normalizedExternalCode);
createReqVO.setExternalDeptName(normalizedExternalName);
createReqVO.setStatus(status == null ? CommonStatusEnum.ENABLE.getStatus() : status);
return getDeptPushMsgDetails(createReqVO);
}*/
/* @Override
public void deleteDeptExternalCodesByDeptId(Long deptId) {
if (deptId == null) {
return;
}
espMapper.deleteByDeptId(deptId);
evictCacheSafely(deptId);
}*/
return BeanUtils.toBean(espMapper.selectpushMsg(syncReqDTO), EspDto.class);
}
private DeptPushMsgDO validateExists(Long id) {
if (id == null) {

View File

@@ -1,10 +1,11 @@
package com.zt.plat.module.system.service.dept;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.module.system.api.dept.dto.DeptSaveReqDTO;
import com.zt.plat.module.system.api.esp.dto.EspDto;
import com.zt.plat.module.system.controller.admin.dept.vo.depexternalcode.EspPageReqVO;
import com.zt.plat.module.system.controller.admin.dept.vo.depexternalcode.EspSaveRespVo;
import com.zt.plat.module.system.dal.dataobject.dept.DeptPushMsgDO;
import java.util.List;
/**
@@ -27,7 +28,6 @@ public interface IEspService {
/**
* 删除映射关系
*
* @param id 记录编号
*/
void deleteDeptPushMsg(Long id);
@@ -47,33 +47,11 @@ public interface IEspService {
*/
List<DeptPushMsgDO> getPushMsgByDeptId(Long deptId);
/**
* 根据部门与外部系统保存/更新映射(存在则更新,不存在则创建)
* @param deptId 本系统部门 ID
* @param systemCode 外部系统标识
* @param externalDeptCode 外部系统组织编码
* @param externalDeptName 外部系统组织名称(可选)
* @param status 状态,默认启用
* @return 映射记录 ID
*/
/* Long getDeptPushMsgDetails(Long deptId, String systemCode, String externalDeptCode, String externalDeptName,
Integer status);*/
/**
* 根据部门删除全部外部编码映射
*
* @param deptId 部门编号
* 推送部门数据到外部系统
* @param syncReqDTO 同步请求
*/
//void deleteDeptExternalCodesByDeptId(Long deptId);
/**
* 根据外部系统与外部组织编码查询映射
*/
//DeptExternalCodeDO getBySystemCodeAndExternalCode(String systemCode, String externalDeptCode);
/**
* 根据外部系统与部门编号查询映射
*/
//DeptExternalCodeDO getBySystemCodeAndDeptId(String systemCode, Long deptId);
List<EspDto> pushMsg(DeptSaveReqDTO syncReqDTO);
}