| 
					
				 | 
			
			
				@@ -0,0 +1,600 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+package com.gree.mall.contest.logic.admin; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import cn.hutool.core.date.DateField; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import cn.hutool.core.date.DateTime; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import cn.hutool.core.date.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import cn.hutool.core.util.IdUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import cn.hutool.crypto.SecureUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.core.metadata.IPage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.google.code.kaptcha.impl.DefaultKaptcha; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.bean.SVerification; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.bean.admin.AdminModuleTree; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.bean.admin.AdminUserBean; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.bean.admin.AdminUserCom; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.bean.admin.AdminWebsitGrantBean; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.bean.admin.reqDto.AdminUserAddReqBean; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.commonmapper.AdminMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.commonmapper.CommonMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.constant.Constant; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.enums.admin.RoleTypeEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.exception.RemoteServiceException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.helper.ResponseHelper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.logic.SMSLogic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.logic.common.CommonLogic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.plus.entity.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.plus.service.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.utils.CommonUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.utils.JwtUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.utils.RedisUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import lombok.RequiredArgsConstructor; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import lombok.extern.slf4j.Slf4j; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.beans.BeanUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.beans.factory.annotation.Value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import javax.imageio.ImageIO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import javax.servlet.http.HttpServletRequest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.awt.image.BufferedImage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.io.ByteArrayOutputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+@Slf4j 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+@Service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+@RequiredArgsConstructor 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+public class AdminUserLogic { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final RedisUtil redisUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final DefaultKaptcha defaultKaptcha; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final CommonLogic commonLogic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final AdminUserService adminUserService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final AdminModuleService adminModuleService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final AdminRoleService adminRoleService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final AdminUserModuleRelaService adminUserModuleRelaService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final AdminCompanyWechatService adminCompanyWechatService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final AdminWebsitService adminWebsitService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final AdminMapper adminMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final SMSLogic smsLogic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final ServiceProviderService serviceProviderService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final MerchantService merchantService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final CommonMapper commonMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final SysConfigService sysConfigService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final ServiceBalanceAccService serviceBalanceAccService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final AdminWebsitLogic adminWebsitLogic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Value("${jwt.expire}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private Long expiration; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 验证码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public SVerification defaultKaptcha() throws IOException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 生成文字验证码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String text = defaultKaptcha.createText(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 生成图片验证码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ByteArrayOutputStream outputStream = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        BufferedImage image = defaultKaptcha.createImage(text); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        outputStream = new ByteArrayOutputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ImageIO.write(image, "png", outputStream); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        byte b[] = outputStream.toByteArray();//从流中获取数据数组。 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        String baseStr = new BASE64Encoder().encode(b); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String baseStr = Base64.getEncoder().encodeToString(b); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //生成一个token 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String code = UUID.randomUUID().toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        redisUtil.set(Constant.RedisPrefix.TOKEN_VERIFICATION + code, text, 2 * 60); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        SVerification verification = new SVerification(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        verification.setCode(code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        verification.setPic(baseStr); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return verification; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 登录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public AdminUserBean login(String userName, String password, String code, String codeValue) throws RemoteServiceException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminUser adminUser = adminUserService.lambdaQuery().eq(AdminUser::getUserName, userName).one(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (adminUser == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("帐号不存在"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //如果是admin操作非admin账号登陆不需要判断密码是否正确 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminUserCom adminUser1 = commonLogic.getAdminUser(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(adminUser1 == null || !(adminUser1.getUserName().equals("admin")) && !StringUtils.equals(userName,"admin")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String value = (String) redisUtil.get(Constant.RedisPrefix.TOKEN_VERIFICATION + code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if(StringUtils.isBlank(value)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                throw new RemoteServiceException("验证码过期,请刷新验证码重试"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (!value.equals(codeValue)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                throw new RemoteServiceException("验证码错误"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if(adminUser.getLoginErrNum() >= 3){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                throw new RemoteServiceException("登陆失败,您已连续输入错误3次密码,请联系管理人员重置密码"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (!StringUtils.equals(adminUser.getPassword(), SecureUtil.md5(password))) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                adminUser.setLoginErrNum(adminUser.getLoginErrNum() + 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                adminUserService.saveOrUpdate(adminUser); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //记录错误次数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                throw new RemoteServiceException("帐号密码错误"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!adminUser.getStatus()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("帐号冻结中,请联系相关管理人员"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        adminUser.setLoginErrNum(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        adminUser.setLastLoginTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        adminUser.updateById(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminUserBean adminUserBean = new AdminUserBean(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        BeanUtils.copyProperties(adminUser, adminUserBean); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 注入服务对象 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (RoleTypeEnum.isServiceProvider(adminUser.getType())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (StringUtils.isNotBlank(adminUser.getServiceProviderId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //adminUserBean.setServiceProvider(serviceProviderService.getById(adminUser.getServiceProviderId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //adminUserBean.setIsAllinpay(adminUserBean.getIsAllinpay()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // token到期时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        final DateTime offset = DateUtil.offset(DateUtil.date(), DateField.MINUTE, Math.toIntExact(expiration)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        adminUserBean.setExpireTimeToken(offset); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //不返回密码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        adminUserBean.setPassword(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        adminUserBean.setToken(JwtUtils.generateToken(adminUser.getAdminUserId(), adminUser.getUserName(), adminUser.getNickName(), adminUser.getType(), Constant.PC_API)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //存放到redis 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        redisUtil.set(Constant.RedisPrefix.TOKEN_MANAGE + adminUserBean.getToken(), adminUser, expiration * 1000); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return adminUserBean; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 修改密码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void updatePassword(String userName, String password, String newPwd) throws RemoteServiceException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String pas = SecureUtil.md5(password); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminUser adminUser = adminUserService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(AdminUser::getUserName, userName) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(AdminUser::getPassword, pas).one(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (adminUser == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("帐号密码错误"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        adminUser.setLoginErrNum(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        adminUser.setPassword(SecureUtil.md5(newPwd)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        adminUserService.updateById(adminUser); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 修改帐号状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void updateStatus(String adminUserId, Boolean status) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        adminUserService.lambdaUpdate().set(AdminUser::getStatus, status).eq(AdminUser::getAdminUserId, adminUserId).update(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 重置密码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void resetPassword(String adminUserId, String password, HttpServletRequest request) throws RemoteServiceException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //检查是否拥有重置的密码权限 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminUserCom adminUser1 = commonLogic.getAdminUser(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (adminUser1.getType().equals(RoleTypeEnum.F.getCode()) || adminUser1.getType().equals(RoleTypeEnum.E.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("子账号不允许重置密码"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //开始重置 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminUser adminUser = adminUserService.getById(adminUserId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!StringUtils.isEmpty(adminUser1.getServiceProviderId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                && adminUser1.getServiceProviderId().equals(adminUser.getServiceProviderId()) && 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                (adminUser1.getType().equals(RoleTypeEnum.B.getCode()) || adminUser1.getType().equals(RoleTypeEnum.C.getCode())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminUser.setPassword(SecureUtil.md5(password)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminUser.setLoginErrNum(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminUser.updateById(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (adminUser1.getType().equals(RoleTypeEnum.A.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminUser.setPassword(SecureUtil.md5(password)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminUser.setLoginErrNum(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminUser.updateById(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("账号不允许重置别人密码"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 新增帐号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void add(AdminUserAddReqBean adminUser) throws RemoteServiceException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminUserCom curAdminUser = commonLogic.getAdminUser(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (StringUtils.isBlank(adminUser.getUserName()) || StringUtils.isBlank(adminUser.getPassword())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("参数错误"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Long count = adminUserService.lambdaQuery().eq(AdminUser::getUserName, adminUser.getUserName()).count(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (count > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("帐号已被注册"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //当前用户选择的部门 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminWebsit adminWebsit = adminWebsitService.getById(adminUser.getAdminWebsitId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(adminWebsit == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("请选择部门"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //需要用户roleId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminRole addUserRole = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (StringUtils.isBlank(adminUser.getRoleId()) || 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                (addUserRole = adminRoleService.getById(adminUser.getRoleId())) == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("请为用户选择角色"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        adminUser.setRoleName(addUserRole.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (adminUser.getRoleName().equals("推单员")) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("推单员需要在推单员列表配置账号"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(curAdminUser.getType().equals(RoleTypeEnum.B.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminUser.setType(RoleTypeEnum.D.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminUser.setServiceProviderId(curAdminUser.getServiceProviderId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(curAdminUser.getType().equals(RoleTypeEnum.C.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminUser.setType(RoleTypeEnum.E.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminUser.setServiceProviderId(curAdminUser.getServiceProviderId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        adminUser.setPassword(SecureUtil.md5(adminUser.getPassword())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        adminUser.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        adminUserService.save(adminUser); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 修改帐号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void update(HttpServletRequest request, AdminUserAddReqBean newUser) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminUserCom admin = commonLogic.getAdminUser(request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminUser oldUser = adminUserService.getById(newUser.getAdminUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //需要用户roleId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminRole addUserRole = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (StringUtils.isBlank(newUser.getRoleId()) || (addUserRole = adminRoleService.getById(newUser.getRoleId())) == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("请为用户选择角色"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //当前用户选择的部门 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminWebsit adminWebsit = adminWebsitService.getById(newUser.getAdminWebsitId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(adminWebsit == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("请选择部门"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        this.setType(admin,oldUser,newUser); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        newUser.setRoleName(addUserRole.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        newUser.setUserName(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        newUser.setPassword(StringUtils.isBlank(newUser.getPassword()) ? null : SecureUtil.md5(newUser.getPassword())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        newUser.updateById(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 用户类型处理 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param curAdmin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param oldAdmin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param newAdmin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public AdminUser setType(AdminUserCom curAdmin,AdminUser oldAdmin,AdminUser newAdmin){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(StringUtils.isBlank(newAdmin.getType())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return newAdmin; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //服务商不可变更服务商信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(curAdmin.getType().equals(oldAdmin.getType()) && !curAdmin.getUserName().equals("admin")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("您暂无权限变更"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //如果是平台添加帐号则为业务员 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //如果是服务商添加账号则为子账号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //如果是合作商添加账号则为合作商子账号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(oldAdmin.getType().equals(RoleTypeEnum.A.getCode())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            newAdmin.setType(RoleTypeEnum.A.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }else if(oldAdmin.getType().equals(RoleTypeEnum.B.getCode())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            newAdmin.setType(RoleTypeEnum.D.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }else if(oldAdmin.getType().equals(RoleTypeEnum.C.getCode())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            newAdmin.setType(RoleTypeEnum.E.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            newAdmin.setType(oldAdmin.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return newAdmin; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 运营后台用户列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public IPage<AdminUser> list(String adminWebsitId,String roleId, Boolean status, String userName, Integer pageNum, Integer pageSize) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminUserCom adminUser = commonLogic.getAdminUser(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<String> adminWebsitIds = adminUser.getAdminWebsitIds(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(StringUtils.isNotBlank(adminWebsitId)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<AdminWebsit> list = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            list.addAll(commonLogic.queryAllChild(list, adminWebsitId)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminWebsitIds = list.stream().map(AdminWebsit::getWebsitId).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //要把查得父id加入 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminWebsitIds.add(adminWebsitId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        IPage<AdminUser> page = adminUserService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .in(CollectionUtils.isNotEmpty(adminWebsitIds),AdminUser::getAdminWebsitId,adminWebsitIds) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(StringUtils.isNotBlank(roleId), AdminUser::getRoleId, roleId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(status != null, AdminUser::getStatus, status) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .and(StringUtils.isNotBlank(userName),item -> item.like(AdminUser::getUserName, userName) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .or().like(AdminUser::getNickName,userName) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .orderByDesc(AdminUser::getCreateTime) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .page(new Page<>(pageNum, pageSize)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return page; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 运营后台用户详情 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param adminUserId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public AdminUserBean detail(String adminUserId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminUser adminUser = adminUserService.getById(adminUserId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminUserBean adminUserBean = new AdminUserBean(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        BeanUtils.copyProperties(adminUser, adminUserBean); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //服务商对象 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ServiceProvider serviceProvider = serviceProviderService.getById(adminUser.getServiceProviderId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Merchant merchant = merchantService.getById(adminUser.getServiceProviderId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        adminUserBean.setServiceProvider(serviceProvider); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        adminUserBean.setMerchant(merchant); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return adminUserBean; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 退出登录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void logout(HttpServletRequest request) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String token = CommonUtils.getToken(request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        redisUtil.del(Constant.RedisPrefix.TOKEN_MANAGE + token); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 根据登录帐号查询权限模块 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public List<AdminModuleTree> queryAdminModule(String adminUserId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //String adminUserId = CommonUtils.getUserId(request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminUser adminUser = adminUserService.getById(adminUserId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (adminUser.getUserName().equals("admin")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return this.queryAdminModuleTree(null, true, null, null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return this.queryAdminModuleTree(adminUser.getRoleId(), false, null, null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 给角色授权 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void grantModules(AdminWebsitGrantBean adminWebsitGrantBean) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String roleId = adminWebsitGrantBean.getAdminRoleId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //1.清空该角色的权限 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        adminUserModuleRelaService.lambdaUpdate().eq(AdminUserModuleRela::getAdminRoleId, roleId).remove(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //2.生成权限 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<AdminUserModuleRela> list = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (String adminModuleId : adminWebsitGrantBean.getAdminModuleIds()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            AdminUserModuleRela adminUserModuleRela = new AdminUserModuleRela(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminUserModuleRela.setAdminRoleId(roleId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminUserModuleRela.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminUserModuleRela.setStatus(true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminUserModuleRela.setAdminModuleId(adminModuleId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminUserModuleRela.setFlag(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            list.add(adminUserModuleRela); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (String adminModuleId : adminWebsitGrantBean.getAdminModuleIds2()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            AdminUserModuleRela adminUserModuleRela = new AdminUserModuleRela(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminUserModuleRela.setAdminRoleId(roleId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminUserModuleRela.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminUserModuleRela.setStatus(true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminUserModuleRela.setAdminModuleId(adminModuleId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminUserModuleRela.setFlag(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            list.add(adminUserModuleRela); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        adminUserModuleRelaService.saveBatch(list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 根据角色id查询拥有的权限ids 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public List<String> queryModuleIdChecked(String adminRoleId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminRole adminRole = adminRoleService.getById(adminRoleId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Boolean admin = adminRole.getName().equals("超级管理员"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (admin) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<AdminModule> list = adminModuleService.list(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (list.size() == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return list.stream().map(AdminModule::getModuleId).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<AdminUserModuleRela> list = adminUserModuleRelaService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(AdminUserModuleRela::getFlag,1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(AdminUserModuleRela::getAdminRoleId, adminRoleId).list(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (CollectionUtils.isEmpty(list)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return list.stream().map(AdminUserModuleRela::getAdminModuleId).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 根据角色查询所有功能模块权限 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public List<AdminModuleTree> queryAllAdminModuleTree(String adminRoleId, HttpServletRequest request) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String userId = CommonUtils.getUserId(request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminUser adminUser = adminUserService.getById(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //更改的角色 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminRole adminRole = adminRoleService.getById(adminRoleId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //查询该角色有的权限d 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<AdminUserModuleRela> hasModules = adminUserModuleRelaService.lambdaQuery().eq(AdminUserModuleRela::getAdminRoleId, adminRoleId).list(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<String> collect = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!CollectionUtils.isEmpty(hasModules)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            collect = hasModules.stream().map(AdminUserModuleRela::getAdminModuleId).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<AdminModuleTree> adminModuleTrees = this.queryAdminModuleTree(adminRoleId, adminRole.getName().equals("超级管理员"), collect, adminUser); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return adminModuleTrees; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private List<AdminModuleTree> queryAdminModuleTree(String roleId, Boolean admin, List<String> hasModule, AdminUser adminUser) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<AdminModule> adminModules = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (admin != null && !admin) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //非超管角色 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<AdminUserModuleRela> list = adminUserModuleRelaService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .eq(StringUtils.isNotBlank(roleId), AdminUserModuleRela::getAdminRoleId, roleId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .list(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (list.size() == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<String> moduleIds = list.stream().map(AdminUserModuleRela::getAdminModuleId).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminModules = adminModuleService.lambdaQuery().in(AdminModule::getModuleId, moduleIds) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .orderByAsc(AdminModule::getSortNum).list(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //超管角色 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminModules = adminModuleService.lambdaQuery().orderByAsc(AdminModule::getSortNum).list(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<AdminModuleTree> trees = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (AdminModule adminModule : adminModules) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            AdminModuleTree adminModuleTree = new AdminModuleTree(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            BeanUtils.copyProperties(adminModule, adminModuleTree); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if ((hasModule != null && hasModule.contains(adminModule.getModuleId())) || admin) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                adminModuleTree.setShow(true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            trees.add(adminModuleTree); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<AdminModuleTree> parents = trees.stream().filter(v -> v.getLevel() == 1).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (AdminModuleTree adminModuleTree : parents) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminModuleTree.setChildren(this.treeModule(trees, adminModuleTree.getModuleId(), hasModule, admin)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return parents; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private List<AdminModuleTree> treeModule(List<AdminModuleTree> list, String parentId, List<String> hasModule, Boolean admin) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //最父级资源树 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (StringUtils.isBlank(parentId)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<AdminModuleTree> collect = list.stream().filter(e -> e.getParentId().equals(parentId)).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (AdminModuleTree bean : collect) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if ((hasModule != null && hasModule.contains(bean.getModuleId())) || admin) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                bean.setShow(true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            bean.setChildren(this.treeModule(list, bean.getModuleId(), hasModule, admin)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return collect; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 找回密码-获取验证码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param userName 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param mobile 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public AdminUserBean resetPasswordGetCode(String userName,String mobile, String code) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        smsLogic.checkSmsCode(mobile, code, "RESET"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        final AdminUser adminUser = adminUserService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(AdminUser::getUserName,userName) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(AdminUser::getLinkPhone, mobile) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .one(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (Objects.isNull(adminUser)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("账号不存在"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminUserBean bean = new AdminUserBean(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bean.setAdminUserId(adminUser.getAdminUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bean.setUserName(adminUser.getUserName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bean.setToken(IdUtil.simpleUUID()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        redisUtil.set(adminUser.getAdminUserId() + ":" + bean.getToken(), bean.getToken(), 5*60); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return bean; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 找回密码-更新密码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param adminUserId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param token 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param newPassword 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param confirmPassword 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void resetPasswordUpdate(String adminUserId, String token, String newPassword, String confirmPassword) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String redisKey = adminUserId + ":" + token; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!redisUtil.hasKey(redisKey)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("超时操作,请重新找回"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String value = (String)redisUtil.get(redisKey); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(!StringUtils.equals(value, token)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("修改密码,参数异常"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!StringUtils.equals(newPassword, confirmPassword)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("新密码与确认密码不匹配"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        adminUserService.lambdaUpdate() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .set(AdminUser::getPassword, SecureUtil.md5(newPassword)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(AdminUser::getAdminUserId, adminUserId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .update(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        redisUtil.del(redisKey); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void serviceUpdateMpMobile(String mobile) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        final AdminUserCom adminUser = commonLogic.getAdminUser(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!(adminUser.getType().equals(RoleTypeEnum.B.getCode()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                || adminUser.getType().equals(RoleTypeEnum.D.getCode()))) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("非服务商不能修改"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        serviceProviderService.lambdaUpdate() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .set(ServiceProvider::getReceiveMpMobile, mobile) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(ServiceProvider::getId, adminUser.getServiceProviderId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .update(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public AdminUserBean renewal(String token) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        final Object o = redisUtil.get(Constant.RedisPrefix.TOKEN_MANAGE + token); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (Objects.isNull(o)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException(ResponseHelper.ResponseCode_AUTH_ERROR, "登录过期"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminUserBean bean = (AdminUserBean) o; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        final AdminUser adminUser = adminUserService.getById(bean.getAdminUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bean.setToken(JwtUtils.refreshToken(token, Constant.PC_API)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //存放到redis 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        redisUtil.set(Constant.RedisPrefix.TOKEN_MANAGE + bean.getToken(), adminUser, 2 * 60 * 60 * 1000); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return bean; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |