From a8a78a1b733914ea97393ccc5a81bf7ea76ed5aa Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期四, 12 三月 2026 17:58:38 +0800
Subject: [PATCH] Merge branch 'dev_宁夏_中盛建材' of http://114.132.189.42:9002/r/product-inventory-management-after into dev_宁夏_中盛建材
---
src/main/java/com/ruoyi/production/service/impl/ProductMaterialConfigServiceImpl.java | 96 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 96 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductMaterialConfigServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductMaterialConfigServiceImpl.java
index 7136f8a..f61f0dc 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductMaterialConfigServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductMaterialConfigServiceImpl.java
@@ -1,11 +1,19 @@
package com.ruoyi.production.service.impl;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.production.dto.ProductMaterialConfigDto;
+import com.ruoyi.production.enums.MaterialConfigTypeEnum;
import com.ruoyi.production.mapper.ProductMaterialConfigMapper;
import com.ruoyi.production.pojo.ProductMaterialConfig;
import com.ruoyi.production.service.ProductMaterialConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
/**
* <br>
@@ -20,5 +28,93 @@
@Service
public class ProductMaterialConfigServiceImpl extends ServiceImpl<ProductMaterialConfigMapper, ProductMaterialConfig> implements ProductMaterialConfigService {
+ @Override
+ public List<ProductMaterialConfig> materialTypeList() {
+ return getByType(MaterialConfigTypeEnum.MATERIAL_TYPE);
+ }
+ @Override
+ public List<ProductMaterialConfig> inventoryCategoryList() {
+ return getByType(MaterialConfigTypeEnum.INVENTORY_CAT);
+ }
+
+ private List<ProductMaterialConfig> getByType(MaterialConfigTypeEnum type) {
+ return list(new LambdaQueryWrapper<ProductMaterialConfig>().eq(ProductMaterialConfig::getConfigType, type.name()));
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void addProductMaterialConfig(ProductMaterialConfigDto config) {
+ config.setConfigType(MaterialConfigTypeEnum.getConfigType(config.getType()));
+ validateConfig(config, false);
+ if (existsConfig(config.getConfigType(), config.getConfigName(), null)) {
+ throw new ServiceException("閰嶇疆鍚嶇О宸插瓨鍦�");
+ }
+ if (!this.save(config)) {
+ throw new ServiceException("鏂板閰嶇疆澶辫触");
+ }
+ log.info("鏂板鐗╂枡閰嶇疆鎴愬姛 type={}, name={}", config.getConfigType(), config.getConfigName());
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void updateProductMaterialConfig(ProductMaterialConfigDto config) {
+ config.setConfigType(MaterialConfigTypeEnum.getConfigType(config.getType()));
+ validateConfig(config, true);
+ ProductMaterialConfig exist = this.getById(config.getId());
+ if (exist == null) {
+ throw new ServiceException("閰嶇疆涓嶅瓨鍦�");
+ }
+ if (existsConfig(config.getConfigType(), config.getConfigName(), config.getId())) {
+ throw new ServiceException("閰嶇疆鍚嶇О宸插瓨鍦�");
+ }
+ if (!this.updateById(config)) {
+ throw new ServiceException("淇敼閰嶇疆澶辫触");
+ }
+ log.info("淇敼鐗╂枡閰嶇疆鎴愬姛 id={}", config.getId());
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void deleteProductMaterialConfig(List<Integer> ids) {
+ if (ids == null || ids.isEmpty()) {
+ throw new ServiceException("璇烽�夋嫨鑷冲皯涓�鏉℃暟鎹�");
+ }
+ if (!this.removeByIds(ids)) {
+ throw new ServiceException("鍒犻櫎閰嶇疆澶辫触");
+ }
+ log.info("鍒犻櫎鐗╂枡閰嶇疆鎴愬姛 ids={}", ids);
+ }
+
+ private void validateConfig(ProductMaterialConfig config, boolean requireId) {
+ if (config == null) {
+ throw new ServiceException("鍙傛暟涓嶈兘涓虹┖");
+ }
+ if (requireId && config.getId() == null) {
+ throw new ServiceException("涓婚敭ID涓嶈兘涓虹┖");
+ }
+ if (StringUtils.isEmpty(config.getConfigType())) {
+ throw new ServiceException("閰嶇疆绫诲瀷涓嶈兘涓虹┖");
+ }
+ try {
+ MaterialConfigTypeEnum.valueOf(config.getConfigType());
+ } catch (IllegalArgumentException e) {
+ throw new ServiceException("閰嶇疆绫诲瀷涓嶅悎娉�");
+ }
+ if (StringUtils.isEmpty(config.getConfigName())) {
+ throw new ServiceException("閰嶇疆鍚嶇О涓嶈兘涓虹┖");
+ }
+ }
+
+ private boolean existsConfig(String configType, String configName, Integer excludeId) {
+ if (StringUtils.isEmpty(configName) || StringUtils.isEmpty(configType)) {
+ return false;
+ }
+ LambdaQueryWrapper<ProductMaterialConfig> wrapper = new LambdaQueryWrapper<>();
+ wrapper.eq(ProductMaterialConfig::getConfigType, configType).eq(ProductMaterialConfig::getConfigName, configName);
+ if (excludeId != null) {
+ wrapper.ne(ProductMaterialConfig::getId, excludeId);
+ }
+ return this.count(wrapper) > 0;
+ }
}
--
Gitblit v1.9.3