修复酸轧实绩提交问题,规程重新完成逻辑

This commit is contained in:
2026-05-21 13:41:21 +08:00
parent 2c9cc6241f
commit eb5601ade3
6 changed files with 677 additions and 557 deletions

View File

@@ -61,7 +61,13 @@ public class DrMillProcessRecipeController extends BaseController {
@GetMapping("/version/list/{recipeId}")
public R<List<DrMillProcessRecipeVersion>> versionList(@PathVariable Long recipeId) {
return R.ok(versionService.listByRecipeId(recipeId));
List<DrMillProcessRecipeVersion> list = versionService.listByRecipeId(recipeId);
// 同步版本到主库 wms_process_spec_version幂等
DrMillProcessRecipe recipe = recipeService.selectDetailById(recipeId);
if (recipe != null) {
syncService.syncVersionsToSpec(recipe.getRecipeNo(), list);
}
return R.ok(list);
}
@GetMapping("/version/{versionId}")
@@ -71,7 +77,14 @@ public class DrMillProcessRecipeController extends BaseController {
@PostMapping("/version")
public R<Long> addVersion(@RequestBody DrMillProcessRecipeVersion version) {
return R.ok(versionService.save(version));
Long newId = versionService.save(version);
// 新增后重新同步该方案的所有版本
List<DrMillProcessRecipeVersion> all = versionService.listByRecipeId(version.getRecipeId());
DrMillProcessRecipe recipe = recipeService.selectDetailById(version.getRecipeId());
if (recipe != null) {
syncService.syncVersionsToSpec(recipe.getRecipeNo(), all);
}
return R.ok(newId);
}
@PutMapping("/version")
@@ -83,6 +96,15 @@ public class DrMillProcessRecipeController extends BaseController {
@PutMapping("/version/activate/{versionId}")
public R<Void> activate(@PathVariable Long versionId) {
versionService.activate(versionId);
// 激活后重新同步 isActive 状态到主库
DrMillProcessRecipeVersion ver = versionService.getDetailById(versionId);
if (ver != null) {
List<DrMillProcessRecipeVersion> all = versionService.listByRecipeId(ver.getRecipeId());
DrMillProcessRecipe recipe = recipeService.selectDetailById(ver.getRecipeId());
if (recipe != null) {
syncService.syncVersionsToSpec(recipe.getRecipeNo(), all);
}
}
return R.ok();
}

View File

@@ -3,9 +3,12 @@ package com.klp.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.klp.domain.DrMillProcessRecipe;
import com.klp.domain.DrMillProcessRecipeVersion;
import com.klp.domain.WmsProcessSpec;
import com.klp.domain.WmsProcessSpecVersion;
import com.klp.domain.WmsProductionLine;
import com.klp.mapper.WmsProcessSpecMapper;
import com.klp.mapper.WmsProcessSpecVersionMapper;
import com.klp.mapper.WmsProductionLineMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -35,8 +38,9 @@ public class DrRecipeSyncService {
/** spec_code 前缀,区分同名方案号属于哪条产线 */
private static final String SPEC_CODE_PREFIX = "DR-";
private final WmsProcessSpecMapper specMapper;
private final WmsProductionLineMapper lineMapper;
private final WmsProcessSpecMapper specMapper;
private final WmsProcessSpecVersionMapper specVersionMapper;
private final WmsProductionLineMapper lineMapper;
/**
* 检查并补充 wms_process_spec
@@ -72,6 +76,52 @@ public class DrRecipeSyncService {
}
}
/**
* 将双机架工艺版本mill_process_recipe_version同步到主库规程版本wms_process_spec_version
* <p>已存在的版本更新 isActive / status不存在则新增。</p>
*
* @param recipeNo 对应方案号(用于定位 wms_process_spec
* @param drVersions 已从 double-rack 库查出的版本列表
*/
@Transactional(rollbackFor = Exception.class)
public void syncVersionsToSpec(String recipeNo, List<DrMillProcessRecipeVersion> drVersions) {
if (recipeNo == null || drVersions == null || drVersions.isEmpty()) return;
String specCode = SPEC_CODE_PREFIX + recipeNo;
LambdaQueryWrapper<WmsProcessSpec> sqw = Wrappers.lambdaQuery();
sqw.eq(WmsProcessSpec::getSpecCode, specCode);
WmsProcessSpec spec = specMapper.selectOne(sqw);
if (spec == null) return; // spec 尚未同步,跳过
Long specId = spec.getSpecId();
for (DrMillProcessRecipeVersion drVer : drVersions) {
LambdaQueryWrapper<WmsProcessSpecVersion> vqw = Wrappers.lambdaQuery();
vqw.eq(WmsProcessSpecVersion::getSpecId, specId)
.eq(WmsProcessSpecVersion::getVersionCode, drVer.getVersionCode());
WmsProcessSpecVersion existing = specVersionMapper.selectOne(vqw);
int isActive = drVer.getIsActive() != null ? drVer.getIsActive() : 0;
String status = "1".equals(drVer.getStatus()) ? "PUBLISHED" : "DRAFT";
if (existing == null) {
WmsProcessSpecVersion ver = new WmsProcessSpecVersion();
ver.setSpecId(specId);
ver.setVersionCode(drVer.getVersionCode());
ver.setIsActive(isActive);
ver.setStatus(status);
ver.setRemark(drVer.getRemark() != null ? drVer.getRemark() : "由双机架工艺版本自动同步");
specVersionMapper.insert(ver);
log.info("[DR同步] 新增 wms_process_spec_version: specCode={}, versionCode={}",
specCode, drVer.getVersionCode());
} else {
existing.setIsActive(isActive);
existing.setStatus(status);
specVersionMapper.updateById(existing);
}
}
}
/**
* 查找或创建双机架产线记录,返回 line_id。
*/