Commit 1c603dfa by lijingjing

编号规则处理;

parent 1775bc9f
...@@ -123,6 +123,8 @@ public interface IEntrustSampleService extends IBaseService<EntrustSample> { ...@@ -123,6 +123,8 @@ public interface IEntrustSampleService extends IBaseService<EntrustSample> {
String getNewCode(String queryKey, int lens); String getNewCode(String queryKey, int lens);
String getNewCode(String queryKey, int start, int lens);
EntrustSample getByContractId(Long contractId); EntrustSample getByContractId(Long contractId);
boolean saveOrUpdateInfoBatch(List<EntrustSample> sampleList); boolean saveOrUpdateInfoBatch(List<EntrustSample> sampleList);
......
...@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.mapper.Wrapper; ...@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page; import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.toolkit.CollectionUtils; import com.baomidou.mybatisplus.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.toolkit.IdWorker; import com.baomidou.mybatisplus.toolkit.IdWorker;
import com.baomidou.mybatisplus.toolkit.StringUtils;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.patzn.cloud.commons.api.RestAssert; import com.patzn.cloud.commons.api.RestAssert;
import com.patzn.cloud.commons.controller.Account; import com.patzn.cloud.commons.controller.Account;
...@@ -31,6 +30,7 @@ import com.patzn.cloud.service.lims.hmhj.mapper.EntrustReportMapper; ...@@ -31,6 +30,7 @@ import com.patzn.cloud.service.lims.hmhj.mapper.EntrustReportMapper;
import com.patzn.cloud.service.lims.hmhj.original.OriginalUtil; import com.patzn.cloud.service.lims.hmhj.original.OriginalUtil;
import com.patzn.cloud.service.lims.hmhj.service.*; import com.patzn.cloud.service.lims.hmhj.service.*;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*; import org.apache.poi.xssf.usermodel.*;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
...@@ -206,16 +206,20 @@ public class EntrustReportServiceImpl extends BaseServiceImpl<EntrustReportMappe ...@@ -206,16 +206,20 @@ public class EntrustReportServiceImpl extends BaseServiceImpl<EntrustReportMappe
if (CollectionUtils.isEmpty(sampleList)) { if (CollectionUtils.isEmpty(sampleList)) {
return; return;
} }
// 正常情况下,所有的样品数据一级编码都不能为空
Map<String, String> sampleMap = sampleList.stream().collect(Collectors.toMap(t -> { Map<String, String> sampleMap = sampleList.stream().collect(Collectors.toMap(t -> {
if (StringUtils.isNotEmpty(t.getThirdCode())) { if (StringUtils.isNotEmpty(t.getThirdCode())) {
return t.getThirdCode(); return t.getThirdCode();
} else if (StringUtils.isNotEmpty(t.getSecondCode())) { } else if (StringUtils.isNotEmpty(t.getSecondCode())) {
return t.getSecondCode(); return t.getSecondCode();
} else { } else if (StringUtils.isNotBlank(t.getFirstCode())) {
return t.getFirstCode(); return t.getFirstCode();
} else {
return t.getCode();
} }
}, EntrustSample::getFirstCode)); }, t -> {
return StringUtils.isNotBlank(t.getFirstCode()) ? t.getFirstCode() : t.getCode();
}));
// objectKey data // objectKey data
InputStream is = ossClient.download(report.getObjectKey()); InputStream is = ossClient.download(report.getObjectKey());
...@@ -236,6 +240,9 @@ public class EntrustReportServiceImpl extends BaseServiceImpl<EntrustReportMappe ...@@ -236,6 +240,9 @@ public class EntrustReportServiceImpl extends BaseServiceImpl<EntrustReportMappe
for (int i = 1; i < rowNum; i++) { for (int i = 1; i < rowNum; i++) {
startRow = i; startRow = i;
XSSFRow xssfRow = sheet.getRow(i); XSSFRow xssfRow = sheet.getRow(i);
if (null == xssfRow) {
continue;
}
for (int j = 0; j < xssfRow.getLastCellNum(); j++) { for (int j = 0; j < xssfRow.getLastCellNum(); j++) {
String title = getCellValue(xssfRow, j); String title = getCellValue(xssfRow, j);
if ("试样编号".equals(title)) { if ("试样编号".equals(title)) {
...@@ -247,6 +254,9 @@ public class EntrustReportServiceImpl extends BaseServiceImpl<EntrustReportMappe ...@@ -247,6 +254,9 @@ public class EntrustReportServiceImpl extends BaseServiceImpl<EntrustReportMappe
for (int i = startRow + 1; i < rowNum; i++) { for (int i = startRow + 1; i < rowNum; i++) {
XSSFRow xssfRow = sheet.getRow(i); XSSFRow xssfRow = sheet.getRow(i);
if (null == xssfRow) {
continue;
}
String sampleCode = getCellValue(xssfRow, sampleCodePos); String sampleCode = getCellValue(xssfRow, sampleCodePos);
if (org.apache.commons.lang3.StringUtils.isBlank(sampleCode)) { if (org.apache.commons.lang3.StringUtils.isBlank(sampleCode)) {
continue; continue;
......
...@@ -1936,6 +1936,38 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe ...@@ -1936,6 +1936,38 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
} }
@Override @Override
public String getNewCode(String queryKey, int start, int lens) {
String startKey = "000000000000000000";
// 长度默认1
lens = lens == 0 ? 1 : lens;
// 默认值:xxx___zz或者 xxxzz___此处使用替换
String repSymbol = "";
while (repSymbol.length() != lens) {
repSymbol += "_";
}
String repStr = startKey.substring(0, lens - 1) + 1;
String defKey = queryKey.replace(repSymbol, repStr);
// ==
if (StringUtils.isBlank(queryKey)) {
return defKey;
}
String lastCode = baseMapper.selectLastCode(queryKey);
if (StringUtils.isBlank(lastCode)) {
return defKey;
}
// 截取最大编号中的流水号信息
String sampleSN = lastCode.substring(start, start + lens);
try {
Integer nextSN = Integer.parseInt(sampleSN) + 1;
repStr = startKey.substring(0, lens - nextSN.toString().length()) + nextSN;
return queryKey.replace(repSymbol, repStr);
} catch (NumberFormatException e) {
logger.error(e.getMessage(), e.getCause());
throw new PatznException("样品编码流水号获取异常");
}
}
@Override
public EntrustSample getByContractId(Long contractId) { public EntrustSample getByContractId(Long contractId) {
if (null == contractId) { if (null == contractId) {
return null; return null;
......
...@@ -250,43 +250,27 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -250,43 +250,27 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
} }
// 原铝散样样品编号处理 // 原铝散样样品编号处理
else if (CodeTypeEnum.AL_BULK_SAMPLE_CODE == codeType) { else if (CodeTypeEnum.AL_BULK_SAMPLE_CODE == codeType) {
// 替换槽号CH
sampleCode = sampleCode.replace("CH", sample.getSlotNo());
// 根据当前系统时间获取班次
LocalTime now = LocalTime.now();
LocalTime zero = LocalTime.parse("00:00:00");
LocalTime eight = LocalTime.parse("08:00:00");
LocalTime sixth = LocalTime.parse("16:00:00");
String clazz;
if (now.isAfter(zero) && now.isBefore(eight)) {
clazz = "E";
} else if (now.isAfter(eight) && now.isBefore(sixth)) {
clazz = "A";
} else {
clazz = "C";
}
// 替换班次BC // 替换班次BC
sampleCode = sampleCode.replace("BC", clazz); sampleCode = sampleCode.replace("BC", getShiftByNow());
// @yyMM&CH&BC&SN len(SN) = 3 // YYMMDD+(A/C/E)+SN(1)+ 槽号(4)
String queryKey = sampleCode.substring(0, sampleCode.length() - 3); String queryKey = sampleCode.substring(0, 7) + "_" + sampleCode.substring(8);
sampleCode = entrustSampleService.getNewCode(queryKey, 3); sampleCode = entrustSampleService.getNewCode(queryKey, 7, 1);
} }
// 电解质散样样品编号处理 // 电解质散样样品编号处理
else if (CodeTypeEnum.ELECT_BULK_SAMPLE_CODE == codeType) { // else if (CodeTypeEnum.ELECT_BULK_SAMPLE_CODE == codeType) {
// 替换槽号CH // // D+@yyMMdd&-&${et.slotNo}
sampleCode = sampleCode.replace("CH", sample.getSlotNo()); // String queryKey = sampleCode.substring(0, sampleCode.length() - 3);
// @yyMM&CH&SN len(SN) = 3 // sampleCode = entrustSampleService.getNewCode(queryKey, 3);
String queryKey = sampleCode.substring(0, sampleCode.length() - 3); // }
sampleCode = entrustSampleService.getNewCode(queryKey, 3); //== 原铝重取样品编号处理
} // add by meazty on 2022-01-06 14:42〔原铝重取不再根据以下规则生成,使用默认规则即可〕
//原铝重取样品编号处理 // else if (CodeTypeEnum.AL_RETAKE_SAMPLE_CODE == codeType) {
else if (CodeTypeEnum.AL_RETAKE_SAMPLE_CODE == codeType) { // // 替换槽号CH
// 替换槽号CH // sampleCode = sampleCode.replace("CH", sample.getSlotNo());
sampleCode = sampleCode.replace("CH", sample.getSlotNo()); // // @yyMMdd&CH&C&SN len(SN) = 1
// @yyMMdd&CH&C&SN len(SN) = 1 // String queryKey = sampleCode.substring(0, sampleCode.length() - 1);
String queryKey = sampleCode.substring(0, sampleCode.length() - 1); // sampleCode = entrustSampleService.getNewCode(queryKey, 1);
sampleCode = entrustSampleService.getNewCode(queryKey, 1); // }
}
} }
if (StringUtils.isNotBlank(sampleCode)) { if (StringUtils.isNotBlank(sampleCode)) {
...@@ -306,6 +290,27 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -306,6 +290,27 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
} }
} }
/**
* 根据当前系统时间获取班次
* @return
*/
private String getShiftByNow() {
// 根据当前系统时间获取班次
LocalTime now = LocalTime.now();
LocalTime zero = LocalTime.parse("00:00:00");
LocalTime eight = LocalTime.parse("08:00:00");
LocalTime sixth = LocalTime.parse("16:00:00");
String clazz;
if (now.isAfter(zero) && now.isBefore(eight)) {
clazz = "E";
} else if (now.isAfter(eight) && now.isBefore(sixth)) {
clazz = "A";
} else {
clazz = "C";
}
return clazz;
}
// 验证样品非空字段 // 验证样品非空字段
private void judgeSampleFields(EntrustSample sample, boolean isRequiredFill) { private void judgeSampleFields(EntrustSample sample, boolean isRequiredFill) {
if (isRequiredFill) { if (isRequiredFill) {
......
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