| | |
| | | package cn.huge.module.ctuser.service; |
| | | |
| | | import cn.huge.base.common.bo.R; |
| | | import cn.huge.base.common.bo.ReturnBO; |
| | | import cn.huge.base.common.exception.ServiceException; |
| | | import cn.huge.base.common.utils.*; |
| | |
| | | import cn.huge.module.client.api.impl.UtilsClientImpl; |
| | | import cn.huge.module.ctuser.dao.mapper.CtAccountMapper; |
| | | import cn.huge.module.ctuser.domain.po.CtAccount; |
| | | import cn.huge.module.ctuser.domain.po.CtUnit; |
| | | import cn.huge.module.ctuser.domain.po.CtUser; |
| | | import cn.huge.module.ctuser.domain.po.CtUserole; |
| | | import cn.huge.module.ctuser.dto.CtAccountLoginDTO; |
| | | import cn.huge.module.ctuser.dto.CtCipherDTO; |
| | | import cn.huge.module.ctuser.dto.CtUserAddrDTO; |
| | | import cn.huge.module.ctuser.dto.UserLoginDTO; |
| | | import cn.huge.module.ctuser.dto.*; |
| | | import cn.huge.module.cust.constant.UserBaseConsts; |
| | | import cn.huge.module.sys.dto.GridTokenBaseDTO; |
| | | import cn.huge.module.sys.dto.GridUserBaseDTO; |
| | | import cn.huge.module.sys.dto.GridUserRoleDTO; |
| | | import cn.huge.module.sys.vo.GridRoleMenuVo; |
| | | import cn.huge.module.sys.vo.GridUserRoleVo; |
| | | import cn.huge.module.utils.JwtUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | |
| | | import org.springframework.util.DigestUtils; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | private CtUseroleService ctUseroleService; |
| | | @Autowired |
| | | private SysClientImpl sysClient; |
| | | @Autowired |
| | | private CtUnitService ctUnitService; |
| | | |
| | | /** |
| | | * 更新对象 |
| | |
| | | return ReturnFailUtils.getRepInfo("gridToken已失效,请重新登录!"); |
| | | } |
| | | // 判断账号是否存在 |
| | | CtAccount ctAccount = this.getByAccAndType(gridUserBaseDTO.getAccount(), UserBaseConsts.ACC_TYPE_1); |
| | | if (ObjectUtils.isEmpty(ctAccount)) { |
| | | ctAccount = this.getByAccAndType(gridUserBaseDTO.getMobile(), UserBaseConsts.ACC_TYPE_1); |
| | | } |
| | | CtAccount ctAccount = null; |
| | | CtUser ctUser = null; |
| | | if (ObjectUtils.isNotEmpty(ctAccount)) { |
| | | //返回结果 |
| | | ctUser = ctUserService.getById(ctAccount.getUserId()); |
| | | if (ObjectUtils.isEmpty(ctUser)) { |
| | | return ReturnFailUtils.getRepInfo("用户不存在!"); |
| | | } |
| | | } else { |
| | | //如果和亿迅系统的手机号对不上,在用身份证号去查询用户,如果查询得到,就对得上,如果查询不到,就说明用户不存在 |
| | | ctUser = ctUserService.getByIdCard(gridUserBaseDTO.getIdNumber()); |
| | | } |
| | | if (ObjectUtils.isNotEmpty(ctUser)) { |
| | | //返回结果 |
| | | ctAccount = this.getByUserIdAndType(ctUser.getId(), UserBaseConsts.ACC_TYPE_1); |
| | | } |
| | | // CtAccount ctAccount = this.getByAccAndType(gridUserBaseDTO.getAccount(), UserBaseConsts.ACC_TYPE_1); |
| | | // if (ObjectUtils.isEmpty(ctAccount)) { |
| | | // ctAccount = this.getByAccAndType(gridUserBaseDTO.getMobile(), UserBaseConsts.ACC_TYPE_1); |
| | | // } |
| | | |
| | | // if (ObjectUtils.isNotEmpty(ctAccount)) { |
| | | // //返回结果 |
| | | // ctUser = ctUserService.getById(ctAccount.getUserId()); |
| | | // if (ObjectUtils.isEmpty(ctUser)) { |
| | | // return ReturnFailUtils.getRepInfo("用户不存在!"); |
| | | // } |
| | | // } else { |
| | | // |
| | | // } |
| | | if (ObjectUtils.isNotEmpty(ctUser)) { |
| | | //有对应用户,则模拟登录,返回对应信息 |
| | | UserLoginDTO userLoginDTO = login(ctAccount, ctUser); |
| | | return ReturnSucUtils.getRepInfo(userLoginDTO); |
| | | } else { |
| | | //没有对应用户,创建用户,根据用户id获取用户信息 |
| | | ReturnBO repInfo = initNewUser(gridUserBaseDTO); |
| | | if (repInfo.getCode() == 0) { |
| | | //创建用户成功,模拟登录 |
| | | ctUser = ctUserService.getByIdCard(gridUserBaseDTO.getIdNumber()); |
| | | if (ObjectUtils.isNotEmpty(ctUser)) { |
| | | ctAccount = this.getByUserIdAndType(ctUser.getId(), UserBaseConsts.ACC_TYPE_1); |
| | | } |
| | | UserLoginDTO userLoginDTO = login(ctAccount, ctUser); |
| | | return ReturnSucUtils.getRepInfo(userLoginDTO); |
| | | } else { |
| | | //创建用户失败,返回失败信息 |
| | | return repInfo; |
| | | } |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("service方法[AccountService.webGridLogin]调用失败,异常信息:" + e, e); |
| | | throw new ServiceException("CtAccountService.webGridLogin", e); |
| | | } |
| | | } |
| | | |
| | | private UserLoginDTO login(CtAccount ctAccount, CtUser ctUser) { |
| | | UserLoginDTO userLoginDTO = new UserLoginDTO(); |
| | | // 封装用户信息 |
| | | userLoginDTO.setToken(JwtUtils.buildJWT(ctUser.getId())); |
| | |
| | | ctUserAddrDTO.setVillageName(ctUser.getVillageName()); |
| | | userLoginDTO.setCtUserAddrDTO(ctUserAddrDTO); |
| | | // 最后登录时间 |
| | | Date loginTime = ctAccount.getLoginTime(); |
| | | if (ObjectUtils.isEmpty(ctAccount.getLoginTime())) { |
| | | loginTime = DateUtils.getNowDate(); |
| | | } |
| | | Date loginTime = new Date(); |
| | | userLoginDTO.setLastLoginTime(loginTime); |
| | | // 更新最新登录时间 |
| | | UpdateWrapper<CtAccount> accountUpdateWrapper = new UpdateWrapper<>(); |
| | | accountUpdateWrapper.set("login_time", loginTime).eq("id", ctAccount.getId()); |
| | | this.update(accountUpdateWrapper); |
| | | return ReturnSucUtils.getRepInfo(userLoginDTO); |
| | | } else { |
| | | return userLoginDTO; |
| | | } |
| | | |
| | | private ReturnBO initNewUser(GridUserBaseDTO gridUserBaseDTO) { |
| | | String userId = gridUserBaseDTO.getId(); |
| | | //根据用户id获取用户信息 |
| | | |
| | | //拿到用户机构信息 |
| | | |
| | | //拿到用户角色菜单权限信息 |
| | | |
| | | //如果全部菜单权限,分配管理员角色;如果部分菜单权限,分配纠纷化解员角色 |
| | | |
| | | |
| | | //初始化完成用户信息,返回给前端登录 |
| | | |
| | | |
| | | GridUserRoleVo gridUserRoleVo = new GridUserRoleVo(); |
| | | gridUserRoleVo.setUserId(userId); |
| | | GridUserRoleDTO userRoleDTO = sysClient.getUserRoleList(gridUserRoleVo); |
| | | if (StringUtils.isEmpty(userRoleDTO.getOrgName())) { |
| | | return ReturnFailUtils.getRepInfo("用户不存在!,请确认后重试!"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("service方法[AccountService.webGridLogin]调用失败,异常信息:" + e, e); |
| | | throw new ServiceException("CtAccountService.webGridLogin", e); |
| | | if (StringUtils.isNotEmpty(userRoleDTO.getOrgName()) && userRoleDTO.getOrgName().endsWith("网格")) { |
| | | return ReturnFailUtils.getRepInfo("该用户所在机构禁止登录矛调系统,请切换该用户机构为区、镇街、社区机构"); |
| | | } |
| | | //拿到用户角色菜单权限信息 |
| | | GridRoleMenuVo gridRoleMenuVo = new GridRoleMenuVo(); |
| | | gridRoleMenuVo.setOrgRoleId(userRoleDTO.getRoleId()); |
| | | gridRoleMenuVo.setMenuSys("sub-mdjfhj"); |
| | | CtUserole roleMenu = sysClient.getRoleMenu(gridRoleMenuVo); |
| | | List<CtUserole> ctUseroles = new ArrayList<>(); |
| | | ctUseroles.add(roleMenu); |
| | | CtUnit ctUnit = ctUnitService.selectUnitByGridId(userRoleDTO.getOrgId()); |
| | | if (ctUnit != null && StringUtils.isNotEmpty(ctUnit.getId())) { |
| | | CtUserSaveDTO ctUserSaveDTO = new CtUserSaveDTO(); |
| | | ctUserSaveDTO.setUnitId(ctUnit.getId()); |
| | | ctUserSaveDTO.setUnitName(ctUnit.getUnitName()); |
| | | ctUserSaveDTO.setCipher("byzfw2023!"); |
| | | ctUserSaveDTO.setAcc(gridUserBaseDTO.getMobile()); |
| | | ctUserSaveDTO.setTrueName(gridUserBaseDTO.getName()); |
| | | ctUserSaveDTO.setMobile(gridUserBaseDTO.getMobile()); |
| | | ctUserSaveDTO.setIdcard(gridUserBaseDTO.getIdNumber()); |
| | | ctUserSaveDTO.setCtUseroleList(ctUseroles); |
| | | ctUserService.webSaveCtUser(ctUserSaveDTO, "-1"); |
| | | |
| | | } else { |
| | | return ReturnFailUtils.getRepInfo("用户不存在!,请确认后重试!"); |
| | | } |
| | | return ReturnSucUtils.getRepInfo("创建账号成功"); |
| | | } |
| | | |
| | | } |