whyclxw
2025-01-16 c967a290ba1865e4859900e1f85ab583fcc5bf58
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
package com.whyc.service;
 
import com.whyc.mapper.CallBack;
import com.whyc.pojo.db_lock_his.LockHis;
import com.whyc.util.ActionUtil;
import com.whyc.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
 
@Service
public class SubTableService {
    @Autowired
    private MybatisSqlExecuteService sqlExecuteService;
    //锁的历史记录总数
    public int getLockHisCount(LockHis his) {
        String sql="SELECT  count(*) as number FROM db_lock_his"+ his.getRecordYear()+" history " +
                " where history.lock_id="+ his.getLockId() ;
        if(his.getStartTime()!=null){
            sql+=" and record_time  >='"+ ThreadLocalUtil.format(his.getStartTime(),1)+"' ";
        }
        if(his.getEndTime()!=null){
            sql+=" and record_time  <='"+ThreadLocalUtil.format(his.getEndTime(),1)+"' ";
        }
        List list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                LinkedList<Object> temp = new LinkedList<>();
                try {
                    while (rs.next())
                        temp.add(rs.getInt("number"));
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                return temp;
            }
        });
        int num =0;
        if(list!=null){
            num= (int) list.get(0);
        }
        return num;
    }
    //锁的历史记录
    public List<LockHis> getBattHisList(LockHis his) {
        String sql="SELECT * FROM db_lock_his"+ his.getRecordYear()+" history " +
                " where history.lock_id="+  his.getLockId() ;
        if(his.getStartTime()!=null){
            sql+=" and record_time  >='"+ ThreadLocalUtil.format(his.getStartTime(),1)+"' ";
        }
        if(his.getEndTime()!=null){
            sql+=" and record_time  <='"+ThreadLocalUtil.format(his.getEndTime(),1)+"' ";
        }
        sql+="  ORDER BY record_time asc  limit "+ his.getLimitStart()+","+ his.getLimitEnd()+" ";
        List<LockHis> list=sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                List list=new ArrayList();
                while (rs.next()){
                    LockHis data=new LockHis();
                    data.setNum(rs.getInt("num"));
                    data.setLockId(rs.getInt("lock_id"));
                    data.setRecordTime(rs.getTimestamp("record_time"));
                    data.setLockState(rs.getInt("lock_state"));
                    data.setUnlockType(rs.getInt("unlock_type"));
                    data.setUnlockId(rs.getString("unlock_id"));
                    list.add(data);
                }
                return list;
            }
        });
        return list;
    }
 
 
}