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

import java.util.List;

import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.project.entity.Project;
import com.jeeplus.modules.projectrecord.entity.ProjectRecords;
import com.jeeplus.modules.sys.dao.WorkattachmentDao;
import com.jeeplus.modules.sys.entity.Workattachment;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.workclientinfo.dao.WorkClientAttachmentDao;
import com.jeeplus.modules.workclientinfo.entity.WorkClientAttachment;
import com.jeeplus.modules.workcontractinfo.entity.WorkContractInfo;
import com.jeeplus.modules.workcontractinfo.service.WorkContractInfoService;
import com.jeeplus.modules.workreimbursement.utils.VarStr;
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.projectcontentinfo.entity.ProjectBasedData;
import com.jeeplus.modules.projectcontentinfo.dao.ProjectBasedDataDao;

/**
 * 依据性资料Service
 * @author 杨帆
 * @version 2018-06-05
 */
@Service
@Transactional(readOnly = true)
public class ProjectBasedDataService extends CrudService<ProjectBasedDataDao, ProjectBasedData> {
	@Autowired
	private WorkattachmentDao workattachmentDao;

	public ProjectBasedData get(String id) {
		ProjectBasedData projectBasedData = super.get(id);
		if(projectBasedData!=null) {
            Workattachment workattachment = new Workattachment();
            workattachment.setAttachmentId(id);
            workattachment.setAttachmentFlag("84");
            projectBasedData.setWorkAttachments(workattachmentDao.findList(workattachment));
        }
		return projectBasedData;
	}

	public String getNumber(ProjectRecords projectRecords) {
		if (projectRecords!=null && StringUtils.isNotBlank(projectRecords.getId())){
			ProjectBasedData projectBasedData = new ProjectBasedData();
			projectBasedData.setProject(projectRecords);
			ProjectBasedData value = dao.getNumber(projectBasedData);
			if (value==null || StringUtils.isBlank(value.getNumber())){
				return "001";
			}else {
				return UserUtils.getNumber(value.getNumber());
			}
		}else {
			return "001";
		}

	}

	public List<ProjectBasedData> findList(ProjectBasedData projectBasedData) {
		return super.findList(projectBasedData);
	}
	
	public Page<ProjectBasedData> findPage(Page<ProjectBasedData> page, ProjectBasedData projectBasedData) {
		return super.findPage(page, projectBasedData);
	}
	
	@Transactional(readOnly = false)
	public void save(ProjectBasedData projectBasedData) {
		super.save(projectBasedData);
	}


}