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

import java.util.List;

import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.isignature.service.ISignatureDocumentService;
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.dao.WorkContractReviewDao;
import com.jeeplus.modules.workcontractinfo.entity.WorkContractReview;
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;

/**
 * 合同评价表Service
 * @author 杨帆
 * @version 2018-03-23
 */
@Service
@Transactional(readOnly = true)
public class WorkContractReviewService extends CrudService<WorkContractReviewDao, WorkContractReview> {
	@Autowired
	private WorkClientAttachmentDao workClientAttachmentDao;

	@Autowired
	private ISignatureDocumentService signatureDocumentService;

	public WorkContractReview get(String id) {
		return super.get(id);
	}
	
	public List<WorkContractReview> findList(WorkContractReview workContractReview) {
		return super.findList(workContractReview);
	}
	
	public Page<WorkContractReview> findPage(Page<WorkContractReview> page, WorkContractReview workContractReview) {
		return super.findPage(page, workContractReview);
	}
	
	@Transactional(readOnly = false)
	public void save(WorkContractReview workContractReview) {
		super.save(workContractReview);
		for (WorkClientAttachment workClientAttachment : workContractReview.getWorkAttachments()){
			if (workClientAttachment.getId() == null){
				continue;
			}
			if (WorkClientAttachment.DEL_FLAG_NORMAL.equals(workClientAttachment.getDelFlag())){
				workClientAttachment.setAttachmentId(workContractReview.getId());
				workClientAttachment.setAttachmentFlag("80");
				workClientAttachment.setAttachmentUser(UserUtils.getUser().getId());
				if (StringUtils.isBlank(workClientAttachment.getId()) || "null".equals(workClientAttachment.getId())) {
					workClientAttachment.preInsert();
					workClientAttachmentDao.insert(workClientAttachment);
				} else {
					workClientAttachment.preUpdate();
					workClientAttachmentDao.update(workClientAttachment);
				}
			} else {
				workClientAttachmentDao.delete(workClientAttachment);
			}
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(WorkContractReview workContractReview) {
		super.delete(workContractReview);
	}
	
	
	
	
}