feat:策略
This commit is contained in:
@@ -12,6 +12,8 @@ import cn.idev.excel.annotation.*;
|
||||
@ExcelIgnoreUnannotated
|
||||
public class WarehouseStrategyRespVO {
|
||||
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "库区编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("库区编码")
|
||||
private String sectionCode;
|
||||
|
||||
@@ -88,6 +88,14 @@ public class WarehouseStrategyConfigController {
|
||||
return success(BeanUtils.toBean(pageResult, WarehouseStrategyConfigRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping(value = {"/list-all-simple", "/simple-list"})
|
||||
@Operation(summary = "获得仓储策略配置精简列表")
|
||||
@PreAuthorize("@ss.hasPermission('wms:warehouse-strategy-config:query')")
|
||||
public CommonResult<List<WarehouseStrategyConfigSimpleRespVO>> getSimpleWarehouseStrategyConfigList() {
|
||||
List<WarehouseStrategyConfigDO> list = warehouseStrategyConfigService.getWarehouseStrategyConfigList();
|
||||
return success(BeanUtils.toBean(list, WarehouseStrategyConfigSimpleRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出仓储策略配置 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('wms:warehouse-strategy-config:export')")
|
||||
|
||||
@@ -12,6 +12,8 @@ import cn.idev.excel.annotation.*;
|
||||
@ExcelIgnoreUnannotated
|
||||
public class WarehouseStrategyConfigRespVO {
|
||||
|
||||
private String id;
|
||||
|
||||
@Schema(description = "策略编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("策略编码")
|
||||
private String strategyCode;
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.code.nl.module.wms.controller.admin.warehousestrategyconfig.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 仓储策略配置精简 Response VO")
|
||||
@Data
|
||||
public class WarehouseStrategyConfigSimpleRespVO {
|
||||
|
||||
@Schema(description = "策略编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String strategyCode;
|
||||
|
||||
@Schema(description = "策略名称", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String strategyName;
|
||||
|
||||
}
|
||||
@@ -17,6 +17,12 @@ import cn.code.nl.module.wms.controller.admin.warehousestrategyconfig.vo.*;
|
||||
@Mapper
|
||||
public interface WarehouseStrategyConfigMapper extends BaseMapperX<WarehouseStrategyConfigDO> {
|
||||
|
||||
default List<WarehouseStrategyConfigDO> selectList() {
|
||||
return selectList(new LambdaQueryWrapperX<WarehouseStrategyConfigDO>()
|
||||
.eq(WarehouseStrategyConfigDO::getIsUsed, true)
|
||||
.orderByDesc(WarehouseStrategyConfigDO::getId));
|
||||
}
|
||||
|
||||
default PageResult<WarehouseStrategyConfigDO> selectPage(WarehouseStrategyConfigPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<WarehouseStrategyConfigDO>()
|
||||
.eqIfPresent(WarehouseStrategyConfigDO::getStrategyCode, reqVO.getStrategyCode())
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package cn.code.nl.module.wms.manage;
|
||||
|
||||
import cn.code.nl.framework.common.exception.ServiceException;
|
||||
import cn.code.nl.module.wms.dal.dataobject.warehousestrategyconfig.WarehouseStrategyConfigDO;
|
||||
import cn.code.nl.module.wms.dal.mysql.warehousestrategyconfig.WarehouseStrategyConfigMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 仓储策略决策器抽象基类
|
||||
* <p>
|
||||
* 子类通过 {@code @Service("策略编码")} 注册为 Spring Bean,
|
||||
* 启动时根据 Bean 名称自动从数据库加载对应的策略配置。
|
||||
*
|
||||
* @param <T> 货位/库存数据类型
|
||||
* @param <P> 决策参数类型
|
||||
* @Author: liyongde
|
||||
* @Date: 2026/7/18 11:03
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class DecisionManage<T, P> implements InitializingBean, BeanNameAware {
|
||||
|
||||
/**
|
||||
* 当前策略的数据库配置,子类通过此字段读取策略参数
|
||||
*/
|
||||
public WarehouseStrategyConfigDO strategyConfig;
|
||||
|
||||
/**
|
||||
* Spring Bean 名称,即策略编码,对应 {@link WarehouseStrategyConfigDO#getStrategyCode()}
|
||||
*/
|
||||
private String beanName;
|
||||
|
||||
@Resource
|
||||
private WarehouseStrategyConfigMapper warehouseStrategyConfigMapper;
|
||||
|
||||
/**
|
||||
* 策略执行入口,由子类实现具体的货位分配逻辑
|
||||
*
|
||||
* @param list 候选货位/库存列表
|
||||
* @param param 决策参数(物料信息、出入库类型等)
|
||||
* @return 筛选/排序后的货位/库存列表
|
||||
*/
|
||||
public abstract List<T> handler(List<T> list, P param);
|
||||
|
||||
@Override
|
||||
public void setBeanName(@NonNull String name) {
|
||||
this.beanName = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Spring Bean 初始化时自动加载策略配置
|
||||
* <p>
|
||||
* 通过 BeanNameAware 获取策略编码,从数据库查询对应的策略配置记录。
|
||||
* 若数据库中无对应记录则抛出异常阻止启动,避免运行时才发现配置缺失。
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
this.strategyConfig = warehouseStrategyConfigMapper.selectOne(
|
||||
WarehouseStrategyConfigDO::getStrategyCode, beanName);
|
||||
if (this.strategyConfig == null) {
|
||||
log.error("策略 [{}] 初始化失败:数据库中未找到对应的策略配置记录", beanName);
|
||||
throw new ServiceException(500, "启动失败:当前策略 " + beanName + " 没有实例信息");
|
||||
}
|
||||
log.info("策略 [{}] 初始化成功,策略名称:{}", beanName, strategyConfig.getStrategyName());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package cn.code.nl.module.wms.manage.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*
|
||||
* @Author: liyongde
|
||||
* @Date: 2026/7/18 13:41
|
||||
*/
|
||||
@Data
|
||||
public class DemoDTO {
|
||||
private String id;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.code.nl.module.wms.manage.handle;
|
||||
|
||||
import cn.code.nl.module.wms.manage.DecisionManage;
|
||||
import cn.code.nl.module.wms.manage.dto.DemoDTO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @Author: liyongde
|
||||
* @Date: 2026/7/18 13:39
|
||||
*/
|
||||
@Slf4j
|
||||
@Service("alleyAve")
|
||||
public class AlleyAveRuleHandler extends DecisionManage<DemoDTO, JSONObject> {
|
||||
@Override
|
||||
public List<DemoDTO> handler(List<DemoDTO> list, JSONObject param) {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
@@ -59,4 +59,11 @@ public interface WarehouseStrategyConfigService {
|
||||
*/
|
||||
PageResult<WarehouseStrategyConfigDO> getWarehouseStrategyConfigPage(WarehouseStrategyConfigPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得仓储策略配置列表(仅启用的)
|
||||
*
|
||||
* @return 仓储策略配置列表
|
||||
*/
|
||||
List<WarehouseStrategyConfigDO> getWarehouseStrategyConfigList();
|
||||
|
||||
}
|
||||
@@ -77,4 +77,9 @@ public class WarehouseStrategyConfigServiceImpl implements WarehouseStrategyConf
|
||||
return warehouseStrategyConfigMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WarehouseStrategyConfigDO> getWarehouseStrategyConfigList() {
|
||||
return warehouseStrategyConfigMapper.selectList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { PageParam, PageResult } from '@vben/request';
|
||||
import type { Dayjs } from 'dayjs';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace WmsWarehouseStrategyApi {
|
||||
/** 出入库策略信息 */
|
||||
export interface WarehouseStrategy {
|
||||
id?: number;
|
||||
sectionCode?: string; // 库区编码
|
||||
strategy?: string; // 规则
|
||||
strategyType: string; // 策略类型
|
||||
|
||||
@@ -16,6 +16,12 @@ export namespace WmsWarehouseStrategyConfigApi {
|
||||
ban: boolean; // 禁止操作
|
||||
formData: string; // 限定参数
|
||||
}
|
||||
|
||||
/** 仓储策略配置精简信息 */
|
||||
export interface WarehouseStrategyConfigSimple {
|
||||
strategyCode: string; // 策略编码
|
||||
strategyName: string; // 策略名称
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询仓储策略配置分页 */
|
||||
@@ -60,4 +66,11 @@ export function exportWarehouseStrategyConfig(params: any) {
|
||||
return requestClient.download('/wms/warehouse-strategy-config/export-excel', { params });
|
||||
}
|
||||
|
||||
/** 查询仓储策略配置精简列表 */
|
||||
export function getWarehouseStrategyConfigSimpleList() {
|
||||
return requestClient.get<WmsWarehouseStrategyConfigApi.WarehouseStrategyConfigSimple[]>(
|
||||
'/wms/warehouse-strategy-config/simple-list',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,10 +2,18 @@ import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { WmsWarehouseStrategyApi } from '#/api/wms/warehousestrategy';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { getRangePickerDefaultProps } from '#/utils';
|
||||
import {getDictOptions} from "@vben/hooks";
|
||||
import {DICT_TYPE} from "@vben/constants";
|
||||
|
||||
/** 策略配置选项(供表单多选和列表显示使用) */
|
||||
export const strategyConfigOptions = ref<{ label: string; value: string }[]>([]);
|
||||
|
||||
/** 策略编码 -> 名称的映射 */
|
||||
export const strategyNameMap = ref<Record<string, string>>({});
|
||||
|
||||
/** 新增/修改的表单 */
|
||||
export function useFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
@@ -39,9 +47,11 @@ export function useFormSchema(): VbenFormSchema[] {
|
||||
fieldName: 'strategy',
|
||||
label: '规则',
|
||||
rules: 'required',
|
||||
component: 'Input',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请输入规则',
|
||||
mode: 'multiple',
|
||||
options: strategyConfigOptions,
|
||||
placeholder: '请选择规则',
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -110,7 +120,8 @@ export function useGridColumns(): VxeTableGridOptions<WmsWarehouseStrategyApi.Wa
|
||||
{
|
||||
field: 'strategy',
|
||||
title: '规则',
|
||||
minWidth: 120,
|
||||
minWidth: 200,
|
||||
slots: { default: 'strategy' },
|
||||
},
|
||||
{
|
||||
field: 'strategyType',
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { WmsWarehouseStrategyApi } from '#/api/wms/warehousestrategy';
|
||||
|
||||
import { ref } from 'vue';
|
||||
import { onMounted, ref } from 'vue';
|
||||
|
||||
import { confirm, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
||||
@@ -16,9 +16,10 @@ import {
|
||||
exportWarehouseStrategy,
|
||||
getWarehouseStrategyPage,
|
||||
} from '#/api/wms/warehousestrategy';
|
||||
import { getWarehouseStrategyConfigSimpleList } from '#/api/wms/warehousestrategyconfig';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import { strategyConfigOptions, strategyNameMap, useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
@@ -26,6 +27,37 @@ const [FormModal, formModalApi] = useVbenModal({
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 将 strategy JSON 字符串解析为显示名称 */
|
||||
function resolveStrategyNames(strategy?: string): string {
|
||||
if (!strategy) return '';
|
||||
try {
|
||||
const arr = JSON.parse(strategy);
|
||||
if (!Array.isArray(arr)) return strategy;
|
||||
return arr.map((code: string) => strategyNameMap.value[code] || code).join('、');
|
||||
} catch {
|
||||
return strategy;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
if (strategyConfigOptions.value.length === 0) {
|
||||
try {
|
||||
const configList = await getWarehouseStrategyConfigSimpleList();
|
||||
strategyConfigOptions.value = configList.map((item) => ({
|
||||
label: `${item.strategyName}(${item.strategyCode})`,
|
||||
value: item.strategyCode,
|
||||
}));
|
||||
const map: Record<string, string> = {};
|
||||
configList.forEach((item) => {
|
||||
map[item.strategyCode] = item.strategyName;
|
||||
});
|
||||
strategyNameMap.value = map;
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
@@ -157,6 +189,9 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #strategy="{ row }">
|
||||
{{ resolveStrategyNames(row.strategy) }}
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
|
||||
@@ -9,9 +9,10 @@ import { message } from 'antdv-next';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { createWarehouseStrategy, getWarehouseStrategy, updateWarehouseStrategy } from '#/api/wms/warehousestrategy';
|
||||
import { getWarehouseStrategyConfigSimpleList } from '#/api/wms/warehousestrategyconfig';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
import { strategyConfigOptions, strategyNameMap, useFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<WmsWarehouseStrategyApi.WarehouseStrategy>();
|
||||
@@ -21,6 +22,23 @@ const getTitle = computed(() => {
|
||||
: $t('ui.actionTitle.create', ['出入库策略']);
|
||||
});
|
||||
|
||||
/** 解析 strategy JSON 字符串为数组 */
|
||||
function parseStrategy(strategy?: string): string[] {
|
||||
if (!strategy) return [];
|
||||
try {
|
||||
const parsed = JSON.parse(strategy);
|
||||
return Array.isArray(parsed) ? parsed : [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/** 将 strategy 数组转为 JSON 字符串 */
|
||||
function stringifyStrategy(arr?: string[]): string {
|
||||
if (!arr || arr.length === 0) return '[]';
|
||||
return JSON.stringify(arr);
|
||||
}
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
@@ -43,6 +61,8 @@ const [Modal, modalApi] = useVbenModal({
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as WmsWarehouseStrategyApi.WarehouseStrategy;
|
||||
// 将 strategy 数组转为 JSON 字符串存储
|
||||
data.strategy = stringifyStrategy(data.strategy as unknown as string[]);
|
||||
try {
|
||||
await (formData.value?.id ? updateWarehouseStrategy(data) : createWarehouseStrategy(data));
|
||||
// 关闭并提示
|
||||
@@ -58,6 +78,24 @@ const [Modal, modalApi] = useVbenModal({
|
||||
formData.value = undefined;
|
||||
return;
|
||||
}
|
||||
// 加载策略配置选项(首次加载)
|
||||
if (strategyConfigOptions.value.length === 0) {
|
||||
try {
|
||||
const configList = await getWarehouseStrategyConfigSimpleList();
|
||||
strategyConfigOptions.value = configList.map((item) => ({
|
||||
label: `${item.strategyName}(${item.strategyCode})`,
|
||||
value: item.strategyCode,
|
||||
}));
|
||||
// 构建编码 -> 名称映射
|
||||
const map: Record<string, string> = {};
|
||||
configList.forEach((item) => {
|
||||
map[item.strategyCode] = item.strategyName;
|
||||
});
|
||||
strategyNameMap.value = map;
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
// 加载数据
|
||||
const data = modalApi.getData<WmsWarehouseStrategyApi.WarehouseStrategy>();
|
||||
if (!data || !data.id) {
|
||||
@@ -66,6 +104,8 @@ const [Modal, modalApi] = useVbenModal({
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getWarehouseStrategy(data.id);
|
||||
// 将 strategy JSON 字符串解析为数组供多选组件使用
|
||||
formData.value.strategy = parseStrategy(formData.value.strategy) as unknown as string;
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { WmsWarehouseStrategyConfigApi } from '#/api/wms/warehousestrategyc
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
import { getRangePickerDefaultProps } from '#/utils';
|
||||
import {CommonStatusEnum, DICT_TYPE} from "@vben/constants";
|
||||
import { CommonTrueOrFalseEnum, DICT_TYPE} from "@vben/constants";
|
||||
|
||||
/** 新增/修改的表单 */
|
||||
export function useFormSchema(): VbenFormSchema[] {
|
||||
@@ -79,22 +79,22 @@ export function useFormSchema(): VbenFormSchema[] {
|
||||
label: '是否启用',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
options: getDictOptions(DICT_TYPE.COMMON_TRUE_FALSE, 'boolean'),
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
rules: z.number().default(CommonStatusEnum.ENABLE),
|
||||
rules: z.boolean().default(CommonTrueOrFalseEnum.TRUE),
|
||||
},
|
||||
{
|
||||
fieldName: 'ban',
|
||||
label: '禁止操作',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
options: getDictOptions(DICT_TYPE.COMMON_TRUE_FALSE, 'boolean'),
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
rules: z.number().default(CommonStatusEnum.DISABLE),
|
||||
rules: z.boolean().default(CommonTrueOrFalseEnum.FALSE),
|
||||
},
|
||||
{
|
||||
fieldName: 'formData',
|
||||
|
||||
@@ -5,6 +5,12 @@ export const CommonStatusEnum = {
|
||||
DISABLE: 1, // 禁用
|
||||
};
|
||||
|
||||
// true or false
|
||||
export const CommonTrueOrFalseEnum = {
|
||||
TRUE: true,
|
||||
FALSE: false,
|
||||
};
|
||||
|
||||
// 全局用户类型枚举
|
||||
export const UserTypeEnum = {
|
||||
MEMBER: 1, // 会员
|
||||
|
||||
Reference in New Issue
Block a user