package org.linlinjava.jz.db.service.hm;

import java.util.List;

import org.linlinjava.jz.db.dao.HmButlerTaskChildMapper;
import org.linlinjava.jz.db.dao.HmButlerTaskLogMapper;
import org.linlinjava.jz.db.dao.HmButlerTaskParentMapper;
import org.linlinjava.jz.db.domain.HmButlerTaskChild;
import org.linlinjava.jz.db.domain.HmButlerTaskLog;
import org.linlinjava.jz.db.domain.HmButlerTaskLogExample;
import org.linlinjava.jz.db.domain.HmButlerTaskParent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 拜访类任务日志
 * @author 36952
 *
 */
@Service
public class HmButlerTaskLogService  {

	@Autowired
	HmButlerTaskLogMapper hmButlerTaskLogMapper;

	@Autowired
	HmButlerTaskChildMapper hmButlerTaskChildMapper;

	@Autowired
	HmButlerTaskParentMapper butlerTaskParentMapper;

	// 插入拜访类任务日志
	public int insertButlerTaskLog(Long taskChildId, Long businessId, String operateContent) {

		HmButlerTaskChild taskChild = hmButlerTaskChildMapper.selectByPrimaryKey(taskChildId);

		HmButlerTaskLog record = new HmButlerTaskLog();
		record.setBusinessId(businessId);
		record.setOperateContent(operateContent);

		record.setEmployRelationId(taskChild.getEmployRelationId());
		record.setOrderNo(taskChild.getOrderNo());
		record.setTaskChildId(taskChildId);
		record.setTaskParentId(taskChild.getTaskParentId());

		return hmButlerTaskLogMapper.insertSelective(record);
	}

	// 插入拜访类任务日志--拜访类主任务完成
	public void insertButlerTaskLogParent(Long parentTaskId, Long businessId, String operateContent) {

		HmButlerTaskParent taskParent = butlerTaskParentMapper.selectByPrimaryKey(parentTaskId);

		HmButlerTaskLog record = new HmButlerTaskLog();
		record.setBusinessId(businessId);
		record.setOperateContent(operateContent);

		record.setEmployRelationId(taskParent.getEmployRelationId());
		record.setOrderNo(taskParent.getOrderNo());
//		record.setTaskChildId(null);
		record.setTaskParentId(parentTaskId);

		hmButlerTaskLogMapper.insertSelective(record);
	}
	
	public List<HmButlerTaskLog> getTaskLog(Long taskParentId) {
		HmButlerTaskLogExample logexample = new HmButlerTaskLogExample();
		logexample.or().andTaskParentIdEqualTo(taskParentId);
		logexample.setOrderByClause(" id desc ");
		return hmButlerTaskLogMapper.selectByExample(logexample);
		 
	}
}
