优化
This commit is contained in:
+5
-3
@@ -13,6 +13,7 @@ import com.baiyue.warehouse.entity.ExpressCompanyEntity;
|
||||
import com.baiyue.warehouse.service.ExpressCompanyQueryService;
|
||||
import com.baiyue.warehouse.service.ExpressCompanyImportService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
@@ -42,7 +43,7 @@ import java.nio.charset.StandardCharsets;
|
||||
|
||||
/** 平台快递公司管理接口。 */
|
||||
@Validated
|
||||
@Tag(name = "平台快递公司", description = "按目标租户分页查询快递公司主数据")
|
||||
@Tag(name = "平台快递公司", description = "跨企业分页查询和按目标租户维护快递公司主数据")
|
||||
@RestController
|
||||
@RequestMapping("/api/platform/v1/express-companies")
|
||||
public class PlatformExpressCompanyController {
|
||||
@@ -56,7 +57,7 @@ public class PlatformExpressCompanyController {
|
||||
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAuthority('platform:express:list')")
|
||||
@Operation(summary = "分页查询快递公司", description = "按目标租户、关键字和状态分页查询快递公司")
|
||||
@Operation(summary = "分页查询快递公司", description = "默认查询全部企业;可按目标租户、关键字和状态筛选")
|
||||
@ApiResponses({
|
||||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "查询成功"),
|
||||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "查询条件无效"),
|
||||
@@ -65,7 +66,8 @@ public class PlatformExpressCompanyController {
|
||||
})
|
||||
public ApiResponse<PageResult<ExpressCompanyEntity>> page(
|
||||
@AuthenticationPrincipal AuthenticatedUser user,
|
||||
@RequestParam @Min(1) long tenantId,
|
||||
@Parameter(description = "可选目标企业租户ID;不传时查询全部企业")
|
||||
@RequestParam(required = false) @Min(1) Long tenantId,
|
||||
@Valid @ParameterObject ExpressCompanyPageQuery query) {
|
||||
requirePlatform(user);
|
||||
return ApiResponse.success(service.page(tenantId, query));
|
||||
|
||||
+6
-3
@@ -13,6 +13,7 @@ import com.baiyue.warehouse.entity.PartnerEntity;
|
||||
import com.baiyue.warehouse.service.PlatformPartnerQueryService;
|
||||
import com.baiyue.warehouse.service.PartnerImportService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
@@ -42,7 +43,7 @@ import java.nio.charset.StandardCharsets;
|
||||
|
||||
/** 平台往来单位管理接口。 */
|
||||
@Validated
|
||||
@Tag(name = "平台往来单位", description = "按目标租户分页查询往来单位主数据")
|
||||
@Tag(name = "平台往来单位", description = "跨企业分页查询和按目标租户维护往来单位主数据")
|
||||
@RestController
|
||||
@RequestMapping("/api/platform/v1/partners")
|
||||
public class PlatformPartnerController {
|
||||
@@ -83,7 +84,8 @@ public class PlatformPartnerController {
|
||||
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAuthority('platform:counterparty:list')")
|
||||
@Operation(summary = "分页查询往来单位", description = "按目标租户、关键字、类型和状态分页查询往来单位")
|
||||
@Operation(summary = "分页查询往来单位",
|
||||
description = "默认分页查询全部企业往来单位;可按目标租户、关键字、类型和状态筛选")
|
||||
@ApiResponses({
|
||||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "查询成功"),
|
||||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "查询条件无效"),
|
||||
@@ -92,7 +94,8 @@ public class PlatformPartnerController {
|
||||
})
|
||||
public ApiResponse<PageResult<PartnerEntity>> page(
|
||||
@AuthenticationPrincipal AuthenticatedUser user,
|
||||
@RequestParam @Min(1) long tenantId,
|
||||
@Parameter(description = "可选目标企业租户ID;不传时查询全部企业")
|
||||
@RequestParam(required = false) @Min(1) Long tenantId,
|
||||
@Valid @ParameterObject PartnerPageQuery query) {
|
||||
requirePlatform(user);
|
||||
return ApiResponse.success(service.page(tenantId, query));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.baiyue.warehouse.mapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baiyue.warehouse.entity.PartnerEntity;
|
||||
import com.baiyue.warehouse.entity.PartnerTypeEntity;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
@@ -25,6 +26,56 @@ public interface PartnerMapper extends BaseMapper<PartnerEntity> {
|
||||
@Select("SELECT partner_id FROM wh_partner_type WHERE tenant_id = #{tenantId} AND partner_type = #{type}")
|
||||
List<Long> selectPartnerIdsByType(@Param("tenantId") long tenantId, @Param("type") String type);
|
||||
|
||||
@Select("""
|
||||
<script>
|
||||
SELECT p.*
|
||||
FROM wh_partner p
|
||||
WHERE p.deleted = 0
|
||||
<if test="tenantId != null">
|
||||
AND p.tenant_id = #{tenantId}
|
||||
</if>
|
||||
<choose>
|
||||
<when test="type == 'BOTH'">
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM wh_partner_type customer_type
|
||||
WHERE customer_type.partner_id = p.id
|
||||
AND customer_type.partner_type = 'CUSTOMER'
|
||||
AND customer_type.tenant_id = p.tenant_id
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM wh_partner_type supplier_type
|
||||
WHERE supplier_type.partner_id = p.id
|
||||
AND supplier_type.partner_type = 'SUPPLIER'
|
||||
AND supplier_type.tenant_id = p.tenant_id
|
||||
)
|
||||
</when>
|
||||
<otherwise>
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM wh_partner_type pt
|
||||
WHERE pt.partner_id = p.id
|
||||
AND pt.partner_type = #{type}
|
||||
AND pt.tenant_id = p.tenant_id
|
||||
)
|
||||
</otherwise>
|
||||
</choose>
|
||||
<if test="status != null and status != ''">
|
||||
AND p.status = #{status}
|
||||
</if>
|
||||
<if test="keyword != null and keyword != ''">
|
||||
AND (p.partner_code LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR p.partner_name LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR p.contact_name LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR p.contact_phone LIKE CONCAT('%', #{keyword}, '%'))
|
||||
</if>
|
||||
ORDER BY p.partner_name ASC, p.id ASC
|
||||
</script>
|
||||
""")
|
||||
Page<PartnerEntity> selectPartnerPageByType(Page<PartnerEntity> page,
|
||||
@Param("tenantId") Long tenantId,
|
||||
@Param("type") String type,
|
||||
@Param("status") String status,
|
||||
@Param("keyword") String keyword);
|
||||
|
||||
@Delete("DELETE FROM wh_partner_type WHERE partner_id = #{partnerId}")
|
||||
void deleteTypes(@Param("partnerId") long partnerId);
|
||||
|
||||
|
||||
+3
-3
@@ -9,7 +9,7 @@ import com.baiyue.warehouse.mapper.ExpressCompanyMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/** 快递公司主数据仓储。 */
|
||||
/** 快递公司主数据仓储;平台分页租户条件可选,资源读写仍强制租户边界。 */
|
||||
@Repository
|
||||
public class ExpressCompanyRepository {
|
||||
private final ExpressCompanyMapper mapper;
|
||||
@@ -18,9 +18,9 @@ public class ExpressCompanyRepository {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
public PageResult<ExpressCompanyEntity> page(long tenantId, ExpressCompanyPageQuery query) {
|
||||
public PageResult<ExpressCompanyEntity> page(Long tenantId, ExpressCompanyPageQuery query) {
|
||||
LambdaQueryWrapper<ExpressCompanyEntity> wrapper = new LambdaQueryWrapper<ExpressCompanyEntity>()
|
||||
.eq(ExpressCompanyEntity::getTenantId, tenantId)
|
||||
.eq(tenantId != null, ExpressCompanyEntity::getTenantId, tenantId)
|
||||
.eq(StringUtils.hasText(query.status()), ExpressCompanyEntity::getStatus, query.status())
|
||||
.and(StringUtils.hasText(query.keyword()), condition -> condition
|
||||
.like(ExpressCompanyEntity::getCompanyCode, query.keyword())
|
||||
|
||||
@@ -41,14 +41,17 @@ public class PartnerRepository {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public PageResult<PartnerEntity> page(long tenantId, PartnerPageQuery request) {
|
||||
List<Long> typedIds = typedIds(tenantId, request.type());
|
||||
if (StringUtils.hasText(request.type()) && typedIds.isEmpty()) {
|
||||
return new PageResult<>(List.of(), request.page(), request.size(), 0, 0);
|
||||
public PageResult<PartnerEntity> page(Long tenantId, PartnerPageQuery request) {
|
||||
if (StringUtils.hasText(request.type())) {
|
||||
Page<PartnerEntity> page = mapper.selectPartnerPageByType(
|
||||
new Page<>(request.page(), request.size()), tenantId, request.type(),
|
||||
request.status(), request.keyword());
|
||||
PageResult<PartnerEntity> result = PageResult.from(page);
|
||||
hydrateTypes(result.records());
|
||||
return result;
|
||||
}
|
||||
LambdaQueryWrapper<PartnerEntity> wrapper = new LambdaQueryWrapper<PartnerEntity>()
|
||||
.eq(PartnerEntity::getTenantId, tenantId)
|
||||
.in(StringUtils.hasText(request.type()), PartnerEntity::getId, typedIds)
|
||||
.eq(tenantId != null, PartnerEntity::getTenantId, tenantId)
|
||||
.eq(StringUtils.hasText(request.status()), PartnerEntity::getStatus, request.status())
|
||||
.and(StringUtils.hasText(request.keyword()), query -> query
|
||||
.like(PartnerEntity::getPartnerCode, request.keyword())
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ public class ExpressCompanyQueryService {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
public PageResult<ExpressCompanyEntity> page(long tenantId, ExpressCompanyPageQuery query) {
|
||||
public PageResult<ExpressCompanyEntity> page(Long tenantId, ExpressCompanyPageQuery query) {
|
||||
return repository.page(tenantId, query);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ public class PlatformPartnerQueryService {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
public PageResult<PartnerEntity> page(long tenantId, PartnerPageQuery query) {
|
||||
public PageResult<PartnerEntity> page(Long tenantId, PartnerPageQuery query) {
|
||||
return repository.page(tenantId, query);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user