派生自 projectDept/qhighschool

yn147
2023-11-23 42c48ce1d64e941d28c7bfe4093f9659e77bd523
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package com.qxueyou.scc.portal.homepage.dao;
 
//import com.qxueyou.entity.article.ArticleDO;
//import com.qxueyou.service.MongoService;
//import com.qxueyou.util.CollectionUtils;
import com.qxueyou.scc.base.dao.BaseDAO;
import com.qxueyou.scc.base.model.Pager;
import com.qxueyou.scc.base.util.ClientUtils;
import com.qxueyou.scc.base.util.CollectionUtils;
import com.qxueyou.scc.portal.information.model.Information;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
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 javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * @author ZERO 2021-03-03 16:36
 */
@Repository
public class ArticleDao  extends BaseDAO {
 
 
 
 
 
    public Map<String, Object> moreOccupation(String type, String subColumn, String numbers,int page, int size, String keyword) {
 
        StringBuffer hql = new StringBuffer(500);
         hql.append( "from Information where  deleteFlag=0 and type = ? and status= ?");
        List<Object> params = CollectionUtils.newList(type, Information.UP_STATUS);
 
       // Map<String, Object> condition = CollectionUtils.newObjectMap("type", type, "status", Information.UP_STATUS);
        if(StringUtils.isNotEmpty(keyword)){
            hql.append( " and title = ? ");
            params.add(keyword);
        }
        if (type.equals("examBriefing")) {
            hql.append( "and subColumn = ? ");
            params.add( subColumn);
        }
//        if(subColumn!=null) {
//            if (subColumn.equals("previousContest")) {
//                condition.put("numbers", numbers);
//            }
//        }
 
 
        long totalCount = findCount(hql.toString(),params);
        hql.append( "order by dateTime desc");
 
        List<Information> articleList = findList(hql.toString(),new Pager(page,size),params,Information.class);
 
 
        List<Map<String, Object>> data = articleList
                .stream()
                .map(article -> CollectionUtils.newObjectMap(
                        "id", article.getId(),
                        "content", article.getContent(),
                        "title", article.getTitle(),
                        "attachment", article.getAttachment(),
                        "browseCount", article.getBrowseCount(),
                        "status", article.getStatus(),
                        "thumbnailUrl", article.getThumbnailUrl(),
                        "type", article.getType(),
                        "dateTime", article.getDateTime(),
                        "competition",article.getCompetition()))
                .collect(Collectors.toList());
 
        return CollectionUtils.newObjectMap("totalCount", totalCount, "data", data);
    }
 
    public Map<String, Object> getVideoList(String type, String subColumn,int page, int size){
        StringBuffer hql = new StringBuffer(500);
        hql.append( "from Information where  deleteFlag=0 and type = ? and status= ?  ");
        List<Object> params = CollectionUtils.newList(type, Information.UP_STATUS);
//        Map<String, Object> condition = CollectionUtils.newObjectMap("type", type, "status", Information.UP_STATUS);
 
        if (type.equals("examBriefing")) {
            hql.append( "and subColumn = ? ");
            params.add( subColumn);
        }
        long totalCount = findCount(hql.toString(),params);
        hql.append( "order by dateTime desc");
 
 
        List<Information> articleList =findList(hql.toString(),new Pager(page,size),params,Information.class);
        List<Map<String, Object>> data = articleList
                .stream()
                .map(article -> CollectionUtils.newObjectMap(
                        "title", article.getTitle(),
                        "type", article.getType(),
                        "dateTime", article.getDateTime(),
                        "videoUrl",article.getVideoUrl(),
                        "name",article.getNumbers()))
                .collect(Collectors.toList());
 
        return CollectionUtils.newObjectMap("totalCount", totalCount, "data", data);
    }
//
    public boolean exist(String type) {
        String hql= "from Information where  deleteFlag=0 and type = ? and status= ? ";
        long totalCount = findCount(hql,CollectionUtils.newList(type, Information.UP_STATUS));
        return totalCount>0?true:false;
    }
//
    public boolean existsubColumn(String type, String subColumn) {
 
 
        String hql= "from Information where  deleteFlag=0 and type = ? and status= ? and subColumn=?";
        long totalCount = findCount(hql,CollectionUtils.newList(type, Information.UP_STATUS,subColumn));
        return totalCount>0?true:false;
    }
 
    public Map<String, Object> getPreAndBehindArticle(String currentArticleId, String type) {
        StringBuffer hql = new StringBuffer(500);
        hql.append("from Information where  deleteFlag=0 and type = ? and status= ?  order by updateTime desc");
        List<Object> params = CollectionUtils.newList(type, Information.UP_STATUS);
//        Query query = Query.query(Criteria.where("type").is(type)
//                .and("status").is(ArticleDO.UP_STATUS)
//                .and("deleteFlag").is(false))
//                .with(Sort.by(Sort.Direction.DESC, "updateTime"));
//        query.fields().include("id");
//        List<Information> articleList =find(hql.toString(),params,Information.class);
        List<String> articleIdList = find(hql.toString(),params,Information.class)
                .stream()
                .map(Information::getId)
                .collect(Collectors.toList());
 
        int currentIndex = articleIdList.indexOf(currentArticleId);
 
        Map<String, Object> data = CollectionUtils.newObjectMap("previous", null, "behind", null);
 
        if (currentIndex != 0) {
            Information preArticle = read(Information.class,articleIdList.get(currentIndex - 1));
            data.put("previous", CollectionUtils.newObjectMap(
                    "id", preArticle.getId(),
                    "title", preArticle.getTitle(),
                    "type", preArticle.getType()));
        }
 
        if (currentIndex != articleIdList.size() - 1) {
            Information behindArticle = read(Information.class,articleIdList.get(currentIndex + 1));
            data.put("previous", CollectionUtils.newObjectMap(
                    "id", behindArticle.getId(),
                    "title", behindArticle.getTitle(),
                    "type", behindArticle.getType()));
        }
 
        return data;
    }
//
    public void incBrowseCount(String id) {
//        Query query = Query.query(Criteria.where("id").is(id));
//        Update update = new Update();
//        update.inc("browseCount", 1);
//        template.updateFirst(query, update, clz);
        Information behindArticle = read(Information.class,id);
        behindArticle.setBrowseCount(behindArticle.getBrowseCount()+1);
        saveOrUpdate(behindArticle);
    }
 
    public Information getArticle(String type,String subColumn)
    {
        StringBuffer hql = new StringBuffer(500);
        hql.append( "from Information where  deleteFlag=0 and type = ? and status= ?  order by updateTime desc");
        List<Object> params = CollectionUtils.newList(type, Information.UP_STATUS);
 
        if (type.equals("examBriefing")) {
            hql.append( "and subColumn = ? ");
            params.add( subColumn);
        }
//        Query query = Query.query(Criteria.where("type").is(type)
//                .and("status").is(ArticleDO.UP_STATUS)
//                .and("deleteFlag").is(false))
//                .with(Sort.by(Sort.Direction.DESC, "updateTime"));
//        System.out.println(type);
//        if (type.equals("examBriefing")) {
//            query.addCriteria(Criteria.where("subColumn").is(subColumn));
//        }
        Information articleDO = findUnique(hql.toString(), params, Information.class);
//        ArticleDO articleDO =findOne(query,ArticleDO.class);
        return articleDO;
    }
}