|
|
@@ -1,14 +1,27 @@
|
|
|
package com.fs.company.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fs.common.annotation.DataScope;
|
|
|
+import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
+import com.fs.company.domain.Company;
|
|
|
import com.fs.company.domain.CompanyUser;
|
|
|
import com.fs.company.domain.CompanyWxAccount;
|
|
|
import com.fs.company.mapper.CompanyWxAccountMapper;
|
|
|
+import com.fs.company.service.ICompanyService;
|
|
|
+import com.fs.company.service.ICompanyUserService;
|
|
|
import com.fs.company.service.ICompanyWxAccountService;
|
|
|
+import com.fs.wxcid.domain.CidIpadServerUser;
|
|
|
+import com.fs.wxcid.dto.login.LoginStatusData;
|
|
|
+import com.fs.wxcid.service.AdminLicenseService;
|
|
|
+import com.fs.wxcid.service.ICidIpadServerService;
|
|
|
+import com.fs.wxcid.service.ICidIpadServerUserService;
|
|
|
+import com.fs.wxcid.service.impl.LoginServiceImpl;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -18,10 +31,21 @@ import java.util.List;
|
|
|
* @date 2024-12-09
|
|
|
*/
|
|
|
@Service
|
|
|
-public class CompanyWxServiceImpl implements ICompanyWxAccountService
|
|
|
-{
|
|
|
+public class CompanyWxServiceImpl extends ServiceImpl<CompanyWxAccountMapper, CompanyWxAccount> implements ICompanyWxAccountService {
|
|
|
@Autowired
|
|
|
private CompanyWxAccountMapper companyWxAccountMapper;
|
|
|
+ @Autowired
|
|
|
+ private LoginServiceImpl loginService;
|
|
|
+ @Autowired
|
|
|
+ private ICompanyService companyService;
|
|
|
+ @Autowired
|
|
|
+ private ICompanyUserService companyUserService;
|
|
|
+ @Autowired
|
|
|
+ private ICidIpadServerService cidIpadServerService;
|
|
|
+ @Autowired
|
|
|
+ private ICidIpadServerUserService cidIpadServerUserService;
|
|
|
+ @Autowired
|
|
|
+ private AdminLicenseService adminLicenseService;
|
|
|
|
|
|
/**
|
|
|
* 查询企微账号
|
|
|
@@ -117,4 +141,71 @@ public class CompanyWxServiceImpl implements ICompanyWxAccountService
|
|
|
public CompanyWxAccount selectByCompanyUserAndWxNo(Long userId, String wxNo) {
|
|
|
return companyWxAccountMapper.selectByCompanyUserAndWxNo(userId, wxNo);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getWxQrCode(Long accountId, String ipadOrMac) {
|
|
|
+ CompanyWxAccount account = getById(accountId);
|
|
|
+ if(account.getAuthKey() == null){
|
|
|
+ String token = adminLicenseService.getToken(accountId);
|
|
|
+ account.setAuthKey(token);
|
|
|
+ updateById(account);
|
|
|
+ }
|
|
|
+ return loginService.getLoginQrCodeNewDirect(accountId, ipadOrMac);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean getLoginStatus(Long accountId) {
|
|
|
+ CompanyWxAccount account = getById(accountId);
|
|
|
+ LoginStatusData login = loginService.getLoginStatus(accountId);
|
|
|
+ if(login.getLoginState() == 1){
|
|
|
+ account.setLoginStatus(1);
|
|
|
+ updateById(account);
|
|
|
+ return true;
|
|
|
+ }else{
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R bindService(Long accountId) {
|
|
|
+ CompanyWxAccount account = getById(accountId);
|
|
|
+ Company company = companyService.selectCompanyById(account.getCompanyId());
|
|
|
+ if(company !=null && company.getMaxPadNum() != null && company.getMaxPadNum() != -1){
|
|
|
+ int padCount = baseMapper.selectCount(new QueryWrapper<CompanyWxAccount>()
|
|
|
+ .eq("company_id", company.getCompanyId())
|
|
|
+ .isNotNull("server_id"));
|
|
|
+ if (padCount>=company.getMaxPadNum()){
|
|
|
+ return R.error(501,"该销售公司绑定pad数量超过限制");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Integer serverStatus = account.getServerStatus();
|
|
|
+ if (serverStatus!=null && serverStatus==1){
|
|
|
+ return R.error("已经绑定过");
|
|
|
+ }
|
|
|
+ CompanyUser companyUser = companyUserService.selectCompanyUserById(account.getCompanyUserId());
|
|
|
+ if (companyUser==null){
|
|
|
+ return R.error("未绑定销售");
|
|
|
+ }
|
|
|
+ String addressId = companyUser.getAddressId();
|
|
|
+ if (addressId==null || addressId.isEmpty()){
|
|
|
+ return R.error("请先绑定地址");
|
|
|
+ }
|
|
|
+ Long serverId = cidIpadServerService.selectQwIpadServerByAddressId(addressId);
|
|
|
+ if (serverId==null){
|
|
|
+ return R.error(501,"该地区服务器剩余数量不足");
|
|
|
+ }
|
|
|
+ account.setServerId(serverId);
|
|
|
+ account.setServerStatus(1);
|
|
|
+ updateById(account);
|
|
|
+
|
|
|
+ cidIpadServerService.subtractServer(serverId);
|
|
|
+ CidIpadServerUser qwIpadServerUser = new CidIpadServerUser();
|
|
|
+ qwIpadServerUser.setCompanyUserId(companyUser.getUserId());
|
|
|
+ qwIpadServerUser.setCompanyId(companyUser.getCompanyId());
|
|
|
+ qwIpadServerUser.setCreateTime(new Date());
|
|
|
+ qwIpadServerUser.setServerId(serverId);
|
|
|
+ qwIpadServerUser.setQwUserId(account.getId());
|
|
|
+ cidIpadServerUserService.save(qwIpadServerUser);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|