feat: 添加对SAP和主物料查询的支持

This commit is contained in:
曹鹏飞 2025-07-07 18:06:35 +08:00
parent 70433f1224
commit 06520dca56
28 changed files with 603 additions and 39 deletions

View File

@ -73,15 +73,14 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>tech.powerjob</groupId>
<artifactId>powerjob-worker-spring-boot-starter</artifactId>
<version>5.1.1</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>tech.powerjob</groupId>-->
<!-- <artifactId>powerjob-worker-spring-boot-starter</artifactId>-->
<!-- <version>5.1.1</version>-->
<!-- </dependency>-->
<dependency>
<groupId>tech.powerjob</groupId>
<artifactId>powerjob-client</artifactId>
<version>5.1.1</version>
</dependency>
</dependencies>

View File

@ -0,0 +1,15 @@
package com.nflg.wms.admin.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
@Configuration
public class RestTemplateConfig {
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}

View File

@ -1,16 +0,0 @@
package com.nflg.wms.admin.service;
import com.nflg.wms.common.pojo.dto.BomMaterialDTO;
import org.springframework.stereotype.Component;
@Component
public class BomMaterialService {
public BomMaterialDTO getMaterial(String no){
// TODO 从主数据平台获取物料信息
return new BomMaterialDTO()
.setNo("test")
.setDescribe("测试的虚拟物料")
.setDrawingNo("tttt");
}
}

View File

@ -18,6 +18,7 @@ import com.nflg.wms.common.util.UserUtil;
import com.nflg.wms.common.util.VUtil;
import com.nflg.wms.repository.entity.WmsMaterial;
import com.nflg.wms.repository.service.IWmsMaterialService;
import com.nflg.wms.starter.service.BomMaterialService;
import com.nflg.wms.starter.service.FileUploadService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
@ -153,13 +154,13 @@ public class MaterialControllerService {
wmsMaterial=new WmsMaterial()
.setId(null)
.setVersion(Objects.isNull(wmsMaterial)?1:wmsMaterial.getVersion()+1)
.setNo(bomMaterialDTO.getNo())
.setDescribe(bomMaterialDTO.getDescribe())
.setNo(bomMaterialDTO.getMaterialNo())
.setDescribe(bomMaterialDTO.getMaterialDesc())
.setDrawingNo(bomMaterialDTO.getDrawingNo())
.setCreateBy(UserUtil.getUserName())
.setCreateTime(LocalDateTime.now());
}else {
wmsMaterial.setDescribe(bomMaterialDTO.getDescribe());
wmsMaterial.setDescribe(bomMaterialDTO.getMaterialDesc());
wmsMaterial.setDrawingNo(bomMaterialDTO.getDrawingNo());
wmsMaterial.setUpdateBy(UserUtil.getUserName());
wmsMaterial.setUpdateTime(LocalDateTime.now());

View File

@ -182,4 +182,8 @@ public class WarehouseControllerService {
}
return false;
}
public List<WmsWarehouse> getList() {
return warehouseService.getList();
}
}

View File

@ -0,0 +1,4 @@
package com.nflg.wms.common.pojo.dto;
public record BomLoginQO(String userName, String pwd) {
}

View File

@ -0,0 +1,4 @@
package com.nflg.wms.common.pojo.dto;
public record BomLoginResultDTO(String token) {
}

View File

@ -24,13 +24,13 @@ public class BomMaterialDTO {
* SAP料号
*/
@NotBlank
private String no;
private String materialNo;
/**
* 物料描述
*/
@NotBlank
private String describe;
private String materialDesc;
/**
* 图号
@ -41,7 +41,7 @@ public class BomMaterialDTO {
* 重量
*/
@NotBlank
private BigDecimal weight;
private String materialWeight;
/**
* 数量

View File

@ -0,0 +1,4 @@
package com.nflg.wms.common.pojo.dto;
public record BomResultDTO<T>(int state, String msg,T data) {
}

View File

@ -0,0 +1,4 @@
package com.nflg.wms.common.pojo.dto;
public record SAPSyncFromDTO(String no,String warehouse,String bin) {
}

View File

@ -32,4 +32,6 @@ public interface IWmsWarehouseService extends IService<WmsWarehouse> {
IPage<WarehouseVO> search(@Valid WarehouseSearchQO request);
List<WarehouseVO> getList(List<Long> ids);
List<WmsWarehouse> getList();
}

View File

@ -72,22 +72,22 @@ public class WmsBomServiceImpl extends ServiceImpl<WmsBomMapper, WmsBom> impleme
.map(it -> new BomMaterialDTO()
.setId(it.getId())
.setParentId(it.getParentId())
.setNo(it.getNo())
.setDescribe(it.getDescribe())
.setMaterialNo(it.getNo())
.setMaterialDesc(it.getDescribe())
.setDrawingNo(it.getDrawingNo())
.setNum(it.getNum())
.setWeight(it.getWeight())
.setMaterialWeight(String.valueOf(it.getWeight()))
.setChildren(boms.stream()
.filter(child -> child.getParentId().equals(it.getId()))
.map(child -> {
return new BomMaterialDTO()
.setId(child.getId())
.setParentId(child.getParentId())
.setNo(child.getNo())
.setDescribe(child.getDescribe())
.setMaterialNo(child.getNo())
.setMaterialDesc(child.getDescribe())
.setDrawingNo(child.getDrawingNo())
.setNum(child.getNum())
.setWeight(child.getWeight());
.setMaterialWeight(String.valueOf(child.getWeight()));
})
.toList()
)).toList();

View File

@ -94,4 +94,9 @@ public class WmsWarehouseServiceImpl extends ServiceImpl<WmsWarehouseMapper, Wms
public List<WarehouseVO> getList(List<Long> ids) {
return baseMapper.getList(ids);
}
@Override
public List<WmsWarehouse> getList() {
return lambdaQuery().eq(WmsWarehouse::getEnable, true).list();
}
}

View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

134
nflg-wms-scheduled/pom.xml Normal file
View File

@ -0,0 +1,134 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.nflg</groupId>
<artifactId>nflg-wms</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>nflg-wms-scheduled</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>服务-计划任务执行器</name>
<description>计划任务执行器</description>
<dependencies>
<dependency>
<groupId>com.nflg</groupId>
<artifactId>nflg-wms-common</artifactId>
</dependency>
<dependency>
<groupId>com.nflg</groupId>
<artifactId>nflg-wms-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>tech.powerjob</groupId>-->
<!-- <artifactId>powerjob-client</artifactId>-->
<!-- <version>5.1.1</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.sap.conn.jco</groupId>
<artifactId>sapjco3</artifactId>
<version>3.0.9</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/sapjco3.jar</systemPath>
</dependency>
<dependency>
<groupId>tech.powerjob</groupId>
<artifactId>powerjob-worker</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-external-libs</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<!-- 指定源目录项目根目录下的lib -->
<resources>
<resource>
<directory>${project.basedir}/lib</directory>
<filtering>false</filtering>
</resource>
</resources>
<!-- 指定目标目录(与依赖库相同的目录) -->
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<!-- 自动创建目标目录 -->
<overwrite>true</overwrite>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<excludeGroupIds>${project.groupId}</excludeGroupIds>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.nflg.wms.scheduled.ScheduledApplication</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>${project.groupId}:*</include>
</includes>
</artifactSet>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,13 @@
package com.nflg.wms.scheduled;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ScheduledApplication {
public static void main(String[] args) {
SpringApplication.run(ScheduledApplication.class, args);
}
}

View File

@ -0,0 +1,114 @@
package com.nflg.wms.scheduled.config;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.ext.DestinationDataEventListener;
import com.sap.conn.jco.ext.DestinationDataProvider;
import com.sap.conn.jco.ext.Environment;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@Slf4j
@Configuration
public class SapJcoConfig {
public static final String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL";
private final String sapHost;
private final String sapSysnr;
private final String sapClient;
private final String sapUsername;
private final String sapPassword;
private final String sapLang;
private final String sapPool;
private String sapPeak;
public SapJcoConfig(
@Value("${custom.sap.host}") String sapHost,
@Value("${custom.sap.sysnr}") String sapSysnr,
@Value("${custom.sap.client}") String sapClient,
@Value("${custom.sap.username}") String sapUsername,
@Value("${custom.sap.password}") String sapPassword,
@Value("${custom.sap.lang}") String sapLang,
@Value("${custom.sap.pool}") String sapPool,
@Value("${custom.sap.peak}") String sapPeak
) {
this.sapHost = sapHost;
this.sapSysnr = sapSysnr;
this.sapClient = sapClient;
this.sapUsername = sapUsername;
this.sapPassword = sapPassword;
this.sapLang = sapLang;
this.sapPool = sapPool;
this.sapPeak = sapPeak;
}
@PostConstruct
public void initDestination() {
try {
// 验证连接池配置有效性
validatePoolConfig();
// 直接注册到JCo内存环境避免文件IO
Environment.registerDestinationDataProvider(new SimpleDestinationDataProvider(ABAP_AS_POOLED, buildConnectionProperties()));
} catch (Exception e) {
log.error("SAP JCo目的地初始化失败", e);
throw new IllegalStateException("SAP JCo配置初始化失败", e);
}
}
private Properties buildConnectionProperties() {
Properties props = new Properties();
props.setProperty(DestinationDataProvider.JCO_ASHOST, sapHost);
props.setProperty(DestinationDataProvider.JCO_SYSNR, sapSysnr);
props.setProperty(DestinationDataProvider.JCO_CLIENT, sapClient);
props.setProperty(DestinationDataProvider.JCO_USER, sapUsername);
props.setProperty(DestinationDataProvider.JCO_PASSWD, sapPassword);
props.setProperty(DestinationDataProvider.JCO_LANG, sapLang);
props.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, sapPeak);
props.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, sapPool);
return props;
}
// 连接池配置验证
private void validatePoolConfig() {
try {
int peak = Integer.parseInt(sapPeak);
int pool = Integer.parseInt(sapPool);
if (peak < pool) {
log.warn("JCO_PEAK_LIMIT({}) 不应小于 JCO_POOL_CAPACITY({}),已自动修正", peak, pool);
sapPeak = sapPool;
}
} catch (NumberFormatException e) {
throw new IllegalArgumentException("SAP连接池配置必须是数字");
}
}
@Bean(destroyMethod = "")
public JCoDestination jcoDestination() throws JCoException {
return JCoDestinationManager.getDestination(ABAP_AS_POOLED);
}
private static class SimpleDestinationDataProvider implements DestinationDataProvider {
private final Map<String, Properties> destinations = new HashMap<>();
public SimpleDestinationDataProvider(String destName, Properties props) {
destinations.put(destName, props);
}
@Override
public Properties getDestinationProperties(String destinationName) {
return destinations.get(destinationName);
}
@Override
public void setDestinationDataEventListener(DestinationDataEventListener listener) {}
@Override
public boolean supportsEvents() {
return false;
}
}
}

View File

@ -1,12 +1,12 @@
package com.nflg.wms.admin.processor;
package com.nflg.wms.scheduled.processor;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.nflg.wms.admin.service.BomMaterialService;
import com.nflg.wms.common.pojo.dto.BomMaterialDTO;
import com.nflg.wms.repository.entity.WmsMaterial;
import com.nflg.wms.repository.service.IWmsMaterialService;
import com.nflg.wms.starter.service.BomMaterialService;
import com.nflg.wms.starter.service.FileUploadService;
import jakarta.annotation.Resource;
import org.apache.commons.io.FilenameUtils;
@ -73,14 +73,14 @@ public class MaterialZipImportProcessor implements BasicProcessor {
wmsMaterial = new WmsMaterial()
.setId(null)
.setVersion(Objects.isNull(wmsMaterial) ? 1 : wmsMaterial.getVersion() + 1)
.setNo(bomMaterialDTO.getNo())
.setDescribe(bomMaterialDTO.getDescribe())
.setNo(bomMaterialDTO.getMaterialNo())
.setDescribe(bomMaterialDTO.getMaterialDesc())
.setDrawingNo(bomMaterialDTO.getDrawingNo())
.setCreateBy(userName)
.setCreateTime(LocalDateTime.now());
} else {
omsLogger.info("更新图纸");
wmsMaterial.setDescribe(bomMaterialDTO.getDescribe());
wmsMaterial.setDescribe(bomMaterialDTO.getMaterialDesc());
wmsMaterial.setDrawingNo(bomMaterialDTO.getDrawingNo());
wmsMaterial.setUpdateBy(userName);
wmsMaterial.setUpdateTime(LocalDateTime.now());

View File

@ -0,0 +1,43 @@
package com.nflg.wms.scheduled.processor;
import cn.hutool.core.collection.CollectionUtil;
import com.nflg.wms.repository.entity.WmsWarehouse;
import com.nflg.wms.repository.service.IWmsWarehouseService;
import com.nflg.wms.scheduled.service.SapService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
import tech.powerjob.worker.core.processor.ProcessResult;
import tech.powerjob.worker.core.processor.TaskContext;
import tech.powerjob.worker.core.processor.sdk.BasicProcessor;
import tech.powerjob.worker.log.OmsLogger;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@Component(value = "SAPSyncMaterialProcessor")
public class SAPSyncMaterialProcessor implements BasicProcessor {
@Resource
private SapService sapService;
@Resource
private IWmsWarehouseService warehouseService;
@Override
public ProcessResult process(TaskContext context) throws Exception {
// List<String> params= StrUtil.split(context.getInstanceParams(), "|");
List<WmsWarehouse> warehouses = warehouseService.getList();
Set<String> warehouseNos = warehouses.stream().map(WmsWarehouse::getNo).collect(Collectors.toSet());
if (CollectionUtil.isEmpty(warehouseNos)) {
return new ProcessResult(false, "请先配置仓库");
}
OmsLogger omsLogger = context.getOmsLogger();
int count=warehouseNos.size();
for (int i = 0, size = warehouseNos.size(); i < size; i++) {
String warehouseNo = warehouseNos.toArray()[i].toString();
omsLogger.info("开始同步仓库:{}",warehouseNos.toArray()[i]);
}
return new ProcessResult(true, "同步成功");
}
}

View File

@ -0,0 +1,40 @@
package com.nflg.wms.scheduled.service;
import com.nflg.wms.common.pojo.dto.SAPSyncFromDTO;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoTable;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@Component
public class SapService {
@Resource
private JCoDestination destination;
public List<SAPSyncFromDTO> syncFrom(String factory) throws JCoException {
JCoFunction function = destination.getRepository().getFunction("ZWM3A01");
function.getImportParameterList().setValue("I_WERKS", factory);
// JCoTable itMatnr = function.getTableParameterList().getTable("IT_MATNR");
// for (String matnr : materials) {
// itMatnr.appendRow();
// itMatnr.setValue("MATNR", matnr);
// }
function.execute(destination);
JCoTable tOut = function.getTableParameterList().getTable("T_OUT");
List<SAPSyncFromDTO> result = new ArrayList<>();
for (int i = 0; i < tOut.getNumRows(); i++) {
tOut.setRow(i);
result.add(new SAPSyncFromDTO(tOut.getString("MATNR"), tOut.getString("LGORT"), tOut.getString("LGPBE")));
}
return result;
}
}

View File

@ -0,0 +1,10 @@
logging:
level:
root: info
com:
nflg: debug
alibaba:
cloud:
nacos: debug
org:
springframework: debug

View File

@ -0,0 +1,22 @@
server:
port: 8102
spring:
application:
name: scheduled
profiles:
active: dev
config:
import: nacos:shared.properties?group=${spring.profiles.active}&refreshEnabled=true
cloud:
nacos:
config:
server-addr: ${nacos.server-addr:112.74.186.154:8848}
namespace: wms
group: ${spring.profiles.active}
discovery:
server-addr: ${nacos.server-addr:112.74.186.154:8848}
namespace: wms
group: ${spring.profiles.active}
logging:
level:
root: info

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 引入Spring Boot默认的基础配置 -->
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<Property name="logDir" value="./logs" />
<!-- 控制台输出配置 -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%X{traceId}] %-5level %logger{50} - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<!-- 文件日志配置 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logDir}/nflg-wms-scheduled.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- 按天滚动日志并按大小拆分 -->
<fileNamePattern>${logDir}/%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<!-- 单个日志文件最大大小 -->
<maxFileSize>10MB</maxFileSize>
<!-- 日志保留天数 -->
<maxHistory>7</maxHistory>
<!-- 所有日志文件的总大小上限 -->
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%X{traceId}] %-5level %logger{50} - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<appender name="POWERJOB_WORKER_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logDir}/powerjob-worker.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${logDir}/powerjob-worker.%d{yyyy-MM-dd}.log</FileNamePattern>
<MaxHistory>7</MaxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
<append>true</append>
</appender>
<logger name="com.alibaba.nacos" level="warn" additivity="false">
<appender-ref ref="FILE"/>
</logger>
<logger name="tech.powerjob" level="INFO" additivity="false">
<appender-ref ref="POWERJOB_WORKER_APPENDER" />
</logger>
<!-- 默认配置 -->
<root level="DEBUG">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</root>
</configuration>

View File

@ -0,0 +1,89 @@
package com.nflg.wms.starter.service;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.nflg.wms.common.pojo.dto.BomLoginQO;
import com.nflg.wms.common.pojo.dto.BomLoginResultDTO;
import com.nflg.wms.common.pojo.dto.BomMaterialDTO;
import com.nflg.wms.common.pojo.dto.BomResultDTO;
import com.nflg.wms.common.util.VUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@Slf4j
@Component
public class BomMaterialService {
@Value("${bom.login.url}")
private String loginUrl;
@Value("${bom.user.name}")
private String userName;
@Value("${bom.user.password}")
private String password;
@Value("${bom.material.query.url}")
private String materialQueryUrl;
@Resource
private RestTemplate restTemplate;
@Resource
private StringRedisTemplate stringRedisTemplate;
public BomMaterialDTO getMaterial(String no) {
VUtil.trueThrowBusinessError(StrUtil.isBlank(no)).throwMessage("物料编号不能为空");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("authorization", getToken());
HttpEntity<Void> requestEntity = new HttpEntity<>(null, headers);
ResponseEntity<BomResultDTO<BomMaterialDTO>> response = restTemplate.exchange(
materialQueryUrl + no,
HttpMethod.POST,
requestEntity,
new ParameterizedTypeReference<>() {
}
);
log.info("登录主物料系统返回状态码:" + response.getStatusCode().value());
VUtil.trueThrowBusinessError(!response.getStatusCode().is2xxSuccessful())
.throwMessage("登录主物料系统失败");
BomResultDTO<BomMaterialDTO> resultDTO = response.getBody();
log.info("登录主物料系统返回数据:" + JSONUtil.toJsonStr(resultDTO));
return resultDTO.data();
}
private String getToken() {
String token = stringRedisTemplate.opsForValue().get("bom:token");
if (StrUtil.isBlank(token)) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<BomLoginQO> requestEntity = new HttpEntity<>(new BomLoginQO(userName, password), headers);
ResponseEntity<BomResultDTO<BomLoginResultDTO>> response = restTemplate.exchange(
loginUrl,
HttpMethod.POST,
requestEntity,
new ParameterizedTypeReference<>() {
}
);
log.info("登录主物料系统返回状态码:" + response.getStatusCode().value());
VUtil.trueThrowBusinessError(!response.getStatusCode().is2xxSuccessful())
.throwMessage("登录主物料系统失败");
BomResultDTO<BomLoginResultDTO> resultDTO = response.getBody();
log.info("登录主物料系统返回数据:" + JSONUtil.toJsonStr(resultDTO));
VUtil.trueThrowBusinessError(!Objects.equals(resultDTO.state(), 200)).throwMessage("登录主物料系统失败:" + resultDTO.msg());
token = resultDTO.data().token();
stringRedisTemplate.opsForValue().set("bom:token", token, 8, TimeUnit.HOURS);
}
return token;
}
}

12
pom.xml
View File

@ -22,6 +22,7 @@
<module>nflg-wms-admin</module>
<module>nflg-wms-auth</module>
<module>nflg-wms-file</module>
<module>nflg-wms-scheduled</module>
</modules>
<properties>
<java.version>17</java.version>
@ -41,6 +42,7 @@
<spring-boot-starter-actuator.version>3.4.0</spring-boot-starter-actuator.version>
<eec.version>0.5.24</eec.version>
<cglib.version>3.3.0</cglib.version>
<powerjob.version>5.1.1</powerjob.version>
</properties>
<dependencyManagement>
<dependencies>
@ -150,6 +152,16 @@
<artifactId>cglib</artifactId>
<version>${cglib.version}</version>
</dependency>
<dependency>
<groupId>tech.powerjob</groupId>
<artifactId>powerjob-client</artifactId>
<version>${powerjob.version}</version>
</dependency>
<dependency>
<groupId>tech.powerjob</groupId>
<artifactId>powerjob-worker</artifactId>
<version>${powerjob.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>