All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.quhaodian.user.data.service.impl.UserOauthTokenServiceImpl Maven / Gradle / Ivy

There is a newer version: 1.8.31
Show newest version
package com.quhaodian.user.data.service.impl;

import com.quhaodian.data.core.Finder;
import com.quhaodian.data.core.Updater;
import com.quhaodian.data.page.Filter;
import com.quhaodian.data.page.Order;
import com.quhaodian.data.page.Page;
import com.quhaodian.data.page.Pageable;
import com.quhaodian.data.utils.FilterUtils;
import com.quhaodian.user.data.dao.UserInfoDao;
import com.quhaodian.user.data.dao.UserOauthTokenDao;
import com.quhaodian.user.data.entity.UserInfo;
import com.quhaodian.user.data.entity.UserOauthToken;
import com.quhaodian.user.data.service.UserOauthTokenService;
import com.quhaodian.user.oauth.domain.OauthResponse;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * Created by imake on 2017年07月21日16:04:29.
 */
@Service
@Transactional
public class UserOauthTokenServiceImpl implements UserOauthTokenService {

  private UserOauthTokenDao dao;

  @Autowired
  private UserInfoDao userInfoDao;


  @Override
  public UserOauthToken findByUid(String uid) {


    Finder finder = Finder.create();
    finder.append("from UserOauthToken u where u.uid=:uid");
    finder.setParam("uid", uid);
    return dao.findOne(finder);
  }

  @Override
  public UserOauthToken login(OauthResponse response) {

    Finder finder = Finder.create();
    finder.append("from UserOauthToken u where u.uid=:uid");
    finder.append(" and u.token_type=:token_type");
    finder.setParam("uid", response.getOpenid());
    finder.setParam("token_type", response.type());
    UserOauthToken token = dao.findOne(finder);
    if (token == null) {
      token = new UserOauthToken();
      token.setUid(response.getOpenid());
      token.setToken_type(response.type());
      UserInfo user = new UserInfo();
      user.setAvatar(response.getAvatar());
      user.setName(response.getName());
      user.setRegisterType(response.type());
      userInfoDao.save(user);
      token.setUser(user);
      dao.save(token);
    }
    return token;
  }

  @Override
  @Transactional(readOnly = true)
  public UserOauthToken findById(Long id) {
    return dao.findById(id);
  }


  @Override
  @Transactional
  public UserOauthToken save(UserOauthToken bean) {
    dao.save(bean);
    return bean;
  }

  @Override
  @Transactional
  public UserOauthToken update(UserOauthToken bean) {
    Updater updater = new Updater(bean);
    return dao.updateByUpdater(updater);
  }

  @Override
  @Transactional
  public UserOauthToken deleteById(Long id) {
    UserOauthToken bean = dao.findById(id);
    dao.deleteById(id);
    return bean;
  }

  @Override
  @Transactional
  public UserOauthToken[] deleteByIds(Long[] ids) {
    UserOauthToken[] beans = new UserOauthToken[ids.length];
    for (int i = 0, len = ids.length; i < len; i++) {
      beans[i] = deleteById(ids[i]);
    }
    return beans;
  }


  @Autowired
  public void setDao(UserOauthTokenDao dao) {
    this.dao = dao;
  }

  @Override
  public Page page(Pageable pageable) {
    return dao.page(pageable);
  }


  @Override
  public Page page(Pageable pageable, Object search) {
    List filters = FilterUtils.getFilters(search);
    if (filters != null) {
      pageable.getFilters().addAll(filters);
    }
    return dao.page(pageable);
  }

  @Override
  public List list(int first, Integer size, List filters, List orders) {
    return dao.list(first, size, filters, orders);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy