Pu Zhibing
1 天以前 cad8d3cdcb6253ef719bb9c85391df7d90d5ac59
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
package com.ruoyi.dataInterchange.controller;
 
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import com.ruoyi.dataInterchange.api.vo.UPExgMsgTakeEwayBillAckVo;
import com.ruoyi.dataInterchange.dao.UPExgMsgTakeEwayBillAckDao;
import com.ruoyi.dataInterchange.model.UPExgMsgTakeEwayBillAck;
import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.RangeQueryBuilder;
import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.elasticsearch.client.elc.QueryBuilders;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import javax.naming.directory.SearchResult;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
 
/**
 * @author zhibing.pu
 * @Date 2025/4/2 11:36
 */
@RestController
@RequestMapping("/exgMsgTakeEwayBillAck")
public class UPExgMsgTakeEwayBillAckController {
    
    @Resource
    private UPExgMsgTakeEwayBillAckDao upExgMsgTakeEwayBillAckDao;
 
    @Resource
    private ElasticsearchRestTemplate elasticsearchRestTemplate;
    
    
    /**
     * 获取大于给定日期的数据
     *
     * @param createTime
     * @return
     */
    @PostMapping("/findByCreateTimeAfter")
    public R<List<UPExgMsgTakeEwayBillAckVo>> findByCreateTimeAfter(@RequestParam("createTime") Long createTime) {
        List<UPExgMsgTakeEwayBillAckVo> list = new ArrayList<>();
            if (-1 == createTime) {
                //设置排序(排序方式,正序还是倒序,排序的 id)
                Sort sort = Sort.by(Sort.Direction.ASC, "createTime");
                //设置分页(页码,每页显示的条数)
                //当前页码0开始
                int currentPage = 0;
                //每页显示的条数
                int pageSize = 10000;
                PageRequest pageRequest = PageRequest.of(currentPage, pageSize, sort);
            Iterator<UPExgMsgTakeEwayBillAck> iterator = upExgMsgTakeEwayBillAckDao.findAll(pageRequest).iterator();
            if (iterator.hasNext()) {
                UPExgMsgTakeEwayBillAck takeEwayBillAck = iterator.next();
                UPExgMsgTakeEwayBillAckVo vo = new UPExgMsgTakeEwayBillAckVo();
                BeanUtils.copyProperties(takeEwayBillAck, vo);
                list.add(vo);
            }
        } else {
            //查询,获取查询结果
            List<UPExgMsgTakeEwayBillAck> byCreateTimeIsAfter = upExgMsgTakeEwayBillAckDao.findByCreateTimeIsAfter(createTime);
            for (UPExgMsgTakeEwayBillAck searchHit : byCreateTimeIsAfter) {
                UPExgMsgTakeEwayBillAckVo vo = new UPExgMsgTakeEwayBillAckVo();
                BeanUtils.copyProperties(searchHit, vo);
                list.add(vo);
            }
        }
        return R.ok(list);
    }
    
}