package digital.laboratory.platform.entrustment.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import digital.laboratory.platform.common.core.util.R;
import digital.laboratory.platform.common.mybatis.security.service.DLPUser;
import digital.laboratory.platform.entrustment.dto.PrintDTO;
import digital.laboratory.platform.entrustment.entity.CaseEvidence;
import digital.laboratory.platform.entrustment.entity.EntrustmentIdentificationMaterial;
import digital.laboratory.platform.entrustment.vo.EntrustmentIdentificationMaterialVO;
import digital.laboratory.platform.entrustment.vo.SampleBoxVO;

import java.util.List;

/**
 * 检材信息服务类
 *
 * @author Zhang Xiaolong created at  2022-03-22
 * @describe 检材信息服务类
 */
public interface EntrustmentIdentificationMaterialService extends IService<EntrustmentIdentificationMaterial> {

    /**
     * ## 检材编码
     * ```
     * JC <物证编号后 28 位> <顺序号4位>
     * 例如:
     * JC 5201010400002020030002 0000001 0001
     * 合计 34 位
     * ```
     * 一份物证, 有可能会多次送检。每次送检的时候, 在原来的顺序号上递增。
     * 定义这个编号的时候有点纠结, 有两个方向的关联: 在案件号上扩充、在物证号上扩充。我们选择在物证号上扩充。
     * 检材编码的长度不一定刚好是 34 位！我们取“物证编号后 28 位”时, 其实是去掉物证编码前第1个字符后剩下的部分。
     * 如果物证编码不是 29 位, 那么取到的就不是 28 位, 而是物证编码长度减1位。
     *
     * @param evidenceNo
     * @return
     */
    String getNewIdentificationMaterialNo(String evidenceNo);

    /**
     * 创建新的检材
     * 根据参数中的物证生成新的检材, 新创建的检材将继承该物证的部分属性
     *
     * @param ce
     * @return
     */
    EntrustmentIdentificationMaterial createNewIdentificationMaterial(CaseEvidence ce);

    long countByEntrustmentId(String entrustmentId);

    List<EntrustmentIdentificationMaterialVO> getEntrustmentIdentificationMaterialVOList(QueryWrapper<EntrustmentIdentificationMaterial> qw);

    int setEntrustmentIdentificationMaterialStatusByEntrustment(EntrustmentIdentificationMaterial im, String EntrustmentId);

    //生成受理编号
    String getNewMaterialAcceptNo(String entrustAcceptNo);

    //同步已受理数据的时候，生成受理编号
    public String getThirdSysMaterialAcceptNo(String entrustAcceptNo);

    //生成案前委托的受理编号
    String getNewMaterialAcceptNoForBeforeCase(String entrustBeforeAcceptNo);

    //根据盒子ID 查询该盒子下的检材
    public List<EntrustmentIdentificationMaterial> getQueryListByBoxID(String boxId, String boxType);

    //根据盒子ID，分样类型，检材ID 删除分样信息
    Boolean delSampleBoxInfo(String boxId, String sampleNo, String boxType);

    //统计盒子中装了多少样本
    SampleBoxVO getBoxCountInfo(String boxId);

    //将样本装进盒子
    List<EntrustmentIdentificationMaterial> putSampleToBox(String boxId, List<String> sampleNoList, String boxType);

    //根据用户ID 获取用户
    String getUserNameByEntrustUserID(String userId);

    EntrustmentIdentificationMaterial bizCheck_Apply(EntrustmentIdentificationMaterial identificationMaterial, Integer opCode, DLPUser dlpUser);

    EntrustmentIdentificationMaterial bizApprove_Apply(EntrustmentIdentificationMaterial identificationMaterial, Integer opCode, DLPUser dlpUser);

    List<EntrustmentIdentificationMaterial> bizAccept_Save(List<EntrustmentIdentificationMaterial> materialList, DLPUser dlpUser);

    EntrustmentIdentificationMaterial bizAccept_Apply(EntrustmentIdentificationMaterial identificationMaterial, Integer opCode, DLPUser dlpUser);

    EntrustmentIdentificationMaterial createIdentificationMaterialByEvidenceId(EntrustmentIdentificationMaterial identificationMaterial, DLPUser dlpUser);

    EntrustmentIdentificationMaterial putUpdateById(EntrustmentIdentificationMaterial identificationMaterial, DLPUser dlpUser);

    void saveCollectors(EntrustmentIdentificationMaterial material, DLPUser dlpUser);

    EntrustmentIdentificationMaterial settingAcceptSampleInfoDivide(EntrustmentIdentificationMaterial material);

    //设置送检单位初始分样信息

    EntrustmentIdentificationMaterial settingProviderSampleInfo(EntrustmentIdentificationMaterial material);

    EntrustmentIdentificationMaterial settingAcceptSampleInfoNoDivide(EntrustmentIdentificationMaterial material);

    EntrustmentIdentificationMaterial deleteById(String id);

    boolean saveRepWeigh(EntrustmentIdentificationMaterial entrustmentIdentificationMaterial, double sample1RepeatWeigh, double sample2RepeatWeigh, boolean isUseBalance, String sampleFlag);

    EntrustmentIdentificationMaterial settingRetained(String id, int flag);

    List<EntrustmentIdentificationMaterial> createNewIm(List<EntrustmentIdentificationMaterial> identificationMaterial, DLPUser dlpUser);

    public List<String> printLabel(List<PrintDTO> printDTOList);

    List<String> printManyLabel(List<PrintDTO> printDTOList);

    String printMaterialArchives(String entrustmentId) throws Exception;

    void conformityDrugs(List<EntrustmentIdentificationMaterial> list);
}
