Commit 22150eb1 by lijingjing

原铝散样,编号处理;

parent 27ab43bc
...@@ -28,5 +28,7 @@ public interface ICodeRuleService extends IBaseService<CodeRule> { ...@@ -28,5 +28,7 @@ public interface ICodeRuleService extends IBaseService<CodeRule> {
String getKey(String prefix, String rule, BaseEntity entity); String getKey(String prefix, String rule, BaseEntity entity);
void recycleCode(CodeTypeEnum codeTypeEnum, List<String> codeList, Account account); void recycleCode(CodeTypeEnum codeTypeEnum, List<String> codeList, String curVary, Account account);
boolean updateSn(CodeTypeEnum codeTypeEnum, String vary, Integer sn, Account account);
} }
...@@ -32,6 +32,8 @@ public interface IEntrustSampleService extends IBaseService<EntrustSample> { ...@@ -32,6 +32,8 @@ public interface IEntrustSampleService extends IBaseService<EntrustSample> {
boolean removeByIds(List<Long> ids); boolean removeByIds(List<Long> ids);
void recyleCodes(List<EntrustSample> samples);
List<EntrustSampleVO> obtainMakeInfo(Long[] ids, Account account); List<EntrustSampleVO> obtainMakeInfo(Long[] ids, Account account);
Page<EntrustSampleVO> pageSampleReceive(Page<EntrustSampleVO> page, EntrustSampleVO entrustSample); Page<EntrustSampleVO> pageSampleReceive(Page<EntrustSampleVO> page, EntrustSampleVO entrustSample);
...@@ -141,4 +143,6 @@ public interface IEntrustSampleService extends IBaseService<EntrustSample> { ...@@ -141,4 +143,6 @@ public interface IEntrustSampleService extends IBaseService<EntrustSample> {
boolean deletePhysicalByEntrustIds(List<Long> ids); boolean deletePhysicalByEntrustIds(List<Long> ids);
boolean updateStatus(EntrustSampleStatusEnum sampleStatus, List<Long> sampleIds); boolean updateStatus(EntrustSampleStatusEnum sampleStatus, List<Long> sampleIds);
String getCompatibleCode(EntrustSample sample);
} }
...@@ -51,6 +51,8 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul ...@@ -51,6 +51,8 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul
@Autowired @Autowired
private ICodeRuleRecordService codeRuleRecordService; private ICodeRuleRecordService codeRuleRecordService;
private static final String SN = "#SN#";
@Override @Override
public Page<CodeRule> page(Page<CodeRule> page, CodeRule codeRule) { public Page<CodeRule> page(Page<CodeRule> page, CodeRule codeRule) {
Wrapper wrapper = new EntityWrapper<>(codeRule); Wrapper wrapper = new EntityWrapper<>(codeRule);
...@@ -159,8 +161,6 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul ...@@ -159,8 +161,6 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul
} else { } else {
sn = CodeKeyUtils.getSn(codeRule.getSn() + 1, codeRule.getLength()); sn = CodeKeyUtils.getSn(codeRule.getSn() + 1, codeRule.getLength());
} }
// 更新规则序列号 // 更新规则序列号
nextSn(codeRule.getId(), codeRule.getSn()); nextSn(codeRule.getId(), codeRule.getSn());
return key.toString().replaceAll(CommonConstants.SN, sn); return key.toString().replaceAll(CommonConstants.SN, sn);
...@@ -222,7 +222,7 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul ...@@ -222,7 +222,7 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul
} }
@Override @Override
public void recycleCode(CodeTypeEnum codeTypeEnum, List<String> codeList, Account account) { public void recycleCode(CodeTypeEnum codeTypeEnum, List<String> codeList, String curVary, Account account) {
codeList.removeIf(StringUtils::isBlank); codeList.removeIf(StringUtils::isBlank);
if (CollectionUtils.isEmpty(codeList)) { if (CollectionUtils.isEmpty(codeList)) {
return; return;
...@@ -241,9 +241,14 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul ...@@ -241,9 +241,14 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul
List<Long> codeIdList = new ArrayList<>(); List<Long> codeIdList = new ArrayList<>();
codeRuleList.forEach((lmsCode -> codeIdList.add(lmsCode.getId()))); codeRuleList.forEach((lmsCode -> codeIdList.add(lmsCode.getId())));
// 查询编号记录表 // 查询编号记录表
List<Map<String, Object>> recordList = SqlRunner.db(). String sql = "select * from code_rule_record where company_id = {0} and code_rule_id in {1} and vary ";
selectList("select * from code_rule_record where company_id = {0} and code_rule_id in {1} and vary like '%#SN#'", if (codeTypeEnum == CodeTypeEnum.AL_BULK_SAMPLE_CODE) {
account.getCompanyId(), codeIdList); sql += " = '" + curVary + "'";
} else {
sql += "like '%" + SN + "%'";
}
List<Map<String, Object>> recordList = SqlRunner.db().selectList(sql, account.getCompanyId(), codeIdList);
if (CollectionUtils.isEmpty(recordList)) { if (CollectionUtils.isEmpty(recordList)) {
// 如果没有配置顺序号,不予处理 // 如果没有配置顺序号,不予处理
return; return;
...@@ -260,8 +265,14 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul ...@@ -260,8 +265,14 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul
while (iterator.hasNext()) { while (iterator.hasNext()) {
// 数据库中的编号记录 // 数据库中的编号记录
CodeRuleRecord codeRuleRecord = iterator.next(); CodeRuleRecord codeRuleRecord = iterator.next();
// 这是数据库中存储的编号前缀 String varyContent = codeRuleRecord.getVary();
String codeRulePrefix = codeRuleRecord.getVary().replace("#SN#", ""); // 获取序号前半段
String frontVary = varyContent.substring(0, varyContent.indexOf(SN));
// 如果有后半段的话,需要处理后半段
String hindVary = varyContent.replace(frontVary, "").replace(SN, "");
// 这是数据库中存储的编号前缀+后缀
String codeRulePrefix = frontVary + hindVary;
// 先将实际编号后面的 sn 的长度删除, 删除之后就是实际编号的前缀了 // 先将实际编号后面的 sn 的长度删除, 删除之后就是实际编号的前缀了
CodeRule lmsCodeRule = ruleMap.get(codeRuleRecord.getCodeRuleId()); CodeRule lmsCodeRule = ruleMap.get(codeRuleRecord.getCodeRuleId());
// tmpCode 就是实际的编号 // tmpCode 就是实际的编号
...@@ -274,25 +285,28 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul ...@@ -274,25 +285,28 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul
// 如果实际编号长度减去配置的编号长度 <= 0, 说明编号的前缀极有可能不存在, 所以没有回收依据, 不予回收 // 如果实际编号长度减去配置的编号长度 <= 0, 说明编号的前缀极有可能不存在, 所以没有回收依据, 不予回收
continue; continue;
} }
tmpCode = tmpCode.substring(0, tmpCode.length() - length); // 假如说:样品编号是:220704A11121,其中A后面的1才是流水号,那么处理时需要注意截取内容
// 此处不改变运行逻辑,剔除后半段内容,再去做减法,然后再加上后半段比较
tmpCode = tmpCode.replace(hindVary, "");
tmpCode = tmpCode.substring(0, tmpCode.length() - length) + hindVary;
} }
} }
// 这里的 tmpCode 就是实际编号的前缀了 // 这里的 tmpCode 就是实际编号的前缀了
// 判断删除顺序号后的编号和编号前缀是否相同 // 判断删除顺序号后的编号和编号前缀是否相同
if (Objects.equals(tmpCode, codeRulePrefix) if (Objects.equals(tmpCode, codeRulePrefix) || (!"".equals(codeRulePrefix) && tmpCode.startsWith(codeRulePrefix))) {
|| (!"".equals(codeRulePrefix) && tmpCode.startsWith(codeRulePrefix))) {
// 相同 // 相同
String sn = code.replace(codeRulePrefix, ""); // 更改:剔除前缀和后缀,这样做才是真正获取的流水号
String sn = code.replace(frontVary, "").replace(hindVary, "");
if (NumberUtils.isDigits(sn)) { if (NumberUtils.isDigits(sn)) {
if (codeMap.containsKey(codeRulePrefix)) { if (codeMap.containsKey(varyContent)) {
codeMap.get(codeRulePrefix).add(Integer.valueOf(sn)); codeMap.get(varyContent).add(Integer.valueOf(sn));
} else { } else {
List<Integer> list = new ArrayList<>(); List<Integer> list = new ArrayList<>();
list.add(Integer.valueOf(sn)); list.add(Integer.valueOf(sn));
codeMap.put(codeRulePrefix, list); codeMap.put(varyContent, list);
} }
// 放入 map // 放入 map
varyIdMap.put(codeRulePrefix, codeRuleRecord.getCodeRuleId()); varyIdMap.put(varyContent, codeRuleRecord.getCodeRuleId());
} }
// 下一层外循环 // 下一层外循环
break; break;
...@@ -303,10 +317,21 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul ...@@ -303,10 +317,21 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul
Collections.sort(snList); Collections.sort(snList);
LmsCodeRuleRecord record = new LmsCodeRuleRecord(); LmsCodeRuleRecord record = new LmsCodeRuleRecord();
record.setCodeRuleId(varyIdMap.get(vary)); record.setCodeRuleId(varyIdMap.get(vary));
record.setVary(vary + "#SN#"); record.setVary(vary);
record.setSn(snList.get(0) - 1); record.setSn(snList.get(0) - 1);
SqlRunner.db().update("update code_rule_record set sn = {0} where code_rule_id = {1} and vary = {2}", SqlRunner.db().update("update code_rule_record set sn = {0} where code_rule_id = {1} and vary = {2}",
snList.get(0) - 1, varyIdMap.get(vary), vary + "#SN#"); snList.get(0) - 1, varyIdMap.get(vary), vary);
}); });
} }
@Override
public boolean updateSn(CodeTypeEnum codeTypeEnum, String vary, Integer sn, Account account) {
RestAssert.fail(null == codeTypeEnum, "编号类型为空");
RestAssert.fail(StringUtils.isBlank(vary), "编号规则为空");
RestAssert.fail(null == sn, "编号流水号为空");
CodeRule codeRule = super.getOne(Condition.create().eq("type", codeTypeEnum.getValue()).last("LIMIT 1"));
RestAssert.fail(null == codeRule, "编号规则不存在");
return SqlRunner.db().update("update code_rule_record set sn = {0} where code_rule_id = {1} and vary = {2}",
sn, codeRule.getId(), vary);
}
} }
...@@ -676,13 +676,34 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe ...@@ -676,13 +676,34 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
entrustSampleItemService.remove(Condition.create().in("entrust_sample_id", ids)); entrustSampleItemService.remove(Condition.create().in("entrust_sample_id", ids));
// 查询要删除的样品编号 // 查询要删除的样品编号
List<EntrustSample> samples = super.getBatchIds(ids); List<EntrustSample> samples = super.getBatchIds(ids);
List<String> sampleCodes = samples.stream().map(EntrustSample::getCode).collect(Collectors.toList()); recyleCodes(samples);
return baseMapper.deleteBatchIds(ids) > 0;
}
@Override
public void recyleCodes(List<EntrustSample> samples) {
if (CollectionUtils.isEmpty(samples)) {
return;
}
List<String> sampleCodes = new ArrayList<>();
// 需要对编号额外处理
String vary = null;
for (EntrustSample s : samples) {
if (s.getCodeRuleType() == CodeTypeEnum.AL_BULK_SAMPLE_CODE.getIntValue()) {
String str = s.getCode().replaceAll("(A|B|C)", "BC");
s.setCode(str);
if (null == vary) {
vary = str.substring(0, 8) + "#SN#" + str.substring(9);
}
}
sampleCodes.add(s.getCode());
}
Integer codeRuleType = samples.get(0).getCodeRuleType(); Integer codeRuleType = samples.get(0).getCodeRuleType();
// 不为空的情下触发编号回收机制 // 不为空的情下触发编号回收机制
if (CollectionUtils.isNotEmpty(sampleCodes) && null != codeRuleType) { if (CollectionUtils.isNotEmpty(sampleCodes) && null != codeRuleType) {
codeRuleService.recycleCode(CodeTypeEnum.get(codeRuleType), sampleCodes, LoginHelper.getAccount()); codeRuleService.recycleCode(CodeTypeEnum.get(codeRuleType), sampleCodes, vary, LoginHelper.getAccount());
} }
return baseMapper.deleteBatchIds(ids) > 0;
} }
@Override @Override
...@@ -2279,13 +2300,7 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe ...@@ -2279,13 +2300,7 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
ids.forEach(id -> { ids.forEach(id -> {
// 只查询当前委托下的样品 // 只查询当前委托下的样品
List<EntrustSample> samples = sampleList.stream().filter(t -> Objects.equals(t.getEntrustId(), id)).collect(Collectors.toList()); List<EntrustSample> samples = sampleList.stream().filter(t -> Objects.equals(t.getEntrustId(), id)).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(samples)) { recyleCodes(samples);
List<String> sampleCodes = samples.stream().map(EntrustSample::getCode).collect(Collectors.toList());
Integer codeRuleType = samples.get(0).getCodeRuleType();
if (null != codeRuleType && org.apache.commons.collections.CollectionUtils.isNotEmpty(sampleCodes)) {
codeRuleService.recycleCode(CodeTypeEnum.get(codeRuleType), sampleCodes, LoginHelper.getAccount());
}
}
}); });
// 删除备样 // 删除备样
...@@ -2327,6 +2342,42 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe ...@@ -2327,6 +2342,42 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
return update(entrustSample, Condition.create().in("id", sampleIds)); return update(entrustSample, Condition.create().in("id", sampleIds));
} }
@Override
@Transactional(rollbackFor = Exception.class)
public String getCompatibleCode(EntrustSample sample) {
RestAssert.fail(StringUtils.isBlank(sample.getCode()), "匹配的样品编号为空!");
RestAssert.fail(Objects.isNull(sample.getCodeRuleType()), "匹配的样品编号类型为空!");
boolean updateRule = false;
String sampleCode = sample.getCode(), front = sampleCode.substring(0, 7),
backend = sampleCode.substring(8), vary = front.substring(0, 6) + "BC" + CommonConstants.SN + backend;
// 流水默认设置1
int sn = 1;
while (isRepeatSampleCode(sample)) {
updateRule = true;
// 原铝散样处理方式
if (sample.getCodeRuleType() == CodeTypeEnum.AL_BULK_SAMPLE_CODE.getIntValue()) {
sn = Integer.parseInt(sampleCode.substring(7, 8)) + 1;
sampleCode = front + sn + backend;
sample.setCode(sampleCode);
}
}
// 若生成的编号在数据库中查询不重复(例如:220704B63333),那么继续模糊匹配是否存在此时间段的初始编号,不存在,重置编号
if (!updateRule) {
// 使用初始编号查询,若查询不出,重置流水
sample.setCode(sampleCode.substring(0, 7) + sn + sampleCode.substring(8));
if (!isRepeatSampleCode(sample)) {
sampleCode = sample.getCode();
updateRule = true;
}
}
if (updateRule) {
codeRuleService.updateSn(CodeTypeEnum.get(sample.getCodeRuleType()), vary, sn, LoginHelper.getAccount());
}
return sampleCode;
}
private List<EntrustSampleItemIndex> getIndexList(Long sampleId) { private List<EntrustSampleItemIndex> getIndexList(Long sampleId) {
if (null == sampleId) { if (null == sampleId) {
......
...@@ -146,15 +146,11 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -146,15 +146,11 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
ids.forEach(id -> { ids.forEach(id -> {
List<EntrustSample> samples = entrustSampleService.list(Condition.create().eq("entrust_id", id)); List<EntrustSample> samples = entrustSampleService.list(Condition.create().eq("entrust_id", id));
if (CollectionUtils.isNotEmpty(samples)) { entrustSampleService.recyleCodes(samples);
List<String> sampleCodes = samples.stream().map(EntrustSample::getCode).collect(Collectors.toList());
Integer codeRuleType = samples.get(0).getCodeRuleType();
if (null != codeRuleType && CollectionUtils.isNotEmpty(sampleCodes)) {
codeRuleService.recycleCode(CodeTypeEnum.get(codeRuleType), sampleCodes, LoginHelper.getAccount());
}
}
}); });
// entrustSampleService.recyleCodes();
entrustSampleService.remove(Condition.create().in("entrust_id", ids)); entrustSampleService.remove(Condition.create().in("entrust_id", ids));
entrustSampleItemService.remove(Condition.create().in("entrust_id", ids)); entrustSampleItemService.remove(Condition.create().in("entrust_id", ids));
// 是否根据条件回收委托编号 // 是否根据条件回收委托编号
...@@ -204,6 +200,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -204,6 +200,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
/** /**
* 转换自动大写编号 * 转换自动大写编号
*
* @param sample * @param sample
*/ */
private void toSampleCodeUpperCase(EntrustSample sample) { private void toSampleCodeUpperCase(EntrustSample sample) {
...@@ -321,8 +318,17 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -321,8 +318,17 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
// 替换班次BC // 替换班次BC
sampleCode = sampleCode.replace("BC", DateKit.getShiftByNow()); sampleCode = sampleCode.replace("BC", DateKit.getShiftByNow());
// YYMMDD+(A/C/E)+SN(1)+ 槽号(4) // YYMMDD+(A/C/E)+SN(1)+ 槽号(4)
String queryKey = sampleCode.substring(0, 7) + "_" + sampleCode.substring(8); // String queryKey = sampleCode.substring(0, 7) + "_" + sampleCode.substring(8);
sampleCode = entrustSampleService.getNewCode(queryKey, 7, 1); // sampleCode = entrustSampleService.getNewCode(queryKey, 7, 1);
// 初始时,处理可能因a,b,c时间段重复编号
EntrustSample example = new EntrustSample();
example.setId(sample.getId());
example.setCode(sampleCode).setCodeRuleType(codeType.getIntValue());
// example.setFirstCode(sampleCode.replaceAll("(A|B|C)", "_"));
String newSampleCode = entrustSampleService.getCompatibleCode(example);
if (!sampleCode.equals(newSampleCode)) {
sampleCode = newSampleCode;
}
} }
// 电解质散样样品编号处理 // 电解质散样样品编号处理
// else if (CodeTypeEnum.ELECT_BULK_SAMPLE_CODE == codeType) { // else if (CodeTypeEnum.ELECT_BULK_SAMPLE_CODE == codeType) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment