|
@@ -5,19 +5,22 @@ import cn.hutool.http.HttpRequest;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.redis.RedisCache;
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
|
+import com.fs.company.domain.CompanyUser;
|
|
import com.fs.company.service.ICompanyConfigService;
|
|
import com.fs.company.service.ICompanyConfigService;
|
|
|
|
+import com.fs.company.service.ICompanyUserService;
|
|
import com.fs.config.cloud.CloudHostProper;
|
|
import com.fs.config.cloud.CloudHostProper;
|
|
import com.fs.his.config.FsSysConfig;
|
|
import com.fs.his.config.FsSysConfig;
|
|
import com.fs.his.utils.ConfigUtil;
|
|
import com.fs.his.utils.ConfigUtil;
|
|
import com.fs.qw.domain.QwCompany;
|
|
import com.fs.qw.domain.QwCompany;
|
|
|
|
+import com.fs.qw.domain.QwIpadServerLog;
|
|
|
|
+import com.fs.qw.domain.QwIpadServerUser;
|
|
import com.fs.qw.domain.QwUser;
|
|
import com.fs.qw.domain.QwUser;
|
|
import com.fs.qw.dto.QwUserByToolDTO;
|
|
import com.fs.qw.dto.QwUserByToolDTO;
|
|
import com.fs.qw.dto.QwUserKeyDTO;
|
|
import com.fs.qw.dto.QwUserKeyDTO;
|
|
import com.fs.qw.mapper.QwUserMapper;
|
|
import com.fs.qw.mapper.QwUserMapper;
|
|
import com.fs.qw.param.*;
|
|
import com.fs.qw.param.*;
|
|
import com.fs.qw.result.QwFsServerBindResult;
|
|
import com.fs.qw.result.QwFsServerBindResult;
|
|
-import com.fs.qw.service.IQwCompanyService;
|
|
|
|
-import com.fs.qw.service.IQwUserService;
|
|
|
|
|
|
+import com.fs.qw.service.*;
|
|
import com.fs.qw.utils.RSASignatureUtils;
|
|
import com.fs.qw.utils.RSASignatureUtils;
|
|
import com.fs.qw.utils.RSAUtils;
|
|
import com.fs.qw.utils.RSAUtils;
|
|
import com.fs.qw.vo.QwCloudAPVO;
|
|
import com.fs.qw.vo.QwCloudAPVO;
|
|
@@ -31,16 +34,15 @@ import com.fs.qwApi.domain.inner.DeptUser;
|
|
import com.fs.qwApi.param.QwOpenidByUserParams;
|
|
import com.fs.qwApi.param.QwOpenidByUserParams;
|
|
import com.fs.qwApi.service.QwApiService;
|
|
import com.fs.qwApi.service.QwApiService;
|
|
import com.fs.voice.utils.StringUtil;
|
|
import com.fs.voice.utils.StringUtil;
|
|
|
|
+import com.fs.wxwork.dto.*;
|
|
|
|
+import com.fs.wxwork.service.WxWorkService;
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
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.scheduling.annotation.EnableAsync;
|
|
import org.springframework.scheduling.annotation.EnableAsync;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.io.BufferedInputStream;
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.FileOutputStream;
|
|
|
|
-import java.io.IOException;
|
|
|
|
|
|
+import java.io.*;
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
import java.security.KeyFactory;
|
|
import java.security.KeyFactory;
|
|
import java.security.PrivateKey;
|
|
import java.security.PrivateKey;
|
|
@@ -83,6 +85,99 @@ public class QwUserServiceImpl implements IQwUserService
|
|
// @Value("${hook.path}")
|
|
// @Value("${hook.path}")
|
|
// private String hookPath;
|
|
// private String hookPath;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ ICompanyUserService companyUserService;
|
|
|
|
+ @Autowired
|
|
|
|
+ IQwIpadServerService ipadServerService;
|
|
|
|
+ @Autowired
|
|
|
|
+ IQwIpadServerLogService qwIpadServerLogService;
|
|
|
|
+ @Autowired
|
|
|
|
+ IQwIpadServerUserService qwIpadServerUserService;
|
|
|
|
+ @Override
|
|
|
|
+ public R getQwIpad(QwLoginHookParam loginParam) {
|
|
|
|
+ QwUser qwUser = qwUserMapper.selectQwUserById(loginParam.getQwUserId());
|
|
|
|
+ Integer serverStatus = qwUser.getServerStatus();
|
|
|
|
+ if (serverStatus!=null && serverStatus==1){
|
|
|
|
+ return R.error("已经绑定过");
|
|
|
|
+ }
|
|
|
|
+ if (qwUser.getAppKey()==null){
|
|
|
|
+ return R.error("请先授权key");
|
|
|
|
+ }
|
|
|
|
+ CompanyUser companyUser = companyUserService.selectCompanyUserById(qwUser.getCompanyUserId());
|
|
|
|
+ if (companyUser==null){
|
|
|
|
+ return R.error("未绑定销售");
|
|
|
|
+ }
|
|
|
|
+ String addressId = companyUser.getAddressId();
|
|
|
|
+ if (addressId==null || addressId.isEmpty()){
|
|
|
|
+ return R.error("请先绑定地址");
|
|
|
|
+ }
|
|
|
|
+ Long serverId = ipadServerService.selectQwIpadServerByAddressId(addressId);
|
|
|
|
+ if (serverId==null){
|
|
|
|
+ return R.error(501,"该地区服务器剩余数量不足");
|
|
|
|
+ }
|
|
|
|
+ QwUser u = new QwUser();
|
|
|
|
+ u.setId(qwUser.getId());
|
|
|
|
+ u.setServerId(serverId);
|
|
|
|
+ u.setServerStatus(1);
|
|
|
|
+ qwUserMapper.updateQwUser(u);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ ipadServerService.subtractServer(serverId);
|
|
|
|
+ QwIpadServerLog qwIpadServerLog = new QwIpadServerLog();
|
|
|
|
+ qwIpadServerLog.setType(1);
|
|
|
|
+ qwIpadServerLog.setTilie("绑定");
|
|
|
|
+ qwIpadServerLog.setServerId(serverId);
|
|
|
|
+ qwIpadServerLog.setQwUserId(qwUser.getId());
|
|
|
|
+ qwIpadServerLog.setCompanyUserId(companyUser.getUserId());
|
|
|
|
+ qwIpadServerLog.setCompanyId(companyUser.getCompanyId());
|
|
|
|
+ qwIpadServerLog.setCreateTime(new Date());
|
|
|
|
+ qwIpadServerLogService.insertQwIpadServerLog(qwIpadServerLog);
|
|
|
|
+ QwIpadServerUser qwIpadServerUser = new QwIpadServerUser();
|
|
|
|
+ qwIpadServerUser.setCompanyUserId(companyUser.getUserId());
|
|
|
|
+ qwIpadServerUser.setCompanyId(companyUser.getCompanyId());
|
|
|
|
+ qwIpadServerUser.setCreateTime(new Date());
|
|
|
|
+ qwIpadServerUser.setServerId(serverId);
|
|
|
|
+ qwIpadServerUser.setQwUserId(qwUser.getId());
|
|
|
|
+ qwIpadServerUserService.insertQwIpadServerUser(qwIpadServerUser);
|
|
|
|
+
|
|
|
|
+ return R.ok();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public R delQwIpad(QwLoginHookParam loginParam) {
|
|
|
|
+ QwUser qwUser = qwUserMapper.selectQwUserById(loginParam.getQwUserId());
|
|
|
|
+ Integer serverStatus = qwUser.getServerStatus();
|
|
|
|
+ Long serverId = qwUser.getServerId();
|
|
|
|
+ if (serverStatus==0){
|
|
|
|
+ return R.error("不需要解绑");
|
|
|
|
+ }
|
|
|
|
+ if (serverId==null){
|
|
|
|
+ return R.error("serverId不存在");
|
|
|
|
+ }
|
|
|
|
+ QwUser u = new QwUser();
|
|
|
|
+ u.setId(qwUser.getId());
|
|
|
|
+ u.setServerId(null);
|
|
|
|
+ u.setServerStatus(0);
|
|
|
|
+ qwUserMapper.updateQwUser(u);
|
|
|
|
+ ipadServerService.addServer(serverId);
|
|
|
|
+ QwIpadServerLog qwIpadServerLog = new QwIpadServerLog();
|
|
|
|
+ qwIpadServerLog.setType(2);
|
|
|
|
+ qwIpadServerLog.setTilie("解绑");
|
|
|
|
+ qwIpadServerLog.setServerId(serverId);
|
|
|
|
+ qwIpadServerLog.setQwUserId(qwUser.getId());
|
|
|
|
+ qwIpadServerLog.setCompanyUserId(qwUser.getCompanyUserId());
|
|
|
|
+ qwIpadServerLog.setCompanyId(qwUser.getCompanyId());
|
|
|
|
+ qwIpadServerLog.setCreateTime(new Date());
|
|
|
|
+ qwIpadServerLogService.insertQwIpadServerLog(qwIpadServerLog);
|
|
|
|
+ qwIpadServerUserService.deleteQwIpadServerUserByQwUserId(qwUser.getId());
|
|
|
|
+ WxWorkGetQrCodeDTO wxWorkGetQrCodeDTO = new WxWorkGetQrCodeDTO();
|
|
|
|
+ wxWorkGetQrCodeDTO.setUuid(qwUser.getUid());
|
|
|
|
+ wxWorkService.LoginOut(wxWorkGetQrCodeDTO,qwUser.getServerId());
|
|
|
|
+ updateIpadStatus(qwUser.getId(),0);
|
|
|
|
+ return R.ok();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 查询企微用户
|
|
* 查询企微用户
|
|
*
|
|
*
|
|
@@ -962,6 +1057,200 @@ public class QwUserServiceImpl implements IQwUserService
|
|
return tempFile;
|
|
return tempFile;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ WxWorkService wxWorkService;
|
|
|
|
+ @Override
|
|
|
|
+ public R loginQwIpad(QwLoginHookParam loginParam) {
|
|
|
|
+ QwUser qwUser = qwUserMapper.selectQwUserById(loginParam.getQwUserId());
|
|
|
|
+ if (qwUser.getAppKey()==null){
|
|
|
|
+ return R.error("请先授权key");
|
|
|
|
+ }
|
|
|
|
+ Long serverId = qwUser.getServerId();
|
|
|
|
+ if (serverId==null){
|
|
|
|
+ return R.error("请先获取ai主机");
|
|
|
|
+ }
|
|
|
|
+ if (qwUser.getServerStatus()!=1){
|
|
|
|
+ return R.error("请先获取ai主机");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (qwUser.getUid()!=null){
|
|
|
|
+ WxWorkGetQrCodeDTO wxWorkGetQrCodeDTO = new WxWorkGetQrCodeDTO();
|
|
|
|
+ wxWorkGetQrCodeDTO.setUuid(qwUser.getUid());
|
|
|
|
+ WxWorkResponseDTO wxWorkResponseDTO = wxWorkService.automaticLogin(wxWorkGetQrCodeDTO,qwUser.getServerId());
|
|
|
|
+ if (wxWorkResponseDTO.getErrcode()==0){
|
|
|
|
+ updateIpadStatus(qwUser.getId(),1);
|
|
|
|
+ redisCache.setCacheObject("qrCode:uuid:"+qwUser.getUid(),loginParam.getQwUserId());
|
|
|
|
+ return R.ok("登录成功");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //自动登录失败
|
|
|
|
+ WxWorkInitDTO wxWorkInitDTO = new WxWorkInitDTO();
|
|
|
|
+ if (qwUser.getVid()!=null){
|
|
|
|
+ wxWorkInitDTO.setVid(qwUser.getVid());
|
|
|
|
+ }
|
|
|
|
+ WxWorkResponseDTO<WxWorkInitRespDTO> init = wxWorkService.init(wxWorkInitDTO,serverId);
|
|
|
|
+ if (init.getErrcode()!=0){
|
|
|
|
+ //vid登录失败
|
|
|
|
+ return R.error("初始化失败");
|
|
|
|
+ }
|
|
|
|
+ WxWorkInitRespDTO data = init.getData();
|
|
|
|
+ QwUser u = new QwUser();
|
|
|
|
+
|
|
|
|
+ u.setId(loginParam.getQwUserId());
|
|
|
|
+ u.setUid(data.getUuid());
|
|
|
|
+
|
|
|
|
+ qwUserMapper.updateQwUser(u);
|
|
|
|
+ if (data.getIs_login().equals("true")) {
|
|
|
|
+ updateIpadStatus(qwUser.getId(),1);
|
|
|
|
+ redisCache.setCacheObject("qrCode:uuid:"+data.getUuid(),loginParam.getQwUserId());
|
|
|
|
+ return R.ok("登录成功");
|
|
|
|
+ }
|
|
|
|
+ WxWorkSetCallbackUrlDTO wxWorkSetCallbackUrlDTO = new WxWorkSetCallbackUrlDTO();
|
|
|
|
+ wxWorkSetCallbackUrlDTO.setUrl("http://ipad.cdwjyyh.com/msg/callback/"+serverId);
|
|
|
|
+ wxWorkSetCallbackUrlDTO.setUuid(data.getUuid());
|
|
|
|
+ wxWorkService.SetCallbackUrl(wxWorkSetCallbackUrlDTO,serverId);
|
|
|
|
+
|
|
|
|
+ WxWorkGetQrCodeDTO wxWorkGetQrCodeDTO = new WxWorkGetQrCodeDTO();
|
|
|
|
+ wxWorkGetQrCodeDTO.setUuid(data.getUuid());
|
|
|
|
+ WxWorkResponseDTO<WxWorkGetQrCodeRespDTO> qrCode = wxWorkService.getQrCode(wxWorkGetQrCodeDTO,serverId);
|
|
|
|
+ WxWorkGetQrCodeRespDTO qrData = qrCode.getData();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ redisCache.setCacheObject("qrCode:uuid:"+data.getUuid(),loginParam.getQwUserId());
|
|
|
|
+ redisCache.setCacheObject("qrCode:qwUserId:"+loginParam.getQwUserId(),qrData.getKey(),10, TimeUnit.MINUTES);
|
|
|
|
+ redisCache.setCacheObject("qrCodeUid:qwUserId:"+loginParam.getQwUserId(),data.getUuid(),10, TimeUnit.MINUTES);
|
|
|
|
+ return R.ok().put("qrCode",qrData.getQrcode()).put("qrCode64",qrData.getQrcodeData());
|
|
|
|
+ }
|
|
|
|
+ void updateIpadStatus(Long id ,Integer status){
|
|
|
|
+ QwUser u = new QwUser();
|
|
|
|
+ u.setId(id);
|
|
|
|
+ u.setIpadStatus(status);
|
|
|
|
+ qwUserMapper.updateQwUser(u);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public R qrCodeStatus(QwLoginHookParam loginParam) {
|
|
|
|
+ String uid = redisCache.getCacheObject("qrCodeUid:qwUserId:" + loginParam.getQwUserId());
|
|
|
|
+ if (uid == null) {
|
|
|
|
+ return R.error("未获取到Uid");
|
|
|
|
+ }
|
|
|
|
+ Integer status = redisCache.getCacheObject("qrCodeUid:" + uid);
|
|
|
|
+ if (status==null){
|
|
|
|
+ return R.ok("100000");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return R.ok(status.toString());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public R qrCodeVerify(QwLoginHookParam loginParam) {
|
|
|
|
+
|
|
|
|
+ String key = redisCache.getCacheObject("qrCode:qwUserId:" + loginParam.getQwUserId());
|
|
|
|
+ String uid = redisCache.getCacheObject("qrCodeUid:qwUserId:" + loginParam.getQwUserId());
|
|
|
|
+ if (key==null||uid==null){
|
|
|
|
+ return R.error("初始化错误请重新登录");
|
|
|
|
+ }
|
|
|
|
+ QwUser qwUser = qwUserMapper.selectQwUserById(loginParam.getQwUserId());
|
|
|
|
+ WxWorkCheckCodeDTO wxWorkCheckCodeDTO = new WxWorkCheckCodeDTO();
|
|
|
|
+ wxWorkCheckCodeDTO.setUuid(uid);
|
|
|
|
+ wxWorkCheckCodeDTO.setCode(loginParam.getCode());
|
|
|
|
+ wxWorkCheckCodeDTO.setQrcodeKey(key);
|
|
|
|
+ System.out.println("登录参数:"+wxWorkCheckCodeDTO);
|
|
|
|
+ WxWorkResponseDTO wxWorkResponseDTO = wxWorkService.CheckCode(wxWorkCheckCodeDTO,qwUser.getServerId());
|
|
|
|
+ if (wxWorkResponseDTO.getErrcode()==0){
|
|
|
|
+ return R.ok();
|
|
|
|
+ }
|
|
|
|
+ return R.error("验证码错误重新输入验证码或重新扫码登录");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public R outLoginQwIpad(QwLoginHookParam loginParam) {
|
|
|
|
+ QwUser qwUser = qwUserMapper.selectQwUserById(loginParam.getQwUserId());
|
|
|
|
+ if (qwUser.getAppKey()==null){
|
|
|
|
+ return R.error("请先授权key");
|
|
|
|
+ }
|
|
|
|
+ if (qwUser.getServerStatus()!=1){
|
|
|
|
+ return R.error("请先获取ai主机");
|
|
|
|
+ }
|
|
|
|
+ if (qwUser.getServerId()==null){
|
|
|
|
+ return R.error("请先获取ai主机");
|
|
|
|
+ }
|
|
|
|
+ WxWorkGetQrCodeDTO wxWorkGetQrCodeDTO = new WxWorkGetQrCodeDTO();
|
|
|
|
+ wxWorkGetQrCodeDTO.setUuid(qwUser.getUid());
|
|
|
|
+ try {
|
|
|
|
+ wxWorkService.LoginOut(wxWorkGetQrCodeDTO,qwUser.getServerId());
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ updateIpadStatus(qwUser.getId(),0);
|
|
|
|
+ return R.ok();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public R getTwoCode(QwLoginHookParam loginParam) {
|
|
|
|
+ QwUser qwUser = qwUserMapper.selectQwUserById(loginParam.getQwUserId());
|
|
|
|
+ if (qwUser.getAppKey()==null){
|
|
|
|
+ return R.error("请先授权key");
|
|
|
|
+ }
|
|
|
|
+ if (qwUser.getServerStatus()!=1){
|
|
|
|
+ return R.error("请先获取ai主机");
|
|
|
|
+ }
|
|
|
|
+ if (qwUser.getServerId()==null){
|
|
|
|
+ return R.error("请先获取ai主机");
|
|
|
|
+ }
|
|
|
|
+ WxWorkGetQrCodeDTO wxWorkGetQrCodeDTO = new WxWorkGetQrCodeDTO();
|
|
|
|
+ wxWorkGetQrCodeDTO.setUuid(qwUser.getUid());
|
|
|
|
+ WxWorkResponseDTO<WxwSecondaryValidationRespDTO> wxwSecondaryValidationRespDTOWxWorkResponseDTO = wxWorkService.SecondaryValidation(wxWorkGetQrCodeDTO,qwUser.getServerId());
|
|
|
|
+ if (wxwSecondaryValidationRespDTOWxWorkResponseDTO.getErrcode()==0){
|
|
|
|
+ WxwSecondaryValidationRespDTO data = wxwSecondaryValidationRespDTOWxWorkResponseDTO.getData();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ String base64 = convertImageToBase64(data.getQrcode());
|
|
|
|
+ return R.ok().put("data",data).put("qrCode",base64);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ return R.error("二维码图片解析失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return R.error("未获取到二次验证信息");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static String convertImageToBase64(String imageUrl) throws IOException {
|
|
|
|
+ // 创建URL对象
|
|
|
|
+ URL url = new URL(imageUrl);
|
|
|
|
+
|
|
|
|
+ // 打开输入流
|
|
|
|
+ try (InputStream inputStream = url.openStream();
|
|
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
|
|
|
+
|
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
|
+ int bytesRead;
|
|
|
|
+
|
|
|
|
+ // 读取图片数据
|
|
|
|
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
|
|
|
|
+ outputStream.write(buffer, 0, bytesRead);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 将字节数组转换为Base64字符串
|
|
|
|
+ byte[] imageBytes = outputStream.toByteArray();
|
|
|
|
+ return Base64.getEncoder().encodeToString(imageBytes);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ @Override
|
|
|
|
+ public R getTwoCodeStatus(QwLoginHookParam loginParam) {
|
|
|
|
+ String uid = redisCache.getCacheObject("qrCodeUid:qwUserId:" + loginParam.getQwUserId());
|
|
|
|
+ if (uid == null) {
|
|
|
|
+ return R.error("未获取到Uid");
|
|
|
|
+ }
|
|
|
|
+ Integer status = redisCache.getCacheObject("twoCodeUid:" + uid);
|
|
|
|
+ if (status==null){
|
|
|
|
+ return R.ok("100000");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return R.ok(status.toString());
|
|
|
|
+ }
|
|
/**
|
|
/**
|
|
* 获取文件名
|
|
* 获取文件名
|
|
*/
|
|
*/
|