15 changed files with 736 additions and 0 deletions
-
53src/main/java/com/gaotao/modules/scrap/controller/ScrapController.java
-
12src/main/java/com/gaotao/modules/scrap/dao/ScrapMapper.java
-
18src/main/java/com/gaotao/modules/scrap/entity/ScrapConfirmDto.java
-
20src/main/java/com/gaotao/modules/scrap/entity/ScrapLabelDto.java
-
20src/main/java/com/gaotao/modules/scrap/service/ScrapService.java
-
166src/main/java/com/gaotao/modules/scrap/service/impl/ScrapServiceImpl.java
-
71src/main/java/com/gaotao/modules/transit/controller/TransitController.java
-
30src/main/java/com/gaotao/modules/transit/dao/TransitMapper.java
-
19src/main/java/com/gaotao/modules/transit/entity/TransitDetailDto.java
-
20src/main/java/com/gaotao/modules/transit/entity/TransitLabelDto.java
-
18src/main/java/com/gaotao/modules/transit/entity/TransitReceiveDto.java
-
21src/main/java/com/gaotao/modules/transit/entity/TransitRecordDto.java
-
26src/main/java/com/gaotao/modules/transit/service/TransitService.java
-
164src/main/java/com/gaotao/modules/transit/service/impl/TransitServiceImpl.java
-
78src/main/resources/mapper/transit/TransitMapper.xml
@ -0,0 +1,53 @@ |
|||||
|
package com.gaotao.modules.scrap.controller; |
||||
|
|
||||
|
import com.gaotao.common.utils.R; |
||||
|
import com.gaotao.modules.scrap.entity.ScrapLabelDto; |
||||
|
import com.gaotao.modules.scrap.entity.ScrapConfirmDto; |
||||
|
import com.gaotao.modules.scrap.service.ScrapService; |
||||
|
import com.gaotao.modules.sys.controller.AbstractController; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
/** |
||||
|
* 报废相关控制器 |
||||
|
*/ |
||||
|
@RequestMapping("scrap") |
||||
|
@RestController |
||||
|
public class ScrapController extends AbstractController { |
||||
|
|
||||
|
@Autowired |
||||
|
private ScrapService scrapService; |
||||
|
|
||||
|
/** |
||||
|
* 扫描报废标签 |
||||
|
*/ |
||||
|
@PostMapping("scanScrapLabel") |
||||
|
public R scanScrapLabel(@RequestBody ScrapLabelDto dto) { |
||||
|
try { |
||||
|
ScrapLabelDto labelInfo = scrapService.scanScrapLabel(dto); |
||||
|
if (labelInfo != null) { |
||||
|
return R.ok().put("labelInfo", labelInfo); |
||||
|
} else { |
||||
|
return R.error("标签验证失败"); |
||||
|
} |
||||
|
} catch (Exception e) { |
||||
|
return R.error("扫描标签失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 确认报废 |
||||
|
*/ |
||||
|
@PostMapping("confirmScrap") |
||||
|
public R confirmScrap(@RequestBody ScrapConfirmDto dto) { |
||||
|
try { |
||||
|
scrapService.confirmScrap(dto); |
||||
|
return R.ok().put("message", "报废成功"); |
||||
|
} catch (Exception e) { |
||||
|
return R.error("报废失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
package com.gaotao.modules.scrap.dao; |
||||
|
|
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
/** |
||||
|
* 报废数据访问层 |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface ScrapMapper { |
||||
|
// 目前主要依赖IFS接口,暂时不需要数据库操作 |
||||
|
// 后续可以根据需要添加数据库查询方法 |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
package com.gaotao.modules.scrap.entity; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 报废确认DTO |
||||
|
*/ |
||||
|
@Data |
||||
|
public class ScrapConfirmDto { |
||||
|
private String site; |
||||
|
private String scrapReason; |
||||
|
private List<ScrapLabelDto> labels; |
||||
|
private String operatorId; |
||||
|
private String operatorName; |
||||
|
private Date scrapDate; |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
package com.gaotao.modules.scrap.entity; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
import java.math.BigDecimal; |
||||
|
|
||||
|
/** |
||||
|
* 报废标签DTO |
||||
|
*/ |
||||
|
@Data |
||||
|
public class ScrapLabelDto { |
||||
|
private String labelCode; |
||||
|
private String site; |
||||
|
private String partNo; |
||||
|
private String partDesc; |
||||
|
private BigDecimal quantity; |
||||
|
private String unit; |
||||
|
private String batchNo; |
||||
|
private String locationId; |
||||
|
private String warehouseId; |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
package com.gaotao.modules.scrap.service; |
||||
|
|
||||
|
import com.gaotao.modules.scrap.entity.ScrapLabelDto; |
||||
|
import com.gaotao.modules.scrap.entity.ScrapConfirmDto; |
||||
|
|
||||
|
/** |
||||
|
* 报废服务接口 |
||||
|
*/ |
||||
|
public interface ScrapService { |
||||
|
|
||||
|
/** |
||||
|
* 扫描报废标签 |
||||
|
*/ |
||||
|
ScrapLabelDto scanScrapLabel(ScrapLabelDto dto); |
||||
|
|
||||
|
/** |
||||
|
* 确认报废 |
||||
|
*/ |
||||
|
void confirmScrap(ScrapConfirmDto dto); |
||||
|
} |
||||
@ -0,0 +1,166 @@ |
|||||
|
package com.gaotao.modules.scrap.service.impl; |
||||
|
|
||||
|
import com.alibaba.fastjson2.JSONObject; |
||||
|
import com.fasterxml.jackson.core.type.TypeReference; |
||||
|
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
|
import com.gaotao.common.exception.XJException; |
||||
|
import com.gaotao.common.utils.HttpUtils; |
||||
|
import com.gaotao.modules.scrap.entity.*; |
||||
|
import com.gaotao.modules.scrap.service.ScrapService; |
||||
|
import com.gaotao.modules.scrap.dao.ScrapMapper; |
||||
|
import com.gaotao.modules.trans.entity.TransHeader; |
||||
|
import com.gaotao.modules.trans.entity.TransDetail; |
||||
|
import com.gaotao.modules.trans.entity.TransDetailDto; |
||||
|
import com.gaotao.modules.trans.service.TransHeaderService; |
||||
|
import com.gaotao.modules.trans.service.TransDetailService; |
||||
|
import com.gaotao.modules.trans.service.TransNoControlService; |
||||
|
import com.gaotao.modules.sys.entity.SysUserEntity; |
||||
|
import com.gaotao.modules.sys.controller.AbstractController; |
||||
|
import org.apache.shiro.SecurityUtils; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 报废服务实现类 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Service |
||||
|
public class ScrapServiceImpl extends AbstractController implements ScrapService { |
||||
|
|
||||
|
@Autowired |
||||
|
private ScrapMapper scrapMapper; |
||||
|
|
||||
|
@Autowired |
||||
|
private TransHeaderService transHeaderService; |
||||
|
|
||||
|
@Autowired |
||||
|
private TransDetailService transDetailService; |
||||
|
|
||||
|
@Autowired |
||||
|
private TransNoControlService transNoControlService; |
||||
|
|
||||
|
@Value("${custom.ifs-url}") |
||||
|
private String ifsUrl; |
||||
|
@Value("${custom.ifs-ifsDBName}") |
||||
|
private String ifsDBName; |
||||
|
@Value("${custom.ifs-domainUserID}") |
||||
|
private String domainUserID; |
||||
|
|
||||
|
@Override |
||||
|
public ScrapLabelDto scanScrapLabel(ScrapLabelDto dto) { |
||||
|
try { |
||||
|
// 从IFS接口获取标签信息 |
||||
|
Map<String, Object> params = Map.of( |
||||
|
"ifsDBName", ifsDBName, |
||||
|
"domainUserID", domainUserID, |
||||
|
"ifsSiteID", dto.getSite(), |
||||
|
"labelCode", dto.getLabelCode() |
||||
|
); |
||||
|
|
||||
|
ObjectMapper objectMapper = new ObjectMapper(); |
||||
|
String jsonBody = objectMapper.writeValueAsString(params); |
||||
|
String ifsResponse = HttpUtils.doGetWithBody(ifsUrl + "LabelInfo", jsonBody, null); |
||||
|
|
||||
|
// 解析IFS响应 |
||||
|
Map<String, Object> ifsData = objectMapper.readValue(ifsResponse, new TypeReference<Map<String, Object>>() {}); |
||||
|
|
||||
|
// 构建标签信息 |
||||
|
ScrapLabelDto labelInfo = new ScrapLabelDto(); |
||||
|
labelInfo.setLabelCode(dto.getLabelCode()); |
||||
|
labelInfo.setSite(dto.getSite()); |
||||
|
labelInfo.setPartNo((String) ifsData.get("partNo")); |
||||
|
labelInfo.setPartDesc((String) ifsData.get("partDesc")); |
||||
|
labelInfo.setQuantity(new BigDecimal(ifsData.get("quantity").toString())); |
||||
|
labelInfo.setUnit((String) ifsData.get("unit")); |
||||
|
labelInfo.setBatchNo((String) ifsData.get("batchNo")); |
||||
|
labelInfo.setLocationId((String) ifsData.get("locationId")); |
||||
|
labelInfo.setWarehouseId((String) ifsData.get("warehouseId")); |
||||
|
|
||||
|
return labelInfo; |
||||
|
|
||||
|
} catch (Exception e) { |
||||
|
log.error("扫描报废标签异常: {}", e.getMessage()); |
||||
|
throw new XJException("扫描报废标签失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional |
||||
|
public void confirmScrap(ScrapConfirmDto dto) { |
||||
|
SysUserEntity currentUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
||||
|
|
||||
|
// 1. 生成报废出库事务记录 |
||||
|
TransDetailDto outData = new TransDetailDto(); |
||||
|
outData.setSite(dto.getSite()); |
||||
|
outData.setWarehouseId("1"); // 使用默认仓库ID |
||||
|
outData.setRemark("物料报废 - " + dto.getScrapReason()); |
||||
|
outData.setOrderRef1(dto.getScrapReason()); // 存储报废原因 |
||||
|
|
||||
|
// 生成报废出库事务号 |
||||
|
TransHeader outTransHeader = transHeaderService.genTrans(outData, "SCRAP"); // 报废事务类型 |
||||
|
outTransHeader.setStatus("COMPLETED"); |
||||
|
outTransHeader.setStatusDb("COMPLETED"); |
||||
|
transHeaderService.updateById(outTransHeader); |
||||
|
|
||||
|
// 2. 保存报废明细 |
||||
|
for (int i = 0; i < dto.getLabels().size(); i++) { |
||||
|
ScrapLabelDto label = dto.getLabels().get(i); |
||||
|
|
||||
|
TransDetail outDetail = new TransDetail(); |
||||
|
outDetail.setSite(dto.getSite()); |
||||
|
outDetail.setTransNo(outTransHeader.getTransNo()); |
||||
|
outDetail.setItemNo((double) i); |
||||
|
outDetail.setPartNo(label.getPartNo()); |
||||
|
outDetail.setTransQty(label.getQuantity()); |
||||
|
outDetail.setBatchNo(label.getBatchNo()); |
||||
|
outDetail.setLocationId(label.getLocationId()); |
||||
|
outDetail.setOrderRef1(dto.getScrapReason()); // 存储报废原因 |
||||
|
outDetail.setOrderRef2(label.getLabelCode()); // 存储标签编码 |
||||
|
outDetail.setRemark("物料报废"); |
||||
|
|
||||
|
transDetailService.save(outDetail); |
||||
|
} |
||||
|
|
||||
|
// 3. 调用IFS接口同步报废信息 |
||||
|
try { |
||||
|
Map<String, Object> ifsParams = Map.of( |
||||
|
"ifsDBName", ifsDBName, |
||||
|
"domainUserID", domainUserID, |
||||
|
"ifsSiteID", dto.getSite(), |
||||
|
"transNo", outTransHeader.getTransNo(), |
||||
|
"scrapReason", dto.getScrapReason(), |
||||
|
"labels", dto.getLabels() |
||||
|
); |
||||
|
|
||||
|
ObjectMapper objectMapper = new ObjectMapper(); |
||||
|
String jsonBody = objectMapper.writeValueAsString(ifsParams); |
||||
|
String ifsResponse = HttpUtils.doPost(ifsUrl + "ScrapSync", jsonBody, null); |
||||
|
|
||||
|
log.info("IFS报废同步响应: {}", ifsResponse); |
||||
|
|
||||
|
} catch (Exception e) { |
||||
|
log.error("IFS报废同步失败: {}", e.getMessage()); |
||||
|
// 注意:这里不抛出异常,因为WMS事务已经完成,IFS同步失败不影响WMS操作 |
||||
|
} |
||||
|
|
||||
|
// 4. 更新库存(这里需要调用库存服务) |
||||
|
// updateInventoryStock(dto); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 更新库存(需要根据实际的库存服务实现) |
||||
|
*/ |
||||
|
private void updateInventoryStock(ScrapConfirmDto dto) { |
||||
|
// TODO: 实现库存更新逻辑 |
||||
|
// 减少对应仓库和库位的库存 |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,71 @@ |
|||||
|
package com.gaotao.modules.transit.controller; |
||||
|
|
||||
|
import com.gaotao.common.utils.R; |
||||
|
import com.gaotao.modules.transit.entity.TransitRecordDto; |
||||
|
import com.gaotao.modules.transit.entity.TransitLabelDto; |
||||
|
import com.gaotao.modules.transit.entity.TransitReceiveDto; |
||||
|
import com.gaotao.modules.transit.service.TransitService; |
||||
|
import com.gaotao.modules.sys.controller.AbstractController; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
/** |
||||
|
* 移库相关控制器 |
||||
|
*/ |
||||
|
@RequestMapping("transit") |
||||
|
@RestController |
||||
|
public class TransitController extends AbstractController { |
||||
|
|
||||
|
@Autowired |
||||
|
private TransitService transitService; |
||||
|
|
||||
|
/** |
||||
|
* 获取移库记录 |
||||
|
*/ |
||||
|
@PostMapping("getTransitRecord") |
||||
|
public R getTransitRecord(@RequestBody TransitRecordDto dto) { |
||||
|
try { |
||||
|
TransitRecordDto record = transitService.getTransitRecord(dto.getTransactionId(), dto.getSite()); |
||||
|
if (record != null) { |
||||
|
return R.ok().put("data", record); |
||||
|
} else { |
||||
|
return R.error("未找到移库记录"); |
||||
|
} |
||||
|
} catch (Exception e) { |
||||
|
return R.error("查询移库记录失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 扫描移库标签 |
||||
|
*/ |
||||
|
@PostMapping("scanTransitLabel") |
||||
|
public R scanTransitLabel(@RequestBody TransitLabelDto dto) { |
||||
|
try { |
||||
|
TransitLabelDto labelInfo = transitService.scanTransitLabel(dto); |
||||
|
if (labelInfo != null) { |
||||
|
return R.ok().put("labelInfo", labelInfo); |
||||
|
} else { |
||||
|
return R.error("标签验证失败"); |
||||
|
} |
||||
|
} catch (Exception e) { |
||||
|
return R.error("扫描标签失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 确认移库接收 |
||||
|
*/ |
||||
|
@PostMapping("confirmTransitReceive") |
||||
|
public R confirmTransitReceive(@RequestBody TransitReceiveDto dto) { |
||||
|
try { |
||||
|
transitService.confirmTransitReceive(dto); |
||||
|
return R.ok().put("message", "移库接收成功"); |
||||
|
} catch (Exception e) { |
||||
|
return R.error("移库接收失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
package com.gaotao.modules.transit.dao; |
||||
|
|
||||
|
import com.gaotao.modules.trans.entity.TransHeader; |
||||
|
import com.gaotao.modules.trans.entity.TransDetail; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
import org.apache.ibatis.annotations.Param; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 移库数据访问层 |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface TransitMapper { |
||||
|
|
||||
|
/** |
||||
|
* 获取移库头信息 |
||||
|
*/ |
||||
|
TransHeader getTransitHeader(@Param("transNo") String transNo, @Param("site") String site); |
||||
|
|
||||
|
/** |
||||
|
* 获取移库明细 |
||||
|
*/ |
||||
|
List<TransDetail> getTransitDetails(@Param("transNo") String transNo, @Param("site") String site); |
||||
|
|
||||
|
/** |
||||
|
* 根据标签获取移库明细 |
||||
|
*/ |
||||
|
TransDetail getTransitDetailByLabel(@Param("labelCode") String labelCode, @Param("transNo") String transNo, @Param("site") String site); |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
package com.gaotao.modules.transit.entity; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
import java.math.BigDecimal; |
||||
|
|
||||
|
/** |
||||
|
* 移库明细DTO |
||||
|
*/ |
||||
|
@Data |
||||
|
public class TransitDetailDto { |
||||
|
private String partNo; |
||||
|
private String partDesc; |
||||
|
private BigDecimal quantity; |
||||
|
private String unit; |
||||
|
private String batchNo; |
||||
|
private String fromLocation; |
||||
|
private String toLocation; |
||||
|
private String labelCode; |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
package com.gaotao.modules.transit.entity; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
import java.math.BigDecimal; |
||||
|
|
||||
|
/** |
||||
|
* 移库标签DTO |
||||
|
*/ |
||||
|
@Data |
||||
|
public class TransitLabelDto { |
||||
|
private String labelCode; |
||||
|
private String transNo; |
||||
|
private String site; |
||||
|
private String partNo; |
||||
|
private String partDesc; |
||||
|
private BigDecimal quantity; |
||||
|
private String unit; |
||||
|
private String batchNo; |
||||
|
private String locationId; |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
package com.gaotao.modules.transit.entity; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 移库接收DTO |
||||
|
*/ |
||||
|
@Data |
||||
|
public class TransitReceiveDto { |
||||
|
private String site; |
||||
|
private String transNo; |
||||
|
private List<TransitLabelDto> labels; |
||||
|
private String operatorId; |
||||
|
private String operatorName; |
||||
|
private Date receiveDate; |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
package com.gaotao.modules.transit.entity; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 移库记录DTO |
||||
|
*/ |
||||
|
@Data |
||||
|
public class TransitRecordDto { |
||||
|
private String transactionId; |
||||
|
private String site; |
||||
|
private String transNo; |
||||
|
private String fromWarehouse; |
||||
|
private String toWarehouse; |
||||
|
private String status; |
||||
|
private Date transDate; |
||||
|
private String remark; |
||||
|
private List<TransitDetailDto> detailList; |
||||
|
} |
||||
@ -0,0 +1,26 @@ |
|||||
|
package com.gaotao.modules.transit.service; |
||||
|
|
||||
|
import com.gaotao.modules.transit.entity.TransitRecordDto; |
||||
|
import com.gaotao.modules.transit.entity.TransitLabelDto; |
||||
|
import com.gaotao.modules.transit.entity.TransitReceiveDto; |
||||
|
|
||||
|
/** |
||||
|
* 移库服务接口 |
||||
|
*/ |
||||
|
public interface TransitService { |
||||
|
|
||||
|
/** |
||||
|
* 获取移库记录 |
||||
|
*/ |
||||
|
TransitRecordDto getTransitRecord(String transactionId, String site); |
||||
|
|
||||
|
/** |
||||
|
* 扫描移库标签 |
||||
|
*/ |
||||
|
TransitLabelDto scanTransitLabel(TransitLabelDto dto); |
||||
|
|
||||
|
/** |
||||
|
* 确认移库接收 |
||||
|
*/ |
||||
|
void confirmTransitReceive(TransitReceiveDto dto); |
||||
|
} |
||||
@ -0,0 +1,164 @@ |
|||||
|
package com.gaotao.modules.transit.service.impl; |
||||
|
|
||||
|
import com.alibaba.fastjson2.JSONObject; |
||||
|
import com.fasterxml.jackson.core.type.TypeReference; |
||||
|
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
|
import com.gaotao.common.exception.XJException; |
||||
|
import com.gaotao.common.utils.HttpUtils; |
||||
|
import com.gaotao.modules.transit.entity.*; |
||||
|
import com.gaotao.modules.transit.service.TransitService; |
||||
|
import com.gaotao.modules.transit.dao.TransitMapper; |
||||
|
import com.gaotao.modules.trans.entity.TransHeader; |
||||
|
import com.gaotao.modules.trans.entity.TransDetail; |
||||
|
import com.gaotao.modules.trans.entity.TransDetailDto; |
||||
|
import com.gaotao.modules.trans.service.TransHeaderService; |
||||
|
import com.gaotao.modules.trans.service.TransDetailService; |
||||
|
import com.gaotao.modules.trans.service.TransNoControlService; |
||||
|
import com.gaotao.modules.sys.entity.SysUserEntity; |
||||
|
import com.gaotao.modules.sys.controller.AbstractController; |
||||
|
import org.apache.shiro.SecurityUtils; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 移库服务实现类 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Service |
||||
|
public class TransitServiceImpl extends AbstractController implements TransitService { |
||||
|
|
||||
|
@Autowired |
||||
|
private TransitMapper transitMapper; |
||||
|
|
||||
|
@Autowired |
||||
|
private TransHeaderService transHeaderService; |
||||
|
|
||||
|
@Autowired |
||||
|
private TransDetailService transDetailService; |
||||
|
|
||||
|
@Autowired |
||||
|
private TransNoControlService transNoControlService; |
||||
|
|
||||
|
@Value("${custom.ifs-url}") |
||||
|
private String ifsUrl; |
||||
|
@Value("${custom.ifs-ifsDBName}") |
||||
|
private String ifsDBName; |
||||
|
@Value("${custom.ifs-domainUserID}") |
||||
|
private String domainUserID; |
||||
|
|
||||
|
@Override |
||||
|
public TransitRecordDto getTransitRecord(String transactionId, String site) { |
||||
|
try { |
||||
|
// 从IFS接口获取移库记录 |
||||
|
Map<String, Object> params = Map.of( |
||||
|
"ifsDBName", ifsDBName, |
||||
|
"domainUserID", domainUserID, |
||||
|
"ifsSiteID", site, |
||||
|
"transactionId", transactionId |
||||
|
); |
||||
|
|
||||
|
ObjectMapper objectMapper = new ObjectMapper(); |
||||
|
String jsonBody = objectMapper.writeValueAsString(params); |
||||
|
//String ifsResponse = HttpUtils.doGetWithBody(ifsUrl + "TransitRecord", jsonBody, null); |
||||
|
|
||||
|
// 解析IFS响应 |
||||
|
//Map<String, Object> ifsData = objectMapper.readValue(ifsResponse, new TypeReference<Map<String, Object>>() {}); |
||||
|
|
||||
|
// 构建返回数据 |
||||
|
TransitRecordDto recordDto = new TransitRecordDto(); |
||||
|
recordDto.setTransactionId(transactionId); |
||||
|
recordDto.setSite(site); |
||||
|
recordDto.setTransNo("transNo"); |
||||
|
recordDto.setFromWarehouse("fromWarehouse"); |
||||
|
recordDto.setToWarehouse("toWarehouse"); |
||||
|
|
||||
|
return recordDto; |
||||
|
|
||||
|
} catch (Exception e) { |
||||
|
log.error("获取移库记录异常: {}", e.getMessage()); |
||||
|
throw new XJException("获取移库记录失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public TransitLabelDto scanTransitLabel(TransitLabelDto dto) { |
||||
|
// 简化处理,直接返回标签信息,不进行验证 |
||||
|
TransitLabelDto labelInfo = new TransitLabelDto(); |
||||
|
labelInfo.setLabelCode(dto.getLabelCode()); |
||||
|
labelInfo.setTransNo(dto.getTransNo()); |
||||
|
labelInfo.setSite(dto.getSite()); |
||||
|
labelInfo.setPartNo("待确认"); |
||||
|
labelInfo.setQuantity(new BigDecimal("1")); |
||||
|
labelInfo.setUnit("个"); |
||||
|
labelInfo.setBatchNo(""); |
||||
|
labelInfo.setLocationId(""); |
||||
|
|
||||
|
return labelInfo; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional |
||||
|
public void confirmTransitReceive(TransitReceiveDto dto) { |
||||
|
SysUserEntity currentUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
||||
|
|
||||
|
// 1. 生成移入事务记录 |
||||
|
TransDetailDto inData = new TransDetailDto(); |
||||
|
inData.setSite(dto.getSite()); |
||||
|
inData.setWarehouseId("1"); // 使用默认仓库ID |
||||
|
inData.setRemark("移库接收"); |
||||
|
inData.setOrderRef1(dto.getTransNo()); // 关联原移库单号 |
||||
|
|
||||
|
// 生成移入事务号 |
||||
|
TransHeader inTransHeader = transHeaderService.genTrans(inData, "TRIN"); // 移入事务类型 |
||||
|
inTransHeader.setStatus("COMPLETED"); |
||||
|
inTransHeader.setStatusDb("COMPLETED"); |
||||
|
transHeaderService.updateById(inTransHeader); |
||||
|
|
||||
|
// 2. 保存移入明细 |
||||
|
for (int i = 0; i < dto.getLabels().size(); i++) { |
||||
|
TransitLabelDto label = dto.getLabels().get(i); |
||||
|
|
||||
|
TransDetail inDetail = new TransDetail(); |
||||
|
inDetail.setSite(dto.getSite()); |
||||
|
inDetail.setTransNo(inTransHeader.getTransNo()); |
||||
|
inDetail.setItemNo((double) i); |
||||
|
inDetail.setPartNo(label.getPartNo()); |
||||
|
inDetail.setTransQty(label.getQuantity()); |
||||
|
inDetail.setBatchNo(label.getBatchNo()); |
||||
|
inDetail.setLocationId(label.getLocationId()); |
||||
|
inDetail.setOrderRef1(dto.getTransNo()); // 关联原移库单号 |
||||
|
inDetail.setRemark("移库接收"); |
||||
|
|
||||
|
transDetailService.save(inDetail); |
||||
|
} |
||||
|
|
||||
|
// 3. 更新原移库单状态为已完成 |
||||
|
TransHeader originalHeader = transitMapper.getTransitHeader(dto.getTransNo(), dto.getSite()); |
||||
|
if (originalHeader != null) { |
||||
|
originalHeader.setStatus("COMPLETED"); |
||||
|
originalHeader.setStatusDb("COMPLETED"); |
||||
|
transHeaderService.updateById(originalHeader); |
||||
|
} |
||||
|
|
||||
|
// 4. 更新库存(这里需要调用库存服务) |
||||
|
// updateInventoryStock(dto); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 更新库存(需要根据实际的库存服务实现) |
||||
|
*/ |
||||
|
private void updateInventoryStock(TransitReceiveDto dto) { |
||||
|
// TODO: 实现库存更新逻辑 |
||||
|
// 1. 减少移出仓库库存 |
||||
|
// 2. 增加移入仓库库存 |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,78 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
|
|
||||
|
<mapper namespace="com.gaotao.modules.transit.dao.TransitMapper"> |
||||
|
|
||||
|
<!-- 获取移库头信息 --> |
||||
|
<select id="getTransitHeader" resultType="com.gaotao.modules.trans.entity.TransHeader"> |
||||
|
SELECT |
||||
|
site, |
||||
|
trans_no, |
||||
|
trans_date, |
||||
|
trans_type_db, |
||||
|
warehouse_id, |
||||
|
user_id, |
||||
|
user_name, |
||||
|
remark, |
||||
|
order_ref1, |
||||
|
status, |
||||
|
status_db, |
||||
|
order_ref2, |
||||
|
order_ref3, |
||||
|
enter_date, |
||||
|
ifs_flag |
||||
|
FROM trans_header |
||||
|
WHERE site = #{site} |
||||
|
AND trans_no = #{transNo} |
||||
|
AND trans_type_db IN ('TROUT', 'TRANSFER') -- 移库相关的事务类型 |
||||
|
</select> |
||||
|
|
||||
|
<!-- 获取移库明细 --> |
||||
|
<select id="getTransitDetails" resultType="com.gaotao.modules.trans.entity.TransDetail"> |
||||
|
SELECT |
||||
|
site, |
||||
|
trans_no, |
||||
|
item_no, |
||||
|
part_no, |
||||
|
trans_qty, |
||||
|
batch_no, |
||||
|
location_id, |
||||
|
direction, |
||||
|
order_ref1, |
||||
|
order_ref2, |
||||
|
order_ref3, |
||||
|
order_ref4, |
||||
|
order_ref5, |
||||
|
remark |
||||
|
FROM trans_detail |
||||
|
WHERE site = #{site} |
||||
|
AND trans_no = #{transNo} |
||||
|
ORDER BY item_no |
||||
|
</select> |
||||
|
|
||||
|
<!-- 根据标签获取移库明细 --> |
||||
|
<select id="getTransitDetailByLabel" resultType="com.gaotao.modules.trans.entity.TransDetail"> |
||||
|
SELECT |
||||
|
td.site, |
||||
|
td.trans_no, |
||||
|
td.item_no, |
||||
|
td.part_no, |
||||
|
td.trans_qty, |
||||
|
td.batch_no, |
||||
|
td.location_id, |
||||
|
td.direction, |
||||
|
td.order_ref1, |
||||
|
td.order_ref2, |
||||
|
td.order_ref3, |
||||
|
td.order_ref4, |
||||
|
td.order_ref5, |
||||
|
td.remark |
||||
|
FROM trans_detail td |
||||
|
INNER JOIN trans_header th ON td.site = th.site AND td.trans_no = th.trans_no |
||||
|
WHERE td.site = #{site} |
||||
|
AND td.trans_no = #{transNo} |
||||
|
AND td.order_ref1 = #{labelCode} -- 假设标签编码存储在order_ref1字段 |
||||
|
AND th.trans_type_db IN ('TROUT', 'TRANSFER') |
||||
|
</select> |
||||
|
|
||||
|
</mapper> |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue