mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-10 11:26:50 +08:00
增加同步用户的接口
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
package com.xboe.data.api;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.xboe.account.entity.Account;
|
||||
import com.xboe.account.service.IAccountService;
|
||||
import com.xboe.core.JsonResponse;
|
||||
import com.xboe.core.api.ApiBaseController;
|
||||
import com.xboe.data.dto.UserData;
|
||||
import com.xboe.data.service.IDataUserSyncService;
|
||||
import com.xboe.system.organization.entity.Organization;
|
||||
import com.xboe.system.organization.service.IOrganizationService;
|
||||
import com.xboe.system.user.entity.User;
|
||||
import com.xboe.system.user.service.IUserService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 用户数据同步的处理
|
||||
*
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping(value = "/xboe/data")
|
||||
public class UserDataSyncApi extends ApiBaseController {
|
||||
|
||||
@Autowired
|
||||
IAccountService accountService;
|
||||
|
||||
@Autowired
|
||||
IUserService userService;
|
||||
|
||||
@Autowired
|
||||
IOrganizationService orgService;
|
||||
|
||||
@Autowired
|
||||
IDataUserSyncService service;
|
||||
|
||||
@PostMapping("/user")
|
||||
public JsonResponse<Boolean> syncUser(@RequestBody UserData user) {
|
||||
if (StringUtils.isBlank(user.getId())) {
|
||||
return error("无用户的id");
|
||||
}
|
||||
//清除缓存需要loginName
|
||||
try {
|
||||
//先查询是否存在
|
||||
Account a=accountService.get(user.getId());
|
||||
User u=userService.get(user.getId());
|
||||
Organization org=null;
|
||||
if(a!=null) {
|
||||
//账户只是修改状态
|
||||
a.setDeleted(user.getDeleted());
|
||||
}else {
|
||||
//新账户
|
||||
a=new Account();
|
||||
a.setDeleted(user.getDeleted());
|
||||
a.setSysId(user.getKid());
|
||||
a.setLoginName(user.getCode());
|
||||
a.setAvatar(user.getAvatar());
|
||||
a.setId(user.getId());
|
||||
a.setRegTime(LocalDateTime.now());
|
||||
a.setSysId(user.getKid());
|
||||
a.setStatus(1);
|
||||
}
|
||||
if(u!=null) {
|
||||
//更新部分用户字段
|
||||
u.setDepartId(user.getDepartId());
|
||||
u.setDepartName(user.getDepartName());
|
||||
u.setName(user.getName());
|
||||
u.setUserType(user.getUserType());
|
||||
u.setLearningDuration(user.getLearningDuration());
|
||||
}else {
|
||||
//新建用户
|
||||
u=new User();
|
||||
u.setId(user.getId());
|
||||
u.setDepartId(user.getDepartId());
|
||||
u.setDepartName(user.getDepartName());
|
||||
u.setDynamic(0);
|
||||
u.setGender(u.getGender());
|
||||
u.setName(user.getName());
|
||||
u.setSign("");
|
||||
u.setUserNo(user.getCode());
|
||||
u.setUserType(user.getUserType());
|
||||
u.setSysId(user.getKid());
|
||||
u.setStudyTotal(0);
|
||||
u.setLearningDuration(user.getLearningDuration());
|
||||
if(user.getBandLevel()!=null && user.getBandLevel()>15) {
|
||||
u.setShowHome(false);//band16及以上
|
||||
}else {
|
||||
u.setShowHome(true);//band16以下,及其它无bandLevel的信息
|
||||
}
|
||||
|
||||
}
|
||||
//对机构的判断,不为空时才会处理,为空时不处理
|
||||
if(StringUtils.isNotBlank(user.getDepartId())) {
|
||||
org=orgService.get(user.getDepartId());
|
||||
if(org==null) {
|
||||
org=new Organization();
|
||||
org.setId(user.getDepartId());
|
||||
org.setName(user.getDepartName());
|
||||
org.setDeleted(false);
|
||||
org.setStatus(1);
|
||||
}
|
||||
org.setNamePath(user.getOrgNamePath());
|
||||
|
||||
}
|
||||
service.syncUserFull(a, u, org);
|
||||
|
||||
return success(true);
|
||||
} catch (Exception e) {
|
||||
log.error("同步处理用户错误", e);
|
||||
return error("同步处理用户失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.xboe.data.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 用于同步的用户数据
|
||||
* @author seastar
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
public class UserData {
|
||||
|
||||
/**用户的id*/
|
||||
private String id;
|
||||
|
||||
/**主要是为了兼容之前的使用,新用户可以为空*/
|
||||
private String kid;
|
||||
|
||||
/**用户工号*/
|
||||
private String code;
|
||||
|
||||
/**band的级别*/
|
||||
private Integer bandLevel;
|
||||
|
||||
/**姓名*/
|
||||
private String name;
|
||||
|
||||
/**用户的头像*/
|
||||
private String avatar;
|
||||
|
||||
/**性别 1:男 2:女*/
|
||||
private Integer gender;
|
||||
|
||||
/**学习时长,秒*/
|
||||
private Integer learningDuration;
|
||||
|
||||
/**部门id*/
|
||||
private String departId;
|
||||
|
||||
/**部门名称*/
|
||||
private String departName;
|
||||
|
||||
/**此字段主要是为了人员的显示*/
|
||||
private String orgNamePath;
|
||||
|
||||
/**
|
||||
* 用户类型,1表学员,2表教师,3表管理员
|
||||
*/
|
||||
private Integer userType;
|
||||
|
||||
/**
|
||||
* 是否删除的,如果是删除的,上面所有的字段可以不提供,只提供id就可以了
|
||||
*/
|
||||
private Boolean deleted;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.xboe.data.service;
|
||||
|
||||
import com.xboe.account.entity.Account;
|
||||
import com.xboe.system.organization.entity.Organization;
|
||||
import com.xboe.system.user.entity.User;
|
||||
|
||||
/**
|
||||
* 用户数据的更橷
|
||||
*
|
||||
*/
|
||||
public interface IDataUserSyncService {
|
||||
|
||||
/**
|
||||
* 同步用户,账号,机构等信息
|
||||
* @param a
|
||||
* @param u
|
||||
* @param org
|
||||
* @return
|
||||
*/
|
||||
void syncUserFull(Account a,User u,Organization org);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.xboe.data.service.impl;
|
||||
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.xboe.account.dao.AccountDao;
|
||||
import com.xboe.account.entity.Account;
|
||||
import com.xboe.data.service.IDataUserSyncService;
|
||||
import com.xboe.module.teacher.dao.TeacherDao;
|
||||
import com.xboe.module.teacher.entity.Teacher;
|
||||
import com.xboe.system.organization.dao.OrganizationDao;
|
||||
import com.xboe.system.organization.entity.Organization;
|
||||
import com.xboe.system.user.dao.UserDao;
|
||||
import com.xboe.system.user.entity.User;
|
||||
|
||||
@Service
|
||||
public class DataUserSyncServiceImpl implements IDataUserSyncService{
|
||||
|
||||
@Autowired
|
||||
AccountDao accountDao;
|
||||
|
||||
@Autowired
|
||||
UserDao userDao;
|
||||
|
||||
@Autowired
|
||||
OrganizationDao orgDao;
|
||||
|
||||
@Autowired
|
||||
TeacherDao teacherDao;
|
||||
|
||||
@Override
|
||||
@Transient
|
||||
public void syncUserFull(Account a, User u, Organization org) {
|
||||
accountDao.saveOrUpdate(a);
|
||||
userDao.saveOrUpdate(u);
|
||||
if(org!=null) {
|
||||
orgDao.saveOrUpdate(org);
|
||||
}
|
||||
//老师信息
|
||||
if(u.getUserType()!=null && u.getUserType()==2) {
|
||||
Teacher t = teacherDao.get(u.getId());
|
||||
if(t==null) {
|
||||
t=new Teacher();
|
||||
t.setId(u.getId());
|
||||
t.setDepartId(u.getDepartId());
|
||||
t.setDeleted(false);
|
||||
t.setGender(u.getGender());
|
||||
t.setName(u.getName());
|
||||
t.setStatus(1);
|
||||
t.setWaitStatus(0);
|
||||
t.setUser(u);
|
||||
teacherDao.save(t);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -287,6 +287,7 @@ public class UserServiceImpl implements IUserService {
|
||||
return user.getAccount();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void syncUpdateUser(UserVo uv)throws XaskException{
|
||||
|
||||
Reference in New Issue
Block a user