mirror of
https://gitee.com/dromara/MaxKey.git
synced 2026-05-14 12:32:09 +08:00
kafka support fix
This commit is contained in:
@@ -60,6 +60,8 @@ public class Accounts extends JpaBaseEntity implements Serializable {
|
||||
private String relatedUsername;
|
||||
@Column
|
||||
private String relatedPassword;
|
||||
|
||||
UserInfo userInfo;
|
||||
|
||||
public Accounts() {
|
||||
super();
|
||||
@@ -146,6 +148,14 @@ public class Accounts extends JpaBaseEntity implements Serializable {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public UserInfo getUserInfo() {
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
public void setUserInfo(UserInfo userInfo) {
|
||||
this.userInfo = userInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AppAccounts [uid=" + uid + ", username=" + username + ", displayName=" + displayName + ", appId="
|
||||
|
||||
@@ -89,6 +89,8 @@ public class Organizations extends JpaBaseEntity implements Serializable {
|
||||
private String extId;
|
||||
@Column
|
||||
private String extParentId;
|
||||
|
||||
private int isPrimary = 0;
|
||||
|
||||
public Organizations() {
|
||||
//
|
||||
@@ -322,7 +324,15 @@ public class Organizations extends JpaBaseEntity implements Serializable {
|
||||
this.extParentId = extParentId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIsPrimary() {
|
||||
return isPrimary;
|
||||
}
|
||||
|
||||
public void setIsPrimary(int isPrimary) {
|
||||
this.isPrimary = isPrimary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("Organizations [id=");
|
||||
|
||||
@@ -21,6 +21,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
@@ -258,7 +260,9 @@ public class UserInfo extends JpaBaseEntity {
|
||||
@Column
|
||||
String description;
|
||||
|
||||
List<Organizations> depts;
|
||||
|
||||
List<UserInfoAdjoint> adjoints;
|
||||
|
||||
public static class ONLINE {
|
||||
// 在线
|
||||
@@ -1240,7 +1244,23 @@ public class UserInfo extends JpaBaseEntity {
|
||||
this.userState = userState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Organizations> getDepts() {
|
||||
return depts;
|
||||
}
|
||||
|
||||
public void setDepts(List<Organizations> depts) {
|
||||
this.depts = depts;
|
||||
}
|
||||
|
||||
public List<UserInfoAdjoint> getAdjoints() {
|
||||
return adjoints;
|
||||
}
|
||||
|
||||
public void setAdjoints(List<UserInfoAdjoint> adjoints) {
|
||||
this.adjoints = adjoints;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("UserInfo [id=");
|
||||
|
||||
@@ -47,6 +47,10 @@ public class KafkaPersistService {
|
||||
this.kafkaTemplate = kafkaTemplate;
|
||||
}
|
||||
|
||||
public ApplicationConfig getApplicationConfig() {
|
||||
return applicationConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* send msg to kafka
|
||||
* @param topic kafka TOPIC
|
||||
|
||||
@@ -17,9 +17,14 @@
|
||||
|
||||
package org.maxkey.persistence.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
import org.apache.mybatis.jpa.persistence.IJpaBaseMapper;
|
||||
import org.maxkey.entity.Organizations;
|
||||
import org.maxkey.entity.UserInfo;
|
||||
import org.maxkey.entity.UserInfoAdjoint;
|
||||
|
||||
|
||||
/**
|
||||
@@ -59,8 +64,14 @@ public interface UserInfoMapper extends IJpaBaseMapper<UserInfo>{
|
||||
public int changeMobile(UserInfo userInfo);
|
||||
|
||||
public int updateProfile(UserInfo userInfo);
|
||||
|
||||
public List<Organizations> loadDeptsByUserId(String userId);
|
||||
|
||||
public List<UserInfoAdjoint> loadAdjointsByUserId(String userId);
|
||||
|
||||
@Select("select * from mxk_userinfo where email = #{value} or mobile= #{value}")
|
||||
public UserInfo queryUserInfoByEmailMobile(String emailMobile);
|
||||
|
||||
|
||||
@Update("update mxk_userinfo set gridlist = #{gridList} where id = #{id}")
|
||||
public int updateGridList(UserInfo userInfo) ;
|
||||
}
|
||||
|
||||
@@ -19,12 +19,23 @@ package org.maxkey.persistence.service;
|
||||
|
||||
import org.apache.mybatis.jpa.persistence.JpaBaseService;
|
||||
import org.maxkey.entity.Accounts;
|
||||
import org.maxkey.entity.UserInfo;
|
||||
import org.maxkey.persistence.kafka.KafkaIdentityAction;
|
||||
import org.maxkey.persistence.kafka.KafkaIdentityTopic;
|
||||
import org.maxkey.persistence.kafka.KafkaPersistService;
|
||||
import org.maxkey.persistence.mapper.AccountsMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class AccountsService extends JpaBaseService<Accounts>{
|
||||
|
||||
@Autowired
|
||||
KafkaPersistService kafkaPersistService;
|
||||
|
||||
@Autowired
|
||||
UserInfoService userInfoService;
|
||||
|
||||
public AccountsService() {
|
||||
super(AccountsMapper.class);
|
||||
}
|
||||
@@ -38,4 +49,55 @@ public class AccountsService extends JpaBaseService<Accounts>{
|
||||
return (AccountsMapper)super.getMapper();
|
||||
}
|
||||
|
||||
|
||||
public boolean insert(Accounts account) {
|
||||
if (super.insert(account)) {
|
||||
if(kafkaPersistService.getApplicationConfig().isKafkaSupport()) {
|
||||
UserInfo loadUserInfo = userInfoService.loadUserRelated(account.getUid());
|
||||
account.setUserInfo(loadUserInfo);
|
||||
kafkaPersistService.send(
|
||||
KafkaIdentityTopic.ACCOUNT_TOPIC,
|
||||
account,
|
||||
KafkaIdentityAction.CREATE_ACTION);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean update(Accounts account) {
|
||||
if (super.update(account)) {
|
||||
if(kafkaPersistService.getApplicationConfig().isKafkaSupport()) {
|
||||
UserInfo loadUserInfo = userInfoService.loadUserRelated(account.getUid());
|
||||
account.setUserInfo(loadUserInfo);
|
||||
kafkaPersistService.send(
|
||||
KafkaIdentityTopic.ACCOUNT_TOPIC,
|
||||
account,
|
||||
KafkaIdentityAction.UPDATE_ACTION);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean remove(String id) {
|
||||
Accounts account = this.get(id);
|
||||
if (super.remove(id)) {
|
||||
UserInfo loadUserInfo = null;
|
||||
if(kafkaPersistService.getApplicationConfig().isKafkaSupport()) {
|
||||
loadUserInfo = userInfoService.loadUserRelated(account.getUid());
|
||||
account.setUserInfo(loadUserInfo);
|
||||
kafkaPersistService.send(
|
||||
KafkaIdentityTopic.ACCOUNT_TOPIC,
|
||||
account,
|
||||
KafkaIdentityAction.DELETE_ACTION);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -68,7 +68,6 @@ import com.google.common.collect.Lists;
|
||||
public class UserInfoService extends JpaBaseService<UserInfo> {
|
||||
final static Logger _logger = LoggerFactory.getLogger(UserInfoService.class);
|
||||
|
||||
final static String UPDATE_GRIDLIST_SQL = "UPDATE MXK_USERINFO SET GRIDLIST = ? WHERE ID = ?";
|
||||
@Autowired
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
@@ -96,10 +95,14 @@ public class UserInfoService extends JpaBaseService<UserInfo> {
|
||||
public boolean insert(UserInfo userInfo) {
|
||||
userInfo = passwordEncoder(userInfo);
|
||||
if (super.insert(userInfo)) {
|
||||
kafkaPersistService.send(
|
||||
KafkaIdentityTopic.USERINFO_TOPIC,
|
||||
userInfo,
|
||||
KafkaIdentityAction.CREATE_ACTION);
|
||||
if(kafkaPersistService.getApplicationConfig().isKafkaSupport()) {
|
||||
UserInfo loadUserInfo = loadUserRelated(userInfo.getId());
|
||||
kafkaPersistService.send(
|
||||
KafkaIdentityTopic.USERINFO_TOPIC,
|
||||
loadUserInfo,
|
||||
KafkaIdentityAction.CREATE_ACTION);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -109,11 +112,13 @@ public class UserInfoService extends JpaBaseService<UserInfo> {
|
||||
public boolean update(UserInfo userInfo) {
|
||||
userInfo = passwordEncoder(userInfo);
|
||||
if (super.update(userInfo)) {
|
||||
kafkaPersistService.send(
|
||||
KafkaIdentityTopic.USERINFO_TOPIC,
|
||||
userInfo,
|
||||
KafkaIdentityAction.UPDATE_ACTION);
|
||||
|
||||
if(kafkaPersistService.getApplicationConfig().isKafkaSupport()) {
|
||||
UserInfo loadUserInfo = loadUserRelated(userInfo.getId());
|
||||
kafkaPersistService.send(
|
||||
KafkaIdentityTopic.USERINFO_TOPIC,
|
||||
loadUserInfo,
|
||||
KafkaIdentityAction.UPDATE_ACTION);
|
||||
}
|
||||
changePasswordProvisioning(userInfo);
|
||||
return true;
|
||||
}
|
||||
@@ -121,23 +126,33 @@ public class UserInfoService extends JpaBaseService<UserInfo> {
|
||||
}
|
||||
|
||||
public boolean delete(UserInfo userInfo) {
|
||||
UserInfo loadUserInfo = null;
|
||||
if(kafkaPersistService.getApplicationConfig().isKafkaSupport()) {
|
||||
loadUserInfo = loadUserRelated(userInfo.getId());
|
||||
}
|
||||
|
||||
if( super.delete(userInfo)){
|
||||
kafkaPersistService.send(
|
||||
KafkaIdentityTopic.USERINFO_TOPIC,
|
||||
userInfo,
|
||||
loadUserInfo,
|
||||
KafkaIdentityAction.DELETE_ACTION);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public UserInfo loadUserRelated(String userId) {
|
||||
UserInfo loadUserInfo =this.get(userId);
|
||||
loadUserInfo.setDepts(getMapper().loadDeptsByUserId(userId));
|
||||
loadUserInfo.setAdjoints(getMapper().loadAdjointsByUserId(userId));
|
||||
return loadUserInfo;
|
||||
}
|
||||
|
||||
public boolean updateGridList(String gridList) {
|
||||
try {
|
||||
if (gridList != null && !gridList.equals("")) {
|
||||
int intGridList = Integer.parseInt(gridList);
|
||||
jdbcTemplate.update(UPDATE_GRIDLIST_SQL, intGridList,
|
||||
WebContext.getUserInfo().getId());
|
||||
WebContext.getUserInfo().setGridList(intGridList);
|
||||
WebContext.getUserInfo().setGridList(Integer.parseInt(gridList));
|
||||
getMapper().updateGridList(WebContext.getUserInfo());
|
||||
}
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -249,4 +249,23 @@
|
||||
id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="loadDeptsByUserId" parameterType="string" resultType="Organizations">
|
||||
select o.* , 1 isPrimary from mxk_organizations o,mxk_userinfo u
|
||||
where o.id=u.departmentid
|
||||
and u.id=#{value}
|
||||
|
||||
union all
|
||||
|
||||
select o.* , 0 isPrimary from mxk_organizations o,mxk_userinfo_adjunct ua
|
||||
where o.id=ua.departmentid
|
||||
and ua.userid=#{value}
|
||||
</select>
|
||||
|
||||
<select id="loadAdjointsByUserId" parameterType="string" resultType="UserInfoAdjoint">
|
||||
select
|
||||
*
|
||||
from mxk_userinfo_adjunct
|
||||
where userid=#{value}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user