| | |
| | | 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; |
| | | |
| | | /** |
| | | * 更新对象 |
| | |
| | | userLoginDTO.setToken(JwtUtils.buildJWT(ctUser.getId())); |
| | | userLoginDTO.setUserId(ctUser.getId()); |
| | | userLoginDTO.setTrueName(ctUser.getTrueName()); |
| | | userLoginDTO.setUnit(ctUser.getUnitName()); |
| | | CtUnit ctUnit = ctUnitService.getById(ctUser.getUnitId()); |
| | | if (ObjectUtils.isNotEmpty(ctUnit)){ |
| | | if (ctUnit.getUnitGrade() == UserBaseConsts.UNIT_GRADE_3 && ctUnit.getUnitType() == UserBaseConsts.UNIT_TYPE_102){ |
| | | userLoginDTO.setUnit(ctUnit.getUnitDes()); |
| | | // CtUnit parentCtUnit = ctUnitService.getById(ctUnit.getParentId()); |
| | | // if (ObjectUtils.isNotEmpty(parentCtUnit)) {1 |
| | | // userLoginDTO.setUnit(parentCtUnit.getUnitName()); |
| | | // }else { |
| | | // userLoginDTO.setUnit(ctUnit.getUnitDes()); |
| | | // } |
| | | }else { |
| | | userLoginDTO.setUnit(ctUnit.getUnitName()); |
| | | } |
| | | }else { |
| | | userLoginDTO.setUnit(ctUser.getUnitName()); |
| | | } |
| | | userLoginDTO.setDept(ctUser.getDeptName()); |
| | | userLoginDTO.setCustId(ctUser.getCustId()); |
| | | // 登录用户角色 |
| | |
| | | return ReturnFailUtils.getRepInfo("gridToken已失效,请重新登录!"); |
| | | } |
| | | // 判断账号是否存在 |
| | | CtAccount ctAccount = this.getByAccAndType(gridUserBaseDTO.getAccount(), UserBaseConsts.ACC_TYPE_1); |
| | | CtAccount ctAccount = null; |
| | | CtUser ctUser = null; |
| | | ctAccount = this.getByAccAndType(gridUserBaseDTO.getAccount(), UserBaseConsts.ACC_TYPE_1); |
| | | if (ObjectUtils.isEmpty(ctAccount)) { |
| | | ctAccount = this.getByAccAndType(gridUserBaseDTO.getMobile(), UserBaseConsts.ACC_TYPE_1); |
| | | } |
| | | CtUser ctUser = null; |
| | | if (ObjectUtils.isNotEmpty(ctAccount)) { |
| | | //返回结果 |
| | | ctUser = ctUserService.getById(ctAccount.getUserId()); |
| | |
| | | } else { |
| | | //如果和亿迅系统的手机号对不上,在用身份证号去查询用户,如果查询得到,就对得上,如果查询不到,就说明用户不存在 |
| | | ctUser = ctUserService.getByIdCard(gridUserBaseDTO.getIdNumber()); |
| | | if (ObjectUtils.isNotEmpty(ctUser)) { |
| | | ctAccount = this.getByUserIdAndType(ctUser.getId(), UserBaseConsts.ACC_TYPE_1); |
| | | } |
| | | } |
| | | if (ObjectUtils.isNotEmpty(ctUser)) { |
| | | //返回结果 |
| | | UserLoginDTO userLoginDTO = new UserLoginDTO(); |
| | | // 封装用户信息 |
| | | userLoginDTO.setToken(JwtUtils.buildJWT(ctUser.getId())); |
| | | userLoginDTO.setUserId(ctUser.getId()); |
| | | userLoginDTO.setTrueName(ctUser.getTrueName()); |
| | | userLoginDTO.setUnit(ctUser.getUnitName()); |
| | | userLoginDTO.setDept(ctUser.getDeptName()); |
| | | userLoginDTO.setCustId(ctUser.getCustId()); |
| | | // 登录用户角色 |
| | | List<CtUserole> ctUseroleList = ctUseroleService.listByUserId(ctUser.getId()); |
| | | userLoginDTO.setCtUseroleList(ctUseroleList); |
| | | // 登录用户地址信息 |
| | | CtUserAddrDTO ctUserAddrDTO = new CtUserAddrDTO(); |
| | | ctUserAddrDTO.setProv(ctUser.getProv()); |
| | | ctUserAddrDTO.setProvName(ctUser.getProvName()); |
| | | ctUserAddrDTO.setCity(ctUser.getCity()); |
| | | ctUserAddrDTO.setCityName(ctUser.getCityName()); |
| | | ctUserAddrDTO.setArea(ctUser.getArea()); |
| | | ctUserAddrDTO.setAreaName(ctUser.getAreaName()); |
| | | ctUserAddrDTO.setRoad(ctUser.getRoad()); |
| | | ctUserAddrDTO.setRoadName(ctUser.getRoadName()); |
| | | ctUserAddrDTO.setVillage(ctUser.getVillage()); |
| | | ctUserAddrDTO.setVillageName(ctUser.getVillageName()); |
| | | userLoginDTO.setCtUserAddrDTO(ctUserAddrDTO); |
| | | // 最后登录时间 |
| | | Date loginTime = ctAccount.getLoginTime(); |
| | | if (ObjectUtils.isEmpty(ctAccount.getLoginTime())) { |
| | | loginTime = DateUtils.getNowDate(); |
| | | } |
| | | userLoginDTO.setLastLoginTime(loginTime); |
| | | // 更新最新登录时间 |
| | | UpdateWrapper<CtAccount> accountUpdateWrapper = new UpdateWrapper<>(); |
| | | accountUpdateWrapper.set("login_time", loginTime).eq("id", ctAccount.getId()); |
| | | this.update(accountUpdateWrapper); |
| | | //有对应用户,则模拟登录,返回对应信息 |
| | | UserLoginDTO userLoginDTO = login(ctAccount, ctUser); |
| | | return ReturnSucUtils.getRepInfo(userLoginDTO); |
| | | } else { |
| | | String userId = gridUserBaseDTO.getId(); |
| | | //根据用户id获取用户信息 |
| | | //没有对应用户,创建用户,根据用户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; |
| | | } |
| | | |
| | | //拿到用户机构信息 |
| | | |
| | | //拿到用户角色菜单权限信息 |
| | | |
| | | //如果全部菜单权限,分配管理员角色;如果部分菜单权限,分配纠纷化解员角色 |
| | | |
| | | |
| | | //初始化完成用户信息,返回给前端登录 |
| | | |
| | | |
| | | return ReturnFailUtils.getRepInfo("用户不存在!,请确认后重试!"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("service方法[AccountService.webGridLogin]调用失败,异常信息:" + e, e); |
| | |
| | | } |
| | | } |
| | | |
| | | private UserLoginDTO login(CtAccount ctAccount, CtUser ctUser) { |
| | | UserLoginDTO userLoginDTO = new UserLoginDTO(); |
| | | // 封装用户信息 |
| | | userLoginDTO.setToken(JwtUtils.buildJWT(ctUser.getId())); |
| | | userLoginDTO.setUserId(ctUser.getId()); |
| | | userLoginDTO.setTrueName(ctUser.getTrueName()); |
| | | userLoginDTO.setUnit(ctUser.getUnitName()); |
| | | userLoginDTO.setDept(ctUser.getDeptName()); |
| | | userLoginDTO.setCustId(ctUser.getCustId()); |
| | | // 登录用户角色 |
| | | List<CtUserole> ctUseroleList = ctUseroleService.listByUserId(ctUser.getId()); |
| | | userLoginDTO.setCtUseroleList(ctUseroleList); |
| | | // 登录用户地址信息 |
| | | CtUserAddrDTO ctUserAddrDTO = new CtUserAddrDTO(); |
| | | ctUserAddrDTO.setProv(ctUser.getProv()); |
| | | ctUserAddrDTO.setProvName(ctUser.getProvName()); |
| | | ctUserAddrDTO.setCity(ctUser.getCity()); |
| | | ctUserAddrDTO.setCityName(ctUser.getCityName()); |
| | | ctUserAddrDTO.setArea(ctUser.getArea()); |
| | | ctUserAddrDTO.setAreaName(ctUser.getAreaName()); |
| | | ctUserAddrDTO.setRoad(ctUser.getRoad()); |
| | | ctUserAddrDTO.setRoadName(ctUser.getRoadName()); |
| | | ctUserAddrDTO.setVillage(ctUser.getVillage()); |
| | | ctUserAddrDTO.setVillageName(ctUser.getVillageName()); |
| | | userLoginDTO.setCtUserAddrDTO(ctUserAddrDTO); |
| | | // 最后登录时间 |
| | | 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 userLoginDTO; |
| | | } |
| | | |
| | | private ReturnBO initNewUser(GridUserBaseDTO gridUserBaseDTO) { |
| | | String userId = gridUserBaseDTO.getId(); |
| | | //拿到用户机构信息 |
| | | GridUserRoleVo gridUserRoleVo = new GridUserRoleVo(); |
| | | gridUserRoleVo.setUserId(userId); |
| | | GridUserRoleDTO userRoleDTO = sysClient.getUserRoleList(gridUserRoleVo); |
| | | if (StringUtils.isEmpty(userRoleDTO.getRoleName()) || !userRoleDTO.getRoleName().contains("矛调系统")) { |
| | | return ReturnFailUtils.getRepInfo("该用户没有矛调系统的权限"); |
| | | } |
| | | if (StringUtils.isNotEmpty(userRoleDTO.getOrgName()) && userRoleDTO.getOrgName().endsWith("网格")) { |
| | | return ReturnFailUtils.getRepInfo("该用户所在机构禁止登录矛调系统,请切换该用户机构为区、镇街、社区机构"); |
| | | } |
| | | CtUserole ctUserole = new CtUserole(); |
| | | if (userRoleDTO.getRoleName().contains("纷化解人员")) { |
| | | ctUserole.setRoleId("22_00024-4"); |
| | | ctUserole.setRoleName("纠纷化解人员"); |
| | | } else { |
| | | ctUserole.setRoleId("22_00024-3"); |
| | | ctUserole.setRoleName("单位管理员"); |
| | | } |
| | | |
| | | List<CtUserole> ctUseroles = new ArrayList<>(); |
| | | ctUseroles.add(ctUserole); |
| | | log.info("xsd:CtUserole:{}", ctUserole); |
| | | CtUnit ctUnit = ctUnitService.selectUnitByGridId(userRoleDTO.getOrgId()); |
| | | log.info("xsd:ctUnit:{}", ctUnit); |
| | | 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"); |
| | | log.info("xsd:ctUserSaveDTO:{}", ctUserSaveDTO); |
| | | } else { |
| | | return ReturnFailUtils.getRepInfo("该用户所在机构禁止登录矛调系统!请调整机构后重试!"); |
| | | } |
| | | return ReturnSucUtils.getRepInfo("创建账号成功"); |
| | | } |
| | | |
| | | } |