package com.zt.plat.module.qms.business.bus.controller.vo;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;

import cn.hutool.core.collection.CollUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
public class BusinessSubSampleExtendRespVO extends BusinessSubSampleRespVO {
	
	/** 子样类型名称 **/
	@Schema(description = "子样类型名称")
	private String dictionaryBusinessName;
	
	@Schema(description = "分析任务数")
	private Integer assayTaskCount;
	
	@Schema(description = "子样检测方法")
	private List<BusinessAssayTaskDataExtendRespVO> businessAssayTaskDataList;
	
	@Schema(description = "分析班组")
	private List<BusinessSubSampleAnalysisGroupRespVO> businessSubSampleAnalysisGroupList;
	
	@Schema(description = "样品去向")
	private String sampleDestination;
	
	public String getSampleDestination() {
		String _sampleDestination = null;
		if (CollUtil.isNotEmpty(this.businessSubSampleAnalysisGroupList)) {
			List<String> collect = this.businessSubSampleAnalysisGroupList.stream().filter(f -> f.getSampleStatus().equals("待收样")).map(m -> m.getAssayDepartmentName()).collect(Collectors.toList());
			_sampleDestination = CollUtil.join(collect, ",");
		}
		if (StringUtils.isBlank(_sampleDestination)) {//所有分析班组已完成，去向显示为库名
			_sampleDestination = this.getWarehouseName();
		}
		return _sampleDestination;
	}
	
	@Schema(description = "样品所在位置")
	private String sampleLocation;
	
	public String getSampleLocation() {
		this.sampleLocation = null;
		if (CollUtil.isNotEmpty(this.businessSubSampleAnalysisGroupList)) {
			List<String> collect = this.businessSubSampleAnalysisGroupList.stream().filter(f -> f.getSampleStatus().equals("已收样")).map(m -> m.getAssayDepartmentName()).collect(Collectors.toList());
			this.sampleLocation = CollUtil.join(collect, ",");
		}
		return this.sampleLocation;
	} 
	
	@Schema(description = "分析部门id")
    private Long assayDepartmentId;
	
	@Schema(description = "分析部门名称")
    private String assayDepartmentName;
	
	@Schema(description = "是否已送样")
	private Integer isSendSample;

    @Schema(description = "是否打印")
    private Integer isPrint;

    @Schema(description = "样品标签打印模版")
    private String printTemplate;
    
    @Schema(description = "样品标签打印份数")
    private Integer codePrintQuantity;
	
    @Schema(description = "收样人")
    private String sampleReceiver;
    
    @Schema(description = "分析项目")
    private String assayProject;

    @JsonSerialize(using = LocalDateTimeSerializer.class) // 序列化（响应）
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "收样时间")
    private LocalDateTime sampleReceiveTime;

	@Schema(description = "库位编码")
	private String warehouseLocationCode;

	@Schema(description = "仓库名称")
	private String warehouseName;
}
