Compare commits
2 Commits
9b1983292c
...
32bacfa02d
| Author | SHA1 | Date | |
|---|---|---|---|
| 32bacfa02d | |||
| c348a809a5 |
@@ -181,6 +181,7 @@ public class SysLoginController
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/getTjmhToken")
|
@GetMapping("/getTjmhToken")
|
||||||
public AjaxResult getTjmhToken(@RequestParam("code") String code){
|
public AjaxResult getTjmhToken(@RequestParam("code") String code){
|
||||||
|
System.out.println("参数code==========================="+code);
|
||||||
if(StringUtils.isBlank(code)){
|
if(StringUtils.isBlank(code)){
|
||||||
return AjaxResult.error("参数code为空,请传递code参数");
|
return AjaxResult.error("参数code为空,请传递code参数");
|
||||||
}
|
}
|
||||||
@@ -212,6 +213,7 @@ public class SysLoginController
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/getWwTjmHlwToken")
|
@GetMapping("/getWwTjmHlwToken")
|
||||||
public AjaxResult getWwTjmHlwToken(@RequestParam("token") String token){
|
public AjaxResult getWwTjmHlwToken(@RequestParam("token") String token){
|
||||||
|
System.out.println("互联网token================================"+token);
|
||||||
if (StringUtils.isNotBlank(token)) {
|
if (StringUtils.isNotBlank(token)) {
|
||||||
WwTokenResult wwTokenResult=new WwTokenResult();
|
WwTokenResult wwTokenResult=new WwTokenResult();
|
||||||
wwTokenResult.setAccessToken(token);
|
wwTokenResult.setAccessToken(token);
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class IndustryController extends BaseController
|
|||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
}
|
}
|
||||||
@ApiOperation("行业树结构")
|
@ApiOperation("行业树结构")
|
||||||
@PreAuthorize("@ss.hasPermi('cms:industry:list')")
|
// @PreAuthorize("@ss.hasPermi('cms:industry:list')")
|
||||||
@GetMapping("/treeselect")
|
@GetMapping("/treeselect")
|
||||||
public AjaxResult treeselect(Industry industry)
|
public AjaxResult treeselect(Industry industry)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,8 +10,11 @@ import com.ruoyi.common.core.domain.entity.tymh.nwToken.NwUserInfoResult;
|
|||||||
import com.ruoyi.common.core.domain.entity.tymh.wwToken.WwTokenResult;
|
import com.ruoyi.common.core.domain.entity.tymh.wwToken.WwTokenResult;
|
||||||
import com.ruoyi.common.core.domain.entity.tymh.wwToken.WwTyInfo;
|
import com.ruoyi.common.core.domain.entity.tymh.wwToken.WwTyInfo;
|
||||||
import com.ruoyi.common.core.domain.entity.tymh.wwToken.WwUserLogin;
|
import com.ruoyi.common.core.domain.entity.tymh.wwToken.WwUserLogin;
|
||||||
|
import com.ruoyi.common.core.redis.RedisCache;
|
||||||
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.common.utils.crypto.CryptoUtil;
|
import com.ruoyi.common.utils.crypto.CryptoUtil;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -19,6 +22,7 @@ import java.io.IOException;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -72,6 +76,11 @@ public class OauthClient {
|
|||||||
@Value("${oauth.write-timeout:30}")
|
@Value("${oauth.write-timeout:30}")
|
||||||
private int writeTimeout;
|
private int writeTimeout;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisCache redisCache;
|
||||||
|
|
||||||
|
private final String MH_JBD_TOKEN="mhjdb:token:";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取经办段token
|
* 获取经办段token
|
||||||
*/
|
*/
|
||||||
@@ -92,6 +101,19 @@ public class OauthClient {
|
|||||||
throw new RuntimeException("授权码解密失败:" + e.getMessage(), e);
|
throw new RuntimeException("授权码解密失败:" + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//判断redis中是否存在获取token
|
||||||
|
String redisKey=MH_JBD_TOKEN+decryptedCode;
|
||||||
|
NwTokenResult cacheResult=redisCache.getCacheObject(redisKey);
|
||||||
|
if(cacheResult!=null){
|
||||||
|
long ttlSeconds = redisCache.getExpire(redisKey);
|
||||||
|
if (ttlSeconds > 60) {
|
||||||
|
return cacheResult;
|
||||||
|
} else {
|
||||||
|
redisCache.deleteObject(redisKey);
|
||||||
|
throw new RuntimeException("令牌剩余时间不足(" + ttlSeconds + "秒),已清理旧数据");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, Object> params = new HashMap<>(2);
|
Map<String, Object> params = new HashMap<>(2);
|
||||||
params.put("appid", appid);
|
params.put("appid", appid);
|
||||||
params.put("code", decryptedCode);
|
params.put("code", decryptedCode);
|
||||||
@@ -104,9 +126,11 @@ public class OauthClient {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (StringUtils.isEmpty(result.getAccessToken())) {
|
if (StringUtils.isEmpty(result.getAccessToken())) {
|
||||||
|
redisCache.deleteObject(decryptedCode);
|
||||||
throw new RuntimeException("Token获取失败:返回的accessToken为空");
|
throw new RuntimeException("Token获取失败:返回的accessToken为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
redisCache.setCacheObject(redisKey,result,safeLongToInt(result.getExpiresIn()), TimeUnit.MINUTES);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,6 +451,24 @@ public class OauthClient {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Long 转 int
|
||||||
|
*/
|
||||||
|
private int safeLongToInt(Long value) {
|
||||||
|
if (value == null) {
|
||||||
|
throw new ServiceException("门户 Token 有效期不能为空");
|
||||||
|
}
|
||||||
|
// 校验是否超过 int 最大值(实际场景几乎不会触发)
|
||||||
|
if (value > Integer.MAX_VALUE) {
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
// 校验是否为负数(无效有效期)
|
||||||
|
if (value < 0) {
|
||||||
|
throw new ServiceException("门户 Token 有效期不能为负数");
|
||||||
|
}
|
||||||
|
return value.intValue();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 静态返回解析
|
* 静态返回解析
|
||||||
* @param <T>
|
* @param <T>
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import com.ruoyi.framework.manager.AsyncManager;
|
|||||||
import com.ruoyi.framework.manager.factory.AsyncFactory;
|
import com.ruoyi.framework.manager.factory.AsyncFactory;
|
||||||
import com.ruoyi.framework.security.context.AuthenticationContextHolder;
|
import com.ruoyi.framework.security.context.AuthenticationContextHolder;
|
||||||
import com.ruoyi.system.service.ISysUserService;
|
import com.ruoyi.system.service.ISysUserService;
|
||||||
import io.jsonwebtoken.lang.Collections;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
@@ -34,8 +34,7 @@ import org.springframework.security.core.userdetails.UserDetails;
|
|||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -167,15 +166,9 @@ public class OauthLoginHlwService {
|
|||||||
newUser.setNickName(wwTyInfo.getEnterprisename());
|
newUser.setNickName(wwTyInfo.getEnterprisename());
|
||||||
newUser.setIdCard(wwTyInfo.getEnterprisecode());
|
newUser.setIdCard(wwTyInfo.getEnterprisecode());
|
||||||
newUser.setRoleIds(new Long[]{parseStringToLoing(StringUtil.SYS_QY)});
|
newUser.setRoleIds(new Long[]{parseStringToLoing(StringUtil.SYS_QY)});
|
||||||
//企业联系人->现根据社会信用代码查询企业信息
|
//修改企业和企业联系人
|
||||||
Company company=companyService.queryCodeCompany(wwTyInfo.getEnterprisecode());
|
updateCompanyContact(wwTyInfo);
|
||||||
if(company!=null){
|
|
||||||
CompanyContact companyContact=new CompanyContact();
|
|
||||||
companyContact.setContactPerson(wwTyInfo.getContactperson());
|
|
||||||
companyContact.setContactPersonPhone(wwTyInfo.getContactphone());
|
|
||||||
companyContact.setCompanyId(company.getCompanyId());
|
|
||||||
companyContactService.insertContact(companyContact);
|
|
||||||
}
|
|
||||||
//移动端
|
//移动端
|
||||||
appUserParm.setPhone(wwTyInfo.getPhone());
|
appUserParm.setPhone(wwTyInfo.getPhone());
|
||||||
appUserParm.setIdCard(wwTyInfo.getEnterprisecode());
|
appUserParm.setIdCard(wwTyInfo.getEnterprisecode());
|
||||||
@@ -321,19 +314,50 @@ public class OauthLoginHlwService {
|
|||||||
* @param wwTyInfo
|
* @param wwTyInfo
|
||||||
*/
|
*/
|
||||||
public void updateCompanyContact(WwTyInfo wwTyInfo) {
|
public void updateCompanyContact(WwTyInfo wwTyInfo) {
|
||||||
Company company=companyService.queryCodeCompany(wwTyInfo.getEnterprisecode());
|
if (wwTyInfo == null) {
|
||||||
if(company!=null){
|
throw new IllegalArgumentException("参数WwTyInfo不能为空");
|
||||||
CompanyContact parm=new CompanyContact();
|
}
|
||||||
parm.setContactPerson(wwTyInfo.getContactperson());
|
String enterpriseCode = wwTyInfo.getEnterprisecode();
|
||||||
parm.setContactPersonPhone(wwTyInfo.getContactphone());
|
String enterpriseName = wwTyInfo.getEnterprisename();
|
||||||
parm.setCompanyId(company.getCompanyId());
|
|
||||||
List<CompanyContact> companyContacts=companyContactService.getSelectList(parm);
|
String contactPerson = wwTyInfo.getContactperson();
|
||||||
if(Collections.isEmpty(companyContacts)){
|
String contactPhone = wwTyInfo.getContactphone();
|
||||||
CompanyContact companyContact=new CompanyContact();
|
|
||||||
companyContact.setContactPerson(wwTyInfo.getContactperson());
|
Company company = companyService.queryCodeCompany(enterpriseCode);
|
||||||
companyContact.setContactPersonPhone(wwTyInfo.getContactphone());
|
|
||||||
companyContact.setCompanyId(company.getCompanyId());
|
CompanyContact contact = new CompanyContact();
|
||||||
companyContactService.insertContact(companyContact);
|
contact.setContactPerson(contactPerson);
|
||||||
|
contact.setContactPersonPhone(contactPhone);
|
||||||
|
|
||||||
|
if (Objects.nonNull(company)) {
|
||||||
|
Company updateCompany = new Company();
|
||||||
|
updateCompany.setCompanyId(company.getCompanyId());
|
||||||
|
updateCompany.setCode(enterpriseCode);
|
||||||
|
updateCompany.setName(enterpriseName);
|
||||||
|
companyService.updateCompany(updateCompany);
|
||||||
|
|
||||||
|
contact.setCompanyId(company.getCompanyId());
|
||||||
|
List<CompanyContact> existingContacts = companyContactService.getSelectList(contact);
|
||||||
|
|
||||||
|
List<CompanyContact> contactList = new ArrayList<>();
|
||||||
|
if (!CollectionUtils.isEmpty(existingContacts)) {
|
||||||
|
contact.setId(existingContacts.get(0).getId());
|
||||||
|
contactList.add(contact);
|
||||||
|
companyContactService.insertUpadteCompanyContact(contactList);
|
||||||
|
} else {
|
||||||
|
companyContactService.insertContact(contact);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Company newCompany = new Company();
|
||||||
|
newCompany.setCode(enterpriseCode);
|
||||||
|
newCompany.setName(enterpriseName);
|
||||||
|
companyService.insertCompany(newCompany);
|
||||||
|
|
||||||
|
if (Objects.nonNull(newCompany.getCompanyId())) {
|
||||||
|
contact.setCompanyId(newCompany.getCompanyId());
|
||||||
|
companyContactService.insertContact(contact);
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("新增企业失败:社会信用代码=" + enterpriseCode + ",未返回有效企业ID");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user