员工管理、根据状态踢下线
This commit is contained in:
parent
dfb13e28a8
commit
eb6be970fe
@ -14,11 +14,9 @@ public class TenantInterceptor implements HandlerInterceptor {
|
|||||||
public boolean preHandle(@NotNull HttpServletRequest request
|
public boolean preHandle(@NotNull HttpServletRequest request
|
||||||
, @NotNull HttpServletResponse response, @NotNull Object handler){
|
, @NotNull HttpServletResponse response, @NotNull Object handler){
|
||||||
|
|
||||||
//通过 request 去获取租户 ID
|
|
||||||
boolean login = StpUtil.isLogin();
|
boolean login = StpUtil.isLogin();
|
||||||
if (login) {
|
if (login) {
|
||||||
Long tenantId = getTenantIdByReuqest(request);
|
Long tenantId = getTenantIdByReuqest(request);
|
||||||
//设置租户ID到 request 的 attribute
|
|
||||||
request.setAttribute("tenantId", tenantId);
|
request.setAttribute("tenantId", tenantId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,23 @@
|
|||||||
package com.cdzy.staff.controller;
|
package com.cdzy.staff.controller;
|
||||||
|
|
||||||
import com.cdzy.common.enums.Message;
|
import com.cdzy.common.enums.Message;
|
||||||
|
import com.cdzy.common.model.request.PageParam;
|
||||||
import com.cdzy.common.model.response.JsonResult;
|
import com.cdzy.common.model.response.JsonResult;
|
||||||
import com.cdzy.staff.model.dto.StaffInfo;
|
import com.cdzy.staff.model.dto.StaffInfo;
|
||||||
|
import com.cdzy.staff.model.entity.EbikeOperatorStaff;
|
||||||
|
import com.cdzy.staff.model.vo.LoginVo;
|
||||||
import com.cdzy.staff.model.vo.StaffVo;
|
import com.cdzy.staff.model.vo.StaffVo;
|
||||||
import com.cdzy.staff.service.EbikeOperatorStaffService;
|
import com.cdzy.staff.service.EbikeOperatorStaffService;
|
||||||
|
import com.mybatisflex.core.paginate.Page;
|
||||||
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
|
import com.mybatisflex.core.util.StringUtil;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import static com.cdzy.staff.model.entity.table.EbikeOperatorStaffTableDef.EBIKE_OPERATOR_STAFF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 运营商员工账户表 控制层。
|
* 运营商员工账户表 控制层。
|
||||||
*
|
*
|
||||||
@ -33,27 +42,95 @@ public class EbikeOperatorStaffController {
|
|||||||
return JsonResult.success(info);
|
return JsonResult.success(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据账号详情
|
||||||
|
*
|
||||||
|
* @return 运营商员工账户表详情
|
||||||
|
*/
|
||||||
|
@GetMapping("getStaffInfoById")
|
||||||
|
public JsonResult<?> getStaffInfoById(@NotNull(message = "员工ID不能为空") Long staffId) {
|
||||||
|
StaffInfo info = ebikeOperatorStaffService.getStaffInfoById(staffId);
|
||||||
|
return JsonResult.success(info);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 运营商员工登录。
|
* 运营商员工登录。
|
||||||
*
|
*
|
||||||
* @param staffVo 登录信息
|
* @param loginVo 登录信息
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@PostMapping("login")
|
@PostMapping("login")
|
||||||
public JsonResult<?> login(@Validated @RequestBody StaffVo staffVo) {
|
public JsonResult<?> login(@Validated @RequestBody LoginVo loginVo) {
|
||||||
String token = ebikeOperatorStaffService.login(staffVo);
|
String token = ebikeOperatorStaffService.login(loginVo);
|
||||||
return JsonResult.success(Message.LOGIN, token);
|
return JsonResult.success(Message.LOGIN, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 运营商员工添加。
|
* 添加运营商员工。
|
||||||
* `
|
* `
|
||||||
|
*
|
||||||
* @param staffVo 登录信息
|
* @param staffVo 登录信息
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@PostMapping("add")
|
@PostMapping("save")
|
||||||
public JsonResult<?> add(@Validated @RequestBody StaffVo staffVo) {
|
public JsonResult<?> saveStaff(@Validated @RequestBody StaffVo staffVo) {
|
||||||
ebikeOperatorStaffService.add(staffVo);
|
ebikeOperatorStaffService.saveStaff(staffVo);
|
||||||
return JsonResult.success(Message.ADD_SUCCESS);
|
return JsonResult.success(Message.ADD_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改运营商员工。
|
||||||
|
* `
|
||||||
|
*
|
||||||
|
* @param staffVo 登录信息
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@PostMapping("update")
|
||||||
|
public JsonResult<?> update(@Validated @RequestBody StaffVo staffVo) {
|
||||||
|
ebikeOperatorStaffService.updateStaff(staffVo);
|
||||||
|
return JsonResult.success(Message.UPDATE_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除运营商员工。
|
||||||
|
* `
|
||||||
|
*
|
||||||
|
* @param staffId 员工id
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@GetMapping("remove")
|
||||||
|
public JsonResult<?> remove(@NotNull(message = "员工ID不能为空") Long staffId) {
|
||||||
|
ebikeOperatorStaffService.removeStaff(staffId);
|
||||||
|
return JsonResult.success(Message.ADD_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询运营商员工
|
||||||
|
*
|
||||||
|
* @param pageParam 分页参数
|
||||||
|
* @param username 用户名
|
||||||
|
* @param contactPhone 联系电话
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@GetMapping("page")
|
||||||
|
public JsonResult<?> page(PageParam pageParam, String username, String contactPhone) {
|
||||||
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||||
|
.select(
|
||||||
|
EBIKE_OPERATOR_STAFF.STAFF_ID,
|
||||||
|
EBIKE_OPERATOR_STAFF.OPERATOR_ID,
|
||||||
|
EBIKE_OPERATOR_STAFF.STATUS,
|
||||||
|
EBIKE_OPERATOR_STAFF.LAST_LOGIN,
|
||||||
|
EBIKE_OPERATOR_STAFF.UPDATE_BY,
|
||||||
|
EBIKE_OPERATOR_STAFF.UPDATE_TIME,
|
||||||
|
EBIKE_OPERATOR_STAFF.CONTACT_PHONE,
|
||||||
|
EBIKE_OPERATOR_STAFF.CREATE_BY,
|
||||||
|
EBIKE_OPERATOR_STAFF.CREATE_TIME,
|
||||||
|
EBIKE_OPERATOR_STAFF.USERNAME,
|
||||||
|
EBIKE_OPERATOR_STAFF.IS_DELETED
|
||||||
|
)
|
||||||
|
.where(EBIKE_OPERATOR_STAFF.USERNAME.like(username, StringUtil.hasText(username)))
|
||||||
|
.where(EBIKE_OPERATOR_STAFF.CONTACT_PHONE.like(contactPhone, StringUtil.hasText(contactPhone)));
|
||||||
|
Page<EbikeOperatorStaff> page = ebikeOperatorStaffService.page(pageParam.getPage(), queryWrapper);
|
||||||
|
return JsonResult.success(page);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,7 +38,7 @@ public class StaffInfo implements Serializable {
|
|||||||
|
|
||||||
private Boolean isDeleted;
|
private Boolean isDeleted;
|
||||||
|
|
||||||
// private List<EbikeRole> roles;
|
private String contactPhone;
|
||||||
|
|
||||||
private List<String> roleCodes;
|
private List<String> roleCodes;
|
||||||
|
|
||||||
|
|||||||
@ -37,8 +37,10 @@ public class EbikeOperatorStaff implements Serializable {
|
|||||||
|
|
||||||
private String salt;
|
private String salt;
|
||||||
|
|
||||||
|
@Column(tenantId = true)
|
||||||
private Long operatorId;
|
private Long operatorId;
|
||||||
|
|
||||||
|
@Column(onInsertValue = "1")
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
private LocalDateTime lastLogin;
|
private LocalDateTime lastLogin;
|
||||||
@ -59,4 +61,6 @@ public class EbikeOperatorStaff implements Serializable {
|
|||||||
@Column(isLogicDelete = true)
|
@Column(isLogicDelete = true)
|
||||||
private Boolean isDeleted;
|
private Boolean isDeleted;
|
||||||
|
|
||||||
|
private String contactPhone;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,6 +44,7 @@ public class EbikeRole implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 所属运营商
|
* 所属运营商
|
||||||
*/
|
*/
|
||||||
|
@Column(tenantId = true)
|
||||||
private Long operatorId;
|
private Long operatorId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -0,0 +1,21 @@
|
|||||||
|
package com.cdzy.staff.model.vo;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class LoginVo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "用户名不能为空")
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "密码不能为空")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,15 +1,48 @@
|
|||||||
package com.cdzy.staff.model.vo;
|
package com.cdzy.staff.model.vo;
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import jakarta.validation.constraints.Pattern;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class StaffVo {
|
public class StaffVo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 员工id
|
||||||
|
*/
|
||||||
|
private Long staffId;
|
||||||
|
|
||||||
|
private List<Long> roleIds;
|
||||||
|
|
||||||
|
@NotNull(message = "用户启用状态不能为空")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 运营商ID
|
||||||
|
*/
|
||||||
|
@NotNull(message = "运营ID不能为空")
|
||||||
|
private Long operatorId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
@NotBlank(message = "用户名不能为空")
|
@NotBlank(message = "用户名不能为空")
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
@NotBlank(message = "密码不能为空")
|
@NotBlank(message = "密码不能为空")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 联系电话
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "运营商联系手机号不能为空")
|
||||||
|
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "联系手机号格式错误")
|
||||||
|
private String contactPhone;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.cdzy.staff.service;
|
package com.cdzy.staff.service;
|
||||||
|
|
||||||
import com.cdzy.staff.model.dto.StaffInfo;
|
import com.cdzy.staff.model.dto.StaffInfo;
|
||||||
|
import com.cdzy.staff.model.vo.LoginVo;
|
||||||
import com.cdzy.staff.model.vo.StaffVo;
|
import com.cdzy.staff.model.vo.StaffVo;
|
||||||
import com.mybatisflex.core.service.IService;
|
import com.mybatisflex.core.service.IService;
|
||||||
import com.cdzy.staff.model.entity.EbikeOperatorStaff;
|
import com.cdzy.staff.model.entity.EbikeOperatorStaff;
|
||||||
@ -13,9 +14,15 @@ import com.cdzy.staff.model.entity.EbikeOperatorStaff;
|
|||||||
*/
|
*/
|
||||||
public interface EbikeOperatorStaffService extends IService<EbikeOperatorStaff> {
|
public interface EbikeOperatorStaffService extends IService<EbikeOperatorStaff> {
|
||||||
|
|
||||||
String login(StaffVo staffVo);
|
String login(LoginVo loginVo);
|
||||||
|
|
||||||
StaffInfo getStaffInfo();
|
StaffInfo getStaffInfo();
|
||||||
|
|
||||||
void add(StaffVo staffVo);
|
void saveStaff(StaffVo staffVo);
|
||||||
|
|
||||||
|
void updateStaff(StaffVo staffVo);
|
||||||
|
|
||||||
|
void removeStaff(Long staffId);
|
||||||
|
|
||||||
|
StaffInfo getStaffInfoById(Long staffId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,10 +3,13 @@ package com.cdzy.staff.service.impl;
|
|||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import com.cdzy.common.ex.EbikeException;
|
import com.cdzy.common.ex.EbikeException;
|
||||||
import com.cdzy.common.utils.SHA256WithSaltUtil;
|
import com.cdzy.common.utils.SHA256WithSaltUtil;
|
||||||
|
import com.cdzy.staff.mapper.EbikeStaffRoleMapper;
|
||||||
import com.cdzy.staff.model.dto.StaffInfo;
|
import com.cdzy.staff.model.dto.StaffInfo;
|
||||||
import com.cdzy.staff.model.entity.EbikeOperatorStaff;
|
import com.cdzy.staff.model.entity.EbikeOperatorStaff;
|
||||||
import com.cdzy.staff.mapper.EbikeOperatorStaffMapper;
|
import com.cdzy.staff.mapper.EbikeOperatorStaffMapper;
|
||||||
import com.cdzy.staff.model.entity.EbikeRole;
|
import com.cdzy.staff.model.entity.EbikeRole;
|
||||||
|
import com.cdzy.staff.model.entity.EbikeStaffRole;
|
||||||
|
import com.cdzy.staff.model.vo.LoginVo;
|
||||||
import com.cdzy.staff.service.EbikeOperatorStaffService;
|
import com.cdzy.staff.service.EbikeOperatorStaffService;
|
||||||
import com.cdzy.staff.model.vo.StaffVo;
|
import com.cdzy.staff.model.vo.StaffVo;
|
||||||
import com.cdzy.staff.service.EbikeRoleService;
|
import com.cdzy.staff.service.EbikeRoleService;
|
||||||
@ -14,6 +17,7 @@ import com.mybatisflex.core.query.QueryWrapper;
|
|||||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -37,16 +41,21 @@ public class EbikeOperatorStaffServiceImpl extends ServiceImpl<EbikeOperatorStaf
|
|||||||
@Resource
|
@Resource
|
||||||
private EbikeRoleService roleService;
|
private EbikeRoleService roleService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private EbikeStaffRoleMapper staffRoleMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String login(StaffVo staffVo) {
|
public String login(LoginVo loginVo) {
|
||||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||||
.where(EBIKE_OPERATOR_STAFF.USERNAME.eq(staffVo.getUsername()));
|
.where(EBIKE_OPERATOR_STAFF.USERNAME.eq(loginVo.getUsername()));
|
||||||
EbikeOperatorStaff ebikeOperatorStaff = staffMapper.selectOneByQuery(queryWrapper);
|
EbikeOperatorStaff ebikeOperatorStaff = staffMapper.selectOneByQuery(queryWrapper);
|
||||||
if (ebikeOperatorStaff == null) {
|
if (ebikeOperatorStaff == null) {
|
||||||
throw new EbikeException("用户名错误");
|
throw new EbikeException("用户名错误");
|
||||||
|
} else if (ebikeOperatorStaff.getStatus() == 2) {
|
||||||
|
throw new EbikeException("该账户已被禁用");
|
||||||
} else {
|
} else {
|
||||||
String salt = ebikeOperatorStaff.getSalt();
|
String salt = ebikeOperatorStaff.getSalt();
|
||||||
String password = staffVo.getPassword();
|
String password = loginVo.getPassword();
|
||||||
password = SHA256WithSaltUtil.encrypt(password, salt);
|
password = SHA256WithSaltUtil.encrypt(password, salt);
|
||||||
boolean equals = ebikeOperatorStaff.getPassword().equals(password);
|
boolean equals = ebikeOperatorStaff.getPassword().equals(password);
|
||||||
if (!equals) {
|
if (!equals) {
|
||||||
@ -67,7 +76,7 @@ public class EbikeOperatorStaffServiceImpl extends ServiceImpl<EbikeOperatorStaf
|
|||||||
EBIKE_OPERATOR_STAFF.STAFF_ID, EBIKE_OPERATOR_STAFF.OPERATOR_ID,
|
EBIKE_OPERATOR_STAFF.STAFF_ID, EBIKE_OPERATOR_STAFF.OPERATOR_ID,
|
||||||
EBIKE_OPERATOR_STAFF.USERNAME, EBIKE_OPERATOR_STAFF.CREATE_BY, EBIKE_OPERATOR_STAFF.CREATE_TIME,
|
EBIKE_OPERATOR_STAFF.USERNAME, EBIKE_OPERATOR_STAFF.CREATE_BY, EBIKE_OPERATOR_STAFF.CREATE_TIME,
|
||||||
EBIKE_OPERATOR_STAFF.UPDATE_BY, EBIKE_OPERATOR_STAFF.UPDATE_TIME,
|
EBIKE_OPERATOR_STAFF.UPDATE_BY, EBIKE_OPERATOR_STAFF.UPDATE_TIME,
|
||||||
EBIKE_OPERATOR_STAFF.LAST_LOGIN, EBIKE_OPERATOR_STAFF.STATUS
|
EBIKE_OPERATOR_STAFF.LAST_LOGIN, EBIKE_OPERATOR_STAFF.STATUS,EBIKE_OPERATOR_STAFF.CONTACT_PHONE
|
||||||
)
|
)
|
||||||
.where(EBIKE_OPERATOR_STAFF.STAFF_ID.eq(loginId));
|
.where(EBIKE_OPERATOR_STAFF.STAFF_ID.eq(loginId));
|
||||||
StaffInfo info = staffMapper.selectOneByQueryAs(queryWrapper, StaffInfo.class);
|
StaffInfo info = staffMapper.selectOneByQueryAs(queryWrapper, StaffInfo.class);
|
||||||
@ -88,17 +97,117 @@ public class EbikeOperatorStaffServiceImpl extends ServiceImpl<EbikeOperatorStaf
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(StaffVo staffVo) {
|
@Transactional
|
||||||
|
public void saveStaff(StaffVo staffVo) {
|
||||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||||
.where(EBIKE_OPERATOR_STAFF.USERNAME.eq(staffVo.getUsername()));
|
.where(EBIKE_OPERATOR_STAFF.USERNAME.eq(staffVo.getUsername()));
|
||||||
EbikeOperatorStaff ebikeOperatorStaff = staffMapper.selectOneByQuery(queryWrapper);
|
EbikeOperatorStaff ebikeOperatorStaff = staffMapper.selectOneByQuery(queryWrapper);
|
||||||
if (ebikeOperatorStaff == null) {
|
if (ebikeOperatorStaff != null) {
|
||||||
throw new EbikeException("用户名错误");
|
throw new EbikeException("用户名错误");
|
||||||
} else {
|
} else {
|
||||||
String salt = SHA256WithSaltUtil.generateSalt();
|
String salt = SHA256WithSaltUtil.generateSalt();
|
||||||
String password = staffVo.getPassword();
|
String password = staffVo.getPassword();
|
||||||
password = SHA256WithSaltUtil.encrypt(password, salt);
|
password = SHA256WithSaltUtil.encrypt(password, salt);
|
||||||
//TODO:添加用户账号密码与对应权限
|
EbikeOperatorStaff staff = EbikeOperatorStaff.builder()
|
||||||
|
.operatorId(staffVo.getOperatorId())
|
||||||
|
.username(staffVo.getUsername())
|
||||||
|
.password(password)
|
||||||
|
.salt(salt)
|
||||||
|
.createBy(StpUtil.getLoginIdAsLong())
|
||||||
|
.contactPhone(staffVo.getContactPhone())
|
||||||
|
.build();
|
||||||
|
staffMapper.insert(staff);
|
||||||
|
if (staffVo.getRoleIds() != null && !staffVo.getRoleIds().isEmpty()){
|
||||||
|
List<EbikeStaffRole> list = staffVo.getRoleIds().stream().map(roleId -> EbikeStaffRole.builder()
|
||||||
|
.roleId(roleId)
|
||||||
|
.staffId(staff.getStaffId())
|
||||||
|
.createBy(StpUtil.getLoginIdAsLong())
|
||||||
|
.build()).toList();
|
||||||
|
staffRoleMapper.insertBatch(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void updateStaff(StaffVo staffVo) {
|
||||||
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||||
|
.where(EBIKE_OPERATOR_STAFF.STAFF_ID.eq(staffVo.getStaffId()));
|
||||||
|
EbikeOperatorStaff ebikeOperatorStaff = staffMapper.selectOneByQuery(queryWrapper);
|
||||||
|
if (ebikeOperatorStaff == null) {
|
||||||
|
throw new EbikeException("员工ID错误");
|
||||||
|
} else {
|
||||||
|
String salt = SHA256WithSaltUtil.generateSalt();
|
||||||
|
String password = staffVo.getPassword();
|
||||||
|
password = SHA256WithSaltUtil.encrypt(password, salt);
|
||||||
|
ebikeOperatorStaff.setUsername(staffVo.getUsername());
|
||||||
|
ebikeOperatorStaff.setPassword(password);
|
||||||
|
ebikeOperatorStaff.setSalt(salt);
|
||||||
|
ebikeOperatorStaff.setStatus(staffVo.getStatus());
|
||||||
|
ebikeOperatorStaff.setUpdateBy(StpUtil.getLoginIdAsLong());
|
||||||
|
ebikeOperatorStaff.setContactPhone(staffVo.getContactPhone());
|
||||||
|
//禁用后踢下线
|
||||||
|
if (staffVo.getStatus() == 2){
|
||||||
|
StpUtil.logout(staffVo.getStaffId());
|
||||||
|
}
|
||||||
|
staffMapper.update(ebikeOperatorStaff);
|
||||||
|
|
||||||
|
queryWrapper.clear();
|
||||||
|
queryWrapper.where(EBIKE_STAFF_ROLE.STAFF_ID.eq(ebikeOperatorStaff.getStaffId()));
|
||||||
|
staffRoleMapper.deleteByQuery(queryWrapper);
|
||||||
|
if (staffVo.getRoleIds() != null && !staffVo.getRoleIds().isEmpty()) {
|
||||||
|
List<EbikeStaffRole> list = staffVo.getRoleIds().stream().distinct().map(roleId -> EbikeStaffRole.builder()
|
||||||
|
.roleId(roleId)
|
||||||
|
.staffId(ebikeOperatorStaff.getStaffId())
|
||||||
|
.createBy(StpUtil.getLoginIdAsLong())
|
||||||
|
.build()).toList();
|
||||||
|
staffRoleMapper.insertBatch(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void removeStaff(Long staffId) {
|
||||||
|
checkAdmin(staffId);
|
||||||
|
QueryWrapper queryWrapper = QueryWrapper.create().from(EBIKE_ROLE)
|
||||||
|
.where(EBIKE_STAFF_ROLE.STAFF_ID.eq(staffId));
|
||||||
|
staffRoleMapper.deleteByQuery(queryWrapper);
|
||||||
|
//踢下线
|
||||||
|
StpUtil.logout(staffId);
|
||||||
|
staffMapper.deleteById(staffId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StaffInfo getStaffInfoById(Long staffId) {
|
||||||
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||||
|
.select(
|
||||||
|
EBIKE_OPERATOR_STAFF.STAFF_ID, EBIKE_OPERATOR_STAFF.OPERATOR_ID,
|
||||||
|
EBIKE_OPERATOR_STAFF.USERNAME, EBIKE_OPERATOR_STAFF.CREATE_BY, EBIKE_OPERATOR_STAFF.CREATE_TIME,
|
||||||
|
EBIKE_OPERATOR_STAFF.UPDATE_BY, EBIKE_OPERATOR_STAFF.UPDATE_TIME,
|
||||||
|
EBIKE_OPERATOR_STAFF.LAST_LOGIN, EBIKE_OPERATOR_STAFF.STATUS,EBIKE_OPERATOR_STAFF.CONTACT_PHONE
|
||||||
|
)
|
||||||
|
.where(EBIKE_OPERATOR_STAFF.STAFF_ID.eq(staffId));
|
||||||
|
StaffInfo info = staffMapper.selectOneByQueryAs(queryWrapper, StaffInfo.class);
|
||||||
|
queryWrapper.clear();
|
||||||
|
queryWrapper
|
||||||
|
.from(EBIKE_ROLE)
|
||||||
|
.leftJoin(EBIKE_STAFF_ROLE).on(EBIKE_STAFF_ROLE.ROLE_ID.eq(EBIKE_ROLE.ROLE_ID))
|
||||||
|
.where(EBIKE_STAFF_ROLE.STAFF_ID.eq(staffId));
|
||||||
|
List<EbikeRole> list = roleService.list(queryWrapper);
|
||||||
|
info.setRoles(list);
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkAdmin(Long staffId) {
|
||||||
|
QueryWrapper queryWrapper = QueryWrapper.create().from(EBIKE_ROLE)
|
||||||
|
.leftJoin(EBIKE_STAFF_ROLE).on(EBIKE_STAFF_ROLE.ROLE_ID.eq(EBIKE_ROLE.ROLE_ID))
|
||||||
|
.where(EBIKE_STAFF_ROLE.STAFF_ID.eq(staffId));
|
||||||
|
List<EbikeRole> roles = roleService.list(queryWrapper);
|
||||||
|
for (EbikeRole ebikeRole : roles) {
|
||||||
|
if (ebikeRole.getSysAdmin()) {
|
||||||
|
throw new EbikeException("超级管理员不可删除");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user