| | |
| | | package com.ks.app.dao.admin; |
| | | |
| | | import com.ks.app.entity.AdminUser; |
| | | import com.ks.app.entity.admin.AdminUser; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.data.mongodb.core.query.Update; |
| | | import org.springframework.stereotype.Repository; |
| | | import org.yeshi.utils.mongo.MongodbBaseDao; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author hxh |
| | | * @title: AdminUserDao |
| | | * @description: TODO |
| | | * @description: 管理员 |
| | | * @date 2021/11/13 13:08 |
| | | */ |
| | | @Repository |
| | | public class AdminUserDao extends MongodbBaseDao<AdminUser> { |
| | | |
| | | /** |
| | | * @return AdminUser |
| | | * @return com.yeshi.makemoney.app.entity.AdminUser |
| | | * @author hxh |
| | | * @description 根据账号查询 |
| | | * @date 13:10 2021/11/13 |
| | |
| | | return findOne(query); |
| | | } |
| | | |
| | | public List<AdminUser> list(DaoQuery daoQuery) { |
| | | Query query = getQuery(daoQuery); |
| | | if (daoQuery.sortList != null && daoQuery.sortList.size() > 0) { |
| | | query.with(Sort.by(daoQuery.sortList)); |
| | | } |
| | | query.skip(daoQuery.start); |
| | | query.limit(daoQuery.count); |
| | | return findList(query); |
| | | } |
| | | |
| | | public long count(DaoQuery daoQuery) { |
| | | Query query = getQuery(daoQuery); |
| | | return count(query); |
| | | } |
| | | |
| | | private Query getQuery(DaoQuery daoQuery) { |
| | | List<Criteria> andList = new ArrayList<>(); |
| | | Query query = new Query(); |
| | | Criteria[] ands = new Criteria[andList.size()]; |
| | | andList.toArray(ands); |
| | | if (ands.length > 0) { |
| | | query.addCriteria(new Criteria().andOperator(ands)); |
| | | } |
| | | return query; |
| | | } |
| | | |
| | | |
| | | public void updateSelective(AdminUser bean) { |
| | | Query query = new Query(); |
| | | Update update = new Update(); |
| | | query.addCriteria(Criteria.where("_id").is(bean.getAccount())); |
| | | if (bean.getName() != null) { |
| | | update.set("name", bean.getName()); |
| | | } |
| | | if (bean.getEmail() != null) { |
| | | update.set("email", bean.getEmail()); |
| | | } |
| | | if (bean.getPwd() != null) { |
| | | update.set("pwd", bean.getPwd()); |
| | | } |
| | | update.set("updateTime", new Date()); |
| | | update(query, update); |
| | | } |
| | | |
| | | public static class DaoQuery { |
| | | public int start; |
| | | public int count; |
| | | public List<Sort.Order> sortList; |
| | | } |
| | | |
| | | } |