Commit 3391ac94 by lijingjing

原铝散样,接收退回时,清空原铝散样的编号,并重置流水;

parent 22150eb1
...@@ -30,5 +30,7 @@ public interface ICodeRuleService extends IBaseService<CodeRule> { ...@@ -30,5 +30,7 @@ public interface ICodeRuleService extends IBaseService<CodeRule> {
void recycleCode(CodeTypeEnum codeTypeEnum, List<String> codeList, String curVary, Account account); void recycleCode(CodeTypeEnum codeTypeEnum, List<String> codeList, String curVary, Account account);
void recycleAlBulkCode(List<String> codeList, Account account);
boolean updateSn(CodeTypeEnum codeTypeEnum, String vary, Integer sn, Account account); boolean updateSn(CodeTypeEnum codeTypeEnum, String vary, Integer sn, Account account);
} }
...@@ -325,6 +325,105 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul ...@@ -325,6 +325,105 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul
} }
@Override @Override
public void recycleAlBulkCode(List<String> codeList, Account account) {
codeList.removeIf(StringUtils::isBlank);
if (CollectionUtils.isEmpty(codeList)) {
return;
}
// 根据编号规则枚举查询已经存在的编号前缀
List<Map<String, Object>> lmsCodeList;
List<String> varyList = codeList.stream().map(c -> {
// 编号:220704A13333 ,替换后,220704BC#SN#3333
return c.substring(0,6) + "BC" + SN + c.substring(c.length() - 4);
}).collect(Collectors.toList());
lmsCodeList = SqlRunner.db().selectList("select * from code_rule where type = {0} and company_id = {1}", CodeTypeEnum.AL_BULK_SAMPLE_CODE.getValue(), account.getCompanyId());
RestAssert.fail(CollectionUtils.isEmpty(lmsCodeList), "未配置编号规则");
// 将 map 转换为编号规则对象
List<CodeRule> codeRuleList = lmsCodeList.stream().map(CodeRuleServiceImpl::getCodeRule).collect(Collectors.toList());
// 将编号规则的 id 和对象本身组成一个 map
Map<Long, CodeRule> ruleMap = codeRuleList.stream().collect(Collectors.toMap(CodeRule::getId, Function.identity()));
List<Long> codeIdList = new ArrayList<>();
codeRuleList.forEach((lmsCode -> codeIdList.add(lmsCode.getId())));
// 查询编号记录表
String sql = "select * from code_rule_record where company_id = {0} and code_rule_id in {1} and vary in {2}";
List<Map<String, Object>> recordList = SqlRunner.db().selectList(sql, account.getCompanyId(), codeIdList, varyList);
if (CollectionUtils.isEmpty(recordList)) {
// 如果没有配置顺序号,不予处理
return;
}
// 将map转换成编号记录的实体的list
List<CodeRuleRecord> ruleRecordList = recordList.stream().map(CodeRuleServiceImpl::getCodeRuleRecord)
.collect(Collectors.toList());
// 创建一个map,因为vary部分可能有多个
Map<String, List<Integer>> codeMap = new HashMap<>(16);
Map<String, Integer> codeSnMap = new HashMap<>(16);
Map<String, Long> varyIdMap = new HashMap<>(16);
for (String code : codeList) {
// 内层遍历编号记录
Iterator<CodeRuleRecord> iterator = ruleRecordList.iterator();
while (iterator.hasNext()) {
// 数据库中的编号记录
CodeRuleRecord codeRuleRecord = iterator.next();
String varyContent = codeRuleRecord.getVary();
codeSnMap.put(codeRuleRecord.getVary(), codeRuleRecord.getSn());
// 获取序号前半段
String frontVary = varyContent.substring(0, 6);
// 如果有后半段的话,需要处理后半段
String hindVary = varyContent.replace(frontVary, "").replace("BC", "").replace(SN, "");
// 这是数据库中存储的编号前缀+后缀
String codeRulePrefix = frontVary + hindVary;
// 先将实际编号后面的 sn 的长度删除, 删除之后就是实际编号的前缀了
CodeRule lmsCodeRule = ruleMap.get(codeRuleRecord.getCodeRuleId());
// tmpCode 就是实际的编号
String tmpCode = code;
if (lmsCodeRule != null) {
// length 是编号规则中配置的长度字段
Integer length = lmsCodeRule.getLength();
if (length != null) {
if (tmpCode.length() - length <= 0) {
// 如果实际编号长度减去配置的编号长度 <= 0, 说明编号的前缀极有可能不存在, 所以没有回收依据, 不予回收
continue;
}
// 假如说:样品编号是:220704A11121,其中A后面的1才是流水号,那么处理时需要注意截取内容
// 此处不改变运行逻辑,剔除后半段内容,再去做减法,然后再加上后半段比较
tmpCode = tmpCode.replace(hindVary, "").replaceAll("(A|B|C)", "");
tmpCode = tmpCode.substring(0, tmpCode.length() - length) + hindVary;
}
}
// 这里的 tmpCode 就是实际编号的前缀了
// 判断删除顺序号后的编号和编号前缀是否相同
if (Objects.equals(tmpCode, codeRulePrefix) || (!"".equals(codeRulePrefix) && tmpCode.startsWith(codeRulePrefix))) {
// 相同
// 更改:剔除前缀和后缀,这样做才是真正获取的流水号
String sn = code.substring(7, 8);
if (NumberUtils.isDigits(sn)) {
if (codeMap.containsKey(varyContent)) {
codeMap.get(varyContent).add(Integer.valueOf(sn));
} else {
List<Integer> list = new ArrayList<>();
list.add(Integer.valueOf(sn));
codeMap.put(varyContent, list);
}
// 放入 map
varyIdMap.put(varyContent, codeRuleRecord.getCodeRuleId());
}
// 下一层外循环
break;
}
}
}
codeMap.forEach((vary, snList) -> {
Collections.sort(snList);
int sn = codeSnMap.get(vary);
sn = snList.get(0) - 1 < sn ? snList.get(0) - 1 : sn;
SqlRunner.db().update("update code_rule_record set sn = {0} where code_rule_id = {1} and vary = {2}",
sn, varyIdMap.get(vary), vary);
});
}
@Override
public boolean updateSn(CodeTypeEnum codeTypeEnum, String vary, Integer sn, Account account) { public boolean updateSn(CodeTypeEnum codeTypeEnum, String vary, Integer sn, Account account) {
RestAssert.fail(null == codeTypeEnum, "编号类型为空"); RestAssert.fail(null == codeTypeEnum, "编号类型为空");
RestAssert.fail(StringUtils.isBlank(vary), "编号规则为空"); RestAssert.fail(StringUtils.isBlank(vary), "编号规则为空");
......
...@@ -685,24 +685,23 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe ...@@ -685,24 +685,23 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
if (CollectionUtils.isEmpty(samples)) { if (CollectionUtils.isEmpty(samples)) {
return; return;
} }
// == 是否原铝散样
boolean isAlBulkSample = Objects.equals(samples.get(0).getCodeRuleType(), CodeTypeEnum.AL_BULK_SAMPLE_CODE.getIntValue());
List<String> sampleCodes = new ArrayList<>(); List<String> sampleCodes = new ArrayList<>();
// 需要对编号额外处理 // 需要对编号额外处理
String vary = null; String vary = null;
for (EntrustSample s : samples) { 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()); sampleCodes.add(s.getCode());
} }
Account account = LoginHelper.getAccount();
Integer codeRuleType = samples.get(0).getCodeRuleType(); Integer codeRuleType = samples.get(0).getCodeRuleType();
// 不为空的情下触发编号回收机制 // 不为空的情下触发编号回收机制
if (CollectionUtils.isNotEmpty(sampleCodes) && null != codeRuleType) { if (null != codeRuleType) {
codeRuleService.recycleCode(CodeTypeEnum.get(codeRuleType), sampleCodes, vary, LoginHelper.getAccount()); if (isAlBulkSample) {
codeRuleService.recycleAlBulkCode(sampleCodes, account);
} else {
codeRuleService.recycleCode(CodeTypeEnum.get(codeRuleType), sampleCodes, vary, account);
}
} }
} }
......
...@@ -1280,14 +1280,34 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -1280,14 +1280,34 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
entrustRecordService.record(new Long[]{e.getId()}, EntrustStatusEnum.TEST.getDisplay(), EntrustStatusEnum.DRAFT.getDisplay(), 1, account, reason); entrustRecordService.record(new Long[]{e.getId()}, EntrustStatusEnum.TEST.getDisplay(), EntrustStatusEnum.DRAFT.getDisplay(), 1, account, reason);
sendUidList.add(e.getUid()); sendUidList.add(e.getUid());
// 更新样品状态 // 更新样品状态
EntrustSample entrustSample = new EntrustSample(); List<EntrustSample> sampleList = entrustSampleService.getByEntrustId(e.getId());
entrustSample.setStatus(EntrustSampleStatusEnum.DRAFT); // 抓取样品IDS
entrustSample.setProgress(EntrustSampleStatusEnum.DRAFT); List<Long> sampleIds = sampleList.stream().map(EntrustSample::getId).collect(Collectors.toList());
// 获取其中一个样品,判断是否是原铝散样
EntrustSample sample = sampleList.get(0);
boolean isAlBulkSample = Objects.equals(sample.getCodeRuleType(), CodeTypeEnum.AL_BULK_SAMPLE_CODE.getIntValue());
// 更新样品状态前,确认样品是否为原铝散样,若为原铝散样,清除样品编号
// 其他样品类型,不做处理
if (isAlBulkSample) {
List<String> codeList = new ArrayList<>();
for (EntrustSample s : sampleList) {
codeList.add(s.getCode());
s.setCode(null).setFirstCode(null).setSecondCode(null).setThirdCode(null)
.setStatus(EntrustSampleStatusEnum.DRAFT).setProgress(EntrustSampleStatusEnum.DRAFT);
}
entrustSampleService.updateBatchByData(sampleList);
codeRuleService.recycleAlBulkCode(codeList, account);
} else {
EntrustSample entrustSample = new EntrustSample();
entrustSample.setStatus(EntrustSampleStatusEnum.DRAFT);
entrustSample.setProgress(EntrustSampleStatusEnum.DRAFT);
entrustSampleService.update(entrustSample, Condition.create().eq("entrust_id", e.getId()));
}
// 检测项目处理
EntrustSampleItem entrustSampleItem = new EntrustSampleItem(); EntrustSampleItem entrustSampleItem = new EntrustSampleItem();
entrustSampleItem.setStatus(EntrustSampleItemStatusEnum.DRAFT); entrustSampleItem.setStatus(EntrustSampleItemStatusEnum.DRAFT);
entrustSampleItem.setProgress(EntrustSampleItemStatusEnum.DRAFT); entrustSampleItem.setProgress(EntrustSampleItemStatusEnum.DRAFT);
List<Long> sampleIds = entrustSampleService.getIdsByEntrustId(e.getId()); // 备样处理
entrustSampleService.update(entrustSample, Condition.create().eq("entrust_id", e.getId()));
entrustSamplePrepareService.removeBySampleIds(sampleIds.toArray(new Long[sampleIds.size()])); entrustSamplePrepareService.removeBySampleIds(sampleIds.toArray(new Long[sampleIds.size()]));
if (sampleIds.size() > 0) { if (sampleIds.size() > 0) {
entrustSampleItemService.update(entrustSampleItem, Condition.create().in("entrust_sample_id", sampleIds)); entrustSampleItemService.update(entrustSampleItem, Condition.create().in("entrust_sample_id", sampleIds));
......
...@@ -138,6 +138,7 @@ ...@@ -138,6 +138,7 @@
s.ID, s.ID,
s.NAME, s.NAME,
s.code, s.code,
s.first_code,s.second_code,s.third_code,
e.code AS "entrustCode", e.code AS "entrustCode",
e.client, e.client,
e.entrust_time, e.entrust_time,
...@@ -574,6 +575,14 @@ ...@@ -574,6 +575,14 @@
,compliance_test = #{item.complianceTest} ,compliance_test = #{item.complianceTest}
,fee = #{item.fee} ,fee = #{item.fee}
,modified = #{item.modified} ,modified = #{item.modified}
,material_id = #{item.materialId}
,code_edit = #{item.codeEdit}
,retake = #{item.retake}
,sampling_id = #{item.samplingId}
,conclusion = #{item.conclusion}
,recheck_code = #{item.recheckCode}
,send_erp = #{item.sendErp}
,code_rule_type = #{item.codeRuleType}
</set> </set>
where id = #{item.id} where id = #{item.id}
</foreach> </foreach>
......
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