|
|
|
@ -11,11 +11,16 @@ import com.gaotao.modules.other.entity.OtherInboundRequestDto; |
|
|
|
import com.gaotao.modules.other.entity.OtherTransactionIfsDto; |
|
|
|
import com.gaotao.modules.other.service.OtherInboundService; |
|
|
|
import com.gaotao.modules.sys.entity.SysUserEntity; |
|
|
|
import com.gaotao.modules.trans.entity.TransCommonRequestDto; |
|
|
|
import com.gaotao.modules.trans.entity.TransCommonSubDto; |
|
|
|
import com.gaotao.modules.other.entity.OtherInboundTransRequestDto; |
|
|
|
import com.gaotao.modules.other.entity.OtherInboundTransSubDto; |
|
|
|
import com.gaotao.modules.trans.entity.TransDetail; |
|
|
|
import com.gaotao.modules.trans.entity.TransDetailSub; |
|
|
|
import com.gaotao.modules.trans.entity.TransHeader; |
|
|
|
import com.gaotao.modules.trans.entity.TransNoControl; |
|
|
|
import com.gaotao.modules.trans.dao.TransDetailMapper; |
|
|
|
import com.gaotao.modules.trans.service.TransDetailSubService; |
|
|
|
import com.gaotao.modules.trans.service.TransHeaderService; |
|
|
|
import com.gaotao.modules.trans.service.TransNoControlService; |
|
|
|
import com.gaotao.modules.warehouse.entity.Location; |
|
|
|
import com.gaotao.modules.warehouse.service.InventoryStockService; |
|
|
|
import com.gaotao.modules.warehouse.service.LocationService; |
|
|
|
@ -26,9 +31,8 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* 其它入库服务实现类 |
|
|
|
@ -39,6 +43,15 @@ public class OtherInboundServiceImpl implements OtherInboundService { |
|
|
|
@Autowired |
|
|
|
private TransHeaderService transHeaderService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private TransNoControlService transNoControlService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private TransDetailMapper transDetailMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private TransDetailSubService transDetailSubService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private HandlingUnitService handlingUnitService; |
|
|
|
|
|
|
|
@ -63,15 +76,15 @@ public class OtherInboundServiceImpl implements OtherInboundService { |
|
|
|
// 2. 验证HandlingUnit |
|
|
|
List<HandlingUnit> handlingUnits = validateHandlingUnits(dto); |
|
|
|
|
|
|
|
// 3. 构建TransCommonRequestDto |
|
|
|
TransCommonRequestDto transRequest = buildTransCommonRequest(dto, currentUser); |
|
|
|
// 3. 构建OtherInboundTransRequestDto |
|
|
|
OtherInboundTransRequestDto transRequest = buildOtherInboundTransRequest(dto, currentUser); |
|
|
|
|
|
|
|
// 4. 构建subList(从HandlingUnit获取信息) |
|
|
|
List<TransCommonSubDto> subList = buildSubList(handlingUnits, dto); |
|
|
|
List<OtherInboundTransSubDto> subList = buildOtherInboundSubList(handlingUnits, dto); |
|
|
|
transRequest.setSubList(subList); |
|
|
|
|
|
|
|
// 5. 调用通用的出入库方法生成记录和变更库存 |
|
|
|
List<TransDetail> detailList = transHeaderService.genTransAndChangeInventoryStock(transRequest, "IN"); |
|
|
|
// 5. 调用独立的其它入库方法生成记录和变更库存 |
|
|
|
List<TransDetail> detailList = genOtherInboundTransAndChangeStock(transRequest, "IN"); |
|
|
|
|
|
|
|
// 6. 调用IFS接口同步入库信息 |
|
|
|
// for (TransDetail detail : detailList) { |
|
|
|
@ -109,35 +122,6 @@ public class OtherInboundServiceImpl implements OtherInboundService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<OtherInboundHistoryDto> getOtherInboundHistory(String site) { |
|
|
|
// 查询其它入库的历史记录 |
|
|
|
// 通过TransHeader查询transType为"OI"的记录 |
|
|
|
try { |
|
|
|
// 这里应该通过Mapper查询数据库 |
|
|
|
// 暂时返回模拟数据,实际项目中需要实现具体的查询逻辑 |
|
|
|
List<OtherInboundHistoryDto> historyList = new ArrayList<>(); |
|
|
|
|
|
|
|
// 可以添加一些模拟数据用于测试 |
|
|
|
OtherInboundHistoryDto history1 = new OtherInboundHistoryDto(); |
|
|
|
history1.setTransNo("OI" + new SimpleDateFormat("yyMMddHHmmss").format(new Date()) + "001"); |
|
|
|
history1.setPartNo("P001-BOLT-M8"); |
|
|
|
history1.setPartDesc("M8螺栓 不锈钢材质"); |
|
|
|
history1.setInboundQty(new BigDecimal("250")); |
|
|
|
history1.setTargetLocationId("A01-01-01"); |
|
|
|
history1.setOperatorName("张三"); |
|
|
|
history1.setInboundReason("其它入库测试"); |
|
|
|
history1.setInboundDate(new Date()); |
|
|
|
history1.setSite(site); |
|
|
|
|
|
|
|
historyList.add(history1); |
|
|
|
|
|
|
|
return historyList; |
|
|
|
} catch (Exception e) { |
|
|
|
throw new XJException("查询其它入库历史失败: " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 验证目标库位 |
|
|
|
*/ |
|
|
|
@ -186,35 +170,28 @@ public class OtherInboundServiceImpl implements OtherInboundService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 构建TransCommonRequestDto |
|
|
|
* 构建OtherInboundTransRequestDto |
|
|
|
*/ |
|
|
|
private TransCommonRequestDto buildTransCommonRequest(OtherInboundRequestDto dto, SysUserEntity currentUser) { |
|
|
|
TransCommonRequestDto transRequest = new TransCommonRequestDto(); |
|
|
|
private OtherInboundTransRequestDto buildOtherInboundTransRequest(OtherInboundRequestDto dto, SysUserEntity currentUser) { |
|
|
|
OtherInboundTransRequestDto transRequest = new OtherInboundTransRequestDto(); |
|
|
|
transRequest.setSite(dto.getSite()); |
|
|
|
transRequest.setTransType("OI"); // 其它入库类型 |
|
|
|
transRequest.setStatus("C"); // 完成状态 |
|
|
|
|
|
|
|
// 构建备注信息 |
|
|
|
StringBuilder remark = new StringBuilder("其它入库"); |
|
|
|
if (dto.getInboundReason() != null && !dto.getInboundReason().trim().isEmpty()) { |
|
|
|
remark.append(" - ").append(dto.getInboundReason()); |
|
|
|
} |
|
|
|
remark.append(" - 操作员: ").append(dto.getOperatorName()); |
|
|
|
remark.append(" - 操作时间: ").append(dto.getOperateTime()); |
|
|
|
|
|
|
|
transRequest.setRemark(remark.toString()); |
|
|
|
|
|
|
|
// 构建备注信息 入库原因 |
|
|
|
transRequest.setRemark(dto.getInboundReason()); |
|
|
|
|
|
|
|
return transRequest; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 构建subList |
|
|
|
*/ |
|
|
|
private List<TransCommonSubDto> buildSubList(List<HandlingUnit> handlingUnits, OtherInboundRequestDto dto) { |
|
|
|
List<TransCommonSubDto> subList = new ArrayList<>(); |
|
|
|
private List<OtherInboundTransSubDto> buildOtherInboundSubList(List<HandlingUnit> handlingUnits, OtherInboundRequestDto dto) { |
|
|
|
List<OtherInboundTransSubDto> subList = new ArrayList<>(); |
|
|
|
|
|
|
|
for (HandlingUnit hu : handlingUnits) { |
|
|
|
TransCommonSubDto subDto = new TransCommonSubDto(); |
|
|
|
OtherInboundTransSubDto subDto = new OtherInboundTransSubDto(); |
|
|
|
subDto.setPartNo(hu.getPartNo()); |
|
|
|
subDto.setSubNo(hu.getUnitId()); |
|
|
|
subDto.setBatchNo(hu.getBatchNo()); |
|
|
|
@ -230,6 +207,137 @@ public class OtherInboundServiceImpl implements OtherInboundService { |
|
|
|
return subList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 其它入库独立的事务生成和库存变更方法 |
|
|
|
*/ |
|
|
|
@Transactional |
|
|
|
public List<TransDetail> genOtherInboundTransAndChangeStock(OtherInboundTransRequestDto dto, String fangxiang) { |
|
|
|
SysUserEntity currentUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
String direction = ""; |
|
|
|
if("OUT".equals(fangxiang)){ |
|
|
|
direction = "-"; |
|
|
|
}else{ |
|
|
|
direction = "+"; |
|
|
|
} |
|
|
|
|
|
|
|
//添加出入库header信息 |
|
|
|
TransNoControl transNo = transNoControlService.getTransNo(dto.getSite(), dto.getTransType(), 8); |
|
|
|
TransHeader transHeader = new TransHeader(); |
|
|
|
transHeader.setSite(dto.getSite()); |
|
|
|
transHeader.setTransNo(transNo.getNewTransNo()); |
|
|
|
transHeader.setTransDate(new Date()); |
|
|
|
transHeader.setTransTypeDb(dto.getTransType()); |
|
|
|
|
|
|
|
transHeader.setWarehouseId(dto.getWarehouseId()); |
|
|
|
transHeader.setUserId(currentUser.getUserId().toString()); |
|
|
|
transHeader.setUserName(currentUser.getUserDisplay()); |
|
|
|
transHeader.setRemark(dto.getRemark()); |
|
|
|
|
|
|
|
transHeader.setStatus(dto.getStatus()); |
|
|
|
transHeader.setStatusDb(dto.getStatus()); |
|
|
|
transHeader.setOrderRef1(dto.getWorkOrderNo()); |
|
|
|
transHeaderService.save(transHeader); |
|
|
|
|
|
|
|
List<TransDetail> detailList = new ArrayList<>(); |
|
|
|
List<TransDetailSub> detailSubs = new ArrayList<>(); |
|
|
|
|
|
|
|
//保存sub |
|
|
|
for (OtherInboundTransSubDto subDto : dto.getSubList()){ |
|
|
|
TransDetailSub detailSub = new TransDetailSub(); |
|
|
|
detailSub.setSite(dto.getSite()); |
|
|
|
detailSub.setTransNo(transHeader.getTransNo()); |
|
|
|
detailSub.setItemNo(subDto.getItemNo()); |
|
|
|
detailSub.setSubNo(subDto.getSubNo()); |
|
|
|
detailSub.setSubQty(Double.valueOf(subDto.getTransQty())); |
|
|
|
detailSub.setDirection(subDto.getDirection()); |
|
|
|
detailSub.setPartNo(subDto.getPartNo()); |
|
|
|
detailSub.setBatchNo(subDto.getBatchNo()); |
|
|
|
detailSub.setLocationId(subDto.getLocationId()); |
|
|
|
detailSub.setOrderRef3(subDto.getWdrNo()); |
|
|
|
detailSub.setOrderRef4(subDto.getWarehouseId()); |
|
|
|
|
|
|
|
// 更新HandlingUnit状态 |
|
|
|
HandlingUnit handlingUnit = handlingUnitService.lambdaQuery() |
|
|
|
.eq(HandlingUnit::getSite, dto.getSite()) |
|
|
|
.eq(HandlingUnit::getUnitId, subDto.getSubNo()) |
|
|
|
.one(); |
|
|
|
|
|
|
|
if (handlingUnit != null) { |
|
|
|
if("OUT".equals(fangxiang)){ |
|
|
|
handlingUnit.setInStockFlag("N"); |
|
|
|
}else{ |
|
|
|
handlingUnit.setInStockFlag("Y"); |
|
|
|
// 入库时更新库位到目标库位 |
|
|
|
handlingUnit.setLocationId(subDto.getLocationId()); |
|
|
|
} |
|
|
|
handlingUnit.setModifiedDate(new Date()); |
|
|
|
handlingUnit.setModifiedBy(currentUser.getUserDisplay()); |
|
|
|
handlingUnitService.updateById(handlingUnit); |
|
|
|
} |
|
|
|
|
|
|
|
detailSubs.add(detailSub); |
|
|
|
} |
|
|
|
|
|
|
|
//总计sub数量添加到list |
|
|
|
Map<List<String>, Double> collect = detailSubs.stream().collect( |
|
|
|
Collectors.groupingBy(item -> Arrays.asList( |
|
|
|
item.getSite(), |
|
|
|
item.getPartNo(), |
|
|
|
item.getBatchNo(), |
|
|
|
item.getLocationId(), |
|
|
|
item.getOrderRef3(), |
|
|
|
item.getOrderRef4() |
|
|
|
), Collectors.summingDouble(TransDetailSub::getSubQty))); |
|
|
|
|
|
|
|
Double index = 1.0; |
|
|
|
for (Map.Entry<List<String>, Double> entry : collect.entrySet()) { |
|
|
|
List<String> key = entry.getKey(); |
|
|
|
Double totalQty = entry.getValue(); |
|
|
|
|
|
|
|
TransDetail detail = new TransDetail(); |
|
|
|
detail.setSite(dto.getSite()); |
|
|
|
detail.setTransNo(transHeader.getTransNo()); |
|
|
|
detail.setItemNo(index); |
|
|
|
detail.setPartNo(key.get(1)); |
|
|
|
detail.setBatchNo(key.get(2)); |
|
|
|
detail.setLocationId(key.get(3)); |
|
|
|
detail.setWdrNo(key.get(4)); |
|
|
|
detail.setOrderRef4(key.get(5)); |
|
|
|
detail.setTransQty(new BigDecimal(totalQty)); |
|
|
|
detail.setDirection(direction); |
|
|
|
detailList.add(detail); |
|
|
|
index++; |
|
|
|
} |
|
|
|
transDetailMapper.batchInsert(detailList); |
|
|
|
|
|
|
|
//回写itemNo |
|
|
|
for (TransDetailSub sub : detailSubs){ |
|
|
|
for (int i = 0; i < detailList.size(); i++){ |
|
|
|
if(detailList.get(i).getSite().equals(sub.getSite()) |
|
|
|
&& detailList.get(i).getPartNo().equals(sub.getPartNo()) |
|
|
|
&& detailList.get(i).getBatchNo().equals(sub.getBatchNo()) |
|
|
|
&& detailList.get(i).getLocationId().equals(sub.getLocationId()) |
|
|
|
&& detailList.get(i).getWdrNo().equals(sub.getOrderRef3()) |
|
|
|
&& detailList.get(i).getOrderRef4().equals(sub.getOrderRef4()) |
|
|
|
){ |
|
|
|
sub.setItemNo(detailList.get(i).getItemNo()); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
for (TransDetailSub sub : detailSubs){ |
|
|
|
transDetailSubService.save(sub); |
|
|
|
} |
|
|
|
|
|
|
|
for(TransDetail detail : detailList){ |
|
|
|
// 变更库存 |
|
|
|
inventoryStockService.changeInventoryStock(detail.getSite(), detail.getOrderRef4(), detail.getPartNo(), |
|
|
|
detail.getBatchNo(), detail.getLocationId(), detail.getTransQty(), detail.getWdrNo(), fangxiang); |
|
|
|
} |
|
|
|
|
|
|
|
return detailList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 更新HandlingUnit状态 |
|
|
|
*/ |
|
|
|
|