This commit is contained in:
2026-09-20 13:16:44 +08:00
parent 380fd117c5
commit a138f3b916
14 changed files with 296 additions and 26 deletions
@@ -0,0 +1,81 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.transport.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.secure.constant.AuthConstant;
import org.springblade.core.tenant.annotation.TenantIgnore;
import org.springblade.core.tool.api.R;
import org.springblade.transport.pojo.vo.CustomerArchiveVO;
import org.springblade.transport.pojo.vo.CustomerChangeRecordVO;
import org.springblade.transport.service.ICustomerArchiveService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 客商档案公开查看 控制器
*
* @author Chill
*/
@RestController
@AllArgsConstructor
@TenantIgnore
@PreAuth(AuthConstant.PERMIT_ALL)
@RequestMapping("/customer-archive/public")
@Tag(name = "客商档案公开查看", description = "客商档案公开查看")
public class CustomerArchivePublicController {
private final ICustomerArchiveService customerArchiveService;
/**
* 公开详情
*/
@GetMapping("/detail")
@ApiOperationSupport(order = 1)
@Operation(summary = "公开详情", description = "传入id,无需登录")
public R<CustomerArchiveVO> detail(@Parameter(description = "主键", required = true) @RequestParam Long id) {
return R.data(customerArchiveService.publicDetail(id));
}
/**
* 公开变更记录分页
*/
@GetMapping("/change-record/list")
@ApiOperationSupport(order = 2)
@Operation(summary = "公开变更记录分页", description = "传入客商ID,无需登录")
public R<IPage<CustomerChangeRecordVO>> changeRecordList(
@Parameter(description = "客商ID", required = true) @RequestParam Long customerId, Query query) {
return R.data(customerArchiveService.publicChangeRecordPage(Condition.getPage(query), customerId));
}
}
@@ -66,6 +66,23 @@ public interface ICustomerArchiveService extends BaseService<CustomerArchive> {
*/
CustomerArchiveVO detail(Long id);
/**
* 公开查看详情(不校验登录态与数据权限)
*
* @param id 主键
* @return 客商档案详情
*/
CustomerArchiveVO publicDetail(Long id);
/**
* 公开查看变更记录分页(不校验登录态与数据权限)
*
* @param page 分页参数
* @param customerId 客商ID
* @return 变更记录分页
*/
IPage<CustomerChangeRecordVO> publicChangeRecordPage(IPage<CustomerChangeRecordVO> page, Long customerId);
/**
* 新增或修改客商档案
* <p>仅当 {@code customer.recordChange = true}(前端点「提交」)时写入变更记录;「保存」不落变更记录。</p>
@@ -32,6 +32,7 @@ import lombok.RequiredArgsConstructor;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tenant.annotation.TenantIgnore;
import org.springblade.core.tool.jackson.JsonUtil;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
@@ -151,31 +152,28 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
throw new ServiceException("客商ID不能为空");
}
ensureCustomerAccessible(customerId);
IPage<CustomerChangeRecord> recordPage = changeRecordMapper.selectPage(
new Page<>(page.getCurrent(), page.getSize()),
Wrappers.<CustomerChangeRecord>lambdaQuery()
.eq(CustomerChangeRecord::getCustomerId, customerId)
.eq(CustomerChangeRecord::getIsDeleted, 0)
.orderByDesc(CustomerChangeRecord::getChangeTime));
page.setTotal(recordPage.getTotal());
return page.setRecords(recordPage.getRecords().stream()
.map(record -> Objects.requireNonNull(BeanUtil.copyProperties(record, CustomerChangeRecordVO.class)))
.toList());
return queryChangeRecordPage(page, customerId);
}
@Override
@TenantIgnore
public IPage<CustomerChangeRecordVO> publicChangeRecordPage(IPage<CustomerChangeRecordVO> page, Long customerId) {
if (Func.isEmpty(customerId)) {
throw new ServiceException("客商ID不能为空");
}
getExistingCustomer(customerId);
return queryChangeRecordPage(page, customerId);
}
@Override
public CustomerArchiveVO detail(Long id) {
if (Func.isEmpty(id)) {
throw new ServiceException("主键不能为空");
}
CustomerArchive customer = ensureCustomerAccessible(id);
CustomerArchiveVO detail = Objects.requireNonNull(BeanUtil.copyProperties(customer, CustomerArchiveVO.class));
detail.setContacts(loadContacts(id));
detail.setReceiptAccounts(loadReceiptAccounts(id));
detail.setInvoices(loadInvoices(id));
detail.setScores(loadScores(id));
fillFundUseRisk(List.of(detail));
return detail;
return buildDetail(ensureCustomerAccessible(id));
}
@Override
@TenantIgnore
public CustomerArchiveVO publicDetail(Long id) {
return buildDetail(getExistingCustomer(id));
}
@Override
@@ -987,11 +985,43 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
return CUSTOMER_CODE_PREFIX + String.format("%06d", nextNumber);
}
private CustomerArchive ensureCustomerAccessible(Long id) {
private IPage<CustomerChangeRecordVO> queryChangeRecordPage(IPage<CustomerChangeRecordVO> page, Long customerId) {
IPage<CustomerChangeRecord> recordPage = changeRecordMapper.selectPage(
new Page<>(page.getCurrent(), page.getSize()),
Wrappers.<CustomerChangeRecord>lambdaQuery()
.eq(CustomerChangeRecord::getCustomerId, customerId)
.eq(CustomerChangeRecord::getIsDeleted, 0)
.orderByDesc(CustomerChangeRecord::getChangeTime));
page.setTotal(recordPage.getTotal());
return page.setRecords(recordPage.getRecords().stream()
.map(record -> Objects.requireNonNull(BeanUtil.copyProperties(record, CustomerChangeRecordVO.class)))
.toList());
}
private CustomerArchiveVO buildDetail(CustomerArchive customer) {
CustomerArchiveVO detail = Objects.requireNonNull(BeanUtil.copyProperties(customer, CustomerArchiveVO.class));
Long id = customer.getId();
detail.setContacts(loadContacts(id));
detail.setReceiptAccounts(loadReceiptAccounts(id));
detail.setInvoices(loadInvoices(id));
detail.setScores(loadScores(id));
fillFundUseRisk(List.of(detail));
return detail;
}
private CustomerArchive getExistingCustomer(Long id) {
if (Func.isEmpty(id)) {
throw new ServiceException("主键不能为空");
}
CustomerArchive customer = getById(id);
if (Func.isEmpty(customer) || Objects.equals(customer.getIsDeleted(), 1)) {
throw new ServiceException("客商档案不存在");
}
return customer;
}
private CustomerArchive ensureCustomerAccessible(Long id) {
CustomerArchive customer = getExistingCustomer(id);
if (baseMapper.selectCustomerPermissionCount(id, AuthUtil.getUserId()) == 0) {
throw new ServiceException("无权访问该客商档案");
}