PowerJob的UserService工作流程源碼解讀
序
本文主要研究一下PowerJob的UserService
UserService
tech/powerjob/server/core/service/UserService.java
@Service
public class UserService {
@Resource
private UserInfoRepository userInfoRepository;
/**
* 保存/修改 用戶
* @param userInfoDO user
*/
public void save(UserInfoDO userInfoDO) {
userInfoDO.setGmtCreate(new Date());
userInfoDO.setGmtModified(userInfoDO.getGmtCreate());
userInfoRepository.saveAndFlush(userInfoDO);
}
/**
* 根據(jù)用戶ID字符串獲取用戶信息詳細(xì)列表
* @param userIds 逗號(hào)分割的用戶ID信息
* @return 用戶信息詳細(xì)列表
*/
public List<UserInfoDO> fetchNotifyUserList(String userIds) {
if (StringUtils.isEmpty(userIds)) {
return Lists.newLinkedList();
}
// 去重
Set<Long> userIdList = Splitter.on(",").splitToList(userIds).stream().map(Long::valueOf).collect(Collectors.toSet());
List<UserInfoDO> res = userInfoRepository.findByIdIn(Lists.newLinkedList(userIdList));
res.forEach(x -> x.setPassword(null));
return res;
}
}UserService提供了save及fetchNotifyUserList方法,基于UserInfoRepository來(lái)實(shí)現(xiàn)
UserInfoDO
tech/powerjob/server/persistence/remote/model/UserInfoDO.java
@Data
@Entity
@Table(indexes = {
@Index(name = "uidx01_user_info", columnList = "username"),
@Index(name = "uidx02_user_info", columnList = "email")
})
public class UserInfoDO {
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "native")
@GenericGenerator(name = "native", strategy = "native")
private Long id;
private String username;
private String password;
/**
* 手機(jī)號(hào)
*/
private String phone;
/**
* 郵箱地址
*/
private String email;
/**
* webHook
*/
private String webHook;
/**
* 擴(kuò)展字段
*/
private String extra;
private Date gmtCreate;
private Date gmtModified;
}UserInfoDO定義了username、email兩個(gè)唯一鍵
UserInfoRepository
tech/powerjob/server/persistence/remote/repository/UserInfoRepository.java
public interface UserInfoRepository extends JpaRepository<UserInfoDO, Long> {
List<UserInfoDO> findByUsernameLike(String username);
List<UserInfoDO> findByIdIn(List<Long> userIds);
}UserInfoRepository基于JpaRepository,聲明了findByUsernameLike、findByIdIn方法
InstanceManager
tech/powerjob/server/core/instance/InstanceManager.java
private void alert(Long instanceId, String alertContent) {
InstanceInfoDO instanceInfo = instanceInfoRepository.findByInstanceId(instanceId);
JobInfoDO jobInfo;
try {
jobInfo = instanceMetadataService.fetchJobInfoByInstanceId(instanceId);
} catch (Exception e) {
log.warn("[InstanceManager-{}] can't find jobInfo, alarm failed.", instanceId);
return;
}
JobInstanceAlarm content = new JobInstanceAlarm();
BeanUtils.copyProperties(jobInfo, content);
BeanUtils.copyProperties(instanceInfo, content);
List<UserInfoDO> userList = SpringUtils.getBean(UserService.class).fetchNotifyUserList(jobInfo.getNotifyUserIds());
if (!StringUtils.isEmpty(alertContent)) {
content.setResult(alertContent);
}
alarmCenter.alarmFailed(content, AlarmUtils.convertUserInfoList2AlarmTargetList(userList));
}InstanceManager的alert會(huì)根據(jù)jobInfo.getNotifyUserIds()區(qū)查找fetchNotifyUserList出來(lái)的userList,最后通過(guò)alarmCenter.alarmFailed給指定用戶發(fā)送報(bào)警信息
小結(jié)
UserService提供了save及fetchNotifyUserList方法,基于UserInfoRepository來(lái)實(shí)現(xiàn);InstanceManager的alert會(huì)根據(jù)jobInfo.getNotifyUserIds()區(qū)查找fetchNotifyUserList出來(lái)的userList,最后通過(guò)alarmCenter.alarmFailed給指定用戶發(fā)送報(bào)警信息。
以上就是PowerJob的UserService工作流程源碼解讀的詳細(xì)內(nèi)容,更多關(guān)于PowerJob UserService的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Java后端長(zhǎng)時(shí)間無(wú)操作自動(dòng)退出的實(shí)現(xiàn)方式
這篇文章主要介紹了Java后端長(zhǎng)時(shí)間無(wú)操作自動(dòng)退出的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-01-01
java實(shí)現(xiàn)簡(jiǎn)易點(diǎn)菜器
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)簡(jiǎn)易點(diǎn)菜器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-12-12
Springboot集成JWT實(shí)現(xiàn)登錄注冊(cè)的示例代碼
本文主要介紹了Springboot集成JWT實(shí)現(xiàn)登錄注冊(cè)的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2024-06-06
MyBatis-Plus中使用EntityWrappe進(jìn)行列表數(shù)據(jù)倒序設(shè)置方式
這篇文章主要介紹了MyBatis-Plus中使用EntityWrappe進(jìn)行列表數(shù)據(jù)倒序設(shè)置方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-03-03
JavaFx實(shí)現(xiàn)登錄成功跳轉(zhuǎn)到程序主頁(yè)面
這篇文章主要為大家詳細(xì)介紹了JavaFx實(shí)現(xiàn)登錄成功跳轉(zhuǎn)到程序主頁(yè)面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-06-06
springmvc開(kāi)啟異步請(qǐng)求報(bào)錯(cuò)Java code using the Ser
這篇文章主要為大家介紹了springmvc開(kāi)啟異步請(qǐng)求報(bào)錯(cuò)Java code using the Servlet API or解決分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2024-02-02

