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

import java.util.List;

import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.sysmodular.dao.SysModularFieldDao;
import com.jeeplus.modules.sysmodular.entity.SysModularField;
import com.jeeplus.modules.workchangejob.entity.WorkChangeJobUser;
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.sysmodular.entity.SysModular;
import com.jeeplus.modules.sysmodular.dao.SysModularDao;

/**
 * 业务模块Service
 * @author ssrh
 * @version 2018-08-17
 */
@Service
@Transactional(readOnly = true)
public class SysModularService extends CrudService<SysModularDao, SysModular> {

	@Autowired
	private SysModularFieldDao sysModularFieldDao;
	public SysModular get(String id) {
		return super.get(id);
	}
	
	public List<SysModular> findList(SysModular sysModular) {
		return super.findList(sysModular);
	}
	
	public Page<SysModular> findPage(Page<SysModular> page, SysModular sysModular) {
		return super.findPage(page, sysModular);
	}

	public List<SysModular> findByTableName(SysModular sysModular) {
		List<SysModular> list=dao.findByTableName(sysModular);
		return list;
	}
	@Transactional(readOnly = false)
	public void save(SysModular sysModular) {
		super.save(sysModular);
	}
	
	@Transactional(readOnly = false)
	public void delete(SysModular sysModular) {
		super.delete(sysModular);
	}


	public List<SysModular> findTable(String dbName) {
		return dao.findTable(dbName);
	}
	@Transactional(readOnly = false)
	public void saveColumn(SysModular sysModular) {
		if(sysModular.getSysModularFieldList()!=null&&sysModular.getSysModularFieldList().size()>0){
			for (SysModularField sysModularField :sysModular.getSysModularFieldList()) {
				if (StringUtils.isBlank(sysModularField.getId()) ) {
					if(StringUtils.isNotBlank(sysModularField.getModularId())){
						sysModularField.preInsert();
						sysModularField.setModularId(sysModular.getId());
						sysModularFieldDao.insert(sysModularField);
					}
				} else {
					if(StringUtils.isNotBlank(sysModularField.getModularId())){
						sysModularField.preUpdate();
						sysModularField.setModularId(sysModular.getId());
						sysModularFieldDao.update(sysModularField);
					}
				}
			}
		}
	}
}