新增自增板逻辑更改,token导出去除*号,token请求头校验增加

This commit is contained in:
liuzhaotian
2025-03-08 14:29:38 +08:00
parent 34cacc6d51
commit caa5743503
12 changed files with 116 additions and 68 deletions
@@ -306,7 +306,7 @@ public class ErrorCodeConstants {
public static final ErrorCode ORDER_PLAN_DATE_ERROR = new ErrorCode(1_002_041_004, "排单信息不存在,请重新进入或切换排单");
public static final ErrorCode ORDER_PLAN_OPTIMIZE_ERROR = new ErrorCode(1_002_041_005, "当前排单对应的优化数据为空,请重新进行优化");
public static final ErrorCode ORDER_PLATE_MODEL_DATE_ERROR = new ErrorCode(1_002_041_006, "生产单对应的板材造型数据为空,请重新导入生产单");
public static final ErrorCode ORDER_PLAN_PLATE_ERROR = new ErrorCode(1_002_041_007, "当前排单对应的板材数据有异常,请查看板材信息或联系客服");
public static final ErrorCode ORDER_PLAN_PLATE_ERROR = new ErrorCode(1_002_041_007, "当前排单对应的板材数据有异常,请查看板材信息");
public static final ErrorCode ORDER_PLAN_ERROR = new ErrorCode(1_002_041_008, "当前排单对应的生产单数据为空,请删掉排单并重新创建排单");
public static final ErrorCode ORDER_PLAN_PLATE_MODEL_DATE_ERROR = new ErrorCode(1_002_041_009, "当前排单对应的板材造型数据为空,请重新导入生产单并排单");
public static final ErrorCode ORDER_GOODS_DATA_ERROR = new ErrorCode(1_002_041_010, "当前大板数据异常,请检查大板信息或者联系客服");
@@ -338,6 +338,7 @@ public class ErrorCodeConstants {
public static final ErrorCode THIS_PLAN_SCHEME_DATA_ERROR = new ErrorCode(1_002_041_047, "当前方案组的优化信息有误,请重新选择方案组或重新导入排单再进行优化");
public static final ErrorCode PLAN_SORT_DATA_ERROR = new ErrorCode(1_002_041_048, "已无可进行排序的数据,无法进行排序");
public static final ErrorCode THIS_PLATE_IS_OPTIMIZE = new ErrorCode(1_002_041_049, "小板:{},已开料,无法删除,请重新选择小板再删除");
public static final ErrorCode PLAN_INSERT_PLATE_ERROR = new ErrorCode(1_002_041_050, "当前排单无法新增自增小板,请删除排单重新创建");
@@ -118,10 +118,10 @@ public class TokenConfigController {
@Operation(summary = "导出配置信息")
// @PreAuthorize("@ss.hasAnyPermissions('system:token:export')")
@OperateLog(type = EXPORT)
public void exportPlateExcel(@Valid TokenConfigPageReqVO pageReqVO,
public void exportTokenConfigExcel(@Valid TokenConfigPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<TokenConfigRespVO> list = tokenConfigService.getTokenConfigPage(pageReqVO).getList();
List<TokenConfigRespVO> list = tokenConfigService.exportTokenConfigExcel(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "token配置信息表.xls", "数据", TokenConfigRespVO.class,
BeanUtils.toBean(list, TokenConfigRespVO.class));
@@ -12,13 +12,17 @@ import com.cf.imes.module.system.controller.admin.oauth2.vo.token.OAuth2AccessTo
import com.cf.imes.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO;
import com.cf.imes.module.system.dal.dataobject.oauth2.OAuth2ClientDO;
import com.cf.imes.module.system.dal.dataobject.oauth2.OAuth2RefreshTokenDO;
import com.cf.imes.module.system.dal.dataobject.organ.OrganizationDO;
import com.cf.imes.module.system.dal.dataobject.user.AdminUserDO;
import com.cf.imes.module.system.dal.mysql.oauth2.OAuth2AccessTokenMapper;
import com.cf.imes.module.system.dal.mysql.oauth2.OAuth2RefreshTokenMapper;
import com.cf.imes.module.system.dal.mysql.organ.OrganMapper;
import com.cf.imes.module.system.dal.redis.oauth2.OAuth2AccessTokenRedisDAO;
import com.cf.imes.module.system.service.organ.OrganService;
import com.cf.imes.module.system.service.tokenconfig.TokenConfigService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.Cursor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -60,6 +64,20 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService {
@Resource
private OrganService organService;
@Resource
private TokenConfigService tokenConfigService;
@Resource
private OrganMapper organMapper;
private static final String FIELD_IMES = "imes-";
@Value("${chenfeng.organ.use-data-code:imes_prod}")
private String useDataCode;
@Override
@Transactional
public OAuth2AccessTokenDO createAccessToken(Long userId, Integer userType, String clientId, List<String> scopes,Boolean large, Integer dbNo, Integer tableNo, String dataCode, Long organId, String nickname) {
@@ -109,19 +127,46 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService {
return null;
}
@Override
public OAuth2AccessTokenDO getAccessToken(String accessToken) {
// 因数据库不在存入缓存数据,所以直接从缓存中获取
// 数据库移除令牌存入,所以直接从缓存中获取
OAuth2AccessTokenDO accessTokenDO = oauth2AccessTokenRedisDAO.get(accessToken);
OAuth2AccessTokenDO accessTokenDO = new OAuth2AccessTokenDO();
if(accessTokenDO != null){
// 校验组织的有效性
organService.validOrgan(accessTokenDO.getOrganId());
// 有令牌的校验,代表有接口访问,延长令牌的过期时间(30分钟)
oauth2AccessTokenRedisDAO.expire(accessToken, 1, TimeUnit.DAYS);
String substring = accessToken.substring(0, 5);
// 外部应用 token 校验
if(FIELD_IMES.equals(substring)){
Long organId = tokenConfigService.checkTokenConfig(accessToken);
OrganizationDO organizationDO = organMapper.selectById(organId);
accessTokenDO.setOrganId(organId);
accessTokenDO.setUserId(organizationDO.getContactUserId());
accessTokenDO.setUserType(2);
accessTokenDO.setClientId("default");
accessTokenDO.setExpiresTime(organizationDO.getExpireTime());
accessTokenDO.setDataCode(useDataCode);
accessTokenDO.setNickname(organizationDO.getName());
accessTokenDO.setIsSupAdmin(true);
}else {
// 因数据库不在存入缓存数据,所以直接从缓存中获取
// 数据库移除令牌存入,所以直接从缓存中获取
accessTokenDO = oauth2AccessTokenRedisDAO.get(accessToken);
if (accessTokenDO != null) {
// 校验组织的有效性
organService.validOrgan(accessTokenDO.getOrganId());
// 有令牌的校验,代表有接口访问,延长令牌的过期时间(30分钟)
oauth2AccessTokenRedisDAO.expire(accessToken, 1, TimeUnit.DAYS);
}
}
return accessTokenDO;
}
@@ -30,4 +30,6 @@ public interface TokenConfigService {
Long checkTokenConfig(String token);
String tokenConfigCopy(Long id);
PageResult<TokenConfigRespVO> exportTokenConfigExcel(TokenConfigPageReqVO pageReqVO);
}
@@ -208,11 +208,6 @@ public class TokenConfigServiceImpl implements TokenConfigService{
@Override
public Long checkTokenConfig(String token) {
String substring = token.substring(0, 5);
if(!FIELD_IMES.equals(substring)){
throw exception(TOKEN_DATA_ERROR);
}
TokenConfigDO tokenConfigDO = tokenConfigMapper.selectByToken(token.substring(5));
if(tokenConfigDO == null){
@@ -253,7 +248,26 @@ public class TokenConfigServiceImpl implements TokenConfigService{
@Override
public PageResult<TokenConfigRespVO> exportTokenConfigExcel(TokenConfigPageReqVO pageReqVO) {
PageResult<TokenConfigDO> pageResult = tokenConfigMapper.selectConfigPage(pageReqVO,null);
if(CollUtil.isEmpty(pageResult.getList())) {
return new PageResult<>();
}
OrganizationDO organizationDO = organService.validOrgan(getUserOrganId());
PageResult<TokenConfigRespVO> result = BeanUtils.toBean(pageResult, TokenConfigRespVO.class);
result.getList().forEach(f->{
f.setOrganName(organizationDO.getName());
f.setAppToken(FIELD_IMES+f.getAppToken());
});
return result;
}
private TokenConfigDO validateTokenConfigExists(Long id) {
@@ -201,6 +201,7 @@ chenfeng:
- system_data_source_field
- system_machine_brand
- system_machine_limit
- system_config_token
use-data-code: imes_prod #动态数据源标识,后期添加的数据源需要修改此值
sms-code: # 短信验证码相关的配置项