[+]增加部门推动消息功能
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
package com.zt.plat.module.system.controller.admin.dept;
|
||||
|
||||
import com.zt.plat.framework.common.pojo.CommonResult;
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
||||
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;
|
||||
import com.zt.plat.module.system.dal.dataobject.dept.DeptPushMsgDO;
|
||||
import com.zt.plat.module.system.service.dept.DeptService;
|
||||
import com.zt.plat.module.system.service.dept.IEspService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - 部门推送消息")
|
||||
@RestController
|
||||
@RequestMapping("/system/esp")
|
||||
@Validated
|
||||
public class EspController
|
||||
{
|
||||
|
||||
@Resource
|
||||
private IEspService espService;
|
||||
@Resource
|
||||
private DeptService deptService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建部门推送消息")
|
||||
@PreAuthorize("@ss.hasPermission('system:esp-external-code:create')")
|
||||
public CommonResult<Long> create(@Valid @RequestBody EspSaveRespVo createReqVO) {
|
||||
Long id = espService.createDeptPushMsg(createReqVO);
|
||||
return success(id);
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "修改部门推送消息")
|
||||
@PreAuthorize("@ss.hasPermission('system:esp-external-code:update')")
|
||||
public CommonResult<Boolean> update(@Valid @RequestBody EspSaveRespVo updateReqVO) {
|
||||
espService.updateDeptPushMsg(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除部门推送消息")
|
||||
@PreAuthorize("@ss.hasPermission('system:esp-external-code:delete')")
|
||||
public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
|
||||
espService.deleteDeptPushMsg(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获取部门推送消息详情")
|
||||
@PreAuthorize("@ss.hasPermission('system:esp-external-code:query')")
|
||||
public CommonResult<EspSaveRespVo> get(@RequestParam("id") Long id) {
|
||||
DeptPushMsgDO entity = espService.getDeptPushMsgDetails(id);
|
||||
EspSaveRespVo respVO = BeanUtils.toBean(entity, EspSaveRespVo.class);
|
||||
fillDeptInfo(List.of(respVO));
|
||||
return success(respVO);
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "分页查询部门推送消息")
|
||||
@PreAuthorize("@ss.hasPermission('system:esp-external-code:query')")
|
||||
public CommonResult<PageResult<EspSaveRespVo>> page(@Valid EspPageReqVO reqVO) {
|
||||
PageResult<DeptPushMsgDO> pageResult = espService.getDeptExternalCodePage(reqVO);
|
||||
PageResult<EspSaveRespVo> result = BeanUtils.toBean(pageResult, EspSaveRespVo.class);
|
||||
fillDeptInfo(result.getList());
|
||||
return success(result);
|
||||
}
|
||||
|
||||
@GetMapping("/list-by-dept")
|
||||
@Operation(summary = "根据部门部门推送消息")
|
||||
@Parameter(name = "deptId", description = "部门编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('system:esp-external-code:query')")
|
||||
public CommonResult<List<EspSaveRespVo>> listByDept(@RequestParam("deptId") Long deptId) {
|
||||
List<DeptPushMsgDO> list = espService.getPushMsgByDeptId(deptId);
|
||||
List<EspSaveRespVo> respList = BeanUtils.toBean(list, EspSaveRespVo.class);
|
||||
fillDeptInfo(respList);
|
||||
return success(respList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void fillDeptInfo(List<EspSaveRespVo> list) {
|
||||
if (list == null || list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Set<Long> deptIds = list.stream()
|
||||
.map(EspSaveRespVo::getDeptId)
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
if (deptIds == null || deptIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Map<Long, DeptDO> deptMap = deptService.getDeptList(deptIds).stream()
|
||||
.collect(Collectors.toMap(DeptDO::getId, dept -> dept, (left, right) -> left));
|
||||
list.forEach(item -> {
|
||||
DeptDO dept = deptMap.get(item.getDeptId());
|
||||
if (dept != null) {
|
||||
item.setDeptName(dept.getName());
|
||||
item.setDeptCode(dept.getCode());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.zt.plat.module.system.controller.admin.dept.vo.depexternalcode;
|
||||
|
||||
import com.zt.plat.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Schema(description = "管理后台 - 部门外部组织编码映射分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class EspPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "部门编号", example = "1024")
|
||||
private Long deptId;
|
||||
|
||||
@Schema(description = "外部系统标识", example = "ERP")
|
||||
private String systemCode;
|
||||
|
||||
@Schema(description = "外部组织编码", example = "100200")
|
||||
private String externalDeptCode;
|
||||
|
||||
@Schema(description = "状态", example = "0")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.zt.plat.module.system.controller.admin.dept.vo.depexternalcode;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 部门外消息推送创建/修改 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class EspSaveRespVo extends DeptExternalCodeBaseVO {
|
||||
|
||||
@Schema(description = "映射编号", example = "1024")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "所属部门名称", example = "技术部")
|
||||
private String deptName;
|
||||
|
||||
@Schema(description = "所属部门编码", example = "DEPT_001")
|
||||
private String deptCode;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "最后更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.zt.plat.module.system.dal.dataobject.dept;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.zt.plat.framework.common.enums.CommonStatusEnum;
|
||||
import com.zt.plat.framework.tenant.core.db.TenantBaseDO;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 部门推送消息 DO
|
||||
*/
|
||||
@TableName("system_dept_push_msg")
|
||||
@KeySequence("system_dept_push_msg_seq")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class DeptPushMsgDO extends TenantBaseDO {
|
||||
|
||||
/**
|
||||
* 主键编号
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 本系统部门 ID
|
||||
*/
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 外部系统标识
|
||||
*/
|
||||
private String systemCode;
|
||||
|
||||
/**
|
||||
* 外部系统组织编码
|
||||
*/
|
||||
private String externalDeptCode;
|
||||
|
||||
/**
|
||||
* 外部系统组织名称
|
||||
*/
|
||||
private String externalDeptName;
|
||||
|
||||
/**
|
||||
* 映射状态
|
||||
* 枚举 {@link CommonStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
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.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 java.util.List;
|
||||
/**
|
||||
* 部门推送消息接口Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface EspMapper extends BaseMapperX<DeptPushMsgDO> {
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param reqVO 消息推送VO
|
||||
* @return PageResult
|
||||
*/
|
||||
default PageResult<DeptPushMsgDO> selectPage(EspPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<DeptPushMsgDO>()
|
||||
.eqIfPresent(DeptPushMsgDO::getDeptId,reqVO.getDeptId())
|
||||
.eqIfPresent(DeptPushMsgDO::getSystemCode, reqVO.getSystemCode())
|
||||
.likeIfPresent(DeptPushMsgDO::getExternalDeptCode, reqVO.getExternalDeptCode())
|
||||
.eqIfPresent(DeptPushMsgDO::getStatus, reqVO.getStatus())
|
||||
.orderByDesc(DeptPushMsgDO::getId));
|
||||
}
|
||||
|
||||
|
||||
default DeptPushMsgDO selectBySystemCodeAndDeptId(String systemCode, Long deptId) {
|
||||
return selectOne(new LambdaQueryWrapperX<DeptPushMsgDO>()
|
||||
.eq(DeptPushMsgDO::getSystemCode, systemCode)
|
||||
.eq(DeptPushMsgDO::getDeptId, deptId));
|
||||
}
|
||||
|
||||
default DeptPushMsgDO selectBySystemCodeAndExternalCode(String systemCode, String externalDeptCode) {
|
||||
return selectOne(new LambdaQueryWrapperX<DeptPushMsgDO>()
|
||||
.eq(DeptPushMsgDO::getSystemCode, systemCode)
|
||||
.eq(DeptPushMsgDO::getExternalDeptCode, externalDeptCode));
|
||||
}
|
||||
|
||||
default List<DeptPushMsgDO> selectListByDeptId(Long deptId) {
|
||||
return selectList(DeptPushMsgDO::getDeptId, deptId);
|
||||
}
|
||||
|
||||
default int deleteByDeptId(Long deptId) {
|
||||
return delete(DeptPushMsgDO::getDeptId, deptId);
|
||||
}
|
||||
|
||||
default List<DeptPushMsgDO> selectListBySystemCode(String systemCode) {
|
||||
return selectList(DeptPushMsgDO::getSystemCode, systemCode);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
package com.zt.plat.module.system.service.dept;
|
||||
|
||||
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.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;
|
||||
import com.zt.plat.module.system.dal.dataobject.dept.DeptPushMsgDO;
|
||||
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.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.zt.plat.module.system.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 部门推送消息接口ServiceImpl实现类
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class EspServiceImpl implements IEspService {
|
||||
|
||||
@Resource
|
||||
private EspMapper espMapper;
|
||||
@Resource
|
||||
private DeptMapper deptMapper;
|
||||
@Resource
|
||||
private CacheManager cacheManager;
|
||||
|
||||
@Override
|
||||
@CacheEvict(cacheNames = RedisKeyConstants.DEPT_EXTERNAL_CODE_LIST, key = "#createReqVO.deptId", beforeInvocation = false)
|
||||
public Long createDeptPushMsg(EspSaveRespVo createReqVO) {
|
||||
|
||||
//请求校验
|
||||
normalizeRequest(createReqVO);
|
||||
//冲突禁用-映射
|
||||
disableActiveMappingIfConflict(createReqVO.getDeptId(), createReqVO.getSystemCode(), createReqVO.getExternalDeptCode());
|
||||
validateForCreateOrUpdate(null, createReqVO.getDeptId(), createReqVO.getSystemCode(),
|
||||
createReqVO.getExternalDeptCode());
|
||||
|
||||
DeptPushMsgDO entity = BeanUtils.toBean(createReqVO, DeptPushMsgDO.class);
|
||||
if (entity.getStatus() == null) {
|
||||
entity.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
}
|
||||
espMapper.insert(entity);
|
||||
return entity.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDeptPushMsg(EspSaveRespVo updateReqVO) {
|
||||
normalizeRequest(updateReqVO);
|
||||
DeptPushMsgDO exists = validateExists(updateReqVO.getId());
|
||||
disableActiveMappingIfConflict(updateReqVO.getDeptId(), updateReqVO.getSystemCode(), updateReqVO.getExternalDeptCode());
|
||||
validateForCreateOrUpdate(updateReqVO.getId(), updateReqVO.getDeptId(), updateReqVO.getSystemCode(),
|
||||
updateReqVO.getExternalDeptCode());
|
||||
|
||||
DeptPushMsgDO updateObj = BeanUtils.toBean(updateReqVO, DeptPushMsgDO.class);
|
||||
// 保持原有的状态默认值逻辑
|
||||
if (updateObj.getStatus() == null) {
|
||||
updateObj.setStatus(exists.getStatus() == null ? CommonStatusEnum.ENABLE.getStatus() : exists.getStatus());
|
||||
}
|
||||
espMapper.updateById(updateObj);
|
||||
evictCacheSafely(exists.getDeptId());
|
||||
evictCacheSafely(updateObj.getDeptId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDeptPushMsg(Long id) {
|
||||
DeptPushMsgDO exists = validateExists(id);
|
||||
espMapper.deleteById(id);
|
||||
evictCacheSafely(exists.getDeptId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeptPushMsgDO getDeptPushMsgDetails(Long id) {
|
||||
return espMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<DeptPushMsgDO> getDeptExternalCodePage(EspPageReqVO reqVO) {
|
||||
|
||||
return espMapper.selectPage(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(cacheNames = RedisKeyConstants.DEPT_EXTERNAL_CODE_LIST, key = "#deptId")
|
||||
public List<DeptPushMsgDO> getPushMsgByDeptId(Long deptId) {
|
||||
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 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);
|
||||
}*/
|
||||
|
||||
private DeptPushMsgDO validateExists(Long id) {
|
||||
if (id == null) {
|
||||
throw exception(DEPT_EXTERNAL_RELATION_NOT_EXISTS);
|
||||
}
|
||||
DeptPushMsgDO entity = espMapper.selectById(id);
|
||||
if (entity == null) {
|
||||
throw exception(DEPT_EXTERNAL_RELATION_NOT_EXISTS);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
private void validateForCreateOrUpdate(Long id, Long deptId, String systemCode, String externalDeptCode) {
|
||||
|
||||
// 校验部门存在
|
||||
DeptDO dept = deptMapper.selectById(deptId);
|
||||
if (dept == null) {
|
||||
throw exception(DEPT_NOT_FOUND);
|
||||
}
|
||||
String normalizedSystemCode = StrUtil.blankToDefault(systemCode, null);
|
||||
String normalizedExternalCode = StrUtil.blankToDefault(externalDeptCode, null);
|
||||
|
||||
// 校验同一系统下部门唯一
|
||||
if (StrUtil.isNotBlank(normalizedSystemCode)) {
|
||||
DeptPushMsgDO sameDept = espMapper
|
||||
.selectBySystemCodeAndDeptId(normalizedSystemCode, deptId);
|
||||
if (sameDept != null && (id == null || !sameDept.getId().equals(id))) {
|
||||
throw exception(DEPT_EXTERNAL_RELATION_EXISTS, normalizedSystemCode);
|
||||
}
|
||||
}
|
||||
// 校验同一系统下外部编码唯一
|
||||
if (StrUtil.isNotBlank(normalizedSystemCode) && StrUtil.isNotBlank(normalizedExternalCode)) {
|
||||
DeptPushMsgDO sameExternal = espMapper
|
||||
.selectBySystemCodeAndExternalCode(normalizedSystemCode, normalizedExternalCode);
|
||||
if (sameExternal != null && (id == null || !sameExternal.getId().equals(id))) {
|
||||
boolean sameDept = Objects.equals(deptId, sameExternal.getDeptId());
|
||||
boolean activeConflict = !sameDept && CommonStatusEnum.isEnable(sameExternal.getStatus());
|
||||
if (activeConflict) {
|
||||
throw exception(DEPT_EXTERNAL_CODE_DUPLICATE, normalizedSystemCode, normalizedExternalCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void normalizeRequest(EspSaveRespVo reqVO) {
|
||||
if (reqVO == null) {
|
||||
return;
|
||||
}
|
||||
if (StrUtil.isNotBlank(reqVO.getSystemCode())) {
|
||||
reqVO.setSystemCode(reqVO.getSystemCode().trim());
|
||||
}
|
||||
if (StrUtil.isNotBlank(reqVO.getExternalDeptCode())) {
|
||||
reqVO.setExternalDeptCode(reqVO.getExternalDeptCode().trim());
|
||||
}
|
||||
if (reqVO.getStatus() == null) {
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
private void disableActiveMappingIfConflict(Long targetDeptId, String systemCode, String externalDeptCode) {
|
||||
String normalizedSystem = StrUtil.trimToNull(systemCode);
|
||||
String normalizedExternal = StrUtil.trimToNull(externalDeptCode);
|
||||
if (StrUtil.hasEmpty(normalizedSystem, normalizedExternal) || targetDeptId == null) {
|
||||
return;
|
||||
}
|
||||
DeptPushMsgDO existing = espMapper.selectBySystemCodeAndExternalCode(normalizedSystem, normalizedExternal);
|
||||
if (existing == null) {
|
||||
return;
|
||||
}
|
||||
if (Objects.equals(existing.getDeptId(), targetDeptId)) {
|
||||
return;
|
||||
}
|
||||
if (CommonStatusEnum.isEnable(existing.getStatus())) {
|
||||
DeptPushMsgDO update = new DeptPushMsgDO();
|
||||
update.setId(existing.getId());
|
||||
update.setStatus(CommonStatusEnum.DISABLE.getStatus());
|
||||
espMapper.updateById(update);
|
||||
evictCacheSafely(existing.getDeptId());
|
||||
}
|
||||
}
|
||||
|
||||
private void evictCacheSafely(Long deptId) {
|
||||
|
||||
if (deptId == null || cacheManager == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (cacheManager.getCache(RedisKeyConstants.DEPT_EXTERNAL_CODE_LIST) != null) {
|
||||
cacheManager.getCache(RedisKeyConstants.DEPT_EXTERNAL_CODE_LIST).evict(deptId);
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
// 缓存失效失败不影响主流程
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.zt.plat.module.system.service.dept;
|
||||
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 部门推送消息 Service 接口
|
||||
*/
|
||||
public interface IEspService {
|
||||
|
||||
/**
|
||||
* 创建映射关系
|
||||
* @param createReqVO 创建请求
|
||||
* @return 新增记录编号
|
||||
*/
|
||||
Long createDeptPushMsg(EspSaveRespVo createReqVO);
|
||||
|
||||
/**
|
||||
* 更新映射关系
|
||||
* @param updateReqVO 更新请求
|
||||
*/
|
||||
void updateDeptPushMsg(EspSaveRespVo updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除映射关系
|
||||
*
|
||||
* @param id 记录编号
|
||||
*/
|
||||
void deleteDeptPushMsg(Long id);
|
||||
|
||||
/**
|
||||
* 获取映射详情
|
||||
*/
|
||||
DeptPushMsgDO getDeptPushMsgDetails(Long id);
|
||||
|
||||
/**
|
||||
* 分页查询映射
|
||||
*/
|
||||
PageResult<DeptPushMsgDO> getDeptExternalCodePage(EspPageReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 根据部门推送消息
|
||||
*/
|
||||
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 部门编号
|
||||
*/
|
||||
//void deleteDeptExternalCodesByDeptId(Long deptId);
|
||||
|
||||
/**
|
||||
* 根据外部系统与外部组织编码查询映射
|
||||
*/
|
||||
//DeptExternalCodeDO getBySystemCodeAndExternalCode(String systemCode, String externalDeptCode);
|
||||
|
||||
/**
|
||||
* 根据外部系统与部门编号查询映射
|
||||
*/
|
||||
//DeptExternalCodeDO getBySystemCodeAndDeptId(String systemCode, Long deptId);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user