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

import java.util.List;

import com.jeeplus.modules.sys.dao.AreaDao;
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.workstaffachiveslog.entity.WorkStaffAchivesLog;
import com.jeeplus.modules.workstaffachiveslog.dao.WorkStaffAchivesLogDao;

/**
 * 档案修改日志Service
 * @author ssrh
 * @version 2018-10-11
 */
@Service
@Transactional(readOnly = true)
public class WorkStaffAchivesLogService extends CrudService<WorkStaffAchivesLogDao, WorkStaffAchivesLog> {
	@Autowired
	private WorkStaffAchivesLogDao workStaffAchivesLogDao;
	public WorkStaffAchivesLog get(String id) {
		return super.get(id);
	}
	
	public List<WorkStaffAchivesLog> findList(WorkStaffAchivesLog workStaffAchivesLog) {
		return super.findList(workStaffAchivesLog);
	}
	
	public Page<WorkStaffAchivesLog> findPage(Page<WorkStaffAchivesLog> page, WorkStaffAchivesLog workStaffAchivesLog) {
		return super.findPage(page, workStaffAchivesLog);
	}
	public List<WorkStaffAchivesLog> findSonId(WorkStaffAchivesLog workStaffAchivesLog) {
		return dao.findSonId(workStaffAchivesLog);
	}

	@Transactional(readOnly = false)
	public void save(WorkStaffAchivesLog workStaffAchivesLog) {
		super.save(workStaffAchivesLog);
	}
	
	@Transactional(readOnly = false)
	public void delete(WorkStaffAchivesLog workStaffAchivesLog) {
		super.delete(workStaffAchivesLog);
	}

	@Transactional(readOnly = false)
	public  void saveStaffLog(WorkStaffAchivesLog workStaffAchivesLog,String staffId,
							  String module,String describes,String fields,String oldValue,
							  String newValue,String oldKey,String newKey,String sonId,String type){
		List<WorkStaffAchivesLog> logs=this.findList(workStaffAchivesLog);
		if (logs!=null&&logs.size()>0) {
			workStaffAchivesLog.preUpdate();
			workStaffAchivesLog.setId(logs.get(0).getId());
			workStaffAchivesLog.setStaffId(staffId);
			workStaffAchivesLog.setModule(module);
			workStaffAchivesLog.setDescribes(describes);
			workStaffAchivesLog.setFields(fields);
			workStaffAchivesLog.setOldValue(oldValue);
			workStaffAchivesLog.setNewValue(newValue);
			workStaffAchivesLog.setOldKey(oldKey);
			workStaffAchivesLog.setNewKey(newKey);
			workStaffAchivesLog.setSonId(sonId);
			workStaffAchivesLog.setType(type);
			workStaffAchivesLog.setState("1");
			workStaffAchivesLogDao.update(workStaffAchivesLog);
		} else {
			workStaffAchivesLog.preInsert();
			workStaffAchivesLog.setStaffId(staffId);
			workStaffAchivesLog.setModule(module);
			workStaffAchivesLog.setDescribes(describes);
			workStaffAchivesLog.setFields(fields);
			workStaffAchivesLog.setOldValue(oldValue);
			workStaffAchivesLog.setNewValue(newValue);
			workStaffAchivesLog.setOldKey(oldKey);
			workStaffAchivesLog.setNewKey(newKey);
			workStaffAchivesLog.setSonId(sonId);
			workStaffAchivesLog.setType(type);
			workStaffAchivesLog.setState("1");
			workStaffAchivesLogDao.insert(workStaffAchivesLog);
		}
	}
	
	
}