|
@@ -0,0 +1,96 @@
|
|
|
|
+package cn.iselab.mooctest.user.service.impl;
|
|
|
|
+
|
|
|
|
+import cn.iselab.mooctest.user.dao.User2IntegralDao;
|
|
|
|
+import cn.iselab.mooctest.user.dao.UserIntegralDao;
|
|
|
|
+import cn.iselab.mooctest.user.model.User2Integral;
|
|
|
|
+import cn.iselab.mooctest.user.model.UserIntegral;
|
|
|
|
+import cn.iselab.mooctest.user.service.IntegralService;
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
|
+import org.springframework.data.jpa.domain.Specifications;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import javax.persistence.criteria.CriteriaBuilder;
|
|
|
|
+import javax.persistence.criteria.CriteriaQuery;
|
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
|
+import javax.persistence.criteria.Root;
|
|
|
|
+import java.sql.Timestamp;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @Author ROKG
|
|
|
|
+ * @Description
|
|
|
|
+ * @Date: Created in 下午6:36 2018/2/13
|
|
|
|
+ * @Modified By:
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class IntegralServiceImpl implements IntegralService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ UserIntegralDao userIntegralDao;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ User2IntegralDao user2IntegralDao;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public UserIntegral findByUserId(long userId){
|
|
|
|
+ List<UserIntegral> userIntegrals=userIntegralDao.findByUserId(userId);
|
|
|
|
+ if(userIntegrals!=null && userIntegrals.size()>0){
|
|
|
|
+ return userIntegrals.get(0);
|
|
|
|
+ }else {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public UserIntegral saveIntegral(UserIntegral userIntegral){
|
|
|
|
+ return userIntegralDao.save(userIntegral);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Page<UserIntegral> findPage(String keyword, Pageable pageable){
|
|
|
|
+ Specifications<UserIntegral> where=Specifications.where(getUserIntegral(keyword));
|
|
|
|
+ return userIntegralDao.findAll(where,pageable);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<User2Integral> findByTime(long userId, long startTime, long endTime){
|
|
|
|
+ Specifications<User2Integral> where=Specifications.where(getUser2Integral(new Timestamp(startTime),new Timestamp(endTime)));
|
|
|
|
+ return user2IntegralDao.findAll(where);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public User2Integral saveUser2Integral(User2Integral user2Integral){
|
|
|
|
+ return user2IntegralDao.save(user2Integral);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Specification<User2Integral> getUser2Integral(Timestamp startTime, Timestamp endTime){
|
|
|
|
+ return new Specification<User2Integral>() {
|
|
|
|
+ @Override
|
|
|
|
+ public Predicate toPredicate(Root<User2Integral> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
|
|
|
|
+ Predicate p=criteriaBuilder.conjunction();
|
|
|
|
+ p.getExpressions()
|
|
|
|
+ .add(criteriaBuilder.lessThan(root.get("createTime"),endTime));
|
|
|
|
+ p.getExpressions()
|
|
|
|
+ .add(criteriaBuilder.greaterThan(root.get("createTime"),startTime));
|
|
|
|
+ return p;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Specification<UserIntegral> getUserIntegral(String keyword){
|
|
|
|
+ return new Specification<UserIntegral>() {
|
|
|
|
+ @Override
|
|
|
|
+ public Predicate toPredicate(Root<UserIntegral> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
|
|
|
|
+ Predicate p=criteriaBuilder.conjunction();
|
|
|
|
+ if(keyword!=null){
|
|
|
|
+ p.getExpressions().add(criteriaBuilder.like(root.get("source"), "%"+ StringUtils.trim(keyword) +"%"));
|
|
|
|
+ }
|
|
|
|
+ return p;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+}
|