|
|
|
@ -2,20 +2,17 @@ package com.gaotao.modules.finishedProduct.sap.service.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.gaotao.common.constant.SysMsgConstant; |
|
|
|
import com.gaotao.common.exception.XJException; |
|
|
|
import com.gaotao.common.utils.DateUtils; |
|
|
|
import com.gaotao.common.utils.R; |
|
|
|
import com.gaotao.common.utils.RandomUtil; |
|
|
|
import com.gaotao.modules.finishedProduct.dao.CRollinfoDao; |
|
|
|
import com.gaotao.modules.finishedProduct.entity.CRollinfoEntity; |
|
|
|
import com.gaotao.modules.finishedProduct.entity.Part; |
|
|
|
import com.gaotao.modules.finishedProduct.entity.*; |
|
|
|
import com.gaotao.modules.finishedProduct.sap.dao.SapViewDao; |
|
|
|
import com.gaotao.modules.finishedProduct.sap.service.SapRollService; |
|
|
|
import com.gaotao.modules.finishedProduct.service.CRollinfoService; |
|
|
|
import com.gaotao.modules.finishedProduct.service.PartService; |
|
|
|
import com.gaotao.modules.finishedProduct.service.TransheaderService; |
|
|
|
import com.gaotao.modules.finishedProduct.service.*; |
|
|
|
import com.gaotao.modules.finishedProduct.vo.CRollInfoStorageVo; |
|
|
|
import com.gaotao.modules.report.dao.ProcedureDao; |
|
|
|
import com.gaotao.modules.schedule.mapper.ProcedureMapper; |
|
|
|
import com.gaotao.modules.sys.entity.SysUserEntity; |
|
|
|
import com.gaotao.modules.sys.service.SysMsgService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
@ -27,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
@ -34,8 +32,8 @@ import java.util.*; |
|
|
|
public class SapRollServiceImpl extends ServiceImpl<CRollinfoDao, CRollinfoEntity> implements SapRollService { |
|
|
|
|
|
|
|
private static final String SAP_SOURCE_TYPE = "SAP成品入库"; |
|
|
|
private static final String SAP_TRANS_TYPE_IN = "SOI"; |
|
|
|
private static final String SAP_TRANS_TYPE_OUT = "SOC"; |
|
|
|
private static final String SAP_TRANS_TYPE_IN = "OI"; |
|
|
|
private static final String SAP_TRANS_TYPE_OUT = "OC"; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CRollinfoService cRollinfoService; |
|
|
|
@ -43,6 +41,12 @@ public class SapRollServiceImpl extends ServiceImpl<CRollinfoDao, CRollinfoEntit |
|
|
|
@Autowired |
|
|
|
private TransheaderService transheaderService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private TransdetailService transdetailService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private TransdetailsubService transdetailsubService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private PartService partService; |
|
|
|
|
|
|
|
@ -77,6 +81,10 @@ public class SapRollServiceImpl extends ServiceImpl<CRollinfoDao, CRollinfoEntit |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public R sapRollToStorage(CRollInfoStorageVo cRollInfoStorageVo) { |
|
|
|
SysUserEntity user = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
//公共参数 |
|
|
|
String site = user.getSite(); |
|
|
|
String warehouseId = cRollInfoStorageVo.getWarehouseId(); |
|
|
|
String reasonCode = cRollInfoStorageVo.getReasonCode(); |
|
|
|
List<CRollinfoEntity> cRollinfoList = new ArrayList<>(); |
|
|
|
Integer num = (int) Math.ceil(cRollInfoStorageVo.getStorageNumber() / cRollInfoStorageVo.getRollNumber()); |
|
|
|
Double y = cRollInfoStorageVo.getStorageNumber() % cRollInfoStorageVo.getRollNumber(); |
|
|
|
@ -118,29 +126,32 @@ public class SapRollServiceImpl extends ServiceImpl<CRollinfoDao, CRollinfoEntit |
|
|
|
cRollinfoList.add(cRollinfoEntity); |
|
|
|
} |
|
|
|
|
|
|
|
transheaderService.saveTransInfo(cRollinfoList, SAP_TRANS_TYPE_IN); |
|
|
|
String transNo = saveTransInfo(cRollinfoList, warehouseId, reasonCode, SAP_TRANS_TYPE_IN); |
|
|
|
cRollinfoService.saveBatch(cRollinfoList); |
|
|
|
|
|
|
|
// TODO 调用SAP存储过程(入库) |
|
|
|
// List<Object> params = new ArrayList<>(); |
|
|
|
// params.add(...); |
|
|
|
// List<Map<String, Object>> resultList = procedureMapper.getProcedureData("存储过程名", params); |
|
|
|
// Map<String, Object> resultMap = resultList.get(0); |
|
|
|
// String resultCode = String.valueOf(resultMap.get("resultCode")); |
|
|
|
// if (!"200".equalsIgnoreCase(resultCode)) { |
|
|
|
// throw new XJException(resultMap.get("resultMsg").toString()); |
|
|
|
// } |
|
|
|
|
|
|
|
// 调用SAP存储过程(入库) |
|
|
|
List<Object> params = new ArrayList<>(); |
|
|
|
params.add(site);// |
|
|
|
params.add(transNo); |
|
|
|
List<Map<String, Object>> resultList = procedureDao.getProcedureData("P_SAP_RECEIVEPART", params); |
|
|
|
Map<String, Object> resultMap = resultList.get(0); |
|
|
|
String resultCode = String.valueOf(resultMap.get("resultCode")); |
|
|
|
if (!"200".equalsIgnoreCase(resultCode)) { |
|
|
|
throw new XJException(resultMap.get("resultMsg").toString(), 400); |
|
|
|
} |
|
|
|
return R.ok().put("inRollList", cRollinfoList); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public R sapBatchRollOutbound(List<CRollinfoEntity> cRollinfoList) { |
|
|
|
public R sapBatchRollOutbound(List<CRollinfoEntity> cRollinfoList, String reasonCode) { |
|
|
|
SysUserEntity user = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
//公共参数 |
|
|
|
String site = user.getSite(); |
|
|
|
String warehouseId = ""; |
|
|
|
if (CollectionUtils.isEmpty(cRollinfoList)) { |
|
|
|
return R.error("请扫描卷再出库"); |
|
|
|
} |
|
|
|
SysUserEntity user = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
|
|
|
|
for (CRollinfoEntity item : cRollinfoList) { |
|
|
|
CRollinfoEntity dbRoll = cRollinfoService.lambdaQuery() |
|
|
|
@ -157,9 +168,10 @@ public class SapRollServiceImpl extends ServiceImpl<CRollinfoDao, CRollinfoEntit |
|
|
|
item.setSite(user.getSite()); |
|
|
|
item.setPartno(dbRoll.getPartno()); |
|
|
|
item.setRollqty(dbRoll.getRollqty()); |
|
|
|
warehouseId = dbRoll.getWarehouseid(); |
|
|
|
} |
|
|
|
|
|
|
|
transheaderService.saveTransInfo(cRollinfoList, SAP_TRANS_TYPE_OUT); |
|
|
|
//调用方法 保存数据 |
|
|
|
String transNo = saveTransInfo(cRollinfoList, warehouseId, reasonCode, SAP_TRANS_TYPE_OUT); |
|
|
|
|
|
|
|
cRollinfoList.forEach(rollInfo -> { |
|
|
|
cRollinfoService.lambdaUpdate() |
|
|
|
@ -172,16 +184,16 @@ public class SapRollServiceImpl extends ServiceImpl<CRollinfoDao, CRollinfoEntit |
|
|
|
.update(); |
|
|
|
}); |
|
|
|
|
|
|
|
// TODO 调用SAP存储过程(出库) |
|
|
|
// List<Object> params = new ArrayList<>(); |
|
|
|
// params.add(...); |
|
|
|
// List<Map<String, Object>> resultList = procedureMapper.getProcedureData("存储过程名", params); |
|
|
|
// Map<String, Object> resultMap = resultList.get(0); |
|
|
|
// String resultCode = String.valueOf(resultMap.get("resultCode")); |
|
|
|
// if (!"200".equalsIgnoreCase(resultCode)) { |
|
|
|
// throw new XJException(resultMap.get("resultMsg").toString()); |
|
|
|
// } |
|
|
|
|
|
|
|
// 调用SAP存储过程(出库) |
|
|
|
List<Object> params = new ArrayList<>(); |
|
|
|
params.add(site); |
|
|
|
params.add(transNo); |
|
|
|
List<Map<String, Object>> resultList = procedureDao.getProcedureData("P_SAP_ISSUEPART", params); |
|
|
|
Map<String, Object> resultMap = resultList.get(0); |
|
|
|
String resultCode = String.valueOf(resultMap.get("resultCode")); |
|
|
|
if (!"200".equalsIgnoreCase(resultCode)) { |
|
|
|
throw new XJException(resultMap.get("resultMsg").toString(), 400); |
|
|
|
} |
|
|
|
return R.ok("出库成功"); |
|
|
|
} |
|
|
|
|
|
|
|
@ -194,4 +206,69 @@ public class SapRollServiceImpl extends ServiceImpl<CRollinfoDao, CRollinfoEntit |
|
|
|
} |
|
|
|
return Collections.emptyList(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public String saveTransInfo(List<CRollinfoEntity> cRollinfoList, String warehouseId, String reasonCode, String tranType) { |
|
|
|
SysUserEntity user = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
// transheader |
|
|
|
String transHeaderNo = RandomUtil.getOrderNoByAtomic(user.getSite(), tranType); |
|
|
|
Transheader herder = new Transheader(); |
|
|
|
herder.setTransno(transHeaderNo); |
|
|
|
herder.setSite(user.getSite()); |
|
|
|
herder.setTranstypeDb(tranType); |
|
|
|
herder.setUserid(user.getUsername()); |
|
|
|
herder.setUsername(user.getUserDisplay()); |
|
|
|
herder.setTransdate(Calendar.getInstance().getTime()); |
|
|
|
herder.setStatus("已录入"); |
|
|
|
String remark = ""; |
|
|
|
switch (tranType){ |
|
|
|
case "OI": |
|
|
|
remark = reasonCode; |
|
|
|
break; |
|
|
|
case "OC": |
|
|
|
remark = reasonCode; |
|
|
|
break; |
|
|
|
case "CRR": |
|
|
|
remark = "采购退货"; |
|
|
|
break; |
|
|
|
} |
|
|
|
herder.setRemark(remark); |
|
|
|
transheaderService.save(herder); |
|
|
|
// transDetail |
|
|
|
Map<String, List<CRollinfoEntity>> partGroup = cRollinfoList.stream().collect(Collectors.groupingBy((CRollinfoEntity::getPartno))); |
|
|
|
List<Transdetail> transdetailList = new ArrayList<>(); |
|
|
|
double itemNo = 0.0; |
|
|
|
for (String partNo : partGroup.keySet() ){ |
|
|
|
itemNo = itemNo+1.0; |
|
|
|
Double sumQty = partGroup.get(partNo).stream().collect(Collectors.summingDouble((CRollinfoEntity::getRollqty))); |
|
|
|
Transdetail transdetail = new Transdetail(); |
|
|
|
transdetail.setTransno(herder.getTransno()); |
|
|
|
transdetail.setSite(user.getSite()); |
|
|
|
transdetail.setPartno(partNo); |
|
|
|
transdetail.setWarehouseid(warehouseId); |
|
|
|
transdetail.setItemno(itemNo); |
|
|
|
transdetail.setTransqty(sumQty); |
|
|
|
transdetail.setBatchno("*"); |
|
|
|
transdetailList.add(transdetail); |
|
|
|
} |
|
|
|
transdetailService.saveBatch(transdetailList,1000); |
|
|
|
// transDetailSub |
|
|
|
List<Transdetailsub> transdetailsubs = new ArrayList<>(); |
|
|
|
for (int i = 0; i < cRollinfoList.size(); i++) { |
|
|
|
CRollinfoEntity cRollinfoEntity = cRollinfoList.get(i); |
|
|
|
Transdetailsub sub = new Transdetailsub(); |
|
|
|
sub.setSite(cRollinfoEntity.getSite()); |
|
|
|
sub.setSubqty(cRollinfoEntity.getRollqty()); |
|
|
|
sub.setOrderref1(cRollinfoEntity.getOrderref1() != null ? cRollinfoEntity.getOrderref1() : ""); |
|
|
|
sub.setOrderref3(cRollinfoEntity.getOrderref2() != null ? cRollinfoEntity.getOrderref2() : ""); |
|
|
|
sub.setItemno(1.0 + i); |
|
|
|
sub.setTransno(herder.getTransno()); |
|
|
|
sub.setSubno(cRollinfoEntity.getRollno()); |
|
|
|
sub.setDirection("-"); |
|
|
|
transdetailsubs.add(sub); |
|
|
|
} |
|
|
|
transdetailsubService.saveBatch(transdetailsubs,1000); |
|
|
|
return transHeaderNo; |
|
|
|
} |
|
|
|
} |