|
@@ -0,0 +1,89 @@
|
|
|
+package com.zzys.lightting.user.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.PageUtil;
|
|
|
+import com.zzys.lightting.user.dao.model.UserListenRecord;
|
|
|
+import com.zzys.lightting.user.dao.repository.UserListenRecordRepository;
|
|
|
+import com.zzys.lightting.user.service.UserListenRecordService;
|
|
|
+import com.zzys.lightting.utils.EscapeUtil;
|
|
|
+import com.zzys.lightting.utils.PageRequestUtil;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
+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.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description:聆听记录接口
|
|
|
+ * @Author: mimang
|
|
|
+ * @Date: 2025/1/21
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class UserListenRecordServiceImpl implements UserListenRecordService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserListenRecordRepository repository;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public UserListenRecord saveRecord(UserListenRecord record) {
|
|
|
+ record.setCreateTime(DateUtil.now());
|
|
|
+ return repository.save(record);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public UserListenRecord findById(String recordId) {
|
|
|
+ return repository.findById(recordId).orElse(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public UserListenRecord finishRecord(UserListenRecord record) {
|
|
|
+ record.setUpdateTime(DateUtil.now());
|
|
|
+ return repository.save(record);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<UserListenRecord> findListByPage(UserListenRecord record, int pageSize, int pageNum) {
|
|
|
+ if (record == null){
|
|
|
+ return repository.findAll(PageRequestUtil.of(pageNum,pageSize));
|
|
|
+ }else {
|
|
|
+ //处理条件
|
|
|
+ Specification<UserListenRecord> specification = ((root, query, criteriaBuilder) -> {
|
|
|
+ List<Predicate> list = new ArrayList<>();
|
|
|
+ if (StringUtils.isNotEmpty(record.getMusicId())){
|
|
|
+ list.add(criteriaBuilder.equal(root.get("musicId"),record.getMusicId()));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(record.getTypeId())){
|
|
|
+ list.add(criteriaBuilder.equal(root.get("typeId"),record.getTypeId()));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(record.getOrgNo())){
|
|
|
+ String orgNo2 = EscapeUtil.escapeChar(record.getOrgNo());
|
|
|
+ list.add(criteriaBuilder.like(root.get("orgNo"),"%"+orgNo2+"%"));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(record.getUserNo())){
|
|
|
+ String userNo2 = EscapeUtil.escapeChar(record.getUserNo());
|
|
|
+ list.add(criteriaBuilder.like(root.get("userNo"),"%"+userNo2+"%"));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(record.getUserName())){
|
|
|
+ String userName2 = EscapeUtil.escapeChar(record.getUserName());
|
|
|
+ list.add(criteriaBuilder.like(root.get("userName"),"%"+userName2+"%"));
|
|
|
+ }
|
|
|
+
|
|
|
+ //list.add(criteriaBuilder.equal(root.get("userStatus"), Constant.DEFAULT_VALUE_ONE));
|
|
|
+ query.where(criteriaBuilder.and(list.toArray(new Predicate[list.size()])));
|
|
|
+ query.orderBy(criteriaBuilder.asc(root.get("createTime")));
|
|
|
+ return query.getRestriction();
|
|
|
+ });
|
|
|
+ return repository.findAll(specification,PageRequestUtil.of(pageNum,pageSize));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|