| | |
| | | |
| | | import static java.util.Objects.isNull; |
| | | import static java.util.Objects.nonNull; |
| | | import static org.apache.commons.lang3.StringUtils.isNotBlank; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Random; |
| | | import java.util.Set; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.validation.constraints.NotBlank; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.panzhihua.common.model.dtos.community.microCommercialStreet.BindUserPhoneDTO; |
| | | import com.panzhihua.common.model.vos.community.microCommercialStreet.McsLoginUserInfoVO; |
| | | import com.panzhihua.service_user.dao.*; |
| | | import com.panzhihua.service_user.entity.SysAppConfig; |
| | | import com.panzhihua.service_user.entity.SysTemplateConfig; |
| | |
| | | import com.panzhihua.common.model.dtos.community.NoticeReadDTO; |
| | | import com.panzhihua.common.model.dtos.community.convenient.ConvenientMerchantDTO; |
| | | import com.panzhihua.common.model.dtos.community.convenient.DisableOrEnableConvenientMerchantDTO; |
| | | import com.panzhihua.common.model.dtos.community.microCommercialStreet.McsMerchantDTO; |
| | | import com.panzhihua.common.model.dtos.grid.EventGridMemberAddDTO; |
| | | import com.panzhihua.common.model.dtos.grid.EventGridMemberEditAdminDTO; |
| | | import com.panzhihua.common.model.dtos.grid.EventGridMemberEditStatusDTO; |
| | |
| | | import com.panzhihua.common.model.vos.user.UserPhoneVO; |
| | | import com.panzhihua.common.utlis.IdCard; |
| | | import com.panzhihua.common.utlis.SensitiveUtil; |
| | | import com.panzhihua.common.utlis.SmsUtil; |
| | | import com.panzhihua.common.utlis.Snowflake; |
| | | import com.panzhihua.common.utlis.StringUtils; |
| | | import com.panzhihua.common.utlis.WxUtil; |
| | |
| | | @Slf4j |
| | | @Service |
| | | public class UserServiceImpl implements UserService { |
| | | |
| | | private static final String DEFAULT_IMAGE_URL = "https://www.psciio.com//idcard/91313573d071436ab1f934231b31c6e5.jpg"; |
| | | |
| | | @Resource |
| | | private UserDao userDao; |
| | | @Resource |
| | |
| | | if (comActVO != null) { |
| | | loginUserInfoVO.setCommunityName(comActVO.getName()); |
| | | loginUserInfoVO.setComActVO(comActVO); |
| | | loginUserInfoVO.setAreaCode(comActVO.getAreaCode()); |
| | | SysAppConfig sysAppConfig=sysAppConfigDao.selectOne(new QueryWrapper<SysAppConfig>().lambda().eq(SysAppConfig::getAreaCode,comActVO.getAreaCode())); |
| | | if(sysAppConfig!=null){ |
| | | loginUserInfoVO.setAppId(sysAppConfig.getAppId()); |
| | |
| | | * @return 人员详情 |
| | | */ |
| | | @Override |
| | | public R detailUser(Long userId) { |
| | | public R<LoginUserInfoVO> detailUser(Long userId) { |
| | | LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO(); |
| | | if (userId < 100000000l) { |
| | | SysUserDO sysUserDO = userDao.selectById(userId); |
| | |
| | | ComActVO comActVO = userDao.selectCommunity(loginUserInfoVO.getCommunityId()); |
| | | if (!ObjectUtils.isEmpty(comActVO)) { |
| | | loginUserInfoVO.setCommunityName(comActVO.getName()); |
| | | loginUserInfoVO.setAreaCode(comActVO.getAreaCode()); |
| | | } |
| | | else{ |
| | | loginUserInfoVO.setAreaCode("510423"); |
| | | } |
| | | //是否是社区物业人员 |
| | | int countPropertyWorker = userDao.countPropertyWorker(userId, loginUserInfoVO.getCommunityId()); |
| | |
| | | |
| | | // 获取所有权限id |
| | | List<SysMenuDO> menuDOList = sysMenuDAO.selectList(new QueryWrapper<SysMenuDO>().lambda() |
| | | .eq(SysMenuDO::getCommunityId, 2L).orderByAsc(SysMenuDO::getOrderNum)); |
| | | .eq(SysMenuDO::getCommunityId, 2L).eq(SysMenuDO::getVisible,0).orderByAsc(SysMenuDO::getOrderNum)); |
| | | if (!menuDOList.isEmpty()) { |
| | | menuIds = menuDOList.stream().map(sysMenuDO -> sysMenuDO.getMenuId()).collect(Collectors.toList()); |
| | | |
| | |
| | | BeanUtils.copyProperties(sysUserDO, loginUserInfoVO); |
| | | return R.ok(loginUserInfoVO); |
| | | } |
| | | |
| | | /** |
| | | * 微商业街新增商家账号 |
| | | * @param mcsMerchantDTO |
| | | * @return 商家用户id |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R addMcsMerchantUser(McsMerchantDTO mcsMerchantDTO) { |
| | | SysUserDO sysUserDO; |
| | | sysUserDO = userDao.selectOne(new QueryWrapper<SysUserDO>().lambda() |
| | | .eq(SysUserDO::getPhone, mcsMerchantDTO.getPhone()).eq(SysUserDO::getType, 11)); |
| | | String encode = new BCryptPasswordEncoder().encode(mcsMerchantDTO.getPassword()); |
| | | if (nonNull(sysUserDO)) { |
| | | sysUserDO.setAccount(mcsMerchantDTO.getAccount()); |
| | | sysUserDO.setStatus(mcsMerchantDTO.getAccountStatus()); |
| | | sysUserDO.setPhone(mcsMerchantDTO.getPhone()); |
| | | sysUserDO.setPassword(encode); |
| | | sysUserDO.setPlaintextPassword(mcsMerchantDTO.getPassword()); |
| | | sysUserDO.setImageUrl(mcsMerchantDTO.getLogo()); |
| | | sysUserDO.setName(mcsMerchantDTO.getName()); |
| | | userDao.updateById(sysUserDO); |
| | | McsLoginUserInfoVO loginUserInfoVO = new McsLoginUserInfoVO(); |
| | | BeanUtils.copyProperties(sysUserDO, loginUserInfoVO); |
| | | return R.ok(loginUserInfoVO); |
| | | } |
| | | // sys_user 表 |
| | | sysUserDO = new SysUserDO(); |
| | | BeanUtils.copyProperties(mcsMerchantDTO, sysUserDO); |
| | | sysUserDO.setAccount(mcsMerchantDTO.getAccount()); |
| | | sysUserDO.setType(11); |
| | | sysUserDO.setAreaId(null); |
| | | sysUserDO.setStatus(mcsMerchantDTO.getAccountStatus()); |
| | | sysUserDO.setPhone(mcsMerchantDTO.getPhone()); |
| | | sysUserDO.setPassword(encode); |
| | | sysUserDO.setPlaintextPassword(mcsMerchantDTO.getPassword()); |
| | | sysUserDO.setImageUrl(mcsMerchantDTO.getLogo()); |
| | | try { |
| | | userDao.insert(sysUserDO); |
| | | McsLoginUserInfoVO loginUserInfoVO = new McsLoginUserInfoVO(); |
| | | BeanUtils.copyProperties(sysUserDO, loginUserInfoVO); |
| | | return R.ok(loginUserInfoVO); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("修改数字商业街商家用户报错【{}】", e.getMessage()); |
| | | if (e.getMessage().contains("union_account_type") || e.getMessage().contains("23000")) { |
| | | return R.fail("账户已经存在"); |
| | | } else { |
| | | return R.fail("账户或手机号已存在,请重新填写尝试"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 微商业街修改商家账号 |
| | | * @param mcsMerchantDTO |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R putMcsMerchantUser(McsMerchantDTO mcsMerchantDTO) { |
| | | SysUserDO sysUserDO = userDao.selectById(mcsMerchantDTO.getUserId()); |
| | | if (isNull(sysUserDO)) { |
| | | return R.fail("用户不存在"); |
| | | } |
| | | String account = mcsMerchantDTO.getAccount(); |
| | | String phone = mcsMerchantDTO.getPhone(); |
| | | Integer accountStatus = mcsMerchantDTO.getAccountStatus(); |
| | | String name = mcsMerchantDTO.getName(); |
| | | if (isNotBlank(account)) { |
| | | sysUserDO.setAccount(account); |
| | | } |
| | | if (isNotBlank(phone)) { |
| | | sysUserDO.setPhone(phone); |
| | | } |
| | | if (nonNull(accountStatus)) { |
| | | sysUserDO.setStatus(accountStatus); |
| | | } |
| | | if (isNotBlank(name)) { |
| | | sysUserDO.setName(name); |
| | | } |
| | | try { |
| | | userDao.updateById(sysUserDO); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("修改数字商业街商家用户报错【{}】", e.getMessage()); |
| | | if (e.getMessage().contains("union_phone_type")) { |
| | | return R.fail("手机号已存在"); |
| | | } else if (e.getMessage().contains("union_account_type")) { |
| | | return R.fail("账户已经存在"); |
| | | }else if(e.getMessage().contains("23000")){ |
| | | return R.fail("手机号已存在"); |
| | | } else { |
| | | return R.fail("账户或手机号已存在,请重新填写尝试"); |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 检查用户是否有效 |
| | | * @param userId |
| | | * @param type |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Boolean checkUserIsValid(Long userId, Integer type) { |
| | | SysUserDO sysUserDO = userDao.selectById(userId); |
| | | if (isNull(sysUserDO) || sysUserDO.getStatus() != 1 || !sysUserDO.getType().equals(type)) { |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 根据手机号、用户类型查询用户 |
| | | * @param phone |
| | | * @param type |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R getSysUserByPhone(String phone, Integer type) { |
| | | SysUserDO sysUserDO = userDao.selectOne(new QueryWrapper<SysUserDO>().lambda().eq(SysUserDO::getPhone, phone).eq(SysUserDO::getType, type)); |
| | | McsLoginUserInfoVO loginUserInfoVO = null; |
| | | if (nonNull(sysUserDO)) { |
| | | loginUserInfoVO = new McsLoginUserInfoVO(); |
| | | BeanUtils.copyProperties(sysUserDO, loginUserInfoVO); |
| | | } |
| | | return R.ok(loginUserInfoVO); |
| | | } |
| | | |
| | | /** |
| | | * 发送验证码 |
| | | * @param phone 手机号 |
| | | * @param clientIP 用户ip |
| | | * @param prefixKey redis Key 前缀 |
| | | * @param limit 获取次数限制 |
| | | * @param timeout 超次数获取时间等待 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R sendMessageCode(String phone, String clientIP, String prefixKey, Integer limit, Integer timeout) { |
| | | ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue(); |
| | | if (isNotBlank(clientIP)) { |
| | | String redisKey = String.join("::", prefixKey, clientIP); |
| | | Long increment = opsForValue.increment(redisKey, 1); |
| | | if (increment > limit) { |
| | | return R.fail(String.format("请求过于频繁,请%d分钟后再次尝试!", timeout/60)); |
| | | } |
| | | stringRedisTemplate.expire(redisKey, timeout, TimeUnit.SECONDS); |
| | | } |
| | | Random r = new Random(); |
| | | StringBuilder rs = new StringBuilder(); |
| | | for (int i = 0; i < 5; i++) { |
| | | rs.append(r.nextInt(10)); |
| | | } |
| | | String code = rs.toString(); |
| | | int result = SmsUtil.sendCode(phone, code); |
| | | if (result == 1) { |
| | | String codeKey = String.join("::", phone, code); |
| | | opsForValue.set(codeKey, code, timeout, TimeUnit.SECONDS); |
| | | return R.ok(); |
| | | } |
| | | return R.fail(); |
| | | } |
| | | |
| | | /** |
| | | * 根据openId获取微商业街用户 |
| | | * @param openid |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R getMcsUserByOpenId(String openid) { |
| | | SysUserDO sysUserDO = userDao.selectOne(new QueryWrapper<SysUserDO>().lambda().eq(SysUserDO::getOpenid, openid).eq(SysUserDO::getType, 11)); |
| | | McsLoginUserInfoVO loginUserInfoVO = null; |
| | | if (nonNull(sysUserDO) && isNotBlank(sysUserDO.getOpenid())) { |
| | | loginUserInfoVO = new McsLoginUserInfoVO(); |
| | | BeanUtils.copyProperties(sysUserDO, loginUserInfoVO); |
| | | } |
| | | return R.ok(loginUserInfoVO); |
| | | } |
| | | |
| | | /** |
| | | * 商业街用户微信授权-绑定手机号 |
| | | * @param bindUserPhoneDTO |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R bindOrAddMcsUser(BindUserPhoneDTO bindUserPhoneDTO) { |
| | | String phone = bindUserPhoneDTO.getPhone(); |
| | | String openId = bindUserPhoneDTO.getOpenId(); |
| | | String redisKey = String.join("::", phone, bindUserPhoneDTO.getCode()); |
| | | Boolean hasKey = stringRedisTemplate.hasKey(redisKey); |
| | | if (hasKey) { |
| | | //通过验证 |
| | | SysUserDO sysUserDO = userDao.selectOne(new QueryWrapper<SysUserDO>().lambda().eq(SysUserDO::getPhone, phone).eq(SysUserDO::getType, 11)); |
| | | if (nonNull(sysUserDO)) { |
| | | //已有用户 |
| | | sysUserDO.setOpenid(openId); |
| | | int result = userDao.updateById(sysUserDO); |
| | | if (result > 0) { |
| | | McsLoginUserInfoVO loginUserInfoVO = new McsLoginUserInfoVO(); |
| | | BeanUtils.copyProperties(sysUserDO, loginUserInfoVO); |
| | | stringRedisTemplate.delete(redisKey); |
| | | return R.ok(loginUserInfoVO); |
| | | } |
| | | return R.fail("绑定失败,请重试"); |
| | | } else { |
| | | //自动创建用户 |
| | | McsMerchantDTO mcsMerchantDTO = new McsMerchantDTO(); |
| | | mcsMerchantDTO.setAccount(phone); |
| | | mcsMerchantDTO.setPassword("88888888"); |
| | | mcsMerchantDTO.setAccountStatus(1); |
| | | mcsMerchantDTO.setPhone(phone); |
| | | mcsMerchantDTO.setName("用户" + retrieveRandomCode(5)); |
| | | mcsMerchantDTO.setImageUrl(DEFAULT_IMAGE_URL); |
| | | mcsMerchantDTO.setOpenId(openId); |
| | | R addUserResult = addMcsMerchantUser(mcsMerchantDTO); |
| | | if (R.isOk(addUserResult)) { |
| | | McsLoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(JSONObject.toJSONString(addUserResult.getData()), McsLoginUserInfoVO.class); |
| | | loginUserInfoVO.setPlaintextPassword("88888888"); |
| | | stringRedisTemplate.delete(redisKey); |
| | | return R.ok(loginUserInfoVO); |
| | | } |
| | | return addUserResult; |
| | | } |
| | | } else { |
| | | return R.fail("验证码错误"); |
| | | } |
| | | } |
| | | |
| | | private String retrieveRandomCode(int length) { |
| | | Random r = new Random(); |
| | | StringBuilder rs = new StringBuilder(); |
| | | for (int i = 0; i < length; i++) { |
| | | rs.append(r.nextInt(10)); |
| | | } |
| | | return rs.toString(); |
| | | } |
| | | } |