改造亲属关系聚合保存亲属资产
This commit is contained in:
@@ -1,13 +1,16 @@
|
|||||||
package com.ruoyi.info.collection.service.impl;
|
package com.ruoyi.info.collection.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.ruoyi.info.collection.domain.CcdiAssetInfo;
|
||||||
import com.ruoyi.info.collection.domain.CcdiStaffFmyRelation;
|
import com.ruoyi.info.collection.domain.CcdiStaffFmyRelation;
|
||||||
|
import com.ruoyi.info.collection.domain.vo.CcdiAssetInfoVO;
|
||||||
import com.ruoyi.info.collection.domain.dto.CcdiStaffFmyRelationAddDTO;
|
import com.ruoyi.info.collection.domain.dto.CcdiStaffFmyRelationAddDTO;
|
||||||
import com.ruoyi.info.collection.domain.dto.CcdiStaffFmyRelationEditDTO;
|
import com.ruoyi.info.collection.domain.dto.CcdiStaffFmyRelationEditDTO;
|
||||||
import com.ruoyi.info.collection.domain.dto.CcdiStaffFmyRelationQueryDTO;
|
import com.ruoyi.info.collection.domain.dto.CcdiStaffFmyRelationQueryDTO;
|
||||||
import com.ruoyi.info.collection.domain.excel.CcdiStaffFmyRelationExcel;
|
import com.ruoyi.info.collection.domain.excel.CcdiStaffFmyRelationExcel;
|
||||||
import com.ruoyi.info.collection.domain.vo.CcdiStaffFmyRelationVO;
|
import com.ruoyi.info.collection.domain.vo.CcdiStaffFmyRelationVO;
|
||||||
import com.ruoyi.info.collection.mapper.CcdiStaffFmyRelationMapper;
|
import com.ruoyi.info.collection.mapper.CcdiStaffFmyRelationMapper;
|
||||||
|
import com.ruoyi.info.collection.service.ICcdiAssetInfoService;
|
||||||
import com.ruoyi.info.collection.service.ICcdiStaffFmyRelationImportService;
|
import com.ruoyi.info.collection.service.ICcdiStaffFmyRelationImportService;
|
||||||
import com.ruoyi.info.collection.service.ICcdiStaffFmyRelationService;
|
import com.ruoyi.info.collection.service.ICcdiStaffFmyRelationService;
|
||||||
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
@@ -19,6 +22,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -42,6 +46,9 @@ public class CcdiStaffFmyRelationServiceImpl implements ICcdiStaffFmyRelationSer
|
|||||||
@Resource
|
@Resource
|
||||||
private RedisTemplate<String, Object> redisTemplate;
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ICcdiAssetInfoService assetInfoService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询员工亲属关系列表
|
* 查询员工亲属关系列表
|
||||||
*
|
*
|
||||||
@@ -90,7 +97,19 @@ public class CcdiStaffFmyRelationServiceImpl implements ICcdiStaffFmyRelationSer
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public CcdiStaffFmyRelationVO selectRelationById(Long id) {
|
public CcdiStaffFmyRelationVO selectRelationById(Long id) {
|
||||||
return relationMapper.selectRelationById(id);
|
CcdiStaffFmyRelationVO relationVO = relationMapper.selectRelationById(id);
|
||||||
|
if (relationVO == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotEmpty(relationVO.getPersonId()) && StringUtils.isNotEmpty(relationVO.getRelationCertNo())) {
|
||||||
|
List<CcdiAssetInfoVO> assetInfoList = assetInfoService
|
||||||
|
.selectByFamilyIdAndPersonId(relationVO.getPersonId(), relationVO.getRelationCertNo())
|
||||||
|
.stream()
|
||||||
|
.map(this::toAssetInfoVO)
|
||||||
|
.toList();
|
||||||
|
relationVO.setAssetInfoList(assetInfoList);
|
||||||
|
}
|
||||||
|
return relationVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,6 +133,7 @@ public class CcdiStaffFmyRelationServiceImpl implements ICcdiStaffFmyRelationSer
|
|||||||
}
|
}
|
||||||
|
|
||||||
int result = relationMapper.insert(relation);
|
int result = relationMapper.insert(relation);
|
||||||
|
assetInfoService.replaceByFamilyIdAndPersonId(addDTO.getPersonId(), addDTO.getRelationCertNo(), addDTO.getAssetInfoList());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,9 +146,19 @@ public class CcdiStaffFmyRelationServiceImpl implements ICcdiStaffFmyRelationSer
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public int updateRelation(CcdiStaffFmyRelationEditDTO editDTO) {
|
public int updateRelation(CcdiStaffFmyRelationEditDTO editDTO) {
|
||||||
|
CcdiStaffFmyRelation existing = relationMapper.selectById(editDTO.getId());
|
||||||
|
if (existing == null) {
|
||||||
|
throw new RuntimeException("员工亲属关系不存在");
|
||||||
|
}
|
||||||
|
if (!StringUtils.equals(existing.getRelationCertType(), editDTO.getRelationCertType())
|
||||||
|
|| !StringUtils.equals(existing.getRelationCertNo(), editDTO.getRelationCertNo())) {
|
||||||
|
throw new RuntimeException("关系人证件类型/证件号码不允许修改");
|
||||||
|
}
|
||||||
|
|
||||||
CcdiStaffFmyRelation relation = new CcdiStaffFmyRelation();
|
CcdiStaffFmyRelation relation = new CcdiStaffFmyRelation();
|
||||||
BeanUtils.copyProperties(editDTO, relation);
|
BeanUtils.copyProperties(editDTO, relation);
|
||||||
int result = relationMapper.updateById(relation);
|
int result = relationMapper.updateById(relation);
|
||||||
|
assetInfoService.replaceByFamilyIdAndPersonId(editDTO.getPersonId(), editDTO.getRelationCertNo(), editDTO.getAssetInfoList());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +171,15 @@ public class CcdiStaffFmyRelationServiceImpl implements ICcdiStaffFmyRelationSer
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public int deleteRelationByIds(Long[] ids) {
|
public int deleteRelationByIds(Long[] ids) {
|
||||||
return relationMapper.deleteBatchIds(java.util.List.of(ids));
|
List<Long> idList = java.util.List.of(ids);
|
||||||
|
List<CcdiStaffFmyRelation> relationList = relationMapper.selectBatchIds(idList);
|
||||||
|
for (CcdiStaffFmyRelation relation : relationList) {
|
||||||
|
if (StringUtils.isEmpty(relation.getPersonId()) || StringUtils.isEmpty(relation.getRelationCertNo())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
assetInfoService.deleteByFamilyIdAndPersonId(relation.getPersonId(), relation.getRelationCertNo());
|
||||||
|
}
|
||||||
|
return relationMapper.deleteBatchIds(idList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -184,4 +222,10 @@ public class CcdiStaffFmyRelationServiceImpl implements ICcdiStaffFmyRelationSer
|
|||||||
|
|
||||||
return taskId;
|
return taskId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CcdiAssetInfoVO toAssetInfoVO(CcdiAssetInfo assetInfo) {
|
||||||
|
CcdiAssetInfoVO assetInfoVO = new CcdiAssetInfoVO();
|
||||||
|
BeanUtils.copyProperties(assetInfo, assetInfoVO);
|
||||||
|
return assetInfoVO;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,176 @@
|
|||||||
|
package com.ruoyi.info.collection.service;
|
||||||
|
|
||||||
|
import com.ruoyi.info.collection.domain.CcdiAssetInfo;
|
||||||
|
import com.ruoyi.info.collection.domain.CcdiStaffFmyRelation;
|
||||||
|
import com.ruoyi.info.collection.domain.dto.CcdiAssetInfoDTO;
|
||||||
|
import com.ruoyi.info.collection.domain.dto.CcdiStaffFmyRelationAddDTO;
|
||||||
|
import com.ruoyi.info.collection.domain.dto.CcdiStaffFmyRelationEditDTO;
|
||||||
|
import com.ruoyi.info.collection.domain.vo.CcdiStaffFmyRelationVO;
|
||||||
|
import com.ruoyi.info.collection.mapper.CcdiStaffFmyRelationMapper;
|
||||||
|
import com.ruoyi.info.collection.service.impl.CcdiStaffFmyRelationServiceImpl;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.inOrder;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
class CcdiStaffFmyRelationServiceImplTest {
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
|
private CcdiStaffFmyRelationServiceImpl service;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private CcdiStaffFmyRelationMapper relationMapper;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ICcdiStaffFmyRelationImportService relationImportService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ICcdiAssetInfoService assetInfoService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void selectRelationById_shouldAggregateAssetInfoList() {
|
||||||
|
CcdiStaffFmyRelationVO relationVO = new CcdiStaffFmyRelationVO();
|
||||||
|
relationVO.setId(10L);
|
||||||
|
relationVO.setPersonId("320101199001010011");
|
||||||
|
relationVO.setRelationCertNo("A123456789");
|
||||||
|
CcdiAssetInfo assetInfo = new CcdiAssetInfo();
|
||||||
|
assetInfo.setFamilyId("320101199001010011");
|
||||||
|
assetInfo.setPersonId("A123456789");
|
||||||
|
assetInfo.setAssetMainType("房产");
|
||||||
|
|
||||||
|
when(relationMapper.selectRelationById(10L)).thenReturn(relationVO);
|
||||||
|
when(assetInfoService.selectByFamilyIdAndPersonId("320101199001010011", "A123456789"))
|
||||||
|
.thenReturn(List.of(assetInfo));
|
||||||
|
|
||||||
|
CcdiStaffFmyRelationVO result = service.selectRelationById(10L);
|
||||||
|
|
||||||
|
assertNotNull(result.getAssetInfoList());
|
||||||
|
assertEquals(1, result.getAssetInfoList().size());
|
||||||
|
assertEquals("A123456789", result.getAssetInfoList().get(0).getPersonId());
|
||||||
|
assertEquals("房产", result.getAssetInfoList().get(0).getAssetMainType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void insertRelation_shouldSaveRelationThenReplaceRelativeAssets() {
|
||||||
|
CcdiStaffFmyRelationAddDTO addDTO = new CcdiStaffFmyRelationAddDTO();
|
||||||
|
addDTO.setPersonId("320101199001010011");
|
||||||
|
addDTO.setRelationType("配偶");
|
||||||
|
addDTO.setRelationName("李四");
|
||||||
|
addDTO.setRelationCertType("护照");
|
||||||
|
addDTO.setRelationCertNo("A123456789");
|
||||||
|
addDTO.setAssetInfoList(List.of(buildAssetDto("房产")));
|
||||||
|
|
||||||
|
when(relationMapper.insert(any(CcdiStaffFmyRelation.class))).thenReturn(1);
|
||||||
|
|
||||||
|
int result = service.insertRelation(addDTO);
|
||||||
|
|
||||||
|
assertEquals(1, result);
|
||||||
|
ArgumentCaptor<CcdiStaffFmyRelation> relationCaptor = ArgumentCaptor.forClass(CcdiStaffFmyRelation.class);
|
||||||
|
verify(relationMapper).insert(relationCaptor.capture());
|
||||||
|
assertEquals("MANUAL", relationCaptor.getValue().getDataSource());
|
||||||
|
assertEquals(Boolean.TRUE, relationCaptor.getValue().getIsEmpFamily());
|
||||||
|
assertEquals(Boolean.FALSE, relationCaptor.getValue().getIsCustFamily());
|
||||||
|
verify(assetInfoService).replaceByFamilyIdAndPersonId("320101199001010011", "A123456789", addDTO.getAssetInfoList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void updateRelation_shouldRejectRelationCertChange() {
|
||||||
|
CcdiStaffFmyRelation existing = new CcdiStaffFmyRelation();
|
||||||
|
existing.setId(10L);
|
||||||
|
existing.setRelationCertType("护照");
|
||||||
|
existing.setRelationCertNo("A123456789");
|
||||||
|
|
||||||
|
CcdiStaffFmyRelationEditDTO editDTO = new CcdiStaffFmyRelationEditDTO();
|
||||||
|
editDTO.setId(10L);
|
||||||
|
editDTO.setPersonId("320101199001010011");
|
||||||
|
editDTO.setRelationType("配偶");
|
||||||
|
editDTO.setRelationName("李四");
|
||||||
|
editDTO.setRelationCertType("身份证");
|
||||||
|
editDTO.setRelationCertNo("A123456789");
|
||||||
|
|
||||||
|
when(relationMapper.selectById(10L)).thenReturn(existing);
|
||||||
|
|
||||||
|
RuntimeException exception = assertThrows(RuntimeException.class, () -> service.updateRelation(editDTO));
|
||||||
|
|
||||||
|
assertEquals("关系人证件类型/证件号码不允许修改", exception.getMessage());
|
||||||
|
verify(relationMapper, never()).updateById(any(CcdiStaffFmyRelation.class));
|
||||||
|
verify(assetInfoService, never()).replaceByFamilyIdAndPersonId(any(), any(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void updateRelation_shouldReplaceAssetsByOwnershipKey() {
|
||||||
|
CcdiStaffFmyRelation existing = new CcdiStaffFmyRelation();
|
||||||
|
existing.setId(10L);
|
||||||
|
existing.setRelationCertType("护照");
|
||||||
|
existing.setRelationCertNo("A123456789");
|
||||||
|
|
||||||
|
CcdiStaffFmyRelationEditDTO editDTO = new CcdiStaffFmyRelationEditDTO();
|
||||||
|
editDTO.setId(10L);
|
||||||
|
editDTO.setPersonId("320101199001010011");
|
||||||
|
editDTO.setRelationType("配偶");
|
||||||
|
editDTO.setRelationName("李四");
|
||||||
|
editDTO.setRelationCertType("护照");
|
||||||
|
editDTO.setRelationCertNo("A123456789");
|
||||||
|
editDTO.setAssetInfoList(List.of(buildAssetDto("车辆")));
|
||||||
|
|
||||||
|
when(relationMapper.selectById(10L)).thenReturn(existing);
|
||||||
|
when(relationMapper.updateById(any(CcdiStaffFmyRelation.class))).thenReturn(1);
|
||||||
|
|
||||||
|
int result = service.updateRelation(editDTO);
|
||||||
|
|
||||||
|
assertEquals(1, result);
|
||||||
|
verify(assetInfoService).replaceByFamilyIdAndPersonId("320101199001010011", "A123456789", editDTO.getAssetInfoList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void deleteRelationByIds_shouldDeleteRelativeAssetsBeforeDeletingRelations() {
|
||||||
|
CcdiStaffFmyRelation relation1 = new CcdiStaffFmyRelation();
|
||||||
|
relation1.setId(10L);
|
||||||
|
relation1.setPersonId("320101199001010011");
|
||||||
|
relation1.setRelationCertNo("A123456789");
|
||||||
|
CcdiStaffFmyRelation relation2 = new CcdiStaffFmyRelation();
|
||||||
|
relation2.setId(11L);
|
||||||
|
relation2.setPersonId("320101199001010022");
|
||||||
|
relation2.setRelationCertNo("B987654321");
|
||||||
|
|
||||||
|
when(relationMapper.selectBatchIds(List.of(10L, 11L))).thenReturn(List.of(relation1, relation2));
|
||||||
|
when(relationMapper.deleteBatchIds(List.of(10L, 11L))).thenReturn(2);
|
||||||
|
|
||||||
|
int result = service.deleteRelationByIds(new Long[]{10L, 11L});
|
||||||
|
|
||||||
|
assertEquals(2, result);
|
||||||
|
var order = inOrder(assetInfoService, relationMapper);
|
||||||
|
order.verify(assetInfoService).deleteByFamilyIdAndPersonId("320101199001010011", "A123456789");
|
||||||
|
order.verify(assetInfoService).deleteByFamilyIdAndPersonId("320101199001010022", "B987654321");
|
||||||
|
order.verify(relationMapper).deleteBatchIds(List.of(10L, 11L));
|
||||||
|
}
|
||||||
|
|
||||||
|
private CcdiAssetInfoDTO buildAssetDto(String assetMainType) {
|
||||||
|
CcdiAssetInfoDTO dto = new CcdiAssetInfoDTO();
|
||||||
|
dto.setAssetMainType(assetMainType);
|
||||||
|
dto.setAssetSubType(assetMainType + "小类");
|
||||||
|
dto.setAssetName(assetMainType + "名称");
|
||||||
|
dto.setCurrentValue(new BigDecimal("100.00"));
|
||||||
|
dto.setAssetStatus("正常");
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user