|
|
@@ -1,15 +1,17 @@
|
|
|
package com.uas.sso.service.impl;
|
|
|
|
|
|
-import com.uas.sso.dao.UserAccountDao;
|
|
|
import com.uas.sso.entity.UserAccount;
|
|
|
import com.uas.sso.service.UserAccountService;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import com.uas.sso.util.CollectionUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.persistence.EntityManager;
|
|
|
+import javax.persistence.PersistenceContext;
|
|
|
+import javax.persistence.TypedQuery;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
- * 用户账户service实现类
|
|
|
+ * 用户账户视图service实现类
|
|
|
*
|
|
|
* @author wangmh
|
|
|
* @date 2018/1/8
|
|
|
@@ -17,36 +19,97 @@ import java.util.List;
|
|
|
@Service
|
|
|
public class UserAccountServiceImpl implements UserAccountService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private UserAccountDao userAccountDao;
|
|
|
+ @PersistenceContext
|
|
|
+ private EntityManager entityManager;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 视图sql
|
|
|
+ */
|
|
|
+ private static final String JPQL= "select new UserAccount(user.userUU, user.vipName, user.mobile, user.mobileArea, " +
|
|
|
+ "user.mobileValidCode, user.password, user.erpPassword, user.salt, user.email, user.emailValidCode, " +
|
|
|
+ "user.identityValidCode, user.lock, us.spaceUU, us.spaceName, us.businessCode, " +
|
|
|
+ "us.domain, app.uid, ur.lastLoginTime) from UserRecord ur, User user inner join user.userspaces us inner join us.apps app where user.userRecord.id = ur.id ";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<UserAccount> findAll() {
|
|
|
+ //建立有类型的查询
|
|
|
+ TypedQuery<UserAccount> reportTypedQuery= entityManager.createQuery(JPQL, UserAccount.class);
|
|
|
+ List<UserAccount> reports= reportTypedQuery.getResultList();
|
|
|
+ return reports;
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
- public UserAccount findOneByMobile(String appId, String mobile, String spaceUU) {
|
|
|
- return userAccountDao.findByAppIdAndMobileAndSpaceUU(appId, mobile, spaceUU);
|
|
|
+ public UserAccount findOneByMobile(String appId, String mobile, Long spaceUU) {
|
|
|
+ String sql = JPQL + " and app.uid = ?1 and user.mobile = ?2 and us.spaceUU = ?3";
|
|
|
+ //建立有类型的查询
|
|
|
+ TypedQuery<UserAccount> reportTypedQuery= entityManager.createQuery(sql, UserAccount.class);
|
|
|
+ //另外有详细查询条件的在jpql中留出参数位置来(?1 ?2 ?3....),然后在这设置
|
|
|
+ reportTypedQuery.setParameter(1, appId);
|
|
|
+ reportTypedQuery.setParameter(2, mobile);
|
|
|
+ reportTypedQuery.setParameter(3, spaceUU);
|
|
|
+ List<UserAccount> reports= reportTypedQuery.getResultList();
|
|
|
+ return CollectionUtils.isEmpty(reports) ? null : reports.get(0);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public UserAccount findOneByEmail(String appId, String email, String spaceUU) {
|
|
|
- return userAccountDao.findByAppIdAndEmailAndSpaceUU(appId, email, spaceUU);
|
|
|
+ public UserAccount findOneByEmail(String appId, String email, Long spaceUU) {
|
|
|
+ String sql = JPQL + " and app.uid = ?1 and user.email = ?2 and us.spaceUU = ?3";
|
|
|
+ //建立有类型的查询
|
|
|
+ TypedQuery<UserAccount> reportTypedQuery= entityManager.createQuery(sql, UserAccount.class);
|
|
|
+ //另外有详细查询条件的在jpql中留出参数位置来(?1 ?2 ?3....),然后在这设置
|
|
|
+ reportTypedQuery.setParameter(1, appId);
|
|
|
+ reportTypedQuery.setParameter(2, email);
|
|
|
+ reportTypedQuery.setParameter(3, spaceUU);
|
|
|
+ List<UserAccount> reports= reportTypedQuery.getResultList();
|
|
|
+ return CollectionUtils.isEmpty(reports) ? null : reports.get(0);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public UserAccount findOneByUserUU(String appId, Long userUU, String spaceUU) {
|
|
|
- return userAccountDao.findByAppIdAndUserUUAndSpaceUU(appId, userUU, spaceUU);
|
|
|
+ public UserAccount findOneByUserUU(String appId, Long userUU, Long spaceUU) {
|
|
|
+ String sql = JPQL + " and app.uid = ?1 and user.userUU = ?2 and us.spaceUU = ?3";
|
|
|
+ //建立有类型的查询
|
|
|
+ TypedQuery<UserAccount> reportTypedQuery= entityManager.createQuery(sql, UserAccount.class);
|
|
|
+ //另外有详细查询条件的在jpql中留出参数位置来(?1 ?2 ?3....),然后在这设置
|
|
|
+ reportTypedQuery.setParameter(1, appId);
|
|
|
+ reportTypedQuery.setParameter(2, userUU);
|
|
|
+ reportTypedQuery.setParameter(3, spaceUU);
|
|
|
+ List<UserAccount> reports= reportTypedQuery.getResultList();
|
|
|
+ return CollectionUtils.isEmpty(reports) ? null : reports.get(0);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<UserAccount> findByMobile(String appId, String mobile) {
|
|
|
- return userAccountDao.findByAppIdAndMobile(appId, mobile);
|
|
|
+ String sql = JPQL + " and app.uid = ?1 and user.mobile = ?2";
|
|
|
+ //建立有类型的查询
|
|
|
+ TypedQuery<UserAccount> reportTypedQuery= entityManager.createQuery(sql, UserAccount.class);
|
|
|
+ //另外有详细查询条件的在jpql中留出参数位置来(?1 ?2 ?3....),然后在这设置
|
|
|
+ reportTypedQuery.setParameter(1, appId);
|
|
|
+ reportTypedQuery.setParameter(2, mobile);
|
|
|
+ List<UserAccount> reports= reportTypedQuery.getResultList();
|
|
|
+ return reports;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<UserAccount> findByEmail(String appId, String email) {
|
|
|
- return userAccountDao.findByAppIdAndEmail(appId, email);
|
|
|
+ String sql = JPQL + " and app.uid = ?1 and user.email = ?2";
|
|
|
+ //建立有类型的查询
|
|
|
+ TypedQuery<UserAccount> reportTypedQuery= entityManager.createQuery(sql, UserAccount.class);
|
|
|
+ //另外有详细查询条件的在jpql中留出参数位置来(?1 ?2 ?3....),然后在这设置
|
|
|
+ reportTypedQuery.setParameter(1, appId);
|
|
|
+ reportTypedQuery.setParameter(2, email);
|
|
|
+ List<UserAccount> reports= reportTypedQuery.getResultList();
|
|
|
+ return reports;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<UserAccount> findByUserUU(String appId, Long userUU) {
|
|
|
- return userAccountDao.findByAppIdAndUserUU(appId, userUU);
|
|
|
+ String sql = JPQL + " and app.uid = ?1 and user.userUU = ?2";
|
|
|
+ //建立有类型的查询
|
|
|
+ TypedQuery<UserAccount> reportTypedQuery= entityManager.createQuery(sql, UserAccount.class);
|
|
|
+ //另外有详细查询条件的在jpql中留出参数位置来(?1 ?2 ?3....),然后在这设置
|
|
|
+ reportTypedQuery.setParameter(1, appId);
|
|
|
+ reportTypedQuery.setParameter(2, userUU);
|
|
|
+ List<UserAccount> reports= reportTypedQuery.getResultList();
|
|
|
+ return reports;
|
|
|
}
|
|
|
}
|