package com.jeesite.modules.sso.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeesite.common.entity.Page;
import com.jeesite.common.service.CrudService;
import com.jeesite.modules.sso.entity.SsoApp;
import com.jeesite.modules.sso.dao.SsoAppDao;
import com.jeesite.modules.file.utils.FileUploadUtils;

/**
 * 应用接入列表Service
 * @author yinet
 * @version 2022-06-14
 */
@Service
@Transactional(readOnly=true)
public class SsoAppService extends CrudService<SsoAppDao, SsoApp> {

	@Autowired
	private SsoAppDao ssoAppDao;
	/**
	 * 获取单条数据
	 * @param ssoApp
	 * @return
	 */
	@Override
	public SsoApp get(SsoApp ssoApp) {
		return super.get(ssoApp);
	}
	
	/**
	 * 查询分页数据
	 * @param ssoApp 查询条件
	 * @param ssoApp.page 分页对象
	 * @return
	 */
	@Override
	public Page<SsoApp> findPage(SsoApp ssoApp) {
		return super.findPage(ssoApp);
	}
	
	/**
	 * 查询列表数据
	 * @param ssoApp
	 * @return
	 */
	@Override
	public List<SsoApp> findList(SsoApp ssoApp) {
		return super.findList(ssoApp);
	}
	
	/**
	 * 保存数据（插入或更新）
	 * @param ssoApp
	 */
	@Override
	@Transactional(readOnly=false)
	public void save(SsoApp ssoApp) {
		super.save(ssoApp);
		// 保存上传图片
		FileUploadUtils.saveFileUpload(ssoApp, ssoApp.getId(), "ssoApp_image");
	}
	
	/**
	 * 更新状态
	 * @param ssoApp
	 */
	@Override
	@Transactional(readOnly=false)
	public void updateStatus(SsoApp ssoApp) {
		super.updateStatus(ssoApp);
	}
	
	/**
	 * 删除数据
	 * @param ssoApp
	 */
	@Override
	@Transactional(readOnly=false)
	public void delete(SsoApp ssoApp) {
		super.delete(ssoApp);
	}

	/**
	 * 修改状态
	 * @param flag
	 * @param id
	 * @return
	 */
	@Transactional(readOnly = false)
    public int changeStatus(String flag, String id) {

		if(flag.equals("true")){
			//修改状态
			int i=ssoAppDao.changeStatus(id,"0");
			return i;
		}else {
			//修改状态
			int i=ssoAppDao.changeStatus(id,"1");
			return i;
		}

    }

	/**
	 * 修改是否推荐
	 * @param flag
	 * @param id
	 * @return
	 */
	@Transactional(readOnly = false)
	public int recommendStatus(String flag, String id) {
		if(flag.equals("true")){
			//修改状态
			int i=ssoAppDao.recommendStatus(id,"0");
			return i;
		}else {
			//修改状态
			int i=ssoAppDao.recommendStatus(id,"1");
			return i;
		}
	}
}