This commit is contained in:
2026-08-11 20:39:28 +08:00
parent 86488da6d0
commit b2af5739c8
15 changed files with 247 additions and 7 deletions
Vendored
+3 -1
View File
@@ -1,5 +1,5 @@
def serviceModules = [
'gateway', 'auth', 'iam', 'firstleg', 'order', 'warehouse', 'file', 'print',
'gateway', 'auth', 'iam', 'firstleg', 'finance', 'order', 'warehouse', 'file', 'print',
'integration-service', 'event-bridge-service', 'audit-service'
]
@@ -8,6 +8,7 @@ def serviceCheckboxes = [
'auth': 'SERVICE_AUTH',
'iam': 'SERVICE_IAM',
'firstleg': 'SERVICE_FIRSTLEG',
'finance': 'SERVICE_FINANCE',
'order': 'SERVICE_ORDER',
'warehouse': 'SERVICE_WAREHOUSE',
'file': 'SERVICE_FILE',
@@ -41,6 +42,7 @@ pipeline {
booleanParam(name: 'SERVICE_AUTH', defaultValue: false, description: '统一认证服务(auth)')
booleanParam(name: 'SERVICE_IAM', defaultValue: false, description: '租户与权限服务(iam)')
booleanParam(name: 'SERVICE_FIRSTLEG', defaultValue: false, description: '头程履约服务(firstleg)')
booleanParam(name: 'SERVICE_FINANCE', defaultValue: false, description: '财务服务(finance)')
booleanParam(name: 'SERVICE_ORDER', defaultValue: false, description: '订单服务(order)')
booleanParam(name: 'SERVICE_WAREHOUSE', defaultValue: false, description: '仓库与往来单位服务(warehouse)')
booleanParam(name: 'SERVICE_FILE', defaultValue: false, description: '文件中心(file)')
+2 -1
View File
@@ -1,5 +1,5 @@
def serviceModules = [
'gateway', 'auth', 'iam', 'firstleg', 'order', 'warehouse', 'file', 'print',
'gateway', 'auth', 'iam', 'firstleg', 'finance', 'order', 'warehouse', 'file', 'print',
'integration-service', 'event-bridge-service', 'audit-service'
]
@@ -8,6 +8,7 @@ def serviceJars = [
'auth': 'auth/target/auth-service-1.0.0-SNAPSHOT.jar',
'iam': 'iam/target/iam-service-1.0.0-SNAPSHOT.jar',
'firstleg': 'firstleg/target/firstleg-service-1.0.0-SNAPSHOT.jar',
'finance': 'finance/target/finance-service-1.0.0-SNAPSHOT.jar',
'order': 'order/target/order-service-1.0.0-SNAPSHOT.jar',
'warehouse': 'warehouse/target/warehouse-service-1.0.0-SNAPSHOT.jar',
'file': 'file/target/file-service-1.0.0-SNAPSHOT.jar',
+13
View File
@@ -86,6 +86,19 @@ services:
FIRSTLEG_DB_USERNAME: ${FIRSTLEG_DB_USERNAME}
FIRSTLEG_DB_PASSWORD: ${FIRSTLEG_DB_PASSWORD}
finance:
<<: *common
image: ${IMAGE_REPOSITORY}/finance:${IMAGE_TAG}
container_name: firstleg-${DEPLOY_ENV:-test}-finance
ports: ["${FINANCE_PORT:-9203}:9203"]
volumes: ["${LOG_ROOT:-/data/logs/baiyue-firstleg}/finance:/app/logs"]
environment:
<<: *common-environment
SERVER_PORT: 9203
FINANCE_DB_URL: ${FINANCE_DB_URL}
FINANCE_DB_USERNAME: ${FINANCE_DB_USERNAME}
FINANCE_DB_PASSWORD: ${FINANCE_DB_PASSWORD}
order:
<<: *common
image: ${IMAGE_REPOSITORY}/order:${IMAGE_TAG}
+11
View File
@@ -27,6 +27,17 @@ env_file_value() {
sed -n "s/^$1=//p" "$ENV_FILE" | tail -n 1 | tr -d '\r'
}
case " $SERVICES " in
*" finance "*)
for key in FINANCE_DB_URL FINANCE_DB_USERNAME FINANCE_DB_PASSWORD; do
if ! env_file_has_key "$key" || [ -z "$(env_file_value "$key")" ]; then
echo "部署 finance 服务时,环境文件必须包含非空 $key" >&2
exit 2
fi
done
;;
esac
case " $SERVICES " in
*" file "*)
if ! env_file_has_key ROCKETMQ_NAME_SERVER || [ -z "$(env_file_value ROCKETMQ_NAME_SERVER)" ]; then
+1 -1
View File
@@ -43,7 +43,7 @@ services:
artifactId: audit-service
jar: audit-service/target/audit-service-1.0.0-SNAPSHOT.jar
port: 9700
finance-service:
finance:
artifactId: finance-service
jar: finance/target/finance-service-1.0.0-SNAPSHOT.jar
port: 9203
@@ -11,6 +11,7 @@ import com.baiyue.firstleg.dto.LoadingPickDtos.ReviewRequest;
import com.baiyue.firstleg.dto.LoadingPickDtos.Operation;
import com.baiyue.firstleg.dto.LoadingPickDtos.BatchRequest;
import com.baiyue.firstleg.dto.LoadingPickDtos.InventorySnapshot;
import com.baiyue.firstleg.dto.LoadingPickDtos.PendingTask;
import java.util.List;
import com.baiyue.firstleg.dto.LoadingPickDtos.Task;
import com.baiyue.firstleg.service.FirstlegScopeGuard;
@@ -49,6 +50,15 @@ public class PlatformLoadingPdaController {
return ApiResponse.success(service.task(containerNo, warehouseId));
}
@GetMapping("/tasks/pending")
@PreAuthorize("hasAuthority('platform:firstleg:pda:view')")
public ApiResponse<List<PendingTask>> pendingTasks(@AuthenticationPrincipal AuthenticatedUser user,
@RequestParam(required = false)
@Size(max = 64) String keyword) {
FirstlegScopeGuard.platform(user);
return ApiResponse.success(service.pendingTasks(user.userId(), keyword));
}
@GetMapping("/tasks/{taskId}/inventory-snapshot")
@PreAuthorize("hasAuthority('platform:firstleg:pda:view')")
public ApiResponse<InventorySnapshot> inventorySnapshot(@AuthenticationPrincipal AuthenticatedUser user,
@@ -99,6 +99,7 @@ public final class LoadingPickDtos {
}
public record PickItem(Long id, Long loadingPlanItemId, Long inboundId, Long inboundDetailId,
String orderNo, String inboundCode, String cargoName, List<String> boxCodes,
Integer plannedPackageCount, Integer pickedPackageCount,
String itemStatus, Integer version) {
}
@@ -120,6 +121,13 @@ public final class LoadingPickDtos {
Review review, List<PickItem> items) {
}
/** PDA 工作台只展示当前作业员可领取或已领取的进行中任务。 */
public record PendingTask(Long taskId, Long loadingPlanId, String containerNo,
Long warehouseId, String warehouseName, String taskStatus,
String workflowStatus, Integer version, Integer assignmentVersion,
Integer itemCount, Integer pendingItemCount) {
}
public record InventoryResource(Long reservationId, Long occupancyId, Long palletId,
Long locationId, String locationCode, Boolean sharedOverflow,
Integer availablePackageCount) {
@@ -7,8 +7,32 @@ import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;
@Mapper
public interface LoadingPickItemMapper extends BaseMapper<LoadingPickItemEntity> {
@Select("""
SELECT pick_item.id AS pickItemId, plan_item.order_no AS orderNo,
plan_item.inbound_code AS inboundCode, label.cargo_name AS cargoName,
label.box_code AS boxCode
FROM fl_loading_pick_item pick_item
JOIN fl_loading_plan_item plan_item ON plan_item.id = pick_item.loading_plan_item_id
JOIN fl_inbound_carton_label label ON label.tenant_id = plan_item.account_id
AND label.inbound_id = plan_item.inbound_id
AND label.inbound_detail_id = plan_item.inbound_detail_id
WHERE pick_item.pick_task_id = #{taskId} AND plan_item.deleted = 0
ORDER BY pick_item.id, label.carton_index
""")
List<CartonLabelRow> selectTaskCartonLabels(@Param("taskId") long taskId);
interface CartonLabelRow {
Long getPickItemId();
String getOrderNo();
String getInboundCode();
String getCargoName();
String getBoxCode();
}
@Update("UPDATE fl_loading_plan_item SET package_count=#{pickedCount},updated_by=#{operatorId},"
+ "updated_by_name=#{operatorName},version=version+1 WHERE id=#{planItemId} AND deleted=0 "
+ "AND package_count=#{plannedCount}")
@@ -7,6 +7,8 @@ import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;
@Mapper
public interface LoadingPickTaskMapper extends BaseMapper<LoadingPickTaskEntity> {
@Select("SELECT * FROM fl_loading_pick_task WHERE id=#{taskId} FOR UPDATE")
@@ -28,4 +30,48 @@ public interface LoadingPickTaskMapper extends BaseMapper<LoadingPickTaskEntity>
""")
LoadingPickTaskEntity selectLoadingByContainerAndAccount(@Param("containerNo") String containerNo,
@Param("warehouseId") long warehouseId);
@Select("""
<script>
SELECT task.id AS taskId, task.loading_plan_id AS loadingPlanId,
task.container_no AS containerNo, booking.warehouse_id AS warehouseId,
booking.warehouse_name AS warehouseName, task.task_status AS taskStatus,
CASE WHEN assignment.pick_task_id IS NULL THEN 'UNASSIGNED' ELSE 'IN_PROGRESS' END AS workflowStatus,
task.version AS version, COALESCE(assignment.version, 0) AS assignmentVersion,
COUNT(pick_item.id) AS itemCount,
SUM(CASE WHEN pick_item.item_status IN ('PENDING', 'PICKING') THEN 1 ELSE 0 END) AS pendingItemCount
FROM fl_loading_pick_task task
JOIN fl_loading_plan plan ON plan.id = task.loading_plan_id
JOIN fl_container_booking booking ON booking.id = plan.container_booking_id
JOIN fl_loading_pick_item pick_item ON pick_item.pick_task_id = task.id
LEFT JOIN fl_loading_pick_assignment assignment ON assignment.pick_task_id = task.id
WHERE task.task_status = 'LOADING'
AND (assignment.pick_task_id IS NULL OR assignment.assignee_id = #{operatorId})
<if test="keyword != null and keyword != ''">
AND (task.container_no LIKE CONCAT('%', #{keyword}, '%')
OR booking.warehouse_name LIKE CONCAT('%', #{keyword}, '%'))
</if>
GROUP BY task.id, task.loading_plan_id, task.container_no, booking.warehouse_id,
booking.warehouse_name, task.task_status, task.version,
assignment.pick_task_id, assignment.version
ORDER BY task.id DESC
LIMIT 100
</script>
""")
List<PendingTaskRow> selectPendingForOperator(@Param("operatorId") long operatorId,
@Param("keyword") String keyword);
interface PendingTaskRow {
Long getTaskId();
Long getLoadingPlanId();
String getContainerNo();
Long getWarehouseId();
String getWarehouseName();
String getTaskStatus();
String getWorkflowStatus();
Integer getVersion();
Integer getAssignmentVersion();
Integer getItemCount();
Integer getPendingItemCount();
}
}
@@ -7,7 +7,9 @@ import com.baiyue.firstleg.entity.LoadingPickTaskEntity;
import com.baiyue.firstleg.mapper.LoadingPickHistoryMapper;
import com.baiyue.firstleg.entity.LoadingPlanItemEntity;
import com.baiyue.firstleg.mapper.LoadingPickItemMapper;
import com.baiyue.firstleg.mapper.LoadingPickItemMapper.CartonLabelRow;
import com.baiyue.firstleg.mapper.LoadingPickTaskMapper;
import com.baiyue.firstleg.mapper.LoadingPickTaskMapper.PendingTaskRow;
import com.baiyue.firstleg.mapper.LoadingPickAssignmentMapper;
import com.baiyue.firstleg.mapper.LoadingPickOperationMapper;
import com.baiyue.firstleg.mapper.LoadingPickReviewMapper;
@@ -66,6 +68,10 @@ public class LoadingPickRepository {
return tasks.selectLoadingByContainerAndAccount(containerNo, warehouseId);
}
public List<PendingTaskRow> pendingTasks(long operatorId, String keyword) {
return tasks.selectPendingForOperator(operatorId, keyword);
}
public LoadingPickItemEntity item(long taskId, long itemId) {
return items.selectOne(new LambdaQueryWrapper<LoadingPickItemEntity>()
.eq(LoadingPickItemEntity::getPickTaskId, taskId)
@@ -78,6 +84,10 @@ public class LoadingPickRepository {
.orderByAsc(LoadingPickItemEntity::getId));
}
public List<CartonLabelRow> cartonLabels(long taskId) {
return items.selectTaskCartonLabels(taskId);
}
public List<LoadingPickItemEntity> items(long taskId, long warehouseId) {
return items.selectTaskItemsWithAccount(taskId, warehouseId);
}
@@ -20,6 +20,7 @@ import com.baiyue.firstleg.dto.LoadingPickDtos.BatchItemRequest;
import com.baiyue.firstleg.dto.LoadingPickDtos.InventoryResource;
import com.baiyue.firstleg.dto.LoadingPickDtos.InboundInventory;
import com.baiyue.firstleg.dto.LoadingPickDtos.InventorySnapshot;
import com.baiyue.firstleg.dto.LoadingPickDtos.PendingTask;
import com.baiyue.firstleg.entity.LoadingPickAssignmentEntity;
import com.baiyue.firstleg.entity.LoadingPickHistoryEntity;
import com.baiyue.firstleg.entity.LoadingPickItemEntity;
@@ -28,6 +29,7 @@ import com.baiyue.firstleg.entity.LoadingPickReviewEntity;
import com.baiyue.firstleg.entity.LoadingPickTaskEntity;
import com.baiyue.firstleg.entity.LoadingPlanItemEntity;
import com.baiyue.firstleg.entity.LoadingPlanHistoryEntity;
import com.baiyue.firstleg.mapper.LoadingPickItemMapper.CartonLabelRow;
import com.baiyue.firstleg.repository.LoadingPickRepository;
import com.baiyue.firstleg.repository.SmartLoadingRepository;
import jakarta.annotation.Resource;
@@ -119,6 +121,15 @@ public class LoadingPickService {
return view(task, warehouseId);
}
public List<PendingTask> pendingTasks(long operatorId, String keyword) {
String normalizedKeyword = StringUtils.hasText(keyword) ? keyword.trim() : null;
return repository.pendingTasks(operatorId, normalizedKeyword).stream()
.map(row -> new PendingTask(row.getTaskId(), row.getLoadingPlanId(), row.getContainerNo(),
row.getWarehouseId(), row.getWarehouseName(), row.getTaskStatus(), row.getWorkflowStatus(),
row.getVersion(), row.getAssignmentVersion(), row.getItemCount(), row.getPendingItemCount()))
.toList();
}
public InventorySnapshot inventorySnapshot(long taskId, long warehouseId) {
LoadingPickTaskEntity task = requiredTask(taskId);
List<LoadingPickItemEntity> items = warehouseScopedItems(task, warehouseId);
@@ -475,10 +486,17 @@ public class LoadingPickService {
private Task view(LoadingPickTaskEntity task, Long warehouseId) {
List<LoadingPickItemEntity> source = warehouseId == null
? repository.items(task.getId()) : repository.items(task.getId(), warehouseId);
List<PickItem> items = source.stream()
.map(item -> new PickItem(item.getId(), item.getLoadingPlanItemId(), item.getInboundId(),
item.getInboundDetailId(), item.getPlannedPackageCount(), item.getPickedPackageCount(),
item.getItemStatus(), item.getVersion())).toList();
Map<Long, List<CartonLabelRow>> cartonsByItem = repository.cartonLabels(task.getId()).stream()
.collect(Collectors.groupingBy(CartonLabelRow::getPickItemId));
List<PickItem> items = source.stream().map(item -> {
List<CartonLabelRow> cartons = cartonsByItem.getOrDefault(item.getId(), List.of());
CartonLabelRow first = cartons.isEmpty() ? null : cartons.get(0);
return new PickItem(item.getId(), item.getLoadingPlanItemId(), item.getInboundId(),
item.getInboundDetailId(), first == null ? null : first.getOrderNo(),
first == null ? null : first.getInboundCode(), first == null ? null : first.getCargoName(),
cartons.stream().map(CartonLabelRow::getBoxCode).toList(), item.getPlannedPackageCount(),
item.getPickedPackageCount(), item.getItemStatus(), item.getVersion());
}).toList();
LoadingPickAssignmentEntity assigned = repository.assignment(task.getId());
LoadingPickReviewEntity reviewed = repository.review(task.getId());
Assignment assignment = assigned == null ? null : new Assignment(assigned.getAssigneeId(),
@@ -11,6 +11,19 @@ paths:
- {name: warehouseId, in: query, required: true, schema: {type: integer, format: int64, minimum: 1}}
responses:
'200': {description: Task with assignment, review and item-level versions}
/api/platform/v1/first-leg/pda-loading/tasks/pending:
get:
summary: List active tasks available to the authenticated PDA operator
parameters:
- {name: keyword, in: query, required: false, schema: {type: string, maxLength: 64}}
responses:
'200':
description: Unassigned tasks and tasks assigned to the current operator; no customer selector required
content:
application/json:
schema:
type: array
items: {$ref: '#/components/schemas/PendingTask'}
/api/platform/v1/first-leg/pda-loading/tasks/{taskId}/claim:
post:
summary: Atomically claim an unassigned task for the authenticated operator
@@ -85,6 +98,21 @@ components:
TaskId: {name: taskId, in: path, required: true, schema: {type: integer, format: int64, minimum: 1}}
ItemId: {name: itemId, in: path, required: true, schema: {type: integer, format: int64, minimum: 1}}
schemas:
PendingTask:
type: object
required: [taskId, loadingPlanId, containerNo, warehouseId, taskStatus, workflowStatus, version, assignmentVersion, itemCount, pendingItemCount]
properties:
taskId: {type: integer, format: int64}
loadingPlanId: {type: integer, format: int64}
containerNo: {type: string}
warehouseId: {type: integer, format: int64}
warehouseName: {type: string, nullable: true}
taskStatus: {type: string, enum: [LOADING]}
workflowStatus: {type: string, enum: [UNASSIGNED, IN_PROGRESS]}
version: {type: integer, minimum: 0}
assignmentVersion: {type: integer, minimum: 0}
itemCount: {type: integer, minimum: 1}
pendingItemCount: {type: integer, minimum: 0}
ClaimRequest:
type: object
required: [expectedAssignmentVersion, operationId]
@@ -13,6 +13,7 @@ class PlatformLoadingPdaControllerContractTest {
@Test
void exposesAssignmentWorkAndReviewWithDedicatedAuthorities() throws Exception {
authority("task", "platform:firstleg:pda:view", AuthenticatedUser.class, String.class, long.class);
authority("pendingTasks", "platform:firstleg:pda:view", AuthenticatedUser.class, String.class);
authority("inventorySnapshot", "platform:firstleg:pda:view", AuthenticatedUser.class, long.class, long.class);
authority("claim", "platform:firstleg:pda:work", AuthenticatedUser.class, long.class, ClaimRequest.class);
authority("assign", "platform:firstleg:pda:assign", AuthenticatedUser.class, long.class, AssignRequest.class);
@@ -0,0 +1,37 @@
package com.baiyue.firstleg.repository;
import com.baiyue.firstleg.mapper.LoadingPickItemMapper;
import com.baiyue.firstleg.mapper.LoadingPickTaskMapper;
import org.apache.ibatis.annotations.Select;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class LoadingPickPdaTaskSqlContractTest {
@Test
void pendingTasksAreLimitedToUnassignedOrCurrentOperatorWithoutCustomerInput() throws Exception {
String sql = LoadingPickTaskMapper.class
.getDeclaredMethod("selectPendingForOperator", long.class, String.class)
.getAnnotation(Select.class).value()[0];
assertThat(sql)
.contains("task.task_status = 'LOADING'")
.contains("assignment.pick_task_id IS NULL OR assignment.assignee_id = #{operatorId}")
.contains("booking.warehouse_id AS warehouseId")
.doesNotContain("tenantId");
}
@Test
void taskDetailsExposeStableCartonCodesBoundToThePlannedInboundDetail() throws Exception {
String sql = LoadingPickItemMapper.class
.getDeclaredMethod("selectTaskCartonLabels", long.class)
.getAnnotation(Select.class).value()[0];
assertThat(sql)
.contains("fl_inbound_carton_label")
.contains("label.tenant_id = plan_item.account_id")
.contains("label.inbound_id = plan_item.inbound_id")
.contains("label.inbound_detail_id = plan_item.inbound_detail_id")
.contains("label.box_code AS boxCode");
}
}
@@ -0,0 +1,31 @@
import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import test from 'node:test'
const read = async (path) => (await readFile(new URL(`../${path}`, import.meta.url), 'utf8'))
.replaceAll('\r\n', '\n')
test('Jenkins pipelines build finance as an independent service', async () => {
const controller = await read('Jenkinsfile')
const service = await read('Jenkinsfile.service')
assert.match(controller, /'gateway', 'auth', 'iam', 'firstleg', 'finance'/)
assert.match(controller, /'finance': 'SERVICE_FINANCE'/)
assert.match(controller, /booleanParam\(name: 'SERVICE_FINANCE'/)
assert.match(service, /'gateway', 'auth', 'iam', 'firstleg', 'finance'/)
assert.match(service, /'finance': 'finance\/target\/finance-service-1\.0\.0-SNAPSHOT\.jar'/)
})
test('Compose and deploy script expose finance with fail-closed database config', async () => {
const compose = await read('deploy/docker-compose.yml')
const serviceMap = await read('deploy/service-map.yml')
const deployScript = await read('deploy/scripts/deploy-services.sh')
assert.match(compose, /^ finance:\s*$/m)
assert.match(compose, /image: \$\{IMAGE_REPOSITORY\}\/finance:\$\{IMAGE_TAG\}/)
assert.match(compose, /SERVER_PORT: 9203/)
assert.match(compose, /FINANCE_DB_URL: \$\{FINANCE_DB_URL\}/)
assert.match(serviceMap, /^ finance:\s*$/m)
assert.match(serviceMap, /jar: finance\/target\/finance-service-1\.0\.0-SNAPSHOT\.jar/)
assert.match(deployScript, /FINANCE_DB_URL FINANCE_DB_USERNAME FINANCE_DB_PASSWORD/)
})