暂存提交

This commit is contained in:
2026-07-31 14:55:34 +08:00
parent bc3c18a6e9
commit 7a19e2f096
28 changed files with 655 additions and 46 deletions
@@ -1,6 +1,9 @@
package com.baiyue.warehouse.repository;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baiyue.common.core.api.PageResult;
import com.baiyue.warehouse.dto.MasterDataQueries.PartnerPageQuery;
import com.baiyue.warehouse.entity.PartnerEntity;
import com.baiyue.warehouse.mapper.PartnerMapper;
import org.springframework.stereotype.Repository;
@@ -24,4 +27,40 @@ public class PartnerRepository {
.eq(PartnerEntity::getTenantId, tenantId).eq(PartnerEntity::getId, id)
.eq(PartnerEntity::getStatus, "ACTIVE"));
}
public PageResult<PartnerEntity> page(long tenantId, PartnerPageQuery request) {
LambdaQueryWrapper<PartnerEntity> wrapper = new LambdaQueryWrapper<PartnerEntity>()
.eq(PartnerEntity::getTenantId, tenantId)
.eq(StringUtils.hasText(request.type()), PartnerEntity::getPartnerType, request.type())
.eq(StringUtils.hasText(request.status()), PartnerEntity::getStatus, request.status())
.and(StringUtils.hasText(request.keyword()), query -> query
.like(PartnerEntity::getPartnerCode, request.keyword())
.or().like(PartnerEntity::getPartnerName, request.keyword())
.or().like(PartnerEntity::getContactName, request.keyword())
.or().like(PartnerEntity::getContactPhone, request.keyword()))
.orderByAsc(PartnerEntity::getPartnerName)
.orderByAsc(PartnerEntity::getId);
return PageResult.from(mapper.selectPage(new Page<>(request.page(), request.size()), wrapper));
}
public PartnerEntity findOwned(long tenantId, long id) {
return mapper.selectOne(new LambdaQueryWrapper<PartnerEntity>()
.eq(PartnerEntity::getTenantId, tenantId)
.eq(PartnerEntity::getId, id));
}
public boolean existsCode(long tenantId, String code, Long excludedId) {
return mapper.selectCount(new LambdaQueryWrapper<PartnerEntity>()
.eq(PartnerEntity::getTenantId, tenantId)
.eq(PartnerEntity::getPartnerCode, code)
.ne(excludedId != null, PartnerEntity::getId, excludedId)) > 0;
}
public void insert(PartnerEntity entity) {
mapper.insert(entity);
}
public void save(PartnerEntity entity) {
mapper.updateById(entity);
}
}
@@ -10,6 +10,8 @@ import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import org.apache.ibatis.builder.MapperBuilderAssistant;
import org.apache.ibatis.session.Configuration;
import java.util.List;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baiyue.warehouse.dto.MasterDataQueries.PartnerPageQuery;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@@ -32,4 +34,19 @@ class PartnerRepositoryTest {
verify(mapper).selectOne(c.capture()); c.getValue().getSqlSegment();
assertThat(c.getValue().getParamNameValuePairs().values()).contains(10002L,9L,"ACTIVE");
}
@Test void 平台分页强制租户并支持筛选() {
PartnerMapper mapper=mock(PartnerMapper.class);
when(mapper.selectPage(any(Page.class), any())).thenAnswer(invocation -> invocation.getArgument(0));
new PartnerRepository(mapper).page(10001L,
new PartnerPageQuery(1, 20, "示例", "CUSTOMER", "ACTIVE"));
@SuppressWarnings("unchecked")
ArgumentCaptor<LambdaQueryWrapper<PartnerEntity>> wrapper=ArgumentCaptor.forClass(LambdaQueryWrapper.class);
verify(mapper).selectPage(any(Page.class), wrapper.capture());
wrapper.getValue().getSqlSegment();
assertThat(wrapper.getValue().getParamNameValuePairs().values())
.contains(10001L, "CUSTOMER", "ACTIVE", "%示例%");
}
}