diff --git a/nl-module-base/nl-module-base-api/src/main/java/cn/code/nl/module/base/enums/ErrorCodeConstants.java b/nl-module-base/nl-module-base-api/src/main/java/cn/code/nl/module/base/enums/ErrorCodeConstants.java index cf79db85..7305fce8 100644 --- a/nl-module-base/nl-module-base-api/src/main/java/cn/code/nl/module/base/enums/ErrorCodeConstants.java +++ b/nl-module-base/nl-module-base-api/src/main/java/cn/code/nl/module/base/enums/ErrorCodeConstants.java @@ -14,4 +14,7 @@ public interface ErrorCodeConstants { ErrorCode CLASSSTANDARD_PARENT_ERROR = new ErrorCode(5, "不能设置自己为父分类"); ErrorCode CLASSSTANDARD_PARENT_IS_CHILD = new ErrorCode(6, "不能设置自己的子分类为父分类"); ErrorCode CLASSSTANDARD_EXISTS_CHILDREN = new ErrorCode(7, "存在子分类,无法删除"); + + // ========== 计量单位 ========== + ErrorCode MEASURE_UNIT_NOT_EXISTS = new ErrorCode(8, "计量单位不存在"); } diff --git a/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/controller/admin/measureunit/MeasureUnitController.java b/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/controller/admin/measureunit/MeasureUnitController.java new file mode 100644 index 00000000..5e646462 --- /dev/null +++ b/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/controller/admin/measureunit/MeasureUnitController.java @@ -0,0 +1,111 @@ +package cn.code.nl.module.base.controller.admin.measureunit; + +import org.springframework.web.bind.annotation.*; +import jakarta.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import jakarta.validation.constraints.*; +import jakarta.validation.*; +import jakarta.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.code.nl.framework.common.pojo.PageParam; +import cn.code.nl.framework.common.pojo.PageResult; +import cn.code.nl.framework.common.pojo.CommonResult; +import cn.code.nl.framework.common.util.object.BeanUtils; +import static cn.code.nl.framework.common.pojo.CommonResult.success; + +import cn.code.nl.framework.excel.core.util.ExcelUtils; + +import cn.code.nl.framework.apilog.core.annotation.ApiAccessLog; +import static cn.code.nl.framework.apilog.core.enums.OperateTypeEnum.*; + +import cn.code.nl.module.base.controller.admin.measureunit.vo.*; +import cn.code.nl.module.base.dal.dataobject.measureunit.MeasureUnitDO; +import cn.code.nl.module.base.service.measureunit.MeasureUnitService; + +@Tag(name = "管理后台 - 计量单位") +@RestController +@RequestMapping("/base/measure-unit") +@Validated +public class MeasureUnitController { + + @Resource + private MeasureUnitService measureUnitService; + + @PostMapping("/create") + @Operation(summary = "创建计量单位") + @PreAuthorize("@ss.hasPermission('base:measure-unit:create')") + public CommonResult createMeasureUnit(@Valid @RequestBody MeasureUnitSaveReqVO createReqVO) { + return success(measureUnitService.createMeasureUnit(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新计量单位") + @PreAuthorize("@ss.hasPermission('base:measure-unit:update')") + public CommonResult updateMeasureUnit(@Valid @RequestBody MeasureUnitSaveReqVO updateReqVO) { + measureUnitService.updateMeasureUnit(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除计量单位") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('base:measure-unit:delete')") + public CommonResult deleteMeasureUnit(@RequestParam("id") Long id) { + measureUnitService.deleteMeasureUnit(id); + return success(true); + } + + @DeleteMapping("/delete-list") + @Parameter(name = "ids", description = "编号", required = true) + @Operation(summary = "批量删除计量单位") + @PreAuthorize("@ss.hasPermission('base:measure-unit:delete')") + public CommonResult deleteMeasureUnitList(@RequestParam("ids") List ids) { + measureUnitService.deleteMeasureUnitListByIds(ids); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得计量单位") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('base:measure-unit:query')") + public CommonResult getMeasureUnit(@RequestParam("id") Long id) { + MeasureUnitDO measureUnit = measureUnitService.getMeasureUnit(id); + return success(BeanUtils.toBean(measureUnit, MeasureUnitRespVO.class)); + } + + @GetMapping("/page") + @Operation(summary = "获得计量单位分页") + @PreAuthorize("@ss.hasPermission('base:measure-unit:query')") + public CommonResult> getMeasureUnitPage(@Valid MeasureUnitPageReqVO pageReqVO) { + PageResult pageResult = measureUnitService.getMeasureUnitPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, MeasureUnitRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出计量单位 Excel") + @PreAuthorize("@ss.hasPermission('base:measure-unit:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportMeasureUnitExcel(@Valid MeasureUnitPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = measureUnitService.getMeasureUnitPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "计量单位.xls", "数据", MeasureUnitRespVO.class, + BeanUtils.toBean(list, MeasureUnitRespVO.class)); + } + + @GetMapping("/simple-list") + @Operation(summary = "获取计量单位精简列表", description = "只包含被开启的单位,用于前端的下拉选项") + public CommonResult> getSimpleMeasureUnitList() { + List list = measureUnitService.getMeasureUnitList(); + return success(BeanUtils.toBean(list, MeasureUnitSimpleRespVO.class)); + } + +} \ No newline at end of file diff --git a/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/controller/admin/measureunit/vo/MeasureUnitPageReqVO.java b/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/controller/admin/measureunit/vo/MeasureUnitPageReqVO.java new file mode 100644 index 00000000..3c09b5e7 --- /dev/null +++ b/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/controller/admin/measureunit/vo/MeasureUnitPageReqVO.java @@ -0,0 +1,35 @@ +package cn.code.nl.module.base.controller.admin.measureunit.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.code.nl.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +import static cn.code.nl.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 计量单位分页 Request VO") +@Data +public class MeasureUnitPageReqVO extends PageParam { + + @Schema(description = "编码") + private String unitCode; + + @Schema(description = "名称", example = "芋艿") + private String unitName; + + @Schema(description = "数据精度") + private Integer qtyPrecision; + + @Schema(description = "是否启用") + private String isUsed; + + @Schema(description = "外部标识", example = "20158") + private String extId; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} \ No newline at end of file diff --git a/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/controller/admin/measureunit/vo/MeasureUnitRespVO.java b/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/controller/admin/measureunit/vo/MeasureUnitRespVO.java new file mode 100644 index 00000000..a257b3e2 --- /dev/null +++ b/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/controller/admin/measureunit/vo/MeasureUnitRespVO.java @@ -0,0 +1,43 @@ +package cn.code.nl.module.base.controller.admin.measureunit.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; +import cn.idev.excel.annotation.*; + +@Schema(description = "管理后台 - 计量单位 Response VO") +@Data +@ExcelIgnoreUnannotated +public class MeasureUnitRespVO { + + @Schema(description = "计量单位标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty("计量单位标识") + private Long measureUnitId; + + @Schema(description = "编码", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("编码") + private String unitCode; + + @Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") + @ExcelProperty("名称") + private String unitName; + + @Schema(description = "数据精度") + @ExcelProperty("数据精度") + private Integer qtyPrecision; + + @Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("是否启用") + private String isUsed; + + @Schema(description = "外部标识", example = "20158") + @ExcelProperty("外部标识") + private String extId; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} \ No newline at end of file diff --git a/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/controller/admin/measureunit/vo/MeasureUnitSaveReqVO.java b/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/controller/admin/measureunit/vo/MeasureUnitSaveReqVO.java new file mode 100644 index 00000000..92ab5f53 --- /dev/null +++ b/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/controller/admin/measureunit/vo/MeasureUnitSaveReqVO.java @@ -0,0 +1,33 @@ +package cn.code.nl.module.base.controller.admin.measureunit.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import jakarta.validation.constraints.*; + +@Schema(description = "管理后台 - 计量单位新增/修改 Request VO") +@Data +public class MeasureUnitSaveReqVO { + + @Schema(description = "计量单位标识", requiredMode = Schema.RequiredMode.REQUIRED) + private Long measureUnitId; + + @Schema(description = "编码", requiredMode = Schema.RequiredMode.REQUIRED) + @NotEmpty(message = "编码不能为空") + private String unitCode; + + @Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED) + @NotEmpty(message = "名称不能为空") + private String unitName; + + @Schema(description = "数据精度") + private Integer qtyPrecision; + + @Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED) + @NotEmpty(message = "是否启用不能为空") + private String isUsed; + + @Schema(description = "外部标识", example = "20158") + private String extId; + +} \ No newline at end of file diff --git a/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/controller/admin/measureunit/vo/MeasureUnitSimpleRespVO.java b/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/controller/admin/measureunit/vo/MeasureUnitSimpleRespVO.java new file mode 100644 index 00000000..29b04c2b --- /dev/null +++ b/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/controller/admin/measureunit/vo/MeasureUnitSimpleRespVO.java @@ -0,0 +1,24 @@ +package cn.code.nl.module.base.controller.admin.measureunit.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** + * 计量单位精简 Response VO(用于下拉框) + * + * @author zhouz + */ +@Schema(description = "管理后台 - 计量单位精简 Response VO") +@Data +public class MeasureUnitSimpleRespVO { + + @Schema(description = "计量单位标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Long measureUnitId; + + @Schema(description = "编码", requiredMode = Schema.RequiredMode.REQUIRED) + private String unitCode; + + @Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "个") + private String unitName; + +} diff --git a/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/dal/dataobject/measureunit/MeasureUnitDO.java b/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/dal/dataobject/measureunit/MeasureUnitDO.java new file mode 100644 index 00000000..5d752697 --- /dev/null +++ b/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/dal/dataobject/measureunit/MeasureUnitDO.java @@ -0,0 +1,52 @@ +package cn.code.nl.module.base.dal.dataobject.measureunit; + +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.*; +import cn.code.nl.framework.mybatis.core.dataobject.BaseDO; + +/** + * 计量单位 DO + * + * @author 芋道源码 + */ +@TableName("base_measureunit") +@KeySequence("base_measureunit_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class MeasureUnitDO extends BaseDO { + + /** + * 计量单位标识 + */ + @TableId + private Long measureUnitId; + /** + * 编码 + */ + private String unitCode; + /** + * 名称 + */ + private String unitName; + /** + * 数据精度 + */ + private Integer qtyPrecision; + /** + * 是否启用 + */ + private String isUsed; + /** + * 外部标识 + */ + private String extId; + + +} \ No newline at end of file diff --git a/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/dal/mysql/measureunit/MeasureUnitMapper.java b/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/dal/mysql/measureunit/MeasureUnitMapper.java new file mode 100644 index 00000000..bf823b1f --- /dev/null +++ b/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/dal/mysql/measureunit/MeasureUnitMapper.java @@ -0,0 +1,37 @@ +package cn.code.nl.module.base.dal.mysql.measureunit; + +import java.util.*; + +import cn.code.nl.framework.common.pojo.PageResult; +import cn.code.nl.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.code.nl.framework.mybatis.core.mapper.BaseMapperX; +import cn.code.nl.module.base.dal.dataobject.measureunit.MeasureUnitDO; +import org.apache.ibatis.annotations.Mapper; +import cn.code.nl.module.base.controller.admin.measureunit.vo.*; + +/** + * 计量单位 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface MeasureUnitMapper extends BaseMapperX { + + default PageResult selectPage(MeasureUnitPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(MeasureUnitDO::getUnitCode, reqVO.getUnitCode()) + .likeIfPresent(MeasureUnitDO::getUnitName, reqVO.getUnitName()) + .eqIfPresent(MeasureUnitDO::getQtyPrecision, reqVO.getQtyPrecision()) + .eqIfPresent(MeasureUnitDO::getIsUsed, reqVO.getIsUsed()) + .eqIfPresent(MeasureUnitDO::getExtId, reqVO.getExtId()) + .betweenIfPresent(MeasureUnitDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(MeasureUnitDO::getMeasureUnitId)); + } + + default List selectList() { + return selectList(new LambdaQueryWrapperX() + .eq(MeasureUnitDO::getIsUsed, "1") + .orderByAsc(MeasureUnitDO::getUnitCode)); + } + +} \ No newline at end of file diff --git a/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/service/measureunit/MeasureUnitService.java b/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/service/measureunit/MeasureUnitService.java new file mode 100644 index 00000000..d7efb134 --- /dev/null +++ b/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/service/measureunit/MeasureUnitService.java @@ -0,0 +1,69 @@ +package cn.code.nl.module.base.service.measureunit; + +import java.util.*; +import jakarta.validation.*; +import cn.code.nl.module.base.controller.admin.measureunit.vo.*; +import cn.code.nl.module.base.dal.dataobject.measureunit.MeasureUnitDO; +import cn.code.nl.framework.common.pojo.PageResult; +import cn.code.nl.framework.common.pojo.PageParam; + +/** + * 计量单位 Service 接口 + * + * @author 芋道源码 + */ +public interface MeasureUnitService { + + /** + * 创建计量单位 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createMeasureUnit(@Valid MeasureUnitSaveReqVO createReqVO); + + /** + * 更新计量单位 + * + * @param updateReqVO 更新信息 + */ + void updateMeasureUnit(@Valid MeasureUnitSaveReqVO updateReqVO); + + /** + * 删除计量单位 + * + * @param id 编号 + */ + void deleteMeasureUnit(Long id); + + /** + * 批量删除计量单位 + * + * @param ids 编号 + */ + void deleteMeasureUnitListByIds(List ids); + + /** + * 获得计量单位 + * + * @param id 编号 + * @return 计量单位 + */ + MeasureUnitDO getMeasureUnit(Long id); + + /** + * 获得计量单位分页 + * + * @param pageReqVO 分页查询 + * @return 计量单位分页 + */ + PageResult getMeasureUnitPage(MeasureUnitPageReqVO pageReqVO); + + /** + * 获得计量单位列表(精简,仅启用的) + * + * @return 计量单位列表 + */ + List getMeasureUnitList(); + +} \ No newline at end of file diff --git a/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/service/measureunit/MeasureUnitServiceImpl.java b/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/service/measureunit/MeasureUnitServiceImpl.java new file mode 100644 index 00000000..23a580af --- /dev/null +++ b/nl-module-base/nl-module-base-server/src/main/java/cn/code/nl/module/base/service/measureunit/MeasureUnitServiceImpl.java @@ -0,0 +1,90 @@ +package cn.code.nl.module.base.service.measureunit; + +import cn.hutool.core.collection.CollUtil; +import org.springframework.stereotype.Service; +import jakarta.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; +import cn.code.nl.module.base.controller.admin.measureunit.vo.*; +import cn.code.nl.module.base.dal.dataobject.measureunit.MeasureUnitDO; +import cn.code.nl.framework.common.pojo.PageResult; +import cn.code.nl.framework.common.pojo.PageParam; +import cn.code.nl.framework.common.util.object.BeanUtils; + +import cn.code.nl.module.base.dal.mysql.measureunit.MeasureUnitMapper; + +import static cn.code.nl.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.code.nl.framework.common.util.collection.CollectionUtils.convertList; +import static cn.code.nl.framework.common.util.collection.CollectionUtils.diffList; +import static cn.code.nl.module.base.enums.ErrorCodeConstants.*; + +/** + * 计量单位 Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Validated +public class MeasureUnitServiceImpl implements MeasureUnitService { + + @Resource + private MeasureUnitMapper measureUnitMapper; + + @Override + public Long createMeasureUnit(MeasureUnitSaveReqVO createReqVO) { + // 插入 + MeasureUnitDO measureUnit = BeanUtils.toBean(createReqVO, MeasureUnitDO.class); + measureUnitMapper.insert(measureUnit); + + // 返回 + return measureUnit.getMeasureUnitId(); + } + + @Override + public void updateMeasureUnit(MeasureUnitSaveReqVO updateReqVO) { + // 校验存在 + validateMeasureUnitExists(updateReqVO.getMeasureUnitId()); + // 更新 + MeasureUnitDO updateObj = BeanUtils.toBean(updateReqVO, MeasureUnitDO.class); + measureUnitMapper.updateById(updateObj); + } + + @Override + public void deleteMeasureUnit(Long id) { + // 校验存在 + validateMeasureUnitExists(id); + // 删除 + measureUnitMapper.deleteById(id); + } + + @Override + public void deleteMeasureUnitListByIds(List ids) { + // 删除 + measureUnitMapper.deleteByIds(ids); + } + + + private void validateMeasureUnitExists(Long id) { + if (measureUnitMapper.selectById(id) == null) { + throw exception(MEASURE_UNIT_NOT_EXISTS); + } + } + + @Override + public MeasureUnitDO getMeasureUnit(Long id) { + return measureUnitMapper.selectById(id); + } + + @Override + public PageResult getMeasureUnitPage(MeasureUnitPageReqVO pageReqVO) { + return measureUnitMapper.selectPage(pageReqVO); + } + + @Override + public List getMeasureUnitList() { + return measureUnitMapper.selectList(); + } + +} \ No newline at end of file diff --git a/nl-module-base/nl-module-base-server/src/main/resources/mapper/measureunit/MeasureUnitMapper.xml b/nl-module-base/nl-module-base-server/src/main/resources/mapper/measureunit/MeasureUnitMapper.xml new file mode 100644 index 00000000..8c25fd7a --- /dev/null +++ b/nl-module-base/nl-module-base-server/src/main/resources/mapper/measureunit/MeasureUnitMapper.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/src/api/base/measureunit/index.ts b/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/src/api/base/measureunit/index.ts new file mode 100644 index 00000000..3f398f9a --- /dev/null +++ b/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/src/api/base/measureunit/index.ts @@ -0,0 +1,64 @@ +import type { PageParam, PageResult } from '@vben/request'; + +import { requestClient } from '#/api/request'; + +export namespace BaseMeasureUnitApi { + /** 计量单位信息 */ + export interface MeasureUnit { + measureUnitId?: number; + unitCode?: string; // 编码 + unitName?: string; // 名称 + qtyPrecision: number; // 数据精度 + isUsed?: string; // 是否启用 + extId: string; // 外部标识 + } +} + +/** 查询计量单位精简列表(仅启用的,用于下拉框) */ +export async function getSimpleMeasureUnitList() { + return requestClient.get( + '/base/measure-unit/simple-list', + ); +} + +/** 查询计量单位分页 */ +export function getMeasureUnitPage(params: PageParam) { + return requestClient.get>( + '/base/measure-unit/page', + { params }, + ); +} + +/** 查询计量单位详情 */ +export function getMeasureUnit(id: number) { + return requestClient.get( + `/base/measure-unit/get?id=${id}`, + ); +} + +/** 新增计量单位 */ +export function createMeasureUnit(data: BaseMeasureUnitApi.MeasureUnit) { + return requestClient.post('/base/measure-unit/create', data); +} + +/** 修改计量单位 */ +export function updateMeasureUnit(data: BaseMeasureUnitApi.MeasureUnit) { + return requestClient.put('/base/measure-unit/update', data); +} + +/** 删除计量单位 */ +export function deleteMeasureUnit(id: number) { + return requestClient.delete(`/base/measure-unit/delete?id=${id}`); +} + +/** 批量删除计量单位 */ +export function deleteMeasureUnitList(ids: number[]) { + return requestClient.delete( + `/base/measure-unit/delete-list?ids=${ids.join(',')}`, + ); +} + +/** 导出计量单位 */ +export function exportMeasureUnit(params: any) { + return requestClient.download('/base/measure-unit/export-excel', { params }); +} diff --git a/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/src/views/base/classstandard/data.ts b/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/src/views/base/classstandard/data.ts index 25099420..07867458 100644 --- a/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/src/views/base/classstandard/data.ts +++ b/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/src/views/base/classstandard/data.ts @@ -28,10 +28,7 @@ export function useFormSchema(): VbenFormSchema[] { allowClear: true, api: async () => { const data = await getClassStandardList(); - data.unshift({ - classId: 0, - className: '顶级分类', - }); + data.unshift({sort: 0, status: 0, classId: 0, className: '顶级分类'}); return handleTree(data, 'classId', 'parentClassId'); }, labelField: 'className', diff --git a/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/src/views/base/materialbase/data.ts b/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/src/views/base/materialbase/data.ts index 3868d9f2..0937d1bd 100644 --- a/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/src/views/base/materialbase/data.ts +++ b/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/src/views/base/materialbase/data.ts @@ -1,371 +1,147 @@ import type { VbenFormSchema } from '#/adapter/form'; import type { VxeTableGridOptions } from '#/adapter/vxe-table'; import type { BaseMaterialBaseApi } from '#/api/base/materialbase'; -import type { BaseClassStandardApi } from '#/api/base/classstandard'; import { handleTree } from '@vben/utils'; -import { z } from '#/adapter/form'; import { getClassStandardList, getClassStandardListByCode } from '#/api/base/classstandard'; +import { getSimpleMeasureUnitList } from '#/api/base/measureunit'; import { getRangePickerDefaultProps } from '#/utils'; -/** 分类名称映射表:classId → className */ -let categoryNameMap: Record = {}; -getClassStandardList().then((data) => { - if (data) { - data.forEach((item) => { - if (item.classId) { - categoryNameMap[item.classId] = item.className; - } - }); - } -}); +// ========== 分类映射:classId → className ========== +const classNameMap: Record = {}; +const unitCodeMap: Record = {}; +const unitNameMap: Record = {}; -/** 获取物料分类的树形下拉数据 */ +/** 预加载所有映射数据,确保表格渲染前映射表已填充 */ +export async function loadAllLookupData() { + const [classData, unitData] = await Promise.all([ + getClassStandardList(), + getSimpleMeasureUnitList(), + ]); + classData?.forEach((item) => { + if (item.classId) classNameMap[item.classId] = item.className; + }); + unitData?.forEach((item) => { + if (item.measureUnitId) { + unitCodeMap[item.measureUnitId] = item.unitCode; + unitNameMap[item.measureUnitId] = item.unitName; + } + }); +} + +// ========== 物料分类树形下拉 ========== async function loadMaterialTypeTree() { const data = await getClassStandardListByCode('0001'); - if (!data || data.length === 0) { - return []; - } + if (!data || data.length === 0) return []; return handleTree(data, 'classId', 'parentClassId'); } -/** 新增/修改的表单 */ +// ========== 计量单位下拉 ========== +async function loadMeasureUnitList() { + const data = await getSimpleMeasureUnitList(); + return data || []; +} + +// ========== 新增/修改的表单 ========== export function useFormSchema(): VbenFormSchema[] { return [ + { fieldName: 'materialId', component: 'Input', dependencies: { triggerFields: [''], show: () => false } }, + { fieldName: 'materialCode', label: '物料编码', rules: 'required', component: 'Input', componentProps: { placeholder: '请输入物料编码' } }, + { fieldName: 'materialName', label: '物料名称', rules: 'required', component: 'Input', componentProps: { placeholder: '请输入物料名称' } }, + { fieldName: 'materialSpec', label: '规格', component: 'Input', componentProps: { placeholder: '请输入规格' } }, + { fieldName: 'materialModel', label: '型号', component: 'Input', componentProps: { placeholder: '请输入型号' } }, + { fieldName: 'englishName', label: '外文名称', component: 'Input', componentProps: { placeholder: '请输入外文名称' } }, { - fieldName: 'materialId', - component: 'Input', - dependencies: { - triggerFields: [''], - show: () => false, - }, - }, - { - fieldName: 'materialCode', - label: '物料编码', - rules: 'required', - component: 'Input', - componentProps: { - placeholder: '请输入物料编码', - }, - }, - { - fieldName: 'materialName', - label: '物料名称', - rules: 'required', - component: 'Input', - componentProps: { - placeholder: '请输入物料名称', - }, - }, - { - fieldName: 'materialSpec', - label: '规格', - component: 'Input', - componentProps: { - placeholder: '请输入规格', - }, - }, - { - fieldName: 'materialModel', - label: '型号', - component: 'Input', - componentProps: { - placeholder: '请输入型号', - }, - }, - { - fieldName: 'englishName', - label: '外文名称', - component: 'Input', - componentProps: { - placeholder: '请输入外文名称', - }, - }, - { - fieldName: 'materialTypeId', - label: '物料分类', + fieldName: 'materialTypeId', label: '物料分类', component: 'ApiTreeSelect', - componentProps: { - api: loadMaterialTypeTree, - labelField: 'className', - valueField: 'classId', - childrenField: 'children', - placeholder: '请选择物料分类', - allowClear: true, - treeDefaultExpandAll: true, - }, + componentProps: { api: loadMaterialTypeTree, labelField: 'className', valueField: 'classId', childrenField: 'children', placeholder: '请选择物料分类', allowClear: true, treeDefaultExpandAll: true }, }, { - fieldName: 'baseUnitId', - label: '基本计量单位', - rules: 'required', - component: 'Input', - componentProps: { - placeholder: '请输入基本计量单位', - }, + fieldName: 'baseUnitId', label: '基本计量单位', rules: 'required', + component: 'ApiSelect', + componentProps: { api: loadMeasureUnitList, labelField: 'unitCode', valueField: 'measureUnitId', placeholder: '请选择基本计量单位', allowClear: true }, }, { - fieldName: 'assUnitId', - label: '辅助计量单位', - component: 'Input', - componentProps: { - placeholder: '请输入辅助计量单位', - }, + fieldName: 'assUnitId', label: '辅助计量单位', + component: 'ApiSelect', + componentProps: { api: loadMeasureUnitList, labelField: 'unitCode', valueField: 'measureUnitId', placeholder: '请选择辅助计量单位', allowClear: true }, }, { - fieldName: 'lenUnitId', - label: '长度单位', - component: 'Input', - componentProps: { - placeholder: '请输入长度单位', - }, + fieldName: 'lenUnitId', label: '长度单位', + component: 'ApiSelect', + componentProps: { api: loadMeasureUnitList, labelField: 'unitCode', valueField: 'measureUnitId', placeholder: '请选择长度单位', allowClear: true }, }, { - fieldName: 'weightUnitId', - label: '重量单位', - component: 'Input', - componentProps: { - placeholder: '请输入重量单位', - }, + fieldName: 'weightUnitId', label: '重量单位', + component: 'ApiSelect', + componentProps: { api: loadMeasureUnitList, labelField: 'unitCode', valueField: 'measureUnitId', placeholder: '请选择重量单位', allowClear: true }, }, { - fieldName: 'isUsed', - label: '是否启用', - rules: 'required', + fieldName: 'cubageUnitId', label: '体积单位', + component: 'ApiSelect', + componentProps: { api: loadMeasureUnitList, labelField: 'unitCode', valueField: 'measureUnitId', placeholder: '请选择体积单位', allowClear: true }, + }, + { + fieldName: 'isUsed', label: '是否启用', rules: 'required', component: 'RadioGroup', - componentProps: { - options: [ - { label: '是', value: '1' }, - { label: '否', value: '0' }, - ], - buttonStyle: 'solid', - optionType: 'button', - }, - }, - { - fieldName: 'extId', - label: '外部标识', - component: 'Input', - componentProps: { - placeholder: '请输入外部标识', - }, + componentProps: { options: [{ label: '是', value: '1' }, { label: '否', value: '0' }], buttonStyle: 'solid', optionType: 'button' }, }, + { fieldName: 'extId', label: '外部标识', component: 'Input', componentProps: { placeholder: '请输入外部标识' } }, ]; } -/** 列表的搜索表单 */ +// ========== 列表的搜索表单 ========== export function useGridFormSchema(): VbenFormSchema[] { return [ + { fieldName: 'materialCode', label: '物料编码', component: 'Input', componentProps: { allowClear: true, placeholder: '请输入物料编码' } }, + { fieldName: 'materialName', label: '物料名称', component: 'Input', componentProps: { allowClear: true, placeholder: '请输入物料名称' } }, { - fieldName: 'materialCode', - label: '物料编码', - component: 'Input', - componentProps: { - allowClear: true, - placeholder: '请输入物料编码', - }, - }, - { - fieldName: 'materialName', - label: '物料名称', - component: 'Input', - componentProps: { - allowClear: true, - placeholder: '请输入物料名称', - }, - }, - { - fieldName: 'materialSpec', - label: '规格', - component: 'Input', - componentProps: { - allowClear: true, - placeholder: '请输入规格', - }, - }, - { - fieldName: 'materialModel', - label: '型号', - component: 'Input', - componentProps: { - allowClear: true, - placeholder: '请输入型号', - }, - }, - { - fieldName: 'englishName', - label: '外文名称', - component: 'Input', - componentProps: { - allowClear: true, - placeholder: '请输入外文名称', - }, - }, - { - fieldName: 'materialTypeId', - label: '物料分类', + fieldName: 'materialTypeId', label: '物料分类', component: 'ApiTreeSelect', - componentProps: { - api: loadMaterialTypeTree, - labelField: 'className', - valueField: 'classId', - childrenField: 'children', - placeholder: '请选择物料分类', - allowClear: true, - treeDefaultExpandAll: true, - }, - }, - { - fieldName: 'baseUnitId', - label: '基本计量单位', - component: 'Input', - componentProps: { - allowClear: true, - placeholder: '请输入基本计量单位', - }, - }, - { - fieldName: 'assUnitId', - label: '辅助计量单位', - component: 'Input', - componentProps: { - allowClear: true, - placeholder: '请输入辅助计量单位', - }, - }, - { - fieldName: 'lenUnitId', - label: '长度单位', - component: 'Input', - componentProps: { - allowClear: true, - placeholder: '请输入长度单位', - }, - }, - { - fieldName: 'weightUnitId', - label: '重量单位', - component: 'Input', - componentProps: { - allowClear: true, - placeholder: '请输入重量单位', - }, - }, - { - fieldName: 'createTime', - label: '创建时间', - component: 'RangePicker', - componentProps: { - ...getRangePickerDefaultProps(), - allowClear: true, - }, - }, - { - fieldName: 'isUsed', - label: '是否启用', - component: 'Select', - componentProps: { - allowClear: true, - placeholder: '请选择', - options: [ - { label: '是', value: '1' }, - { label: '否', value: '0' }, - ], - }, - }, - { - fieldName: 'extId', - label: '外部标识', - component: 'Input', - componentProps: { - allowClear: true, - placeholder: '请输入外部标识', - }, + componentProps: { api: loadMaterialTypeTree, labelField: 'className', valueField: 'classId', childrenField: 'children', placeholder: '请选择物料分类', allowClear: true }, }, + { fieldName: 'createTime', label: '创建时间', component: 'RangePicker', componentProps: { ...getRangePickerDefaultProps(), allowClear: true } }, + { fieldName: 'isUsed', label: '是否启用', component: 'Select', componentProps: { allowClear: true, placeholder: '请选择', options: [{ label: '是', value: '1' }, { label: '否', value: '0' }] } }, ]; } -/** 列表的字段 */ +// ========== 列表的字段 ========== export function useGridColumns(): VxeTableGridOptions['columns'] { return [ { type: 'checkbox', width: 40 }, + { field: 'materialCode', title: '物料编码', minWidth: 120 }, + { field: 'materialName', title: '物料名称', minWidth: 200 }, + { field: 'materialSpec', title: '规格', minWidth: 120 }, + { field: 'materialModel', title: '型号', minWidth: 120 }, + { field: 'englishName', title: '外文名称', minWidth: 120 }, { - field: 'materialCode', - title: '物料编码', - minWidth: 120, + field: 'materialTypeId', title: '物料分类', minWidth: 150, + formatter: ({ cellValue }: { cellValue: number }) => classNameMap[cellValue] || cellValue || '-', }, { - field: 'materialName', - title: '物料名称', - minWidth: 200, + field: 'baseUnitId', title: '基本计量单位', minWidth: 120, + formatter: ({ cellValue }: { cellValue: number }) => unitCodeMap[cellValue] || cellValue || '-', }, { - field: 'materialSpec', - title: '规格', - minWidth: 120, + field: 'assUnitId', title: '辅助计量单位', minWidth: 120, + formatter: ({ cellValue }: { cellValue: number }) => unitCodeMap[cellValue] || cellValue || '-', }, { - field: 'materialModel', - title: '型号', - minWidth: 120, + field: 'lenUnitId', title: '长度单位', minWidth: 120, + formatter: ({ cellValue }: { cellValue: number }) => unitCodeMap[cellValue] || cellValue || '-', }, { - field: 'englishName', - title: '外文名称', - minWidth: 120, + field: 'weightUnitId', title: '重量单位', minWidth: 120, + formatter: ({ cellValue }: { cellValue: number }) => unitCodeMap[cellValue] || cellValue || '-', }, { - field: 'baseUnitId', - title: '基本计量单位', - minWidth: 120, - }, - { - field: 'assUnitId', - title: '辅助计量单位', - minWidth: 120, - }, - { - field: 'materialTypeId', - title: '物料分类', - minWidth: 150, - formatter: ({ cellValue }: { cellValue: number }) => - categoryNameMap[cellValue] || cellValue || '-', - }, - { - field: 'lenUnitId', - title: '长度单位', - minWidth: 120, - }, - { - field: 'weightUnitId', - title: '重量单位', - minWidth: 120, - }, - { - field: 'createTime', - title: '创建时间', - minWidth: 180, - formatter: 'formatDateTime', - }, - { - field: 'isUsed', - title: '是否启用', - minWidth: 100, - formatter: ({ cellValue }: { cellValue: string }) => - cellValue === '1' ? '是' : '否', - }, - { - field: 'extId', - title: '外部标识', - minWidth: 120, - }, - { - title: '操作', - width: 200, - fixed: 'right', - slots: { default: 'actions' }, + field: 'cubageUnitId', title: '体积单位', minWidth: 120, + formatter: ({ cellValue }: { cellValue: number }) => unitCodeMap[cellValue] || cellValue || '-', }, + { field: 'createTime', title: '创建时间', minWidth: 180, formatter: 'formatDateTime' }, + { field: 'isUsed', title: '是否启用', minWidth: 100, formatter: ({ cellValue }: { cellValue: string }) => (cellValue === '1' ? '是' : '否') }, + { field: 'extId', title: '外部标识', minWidth: 120 }, + { title: '操作', width: 200, fixed: 'right', slots: { default: 'actions' } }, ]; } diff --git a/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/src/views/base/materialbase/index.vue b/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/src/views/base/materialbase/index.vue index d66cb71d..a44b5bfe 100644 --- a/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/src/views/base/materialbase/index.vue +++ b/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/src/views/base/materialbase/index.vue @@ -2,7 +2,7 @@ import type { VxeTableGridOptions } from '#/adapter/vxe-table'; import type { BaseMaterialBaseApi } from '#/api/base/materialbase'; -import { ref } from 'vue'; +import { onMounted, ref } from 'vue'; import { confirm, Page, useVbenModal } from '@vben/common-ui'; import { downloadFileFromBlobPart, isEmpty } from '@vben/utils'; @@ -18,9 +18,15 @@ import { } from '#/api/base/materialbase'; import { $t } from '#/locales'; -import { useGridColumns, useGridFormSchema } from './data'; +import { loadAllLookupData, useGridColumns, useGridFormSchema } from './data'; import Form from './modules/form.vue'; +const ready = ref(false); +onMounted(async () => { + await loadAllLookupData(); + ready.value = true; +}); + const [FormModal, formModalApi] = useVbenModal({ connectedComponent: Form, destroyOnClose: true, @@ -125,7 +131,7 @@ const [Grid, gridApi] = useVbenVxeGrid({