package com.dgt.graphdemo.service;

import com.dgt.graphdemo.entity.GraphDatilData;
import com.dgt.graphdemo.jpa.entity.BasicClaimnoEntity;
import com.dgt.graphdemo.jpa.entity.RiskTipEntity;
import com.dgt.graphdemo.jpa.entity.SimilarFactorEntity;
import com.dgt.graphdemo.jpa.entity.SimilarTypeClaimnoEntity;
import com.dgt.graphdemo.jpa.repo.BasicClaimnoRepo;
import com.dgt.graphdemo.jpa.repo.RiskTipRepo;
import com.dgt.graphdemo.jpa.repo.SimilarFactorRepo;
import com.dgt.graphdemo.jpa.repo.SimilarTypeClaimnoRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lugela
 * @Title: DatilFormGraphService
 * @ProjectName graphdemo
 * @Description: TODO
 * @date 2019/6/24 13:46
 */
@Service
public class DatilFormGraphService {
    //基本信息
    @Autowired
    BasicClaimnoRepo basicClaimnoRepo;
    @Autowired
    //风险信息
    RiskTipRepo riskTipRepo;
    //同类案件
    @Autowired
    SimilarTypeClaimnoRepo similarTypeClaimnoRepo;
    //关联同类案件
    @Autowired
    SimilarFactorRepo similarFactorRepo;
    public GraphDatilData getDatilGraph(String claimno){
        BasicClaimnoEntity basicClaimno = basicClaimnoRepo.findByClaimno(claimno);
        RiskTipEntity riskTip = riskTipRepo.findByClaimno(claimno);
        List<SimilarTypeClaimnoEntity> similarTypeClaimnos = similarTypeClaimnoRepo.findByClaimno(claimno);

        if (similarTypeClaimnos!=null&&!similarTypeClaimnos.isEmpty()){
            similarTypeClaimnos.forEach(similarTypeClaimno ->{
                List<SimilarFactorEntity> similarFactorList=null;
                if (similarTypeClaimno!=null ){
                    int id = similarTypeClaimno.getId();
                    similarFactorList = similarFactorRepo.findBySimilarId(id);
                    similarTypeClaimno.setSimilarFactorList(similarFactorList);
                }
            });
        }
        GraphDatilData graphDatilData = new GraphDatilData();
        graphDatilData.setBasicClaimno(basicClaimno);
        graphDatilData.setRiskTip(riskTip);
        graphDatilData.setSimilarTypeClaimnos(similarTypeClaimnos);
        return graphDatilData;

    }
}
