备品件信息提交
This commit is contained in:
68
jeecg-boot/db/mes-xsl-spare-part-menu-permission.sql
Normal file
68
jeecg-boot/db/mes-xsl-spare-part-menu-permission.sql
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
-- MES 备品件信息:建表 + 菜单 + 按钮权限 + 租户 admin 授权(可整文件一次执行)
|
||||||
|
-- 权限前缀与 Controller、前端 v-auth 一致:mes:mes_xsl_spare_part:*
|
||||||
|
-- 依赖:mes_xsl_spare_parts_category、mes_xsl_unit;父菜单 MES基础资料 / MES资料;修改租户改 SET @mes_tenant_id
|
||||||
|
SET NAMES utf8mb4;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `mes_xsl_spare_part` (
|
||||||
|
`id` varchar(32) NOT NULL COMMENT '主键',
|
||||||
|
`spare_part_name` varchar(128) NOT NULL COMMENT '备品件名称(同租户未删除数据中唯一)',
|
||||||
|
`spare_parts_category_id` varchar(32) NOT NULL COMMENT '所属备品件类别 mes_xsl_spare_parts_category.id',
|
||||||
|
`spare_parts_category_name` varchar(128) DEFAULT NULL COMMENT '备品件类别名称冗余',
|
||||||
|
`spec_model` varchar(200) DEFAULT NULL COMMENT '规格型号',
|
||||||
|
`max_stock` decimal(18,4) NOT NULL DEFAULT '0.0000' COMMENT '最大库存',
|
||||||
|
`min_stock` decimal(18,4) NOT NULL DEFAULT '0.0000' COMMENT '最小库存',
|
||||||
|
`unit_id` varchar(36) NOT NULL COMMENT '单位 mes_xsl_unit.id',
|
||||||
|
`unit_name` varchar(100) DEFAULT NULL COMMENT '单位名称冗余',
|
||||||
|
`tenant_id` int DEFAULT NULL COMMENT '租户',
|
||||||
|
`sys_org_code` varchar(64) DEFAULT NULL COMMENT '部门',
|
||||||
|
`create_by` varchar(32) DEFAULT NULL COMMENT '创建人',
|
||||||
|
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
||||||
|
`update_by` varchar(32) DEFAULT NULL COMMENT '更新人',
|
||||||
|
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
|
||||||
|
`del_flag` int DEFAULT '0' COMMENT '删除标记(0正常1删除)',
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `idx_msp_tenant_name` (`tenant_id`, `spare_part_name`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='MES备品件信息';
|
||||||
|
|
||||||
|
SET @mes_tenant_id = 1002;
|
||||||
|
|
||||||
|
SET @mes_base_pid = (
|
||||||
|
SELECT MIN(`id`) FROM `sys_permission`
|
||||||
|
WHERE `del_flag` = 0 AND `menu_type` = 0 AND `name` IN ('MES基础资料', 'MES资料')
|
||||||
|
);
|
||||||
|
SET @mes_base_pid = IFNULL(@mes_base_pid, '1860000000000000001');
|
||||||
|
|
||||||
|
INSERT INTO `sys_permission`(`id`, `parent_id`, `name`, `url`, `component`, `component_name`, `menu_type`, `perms`, `perms_type`, `sort_no`, `is_route`, `is_leaf`, `hidden`, `status`, `del_flag`, `keep_alive`, `internal_or_external`, `create_by`, `create_time`)
|
||||||
|
VALUES ('1860000000000000105', @mes_base_pid, '备品件信息', '/xslmes/mesXslSparePart', 'xslmes/mesXslSparePart/MesXslSparePartList', NULL, 1, NULL, '1', 16, 1, 0, 0, '1', 0, 1, 0, 'admin', NOW())
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
`parent_id` = VALUES(`parent_id`), `name` = VALUES(`name`), `url` = VALUES(`url`), `component` = VALUES(`component`), `component_name` = VALUES(`component_name`),
|
||||||
|
`menu_type` = VALUES(`menu_type`), `perms` = VALUES(`perms`), `perms_type` = VALUES(`perms_type`), `sort_no` = VALUES(`sort_no`),
|
||||||
|
`is_route` = VALUES(`is_route`), `is_leaf` = VALUES(`is_leaf`), `hidden` = VALUES(`hidden`), `status` = VALUES(`status`), `del_flag` = VALUES(`del_flag`),
|
||||||
|
`keep_alive` = VALUES(`keep_alive`), `internal_or_external` = VALUES(`internal_or_external`);
|
||||||
|
|
||||||
|
INSERT INTO `sys_permission`(`id`, `parent_id`, `name`, `menu_type`, `perms`, `perms_type`, `status`, `del_flag`, `create_by`, `create_time`) VALUES
|
||||||
|
('1860000000000000106', '1860000000000000105', '新增', 2, 'mes:mes_xsl_spare_part:add', '1', '1', 0, 'admin', NOW()),
|
||||||
|
('1860000000000000107', '1860000000000000105', '编辑', 2, 'mes:mes_xsl_spare_part:edit', '1', '1', 0, 'admin', NOW()),
|
||||||
|
('1860000000000000108', '1860000000000000105', '删除', 2, 'mes:mes_xsl_spare_part:delete', '1', '1', 0, 'admin', NOW()),
|
||||||
|
('1860000000000000109', '1860000000000000105', '批量删除', 2, 'mes:mes_xsl_spare_part:deleteBatch', '1', '1', 0, 'admin', NOW()),
|
||||||
|
('1860000000000000110', '1860000000000000105', '导出', 2, 'mes:mes_xsl_spare_part:exportXls', '1', '1', 0, 'admin', NOW()),
|
||||||
|
('1860000000000000111', '1860000000000000105', '导入', 2, 'mes:mes_xsl_spare_part:importExcel', '1', '1', 0, 'admin', NOW())
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
`parent_id` = VALUES(`parent_id`), `name` = VALUES(`name`), `menu_type` = VALUES(`menu_type`), `perms` = VALUES(`perms`), `perms_type` = VALUES(`perms_type`),
|
||||||
|
`status` = VALUES(`status`), `del_flag` = VALUES(`del_flag`);
|
||||||
|
|
||||||
|
INSERT INTO `sys_role_permission`(`id`, `role_id`, `permission_id`, `operate_date`, `operate_ip`)
|
||||||
|
SELECT REPLACE(UUID(), '-', ''), r.`id`, p.`id`, NOW(), '127.0.0.1'
|
||||||
|
FROM `sys_role` r
|
||||||
|
CROSS JOIN `sys_permission` p
|
||||||
|
WHERE r.`tenant_id` = @mes_tenant_id
|
||||||
|
AND r.`role_code` = 'admin'
|
||||||
|
AND p.`id` IN (
|
||||||
|
'1860000000000000105',
|
||||||
|
'1860000000000000106', '1860000000000000107', '1860000000000000108', '1860000000000000109',
|
||||||
|
'1860000000000000110', '1860000000000000111'
|
||||||
|
)
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1 FROM `sys_role_permission` rp
|
||||||
|
WHERE rp.`role_id` = r.`id` AND rp.`permission_id` = p.`id`
|
||||||
|
);
|
||||||
24
jeecg-boot/db/mes-xsl-spare-part.sql
Normal file
24
jeecg-boot/db/mes-xsl-spare-part.sql
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
-- 仅建表:MES 备品件信息 mes_xsl_spare_part
|
||||||
|
-- 完整初始化请执行 mes-xsl-spare-part-menu-permission.sql
|
||||||
|
SET NAMES utf8mb4;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `mes_xsl_spare_part` (
|
||||||
|
`id` varchar(32) NOT NULL COMMENT '主键',
|
||||||
|
`spare_part_name` varchar(128) NOT NULL COMMENT '备品件名称(同租户未删除数据中唯一)',
|
||||||
|
`spare_parts_category_id` varchar(32) NOT NULL COMMENT '所属备品件类别 mes_xsl_spare_parts_category.id',
|
||||||
|
`spare_parts_category_name` varchar(128) DEFAULT NULL COMMENT '备品件类别名称冗余',
|
||||||
|
`spec_model` varchar(200) DEFAULT NULL COMMENT '规格型号',
|
||||||
|
`max_stock` decimal(18,4) NOT NULL DEFAULT '0.0000' COMMENT '最大库存',
|
||||||
|
`min_stock` decimal(18,4) NOT NULL DEFAULT '0.0000' COMMENT '最小库存',
|
||||||
|
`unit_id` varchar(36) NOT NULL COMMENT '单位 mes_xsl_unit.id',
|
||||||
|
`unit_name` varchar(100) DEFAULT NULL COMMENT '单位名称冗余',
|
||||||
|
`tenant_id` int DEFAULT NULL COMMENT '租户',
|
||||||
|
`sys_org_code` varchar(64) DEFAULT NULL COMMENT '部门',
|
||||||
|
`create_by` varchar(32) DEFAULT NULL COMMENT '创建人',
|
||||||
|
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
||||||
|
`update_by` varchar(32) DEFAULT NULL COMMENT '更新人',
|
||||||
|
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
|
||||||
|
`del_flag` int DEFAULT '0' COMMENT '删除标记(0正常1删除)',
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `idx_msp_tenant_name` (`tenant_id`, `spare_part_name`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='MES备品件信息';
|
||||||
@@ -0,0 +1,320 @@
|
|||||||
|
package org.jeecg.modules.xslmes.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||||
|
import org.jeecg.common.api.vo.Result;
|
||||||
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
||||||
|
import org.jeecg.common.system.base.controller.JeecgController;
|
||||||
|
import org.jeecg.common.system.query.QueryGenerator;
|
||||||
|
import org.jeecg.common.util.oConvertUtils;
|
||||||
|
import org.jeecg.modules.xslmes.entity.MesXslSparePart;
|
||||||
|
import org.jeecg.modules.xslmes.entity.MesXslSparePartsCategory;
|
||||||
|
import org.jeecg.modules.xslmes.entity.MesXslUnit;
|
||||||
|
import org.jeecg.modules.xslmes.service.IMesXslSparePartService;
|
||||||
|
import org.jeecg.modules.xslmes.service.IMesXslSparePartsCategoryService;
|
||||||
|
import org.jeecg.modules.xslmes.service.IMesXslUnitService;
|
||||||
|
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||||
|
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MES 备品件信息
|
||||||
|
*/
|
||||||
|
@Tag(name = "MES备品件信息")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/xslmes/mesXslSparePart")
|
||||||
|
@Slf4j
|
||||||
|
public class MesXslSparePartController extends JeecgController<MesXslSparePart, IMesXslSparePartService> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IMesXslSparePartService mesXslSparePartService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IMesXslSparePartsCategoryService mesXslSparePartsCategoryService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IMesXslUnitService mesXslUnitService;
|
||||||
|
|
||||||
|
@Operation(summary = "MES备品件信息-分页列表查询")
|
||||||
|
@GetMapping(value = "/list")
|
||||||
|
public Result<IPage<MesXslSparePart>> queryPageList(
|
||||||
|
MesXslSparePart model,
|
||||||
|
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||||
|
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
||||||
|
HttpServletRequest req) {
|
||||||
|
QueryWrapper<MesXslSparePart> queryWrapper = QueryGenerator.initQueryWrapper(model, req.getParameterMap());
|
||||||
|
Page<MesXslSparePart> page = new Page<>(pageNo, pageSize);
|
||||||
|
IPage<MesXslSparePart> pageList = mesXslSparePartService.page(page, queryWrapper);
|
||||||
|
return Result.OK(pageList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoLog(value = "MES备品件信息-添加")
|
||||||
|
@Operation(summary = "MES备品件信息-添加")
|
||||||
|
@RequiresPermissions("mes:mes_xsl_spare_part:add")
|
||||||
|
@PostMapping(value = "/add")
|
||||||
|
public Result<String> add(@RequestBody MesXslSparePart model) {
|
||||||
|
//update-begin---author:jiangxh ---date:20260515 for:【MES】备品件信息保存前校验:名称唯一、类别与单位回填、库存上下限-----------
|
||||||
|
String err = validateForSave(model, null);
|
||||||
|
if (err != null) {
|
||||||
|
return Result.error(err);
|
||||||
|
}
|
||||||
|
//update-end---author:jiangxh ---date:20260515 for:【MES】备品件信息保存前校验:名称唯一、类别与单位回填、库存上下限-----------
|
||||||
|
mesXslSparePartService.save(model);
|
||||||
|
return Result.OK("添加成功!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoLog(value = "MES备品件信息-编辑")
|
||||||
|
@Operation(summary = "MES备品件信息-编辑")
|
||||||
|
@RequiresPermissions("mes:mes_xsl_spare_part:edit")
|
||||||
|
@RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
|
||||||
|
public Result<String> edit(@RequestBody MesXslSparePart model) {
|
||||||
|
//update-begin---author:jiangxh ---date:20260515 for:【MES】备品件信息保存前校验:名称唯一、类别与单位回填、库存上下限-----------
|
||||||
|
String err = validateForSave(model, model.getId());
|
||||||
|
if (err != null) {
|
||||||
|
return Result.error(err);
|
||||||
|
}
|
||||||
|
//update-end---author:jiangxh ---date:20260515 for:【MES】备品件信息保存前校验:名称唯一、类别与单位回填、库存上下限-----------
|
||||||
|
mesXslSparePartService.updateById(model);
|
||||||
|
return Result.OK("编辑成功!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoLog(value = "MES备品件信息-删除")
|
||||||
|
@Operation(summary = "MES备品件信息-通过id删除")
|
||||||
|
@RequiresPermissions("mes:mes_xsl_spare_part:delete")
|
||||||
|
@DeleteMapping(value = "/delete")
|
||||||
|
public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
|
||||||
|
mesXslSparePartService.removeById(id);
|
||||||
|
return Result.OK("删除成功!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoLog(value = "MES备品件信息-批量删除")
|
||||||
|
@Operation(summary = "MES备品件信息-批量删除")
|
||||||
|
@RequiresPermissions("mes:mes_xsl_spare_part:deleteBatch")
|
||||||
|
@DeleteMapping(value = "/deleteBatch")
|
||||||
|
public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
||||||
|
mesXslSparePartService.removeByIds(Arrays.asList(ids.split(",")));
|
||||||
|
return Result.OK("批量删除成功!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "MES备品件信息-通过id查询")
|
||||||
|
@GetMapping(value = "/queryById")
|
||||||
|
public Result<MesXslSparePart> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||||
|
MesXslSparePart entity = mesXslSparePartService.getById(id);
|
||||||
|
if (entity == null) {
|
||||||
|
return Result.error("未找到对应数据");
|
||||||
|
}
|
||||||
|
return Result.OK(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "校验备品件名称是否重复(同租户未删除数据;dataId 为编辑时当前主键)")
|
||||||
|
@GetMapping(value = "/checkSparePartName")
|
||||||
|
public Result<String> checkSparePartName(
|
||||||
|
@RequestParam(name = "sparePartName", required = true) String sparePartName,
|
||||||
|
@RequestParam(name = "dataId", required = false) String dataId) {
|
||||||
|
if (oConvertUtils.isEmpty(sparePartName) || sparePartName.trim().isEmpty()) {
|
||||||
|
return Result.OK("该值可用!");
|
||||||
|
}
|
||||||
|
MesXslSparePart ctx = new MesXslSparePart();
|
||||||
|
if (mesXslSparePartService.isSparePartNameDuplicated(sparePartName.trim(), dataId, ctx)) {
|
||||||
|
return Result.error("备品件名称不能重复");
|
||||||
|
}
|
||||||
|
return Result.OK("该值可用!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresPermissions("mes:mes_xsl_spare_part:exportXls")
|
||||||
|
@RequestMapping(value = "/exportXls")
|
||||||
|
public ModelAndView exportXls(HttpServletRequest request, MesXslSparePart model) {
|
||||||
|
return super.exportXls(request, model, MesXslSparePart.class, "MES备品件信息");
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresPermissions("mes:mes_xsl_spare_part:importExcel")
|
||||||
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
||||||
|
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
//update-begin---author:jiangxh ---date:20260515 for:【MES】备品件信息导入:名称唯一、类别名称与单位编码解析、库存校验-----------
|
||||||
|
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||||
|
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||||
|
for (Map.Entry<String, MultipartFile> ent : fileMap.entrySet()) {
|
||||||
|
MultipartFile file = ent.getValue();
|
||||||
|
ImportParams params = new ImportParams();
|
||||||
|
params.setTitleRows(2);
|
||||||
|
params.setHeadRows(1);
|
||||||
|
params.setNeedSave(true);
|
||||||
|
try {
|
||||||
|
List<MesXslSparePart> list = ExcelImportUtil.importExcel(file.getInputStream(), MesXslSparePart.class, params);
|
||||||
|
if (list == null) {
|
||||||
|
list = List.of();
|
||||||
|
}
|
||||||
|
Set<String> namesInFile = new HashSet<>();
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
MesXslSparePart row = list.get(i);
|
||||||
|
int rowNo = i + 1;
|
||||||
|
if (row == null) {
|
||||||
|
return Result.error("文件导入失败:第 " + rowNo + " 条数据无效(空行)");
|
||||||
|
}
|
||||||
|
String pn = row.getSparePartName();
|
||||||
|
if (pn != null) {
|
||||||
|
pn = pn.trim();
|
||||||
|
}
|
||||||
|
if (oConvertUtils.isEmpty(pn)) {
|
||||||
|
return Result.error("文件导入失败:第 " + rowNo + " 条备品件名称不能为空");
|
||||||
|
}
|
||||||
|
row.setSparePartName(pn);
|
||||||
|
if (!namesInFile.add(pn)) {
|
||||||
|
return Result.error("文件导入失败:备品件名称【" + pn + "】在导入文件中重复");
|
||||||
|
}
|
||||||
|
if (mesXslSparePartService.isSparePartNameDuplicated(pn, null, row)) {
|
||||||
|
return Result.error("文件导入失败:第 " + rowNo + " 条备品件名称【" + pn + "】不能重复(同租户未删除数据中已存在)");
|
||||||
|
}
|
||||||
|
|
||||||
|
String catName = row.getImportCategoryName();
|
||||||
|
if (catName != null) {
|
||||||
|
catName = catName.trim();
|
||||||
|
}
|
||||||
|
if (oConvertUtils.isEmpty(catName)) {
|
||||||
|
return Result.error("文件导入失败:第 " + rowNo + " 条备品件类别名称不能为空");
|
||||||
|
}
|
||||||
|
MesXslSparePartsCategory cat =
|
||||||
|
mesXslSparePartsCategoryService.findOneActiveByCategoryNameAndTenant(catName, row.getTenantId());
|
||||||
|
if (cat == null) {
|
||||||
|
return Result.error("文件导入失败:第 " + rowNo + " 条备品件类别名称【" + catName + "】不存在或未删除数据中无匹配");
|
||||||
|
}
|
||||||
|
row.setSparePartsCategoryId(cat.getId());
|
||||||
|
row.setSparePartsCategoryName(cat.getCategoryName());
|
||||||
|
row.setImportCategoryName(null);
|
||||||
|
|
||||||
|
String ucode = row.getImportUnitCode();
|
||||||
|
if (ucode != null) {
|
||||||
|
ucode = ucode.trim();
|
||||||
|
}
|
||||||
|
if (oConvertUtils.isEmpty(ucode)) {
|
||||||
|
return Result.error("文件导入失败:第 " + rowNo + " 条单位编码不能为空");
|
||||||
|
}
|
||||||
|
MesXslUnit unit = mesXslUnitService.findOneActiveByUnitCodeAndTenant(ucode, row.getTenantId());
|
||||||
|
if (unit == null) {
|
||||||
|
return Result.error("文件导入失败:第 " + rowNo + " 条单位编码【" + ucode + "】不存在或未删除数据中无匹配");
|
||||||
|
}
|
||||||
|
String st = unit.getStatus();
|
||||||
|
if (st != null && "1".equals(st.trim())) {
|
||||||
|
return Result.error("文件导入失败:第 " + rowNo + " 条单位编码【" + ucode + "】对应单位已停用");
|
||||||
|
}
|
||||||
|
row.setUnitId(unit.getId());
|
||||||
|
row.setUnitName(unit.getUnitName());
|
||||||
|
row.setImportUnitCode(null);
|
||||||
|
|
||||||
|
String errStock = normalizeAndValidateStocks(row, rowNo);
|
||||||
|
if (errStock != null) {
|
||||||
|
return Result.error(errStock);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (row.getSpecModel() != null) {
|
||||||
|
row.setSpecModel(row.getSpecModel().trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
mesXslSparePartService.saveBatch(list);
|
||||||
|
log.info("备品件信息Excel导入完成,耗时{}ms,行数={}", System.currentTimeMillis() - start, list.size());
|
||||||
|
return Result.ok("文件导入成功!数据行数:" + list.size());
|
||||||
|
} catch (Exception e) {
|
||||||
|
String msg = e.getMessage();
|
||||||
|
log.error(msg, e);
|
||||||
|
if (msg != null && msg.indexOf("Duplicate entry") >= 0) {
|
||||||
|
return Result.error("文件导入失败: 存在重复数据(备品件名称不能重复)");
|
||||||
|
}
|
||||||
|
return Result.error("文件导入失败:" + e.getMessage());
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
file.getInputStream().close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//update-end---author:jiangxh ---date:20260515 for:【MES】备品件信息导入:名称唯一、类别名称与单位编码解析、库存校验-----------
|
||||||
|
return Result.error("文件导入失败!");
|
||||||
|
}
|
||||||
|
|
||||||
|
//update-begin---author:jiangxh ---date:20260515 for:【MES】备品件信息保存前校验与冗余名称回填-----------
|
||||||
|
private String validateForSave(MesXslSparePart model, String excludeId) {
|
||||||
|
if (oConvertUtils.isEmpty(model.getSparePartName()) || model.getSparePartName().trim().isEmpty()) {
|
||||||
|
return "备品件名称不能为空";
|
||||||
|
}
|
||||||
|
String pn = model.getSparePartName().trim();
|
||||||
|
model.setSparePartName(pn);
|
||||||
|
if (mesXslSparePartService.isSparePartNameDuplicated(pn, excludeId, model)) {
|
||||||
|
return "备品件名称不能重复";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oConvertUtils.isEmpty(model.getSparePartsCategoryId())) {
|
||||||
|
return "请选择所属备品件类别";
|
||||||
|
}
|
||||||
|
MesXslSparePartsCategory cat = mesXslSparePartsCategoryService.getById(model.getSparePartsCategoryId());
|
||||||
|
if (cat == null) {
|
||||||
|
return "所属备品件类别不存在";
|
||||||
|
}
|
||||||
|
model.setSparePartsCategoryName(cat.getCategoryName());
|
||||||
|
|
||||||
|
if (oConvertUtils.isEmpty(model.getUnitId())) {
|
||||||
|
return "请选择单位";
|
||||||
|
}
|
||||||
|
MesXslUnit unit = mesXslUnitService.getById(model.getUnitId());
|
||||||
|
if (unit == null) {
|
||||||
|
return "所选单位不存在";
|
||||||
|
}
|
||||||
|
String ust = unit.getStatus();
|
||||||
|
if (ust != null && "1".equals(ust.trim())) {
|
||||||
|
return "所选单位已停用,请重新选择";
|
||||||
|
}
|
||||||
|
model.setUnitName(unit.getUnitName());
|
||||||
|
|
||||||
|
String errStock = normalizeAndValidateStocks(model, null);
|
||||||
|
if (errStock != null) {
|
||||||
|
return errStock;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (model.getSpecModel() != null) {
|
||||||
|
model.setSpecModel(model.getSpecModel().trim());
|
||||||
|
}
|
||||||
|
model.setImportCategoryName(null);
|
||||||
|
model.setImportUnitCode(null);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 规范化 max/min 库存并校验;rowNo 非空时错误信息带行号(导入用) */
|
||||||
|
private String normalizeAndValidateStocks(MesXslSparePart model, Integer rowNo) {
|
||||||
|
BigDecimal max = model.getMaxStock();
|
||||||
|
BigDecimal min = model.getMinStock();
|
||||||
|
if (max == null || min == null) {
|
||||||
|
return rowNo == null ? "最大库存、最小库存不能为空" : "文件导入失败:第 " + rowNo + " 条最大库存、最小库存不能为空";
|
||||||
|
}
|
||||||
|
max = max.stripTrailingZeros();
|
||||||
|
min = min.stripTrailingZeros();
|
||||||
|
model.setMaxStock(max);
|
||||||
|
model.setMinStock(min);
|
||||||
|
if (max.compareTo(BigDecimal.ZERO) < 0 || min.compareTo(BigDecimal.ZERO) < 0) {
|
||||||
|
return rowNo == null ? "最大库存、最小库存不能为负数" : "文件导入失败:第 " + rowNo + " 条最大库存、最小库存不能为负数";
|
||||||
|
}
|
||||||
|
if (max.compareTo(min) < 0) {
|
||||||
|
return rowNo == null ? "最大库存不能小于最小库存" : "文件导入失败:第 " + rowNo + " 条最大库存不能小于最小库存";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
//update-end---author:jiangxh ---date:20260515 for:【MES】备品件信息保存前校验与冗余名称回填-----------
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package org.jeecg.modules.xslmes.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MES 备品件信息(表 mes_xsl_spare_part)
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("mes_xsl_spare_part")
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Schema(description = "MES备品件信息")
|
||||||
|
public class MesXslSparePart implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@TableId(type = IdType.ASSIGN_ID)
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Excel(name = "备品件名称", width = 22)
|
||||||
|
@Schema(description = "备品件名称(同租户未删除数据中唯一)")
|
||||||
|
private String sparePartName;
|
||||||
|
|
||||||
|
@Schema(description = "所属备品件类别主键")
|
||||||
|
private String sparePartsCategoryId;
|
||||||
|
|
||||||
|
@Excel(name = "类别名称", width = 20)
|
||||||
|
@Schema(description = "备品件类别名称冗余")
|
||||||
|
private String sparePartsCategoryName;
|
||||||
|
|
||||||
|
@Excel(name = "规格型号", width = 20)
|
||||||
|
@Schema(description = "规格型号")
|
||||||
|
private String specModel;
|
||||||
|
|
||||||
|
@Excel(name = "最大库存", width = 14)
|
||||||
|
@Schema(description = "最大库存")
|
||||||
|
private BigDecimal maxStock;
|
||||||
|
|
||||||
|
@Excel(name = "最小库存", width = 14)
|
||||||
|
@Schema(description = "最小库存")
|
||||||
|
private BigDecimal minStock;
|
||||||
|
|
||||||
|
@Schema(description = "单位 mes_xsl_unit.id")
|
||||||
|
private String unitId;
|
||||||
|
|
||||||
|
@Excel(name = "单位名称", width = 14)
|
||||||
|
@Schema(description = "单位名称冗余")
|
||||||
|
private String unitName;
|
||||||
|
|
||||||
|
/** Excel 导入用:备品件类别名称,不落库 */
|
||||||
|
@TableField(exist = false)
|
||||||
|
@Excel(name = "备品件类别名称", width = 22)
|
||||||
|
@Schema(description = "导入用备品件类别名称")
|
||||||
|
private String importCategoryName;
|
||||||
|
|
||||||
|
/** Excel 导入用:单位编码 mes_xsl_unit.unit_code,不落库 */
|
||||||
|
@TableField(exist = false)
|
||||||
|
@Excel(name = "单位编码", width = 16)
|
||||||
|
@Schema(description = "导入用单位编码")
|
||||||
|
private String importUnitCode;
|
||||||
|
|
||||||
|
private Integer tenantId;
|
||||||
|
private String sysOrgCode;
|
||||||
|
private String createBy;
|
||||||
|
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date createTime;
|
||||||
|
private String updateBy;
|
||||||
|
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date updateTime;
|
||||||
|
private Integer delFlag;
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package org.jeecg.modules.xslmes.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.jeecg.modules.xslmes.entity.MesXslSparePart;
|
||||||
|
|
||||||
|
public interface MesXslSparePartMapper extends BaseMapper<MesXslSparePart> {}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* MES XSL 业务模块(Maven 工程名:jeecg-module-xslmes)。
|
* MES XSL 业务模块(Maven 工程名:jeecg-module-xslmes)。
|
||||||
* 包含:客户管理({@link org.jeecg.modules.xslmes.entity.MesXslCustomer})、工序管理({@link org.jeecg.modules.xslmes.entity.MesXslProcessOperation})、设备类别({@link org.jeecg.modules.xslmes.entity.MesXslEquipmentCategory})、设备类型({@link org.jeecg.modules.xslmes.entity.MesXslEquipmentType})、设备部位({@link org.jeecg.modules.xslmes.entity.MesXslEquipmentPart})、设备小部位({@link org.jeecg.modules.xslmes.entity.MesXslEquipmentSubPart})、备品件类别({@link org.jeecg.modules.xslmes.entity.MesXslSparePartsCategory})等。
|
* 包含:客户管理({@link org.jeecg.modules.xslmes.entity.MesXslCustomer})、工序管理({@link org.jeecg.modules.xslmes.entity.MesXslProcessOperation})、设备类别({@link org.jeecg.modules.xslmes.entity.MesXslEquipmentCategory})、设备类型({@link org.jeecg.modules.xslmes.entity.MesXslEquipmentType})、设备部位({@link org.jeecg.modules.xslmes.entity.MesXslEquipmentPart})、设备小部位({@link org.jeecg.modules.xslmes.entity.MesXslEquipmentSubPart})、备品件类别({@link org.jeecg.modules.xslmes.entity.MesXslSparePartsCategory})、备品件信息({@link org.jeecg.modules.xslmes.entity.MesXslSparePart})等。
|
||||||
*/
|
*/
|
||||||
package org.jeecg.modules.xslmes;
|
package org.jeecg.modules.xslmes;
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package org.jeecg.modules.xslmes.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import org.jeecg.modules.xslmes.entity.MesXslSparePart;
|
||||||
|
|
||||||
|
public interface IMesXslSparePartService extends IService<MesXslSparePart> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备品件名称是否已被占用(同租户未删除数据中唯一)。
|
||||||
|
*/
|
||||||
|
boolean isSparePartNameDuplicated(String sparePartName, String excludeId, MesXslSparePart context);
|
||||||
|
}
|
||||||
@@ -13,4 +13,9 @@ public interface IMesXslSparePartsCategoryService extends IService<MesXslSparePa
|
|||||||
* @param context 当前提交的实体(可取 tenantId;可为 null)
|
* @param context 当前提交的实体(可取 tenantId;可为 null)
|
||||||
*/
|
*/
|
||||||
boolean isCategoryNameDuplicated(String categoryName, String excludeId, MesXslSparePartsCategory context);
|
boolean isCategoryNameDuplicated(String categoryName, String excludeId, MesXslSparePartsCategory context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按类别名称在未删除数据中查询一条(同租户),用于备品件信息导入解析等。
|
||||||
|
*/
|
||||||
|
MesXslSparePartsCategory findOneActiveByCategoryNameAndTenant(String categoryName, Integer tenantId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,4 +12,9 @@ public interface IMesXslUnitService extends IService<MesXslUnit> {
|
|||||||
|
|
||||||
/** 单位分类(sys_category)选中节点及其所有下级 id,用于列表筛选 */
|
/** 单位分类(sys_category)选中节点及其所有下级 id,用于列表筛选 */
|
||||||
List<String> listDescendantCategoryIds(String rootId);
|
List<String> listDescendantCategoryIds(String rootId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按单位编码在未删除数据中查询一条(同租户),用于备品件信息导入解析等。
|
||||||
|
*/
|
||||||
|
MesXslUnit findOneActiveByUnitCodeAndTenant(String unitCode, Integer tenantId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package org.jeecg.modules.xslmes.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.jeecg.common.config.TenantContext;
|
||||||
|
import org.jeecg.common.constant.CommonConstant;
|
||||||
|
import org.jeecg.common.util.SpringContextUtils;
|
||||||
|
import org.jeecg.common.util.TokenUtils;
|
||||||
|
import org.jeecg.common.util.oConvertUtils;
|
||||||
|
import org.jeecg.modules.xslmes.entity.MesXslSparePart;
|
||||||
|
import org.jeecg.modules.xslmes.mapper.MesXslSparePartMapper;
|
||||||
|
import org.jeecg.modules.xslmes.service.IMesXslSparePartService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class MesXslSparePartServiceImpl extends ServiceImpl<MesXslSparePartMapper, MesXslSparePart> implements IMesXslSparePartService {
|
||||||
|
|
||||||
|
//update-begin---author:jiangxh ---date:20260515 for:【MES】备品件名称同租户不可重复;仅统计未删除(del_flag=0 或 null)-----------
|
||||||
|
@Override
|
||||||
|
public boolean isSparePartNameDuplicated(String sparePartName, String excludeId, MesXslSparePart context) {
|
||||||
|
if (oConvertUtils.isEmpty(sparePartName)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Integer tenantId = resolveTenantId(context);
|
||||||
|
LambdaQueryWrapper<MesXslSparePart> w = new LambdaQueryWrapper<>();
|
||||||
|
w.eq(MesXslSparePart::getSparePartName, sparePartName.trim());
|
||||||
|
w.and(
|
||||||
|
q ->
|
||||||
|
q.eq(MesXslSparePart::getDelFlag, CommonConstant.DEL_FLAG_0)
|
||||||
|
.or()
|
||||||
|
.isNull(MesXslSparePart::getDelFlag));
|
||||||
|
if (oConvertUtils.isNotEmpty(excludeId)) {
|
||||||
|
w.ne(MesXslSparePart::getId, excludeId);
|
||||||
|
}
|
||||||
|
if (tenantId != null) {
|
||||||
|
w.eq(MesXslSparePart::getTenantId, tenantId);
|
||||||
|
}
|
||||||
|
return this.count(w) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Integer resolveTenantId(MesXslSparePart context) {
|
||||||
|
if (context != null && context.getTenantId() != null) {
|
||||||
|
return context.getTenantId();
|
||||||
|
}
|
||||||
|
String ts = TenantContext.getTenant();
|
||||||
|
if (oConvertUtils.isEmpty(ts)) {
|
||||||
|
try {
|
||||||
|
ts = TokenUtils.getTenantIdByRequest(SpringContextUtils.getHttpServletRequest());
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (oConvertUtils.isEmpty(ts)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(ts.trim());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//update-end---author:jiangxh ---date:20260515 for:【MES】备品件名称同租户不可重复;仅统计未删除(del_flag=0 或 null)-----------
|
||||||
|
}
|
||||||
@@ -39,6 +39,27 @@ public class MesXslSparePartsCategoryServiceImpl extends ServiceImpl<MesXslSpare
|
|||||||
return this.count(w) > 0;
|
return this.count(w) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//update-begin---author:jiangxh ---date:20260515 for:【MES】备品件类别按名称+租户查询单条,供备品件信息导入解析-----------
|
||||||
|
@Override
|
||||||
|
public MesXslSparePartsCategory findOneActiveByCategoryNameAndTenant(String categoryName, Integer tenantId) {
|
||||||
|
if (oConvertUtils.isEmpty(categoryName)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
LambdaQueryWrapper<MesXslSparePartsCategory> w = new LambdaQueryWrapper<>();
|
||||||
|
w.eq(MesXslSparePartsCategory::getCategoryName, categoryName.trim());
|
||||||
|
w.and(
|
||||||
|
q ->
|
||||||
|
q.eq(MesXslSparePartsCategory::getDelFlag, CommonConstant.DEL_FLAG_0)
|
||||||
|
.or()
|
||||||
|
.isNull(MesXslSparePartsCategory::getDelFlag));
|
||||||
|
if (tenantId != null) {
|
||||||
|
w.eq(MesXslSparePartsCategory::getTenantId, tenantId);
|
||||||
|
}
|
||||||
|
w.last("LIMIT 1");
|
||||||
|
return this.getOne(w, false);
|
||||||
|
}
|
||||||
|
//update-end---author:jiangxh ---date:20260515 for:【MES】备品件类别按名称+租户查询单条,供备品件信息导入解析-----------
|
||||||
|
|
||||||
private static Integer resolveTenantId(MesXslSparePartsCategory context) {
|
private static Integer resolveTenantId(MesXslSparePartsCategory context) {
|
||||||
if (context != null && context.getTenantId() != null) {
|
if (context != null && context.getTenantId() != null) {
|
||||||
return context.getTenantId();
|
return context.getTenantId();
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package org.jeecg.modules.xslmes.service.impl;
|
package org.jeecg.modules.xslmes.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.jeecg.common.util.oConvertUtils;
|
||||||
import org.jeecg.modules.xslmes.entity.MesXslUnit;
|
import org.jeecg.modules.xslmes.entity.MesXslUnit;
|
||||||
import org.jeecg.modules.xslmes.mapper.MesXslUnitMapper;
|
import org.jeecg.modules.xslmes.mapper.MesXslUnitMapper;
|
||||||
import org.jeecg.modules.xslmes.service.IMesXslUnitService;
|
import org.jeecg.modules.xslmes.service.IMesXslUnitService;
|
||||||
@@ -18,4 +20,20 @@ public class MesXslUnitServiceImpl extends ServiceImpl<MesXslUnitMapper, MesXslU
|
|||||||
public List<String> listDescendantCategoryIds(String rootId) {
|
public List<String> listDescendantCategoryIds(String rootId) {
|
||||||
return baseMapper.listDescendantCategoryIds(rootId);
|
return baseMapper.listDescendantCategoryIds(rootId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//update-begin---author:jiangxh ---date:20260515 for:【MES】单位按编码+租户查询单条,供备品件信息导入解析-----------
|
||||||
|
@Override
|
||||||
|
public MesXslUnit findOneActiveByUnitCodeAndTenant(String unitCode, Integer tenantId) {
|
||||||
|
if (oConvertUtils.isEmpty(unitCode)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
LambdaQueryWrapper<MesXslUnit> w = new LambdaQueryWrapper<>();
|
||||||
|
w.eq(MesXslUnit::getUnitCode, unitCode.trim());
|
||||||
|
if (tenantId != null) {
|
||||||
|
w.eq(MesXslUnit::getTenantId, tenantId);
|
||||||
|
}
|
||||||
|
w.last("LIMIT 1");
|
||||||
|
return this.getOne(w, false);
|
||||||
|
}
|
||||||
|
//update-end---author:jiangxh ---date:20260515 for:【MES】单位按编码+租户查询单条,供备品件信息导入解析-----------
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,3 +161,23 @@ jeecgboot-vue3/src/views/xslmes/mesXslSparePartsCategory/MesXslSparePartsCategor
|
|||||||
jeecgboot-vue3/src/views/xslmes/mesXslSparePartsCategory/MesXslSparePartsCategory.data.ts
|
jeecgboot-vue3/src/views/xslmes/mesXslSparePartsCategory/MesXslSparePartsCategory.data.ts
|
||||||
jeecgboot-vue3/src/views/xslmes/mesXslSparePartsCategory/MesXslSparePartsCategory.api.ts
|
jeecgboot-vue3/src/views/xslmes/mesXslSparePartsCategory/MesXslSparePartsCategory.api.ts
|
||||||
jeecgboot-vue3/src/views/xslmes/mesXslSparePartsCategory/components/MesXslSparePartsCategoryModal.vue
|
jeecgboot-vue3/src/views/xslmes/mesXslSparePartsCategory/components/MesXslSparePartsCategoryModal.vue
|
||||||
|
|
||||||
|
-- author:jiangxh---date:20260515--for: 【MES】新增备品件信息(mes_xsl_spare_part,挂 MES 基础资料,名称同租户唯一、类别与单位冗余、库存上下限) ---
|
||||||
|
jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/flyway/sql/mysql/V3.9.2_62__mes_xsl_spare_part.sql
|
||||||
|
jeecg-boot/db/mes-xsl-spare-part-menu-permission.sql
|
||||||
|
jeecg-boot/db/mes-xsl-spare-part.sql
|
||||||
|
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/entity/MesXslSparePart.java
|
||||||
|
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mapper/MesXslSparePartMapper.java
|
||||||
|
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/service/IMesXslSparePartService.java
|
||||||
|
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/service/impl/MesXslSparePartServiceImpl.java
|
||||||
|
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/controller/MesXslSparePartController.java
|
||||||
|
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/service/IMesXslSparePartsCategoryService.java
|
||||||
|
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/service/impl/MesXslSparePartsCategoryServiceImpl.java
|
||||||
|
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/service/IMesXslUnitService.java
|
||||||
|
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/service/impl/MesXslUnitServiceImpl.java
|
||||||
|
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/package-info.java
|
||||||
|
jeecgboot-vue3/src/views/xslmes/mesXslSparePartsCategory/components/MesXslSparePartsCategorySelectModal.vue
|
||||||
|
jeecgboot-vue3/src/views/xslmes/mesXslSparePart/MesXslSparePartList.vue
|
||||||
|
jeecgboot-vue3/src/views/xslmes/mesXslSparePart/MesXslSparePart.data.ts
|
||||||
|
jeecgboot-vue3/src/views/xslmes/mesXslSparePart/MesXslSparePart.api.ts
|
||||||
|
jeecgboot-vue3/src/views/xslmes/mesXslSparePart/components/MesXslSparePartModal.vue
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
-- MES 备品件信息:建表 + 菜单 + 按钮 + 租户 admin 授权(与 jeecg-boot/db/mes-xsl-spare-part-menu-permission.sql 建表与菜单段一致)
|
||||||
|
-- 权限前缀:mes:mes_xsl_spare_part:*(与 Controller、前端 v-auth 一致)
|
||||||
|
-- 依赖:mes_xsl_spare_parts_category、mes_xsl_unit;父菜单 MES基础资料 / MES资料
|
||||||
|
SET NAMES utf8mb4;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `mes_xsl_spare_part` (
|
||||||
|
`id` varchar(32) NOT NULL COMMENT '主键',
|
||||||
|
`spare_part_name` varchar(128) NOT NULL COMMENT '备品件名称(同租户未删除数据中唯一)',
|
||||||
|
`spare_parts_category_id` varchar(32) NOT NULL COMMENT '所属备品件类别 mes_xsl_spare_parts_category.id',
|
||||||
|
`spare_parts_category_name` varchar(128) DEFAULT NULL COMMENT '备品件类别名称冗余',
|
||||||
|
`spec_model` varchar(200) DEFAULT NULL COMMENT '规格型号',
|
||||||
|
`max_stock` decimal(18,4) NOT NULL DEFAULT '0.0000' COMMENT '最大库存',
|
||||||
|
`min_stock` decimal(18,4) NOT NULL DEFAULT '0.0000' COMMENT '最小库存',
|
||||||
|
`unit_id` varchar(36) NOT NULL COMMENT '单位 mes_xsl_unit.id',
|
||||||
|
`unit_name` varchar(100) DEFAULT NULL COMMENT '单位名称冗余',
|
||||||
|
`tenant_id` int DEFAULT NULL COMMENT '租户',
|
||||||
|
`sys_org_code` varchar(64) DEFAULT NULL COMMENT '部门',
|
||||||
|
`create_by` varchar(32) DEFAULT NULL COMMENT '创建人',
|
||||||
|
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
||||||
|
`update_by` varchar(32) DEFAULT NULL COMMENT '更新人',
|
||||||
|
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
|
||||||
|
`del_flag` int DEFAULT '0' COMMENT '删除标记(0正常1删除)',
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `idx_msp_tenant_name` (`tenant_id`, `spare_part_name`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='MES备品件信息';
|
||||||
|
|
||||||
|
SET @mes_tenant_id = 1002;
|
||||||
|
|
||||||
|
SET @mes_base_pid = (
|
||||||
|
SELECT MIN(`id`) FROM `sys_permission`
|
||||||
|
WHERE `del_flag` = 0 AND `menu_type` = 0 AND `name` IN ('MES基础资料', 'MES资料')
|
||||||
|
);
|
||||||
|
SET @mes_base_pid = IFNULL(@mes_base_pid, '1860000000000000001');
|
||||||
|
|
||||||
|
INSERT INTO `sys_permission`(`id`, `parent_id`, `name`, `url`, `component`, `component_name`, `menu_type`, `perms`, `perms_type`, `sort_no`, `is_route`, `is_leaf`, `hidden`, `status`, `del_flag`, `keep_alive`, `internal_or_external`, `create_by`, `create_time`)
|
||||||
|
VALUES ('1860000000000000105', @mes_base_pid, '备品件信息', '/xslmes/mesXslSparePart', 'xslmes/mesXslSparePart/MesXslSparePartList', NULL, 1, NULL, '1', 16, 1, 0, 0, '1', 0, 1, 0, 'admin', NOW())
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
`parent_id` = VALUES(`parent_id`), `name` = VALUES(`name`), `url` = VALUES(`url`), `component` = VALUES(`component`), `component_name` = VALUES(`component_name`),
|
||||||
|
`menu_type` = VALUES(`menu_type`), `perms` = VALUES(`perms`), `perms_type` = VALUES(`perms_type`), `sort_no` = VALUES(`sort_no`),
|
||||||
|
`is_route` = VALUES(`is_route`), `is_leaf` = VALUES(`is_leaf`), `hidden` = VALUES(`hidden`), `status` = VALUES(`status`), `del_flag` = VALUES(`del_flag`),
|
||||||
|
`keep_alive` = VALUES(`keep_alive`), `internal_or_external` = VALUES(`internal_or_external`);
|
||||||
|
|
||||||
|
INSERT INTO `sys_permission`(`id`, `parent_id`, `name`, `menu_type`, `perms`, `perms_type`, `status`, `del_flag`, `create_by`, `create_time`) VALUES
|
||||||
|
('1860000000000000106', '1860000000000000105', '新增', 2, 'mes:mes_xsl_spare_part:add', '1', '1', 0, 'admin', NOW()),
|
||||||
|
('1860000000000000107', '1860000000000000105', '编辑', 2, 'mes:mes_xsl_spare_part:edit', '1', '1', 0, 'admin', NOW()),
|
||||||
|
('1860000000000000108', '1860000000000000105', '删除', 2, 'mes:mes_xsl_spare_part:delete', '1', '1', 0, 'admin', NOW()),
|
||||||
|
('1860000000000000109', '1860000000000000105', '批量删除', 2, 'mes:mes_xsl_spare_part:deleteBatch', '1', '1', 0, 'admin', NOW()),
|
||||||
|
('1860000000000000110', '1860000000000000105', '导出', 2, 'mes:mes_xsl_spare_part:exportXls', '1', '1', 0, 'admin', NOW()),
|
||||||
|
('1860000000000000111', '1860000000000000105', '导入', 2, 'mes:mes_xsl_spare_part:importExcel', '1', '1', 0, 'admin', NOW())
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
`parent_id` = VALUES(`parent_id`), `name` = VALUES(`name`), `menu_type` = VALUES(`menu_type`), `perms` = VALUES(`perms`), `perms_type` = VALUES(`perms_type`),
|
||||||
|
`status` = VALUES(`status`), `del_flag` = VALUES(`del_flag`);
|
||||||
|
|
||||||
|
INSERT INTO `sys_role_permission`(`id`, `role_id`, `permission_id`, `operate_date`, `operate_ip`)
|
||||||
|
SELECT REPLACE(UUID(), '-', ''), r.`id`, p.`id`, NOW(), '127.0.0.1'
|
||||||
|
FROM `sys_role` r
|
||||||
|
CROSS JOIN `sys_permission` p
|
||||||
|
WHERE r.`tenant_id` = @mes_tenant_id
|
||||||
|
AND r.`role_code` = 'admin'
|
||||||
|
AND p.`id` IN (
|
||||||
|
'1860000000000000105',
|
||||||
|
'1860000000000000106', '1860000000000000107', '1860000000000000108', '1860000000000000109',
|
||||||
|
'1860000000000000110', '1860000000000000111'
|
||||||
|
)
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1 FROM `sys_role_permission` rp
|
||||||
|
WHERE rp.`role_id` = r.`id` AND rp.`permission_id` = p.`id`
|
||||||
|
);
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import { defHttp } from '/@/utils/http/axios';
|
||||||
|
import { useMessage } from '/@/hooks/web/useMessage';
|
||||||
|
|
||||||
|
const { createConfirm } = useMessage();
|
||||||
|
|
||||||
|
enum Api {
|
||||||
|
list = '/xslmes/mesXslSparePart/list',
|
||||||
|
checkSparePartName = '/xslmes/mesXslSparePart/checkSparePartName',
|
||||||
|
save = '/xslmes/mesXslSparePart/add',
|
||||||
|
edit = '/xslmes/mesXslSparePart/edit',
|
||||||
|
deleteOne = '/xslmes/mesXslSparePart/delete',
|
||||||
|
deleteBatch = '/xslmes/mesXslSparePart/deleteBatch',
|
||||||
|
importExcel = '/xslmes/mesXslSparePart/importExcel',
|
||||||
|
exportXls = '/xslmes/mesXslSparePart/exportXls',
|
||||||
|
queryById = '/xslmes/mesXslSparePart/queryById',
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getExportUrl = Api.exportXls;
|
||||||
|
export const getImportUrl = Api.importExcel;
|
||||||
|
|
||||||
|
export const list = (params) => defHttp.get({ url: Api.list, params });
|
||||||
|
|
||||||
|
export const queryById = (params: { id: string }) => defHttp.get({ url: Api.queryById, params });
|
||||||
|
|
||||||
|
export const checkSparePartName = (params: { sparePartName: string; dataId?: string }) =>
|
||||||
|
defHttp.get(
|
||||||
|
{ url: Api.checkSparePartName, params },
|
||||||
|
{
|
||||||
|
successMessageMode: 'none',
|
||||||
|
errorMessageMode: 'none',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export const deleteOne = (params, handleSuccess) => {
|
||||||
|
return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
|
||||||
|
handleSuccess();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const batchDelete = (params, handleSuccess) => {
|
||||||
|
createConfirm({
|
||||||
|
iconType: 'warning',
|
||||||
|
title: '确认删除',
|
||||||
|
content: '是否删除选中数据',
|
||||||
|
okText: '确认',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: () => {
|
||||||
|
return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
|
||||||
|
handleSuccess();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const saveOrUpdate = (params, isUpdate) => {
|
||||||
|
const url = isUpdate ? Api.edit : Api.save;
|
||||||
|
return defHttp.post({ url, params });
|
||||||
|
};
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
import { BasicColumn, FormSchema } from '/@/components/Table';
|
||||||
|
import { checkSparePartName } from './MesXslSparePart.api';
|
||||||
|
|
||||||
|
export const columns: BasicColumn[] = [
|
||||||
|
{ title: '备品件名称', align: 'center', dataIndex: 'sparePartName', width: 160 },
|
||||||
|
{ title: '类别名称', align: 'center', dataIndex: 'sparePartsCategoryName', width: 140 },
|
||||||
|
{ title: '规格型号', align: 'center', dataIndex: 'specModel', width: 140, ellipsis: true },
|
||||||
|
{ title: '最大库存', align: 'center', dataIndex: 'maxStock', width: 110 },
|
||||||
|
{ title: '最小库存', align: 'center', dataIndex: 'minStock', width: 110 },
|
||||||
|
{ title: '单位', align: 'center', dataIndex: 'unitName', width: 90 },
|
||||||
|
{ title: '创建人', align: 'center', dataIndex: 'createBy', width: 100 },
|
||||||
|
{
|
||||||
|
title: '创建时间',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'createTime',
|
||||||
|
width: 165,
|
||||||
|
customRender: ({ text }) => (!text ? '' : String(text).length > 19 ? String(text).substring(0, 19) : text),
|
||||||
|
},
|
||||||
|
{ title: '租户ID', align: 'center', dataIndex: 'tenantId', width: 90, defaultHidden: true },
|
||||||
|
];
|
||||||
|
|
||||||
|
export const searchFormSchema: FormSchema[] = [
|
||||||
|
{ label: '备品件名称', field: 'sparePartName', component: 'Input', colProps: { span: 6 } },
|
||||||
|
{ label: '类别名称', field: 'sparePartsCategoryName', component: 'Input', colProps: { span: 6 } },
|
||||||
|
{ label: '规格型号', field: 'specModel', component: 'Input', colProps: { span: 6 } },
|
||||||
|
];
|
||||||
|
|
||||||
|
export const formSchema: FormSchema[] = [
|
||||||
|
{ label: '', field: 'id', component: 'Input', show: false },
|
||||||
|
{
|
||||||
|
label: '备品件名称',
|
||||||
|
field: 'sparePartName',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: { placeholder: '同租户内未删除数据中不可重复' },
|
||||||
|
dynamicRules: ({ model }) => [
|
||||||
|
{ required: true, message: '请输入备品件名称' },
|
||||||
|
{
|
||||||
|
validator: async (_rule, value) => {
|
||||||
|
const v = value == null ? '' : String(value).trim();
|
||||||
|
if (!v) {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await checkSparePartName({ sparePartName: v, dataId: model?.id });
|
||||||
|
return Promise.resolve();
|
||||||
|
} catch (e: any) {
|
||||||
|
const msg = e?.response?.data?.message || e?.message || '备品件名称不能重复';
|
||||||
|
return Promise.reject(msg);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
trigger: 'blur',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '',
|
||||||
|
field: 'sparePartsCategoryId',
|
||||||
|
component: 'Input',
|
||||||
|
show: false,
|
||||||
|
dynamicRules: () => [{ required: true, message: '请选择所属备品件类别' }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '所属类别',
|
||||||
|
field: 'sparePartsCategoryName',
|
||||||
|
component: 'Input',
|
||||||
|
slot: 'sparePartsCategoryPicker',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '规格型号',
|
||||||
|
field: 'specModel',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: { placeholder: '可选' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '最大库存',
|
||||||
|
field: 'maxStock',
|
||||||
|
required: true,
|
||||||
|
component: 'InputNumber',
|
||||||
|
componentProps: { min: 0, precision: 4, style: { width: '100%' } },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '最小库存',
|
||||||
|
field: 'minStock',
|
||||||
|
required: true,
|
||||||
|
component: 'InputNumber',
|
||||||
|
componentProps: { min: 0, precision: 4, style: { width: '100%' } },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '',
|
||||||
|
field: 'unitId',
|
||||||
|
component: 'Input',
|
||||||
|
show: false,
|
||||||
|
dynamicRules: () => [{ required: true, message: '请选择单位' }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '单位',
|
||||||
|
field: 'unitName',
|
||||||
|
component: 'Input',
|
||||||
|
slot: 'unitPicker',
|
||||||
|
},
|
||||||
|
];
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<BasicTable @register="registerTable" :rowSelection="rowSelection">
|
||||||
|
<template #tableTitle>
|
||||||
|
<a-button type="primary" v-auth="'mes:mes_xsl_spare_part:add'" @click="handleAdd" preIcon="ant-design:plus-outlined">
|
||||||
|
新增
|
||||||
|
</a-button>
|
||||||
|
<a-button
|
||||||
|
type="primary"
|
||||||
|
v-auth="'mes:mes_xsl_spare_part:exportXls'"
|
||||||
|
preIcon="ant-design:export-outlined"
|
||||||
|
@click="onExportXls"
|
||||||
|
>
|
||||||
|
导出
|
||||||
|
</a-button>
|
||||||
|
<j-upload-button
|
||||||
|
type="primary"
|
||||||
|
v-auth="'mes:mes_xsl_spare_part:importExcel'"
|
||||||
|
preIcon="ant-design:import-outlined"
|
||||||
|
@click="onImportXls"
|
||||||
|
>
|
||||||
|
导入
|
||||||
|
</j-upload-button>
|
||||||
|
<a-dropdown v-if="selectedRowKeys.length > 0">
|
||||||
|
<template #overlay>
|
||||||
|
<a-menu>
|
||||||
|
<a-menu-item key="1" @click="batchHandleDelete">
|
||||||
|
<Icon icon="ant-design:delete-outlined" />
|
||||||
|
删除
|
||||||
|
</a-menu-item>
|
||||||
|
</a-menu>
|
||||||
|
</template>
|
||||||
|
<a-button v-auth="'mes:mes_xsl_spare_part:deleteBatch'">
|
||||||
|
批量操作
|
||||||
|
<Icon icon="mdi:chevron-down" />
|
||||||
|
</a-button>
|
||||||
|
</a-dropdown>
|
||||||
|
</template>
|
||||||
|
<template #action="{ record }">
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{ label: '编辑', onClick: handleEdit.bind(null, record), auth: 'mes:mes_xsl_spare_part:edit' },
|
||||||
|
]"
|
||||||
|
:dropDownActions="getDropDownAction(record)"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</BasicTable>
|
||||||
|
<MesXslSparePartModal @register="registerModal" @success="handleSuccess" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" name="xslmes-mesXslSparePart" setup>
|
||||||
|
import { BasicTable, TableAction } from '/@/components/Table';
|
||||||
|
import { useModal } from '/@/components/Modal';
|
||||||
|
import { useListPage } from '/@/hooks/system/useListPage';
|
||||||
|
import Icon from '/@/components/Icon';
|
||||||
|
import MesXslSparePartModal from './components/MesXslSparePartModal.vue';
|
||||||
|
import { columns, searchFormSchema } from './MesXslSparePart.data';
|
||||||
|
import { list, deleteOne, batchDelete, getExportUrl, getImportUrl } from './MesXslSparePart.api';
|
||||||
|
|
||||||
|
const [registerModal, { openModal }] = useModal();
|
||||||
|
|
||||||
|
const { tableContext, onExportXls, onImportXls } = useListPage({
|
||||||
|
tableProps: {
|
||||||
|
title: '备品件信息',
|
||||||
|
api: list,
|
||||||
|
columns,
|
||||||
|
canResize: true,
|
||||||
|
formConfig: {
|
||||||
|
schemas: searchFormSchema,
|
||||||
|
labelWidth: 110,
|
||||||
|
autoSubmitOnEnter: true,
|
||||||
|
showAdvancedButton: true,
|
||||||
|
},
|
||||||
|
actionColumn: {
|
||||||
|
width: 200,
|
||||||
|
fixed: 'right',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
exportConfig: {
|
||||||
|
name: '备品件信息',
|
||||||
|
url: getExportUrl,
|
||||||
|
},
|
||||||
|
importConfig: {
|
||||||
|
url: getImportUrl,
|
||||||
|
success: handleSuccess,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
|
||||||
|
|
||||||
|
function handleAdd() {
|
||||||
|
openModal(true, { isUpdate: false, showFooter: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleEdit(record: Recordable) {
|
||||||
|
openModal(true, { record, isUpdate: true, showFooter: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDetail(record: Recordable) {
|
||||||
|
openModal(true, { record, isUpdate: true, showFooter: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleDelete(record) {
|
||||||
|
await deleteOne({ id: record.id }, handleSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function batchHandleDelete() {
|
||||||
|
await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleSuccess() {
|
||||||
|
selectedRowKeys.value = [];
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDropDownAction(record) {
|
||||||
|
return [
|
||||||
|
{ label: '详情', onClick: handleDetail.bind(null, record) },
|
||||||
|
{
|
||||||
|
label: '删除',
|
||||||
|
popConfirm: { title: '是否确认删除', confirm: handleDelete.bind(null, record) },
|
||||||
|
auth: 'mes:mes_xsl_spare_part:delete',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
<template>
|
||||||
|
<BasicModal @register="registerModal" :title="title" width="720" v-bind="$attrs" destroyOnClose @ok="handleSubmit">
|
||||||
|
<BasicForm @register="registerForm">
|
||||||
|
<template #sparePartsCategoryPicker="{ model, field }">
|
||||||
|
<a-input-group compact style="display: flex; width: 100%">
|
||||||
|
<a-input v-model:value="model[field]" read-only placeholder="请选择备品件类别" style="flex: 1" />
|
||||||
|
<a-button type="primary" :disabled="isDetail" @click="openCategorySelect">选择类别</a-button>
|
||||||
|
<a-button v-if="model.sparePartsCategoryId && !isDetail" @click="clearCategory">清除</a-button>
|
||||||
|
</a-input-group>
|
||||||
|
</template>
|
||||||
|
<template #unitPicker="{ model, field }">
|
||||||
|
<a-input-group compact style="display: flex; width: 100%">
|
||||||
|
<a-input v-model:value="model[field]" read-only placeholder="请选择单位" style="flex: 1" />
|
||||||
|
<a-button type="primary" :disabled="isDetail" @click="openUnitSelect">选择单位</a-button>
|
||||||
|
<a-button v-if="model.unitId && !isDetail" @click="clearUnit">清除</a-button>
|
||||||
|
</a-input-group>
|
||||||
|
</template>
|
||||||
|
</BasicForm>
|
||||||
|
<MesXslSparePartsCategorySelectModal @register="registerCategoryModal" @select="onCategorySelect" />
|
||||||
|
<MesXslUnitSelectModal @register="registerUnitModal" @select="onUnitSelect" />
|
||||||
|
</BasicModal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { computed, ref, unref } from 'vue';
|
||||||
|
import { BasicModal, useModalInner, useModal } from '/@/components/Modal';
|
||||||
|
import { BasicForm, useForm } from '/@/components/Form/index';
|
||||||
|
import { formSchema } from '../MesXslSparePart.data';
|
||||||
|
import { saveOrUpdate } from '../MesXslSparePart.api';
|
||||||
|
import MesXslSparePartsCategorySelectModal from '/@/views/xslmes/mesXslSparePartsCategory/components/MesXslSparePartsCategorySelectModal.vue';
|
||||||
|
import MesXslUnitSelectModal from '/@/views/xslmes/mesXslVehicle/components/MesXslUnitSelectModal.vue';
|
||||||
|
|
||||||
|
const emit = defineEmits(['register', 'success']);
|
||||||
|
const isUpdate = ref(true);
|
||||||
|
const isDetail = ref(false);
|
||||||
|
|
||||||
|
const [registerCategoryModal, { openModal: openCategoryModal }] = useModal();
|
||||||
|
const [registerUnitModal, { openModal: openUnitModal }] = useModal();
|
||||||
|
|
||||||
|
const [registerForm, { resetFields, setFieldsValue, validate, setProps, getFieldsValue }] = useForm({
|
||||||
|
labelWidth: 120,
|
||||||
|
schemas: formSchema,
|
||||||
|
showActionButtonGroup: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
||||||
|
await resetFields();
|
||||||
|
setModalProps({ confirmLoading: false, showCancelBtn: data?.showFooter, showOkBtn: data?.showFooter });
|
||||||
|
isUpdate.value = !!data?.isUpdate;
|
||||||
|
isDetail.value = !data?.showFooter;
|
||||||
|
if (unref(isUpdate)) await setFieldsValue({ ...data.record });
|
||||||
|
else {
|
||||||
|
await setFieldsValue({ maxStock: 0, minStock: 0 });
|
||||||
|
}
|
||||||
|
setProps({ disabled: !data?.showFooter });
|
||||||
|
});
|
||||||
|
|
||||||
|
const title = computed(() =>
|
||||||
|
!unref(isUpdate) ? '新增备品件信息' : unref(isDetail) ? '备品件信息详情' : '编辑备品件信息',
|
||||||
|
);
|
||||||
|
|
||||||
|
function openCategorySelect() {
|
||||||
|
const vals = getFieldsValue();
|
||||||
|
openCategoryModal(true, { sparePartsCategoryId: vals.sparePartsCategoryId });
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearCategory() {
|
||||||
|
setFieldsValue({ sparePartsCategoryId: '', sparePartsCategoryName: '' });
|
||||||
|
}
|
||||||
|
|
||||||
|
function onCategorySelect(payload: { sparePartsCategoryId?: string; sparePartsCategoryName?: string }) {
|
||||||
|
setFieldsValue({
|
||||||
|
sparePartsCategoryId: payload.sparePartsCategoryId || '',
|
||||||
|
sparePartsCategoryName: payload.sparePartsCategoryName || '',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function openUnitSelect() {
|
||||||
|
const vals = getFieldsValue();
|
||||||
|
openUnitModal(true, { unitId: vals.unitId });
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearUnit() {
|
||||||
|
setFieldsValue({ unitId: '', unitName: '' });
|
||||||
|
}
|
||||||
|
|
||||||
|
function onUnitSelect(payload: { unitId?: string; unitName?: string }) {
|
||||||
|
setFieldsValue({
|
||||||
|
unitId: payload.unitId || '',
|
||||||
|
unitName: payload.unitName || '',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleSubmit() {
|
||||||
|
try {
|
||||||
|
const values = await validate();
|
||||||
|
setModalProps({ confirmLoading: true });
|
||||||
|
await saveOrUpdate(values, isUpdate.value);
|
||||||
|
closeModal();
|
||||||
|
emit('success');
|
||||||
|
} finally {
|
||||||
|
setModalProps({ confirmLoading: false });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
<template>
|
||||||
|
<BasicModal v-bind="$attrs" title="选择备品件类别" :width="800" @register="registerModal" @ok="handleOk">
|
||||||
|
<BasicTable @register="registerTable" />
|
||||||
|
</BasicModal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import { BasicModal, useModalInner } from '/@/components/Modal';
|
||||||
|
import { BasicTable, useTable } from '/@/components/Table';
|
||||||
|
import { list, queryById } from '/@/views/xslmes/mesXslSparePartsCategory/MesXslSparePartsCategory.api';
|
||||||
|
|
||||||
|
const emit = defineEmits(['register', 'select']);
|
||||||
|
|
||||||
|
const selectedRow = ref<Recordable | null>(null);
|
||||||
|
|
||||||
|
function handleSelectionChange(_keys: string[], rows: Recordable[]) {
|
||||||
|
selectedRow.value = rows?.[0] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const [registerTable, { reload, setProps, getSelectRowKeys, getSelectRows, setSelectedRowKeys, clearSelectedRowKeys }] =
|
||||||
|
useTable({
|
||||||
|
api: list,
|
||||||
|
columns: [{ title: '类别名称', dataIndex: 'categoryName', width: 220 }],
|
||||||
|
rowKey: 'id',
|
||||||
|
useSearchForm: true,
|
||||||
|
formConfig: {
|
||||||
|
labelWidth: 90,
|
||||||
|
schemas: [{ label: '类别名称', field: 'categoryName', component: 'Input', colProps: { span: 12 } }],
|
||||||
|
},
|
||||||
|
pagination: { pageSize: 10 },
|
||||||
|
canResize: false,
|
||||||
|
showIndexColumn: false,
|
||||||
|
immediate: true,
|
||||||
|
rowSelection: {
|
||||||
|
type: 'radio',
|
||||||
|
columnWidth: 48,
|
||||||
|
onChange: handleSelectionChange,
|
||||||
|
},
|
||||||
|
clickToRowSelect: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
||||||
|
selectedRow.value = null;
|
||||||
|
clearSelectedRowKeys?.();
|
||||||
|
setProps({
|
||||||
|
rowSelection: {
|
||||||
|
type: 'radio',
|
||||||
|
columnWidth: 48,
|
||||||
|
onChange: handleSelectionChange,
|
||||||
|
},
|
||||||
|
clickToRowSelect: true,
|
||||||
|
});
|
||||||
|
setModalProps({ confirmLoading: false });
|
||||||
|
const cid = data?.sparePartsCategoryId as string | undefined;
|
||||||
|
if (cid) {
|
||||||
|
setSelectedRowKeys?.([cid]);
|
||||||
|
try {
|
||||||
|
const raw = await queryById({ id: cid });
|
||||||
|
const row = (raw as any)?.id != null ? raw : (raw as any)?.result;
|
||||||
|
if (row) {
|
||||||
|
selectedRow.value = row;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// 忽略
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reload();
|
||||||
|
});
|
||||||
|
|
||||||
|
async function handleOk() {
|
||||||
|
const keys = (getSelectRowKeys?.() || []) as string[];
|
||||||
|
let row = selectedRow.value || ((getSelectRows?.() || []) as Recordable[])[0];
|
||||||
|
if (!row && keys.length) {
|
||||||
|
try {
|
||||||
|
const raw = await queryById({ id: keys[0] });
|
||||||
|
row = (raw as any)?.id != null ? raw : (raw as any)?.result;
|
||||||
|
} catch {
|
||||||
|
// 忽略
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!row?.id) {
|
||||||
|
emit('select', { sparePartsCategoryId: '', sparePartsCategoryName: '' });
|
||||||
|
closeModal();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
emit('select', {
|
||||||
|
sparePartsCategoryId: row.id,
|
||||||
|
sparePartsCategoryName: row.categoryName || '',
|
||||||
|
});
|
||||||
|
closeModal();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user