Merge branch 'develop' into dev_zhangke

This commit is contained in:
zhangke 2025-08-05 14:46:00 +08:00
commit 1207038de8
15 changed files with 421 additions and 45 deletions

View File

@ -1,5 +1,6 @@
package com.nflg.wms.admin;
import cn.dev33.satoken.sso.SaSsoManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -19,15 +20,8 @@ public class AdminApplication {
public static void main(String[] args) {
SpringApplication.run(AdminApplication.class, args);
log.info("服务已启动");
// log.info("---------------------- Sa-Token SSO 模式二 Client 端启动成功 ----------------------");
// log.info("配置信息:" + SaSsoManager.getClientConfig());
// SapService sapService= SpringUtil.getBean(SapService.class);
// sapService.printMeta("ZIM_001");
// sapService.zim001query("cdsfds");
// sapService.zwm00_MB017("1309976");
// log.info(JSONUtil.toJsonStr(sapService.searchOrder("0000101808")));
// log.info(JSONUtil.toJsonStr(sapService.getMaterialInfoInOrder("7500188009","0000101808","2100053760")));
log.info("---------------------- Sa-Token SSO 模式二 Client 端启动成功 ----------------------");
log.info("配置信息:" + SaSsoManager.getClientConfig());
}
}

View File

@ -1,10 +1,13 @@
package com.nflg.wms.admin.controller;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.nflg.wms.admin.service.BinService;
import com.nflg.wms.admin.service.SapService;
import com.nflg.wms.admin.util.NoUtil;
import com.nflg.wms.common.pojo.ApiResult;
import com.nflg.wms.common.pojo.PageData;
import com.nflg.wms.common.pojo.dto.InventoryDTO;
import com.nflg.wms.common.pojo.dto.Zim001QueryResultDTO;
import com.nflg.wms.common.pojo.dto.Zim001QueryResultItem1DTO;
import com.nflg.wms.common.pojo.qo.OutPurchaseSearchQO;
@ -13,6 +16,7 @@ import com.nflg.wms.common.util.UserUtil;
import com.nflg.wms.common.util.VUtil;
import com.nflg.wms.repository.entity.WmsOutPurchase;
import com.nflg.wms.repository.entity.WmsOutPurchaseItem;
import com.nflg.wms.repository.service.IWmsInventoryService;
import com.nflg.wms.repository.service.IWmsOutPurchaseItemService;
import com.nflg.wms.repository.service.IWmsOutPurchaseService;
import com.nflg.wms.starter.BaseController;
@ -23,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@ -45,6 +50,9 @@ public class OutPurchaseController extends BaseController {
@Resource
private BinService binService;
@Resource
IWmsInventoryService inventoryService;
/**
* 获取采购退库信息
* @param orderNo 采购单号
@ -65,11 +73,11 @@ public class OutPurchaseController extends BaseController {
*/
@Transactional
@PostMapping("save")
public ApiResult<Void> save(@Valid @RequestBody Zim001QueryResultDTO request){
VUtil.trueThrowBusinessError(request.getItem1().stream().map(Zim001QueryResultItem1DTO::getEBELN).collect(Collectors.toSet()).size()>1)
public ApiResult<Void> save(@Valid @RequestBody Zim001QueryResultDTO request) {
VUtil.trueThrowBusinessError(request.getItem1().stream().map(Zim001QueryResultItem1DTO::getEBELN).collect(Collectors.toSet()).size() > 1)
.throwMessage("采购单号不唯一");
Zim001QueryResultItem1DTO item=request.getItem1().get(0);
WmsOutPurchase purchase=new WmsOutPurchase()
Zim001QueryResultItem1DTO item = request.getItem1().get(0);
WmsOutPurchase purchase = new WmsOutPurchase()
.setNo(NoUtil.getOutPurchaseNo())
.setExternalOrderNo(item.getEBELN())
.setSupplierNo("")
@ -78,19 +86,39 @@ public class OutPurchaseController extends BaseController {
.setCreateTime(LocalDateTime.now());
//TODO 设置供应商信息
outPurchaseService.save(purchase);
outPurchaseItemService.saveBatch(request.getItem1().parallelStream().map(it -> new WmsOutPurchaseItem()
.setPurchaseId(purchase.getId())
.setRowNo(it.getEBELP())
.setMaterialNo(it.getMATNR())
.setMaterialDesc(it.getMAKTX())
.setNum(it.getERFMG())
.setUnit(it.getMEINS())
.setBatchNo(it.getCHARG())
.setFactoryNo(it.getWERKS())
.setWarehouseNo(it.getLGORT())
.set_101Year(it.getLFBJA())
.set_101No(it.getLFBNR())
.set_101Project(it.getLFPOS())).toList());
List<InventoryDTO> inventories = new ArrayList<>();
List<String> errors = new ArrayList<>();
outPurchaseItemService.saveBatch(request.getItem1().parallelStream().map(it -> {
String batchNo = CollectionUtil.get(StrUtil.split(it.getQrCode(), ","), 7);
if (StrUtil.isBlank(batchNo) || !StrUtil.equals(batchNo, it.getCHARG())) {
errors.add(it.getMATNR());
}
WmsOutPurchaseItem purchaseItem = new WmsOutPurchaseItem()
.setPurchaseId(purchase.getId())
.setRowNo(it.getEBELP())
.setMaterialNo(it.getMATNR())
.setMaterialDesc(it.getMAKTX())
.setNum(it.getERFMG())
.setUnit(it.getMEINS())
.setBatchNo(it.getCHARG())
.setFactoryNo(it.getWERKS())
.setWarehouseNo(it.getLGORT())
.set_101Year(it.getLFBJA())
.set_101No(it.getLFBNR())
.set_101Project(it.getLFPOS());
inventories.add(new InventoryDTO()
.setMaterialNo(it.getMATNR())
.setFactoryNo(it.getWERKS())
.setWarehouseNo(it.getLGORT())
.setBatchNumber(it.getCHARG())
.setNum(it.getERFMG().negate())
);
return purchaseItem;
}).toList()
);
VUtil.trueThrowBusinessError(CollectionUtil.isNotEmpty(errors)).throwMessage("以下物料的批次号不符合要求:"+StrUtil.join(",",errors));
//扣减库存
inventoryService.out(inventories);
sapService.zim001(request);
return ApiResult.success();
}

View File

@ -10,10 +10,7 @@ import com.nflg.wms.common.constant.Constant;
import com.nflg.wms.common.constant.STATE;
import com.nflg.wms.common.exception.NflgException;
import com.nflg.wms.common.pojo.dto.*;
import com.nflg.wms.common.pojo.qo.C_MaterialOutboundQO;
import com.nflg.wms.common.pojo.qo.C_MaterialReturnItemQO;
import com.nflg.wms.common.pojo.qo.C_MaterialReturnQO;
import com.nflg.wms.common.pojo.qo.ScanCodeQO;
import com.nflg.wms.common.pojo.qo.*;
import com.nflg.wms.common.util.UserUtil;
import com.nflg.wms.common.util.VUtil;
import com.sap.conn.jco.*;
@ -36,6 +33,75 @@ public class SapService {
@Resource
private JCoRepository repository;
/**
* 生产订单查询
* @param no 生产订单号
*/
public ZWM00MB007DTO zwm00Mb007(String no){
Map<String, Object> parameters = new HashMap<>();
parameters.put("I_AUFNR", no);
JCoFunction function = exec("ZWM00_MB007", parameters);
JCoStructure sreturn = function.getExportParameterList().getStructure("E_RETURN");
VUtil.trueThrowBusinessError(!StrUtil.equals(sreturn.getString("TYPE"), "S"))
.throwMessage("SAP错误:" + sreturn.getString("MSG"));
JCoStructure data = function.getExportParameterList().getStructure("E_OUTPUT");
return new ZWM00MB007DTO()
.setAUFNR(data.getString("AUFNR"))
.setPSMNG(data.getBigDecimal("PSMNG"))
.setPWERK(data.getString("PWERK"))
.setWEMNG(data.getBigDecimal("WEMNG"))
.setMATNR(data.getString("MATNR"))
.setWSHSL(data.getBigDecimal("WSHSL"))
.setLGORT(data.getString("LGORT"))
.setMEINS(data.getString("MEINS"))
.setMAKTX(data.getString("MAKTX"));
}
/**
* 生产订单收货
* @param no 生产订单号
* @param userName 用户名
* @param materials 入库物料列表
* @param sernrs 序列号列表
*/
public Zwm00Mb107DTO zwm00_mb107(String no, String userName, List<Zwm00Mb107QO> materials, List<String> sernrs){
Map<String, Object> parameters = new HashMap<>();
parameters.put("I_AUFNR", no);
parameters.put("I_USNAM", userName);
Map<String, List<Map<String, Object>>> tables = new HashMap<>();
List<Map<String, Object>> list1 = new ArrayList<>();
materials.forEach(item -> {
Map<String, Object> map=new HashMap<>();
map.put("PWERK", item.getPWERK());
map.put("LGORT", item.getLGORT());
map.put("PSMNG", item.getPSMNG());
map.put("AMEIN", item.getAMEIN());
map.put("CHARG", item.getCHARG());
list1.add(map);
});
tables.put("T_LIST1", list1);
List<Map<String, Object>> list2 = new ArrayList<>();
sernrs.forEach(item -> {
list2.add(Map.of("SERNR", item));
});
tables.put("T_LIST2", list2);
JCoFunction function = exec("ZWM00_MB107", parameters, tables);
JCoStructure sreturn = function.getExportParameterList().getStructure("E_RETURN");
VUtil.trueThrowBusinessError(!StrUtil.equals(sreturn.getString("TYPE"), "S"))
.throwMessage("SAP错误:" + sreturn.getString("MSG"));
return new Zwm00Mb107DTO()
.setE_MBLNR(function.getExportParameterList().getString("E_MBLNR"))
.setE_MJAHR(function.getExportParameterList().getString("E_MJAHR"));
}
/**
* 查询采购单退库信息
* @param orderNo 采购单号
@ -478,6 +544,10 @@ public class SapService {
return out;
}
private JCoFunction exec(String functionName, Map<String, Object> parameters) {
return exec(functionName, parameters, null);
}
private JCoFunction exec(String functionName, Map<String, Object> parameters, Map<String, List<Map<String, Object>>> tables) {
try {
functionName=functionName.toUpperCase();
@ -509,11 +579,15 @@ public class SapService {
}
}
public void printMeta(String functionName) throws JCoException {
functionName=functionName.toUpperCase();
JCoFunction function = repository.getFunction(functionName);
VUtil.trueThrowBusinessError(Objects.isNull(function)).throwMessage("方法"+functionName+"不存在");
printMeta(function);
public void printMeta(String functionName) {
try {
functionName=functionName.toUpperCase();
JCoFunction function = repository.getFunction(functionName);
VUtil.trueThrowBusinessError(Objects.isNull(function)).throwMessage("方法"+functionName+"不存在");
printMeta(function);
}catch (Exception e){
log.error("打印方法参数信息异常", e);
}
}
private void printMeta(JCoFunction function){

View File

@ -5,9 +5,9 @@ logging:
nflg: debug
alibaba:
cloud:
nacos: debug
nacos: info
org:
springframework: debug
springframework: info
# sa-token配置
sa-token:
# SSO-相关配置

View File

@ -73,22 +73,33 @@
<message>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%X{traceId}] %-5level %logger{50} - %msg %ex</pattern>
</message>
<verbose>false</verbose>
</appender>
<appender name="ASYNC_LOKI" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="LOKI" />
<!-- 队列大小 -->
<queueSize>1024</queueSize>
<!-- 丢弃策略 -->
<discardingThreshold>0</discardingThreshold>
<!-- 关键:即使队列满也不阻塞 -->
<neverBlock>true</neverBlock>
<includeCallerData>false</includeCallerData>
</appender>
<logger name="com.alibaba.nacos" level="warn" additivity="false">
<!-- <appender-ref ref="FILE"/>-->
<appender-ref ref="LOKI"/>
<appender-ref ref="ASYNC_LOKI"/>
</logger>
<logger name="tech.powerjob" level="INFO" additivity="false">
<!-- <appender-ref ref="POWERJOB_WORKER_APPENDER" />-->
<appender-ref ref="LOKI"/>
<appender-ref ref="ASYNC_LOKI"/>
</logger>
<!-- 默认配置 -->
<root level="DEBUG">
<appender-ref ref="CONSOLE"/>
<!-- <appender-ref ref="FILE"/>-->
<appender-ref ref="LOKI"/>
<appender-ref ref="ASYNC_LOKI"/>
</root>
</configuration>

View File

@ -0,0 +1,23 @@
package com.nflg.wms.admin;
import com.nflg.wms.admin.service.SapService;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class SapMetaPrintTest {
@Resource
private SapService sapService;
@Test
public void ZWM00_MB007(){
sapService.printMeta("ZWM00_MB007");
}
@Test
public void ZWM00_MB107(){
sapService.printMeta("ZWM00_MB107");
}
}

View File

@ -0,0 +1,36 @@
package com.nflg.wms.common.pojo.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import java.math.BigDecimal;
@Data
@Accessors(chain = true)
public class InventoryDTO {
/**
* 物料编号
*/
private String materialNo;
/**
* 工厂
*/
private String factoryNo;
/**
* 库位
*/
private String warehouseNo;
/**
* 批次号
*/
private String batchNumber;
/**
* 数量
*/
private BigDecimal num;
}

View File

@ -0,0 +1,56 @@
package com.nflg.wms.common.pojo.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import java.math.BigDecimal;
@Data
@Accessors(chain = true)
public class ZWM00MB007DTO {
/**
* 订单号
*/
private String AUFNR;
/**
* 物料号
*/
private String MATNR;
/**
* 物料描述
*/
private String MAKTX;
/**
* 工厂
*/
private String PWERK;
/**
* 仓库
*/
private String LGORT;
/**
* 订单数量
*/
private BigDecimal PSMNG;
/**
* 已收货数量
*/
private BigDecimal WEMNG;
/**
* 未收货数量
*/
private BigDecimal WSHSL;
/**
* 单位
*/
private String MEINS;
}

View File

@ -78,6 +78,7 @@ public class Zim001QueryResultItem1DTO {
/**
* 二维码内容
*/
@NotBlank
private String qrCode;
/**

View File

@ -0,0 +1,19 @@
package com.nflg.wms.common.pojo.dto;
import lombok.Data;
import lombok.experimental.Accessors;
@Data
@Accessors(chain = true)
public class Zwm00Mb107DTO {
/**
* 物料凭证编号
*/
private String E_MBLNR;
/**
* 物料凭证年度
*/
private String E_MJAHR;
}

View File

@ -0,0 +1,36 @@
package com.nflg.wms.common.pojo.qo;
import lombok.Data;
import lombok.experimental.Accessors;
import java.math.BigDecimal;
@Data
@Accessors(chain = true)
public class Zwm00Mb107QO {
/**
* 工厂
*/
private String PWERK;
/**
* 仓库
*/
private String LGORT;
/**
* 数量
*/
private BigDecimal PSMNG;
/**
* 单位
*/
private String AMEIN;
/**
* 批次
*/
private String CHARG;
}

View File

@ -43,7 +43,10 @@
<artifactId>freemarker</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@ -1,8 +1,11 @@
package com.nflg.wms.repository.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.nflg.wms.common.pojo.dto.InventoryDTO;
import com.nflg.wms.repository.entity.WmsInventory;
import java.util.List;
/**
* <p>
* 服务类
@ -13,4 +16,7 @@ import com.nflg.wms.repository.entity.WmsInventory;
*/
public interface IWmsInventoryService extends IService<WmsInventory> {
void out(List<InventoryDTO> inventories);
void in(List<InventoryDTO> inventories);
}

View File

@ -1,20 +1,106 @@
package com.nflg.wms.repository.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nflg.wms.common.exception.NflgException;
import com.nflg.wms.common.pojo.dto.InventoryDTO;
import com.nflg.wms.common.util.UserUtil;
import com.nflg.wms.common.util.VUtil;
import com.nflg.wms.repository.entity.WmsInventory;
import com.nflg.wms.repository.mapper.WmsInventoryMapper;
import com.nflg.wms.repository.service.IWmsInventoryService;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* <p>
* 服务实现类
* 服务实现类
* </p>
*
* @author 代码生成器生成
* @since 2025
*/
@Service
public class WmsInventoryServiceImpl extends ServiceImpl<WmsInventoryMapper, WmsInventory> implements IWmsInventoryService {
@Transactional
@Retryable(
noRetryFor = NflgException.class,
maxAttempts = 10, // 最大重试次数包括第一次调用
backoff = @Backoff(delay = 500)
)
@Override
public void out(List<InventoryDTO> inventories) {
List<String> errorMaterialNos = new ArrayList<>();
List<WmsInventory> dbInventories = inventories.stream().map(inventory -> {
WmsInventory info = lambdaQuery()
.eq(WmsInventory::getMaterialNo, inventory.getMaterialNo())
.eq(WmsInventory::getBatchNumber, inventory.getBatchNumber())
.eq(WmsInventory::getFactoryNo, inventory.getFactoryNo())
.eq(WmsInventory::getWarehouseNo, inventory.getWarehouseNo())
.one();
if (Objects.isNull(info) || info.getNum().compareTo(inventory.getNum()) < 0) {
errorMaterialNos.add(inventory.getMaterialNo());
} else {
info.setNum(info.getNum().subtract(inventory.getNum()));
info.setUpdateBy(UserUtil.getUserName());
info.setUpdateTime(LocalDateTime.now());
}
return info;
}
).toList();
VUtil.trueThrowBusinessError(CollectionUtil.isNotEmpty(errorMaterialNos))
.throwMessage("以下物料库存不足:"+StrUtil.join(",", errorMaterialNos));
updateBatchById(dbInventories);
}
@Transactional
@Retryable(
noRetryFor = NflgException.class,
maxAttempts = 10, // 最大重试次数包括第一次调用
backoff = @Backoff(delay = 500)
)
@Override
public void in(List<InventoryDTO> inventories) {
List<WmsInventory> forAdd = new ArrayList<>();
List<WmsInventory> forUpdate = new ArrayList<>();
inventories.forEach(inventory -> {
WmsInventory info = lambdaQuery()
.eq(WmsInventory::getMaterialNo, inventory.getMaterialNo())
.eq(WmsInventory::getBatchNumber, inventory.getBatchNumber())
.eq(WmsInventory::getFactoryNo, inventory.getFactoryNo())
.eq(WmsInventory::getWarehouseNo, inventory.getWarehouseNo())
.one();
if (Objects.isNull(info)) {
info = new WmsInventory()
.setMaterialNo(inventory.getMaterialNo())
.setBatchNumber(inventory.getBatchNumber())
.setFactoryNo(inventory.getFactoryNo())
.setWarehouseNo(inventory.getWarehouseNo())
.setNum(inventory.getNum())
.setCreateBy(UserUtil.getUserName())
.setCreateTime(LocalDateTime.now());
forAdd.add(info);
} else {
info.setNum(info.getNum().add(inventory.getNum()));
info.setUpdateBy(UserUtil.getUserName());
info.setUpdateTime(LocalDateTime.now());
forUpdate.add(info);
}
}
);
if (CollectionUtil.isNotEmpty(forAdd)) {
saveBatch(forAdd);
}
if (CollectionUtil.isNotEmpty(forUpdate)) {
updateBatchById(forUpdate);
}
}
}

View File

@ -1,8 +1,9 @@
package com.nflg.wms.scheduled;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.ComponentScan;
@Slf4j
@ -11,7 +12,9 @@ import org.springframework.context.annotation.ComponentScan;
public class ScheduledApplication {
public static void main(String[] args) {
SpringApplication.run(ScheduledApplication.class, args);
new SpringApplicationBuilder(ScheduledApplication.class)
.web(WebApplicationType.NONE)
.run(args);
log.info("服务已启动");
// SapService sapService=SpringUtil.getBean(SapService.class);