/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.workreimbursementback.service;

import java.util.ArrayList;
import java.util.List;

import com.jeeplus.modules.workloan.dao.WorkLoanDao;
import com.jeeplus.modules.workloan.entity.WorkLoan;
import com.jeeplus.modules.workloan.service.WorkLoanService;
import com.jeeplus.modules.workreimbursement.service.WorkReimbursementService;
import com.jeeplus.modules.workrepay.dao.WorkRepayDao;
import com.jeeplus.modules.workrepay.entity.WorkRepay;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.service.CrudService;
import com.jeeplus.modules.workreimbursementback.entity.WorkReimbursementBack;
import com.jeeplus.modules.workreimbursementback.dao.WorkReimbursementBackDao;

/**
 * 报销还款Service
 * @author ssrh
 * @version 2018-10-17
 */
@Service
@Transactional(readOnly = true)
public class WorkReimbursementBackService extends CrudService<WorkReimbursementBackDao, WorkReimbursementBack> {
	@Autowired
	private WorkRepayDao workRepayDao;
	@Autowired
	private WorkLoanService workLoanService;

	public WorkReimbursementBack get(String id) {
		return super.get(id);
	}
	
	public List<WorkReimbursementBack> findList(WorkReimbursementBack workReimbursementBack) {
		return super.findList(workReimbursementBack);
	}
	
	public Page<WorkReimbursementBack> findPage(Page<WorkReimbursementBack> page, WorkReimbursementBack workReimbursementBack) {
		return super.findPage(page, workReimbursementBack);
	}
	
	@Transactional(readOnly = false)
	public void save(WorkReimbursementBack workReimbursementBack) {
		super.save(workReimbursementBack);
	}
	
	@Transactional(readOnly = false)
	public void delete(WorkReimbursementBack workReimbursementBack) {
		super.delete(workReimbursementBack);
	}

	public List<WorkReimbursementBack> findLoanList(String id) {
		WorkReimbursementBack workReimbursementBack=new WorkReimbursementBack();
		workReimbursementBack.setAchivesId(id);
		List<WorkReimbursementBack> list= dao.findLoanList(workReimbursementBack);
		List<WorkReimbursementBack> newList=new ArrayList<>();
		if(list!=null&&list.size()>0){
			for(WorkReimbursementBack workReimbursementBack1:list){
				List<WorkRepay> workRepayList= workRepayDao.findWorkRepayList(workReimbursementBack1.getWorkLoan().getId());
				if(workRepayList!=null&&workRepayList.size()>0){
				}else{
					WorkLoan workLoan=workLoanService.getLon(workReimbursementBack1.getWorkLoan().getId());
					if(workLoan.getType().equals("1")){
						workLoan.setType("行政借款");
					}else{
						workLoan.setType("项目借款");
					}
					workReimbursementBack1.setWorkLoan(workLoan);
					newList.add(workReimbursementBack1);
				}
			}
		}
		return newList;
	}
	
	
}