|
|
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
import org.springblade.core.mp.base.BaseEntity; |
|
|
|
|
@ -35,6 +36,7 @@ import java.util.stream.Collectors; |
|
|
|
|
* |
|
|
|
|
* @author BladeX |
|
|
|
|
*/ |
|
|
|
|
@Slf4j |
|
|
|
|
@RequiredArgsConstructor |
|
|
|
|
@Service |
|
|
|
|
public class MoldDemandServiceImpl extends BaseServiceImpl<MoldDemandMapper, MoldDemand> implements IMoldDemandService { |
|
|
|
|
@ -165,4 +167,46 @@ public class MoldDemandServiceImpl extends BaseServiceImpl<MoldDemandMapper, Mol |
|
|
|
|
// 5. 批量更新
|
|
|
|
|
return this.updateBatchById(moldDemandList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean saveMoldDemand(String toolCode) { |
|
|
|
|
// 1. 参数校验
|
|
|
|
|
if (toolCode == null || toolCode.trim().isEmpty()) { |
|
|
|
|
throw new IllegalArgumentException("模具编码不能为空"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 2. 检查是否已存在未完成的模具需求(避免重复创建)
|
|
|
|
|
List<MoldDemand> moldDemandList = baseMapper.selectByToolCodee(toolCode); |
|
|
|
|
if (!CollectionUtils.isEmpty(moldDemandList)) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 3. 生成需求单号(建议增加异常处理)
|
|
|
|
|
String code; |
|
|
|
|
try { |
|
|
|
|
code = orderService.generateMdCode(); |
|
|
|
|
if (code == null || code.isEmpty()) { |
|
|
|
|
throw new RuntimeException("生成模具需求单号失败"); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("生成模具需求单号异常, toolCode: {}", toolCode, e); |
|
|
|
|
throw new RuntimeException("生成模具需求单号失败", e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 4. 构建并保存实体
|
|
|
|
|
MoldDemand moldDemand = new MoldDemand(); |
|
|
|
|
moldDemand.setToolCode(toolCode); |
|
|
|
|
moldDemand.setMdCode(code); |
|
|
|
|
moldDemand.setMafStatus(MoldDemandEnum.MAF_STATUS_CREATE.getCode()); |
|
|
|
|
moldDemand.setMafType(MoldDemandEnum.MAF_TYPE_STORE.getCode()); |
|
|
|
|
|
|
|
|
|
boolean saveResult = this.save(moldDemand); |
|
|
|
|
if (!saveResult) { |
|
|
|
|
log.error("保存模具需求失败, toolCode: {}, mdCode: {}", toolCode, code); |
|
|
|
|
throw new RuntimeException("保存模具需求失败"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
log.info("模具需求创建成功, toolCode: {}, mdCode: {}", toolCode, code); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|