|
|
|
@ -33,6 +33,8 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.Objects; |
|
|
|
import java.util.regex.Matcher; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
|
|
|
|
@Service("partSpareService") |
|
|
|
@ -127,6 +129,39 @@ public class PartSpareServiceImpl extends ServiceImpl<PartSpareMapper, PartSpare |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getMaxPartNo(PartSpareEntity partSpare) { |
|
|
|
// 获得 site 和 bu |
|
|
|
if (partSpare.getBu() == null || partSpare.getBu().split("_").length < 2) { |
|
|
|
throw new RuntimeException("工厂和部门有误!"); |
|
|
|
} |
|
|
|
String site = partSpare.getBu().split("_")[0]; |
|
|
|
String buNo = partSpare.getBu().split("_")[1]; |
|
|
|
// 查询当前BU下所有编码,取“字母前缀+数字后缀”中数字最大的一条,前缀与补零位数保持不变后+1 |
|
|
|
List<String> codes = partSpareMapper.listPartNoByBu(site, buNo); |
|
|
|
Pattern pattern = Pattern.compile("^(\\D*?)(\\d+)$"); |
|
|
|
String prefix = "R"; |
|
|
|
int digits = 4; |
|
|
|
long maxNum = -1L; |
|
|
|
for (String code : codes) { |
|
|
|
if (code == null) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
Matcher matcher = pattern.matcher(code.trim()); |
|
|
|
if (!matcher.matches()) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
long num = Long.parseLong(matcher.group(2)); |
|
|
|
if (num > maxNum) { |
|
|
|
maxNum = num; |
|
|
|
prefix = matcher.group(1); |
|
|
|
digits = matcher.group(2).length(); |
|
|
|
} |
|
|
|
} |
|
|
|
long next = (maxNum < 0) ? 1L : maxNum + 1; |
|
|
|
return prefix + String.format("%0" + digits + "d", next); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void deletePartSpare(PartSpareEntity partSpare) { |
|
|
|
// 校验备品备件是否在被使用 |
|
|
|
|