Compare commits

...

2 Commits

Author SHA1 Message Date
sh
32bacfa02d 修改企业联系人和企业信息 2025-11-20 18:31:45 +08:00
sh
c348a809a5 1.修改权限问题
2.修改获取经办端token方法
2025-11-20 14:32:37 +08:00
4 changed files with 95 additions and 27 deletions

View File

@@ -181,6 +181,7 @@ public class SysLoginController
*/
@GetMapping("/getTjmhToken")
public AjaxResult getTjmhToken(@RequestParam("code") String code){
System.out.println("参数code==========================="+code);
if(StringUtils.isBlank(code)){
return AjaxResult.error("参数code为空请传递code参数");
}
@@ -212,6 +213,7 @@ public class SysLoginController
*/
@GetMapping("/getWwTjmHlwToken")
public AjaxResult getWwTjmHlwToken(@RequestParam("token") String token){
System.out.println("互联网token================================"+token);
if (StringUtils.isNotBlank(token)) {
WwTokenResult wwTokenResult=new WwTokenResult();
wwTokenResult.setAccessToken(token);

View File

@@ -52,7 +52,7 @@ public class IndustryController extends BaseController
return getDataTable(list);
}
@ApiOperation("行业树结构")
@PreAuthorize("@ss.hasPermi('cms:industry:list')")
// @PreAuthorize("@ss.hasPermi('cms:industry:list')")
@GetMapping("/treeselect")
public AjaxResult treeselect(Industry industry)
{

View File

@@ -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.WwTyInfo;
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.crypto.CryptoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@@ -19,6 +22,7 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -72,6 +76,11 @@ public class OauthClient {
@Value("${oauth.write-timeout:30}")
private int writeTimeout;
@Autowired
private RedisCache redisCache;
private final String MH_JBD_TOKEN="mhjdb:token:";
/**
* 获取经办段token
*/
@@ -92,6 +101,19 @@ public class OauthClient {
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);
params.put("appid", appid);
params.put("code", decryptedCode);
@@ -104,9 +126,11 @@ public class OauthClient {
);
if (StringUtils.isEmpty(result.getAccessToken())) {
redisCache.deleteObject(decryptedCode);
throw new RuntimeException("Token获取失败返回的accessToken为空");
}
redisCache.setCacheObject(redisKey,result,safeLongToInt(result.getExpiresIn()), TimeUnit.MINUTES);
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>

View File

@@ -26,7 +26,7 @@ import com.ruoyi.framework.manager.AsyncManager;
import com.ruoyi.framework.manager.factory.AsyncFactory;
import com.ruoyi.framework.security.context.AuthenticationContextHolder;
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.security.authentication.UsernamePasswordAuthenticationToken;
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.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.concurrent.TimeUnit;
@Service
@@ -167,15 +166,9 @@ public class OauthLoginHlwService {
newUser.setNickName(wwTyInfo.getEnterprisename());
newUser.setIdCard(wwTyInfo.getEnterprisecode());
newUser.setRoleIds(new Long[]{parseStringToLoing(StringUtil.SYS_QY)});
//企业联系人->现根据社会信用代码查询企业信息
Company company=companyService.queryCodeCompany(wwTyInfo.getEnterprisecode());
if(company!=null){
CompanyContact companyContact=new CompanyContact();
companyContact.setContactPerson(wwTyInfo.getContactperson());
companyContact.setContactPersonPhone(wwTyInfo.getContactphone());
companyContact.setCompanyId(company.getCompanyId());
companyContactService.insertContact(companyContact);
}
//修改企业和企业联系人
updateCompanyContact(wwTyInfo);
//移动端
appUserParm.setPhone(wwTyInfo.getPhone());
appUserParm.setIdCard(wwTyInfo.getEnterprisecode());
@@ -320,20 +313,51 @@ public class OauthLoginHlwService {
* 修改联系人信息
* @param wwTyInfo
*/
public void updateCompanyContact(WwTyInfo wwTyInfo){
Company company=companyService.queryCodeCompany(wwTyInfo.getEnterprisecode());
if(company!=null){
CompanyContact parm=new CompanyContact();
parm.setContactPerson(wwTyInfo.getContactperson());
parm.setContactPersonPhone(wwTyInfo.getContactphone());
parm.setCompanyId(company.getCompanyId());
List<CompanyContact> companyContacts=companyContactService.getSelectList(parm);
if(Collections.isEmpty(companyContacts)){
CompanyContact companyContact=new CompanyContact();
companyContact.setContactPerson(wwTyInfo.getContactperson());
companyContact.setContactPersonPhone(wwTyInfo.getContactphone());
companyContact.setCompanyId(company.getCompanyId());
companyContactService.insertContact(companyContact);
public void updateCompanyContact(WwTyInfo wwTyInfo) {
if (wwTyInfo == null) {
throw new IllegalArgumentException("参数WwTyInfo不能为空");
}
String enterpriseCode = wwTyInfo.getEnterprisecode();
String enterpriseName = wwTyInfo.getEnterprisename();
String contactPerson = wwTyInfo.getContactperson();
String contactPhone = wwTyInfo.getContactphone();
Company company = companyService.queryCodeCompany(enterpriseCode);
CompanyContact contact = new 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");
}
}
}