From eccad5a129106377a275be4f7cdc58e99e9b95d4 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期二, 21 七月 2026 13:45:14 +0800
Subject: [PATCH] feat(mes): 实现库存移库功能

---
 yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/brand/MdmBrandServiceImpl.java |  124 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 124 insertions(+), 0 deletions(-)

diff --git a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/brand/MdmBrandServiceImpl.java b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/brand/MdmBrandServiceImpl.java
new file mode 100644
index 0000000..a53e69c
--- /dev/null
+++ b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/brand/MdmBrandServiceImpl.java
@@ -0,0 +1,124 @@
+package cn.iocoder.yudao.module.mdm.service.brand;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ObjUtil;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.module.mdm.controller.admin.brand.vo.MdmBrandPageReqVO;
+import cn.iocoder.yudao.module.mdm.controller.admin.brand.vo.MdmBrandSaveReqVO;
+import cn.iocoder.yudao.module.mdm.dal.dataobject.brand.MdmBrandDO;
+import cn.iocoder.yudao.module.mdm.dal.mysql.brand.MdmBrandMapper;
+import cn.iocoder.yudao.module.mdm.dal.mysql.item.MdmItemMapper;
+import jakarta.annotation.Resource;
+import org.springframework.stereotype.Service;
+import org.springframework.validation.annotation.Validated;
+
+import java.util.*;
+
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.iocoder.yudao.module.mdm.enums.ErrorCodeConstants.*;
+
+/**
+ * MDM 鍝佺墝 Service 瀹炵幇绫�
+ *
+ * @author 鑺嬮亾婧愮爜
+ */
+@Service
+@Validated
+public class MdmBrandServiceImpl implements MdmBrandService {
+
+    @Resource
+    private MdmBrandMapper brandMapper;
+
+    @Resource
+    private MdmItemMapper itemMapper;
+
+    @Override
+    public Long createBrand(MdmBrandSaveReqVO createReqVO) {
+        // 鏍¢獙鏁版嵁
+        validateBrandSaveData(createReqVO);
+
+        // 鎻掑叆
+        MdmBrandDO brand = BeanUtils.toBean(createReqVO, MdmBrandDO.class);
+        brandMapper.insert(brand);
+        return brand.getId();
+    }
+
+    @Override
+    public void updateBrand(MdmBrandSaveReqVO updateReqVO) {
+        // 鏍¢獙瀛樺湪
+        validateBrandExists(updateReqVO.getId());
+        // 鏍¢獙鏁版嵁
+        validateBrandSaveData(updateReqVO);
+
+        // 鏇存柊
+        MdmBrandDO updateObj = BeanUtils.toBean(updateReqVO, MdmBrandDO.class);
+        brandMapper.updateById(updateObj);
+    }
+
+    @Override
+    public void updateBrandStatus(Long id, Integer status) {
+        // 鏍¢獙瀛樺湪
+        validateBrandExists(id);
+        // 鏇存柊鐘舵��
+        brandMapper.updateById(new MdmBrandDO().setId(id).setStatus(status));
+    }
+
+    @Override
+    public void deleteBrand(Long id) {
+        // 鏍¢獙瀛樺湪
+        validateBrandExists(id);
+        // 鏍¢獙鏄惁琚墿鏂欎娇鐢紙鐩存帴浣跨敤 Mapper 閬垮厤寰幆渚濊禆锛�
+        if (itemMapper.selectCountByBrandId(id) > 0) {
+            throw exception(MDM_BRAND_EXISTS_ITEM);
+        }
+        // 鍒犻櫎
+        brandMapper.deleteById(id);
+    }
+
+    @Override
+    public MdmBrandDO validateBrandExists(Long id) {
+        MdmBrandDO brand = brandMapper.selectById(id);
+        if (brand == null) {
+            throw exception(MDM_BRAND_NOT_EXISTS);
+        }
+        return brand;
+    }
+
+    private void validateBrandSaveData(MdmBrandSaveReqVO reqVO) {
+        // 鏍¢獙缂栫爜鍞竴
+        MdmBrandDO brand = brandMapper.selectByCode(reqVO.getCode());
+        if (brand != null && ObjUtil.notEqual(brand.getId(), reqVO.getId())) {
+            throw exception(MDM_BRAND_CODE_DUPLICATE);
+        }
+        // 鏍¢獙鍚嶇О鍞竴
+        MdmBrandDO sameName = brandMapper.selectByName(reqVO.getName());
+        if (sameName != null && ObjUtil.notEqual(sameName.getId(), reqVO.getId())) {
+            throw exception(MDM_BRAND_NAME_DUPLICATE);
+        }
+    }
+
+    @Override
+    public MdmBrandDO getBrand(Long id) {
+        return brandMapper.selectById(id);
+    }
+
+    @Override
+    public PageResult<MdmBrandDO> getBrandPage(MdmBrandPageReqVO pageReqVO) {
+        return brandMapper.selectPage(pageReqVO);
+    }
+
+    @Override
+    public List<MdmBrandDO> getBrandList(Collection<Long> ids) {
+        if (CollUtil.isEmpty(ids)) {
+            return Collections.emptyList();
+        }
+        return brandMapper.selectBatchIds(ids);
+    }
+
+    @Override
+    public MdmBrandDO getBrandByCode(String code) {
+        return brandMapper.selectByCode(code);
+    }
+
+}

--
Gitblit v1.9.3