package org.springblade.modules.system.service.impl;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import lombok.AllArgsConstructor;
|
import org.springblade.common.cache.SysCache;
|
import org.springblade.common.constant.CommonConstant;
|
import org.springblade.core.log.exception.ServiceException;
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
import org.springblade.core.mp.support.Condition;
|
import org.springblade.core.secure.utils.AuthUtil;
|
import org.springblade.core.tool.utils.DateUtil;
|
import org.springblade.core.tool.utils.DigestUtil;
|
import org.springblade.core.tool.utils.Func;
|
import org.springblade.core.tool.utils.StringUtil;
|
import org.springblade.modules.system.entity.Role;
|
import org.springblade.modules.system.entity.User;
|
import org.springblade.modules.system.entity.UserWx;
|
import org.springblade.modules.system.excel.UserExcel;
|
import org.springblade.modules.system.excel.UserWxExcel;
|
import org.springblade.modules.system.mapper.UserWxMapper;
|
import org.springblade.modules.system.service.IRoleService;
|
import org.springblade.modules.system.service.IUserWxService;
|
import org.springblade.modules.system.vo.UserVO;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.Map;
|
|
@Service
|
@AllArgsConstructor
|
public class UserWxServiceImpl extends BaseServiceImpl<UserWxMapper, UserWx> implements IUserWxService {
|
private final IRoleService roleService;
|
|
@Override
|
public Boolean wxRegister(UserWx user) {
|
|
//密码加密
|
if (Func.isNotEmpty(user.getPassword())) {
|
user.setPassword(DigestUtil.encrypt(user.getPassword()));
|
}
|
|
UserWx params = new UserWx();
|
params.setCardid(user.getCardid());
|
//查看数据库是否有相同身份证号
|
List<UserWx> list = list(Condition.getQueryWrapper(params));
|
if (list.size() > 0) {
|
throw new ServiceException("该身份证号已注册");
|
}
|
|
//注册新用户
|
user.setAccount(user.getPhone());
|
//微信注册角色
|
user.setRoleId("1734015564173127681");
|
//微信注册机构
|
user.setDeptId("1734016112398020609");
|
user.setTenantId("000000");
|
if (StringUtil.isNotBlank(user.getRealName())) {
|
user.setName(user.getRealName());
|
} else {
|
user.setName("微信用户" + user.getPhone());
|
user.setRealName("微信用户" + user.getPhone());
|
}
|
boolean save = save(user);
|
return save;
|
}
|
|
@Override
|
public UserWx getUserWx(String tenantId, String account, String password) {
|
return baseMapper.getUserWx(tenantId, account, password);
|
}
|
|
@Override
|
public IPage<UserVO> selectUserPage(IPage<UserVO> page, User user, Long deptId, String tenantId) {
|
List<Long> deptIdList = SysCache.getDeptChildIds(deptId);
|
List<UserVO> users = baseMapper.selectUserPage(page, user, deptIdList, tenantId);
|
if (users.size() > 0) {
|
//遍历获取部门名称,角色名称
|
users.forEach(userVO -> {
|
//查询当前部门名称及父级部门名称
|
if (null != userVO.getDeptId()) {
|
List<String> list = baseMapper.getDeptName(userVO.getDeptId());
|
if (list.size() > 1) {
|
if (null != list.get(1) && list.get(1) != "") {
|
userVO.setDeptName(list.get(1) + "," + list.get(0));
|
} else {
|
userVO.setDeptName(list.get(0));
|
}
|
}
|
if (list.size() == 1) {
|
userVO.setDeptName(list.get(0));
|
}
|
}
|
//查询角色名称
|
if (null != userVO.getRoleId()) {
|
List<String> asList = Arrays.asList(userVO.getRoleId().split(","));
|
StringBuilder builder = new StringBuilder();
|
asList.forEach(roleIs -> {
|
Role role = roleService.getById(roleIs);
|
if (null != role) {
|
builder.append(role.getRoleName() + ",");
|
}
|
});
|
String substringRoleName = null;
|
if (builder.toString().length() > 0) {
|
substringRoleName = builder.toString().substring(0, builder.toString().length() - 1);
|
}
|
userVO.setRoleName(substringRoleName);
|
}
|
});
|
}
|
return page.setRecords(users);
|
}
|
|
@Override
|
public UserVO getUserDetailById(Long id) {
|
return baseMapper.getUserDetailById(id);
|
}
|
|
@Override
|
public boolean resetPassword(String userIds) {
|
UserWx user = new UserWx();
|
user.setPassword(DigestUtil.encrypt(CommonConstant.DEFAULT_PASSWORD));
|
user.setUpdateTime(DateUtil.now());
|
return this.update(user, Wrappers.<UserWx>update().lambda().in(UserWx::getId, Func.toLongList(userIds)));
|
}
|
|
@Override
|
public boolean removeUser(String userIds) {
|
if (Func.contains(Func.toLongArray(userIds), AuthUtil.getUserId())) {
|
throw new ServiceException("不能删除本账号!");
|
}
|
return deleteLogic(Func.toLongList(userIds));
|
}
|
|
@Override
|
public List<UserWxExcel> exportUser(Map<String, Object> param) {
|
List<UserWxExcel> userList = baseMapper.exportUser(param);
|
return userList;
|
}
|
|
/**
|
* 修改密码
|
* @param userId
|
* @param newPassword
|
* @param oldPassword
|
* @param newPassword1
|
* @return
|
*/
|
@Override
|
public boolean updatePassword(Long userId, String oldPassword, String newPassword, String newPassword1) {
|
UserWx user = getById(userId);
|
if (!newPassword.equals(newPassword1)) {
|
throw new ServiceException("请输入正确的确认密码!");
|
}
|
if (!user.getPassword().equals(DigestUtil.hex(oldPassword))) {
|
throw new ServiceException("原密码不正确!");
|
}
|
return this.update(Wrappers.<UserWx>update().lambda().set(UserWx::getPassword, DigestUtil.hex(newPassword)).eq(UserWx::getId, userId));
|
}
|
}
|