Commit 62ee1f91 by lijingjing

修改进场物资编码问题;

parent 57282c37
......@@ -3,6 +3,7 @@ package com.patzn.cloud.service.lims.hmhj.controller;
import com.baomidou.kisso.annotation.Action;
import com.baomidou.kisso.annotation.Login;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.toolkit.CollectionUtils;
import com.google.common.collect.Lists;
import com.patzn.cloud.commons.api.RestConstants;
import com.patzn.cloud.commons.api.RestResult;
......@@ -820,6 +821,21 @@ public class EntrustController extends ServiceController {
return success(entrustService.pageEntrustByReportHis(getPage(), entrust));
}
@ApiOperation("成品报告分页列表")
@ApiImplicitParams({
@ApiImplicitParam(name = RestConstants.PAGE_PAGE, value = "请求数据的页码", required = true, paramType = "query", dataTypeClass = Integer.class),
@ApiImplicitParam(name = RestConstants.PAGE_ROWS, value = "每页条数", required = true, paramType = "query", dataTypeClass = Integer.class),
@ApiImplicitParam(name = RestConstants.PAGE_SIDX, value = "排序字段", paramType = "query", dataTypeClass = String.class),
@ApiImplicitParam(name = RestConstants.PAGE_SORD, value = "排序方式", paramType = "query", dataTypeClass = String.class),
})
@PostMapping("/page_report_product")
public RestResult<Page<EntrustVO>> getPageReportProduct(EntrustVO entrust) {
// entrust.setGroupNameList(userInfoService.getCurGroupNameList());
// 查询成品报告列表
entrust.setSampleType(2);
return success(entrustService.getPageReportProduct(getPage(), entrust));
}
@ApiOperation("质量判定委托分页列表")
@ApiImplicitParams({
......@@ -948,4 +964,14 @@ public class EntrustController extends ServiceController {
public RestResult<Page<EntrustVO>> getPageEntrustTpl(EntrustVO entrust) {
return success(entrustService.getPageEntrustTpl(getPage(), entrust));
}
@ApiOperation("是否属于化验组织")
@RequestMapping(value = "/belong_assay", method = {RequestMethod.POST, RequestMethod.GET})
public RestResult<Boolean> isBelongAssay() {
List<String> orgNames = userInfoService.getUserOrgNames(getAccount());
if (CollectionUtils.isEmpty(orgNames)) {
return success(false);
}
return success(userInfoService.getUserOrgNames(getAccount()).stream().anyMatch(t -> t.contains("化验") && !t.contains("净化化验")));
}
}
......@@ -17,6 +17,7 @@ import com.patzn.cloud.service.hmhj.enums.EntrustSamplePrepareStatusEnum;
import com.patzn.cloud.service.hmhj.enums.EntrustSampleStatusEnum;
import com.patzn.cloud.service.hmhj.vo.AlGradeStatsVO;
import com.patzn.cloud.service.hmhj.vo.ElectrolyteRatioStatsVO;
import com.patzn.cloud.service.hmhj.vo.EntrustSampleIndexVO;
import com.patzn.cloud.service.hmhj.vo.EntrustSampleVO;
import com.patzn.cloud.service.lims.hmhj.service.IEntrustSampleService;
import com.patzn.cloud.service.lims.hmhj.service.impl.UserInfoServiceImpl;
......@@ -146,6 +147,7 @@ public class EntrustSampleController extends ServiceController {
@PostMapping("/page_report_issue")
public RestResult<Page<EntrustSample>> getPageReportIssue(EntrustSample entrustSample) {
entrustSample.setStatus(EntrustSampleStatusEnum.REPORT_ISSUE);
entrustSample.setType(0);
return success(entrustSampleService.page(getPage(), entrustSample));
}
......@@ -159,6 +161,7 @@ public class EntrustSampleController extends ServiceController {
@PostMapping("/page_report_allow")
public RestResult<Page<EntrustSample>> getPageReportAllow(EntrustSample entrustSample) {
entrustSample.setStatus(EntrustSampleStatusEnum.REPORT_ALLOW);
entrustSample.setType(0);
return success(entrustSampleService.page(getPage(), entrustSample));
}
......@@ -172,6 +175,7 @@ public class EntrustSampleController extends ServiceController {
@PostMapping("/page_report_send")
public RestResult<Page<EntrustSample>> getPageReportSend(EntrustSample entrustSample) {
entrustSample.setStatus(EntrustSampleStatusEnum.REPORT_SEND);
entrustSample.setType(0);
return success(entrustSampleService.page(getPage(), entrustSample));
}
......@@ -185,6 +189,7 @@ public class EntrustSampleController extends ServiceController {
@PostMapping("/page_quality_inspect")
public RestResult<Page<EntrustSample>> getPageQualityInspect(EntrustSample entrustSample) {
entrustSample.setStatus(EntrustSampleStatusEnum.QUALITY_INSPECT);
entrustSample.setType(0);
return success(entrustSampleService.page(getPage(), entrustSample));
}
......@@ -488,8 +493,8 @@ public class EntrustSampleController extends ServiceController {
private void handlerData(EntrustSampleVO vo) {
// 数据来源
// 若为数据录入节点且不为分组管理员,那么需要过滤数据
boolean isLeader = userInfoService.isGroupLeader(vo.getEntrustId(),getAccount());
if("TEST".equalsIgnoreCase(vo.getSource()) && !isLeader){
boolean isLeader = userInfoService.isGroupLeader(vo.getEntrustId(), getAccount());
if ("TEST".equalsIgnoreCase(vo.getSource()) && !isLeader) {
vo.setTesterId(getAccount().getUserId());
}
}
......@@ -622,4 +627,22 @@ public class EntrustSampleController extends ServiceController {
public RestResult<Boolean> scanReceive(@RequestParam("sampleCode") String sampleCode) {
return success(entrustSampleService.scanReceive(sampleCode, getAccount()));
}
@ApiOperation("样品指标分页列表")
@ApiImplicitParams({
@ApiImplicitParam(name = RestConstants.PAGE_PAGE, value = "请求数据的页码", required = true, paramType = "query", dataTypeClass = Integer.class),
@ApiImplicitParam(name = RestConstants.PAGE_ROWS, value = "每页条数", required = true, paramType = "query", dataTypeClass = Integer.class),
@ApiImplicitParam(name = RestConstants.PAGE_SIDX, value = "排序字段", paramType = "query", dataTypeClass = String.class),
@ApiImplicitParam(name = RestConstants.PAGE_SORD, value = "排序方式", paramType = "query", dataTypeClass = String.class),
})
@PostMapping("/page_sample_index")
public RestResult<Page<EntrustSampleIndexVO>> getPageSampleIndex(EntrustSampleIndexVO sampleIndexVO) {
return success(entrustSampleService.getPageSampleIndex(getPage(), sampleIndexVO));
}
@ApiOperation("导出样品指标信息")
@RequestMapping(value = "/export_sample_index", method = {RequestMethod.POST, RequestMethod.GET})
public void exportSampleIndex(Long entrustId) {
entrustSampleService.exportSampleIndex(entrustId, getAccount(), response);
}
}
package com.patzn.cloud.service.lims.hmhj.mapper;
import com.baomidou.mybatisplus.annotations.SqlParser;
import com.baomidou.mybatisplus.plugins.Page;
import com.patzn.cloud.commons.mapper.BatchMapper;
import com.patzn.cloud.service.hmhj.dto.QueryDTO;
import com.patzn.cloud.service.hmhj.dto.SampleItemDTO;
import com.patzn.cloud.service.hmhj.entity.EntrustSampleItem;
import com.patzn.cloud.service.hmhj.vo.EntrustSampleCalcResultVO;
import com.patzn.cloud.service.hmhj.vo.EntrustSampleItemVO;
import com.patzn.cloud.service.hmhj.vo.SampleItemStatsVO;
import com.patzn.cloud.service.hmhj.vo.TesterWorkloadStatsVO;
import com.patzn.cloud.service.hmhj.vo.*;
import com.patzn.cloud.service.lims.base.entity.LmsUserRelGroup;
import com.patzn.cloud.service.lims.base.vo.LmsUserRelGroupVO;
import org.apache.ibatis.annotations.Param;
......@@ -81,4 +77,6 @@ public interface EntrustSampleItemMapper extends BatchMapper<EntrustSampleItem>
@SqlParser(filter = true)
boolean updateSampleRetakeInfoByEntrustId(@Param("entrustId") Long entrustId);
List<EntrustSampleItemIndexVO> selectItemTestByEntrustId(@Param("entrustId") Long entrustId);
}
......@@ -47,4 +47,6 @@ public interface EntrustSampleMapper extends BatchMapper<EntrustSample> {
List<ReportSampleVO> selectReportSampleInfos(@Param("sampleIds") Long[] sampleIds);
String selectLastCode(@Param("queryKey") String queryKey);
List<EntrustSampleIndexVO> selectSampleIndex(RowBounds rowBounds, @Param("vo") EntrustSampleIndexVO sampleIndexVO);
}
package com.patzn.cloud.service.lims.hmhj.mapper;
import com.patzn.cloud.commons.mapper.BatchMapper;
import com.patzn.cloud.service.hmhj.entity.Identifier;
/**
* <p>
* Mapper 接口
* </p>
*
* @author meazty
* @since 2021-10-09
*/
public interface IdentifierMapper extends BatchMapper<Identifier> {
}
......@@ -28,6 +28,10 @@ public interface IEntrustReportService extends IBaseService<EntrustReport> {
void uploadReportGenerateDocx(Entrust entrust, Long[] ids, Account account, String name, String remark, File file);
void uploadReportGenerateXlsx(Entrust entrust, Long[] ids, Account account, String name, String remark, File file);
boolean submitReportMake(Long[] ids, Account account);
boolean submitReportCheck(Long[] ids, Account account);
......
......@@ -9,7 +9,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
* 服务类
* 服务类
*
* @author wwd
* @since 2021-02-26
......@@ -20,7 +20,9 @@ public interface IEntrustReportTemplateService extends IBaseService<EntrustRepor
boolean removeByIds(List<Long> ids);
boolean uploadTemplate(MultipartFile file, String name,String classType, String remark);
boolean uploadTemplate(MultipartFile file, String name, String classType, String remark);
boolean updateTemplateById(EntrustReportTemplate entrustReportTemplate, Account account);
EntrustReportTemplate getByClassType(String classType);
}
......@@ -10,6 +10,7 @@ import com.patzn.cloud.service.hmhj.entity.ItemDeviate;
import com.patzn.cloud.service.hmhj.entity.OriginalRecord;
import com.patzn.cloud.service.hmhj.enums.EntrustFlowEnum;
import com.patzn.cloud.service.hmhj.vo.EntrustSampleCalcResultVO;
import com.patzn.cloud.service.hmhj.vo.EntrustSampleItemIndexVO;
import com.patzn.cloud.service.hmhj.vo.EntrustSampleItemVO;
import com.patzn.cloud.service.hmhj.vo.TesterWorkloadStatsVO;
import com.patzn.cloud.service.lims.base.entity.LmsUserRelGroup;
......@@ -119,4 +120,8 @@ public interface IEntrustSampleItemService extends IBaseService<EntrustSampleIte
boolean updateSampleRetakeByEntrustId(Long entrustId);
List<EntrustSampleItemVO> getSampleItemIndexList(Long sampleId);
List<EntrustSampleItemIndexVO> getItemTestByEntrustId(Long entrustIds);
EntrustSampleItem getItemModelBySampleId(Long sampleId);
}
......@@ -11,11 +11,9 @@ import com.patzn.cloud.service.hmhj.dto.StatsQueryDTO;
import com.patzn.cloud.service.hmhj.entity.Entrust;
import com.patzn.cloud.service.hmhj.entity.EntrustSample;
import com.patzn.cloud.service.hmhj.enums.EntrustFlowEnum;
import com.patzn.cloud.service.hmhj.vo.AlGradeStatsVO;
import com.patzn.cloud.service.hmhj.vo.ElectrolyteRatioStatsVO;
import com.patzn.cloud.service.hmhj.vo.EntrustSampleVO;
import com.patzn.cloud.service.hmhj.vo.ReportSampleVO;
import com.patzn.cloud.service.hmhj.vo.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
......@@ -128,4 +126,8 @@ public interface IEntrustSampleService extends IBaseService<EntrustSample> {
EntrustSample getByContractId(Long contractId);
boolean saveOrUpdateInfoBatch(List<EntrustSample> sampleList);
Page<EntrustSampleIndexVO> getPageSampleIndex(Page<EntrustSampleIndexVO> page, EntrustSampleIndexVO sampleIndexVO);
void exportSampleIndex(Long entrustId, Account account, HttpServletResponse response);
}
......@@ -116,4 +116,5 @@ public interface IEntrustService extends IBaseService<Entrust> {
boolean submitToNextFlow(Long[] ids, Account account);
boolean saveOrUpdateToSubmit(EntrustDTO entrustDTO, Account account);
Page<EntrustVO> getPageReportProduct(Page<EntrustVO> page, EntrustVO entrust);
}
package com.patzn.cloud.service.lims.hmhj.service;
import com.baomidou.mybatisplus.plugins.Page;
import com.patzn.cloud.commons.service.IBaseService;
import com.patzn.cloud.service.hmhj.entity.Identifier;
import java.util.List;
/**
* 服务类
*
* @author meazty
* @since 2021-10-09
*/
public interface IIdentifierService extends IBaseService<Identifier> {
Page<Identifier> page(Page<Identifier> page, Identifier identifier);
boolean removeByIds(List<Long> ids);
String getNextSN(String type);
}
......@@ -5,10 +5,14 @@ import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.toolkit.IdWorker;
import com.baomidou.mybatisplus.toolkit.StringUtils;
import com.google.common.collect.Lists;
import com.patzn.cloud.commons.api.RestAssert;
import com.patzn.cloud.commons.controller.Account;
import com.patzn.cloud.commons.controller.LoginHelper;
import com.patzn.cloud.commons.service.impl.BaseServiceImpl;
import com.patzn.cloud.commons.toolkit.DateUtils;
import com.patzn.cloud.commons.toolkit.FileUtils;
import com.patzn.cloud.feign.base.client.SysUserClient;
import com.patzn.cloud.oss.starter.OssClient;
......@@ -17,10 +21,19 @@ import com.patzn.cloud.service.base.vo.SysUserOrgVO;
import com.patzn.cloud.service.hmhj.entity.*;
import com.patzn.cloud.service.hmhj.enums.*;
import com.patzn.cloud.service.hmhj.vo.EntrustReportVO;
import com.patzn.cloud.service.hmhj.vo.EntrustSampleItemIndexVO;
import com.patzn.cloud.service.hmhj.vo.EntrustSampleVO;
import com.patzn.cloud.service.lims.common.StringHandleUtils;
import com.patzn.cloud.service.lims.hmhj.common.EntrustFlowUtils;
import com.patzn.cloud.service.lims.hmhj.common.HSSFWorkbookUtil;
import com.patzn.cloud.service.lims.hmhj.common.LabreOfficeUtil;
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.service.*;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
......@@ -28,6 +41,8 @@ import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.concurrent.Executor;
......@@ -51,10 +66,16 @@ public class EntrustReportServiceImpl extends BaseServiceImpl<EntrustReportMappe
@Autowired
private IEntrustSampleItemService entrustSampleItemService;
@Autowired
private IEntrustSampleItemIndexService entrustSampleItemIndexService;
@Autowired
private IEntrustService entrustService;
@Autowired
private IEntrustRecordService entrustRecordService;
@Autowired
private IEntrustReportTemplateService entrustReportTemplateService;
@Autowired
private IEntrustReportTemplateConfigService entrustReportTemplateConfigService;
@Autowired
private Executor executor1;
@Autowired
private SysUserClient sysUserClient;
......@@ -146,6 +167,10 @@ public class EntrustReportServiceImpl extends BaseServiceImpl<EntrustReportMappe
report.setObjectKey(fileResult.getObjectKey());
report.setVersionId(fileResult.getVersionId());
report.setSampleName(name);
// 新生成一份以一级编码样品编号的报告
generateOtherReportFile(report, ids);
if (save(report)) {
List<EntrustReportRelSample> saveRel = new ArrayList<>();
......@@ -164,6 +189,123 @@ public class EntrustReportServiceImpl extends BaseServiceImpl<EntrustReportMappe
}
}
private String getCellValue(XSSFRow xssfRow, int cellIndex) {
XSSFCell cell = xssfRow.getCell(cellIndex);
String value = HSSFWorkbookUtil.getJavaValue(cell).toString();
return org.apache.commons.lang3.StringUtils.isBlank(value) ? "" : value.trim();
}
private void generateOtherReportFile(EntrustReport report, Long[] sampleIds) {
if (ArrayUtils.isEmpty(sampleIds)) {
return;
}
List<EntrustSample> sampleList = entrustSampleService.getBatchIds(Arrays.asList(sampleIds));
if (CollectionUtils.isEmpty(sampleList)) {
return;
}
Map<String, String> sampleMap = sampleList.stream().collect(Collectors.toMap(EntrustSample::getCode, EntrustSample::getFirstCode));
// objectKey data
InputStream is = ossClient.download(report.getObjectKey());
//结果回调
XSSFWorkbook xssfWorkbook = null;
try {
xssfWorkbook = new XSSFWorkbook(is);
} catch (Exception e) {
logger.error(e.getMessage(), e.getCause());
}
XSSFSheet sheet = xssfWorkbook.getSheetAt(0);
int rowNum = sheet.getLastRowNum();
// 默认开始行为:5,单元格序号为:-1
int startRow = 5, sampleCodePos = -1, sampleBrandPos = -1;
flag:
for (int i = 5; i < rowNum; i++) {
startRow = i;
XSSFRow xssfRow = sheet.getRow(i);
for (int j = 0; j < xssfRow.getLastCellNum(); j++) {
String title = getCellValue(xssfRow, j);
if ("试样编号".equals(title)) {
sampleCodePos = j;
break flag;
}
}
}
for (int i = startRow + 1; i < rowNum; i++) {
XSSFRow xssfRow = sheet.getRow(i);
String sampleCode = getCellValue(xssfRow, sampleCodePos);
if (org.apache.commons.lang3.StringUtils.isBlank(sampleCode)) {
continue;
}
String sampleNewCode = sampleMap.get(sampleCode);
if (org.apache.commons.lang3.StringUtils.isNotBlank(sampleNewCode)) {
xssfRow.getCell(sampleCodePos).setCellValue(sampleNewCode);
}
}
FileOutputStream os = null;
File file = null;
String generated = "报告一级或多级编码报告生成";
try {
file = File.createTempFile(generated, ".xlsx");
os = new FileOutputStream(file);
xssfWorkbook.write(os);
os.flush();
OssFileResult fileResult = ossClient.upload(file);
if (null != fileResult) {
report.setOtherObjectKey(fileResult.getObjectKey());
}
} catch (Exception e) {
logger.error("Exception 报错" + e.getMessage());
e.printStackTrace();
} finally {
try {
os.close();
xssfWorkbook.close();
is.close();
} catch (Exception e) {
e.printStackTrace();
}
FileUtils.deleteFiles(file);
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void uploadReportGenerateXlsx(Entrust entrust, Long[] ids, Account account, String name, String remark, File file) {
OssFileResult fileResult = ossClient.upload(file);
if (null != fileResult) {
EntrustReport report = new EntrustReport();
report.setEntrustId(entrust.getId()).setRemark(remark).setReportMaker(account.getUserName())
.setReportMakerId(account.getUserId()).setReportMakeTime(new Date())
.setBucketName(fileResult.getBucketName()).setObjectKey(fileResult.getObjectKey())
.setVersionId(fileResult.getVersionId()).setSampleName(name)
.setStatus(EntrustReportStatusEnum.SEND).setProgress(EntrustReportStatusEnum.SEND);
save(report);
List<EntrustReportRelSample> saveRel = new ArrayList<>();
for (Long sampleId : ids) {
EntrustReportRelSample reportRelSample = new EntrustReportRelSample();
reportRelSample.setReportId(report.getId());
reportRelSample.setSampleId(sampleId);
saveRel.add(reportRelSample);
}
if (CollectionUtils.isNotEmpty(saveRel)) {
entrustReportRelSampleService.saveBatch(saveRel);
}
}
}
@Transactional(rollbackFor = Exception.class)
@Override
public boolean submitReportMake(Long[] ids, Account account) {
......@@ -180,6 +322,7 @@ public class EntrustReportServiceImpl extends BaseServiceImpl<EntrustReportMappe
List<EntrustReport> updateReportList = new ArrayList<>();
for (EntrustReport report : reportList) {
InputStream io = ossClient.download(report.getObjectKey());
if (null == io)
continue;
......@@ -192,6 +335,21 @@ public class EntrustReportServiceImpl extends BaseServiceImpl<EntrustReportMappe
EntrustReport u = new EntrustReport();
u.setPdfObjectKey(fileResult.getObjectKey());
u.setId(report.getId());
// ===============
InputStream is = ossClient.download(report.getOtherObjectKey());
if (null == is) {
updateReportList.add(u);
continue;
}
File fileOther = LabreOfficeUtil.inputStream2File(is);
File filePdfOther = LabreOfficeUtil.convertOffice2PDF(libreOfficeUrl, fileOther);
deleteFileList.add(fileOther);
deleteFileList.add(filePdfOther);
fileResult = ossClient.upload(filePdfOther);
u.setOtherPdfObjectKey(fileResult.getObjectKey());
u.setId(report.getId());
updateReportList.add(u);
}
if (CollectionUtils.isNotEmpty(updateReportList)) {
......@@ -279,6 +437,10 @@ public class EntrustReportServiceImpl extends BaseServiceImpl<EntrustReportMappe
// 若从批准往后提交,则生成报告
// 转化PDF
executor1.execute(() -> changeExcelReportToPdf(ids));
// 若为发放
if (toFlowStatus == EntrustFlowEnum.REPORT_SEND) {
generateNewReportFlow(entrust.getId());
}
} else if (toFlowStatus == EntrustFlowEnum.QUALITY_JUDGE || toFlowStatus == EntrustFlowEnum.ARCHIVES) {
// 归档前置条件为已判定
entrust.setStatus(EntrustStatusEnum.QUALITY_CHECK);
......@@ -318,7 +480,7 @@ public class EntrustReportServiceImpl extends BaseServiceImpl<EntrustReportMappe
EntrustSampleStatusEnum finalSampleStatusEnum = sampleStatusEnum;
if (CollectionUtils.isNotEmpty(entrustSamples) && entrustSamples.stream().filter(t -> !sampleIds.contains(t.getId())
).noneMatch(t -> (int) t.getStatus().getValue() < (int) finalSampleStatusEnum.getValue())) {
).noneMatch(t -> (int) t.getStatus().getValue() < (int) finalSampleStatusEnum.getValue())) {
entrust.setFlowStatus(toFlowStatus.getName());
entrustService.updateById(entrust);
entrustRecordService.record(Collections.singletonList(entrust.getId()), fromFlowStatus.getDisplay(),
......@@ -333,6 +495,264 @@ public class EntrustReportServiceImpl extends BaseServiceImpl<EntrustReportMappe
return entrustSampleItemService.updateQualityJudgeFlow(sampleIds.toArray(new Long[sampleIds.size()]), account);
}
@Transactional(rollbackFor = Exception.class)
protected void generateNewReportFlow(Long entrustId) {
if (null == entrustId) {
return;
}
Entrust entrust = entrustService.getById(entrustId);
String sampleName = "铝成品";
Account account = LoginHelper.getAccount();
// ==
List<EntrustSample> sampleList = new ArrayList<>();
List<EntrustSampleVO> sampleVOList = new ArrayList<>();
List<EntrustSampleItem> itemList = new ArrayList<>();
List<EntrustSampleItemIndex> indexList = new ArrayList<>();
List<EntrustSampleItemIndexVO> indexVOList = entrustSampleItemService.getItemTestByEntrustId(entrustId);
// 生成样品
// 获取委托下第一个样品信息,主要为了获取额外参数数据
EntrustSample sampleModel = entrustSampleService.getNormalByEntrustId(entrustId).get(0);
EntrustSampleItem itemModel = entrustSampleItemService.getItemModelBySampleId(sampleModel.getId());
List<String> sampleCodes = indexVOList.stream().map(EntrustSampleItemIndexVO::getSampleCode).distinct().collect(Collectors.toList());
for (String sampleCode : sampleCodes) {
EntrustSample sample = new EntrustSample();
BeanUtils.copyProperties(sampleModel, sample);
sample.setCode(sampleCode).setOrderBy(99).setCtime(new Date()).setLtime(new Date()).setUid(account.getUserId())
.setLid(account.getUserId()).setType(2).setId(IdWorker.getId());
sampleList.add(sample);
EntrustSampleVO sampleVO = new EntrustSampleVO();
BeanUtils.copyProperties(sample, sampleVO);
indexVOList.stream().filter(i -> i.getSampleCode().equals(sampleCode)).forEach(i -> {
// 生成检测项
EntrustSampleItem item = new EntrustSampleItem();
BeanUtils.copyProperties(itemModel, item);
item.setName(i.getName()).setEntrustSampleId(sample.getId()).setProgress(EntrustSampleItemStatusEnum.END)
.setStatus(EntrustSampleItemStatusEnum.END).setCtime(new Date()).setUid(account.getUserId())
.setLid(account.getUserId()).setLtime(new Date()).setId(IdWorker.getId());
itemList.add(item);
// 生成检测值
EntrustSampleItemIndex index = new EntrustSampleItemIndex();
index.setStatus(50);
index.setName(i.getName());
index.setTestValue(i.getTestValue());
index.setProgress(50);
index.setUid(account.getUserId());
index.setCtime(new Date());
index.setEntrustSampleItemId(item.getId());
indexList.add(index);
});
sampleVO.setIndexList(indexList);
sampleVOList.add(sampleVO);
}
if (CollectionUtils.isNotEmpty(sampleList)) {
entrustSampleService.saveBatch(sampleList);
}
if (CollectionUtils.isNotEmpty(itemList)) {
entrustSampleItemService.saveBatch(itemList);
}
if (CollectionUtils.isNotEmpty(indexList)) {
entrustSampleItemIndexService.saveBatch(indexList);
}
// 生成报告及文件
// generateReportFile(entrust, template, sampleVOList, account);
}
private void generateReportFile(Entrust entrust, EntrustReportTemplate sysFileTemplate, List<EntrustSampleVO> sampleVOList, Account account) {
Long[] sampleIds = sampleVOList.stream().map(EntrustSampleVO::getId).toArray(Long[]::new);
String sampleName = sampleVOList.get(0).getName();
InputStream io = ossClient.download(sysFileTemplate.getObjectKey());
XSSFWorkbook xssfWorkbook = null;
try {
xssfWorkbook = new XSSFWorkbook(io);
} catch (IOException e) {
e.printStackTrace();
}
List<EntrustReportTemplateConfig> configList = entrustReportTemplateConfigService.list(Condition.create().eq("template_id", sysFileTemplate.getId()));
OriginalUtil.doReplace(xssfWorkbook, entrust);
Map<String, String> mapReplace = new HashMap<>();
mapReplace.put("#{nowDate}", DateUtils.toYearMonthDay(new Date()));
mapReplace.put("#{sampleNum}", sampleVOList.size() + "");
mapReplace.put("#{sampleFrom}", sampleVOList.size() > 0 ? sampleVOList.get(0).getSampleFrom() : " - ");
mapReplace.put("#{sampleName}", sampleVOList.get(0).getName());
int numberOfSheets = xssfWorkbook.getNumberOfSheets();
for (int k = 0; k < numberOfSheets; k++) {
HSSFWorkbookUtil.replaceModel(mapReplace, xssfWorkbook, k);
XSSFSheet sheetOne = xssfWorkbook.getSheetAt(k);
String sheetName = sheetOne.getSheetName();
System.out.println(sheetName);
sheetOne.setForceFormulaRecalculation(true);
int sampleMergerNum = sysFileTemplate.getSampleMergerNum();
int templateSampleNum = sysFileTemplate.getTemplateSampleNum();
if (templateSampleNum >= sampleVOList.size()) {
Integer beginRow = sysFileTemplate.getSampleBeginRow();
for (EntrustSampleVO vo : sampleVOList) {
XSSFRow xssfRow = sheetOne.getRow(beginRow);
for (EntrustReportTemplateConfig config : configList) {
if (null != config.getSheetNum() && config.getSheetNum() != k) {
continue;
}
if (null == config.getColumnPlace()) {
continue;
}
XSSFCell cell = xssfRow.getCell(config.getColumnPlace());
if ("sn".equals(config.getDataAttribute())) {
continue;
}
if (org.apache.commons.lang3.StringUtils.isBlank(config.getDataAttribute())) {
continue;
}
String value = StringHandleUtils.getFieldValue(config.getDataAttribute(), vo);
cell.setCellValue(value);
}
beginRow += sampleMergerNum;
}
} else {
if (null != sysFileTemplate.getMoreSheet() && sysFileTemplate.getMoreSheet() == 1) {
int total = sampleVOList.size();
int totalSheetSize = (total + templateSampleNum - 1) / templateSampleNum;
List<List<EntrustSampleVO>> listList = Lists.partition(sampleVOList, templateSampleNum);
for (int i = 1; i < totalSheetSize; i++) {
xssfWorkbook.cloneSheet(0, sheetOne.getSheetName() + (i + 1));
}
for (int m = 0; m < listList.size(); m++) {
Integer beginRow = sysFileTemplate.getSampleBeginRow();
List<EntrustSampleVO> sampleVOListIndex = listList.get(k);
for (EntrustSampleVO vo : sampleVOListIndex) {
XSSFSheet sheetOneIndex = xssfWorkbook.getSheetAt(k);
XSSFRow xssfRow = sheetOneIndex.getRow(beginRow);
for (EntrustReportTemplateConfig config : configList) {
XSSFCell cell = xssfRow.getCell(config.getColumnPlace());
if ("sn".equals(config.getDataAttribute())) {
continue;
}
if (org.apache.commons.lang3.StringUtils.isBlank(config.getDataAttribute())) {
continue;
}
String value = StringHandleUtils.getFieldValue(config.getDataAttribute(), vo);
cell.setCellValue(value);
}
beginRow += sampleMergerNum;
}
}
} else {
Integer beginRow = sysFileTemplate.getSampleBeginRow();
int insertRow = beginRow + sampleMergerNum * templateSampleNum;
XSSFRow zeroRow = sheetOne.getRow(beginRow);
XSSFCellStyle cellStyle = zeroRow.getCell(0).getCellStyle();
int lastCellNum = zeroRow.getLastCellNum();
int insertCount = sampleVOList.size() - templateSampleNum;
for (int m = 0; m < insertCount; m++) {
for (int i = 0; i < sampleMergerNum; i++) {
sheetOne.shiftRows(insertRow, sheetOne.getLastRowNum(), 1, true, false);
XSSFRow row = sheetOne.createRow(insertRow);
row.setHeight(zeroRow.getHeight());
for (int j = 0; j < lastCellNum; j++) {
XSSFCell xssfCell = row.createCell(j);
xssfCell.setCellStyle(cellStyle);
}
insertRow++;
}
}
int sn = 1;
for (EntrustSampleVO vo : sampleVOList) {
XSSFRow xssfRow = sheetOne.getRow(beginRow);
for (EntrustReportTemplateConfig config : configList) {
if (null != config.getSheetNum() && config.getSheetNum() != k) {
continue;
}
if (null == config.getColumnPlace()) {
continue;
}
XSSFCell cell = xssfRow.getCell(config.getColumnPlace());
if ("sn".equals(config.getDataAttribute())) {
cell.setCellValue(sn);
} else {
cell.setCellValue(StringHandleUtils.getFieldValue(config.getDataAttribute(), vo));
}
}
beginRow += sampleMergerNum;
sn++;
}
for (EntrustReportTemplateConfig config : configList) {
if (null == config.getMergeRowNum()) {
config.setMergeRowNum(1);
}
if (null == config.getMergeBegin()) {
continue;
}
if (null == config.getMergeEnd()) {
continue;
}
int step = config.getMergeRowNum();
if (step == 1 && config.getMergeEnd() == config.getMergeBegin()) {
continue;
}
if (null != config.getColumnPlace() && null != config.getMergeRowNum()) {
Integer sampleBgMum = sysFileTemplate.getSampleBeginRow() + templateSampleNum * sampleMergerNum;
Integer sampleEnMum = sysFileTemplate.getSampleBeginRow() + sampleVOList.size() * sampleMergerNum - 1;
while (sampleBgMum <= sampleEnMum) {
sheetOne.addMergedRegion(new CellRangeAddress(sampleBgMum, sampleBgMum + step - 1, config.getMergeBegin(), config.getMergeEnd()));
sampleBgMum = sampleBgMum + step;
}
}
}
}
}
}
String generated = entrust.getCode();
FileOutputStream os = null;
File file = null;
try {
file = File.createTempFile(generated, ".xlsx");
os = new FileOutputStream(file);
xssfWorkbook.write(os);
os.flush();
uploadReportGenerateXlsx(entrust, sampleIds, account, sampleName, "报告生成", file);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
os.close();
xssfWorkbook.close();
io.close();
} catch (IOException e) {
e.printStackTrace();
}
FileUtils.deleteFiles(file);
}
}
private List<Long> getSampleIds(Long[] reportIds) {
List<EntrustSample> entrustSampleList = entrustSampleService.getByReportIds(reportIds);
return CollectionUtils.isEmpty(entrustSampleList) ? null : entrustSampleList.stream().map(EntrustSample::getId).collect(Collectors.toList());
......
package com.patzn.cloud.service.lims.hmhj.service.impl;
import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.toolkit.CollectionUtils;
import com.patzn.cloud.commons.api.RestAssert;
import com.patzn.cloud.commons.controller.Account;
import com.patzn.cloud.commons.service.impl.BaseServiceImpl;
import com.patzn.cloud.oss.starter.OssClient;
import com.patzn.cloud.oss.starter.OssFileResult;
import com.patzn.cloud.service.hmhj.entity.EntrustReportTemplate;
import com.patzn.cloud.service.lims.hmhj.mapper.EntrustReportTemplateMapper;
import com.patzn.cloud.service.lims.hmhj.service.IEntrustReportTemplateService;
import com.patzn.cloud.commons.service.impl.BaseServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.web.multipart.MultipartFile;
import java.util.Date;
......@@ -76,4 +78,10 @@ public class EntrustReportTemplateServiceImpl extends BaseServiceImpl<EntrustRep
entrustReportTemplate.setLid(account.getUserId()).setLtime(new Date());
return baseMapper.updateTemplateById(entrustReportTemplate);
}
@Override
public EntrustReportTemplate getByClassType(String classType) {
List<EntrustReportTemplate> list = list(Condition.create().eq("class_type", classType));
return CollectionUtils.isEmpty(list) ? null : list.get(0);
}
}
......@@ -975,7 +975,17 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
RestAssert.fail(null == ids || ids.length == 0, "样品编号不能为空");
// ==
List<EntrustSampleVO> sampleList = entrustSampleService.getVOListByIds(Arrays.asList(ids));
RestAssert.fail(CollectionUtils.isEmpty(sampleList), "样品信息不能为空");
Long entrustId = sampleList.get(0).getEntrustId();
EntrustSampleVO voEntity = new EntrustSampleVO();
voEntity.setEntrustId(entrustId).setType(2);
List<EntrustSampleVO> batchSampleList = entrustSampleService.selectVOLists(voEntity);
if (CollectionUtils.isNotEmpty(batchSampleList)) {
sampleList.addAll(batchSampleList);
}
//其他稀有元素
List<String> otherYsList = Arrays.asList("Mn", "V", "Ni");
......@@ -1125,7 +1135,10 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
if (updateSampleList.size() > 0) {
entrustSampleService.updateBatchById(updateSampleList);
}
handleSampleBrand(ids);
// 处理正常的报告文件
handleSampleBrand(ids, false);
// 处理一级编码的报告文件
handleSampleBrand(ids, true);
return true;
}
......@@ -1137,6 +1150,21 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
return baseMapper.listIndexReplaceItemBySampleId(sampleId);
}
@Override
public List<EntrustSampleItemIndexVO> getItemTestByEntrustId(Long entrustId) {
if (null == entrustId) return null;
return baseMapper.selectItemTestByEntrustId(entrustId);
}
@Override
public EntrustSampleItem getItemModelBySampleId(Long sampleId) {
if (null == sampleId) {
return null;
}
List<EntrustSampleItem> itemList = list(Condition.create().eq("entrust_sample_id", sampleId));
return CollectionUtils.isNotEmpty(itemList) ? itemList.get(0) : null;
}
private String getCellValue(XSSFRow xssfRow, int cellIndex) {
XSSFCell cell = xssfRow.getCell(cellIndex);
String value = HSSFWorkbookUtil.getJavaValue(cell).toString();
......@@ -1148,7 +1176,7 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
*
* @param ids
*/
private void handleSampleBrand(Long[] ids) {
private void handleSampleBrand(Long[] ids, Boolean isOther) {
if (null == ids || 0 == ids.length) {
return;
}
......@@ -1157,16 +1185,27 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
if (CollectionUtils.isEmpty(reportSampleList)) {
return;
}
Boolean finalIsOther = null != isOther && isOther;
List<EntrustReport> reportList = new ArrayList<>();
// objectKey data
Map<String, Long> objReportMap = reportSampleList.stream().collect(Collectors.toMap(ReportSampleVO::getObjectKey, ReportSampleVO::getReportId, (v1, v2) -> v1));
Map<String, Long> objReportMap = reportSampleList.stream().collect(Collectors.toMap(t -> {
return finalIsOther ? t.getOtherObjectKey() : t.getObjectKey();
}, ReportSampleVO::getReportId, (v1, v2) -> v1));
for (Map.Entry<String, Long> entry : objReportMap.entrySet()) {
EntrustReport entrustReport = new EntrustReport();
String objectKey = entry.getKey();
Long reportId = entry.getValue();
entrustReport.setId(reportId);
Map<String, String> sampleMap = reportSampleList.stream().filter(t -> t.getObjectKey().equals(objectKey)).collect(Collectors.toMap(ReportSampleVO::getSampleCode, ReportSampleVO::getSampleGrading));
Map<String, String> sampleMap = reportSampleList.stream().filter(t -> t.getObjectKey().equals(objectKey)).collect(Collectors.toMap(t -> {
return finalIsOther ? t.getFirstCode() : t.getSampleCode();
}, ReportSampleVO::getSampleGrading));
if (StringUtils.isBlank(objectKey)) {
continue;
}
InputStream io = ossClient.download(objectKey);
//结果回调
......@@ -1227,7 +1266,11 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
os.flush();
OssFileResult fileResult = ossClient.upload(file);
if (null != fileResult) {
entrustReport.setObjectKey(fileResult.getObjectKey());
if (finalIsOther) {
entrustReport.setOtherObjectKey(fileResult.getObjectKey());
} else {
entrustReport.setObjectKey(fileResult.getObjectKey());
}
reportList.add(entrustReport);
}
} catch (Exception e) {
......
......@@ -40,10 +40,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
......@@ -1948,4 +1946,196 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
return false;
}
@Override
public Page<EntrustSampleIndexVO> getPageSampleIndex(Page<EntrustSampleIndexVO> page, EntrustSampleIndexVO sampleIndexVO) {
return page.setRecords(baseMapper.selectSampleIndex(page, sampleIndexVO));
}
@Override
public void exportSampleIndex(Long entrustId, Account account, HttpServletResponse response) {
RestAssert.fail(null == entrustId, "请选择要导出的委托");
Entrust entrust = entrustService.getById(entrustId);
// 批样
List<EntrustSample> sampleList = list(Condition.create().eq("entrust_id", entrustId).eq("type", 2));
RestAssert.fail(CollectionUtils.isEmpty(sampleList), "批样数据为空");
List<EntrustSampleVO> sampleVOList = sampleList.stream().map(t -> {
EntrustSampleVO vo = new EntrustSampleVO();
BeanUtils.copyProperties(t, vo);
vo.setIndexList(entrustSampleItemIndexService.listBySampleId(t.getId()));
return vo;
}).collect(Collectors.toList());
String sampleName = "铝成品";
EntrustReportTemplate template = entrustReportTemplateService.getByClassType(sampleName);
RestAssert.fail(null == template || com.baomidou.mybatisplus.toolkit.StringUtils.isEmpty(template.getObjectKey()), "报告模板不存在,无法生成批报告");
InputStream io = ossClient.download(template.getObjectKey());
XSSFWorkbook xssfWorkbook = null;
try {
xssfWorkbook = new XSSFWorkbook(io);
} catch (IOException e) {
e.printStackTrace();
}
List<EntrustReportTemplateConfig> configList = entrustReportTemplateConfigService.list(Condition.create().eq("template_id", template.getId()));
OriginalUtil.doReplace(xssfWorkbook, entrust);
Map<String, String> mapReplace = new HashMap<>();
mapReplace.put("#{nowDate}", DateUtils.toYearMonthDay(new Date()));
mapReplace.put("#{sampleNum}", sampleVOList.size() + "");
mapReplace.put("#{sampleFrom}", sampleVOList.size() > 0 ? sampleVOList.get(0).getSampleFrom() : " - ");
mapReplace.put("#{sampleName}", sampleVOList.get(0).getName());
int numberOfSheets = xssfWorkbook.getNumberOfSheets();
for (int k = 0; k < numberOfSheets; k++) {
HSSFWorkbookUtil.replaceModel(mapReplace, xssfWorkbook, k);
XSSFSheet sheetOne = xssfWorkbook.getSheetAt(k);
String sheetName = sheetOne.getSheetName();
System.out.println(sheetName);
sheetOne.setForceFormulaRecalculation(true);
int sampleMergerNum = template.getSampleMergerNum();
int templateSampleNum = template.getTemplateSampleNum();
if (templateSampleNum >= sampleVOList.size()) {
Integer beginRow = template.getSampleBeginRow();
for (EntrustSampleVO vo : sampleVOList) {
XSSFRow xssfRow = sheetOne.getRow(beginRow);
for (EntrustReportTemplateConfig config : configList) {
if (null != config.getSheetNum() && config.getSheetNum() != k) {
continue;
}
if (null == config.getColumnPlace()) {
continue;
}
XSSFCell cell = xssfRow.getCell(config.getColumnPlace());
if ("sn".equals(config.getDataAttribute())) {
continue;
}
if (org.apache.commons.lang3.StringUtils.isBlank(config.getDataAttribute())) {
continue;
}
String value = StringHandleUtils.getFieldValue(config.getDataAttribute(), vo);
cell.setCellValue(value);
}
beginRow += sampleMergerNum;
}
} else {
if (null != template.getMoreSheet() && template.getMoreSheet() == 1) {
int total = sampleVOList.size();
int totalSheetSize = (total + templateSampleNum - 1) / templateSampleNum;
List<List<EntrustSampleVO>> listList = Lists.partition(sampleVOList, templateSampleNum);
for (int i = 1; i < totalSheetSize; i++) {
xssfWorkbook.cloneSheet(0, sheetOne.getSheetName() + (i + 1));
}
for (int m = 0; m < listList.size(); m++) {
Integer beginRow = template.getSampleBeginRow();
List<EntrustSampleVO> sampleVOListIndex = listList.get(k);
for (EntrustSampleVO vo : sampleVOListIndex) {
XSSFSheet sheetOneIndex = xssfWorkbook.getSheetAt(k);
XSSFRow xssfRow = sheetOneIndex.getRow(beginRow);
for (EntrustReportTemplateConfig config : configList) {
XSSFCell cell = xssfRow.getCell(config.getColumnPlace());
if ("sn".equals(config.getDataAttribute())) {
continue;
}
if (org.apache.commons.lang3.StringUtils.isBlank(config.getDataAttribute())) {
continue;
}
String value = StringHandleUtils.getFieldValue(config.getDataAttribute(), vo);
cell.setCellValue(value);
}
beginRow += sampleMergerNum;
}
}
} else {
Integer beginRow = template.getSampleBeginRow();
int insertRow = beginRow + sampleMergerNum * templateSampleNum;
XSSFRow zeroRow = sheetOne.getRow(beginRow);
XSSFCellStyle cellStyle = zeroRow.getCell(0).getCellStyle();
int lastCellNum = zeroRow.getLastCellNum();
int insertCount = sampleVOList.size() - templateSampleNum;
for (int m = 0; m < insertCount; m++) {
for (int i = 0; i < sampleMergerNum; i++) {
sheetOne.shiftRows(insertRow, sheetOne.getLastRowNum(), 1, true, false);
XSSFRow row = sheetOne.createRow(insertRow);
row.setHeight(zeroRow.getHeight());
for (int j = 0; j < lastCellNum; j++) {
XSSFCell xssfCell = row.createCell(j);
xssfCell.setCellStyle(cellStyle);
}
insertRow++;
}
}
int sn = 1;
for (EntrustSampleVO vo : sampleVOList) {
XSSFRow xssfRow = sheetOne.getRow(beginRow);
for (EntrustReportTemplateConfig config : configList) {
if (null != config.getSheetNum() && config.getSheetNum() != k) {
continue;
}
if (null == config.getColumnPlace()) {
continue;
}
XSSFCell cell = xssfRow.getCell(config.getColumnPlace());
if ("sn".equals(config.getDataAttribute())) {
cell.setCellValue(sn);
} else {
cell.setCellValue(StringHandleUtils.getFieldValue(config.getDataAttribute(), vo));
}
}
beginRow += sampleMergerNum;
sn++;
}
for (EntrustReportTemplateConfig config : configList) {
if (null == config.getMergeRowNum()) {
config.setMergeRowNum(1);
}
if (null == config.getMergeBegin()) {
continue;
}
if (null == config.getMergeEnd()) {
continue;
}
int step = config.getMergeRowNum();
if (step == 1 && config.getMergeEnd() == config.getMergeBegin()) {
continue;
}
if (null != config.getColumnPlace() && null != config.getMergeRowNum()) {
Integer sampleBgMum = template.getSampleBeginRow() + templateSampleNum * sampleMergerNum;
Integer sampleEnMum = template.getSampleBeginRow() + sampleVOList.size() * sampleMergerNum - 1;
while (sampleBgMum <= sampleEnMum) {
sheetOne.addMergedRegion(new CellRangeAddress(sampleBgMum, sampleBgMum + step - 1, config.getMergeBegin(), config.getMergeEnd()));
sampleBgMum = sampleBgMum + step;
}
}
}
}
}
}
String generated = entrust.getCode();
FileOutputStream os = null;
File file = null;
try {
file = File.createTempFile(generated, ".xlsx");
os = new FileOutputStream(file);
xssfWorkbook.write(os);
InputStream is = new FileInputStream(file);
FileUtils.download(is, file.getName(), response);
} catch (IOException e) {
logger.error("导出批样时异常", e);
} finally {
FileUtils.deleteFiles(file);
}
}
}
\ No newline at end of file
......@@ -110,6 +110,12 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
@Autowired
private OssClient ossClient;
@Autowired
private IIdentifierService identifierService;
@Autowired
private IMaterialService materialService;
@Override
public Page<Entrust> page(Page<Entrust> page, Entrust entrust) {
......@@ -151,7 +157,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
}
public void initSampleCode(EntrustSample sample) {
public void initSampleCode(Entrust entrust, EntrustSample sample) {
// 如果合同编号不为空,样品编号不为空,一级编号不为空,则不进行编号生成
if (null != sample.getContractSampleId() && StringUtils.isNotBlank(sample.getCode()) && StringUtils.isNotBlank(sample.getFirstCode())) {
......@@ -234,7 +240,12 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
else if (CodeTypeEnum.SAMPLE_YFL_CODE == codeType) {
sampleCode = phase + sampleCode.substring(1);
secondCode = sampleCode.replace("A", "B").replace(replaceStr, inspectNo);
thirdCode = sampleCode.replace("A", "C").replace(replaceStr, "HY");
// 进场物资,使用针对进场物资的生成规则
if (1 == entrust.getType()) {
thirdCode = getSampleThirdCode(sample);
} else {
thirdCode = sampleCode.replace("A", "C").replace(replaceStr, "HY");
}
sampleCode = sampleCode.replace(replaceStr, inspectNo);
}
// 原铝散样样品编号处理
......@@ -307,19 +318,37 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
/**
* 样品编号处理
*/
private void handleSampleCode(EntrustSample sample) {
private void handleSampleCode(Entrust entrust, EntrustSample sample) {
String sampleCode = sample.getCode();
if (isExistSampleCode(sample) && StringUtils.isBlank(sampleCode)) {
throw new PatznException("样品编号为空");
}
// 非已有编码物质为空时,需要生成样品编号
// 生成样品编号
initSampleCode(sample);
initSampleCode(entrust, sample);
if (StringUtils.isNotBlank(sampleCode)) {
sample.setCode(sampleCode);
}
}
private String getSampleThirdCode(EntrustSample sample) {
RestAssert.fail(null == sample.getMaterialId(), "样品库-物资ID为空");
Material material = materialService.getById(sample.getMaterialId());
RestAssert.fail(null == material, "样品库-物资为空");
String factoryArea = material.getFactoryArea(), abbr = material.getAbbr();
RestAssert.fail(StringUtils.isBlank(factoryArea), "样品库-物资厂区为空");
RestAssert.fail(StringUtils.isBlank(abbr), "样品库-物资简写为空");
String type = "";
// type 处理
if (factoryArea.contains("二三期")) {
String period = userInfoService.getUserPeriod(LoginHelper.getAccount());
type = HmConst.SECOND_PERIOD.equals(period) ? "A" : "B";
}
type = type + (abbr.length() > 2 ? abbr : abbr + "0");
String code = identifierService.getNextSN(type.toUpperCase());
return code;
}
@Transactional(rollbackFor = Exception.class)
@Override
public boolean saveEntrustDTO(EntrustDTO dto, Account account) {
......@@ -361,7 +390,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
}
EntrustSample sample = sampleDTO.convert(EntrustSample.class);
sample.setEntrustId(entrust.getId());
handleSampleCode(sample);
handleSampleCode(entrust, sample);
judgeSampleFields(sample, true);
sample.setId(IdWorker.getId());
sample.setOrderBy(incNum);
......@@ -574,7 +603,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
updateSampleList.add(sample);
} else {
sample.setEntrustId(entrust.getId());
handleSampleCode(sample);
handleSampleCode(entrust, sample);
sample.setId(IdWorker.getId());
saveSampleList.add(sample);
}
......@@ -1071,7 +1100,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
sample.setId(IdWorker.getId());
sample.setCode(null);
//生成样品编号,可能存在为空的情况
initSampleCode(sample);
initSampleCode(entrust, sample);
// 样品编号问题,手填的样品编号不清空
if (StringUtils.isBlank(sample.getCode())) {
sample.setCode(sampleCode);
......@@ -1561,4 +1590,9 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
}
return submitToNextFlow(new Long[]{entrustDTO.getId()}, account);
}
@Override
public Page<EntrustVO> getPageReportProduct(Page<EntrustVO> page, EntrustVO entrust) {
return page.setRecords(baseMapper.selectVOList(page, entrust));
}
}
package com.patzn.cloud.service.lims.hmhj.service.impl;
import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.patzn.cloud.commons.api.RestAssert;
import com.patzn.cloud.commons.constant.CommonConstants;
import com.patzn.cloud.commons.exception.PatznException;
import com.patzn.cloud.commons.service.impl.BaseServiceImpl;
import com.patzn.cloud.commons.toolkit.FreemarkerUtils;
import com.patzn.cloud.service.hmhj.entity.Identifier;
import com.patzn.cloud.service.lims.common.StringHandleUtils;
import com.patzn.cloud.service.lims.hmhj.mapper.IdentifierMapper;
import com.patzn.cloud.service.lims.hmhj.service.IIdentifierService;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 服务实现类
*
* @author meazty
* @since 2021-10-09
*/
@Service
public class IdentifierServiceImpl extends BaseServiceImpl<IdentifierMapper, Identifier> implements IIdentifierService {
@Override
public Page<Identifier> page(Page<Identifier> page, Identifier identifier) {
Wrapper wrapper = new EntityWrapper<>(identifier);
return this.page(page, wrapper);
}
@Override
public boolean removeByIds(List<Long> ids) {
return baseMapper.deleteBatchIds(ids) > 0;
}
@Transactional(rollbackFor = Exception.class)
@Override
public String getNextSN(String type) {
if (StringUtils.isBlank(type)) {
throw new PatznException("编号类型不能为空");
}
Identifier identifier = super.getOne(Condition.create().eq("type", type).last("LIMIT 1"));
if (null == identifier) {
throw new PatznException("请配置编号规则");
}
StringBuilder key = new StringBuilder();
// 前缀规则
if (null != identifier.getPrefix()) {
key.append(identifier.getPrefix());
}
String[] rules = identifier.getRule().split("&");
Map<String, Object> model = new HashMap<>(2);
for (String rule : rules) {
// 日期规则
if (rule.contains("@")) {
if ("@YY".equalsIgnoreCase(rule)) {
key.append(new DateTime().toString("YYYY").substring(2));
} else {
key.append(new DateTime().toString(rule.substring(1)));
}
} else if (rule.contains("%")) {
String myRules = rule.replace("%", "").replace("{", "").replace("}", "");
String[] dictArr = myRules.split("\\.");
if (null != dictArr[1]) {
key.append(StringHandleUtils.getFieldValueByFieldName(dictArr[1], model.get("et")));
}
}
// 属性规则
else if (rule.contains("$")) {
try {
key.append(FreemarkerUtils.process(rule, model));
} catch (Exception e) {
RestAssert.fail("编号生成异常,请联系管理员");
}
}
// SN 序列号
else if ("SN".equals(rule)) {
key.append(CommonConstants.SN);
}
// 原样输出
else {
key.append(rule);
}
}
// 更新SN,限定长度最高9位
String sn = "";
StringBuilder sb = new StringBuilder("0");
int snInt = null == identifier.getSn() ? 0 : identifier.getSn(),
lens = null == identifier.getLength() ? 1 : identifier.getLength();
while (sb.length() < lens) {
sb.append("0");
}
String defZero = sb.toString();
sn = defZero.substring(0, defZero.length() - Integer.toString(snInt).length());
snInt += 1;
if (Integer.toString(snInt).length() > lens) {
identifier.setLength(++lens);
}
identifier.setSn(snInt);
updateById(identifier);
return key.toString().replaceAll(CommonConstants.SN, sn);
}
}
......@@ -50,7 +50,7 @@ spring:
data:
mongodb:
# uri: mongodb://hmuser:hj564Aq@meazty.fun:27017/lims
uri: mongodb://mongo:mong123@meazty.fun:27017/lims
uri: mongodb://mongo:Mong$6358#@meazty.fun:27017/lims
grid-fs-database: lims
# Mongodb GridFS 存储
......
......@@ -129,13 +129,19 @@
with sample as (
SELECT
s.company_id,s.entrust_id,max(s.sample_from) "sample_from"
from entrust_sample s where s.deleted = 0 and s.type = 0
from entrust_sample s where s.deleted = 0
<if test="null != vo.sampleStatus">
and s.status = #{vo.sampleStatus}
</if>
<if test="null != vo.judgeStatus">
and s.judge_status = #{vo.judgeStatus}
</if>
<if test="null == vo.sampleType">
and s.type = 0
</if>
<if test="null != vo.sampleType">
and s.type = #{vo.sampleType}
</if>
<if test="null != vo.judgeStatusList">
and s.judge_status IN
<foreach collection="vo.judgeStatusList" index="index" item="judgeStatus" open="(" separator="," close=")">
......
......@@ -704,6 +704,27 @@
AND s.deleted = 0
AND s.id = #{sampleId}
</select>
<!--查询样品下分批中最大的检测值信息-->
<select id="selectItemTestByEntrustId" resultType="com.patzn.cloud.service.hmhj.vo.EntrustSampleItemIndexVO">
SELECT
s.entrust_id,
split_part( s.code, '-', 1 ) "sample_code",
ii.NAME ,
MAX ( ii.test_value :: NUMERIC ) "test_value"
FROM
entrust_sample_item_index ii
JOIN entrust_sample_item i ON i.ID = ii.entrust_sample_item_id
JOIN entrust_sample s ON s.ID = i.entrust_sample_id
WHERE
ii.deleted = 0
AND is_numeric ( ii.test_value )
AND s.NAME = '铝成品'
AND s.entrust_id = #{entrustId}
GROUP BY
s.entrust_id,
split_part( s.code, '-', 1 ),
ii.NAME
</select>
<update id="updateBatchByData" parameterType="java.util.List">
<foreach collection="itemList" item="item" index="index" open="" close="" separator=";">
......
......@@ -432,10 +432,14 @@
distinct
r.entrust_id,
r.object_key,
r.other_object_key,
rs.report_id,
rs.sample_id,
s.code "sample_code",
s.name "sample_name",
s.first_code,
s.second_code,
s.third_code,
s.sample_grading
from entrust_report r
join entrust_report_rel_sample rs on rs.report_id = r.id
......@@ -451,6 +455,50 @@
select max(s.code) "max_code" from entrust_sample s where s.deleted = 0 and s.code like concat(#{queryKey},'%')
</select>
<!-- 查询样品指标 -->
<select id="selectSampleIndex" resultType="com.patzn.cloud.service.hmhj.vo.EntrustSampleIndexVO">
SELECT
s.entrust_id,
s.code "sample_code",
s.NAME "sample_name",
s.sample_grading "brand",
i.*
FROM
(
SELECT
i.entrust_sample_id,
MAX ( CASE WHEN ii.NAME = '原铝Cu' THEN ii.test_value ELSE '' END ) "cu",
MAX ( CASE WHEN ii.NAME = '原铝Fe' THEN ii.test_value ELSE '' END ) "fe",
MAX ( CASE WHEN ii.NAME = '原铝Ga' THEN ii.test_value ELSE '' END ) "ga",
MAX ( CASE WHEN ii.NAME = '原铝Mg' THEN ii.test_value ELSE '' END ) "mg",
MAX ( CASE WHEN ii.NAME = '原铝Mn' THEN ii.test_value ELSE '' END ) "mn",
MAX ( CASE WHEN ii.NAME = '原铝Ni' THEN ii.test_value ELSE '' END ) "ni",
MAX ( CASE WHEN ii.NAME = '原铝Si' THEN ii.test_value ELSE '' END ) "si",
MAX ( CASE WHEN ii.NAME = '原铝V' THEN ii.test_value ELSE '' END ) "v",
MAX ( CASE WHEN ii.NAME = '原铝Zn' THEN ii.test_value ELSE '' END ) "zn"
FROM
entrust_sample_item_index ii
JOIN entrust_sample_item i ON i.ID = ii.entrust_sample_item_id
WHERE
ii.deleted = 0 AND i.deleted = 0
GROUP BY
i.entrust_sample_id
) i
JOIN entrust_sample s ON s.ID = i.entrust_sample_id
WHERE
s.NAME = '铝成品' AND s.TYPE = 2
<if test="null != vo.entrustId">
AND s.entrust_id = #{vo.entrustId}
</if>
<if test="null != vo.sampleCode">
AND s.code like concat('%',#{vo.sampleCode},'%')
</if>
<if test="null != vo.sampleName">
AND s.name like concat('%',#{vo.sampleName},'%')
</if>
</select>
<update id="updateBatchByData" parameterType="java.util.List">
<foreach collection="sampleList" item="item" index="index" open="" close="" separator=";">
update entrust_sample
......
package com.patzn.cloud.service.lims.test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class TestThreadLocal {
public static ExecutorService executorService = Executors.newFixedThreadPool(16);
private static SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static void main(String[] args) throws InterruptedException {
for (int i=0;i<1000;i++){
executorService.submit(new Runnable() {
@Override
public void run() {
String format = simpleDateFormat.format(new Date());
try {
Date parse = simpleDateFormat.parse("2021-09-01 00:00:00");
} catch (ParseException e) {
e.printStackTrace();
}
System.out.println(format);
}
});
}
Thread.sleep(3000);
executorService.shutdownNow();
}
}
/** created by meazty on 2021/10/8 15:50 **/
/** created by meazty on 2021/10/8 15:50 **/
ALTER TABLE "public"."material"
ADD COLUMN "factory_area" varchar(64) COLLATE "pg_catalog"."default",
ADD COLUMN "abbr" varchar(64) COLLATE "pg_catalog"."default";
COMMENT ON COLUMN "public"."material"."factory_area" IS '厂区';
COMMENT ON COLUMN "public"."material"."abbr" IS '缩写';
ALTER TABLE "public"."entrust_report"
ADD COLUMN "other_object_key" varchar(64) COLLATE "pg_catalog"."default",
ADD COLUMN "other_pdf_object_key" varchar(64) COLLATE "pg_catalog"."default";
COMMENT ON COLUMN "public"."entrust_report"."other_object_key" IS '其他对象Key';
COMMENT ON COLUMN "public"."entrust_report"."other_pdf_object_key" IS '其他对象PdfKey';
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