|  | @@ -3,17 +3,23 @@ package com.fs.qw;
 | 
											
												
													
														|  |  import com.alibaba.fastjson.JSON;
 |  |  import com.alibaba.fastjson.JSON;
 | 
											
												
													
														|  |  import com.fs.common.annotation.Log;
 |  |  import com.fs.common.annotation.Log;
 | 
											
												
													
														|  |  import com.fs.common.annotation.RepeatSubmit;
 |  |  import com.fs.common.annotation.RepeatSubmit;
 | 
											
												
													
														|  | 
 |  | +import com.fs.common.constant.Constants;
 | 
											
												
													
														|  |  import com.fs.common.core.controller.BaseController;
 |  |  import com.fs.common.core.controller.BaseController;
 | 
											
												
													
														|  |  import com.fs.common.core.domain.AjaxResult;
 |  |  import com.fs.common.core.domain.AjaxResult;
 | 
											
												
													
														|  |  import com.fs.common.core.domain.R;
 |  |  import com.fs.common.core.domain.R;
 | 
											
												
													
														|  |  import com.fs.common.core.page.TableDataInfo;
 |  |  import com.fs.common.core.page.TableDataInfo;
 | 
											
												
													
														|  |  import com.fs.common.enums.BusinessType;
 |  |  import com.fs.common.enums.BusinessType;
 | 
											
												
													
														|  | 
 |  | +import com.fs.common.exception.ServiceException;
 | 
											
												
													
														|  | 
 |  | +import com.fs.common.exception.user.UserPasswordNotMatchException;
 | 
											
												
													
														|  | 
 |  | +import com.fs.common.utils.MessageUtils;
 | 
											
												
													
														|  |  import com.fs.common.utils.ServletUtils;
 |  |  import com.fs.common.utils.ServletUtils;
 | 
											
												
													
														|  |  import com.fs.common.utils.poi.ExcelUtil;
 |  |  import com.fs.common.utils.poi.ExcelUtil;
 | 
											
												
													
														|  |  import com.fs.company.domain.Company;
 |  |  import com.fs.company.domain.Company;
 | 
											
												
													
														|  |  import com.fs.company.domain.CompanyUser;
 |  |  import com.fs.company.domain.CompanyUser;
 | 
											
												
													
														|  |  import com.fs.company.mapper.CompanyUserMapper;
 |  |  import com.fs.company.mapper.CompanyUserMapper;
 | 
											
												
													
														|  |  import com.fs.company.service.ICompanyUserService;
 |  |  import com.fs.company.service.ICompanyUserService;
 | 
											
												
													
														|  | 
 |  | +import com.fs.core.manager.AsyncManager;
 | 
											
												
													
														|  | 
 |  | +import com.fs.core.manager.factory.AsyncFactory;
 | 
											
												
													
														|  |  import com.fs.fastGpt.domain.FastGptRole;
 |  |  import com.fs.fastGpt.domain.FastGptRole;
 | 
											
												
													
														|  |  import com.fs.fastGpt.mapper.FastGptRoleMapper;
 |  |  import com.fs.fastGpt.mapper.FastGptRoleMapper;
 | 
											
												
													
														|  |  import com.fs.core.security.LoginUser;
 |  |  import com.fs.core.security.LoginUser;
 | 
											
										
											
												
													
														|  | @@ -38,10 +44,18 @@ import com.fs.voice.utils.StringUtil;
 | 
											
												
													
														|  |  import org.slf4j.LoggerFactory;
 |  |  import org.slf4j.LoggerFactory;
 | 
											
												
													
														|  |  import org.springframework.beans.factory.annotation.Autowired;
 |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
											
												
													
														|  |  import org.springframework.security.access.prepost.PreAuthorize;
 |  |  import org.springframework.security.access.prepost.PreAuthorize;
 | 
											
												
													
														|  | 
 |  | +import org.springframework.security.authentication.AuthenticationManager;
 | 
											
												
													
														|  | 
 |  | +import org.springframework.security.authentication.BadCredentialsException;
 | 
											
												
													
														|  | 
 |  | +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 | 
											
												
													
														|  | 
 |  | +import org.springframework.security.core.Authentication;
 | 
											
												
													
														|  |  import org.springframework.web.bind.annotation.*;
 |  |  import org.springframework.web.bind.annotation.*;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +import javax.annotation.Resource;
 | 
											
												
													
														|  |  import java.util.Arrays;
 |  |  import java.util.Arrays;
 | 
											
												
													
														|  | 
 |  | +import java.util.HashSet;
 | 
											
												
													
														|  |  import java.util.List;
 |  |  import java.util.List;
 | 
											
												
													
														|  | 
 |  | +import java.util.Set;
 | 
											
												
													
														|  | 
 |  | +import java.util.stream.Collectors;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  /**
 |  |  /**
 | 
											
												
													
														|  |   * 企微用户Controller
 |  |   * 企微用户Controller
 | 
											
										
											
												
													
														|  | @@ -78,6 +92,10 @@ public class QwUserController extends BaseController
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      @Autowired
 |  |      @Autowired
 | 
											
												
													
														|  |      private QwApiService qwApiService;
 |  |      private QwApiService qwApiService;
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    @Resource
 | 
											
												
													
														|  | 
 |  | +    private AuthenticationManager authenticationManager;
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
												
													
														|  |       * 查询企微员工列表
 |  |       * 查询企微员工列表
 | 
											
												
													
														|  |       */
 |  |       */
 | 
											
										
											
												
													
														|  | @@ -95,8 +113,8 @@ public class QwUserController extends BaseController
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
												
													
														|  | -    * 直接授权key
 |  | 
 | 
											
												
													
														|  | -    */
 |  | 
 | 
											
												
													
														|  | 
 |  | +     * 直接授权key
 | 
											
												
													
														|  | 
 |  | +     */
 | 
											
												
													
														|  |      @PreAuthorize("@ss.hasPermi('qw:user:authAppKey')")
 |  |      @PreAuthorize("@ss.hasPermi('qw:user:authAppKey')")
 | 
											
												
													
														|  |      @PostMapping("/authAppKey")
 |  |      @PostMapping("/authAppKey")
 | 
											
												
													
														|  |      public R authAppKey(@RequestBody QwUser param){
 |  |      public R authAppKey(@RequestBody QwUser param){
 | 
											
										
											
												
													
														|  | @@ -114,8 +132,8 @@ public class QwUserController extends BaseController
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
												
													
														|  | -    * 登录企业微信(发起登录)
 |  | 
 | 
											
												
													
														|  | -    */
 |  | 
 | 
											
												
													
														|  | 
 |  | +     * 登录企业微信(发起登录)
 | 
											
												
													
														|  | 
 |  | +     */
 | 
											
												
													
														|  |      @PreAuthorize("@ss.hasPermi('qw:user:login')")
 |  |      @PreAuthorize("@ss.hasPermi('qw:user:login')")
 | 
											
												
													
														|  |      @PostMapping("/loginQwCode")
 |  |      @PostMapping("/loginQwCode")
 | 
											
												
													
														|  |      public R loginQwCode(@RequestBody QwLoginParam loginParam){
 |  |      public R loginQwCode(@RequestBody QwLoginParam loginParam){
 | 
											
										
											
												
													
														|  | @@ -140,8 +158,8 @@ public class QwUserController extends BaseController
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
												
													
														|  | -    * 登录企业微信(传输验证信息)
 |  | 
 | 
											
												
													
														|  | -    */
 |  | 
 | 
											
												
													
														|  | 
 |  | +     * 登录企业微信(传输验证信息)
 | 
											
												
													
														|  | 
 |  | +     */
 | 
											
												
													
														|  |      @PreAuthorize("@ss.hasPermi('qw:user:login')")
 |  |      @PreAuthorize("@ss.hasPermi('qw:user:login')")
 | 
											
												
													
														|  |      @PostMapping("/loginQwCodeMsg")
 |  |      @PostMapping("/loginQwCodeMsg")
 | 
											
												
													
														|  |      public R loginQwCodeMsg(@RequestBody QwLoginParam loginParam){
 |  |      public R loginQwCodeMsg(@RequestBody QwLoginParam loginParam){
 | 
											
										
											
												
													
														|  | @@ -167,8 +185,8 @@ public class QwUserController extends BaseController
 | 
											
												
													
														|  |  //    }
 |  |  //    }
 | 
											
												
													
														|  |  //
 |  |  //
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
												
													
														|  | -    * 查询企业微信登录状态
 |  | 
 | 
											
												
													
														|  | -    */
 |  | 
 | 
											
												
													
														|  | 
 |  | +     * 查询企业微信登录状态
 | 
											
												
													
														|  | 
 |  | +     */
 | 
											
												
													
														|  |      @PreAuthorize("@ss.hasPermi('qw:user:login')")
 |  |      @PreAuthorize("@ss.hasPermi('qw:user:login')")
 | 
											
												
													
														|  |      @PostMapping("/getLoginQwStatus")
 |  |      @PostMapping("/getLoginQwStatus")
 | 
											
												
													
														|  |      public R getLoginQwStatus(@RequestBody QwLoginParam loginParam){
 |  |      public R getLoginQwStatus(@RequestBody QwLoginParam loginParam){
 | 
											
										
											
												
													
														|  | @@ -181,27 +199,62 @@ public class QwUserController extends BaseController
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
												
													
														|  | -    * 企业微信员工账号 绑定 云主机
 |  | 
 | 
											
												
													
														|  | -    */
 |  | 
 | 
											
												
													
														|  | 
 |  | +     * 企业微信员工账号 绑定 云主机
 | 
											
												
													
														|  | 
 |  | +     */
 | 
											
												
													
														|  |      @PreAuthorize("@ss.hasPermi('qw:user:loginIp')")
 |  |      @PreAuthorize("@ss.hasPermi('qw:user:loginIp')")
 | 
											
												
													
														|  | 
 |  | +    @Log(title = "绑定 云主机", businessType = BusinessType.INSERT)
 | 
											
												
													
														|  |      @GetMapping("/qwBindCloudHost/{appKey}")
 |  |      @GetMapping("/qwBindCloudHost/{appKey}")
 | 
											
												
													
														|  |      public R qwBindCloudHost(@PathVariable("appKey") String appKey){
 |  |      public R qwBindCloudHost(@PathVariable("appKey") String appKey){
 | 
											
												
													
														|  |          return qwUserService.qwBindCloudHost(appKey);
 |  |          return qwUserService.qwBindCloudHost(appKey);
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
												
													
														|  | -    * 获取云主机的账密
 |  | 
 | 
											
												
													
														|  | 
 |  | +     * 获取云主机的账密
 | 
											
												
													
														|  |       *
 |  |       *
 | 
											
												
													
														|  | -    */
 |  | 
 | 
											
												
													
														|  | 
 |  | +     */
 | 
											
												
													
														|  |      @PreAuthorize("@ss.hasPermi('qw:user:cloudAP')")
 |  |      @PreAuthorize("@ss.hasPermi('qw:user:cloudAP')")
 | 
											
												
													
														|  |      @PostMapping("/selectCloudAP")
 |  |      @PostMapping("/selectCloudAP")
 | 
											
												
													
														|  |      public R selectCloudAP(@RequestBody QwCloudAPParam param) throws Exception {
 |  |      public R selectCloudAP(@RequestBody QwCloudAPParam param) throws Exception {
 | 
											
												
													
														|  |          return qwUserService.selectCloudAP(param);
 |  |          return qwUserService.selectCloudAP(param);
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    /**
 | 
											
												
													
														|  | 
 |  | +     * 根据销售账号密码 获取 他的所有企业微信账号以及云主机和账号密码
 | 
											
												
													
														|  | 
 |  | +     */
 | 
											
												
													
														|  | 
 |  | +    @PostMapping("/selectCloudByCompany")
 | 
											
												
													
														|  | 
 |  | +    public R selectCloudByCompany(@RequestBody QwCloudIPByCompanyParam param) throws Exception {
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        // 用户验证
 | 
											
												
													
														|  | 
 |  | +        Authentication authentication = null;
 | 
											
												
													
														|  | 
 |  | +        try
 | 
											
												
													
														|  | 
 |  | +        {
 | 
											
												
													
														|  | 
 |  | +            // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
 | 
											
												
													
														|  | 
 |  | +            authentication = authenticationManager
 | 
											
												
													
														|  | 
 |  | +                    .authenticate(new UsernamePasswordAuthenticationToken(param.getCompanyAdmin(), param.getCompanyPassWord()));
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        catch (Exception e)
 | 
											
												
													
														|  | 
 |  | +        {
 | 
											
												
													
														|  | 
 |  | +            if (e instanceof BadCredentialsException)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                AsyncManager.me().execute(AsyncFactory.recordLogininfor(0l,param.getCompanyAdmin(), Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
 | 
											
												
													
														|  | 
 |  | +                throw new UserPasswordNotMatchException();
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            else
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                AsyncManager.me().execute(AsyncFactory.recordLogininfor(0l,param.getCompanyAdmin(), Constants.LOGIN_FAIL, e.getMessage()));
 | 
											
												
													
														|  | 
 |  | +                throw new ServiceException(e.getMessage());
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        LoginUser loginUser=(LoginUser) authentication.getPrincipal();
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        return qwUserService.selectCloudByCompany(loginUser.getUser().getCompanyId(),loginUser.getUser().getUserId());
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
												
													
														|  |       * 企业微信员工账号 绑定 云主机
 |  |       * 企业微信员工账号 绑定 云主机
 | 
											
												
													
														|  |       */
 |  |       */
 | 
											
												
													
														|  | -//    @PreAuthorize("@ss.hasPermi('qw:user:loginIp')")
 |  | 
 | 
											
												
													
														|  | 
 |  | +    @PreAuthorize("@ss.hasPermi('qw:user:bindIp')")
 | 
											
												
													
														|  |      @GetMapping("/qwBindCloudHostByIp/{appKey}/{IP}")
 |  |      @GetMapping("/qwBindCloudHostByIp/{appKey}/{IP}")
 | 
											
												
													
														|  |      public R qwBindCloudHostByIp(@PathVariable("appKey") String appKey,@PathVariable("IP") String IP){
 |  |      public R qwBindCloudHostByIp(@PathVariable("appKey") String appKey,@PathVariable("IP") String IP){
 | 
											
												
													
														|  |          return qwUserService.qwBindCloudHostByIp(appKey,IP);
 |  |          return qwUserService.qwBindCloudHostByIp(appKey,IP);
 | 
											
										
											
												
													
														|  | @@ -211,6 +264,7 @@ public class QwUserController extends BaseController
 | 
											
												
													
														|  |       * 企业微信员工账号 解除绑定 云主机
 |  |       * 企业微信员工账号 解除绑定 云主机
 | 
											
												
													
														|  |       */
 |  |       */
 | 
											
												
													
														|  |      @PreAuthorize("@ss.hasPermi('qw:user:loginIpOut')")
 |  |      @PreAuthorize("@ss.hasPermi('qw:user:loginIpOut')")
 | 
											
												
													
														|  | 
 |  | +    @Log(title = "解除绑定 云主机", businessType = BusinessType.UPDATE)
 | 
											
												
													
														|  |      @GetMapping("/qwUnbindCloudHost/{appKey}")
 |  |      @GetMapping("/qwUnbindCloudHost/{appKey}")
 | 
											
												
													
														|  |      public R qwUnbindCloudHost(@PathVariable("appKey") String appKey){
 |  |      public R qwUnbindCloudHost(@PathVariable("appKey") String appKey){
 | 
											
												
													
														|  |          return qwUserService.qwUnbindCloudHost(appKey);
 |  |          return qwUserService.qwUnbindCloudHost(appKey);
 | 
											
										
											
												
													
														|  | @@ -277,8 +331,8 @@ public class QwUserController extends BaseController
 | 
											
												
													
														|  |          return util.exportExcel(list, "企微用户数据");
 |  |          return util.exportExcel(list, "企微用户数据");
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
												
													
														|  | -    * 查询企微员工列表-用于员工管理绑定
 |  | 
 | 
											
												
													
														|  | -    */
 |  | 
 | 
											
												
													
														|  | 
 |  | +     * 查询企微员工列表-用于员工管理绑定
 | 
											
												
													
														|  | 
 |  | +     */
 | 
											
												
													
														|  |      @GetMapping("/getQwUserList")
 |  |      @GetMapping("/getQwUserList")
 | 
											
												
													
														|  |      public R getQwUserList()
 |  |      public R getQwUserList()
 | 
											
												
													
														|  |      {
 |  |      {
 | 
											
										
											
												
													
														|  | @@ -318,8 +372,8 @@ public class QwUserController extends BaseController
 | 
											
												
													
														|  |          return AjaxResult.success(qwUserService.selectQwUserVOById(id));
 |  |          return AjaxResult.success(qwUserService.selectQwUserVOById(id));
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
												
													
														|  | -    * 批量查询 企微用户详细信息
 |  | 
 | 
											
												
													
														|  | -    */
 |  | 
 | 
											
												
													
														|  | 
 |  | +     * 批量查询 企微用户详细信息
 | 
											
												
													
														|  | 
 |  | +     */
 | 
											
												
													
														|  |      @GetMapping(value = "/getInfo/{ids}")
 |  |      @GetMapping(value = "/getInfo/{ids}")
 | 
											
												
													
														|  |      public AjaxResult getInfoByIds(@PathVariable("ids") Long[] ids)
 |  |      public AjaxResult getInfoByIds(@PathVariable("ids") Long[] ids)
 | 
											
												
													
														|  |      {
 |  |      {
 | 
											
										
											
												
													
														|  | @@ -364,7 +418,22 @@ public class QwUserController extends BaseController
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |          return R.ok();
 |  |          return R.ok();
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | 
 |  | +    @RepeatSubmit
 | 
											
												
													
														|  | 
 |  | +    @PreAuthorize("@ss.hasPermi('qw:user:sync')")
 | 
											
												
													
														|  | 
 |  | +    @Log(title = "企微用户", businessType = BusinessType.INSERT)
 | 
											
												
													
														|  | 
 |  | +    @PostMapping("syncName/{corpId}")
 | 
											
												
													
														|  | 
 |  | +    public R syncName(@PathVariable String corpId)
 | 
											
												
													
														|  | 
 |  | +    {
 | 
											
												
													
														|  | 
 |  | +        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
 | 
											
												
													
														|  | 
 |  | +        Company company = loginUser.getCompany();
 | 
											
												
													
														|  | 
 |  | +        List<String> strings = qwCompanyMapper.selectQwCompanyCorpIdListByCompanyId(company.getCompanyId());
 | 
											
												
													
														|  | 
 |  | +        for (String string : strings) {
 | 
											
												
													
														|  | 
 |  | +            if (string.equals(corpId)){
 | 
											
												
													
														|  | 
 |  | +                qwUserService.syncQwUserName(string);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        return R.ok();
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
												
													
														|  |       * 绑定AI客服
 |  |       * 绑定AI客服
 | 
											
												
													
														|  |       */
 |  |       */
 | 
											
										
											
												
													
														|  | @@ -380,11 +449,11 @@ public class QwUserController extends BaseController
 | 
											
												
													
														|  |          FastGptRole role = fastGptRoleMapper.selectFastGptRoleByRoleId(param.getFastGptRoleId());
 |  |          FastGptRole role = fastGptRoleMapper.selectFastGptRoleByRoleId(param.getFastGptRoleId());
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          if (role.getBindCorpId()!=null){
 |  |          if (role.getBindCorpId()!=null){
 | 
											
												
													
														|  | -           if (role.getBindCorpId().equals(param.getCorpId())){
 |  | 
 | 
											
												
													
														|  | -               qwUserService.updateQwUser(qwUser);
 |  | 
 | 
											
												
													
														|  | -           }else {
 |  | 
 | 
											
												
													
														|  | -               return R.error("该角色已绑定其他企业");
 |  | 
 | 
											
												
													
														|  | -           }
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (role.getBindCorpId().equals(param.getCorpId())){
 | 
											
												
													
														|  | 
 |  | +                qwUserService.updateQwUser(qwUser);
 | 
											
												
													
														|  | 
 |  | +            }else {
 | 
											
												
													
														|  | 
 |  | +                return R.error("该角色已绑定其他企业");
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |          }else {
 |  |          }else {
 | 
											
												
													
														|  |              int i = qwUserService.updateQwUser(qwUser);
 |  |              int i = qwUserService.updateQwUser(qwUser);
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -421,48 +490,83 @@ public class QwUserController extends BaseController
 | 
											
												
													
														|  |      @Log(title = "企微用户", businessType = BusinessType.UPDATE)
 |  |      @Log(title = "企微用户", businessType = BusinessType.UPDATE)
 | 
											
												
													
														|  |      @PutMapping("/bindQwUser")
 |  |      @PutMapping("/bindQwUser")
 | 
											
												
													
														|  |      @RepeatSubmit
 |  |      @RepeatSubmit
 | 
											
												
													
														|  | -    public R bindQwUser(@RequestBody QwUserBingParam qwUser)
 |  | 
 | 
											
												
													
														|  | 
 |  | +    public R bindQwUser(@RequestBody QwUserBingParam qwUserParam)
 | 
											
												
													
														|  |      {
 |  |      {
 | 
											
												
													
														|  | -        CompanyUser companyUser = companyUserService.selectCompanyUserById(qwUser.getCompanyUserId());
 |  | 
 | 
											
												
													
														|  | 
 |  | +        CompanyUser companyUser = companyUserService.selectCompanyUserById(qwUserParam.getCompanyUserId());
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        String qwUserIdCompanyStr = companyUser.getQwUserId();
 | 
											
												
													
														|  | 
 |  | +        Set<String> qwUserIdCompanySet = new HashSet<>();
 | 
											
												
													
														|  | 
 |  | +        if (!StringUtil.strIsNullOrEmpty(qwUserIdCompanyStr)) {
 | 
											
												
													
														|  | 
 |  | +            String[] qwUserId = qwUserIdCompanyStr.split(",");
 | 
											
												
													
														|  | 
 |  | +            qwUserIdCompanySet = Arrays.stream(qwUserId)
 | 
											
												
													
														|  | 
 |  | +                    .filter(id -> !id.isEmpty())
 | 
											
												
													
														|  | 
 |  | +                    .collect(Collectors.toSet());
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |          if (companyUser!=null){
 |  |          if (companyUser!=null){
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |              //选择的企业微信账号为“”
 |  |              //选择的企业微信账号为“”
 | 
											
												
													
														|  | -            if (StringUtil.strIsNullOrEmpty(qwUser.getId())&&qwUser.getCompanyUserId()!=null){
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (StringUtil.strIsNullOrEmpty(qwUserParam.getId())&&qwUserParam.getCompanyUserId()!=null){
 | 
											
												
													
														|  |                  //制空企业微信的绑定
 |  |                  //制空企业微信的绑定
 | 
											
												
													
														|  | -                qwUserService.updateUserByUserId(qwUser.getCompanyUserId());
 |  | 
 | 
											
												
													
														|  | 
 |  | +                qwUserService.updateUserByUserId(qwUserParam.getCompanyUserId());
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |                  //制空销售的绑定
 |  |                  //制空销售的绑定
 | 
											
												
													
														|  |                  companyUserMapper.updateCompanyUserByNullQwUserID(companyUser.getUserId());
 |  |                  companyUserMapper.updateCompanyUserByNullQwUserID(companyUser.getUserId());
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |              }else {
 |  |              }else {
 | 
											
												
													
														|  | -                String id = qwUser.getId();
 |  | 
 | 
											
												
													
														|  | -                String[] split = id.split(",");
 |  | 
 | 
											
												
													
														|  | -                for (String s : split) {
 |  | 
 | 
											
												
													
														|  | -                    QwUser qu= qwUserService.selectQwUserById(Long.parseLong(s));
 |  | 
 | 
											
												
													
														|  | -                    if (qu.getCompanyUserId()!=null&&!qu.getCompanyUserId().equals(qwUser.getCompanyUserId())){
 |  | 
 | 
											
												
													
														|  | 
 |  | +                String idParam = qwUserParam.getId();
 | 
											
												
													
														|  | 
 |  | +                String[] splitParam = idParam.split(",");
 | 
											
												
													
														|  | 
 |  | +                Set<String> splitParamSet = Arrays.stream(splitParam)
 | 
											
												
													
														|  | 
 |  | +                        .filter(s -> !s.isEmpty())
 | 
											
												
													
														|  | 
 |  | +                        .collect(Collectors.toSet());
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                // 找出在 qwUserIdCompanySet 中存在但在 splitParamSet 中不存在的元素
 | 
											
												
													
														|  | 
 |  | +                Set<String> difference = new HashSet<>(qwUserIdCompanySet);
 | 
											
												
													
														|  | 
 |  | +                difference.removeAll(splitParamSet);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                //制空绑定
 | 
											
												
													
														|  | 
 |  | +                if (!difference.isEmpty()){
 | 
											
												
													
														|  | 
 |  | +                    difference.forEach(id->{
 | 
											
												
													
														|  | 
 |  | +                        qwUserService.updateUnBindUserById(id);
 | 
											
												
													
														|  | 
 |  | +                    });
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                for (String paramId : splitParamSet) {
 | 
											
												
													
														|  | 
 |  | +                    QwUser qu= qwUserService.selectQwUserById(Long.parseLong(paramId));
 | 
											
												
													
														|  | 
 |  | +                    if (qu.getCompanyUserId()!=null&&!qu.getCompanyUserId().equals(qwUserParam.getCompanyUserId())){
 | 
											
												
													
														|  |                          return R.error( qu.getQwUserName()+"已经被其他人绑定,请先解绑");
 |  |                          return R.error( qu.getQwUserName()+"已经被其他人绑定,请先解绑");
 | 
											
												
													
														|  |                      }
 |  |                      }
 | 
											
												
													
														|  | -                }
 |  | 
 | 
											
												
													
														|  | -                //制空绑定
 |  | 
 | 
											
												
													
														|  | -                qwUserService.updateUserByUserId(qwUser.getCompanyUserId());
 |  | 
 | 
											
												
													
														|  | -                CompanyUser user = new CompanyUser();
 |  | 
 | 
											
												
													
														|  | -                user.setQwUserId(qwUser.getId());
 |  | 
 | 
											
												
													
														|  | -                user.setUserId(companyUser.getUserId());
 |  | 
 | 
											
												
													
														|  | -                user.setQwStatus(1);
 |  | 
 | 
											
												
													
														|  | -                companyUserMapper.updateCompanyUser(user);
 |  | 
 | 
											
												
													
														|  | -                for (String s : split) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                    CompanyUser user = new CompanyUser();
 | 
											
												
													
														|  | 
 |  | +                    user.setQwUserId(qwUserParam.getId());
 | 
											
												
													
														|  | 
 |  | +                    user.setUserId(companyUser.getUserId());
 | 
											
												
													
														|  | 
 |  | +                    user.setQwStatus(1);
 | 
											
												
													
														|  | 
 |  | +                    companyUserMapper.updateCompanyUser(user);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |                      QwUser qw = new QwUser();
 |  |                      QwUser qw = new QwUser();
 | 
											
												
													
														|  | -                    qw.setCompanyUserId(qwUser.getCompanyUserId());
 |  | 
 | 
											
												
													
														|  | -                    qw.setId(Long.parseLong(s));
 |  | 
 | 
											
												
													
														|  | 
 |  | +                    qw.setCompanyUserId(qwUserParam.getCompanyUserId());
 | 
											
												
													
														|  | 
 |  | +                    qw.setId(Long.parseLong(paramId));
 | 
											
												
													
														|  |                      qw.setStatus(1);
 |  |                      qw.setStatus(1);
 | 
											
												
													
														|  |                      qw.setCompanyId(companyUser.getCompanyId());
 |  |                      qw.setCompanyId(companyUser.getCompanyId());
 | 
											
												
													
														|  |                      qwUserService.updateQwUser(qw);
 |  |                      qwUserService.updateQwUser(qw);
 | 
											
												
													
														|  | -                    QwUser qu= qwUserService.selectQwUserById(Long.parseLong(s));
 |  | 
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -                    qwExternalContactMapper.updateBindUserByQwUser(qu.getCorpId(),qu.getQwUserId(),companyUser.getCompanyId(),companyUser.getUserId());
 |  | 
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                //同步最后单独跑/先不异步了pp
 | 
											
												
													
														|  | 
 |  | +                for (String paramId : splitParamSet){
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                    //如果销售没绑定过,全刷,否则只同步新的增加的
 | 
											
												
													
														|  | 
 |  | +                    if (StringUtil.strIsNullOrEmpty(qwUserIdCompanyStr)){
 | 
											
												
													
														|  | 
 |  | +                        updateAndSyncQwUser(paramId, companyUser);
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -                    //根据企微账号和公司id 同步企业微信账号(游标初始为空)
 |  | 
 | 
											
												
													
														|  | -                    syncMyQwExternalContact(qu,null);
 |  | 
 | 
											
												
													
														|  | 
 |  | +                    }
 | 
											
												
													
														|  | 
 |  | +                    else if (!StringUtil.strIsNullOrEmpty(qwUserIdCompanyStr) && !qwUserIdCompanySet.contains(paramId)){
 | 
											
												
													
														|  | 
 |  | +                        updateAndSyncQwUser(paramId, companyUser);
 | 
											
												
													
														|  | 
 |  | +                    }
 | 
											
												
													
														|  |                  }
 |  |                  }
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -474,6 +578,17 @@ public class QwUserController extends BaseController
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    private void updateAndSyncQwUser(String paramId, CompanyUser companyUser) {
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        QwUser qu= qwUserService.selectQwUserById(Long.parseLong(paramId));
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        qwExternalContactMapper.updateBindUserByQwUser(qu.getCorpId(),qu.getQwUserId(),companyUser.getCompanyId(),companyUser.getUserId());
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        //根据企微账号和公司id 同步企业微信账号(游标初始为空)
 | 
											
												
													
														|  | 
 |  | +        syncMyQwExternalContact(qu,null);
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |      /** 修改企微用户的欢迎语 */
 |  |      /** 修改企微用户的欢迎语 */
 | 
											
												
													
														|  |      @PostMapping("/weclomeQwUser")
 |  |      @PostMapping("/weclomeQwUser")
 | 
											
												
													
														|  |      public R weclomeQwUser(@RequestBody QwUser qwUser) throws Exception {
 |  |      public R weclomeQwUser(@RequestBody QwUser qwUser) throws Exception {
 | 
											
										
											
												
													
														|  | @@ -487,7 +602,7 @@ public class QwUserController extends BaseController
 | 
											
												
													
														|  |       */
 |  |       */
 | 
											
												
													
														|  |      @PreAuthorize("@ss.hasPermi('qw:user:remove')")
 |  |      @PreAuthorize("@ss.hasPermi('qw:user:remove')")
 | 
											
												
													
														|  |      @Log(title = "企微用户", businessType = BusinessType.DELETE)
 |  |      @Log(title = "企微用户", businessType = BusinessType.DELETE)
 | 
											
												
													
														|  | -	@DeleteMapping("/{ids}")
 |  | 
 | 
											
												
													
														|  | 
 |  | +    @DeleteMapping("/{ids}")
 | 
											
												
													
														|  |      public AjaxResult remove(@PathVariable Long[] ids)
 |  |      public AjaxResult remove(@PathVariable Long[] ids)
 | 
											
												
													
														|  |      {
 |  |      {
 | 
											
												
													
														|  |          return toAjax(qwUserService.deleteQwUserByIds(ids));
 |  |          return toAjax(qwUserService.deleteQwUserByIds(ids));
 | 
											
										
											
												
													
														|  | @@ -495,8 +610,8 @@ public class QwUserController extends BaseController
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
												
													
														|  | -    * 获取企业微信用户列表
 |  | 
 | 
											
												
													
														|  | -    */
 |  | 
 | 
											
												
													
														|  | 
 |  | +     * 获取企业微信用户列表
 | 
											
												
													
														|  | 
 |  | +     */
 | 
											
												
													
														|  |      @GetMapping("/qwUserList/{corpId}")
 |  |      @GetMapping("/qwUserList/{corpId}")
 | 
											
												
													
														|  |      public TableDataInfo qwUserList(@PathVariable String corpId)
 |  |      public TableDataInfo qwUserList(@PathVariable String corpId)
 | 
											
												
													
														|  |      {
 |  |      {
 | 
											
										
											
												
													
														|  | @@ -591,9 +706,9 @@ public class QwUserController extends BaseController
 | 
											
												
													
														|  |              return R.error("同步失败:"+list.getErrmsg());
 |  |              return R.error("同步失败:"+list.getErrmsg());
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -       if (!StringUtil.strIsNullOrEmpty(list.getNext_cursor())){
 |  | 
 | 
											
												
													
														|  | -           syncMyQwExternalContact(qwUser,list.getNext_cursor());
 |  | 
 | 
											
												
													
														|  | -       }
 |  | 
 | 
											
												
													
														|  | 
 |  | +        if (!StringUtil.strIsNullOrEmpty(list.getNext_cursor())){
 | 
											
												
													
														|  | 
 |  | +            syncMyQwExternalContact(qwUser,list.getNext_cursor());
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  |          return R.ok();
 |  |          return R.ok();
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  }
 |  |  }
 |