@ -1,7 +1,10 @@
package digital.laboratory.platform.entrustment.service.impl ;
import cn.hutool.core.collection.CollUtil ;
import cn.hutool.core.util.StrUtil ;
import com.baomidou.mybatisplus.core.metadata.IPage ;
import com.baomidou.mybatisplus.core.toolkit.Wrappers ;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page ;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl ;
import digital.laboratory.platform.common.core.exception.CheckedException ;
import digital.laboratory.platform.entrustment.convert.DrugLiteConvert ;
@ -13,14 +16,17 @@ import digital.laboratory.platform.entrustment.entity.Entrustment;
import digital.laboratory.platform.entrustment.entity.EntrustmentIdentificationMaterial ;
import digital.laboratory.platform.entrustment.enums.EntrustmentStatusConstants ;
import digital.laboratory.platform.entrustment.mapper.EntrustMaterialCheckoutResultMapper ;
import digital.laboratory.platform.entrustment.query.EntrustMaterialCheckoutResultQuery ;
import digital.laboratory.platform.entrustment.service.CommonFeignService ;
import digital.laboratory.platform.entrustment.service.EntrustMaterialCheckoutResultService ;
import digital.laboratory.platform.entrustment.service.EntrustmentIdentificationMaterialService ;
import digital.laboratory.platform.entrustment.service.EntrustmentService ;
import digital.laboratory.platform.entrustment.vo.EntrustMaterialCheckoutResultVO ;
import digital.laboratory.platform.sys.entity.Area ;
import digital.laboratory.platform.sys.entity.DrugLite ;
import org.apache.poi.ss.usermodel.* ;
import org.apache.poi.xssf.usermodel.XSSFWorkbook ;
import org.springframework.beans.BeanUtils ;
import org.springframework.stereotype.Service ;
import javax.annotation.Resource ;
@ -29,10 +35,7 @@ import java.io.IOException;
import java.net.URLEncoder ;
import java.time.LocalDateTime ;
import java.time.format.DateTimeFormatter ;
import java.util.ArrayList ;
import java.util.Collections ;
import java.util.List ;
import java.util.Map ;
import java.util.* ;
import java.util.function.Function ;
import java.util.stream.Collectors ;
@ -54,6 +57,40 @@ public class EntrustMaterialCheckoutResultServiceImpl extends ServiceImpl<Entrus
@Resource
private CommonFeignService commonFeignService ;
/ * *
* 构建委托材料检验结果字符串
*
* @param entrustId 委托ID
* @return 委托材料检验结果字符串
* /
@Override
public String buildEntrustMaterialCheckoutResultStr ( String entrustId ) {
// 先获取检材列表
List < EntrustmentIdentificationMaterial > materialList = entrustmentIdentificationMaterialService . list ( Wrappers . < EntrustmentIdentificationMaterial > lambdaQuery ( ) . eq ( EntrustmentIdentificationMaterial : : getEntrustmentId , entrustId ) ) ;
Map < String , EntrustmentIdentificationMaterial > materialMap = materialList . stream ( ) . collect ( Collectors . toMap ( EntrustmentIdentificationMaterial : : getId , Function . identity ( ) ) ) ;
// 获取检测结果
List < EntrustMaterialCheckoutResult > checkoutResultList = super . list ( Wrappers . < EntrustMaterialCheckoutResult > lambdaQuery ( ) . eq ( EntrustMaterialCheckoutResult : : getEntrustId , entrustId ) ) ;
if ( CollUtil . isEmpty ( checkoutResultList ) ) {
return "" ;
}
List < String > resultStrList = new ArrayList < > ( ) ;
// 对检测结果进行分组
Map < String , List < EntrustMaterialCheckoutResult > > checkoutResultGroupMap = checkoutResultList . stream ( ) . collect ( Collectors . groupingBy ( item - > DrugLiteConvert . joiningDrugListNameToStr ( item . getQualitativeResult ( ) , "、" ) ) ) ;
checkoutResultGroupMap . forEach ( ( key , value ) - > {
StringBuilder builder = new StringBuilder ( ) ;
builder
. append ( value . stream ( ) . map ( item - > materialMap . get ( item . getId ( ) ) . getOrderNo1 ( ) ) . collect ( Collectors . joining ( "、" ) ) )
. append ( " : [" )
. append ( key )
. append ( "]" ) ;
resultStrList . add ( builder . toString ( ) ) ;
} ) ;
return resultStrList . stream ( ) . sorted ( ) . collect ( Collectors . joining ( "\n" ) ) ;
}
/ * *
* 根据DTO保存检材得检出结果信息
* @param dto 检出DTO
@ -79,6 +116,7 @@ public class EntrustMaterialCheckoutResultServiceImpl extends ServiceImpl<Entrus
}
EntrustMaterialCheckoutResult entrustMaterialCheckoutResult = EntrustMaterialCheckoutResultConvert . dtoToEntity ( dto ) ;
entrustMaterialCheckoutResult . setId ( id ) ;
entrustMaterialCheckoutResult . setEntrustId ( identificationMaterial . getEntrustmentId ( ) ) ;
if ( super . count ( Wrappers . < EntrustMaterialCheckoutResult > lambdaQuery ( ) . eq ( EntrustMaterialCheckoutResult : : getId , id ) ) < = 0 ) {
// throw new CheckedException(String.format("检材编号 [%s] 的检材检出结果已经存在!", identificationMaterial.getImNo()));
success = super . save ( entrustMaterialCheckoutResult ) ;
@ -143,6 +181,35 @@ public class EntrustMaterialCheckoutResultServiceImpl extends ServiceImpl<Entrus
buildExcel ( response , checkoutResultExcelDTOS ) ;
}
/ * *
* vo 分页对象
* @param query
* @return
* /
@Override
public IPage < EntrustMaterialCheckoutResultVO > voiPage ( EntrustMaterialCheckoutResultQuery query ) {
IPage < EntrustMaterialCheckoutResult > page = this . page (
new Page < > ( query . getCurrent ( ) , query . getSize ( ) ) ,
Wrappers . < EntrustMaterialCheckoutResult > lambdaQuery ( )
. eq ( StrUtil . isNotBlank ( query . getEntrustId ( ) ) , EntrustMaterialCheckoutResult : : getEntrustId , query . getEntrustId ( ) )
. orderByDesc ( EntrustMaterialCheckoutResult : : getUpdateTime )
) ;
IPage < EntrustMaterialCheckoutResultVO > voPage = new Page < > ( ) ;
BeanUtils . copyProperties ( page , voPage , "records" ) ;
List < EntrustMaterialCheckoutResult > records = page . getRecords ( ) ;
if ( CollUtil . isNotEmpty ( records ) ) {
List < EntrustmentIdentificationMaterial > entrustmentIdentificationMaterials = entrustmentIdentificationMaterialService . list ( Wrappers . < EntrustmentIdentificationMaterial > lambdaQuery ( ) . in ( EntrustmentIdentificationMaterial : : getId , records . stream ( ) . map ( EntrustMaterialCheckoutResult : : getId ) . collect ( Collectors . toSet ( ) ) ) ) ;
Map < String , EntrustmentIdentificationMaterial > materialMap = entrustmentIdentificationMaterials . stream ( ) . collect ( Collectors . toMap ( EntrustmentIdentificationMaterial : : getId , Function . identity ( ) ) ) ;
List < EntrustMaterialCheckoutResultVO > entrustMaterialCheckoutResultVOS = records . stream ( ) . map ( record - > {
EntrustMaterialCheckoutResultVO entrustMaterialCheckoutResultVO = EntrustMaterialCheckoutResultConvert . entityToVO ( record ) ;
entrustMaterialCheckoutResultVO . setName ( materialMap . get ( record . getId ( ) ) . getName ( ) ) ;
return entrustMaterialCheckoutResultVO ;
} ) . collect ( Collectors . toList ( ) ) ;
voPage . setRecords ( entrustMaterialCheckoutResultVOS ) ;
}
return voPage ;
}
/ * *
* 构建并输出Excel文件 。
*