zhitong.yu
2024-05-11 b72f8f8d58417eb6fb29672d8ac17cfafa46775c
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
package com.hxzk.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hxzk.mapper.KaoQinDao;
import com.hxzk.pojo.TbAchor;
import com.hxzk.pojo.TbKaoqing;
import com.hxzk.pojo.TbTag;
import com.hxzk.service.KaoQinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.List;
 
@Service
public class KaoQinServiceImpl extends ServiceImpl<KaoQinDao, TbKaoqing> implements KaoQinService {
 
    @Autowired
    KaoQinDao kaoQinDao;
 
    @Override
    public PageInfo<TbKaoqing> findAll(Integer page, Integer limit) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        PageHelper.startPage(page, limit);
        LocalDate currentDate = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        String formattedDate = currentDate.format(formatter);
        List<TbKaoqing> cardList = kaoQinDao.findAllKaoQin(formattedDate);
        PageInfo<TbKaoqing> info = new PageInfo<>(cardList);
        return info;
    }
 
    @Override
    public PageInfo<TbKaoqing> findSearch(Integer page, Integer limit, TbKaoqing achor) {
        PageHelper.startPage(page, limit);
        List<TbKaoqing> cardList = null;
        String dateStr = achor.getName();
        String dateStr1 = achor.getBumen();
        SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat outputFormat = new SimpleDateFormat("yyyyMMdd");
        try {
            Date date = inputFormat.parse(dateStr);
            Date date1 = inputFormat.parse(dateStr1);
            String outputDateStr = outputFormat.format(date);
            String outputDateStr1 = outputFormat.format(date1);
            achor.setName(outputDateStr);
            achor.setBumen(outputDateStr1);
            achor.setIntime(dateStr);
            achor.setOuttime(dateStr1);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if (achor.getTagid() == null || achor.getTagid().equals("")) {
            String s = achor.getIntime().split(" ")[0];
            String e = achor.getOuttime().split(" ")[0];
            String[] start = s.split("-");
            String[] end = e.split("-");
            String sql = new String();
            //只根据时间查询
            LocalDate startDate = LocalDate.of(Integer.parseInt(start[0]), Integer.parseInt(start[1]), Integer.parseInt(start[2]));
            LocalDate endDate = LocalDate.of(Integer.parseInt(end[0]), Integer.parseInt(end[1]), Integer.parseInt(end[2]));
            long numOfDaysBetween = ChronoUnit.DAYS.between(startDate, endDate);
            // 计算两个日期之间的天数
            for (int i = 1; i <= numOfDaysBetween; i++) {
                LocalDate date = startDate.plusDays(i);
                String riqi = date.toString().split("-")[0]+date.toString().split("-")[1]+date.toString().split("-")[2];
                sql += " UNION select * from tb_kaoqing_" + riqi+" ";
                achor.setBumen(sql);}
            cardList = kaoQinDao.findSearchTime(achor);
        } else {
            if (achor.getName() == null || achor.getName().equals("")) {
                LocalDate currentDate = LocalDate.now();
                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
                String formattedDate = currentDate.format(formatter);
                achor.setName(formattedDate);
                cardList = kaoQinDao.findSearch(achor);
            } else {
                cardList = kaoQinDao.findSearch(achor);
            }
            //根据时间和输入的姓名进行查询
 
        }
        PageInfo<TbKaoqing> info = new PageInfo<>(cardList);
        return info;
    }
}