package com.ann.demo.service.impl;

import com.ann.demo.entity.filing.ArchiveDetail;
import com.ann.demo.entity.filing.dto.MessageDto;
import com.ann.demo.entity.interfaceEntity.ArchiveMaster;
import com.ann.demo.repository.ArchiveDetailRepository;
import com.ann.demo.repository.ArchiveMasterRepository;
import com.ann.demo.service.ArchiveDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: LeiJiaXin
 * @Date: 2019/9/4 10:05
 */
@Service
public class ArchiveDetailServiceImpl implements ArchiveDetailService {

    @Autowired
    ArchiveDetailRepository archiveDetailRepository;

    @Autowired
    ArchiveMasterRepository archiveMasterRepository;


    @Override
    public String updateFlag(String applyId) {
        // 如果为null 说明新增 如果不为空 那么 更改删除都是作废
        String id = archiveDetailRepository.findIdByApplyId(applyId);
        if (id != null) {
            Integer result = archiveDetailRepository.updateFlag(id);
            if (result > 1) {
                return null;
            } else {
                return "病历清单更新/删除失败。。。";
            }
        } else {
            return "applyId不存在。。。。";
        }
    }

    @Override
    public ArchiveDetail isExit(String id, String type, String source, String applyId) {
        if (archiveDetailRepository.countByMasterIDAndAssortIDAndSourceAndApplyId(id, type, source, applyId) > 0)
            return archiveDetailRepository.findByMasterIDAndAssortIDAndSourceAndApplyIdAndFlag(id, type, source, applyId,"0");
        return null;
    }

    @Override
    public boolean delete(String id) {
        if(archiveDetailRepository.updateFlagById(id) > 0)
            return true;
        return false;
    }
}
