| | |
| | | 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.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; |
| | | |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class UserWxServiceImpl extends BaseServiceImpl<UserWxMapper, UserWx> implements IUserWxService { |
| | | private final IRoleService roleService; |
| | | |
| | | @Override |
| | | public Boolean wxRegister(UserWx user) { |
| | | |
| | |
| | | params.setCardid(user.getCardid()); |
| | | //查看数据库是否有相同身份证号 |
| | | List<UserWx> list = list(Condition.getQueryWrapper(params)); |
| | | if (list.size()>0){ |
| | | if (list.size() > 0) { |
| | | throw new ServiceException("该身份证号已注册"); |
| | | } |
| | | |
| | |
| | | //微信注册机构 |
| | | user.setDeptId("1734016112398020609"); |
| | | user.setTenantId("000000"); |
| | | if (StringUtil.isNotBlank(user.getRealName())){ |
| | | if (StringUtil.isNotBlank(user.getRealName())) { |
| | | user.setName(user.getRealName()); |
| | | }else{ |
| | | user.setName("微信用户"+user.getPhone()); |
| | | user.setRealName("微信用户"+user.getPhone()); |
| | | } else { |
| | | user.setName("微信用户" + user.getPhone()); |
| | | user.setRealName("微信用户" + user.getPhone()); |
| | | } |
| | | boolean save = save(user); |
| | | return save; |
| | |
| | | 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)); |
| | | } |
| | | } |