AccountDao.java
3.52 KB
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
package cn.fw.freya.dao;
import cn.fw.freya.model.data.Account;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
/**
* @author kurisu
*/
@Repository
public interface AccountDao extends JpaRepository<Account, Long> {
/**
* 删除指定账号
*
* @param accountNo
* @param value
*/
@Transactional(rollbackFor = Exception.class)
@Modifying
@Query("delete from Account a where a.accountNo = ?1 and a.type = ?2")
void deleteByAccountNoAndType(String accountNo, Integer value);
/**
* 查询账号
*
* @param accountNo
* @param type
* @return
*/
@Query("select a from Account a where a.accountNo = ?1 and a.type = ?2 ")
Account findByAccountNoAndType(String accountNo, Integer type);
/**
* 随机获取一个账号
*
* @param type
* @return
*/
@Query(nativeQuery = true, value = "select * from `account` where cookies_status = true and `type` = ?1 order by rand() limit 1;")
List<Account> findRandomByAndType(Integer type);
/**
* 获取所有快手账号
*
* @return
*/
@Query(nativeQuery = true, value = "select * from `account` where cookies_status = true and `type` = 1;")
List<Account> getAllKSAccount();
/**
* 删除指定类型的账号
*
* @param value
*/
@Transactional(rollbackFor = Exception.class)
@Modifying
@Query("delete from Account a where a.type = ?1")
void deleteByType(Integer value);
/**
* 查询未抓取数据的账号
*
* @return
*/
@Query(nativeQuery = true, value = "select * from `account` where cookies_status = true and (done = false or report_date is null or fans_cnt is null) order by rand() limit 512;")
List<Account> findNotUseAccount();
/**
* 更新账户信息
*
* @param id 账户id
* @param accountName 账户名
* @param fansCnt 账户粉丝数
* @return
*/
@Transactional(rollbackFor = Exception.class)
@Modifying
@Query("update Account a set a.accountName = ?2, a.fansCnt = ?3, a.reportDate = ?4 where a.id = ?1")
int updateMsg(Long id, String accountName, int fansCnt, Date reportDate);
/**
* 获取今天上报的粉丝数据
*
* @param accountNo 账户号
* @param type 账户类型
* @param reportDate 上报日期
* @return
*/
@Query("select a from Account a where a.accountNo = ?1 and a.type = ?2 and a.reportDate >= ?3")
List<Account> getHasReportDate(String accountNo, Integer type, Date reportDate);
/**
* 更新账户cookies状态
*
* @param accountNo
* @param type
* @param cookiesStatus
*/
@Transactional(rollbackFor = Exception.class)
@Modifying
@Query("update Account a set a.cookiesStatus = ?3 where a.accountNo = ?1 and a.type = ?2")
void updateAccountCookiesStatus(String accountNo, Integer type, boolean cookiesStatus);
/**
* 设置账户状态为未完成
*
* @param accountNo
*/
@Modifying
@Query("update Account a set a.done = false where a.accountNo = ?1")
void setAccountUndone(String accountNo);
}