sap接口调整

highway
zhaoxiaolin 1 year ago
parent 71c9cb591d
commit dbeba66388

@ -11,6 +11,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* sap * sap
* *
@ -30,7 +32,7 @@ public interface RemoteSapService {
/**回传sap母工单**/ /**回传sap母工单**/
@PostMapping("/sap/sapCreateOrder") @PostMapping("/sap/sapCreateOrder")
public R<List<String>> SapCreateOrder(@RequestBody List<SapCreateOrder> sapCreateOrderList); public R<List<Map<String, String>>> SapCreateOrder(@RequestBody List<SapCreateOrder> sapCreateOrderList);
/**关闭订单**/ /**关闭订单**/
@PostMapping("/sap/sapCloseOrder") @PostMapping("/sap/sapCloseOrder")

@ -83,6 +83,15 @@ public class MesPrepareDetailDTO extends BaseEntity {
private String needDate; private String needDate;
private String recoil; private String recoil;
private String buyFlag; private String buyFlag;
private String parentWorkOrder;
public String getParentWorkOrder() {
return parentWorkOrder;
}
public void setParentWorkOrder(String parentWorkOrder) {
this.parentWorkOrder = parentWorkOrder;
}
public String getBuyFlag() { public String getBuyFlag() {
return buyFlag; return buyFlag;

@ -10,6 +10,7 @@ import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
import java.util.Map;
public class RemoteSapFallbackFactory implements FallbackFactory<RemoteSapService> { public class RemoteSapFallbackFactory implements FallbackFactory<RemoteSapService> {
private static final Logger log = LoggerFactory.getLogger(RemoteSapFallbackFactory.class); private static final Logger log = LoggerFactory.getLogger(RemoteSapFallbackFactory.class);
@ -33,7 +34,7 @@ public class RemoteSapFallbackFactory implements FallbackFactory<RemoteSapServic
} }
@Override @Override
public R<List<String>> SapCreateOrder(List<SapCreateOrder> sapCreateOrderList) { public R<List<Map<String, String>>> SapCreateOrder(List<SapCreateOrder> sapCreateOrderList) {
return R.fail("回传sap工单失败:" + throwable.getMessage()); return R.fail("回传sap工单失败:" + throwable.getMessage());
} }

@ -565,10 +565,10 @@ public class ProOrderServiceImpl implements IProOrderService {
if (checkResult.isSuccess()) { if (checkResult.isSuccess()) {
String info = syncImportFunc(orderList); String info = syncImportFunc(orderList);
return success("信息导入完成。其中导入失败订单:"+info); return success("信息导入完成。其中导入失败订单:"+info);
} }else{
// 校验失败
return checkResult; return checkResult;
} }
}
@Override @Override
public R syncSAPOrders() { public R syncSAPOrders() {

@ -266,22 +266,32 @@ public class ProOrderWorkorderServiceImpl implements IProOrderWorkorderService {
whiteOrder.setUpdateTime(DateUtils.getNowDate()); whiteOrder.setUpdateTime(DateUtils.getNowDate());
return proOrderWorkorderMapper.updateWhiteWorkOrder(whiteOrder); return proOrderWorkorderMapper.updateWhiteWorkOrder(whiteOrder);
} else if (whiteOrder != null && !"white".equals(whiteOrder.getProdType())) { } else if (whiteOrder != null && !"white".equals(whiteOrder.getProdType())) {
List<String> pcodes = new ArrayList<>();//一起下发用 List<String> wids = new ArrayList<>();//一起下发用
List<String> wcodes = new ArrayList<>();//领料单用 List<String> wcodes = new ArrayList<>();//领料单用
//成品的母工单//查上一级工单 List<String> ordercodes = new ArrayList<>();//关闭订单用
wids.add(whiteOrder.getWorkorderId());
wcodes.add(whiteOrder.getWorkorderCode());
ordercodes.add(whiteOrder.getOrderCode());
Boolean isTop = true; Boolean isTop = true;
//成品的母工单//查上一级工单
while(isTop) { while(isTop) {
pcodes.add(whiteOrder.getWorkorderId());
wcodes.add(whiteOrder.getWorkorderCode());
//查上一级工单 //查上一级工单
whiteOrder.setWorkorderCode(whiteOrder.getParentOrder()); whiteOrder.setWorkorderCode(whiteOrder.getParentOrder());
ProOrderWorkorder pWorkOrder = proOrderWorkorderMapper.getPWorkOrder(whiteOrder); ProOrderWorkorder pWorkOrder = proOrderWorkorderMapper.getPWorkOrder(whiteOrder);
if(pWorkOrder == null || "0".equals(pWorkOrder.getParentOrder())){ if(pWorkOrder != null ){
isTop = false; wids.add(pWorkOrder.getWorkorderId());
}else{ wcodes.add(pWorkOrder.getWorkorderCode());
ordercodes.add(pWorkOrder.getOrderCode());
}
if("0".equals(pWorkOrder.getParentOrder())){
BeanUtils.copyProperties(pWorkOrder,whiteOrder); BeanUtils.copyProperties(pWorkOrder,whiteOrder);
isTop = false;
} }
} }
//顺序母子
Collections.reverse(wids);
Collections.reverse(wcodes);
sapList = new ArrayList<>(); sapList = new ArrayList<>();
SapCreateOrder sap = new SapCreateOrder(); SapCreateOrder sap = new SapCreateOrder();
sap.setWerks(whiteOrder.getFactoryCode());//工厂编码 sap.setWerks(whiteOrder.getFactoryCode());//工厂编码
@ -301,36 +311,46 @@ public class ProOrderWorkorderServiceImpl implements IProOrderWorkorderService {
sysSapLog.setCreateTime(DateUtils.getNowDate()); sysSapLog.setCreateTime(DateUtils.getNowDate());
proOrderMapper.addSapLog(sysSapLog); proOrderMapper.addSapLog(sysSapLog);
R<List<String>> r = remoteSapService.SapCreateOrder(sapList); R<List<Map<String, String>>> r = remoteSapService.SapCreateOrder(sapList);
logger.info("sap工单回传" + r.getMsg()); logger.info("sap工单回传" + r.getMsg());
if (500 == r.getCode()) { if (500 == r.getCode()) {
logger.error("sap工单回传" + r.getMsg()); logger.error("sap工单回传" + r.getMsg());
return 0; return 0;
} }
List<String> returnCodes = r.getData(); List<Map<String, String>> returnMaps = r.getData();
List<String> returnCodes = new ArrayList<>();
for(Map<String, String> mapdto:returnMaps){
returnCodes.add(mapdto.get("LEAD_AUFNR"));
returnCodes.add(mapdto.get("AUFNR"));
}
Date updateTime = DateUtils.getNowDate(); Date updateTime = DateUtils.getNowDate();
if (!CollectionUtils.isEmpty(returnCodes)) { if (!CollectionUtils.isEmpty(returnCodes)) {
logger.info("sap工单回传sap虚拟工单号" + StringUtils.join(returnCodes, ",")); logger.info("sap工单回传sap虚拟工单号" + StringUtils.join(returnCodes, ","));
//按照母子顺序进行更新
for (int m=0;m<returnCodes.size();m++) { for (int m=0;m<returnCodes.size();m++) {
ProOrderWorkorder oworkSap = new ProOrderWorkorder(); ProOrderWorkorder oworkSap = new ProOrderWorkorder();
oworkSap.setWorkorderCodeSap(returnCodes.get(m)); oworkSap.setWorkorderCodeSap(returnCodes.get(m));
oworkSap.setWorkorderId(pcodes.get(returnCodes.size()-(m+1)));//工单编码 oworkSap.setWorkorderId(wcodes.get(m));//工单编码
oworkSap.setUpdateTime(updateTime); oworkSap.setUpdateTime(updateTime);
/**pro_order_workorder**/ /**pro_order_workorder**/
proOrderWorkorderMapper.updateWorkOrderCodeSap(oworkSap); proOrderWorkorderMapper.updateWorkOrderCodeSap(oworkSap);
} }
} }
//测试
// List<String> returnCodes = new ArrayList<>();
// returnCodes.add("000100305879");
// returnCodes.add("000100305878");
//获取领料单 //获取领料单
Collections.reverse(wcodes);
this.getMesPrepare(returnCodes,wcodes); this.getMesPrepare(returnCodes,wcodes);
//关闭订单//母订单的订单编码 //关闭订单//订单的订单编码
R closeR= remoteSapService.sapCloseOrder(whiteOrder.getOrderCode()); for(String orderCode:ordercodes){
logger.info("下发工单后关闭订单"+whiteOrder.getOrderCode()+":"+closeR.getMsg()); R closeR= remoteSapService.sapCloseOrder(orderCode);
logger.info(workorderId+"下发工单后关闭母订单"+orderCode+":"+closeR.getMsg());
}
//下达工单 //下达工单
String[] idsArrayAll = (String[])pcodes.toArray(new String[pcodes.size()]); String[] idsArrayAll = (String[])wids.toArray(new String[wids.size()]);
return proOrderWorkorderMapper.downWorkorders(idsArrayAll); return proOrderWorkorderMapper.downWorkorders(idsArrayAll);
} }
} }
@ -349,8 +369,9 @@ public class ProOrderWorkorderServiceImpl implements IProOrderWorkorderService {
} }
public void getMesPrepare(List<String> sapWorkOrders,List<String> workOrders) { public void getMesPrepare(List<String> sapWorkOrders,List<String> workOrders) {
for(String sapWorkOrder:sapWorkOrders){ Date createDate = DateUtils.getNowDate();
logger.info("获取sap领料单" + sapWorkOrder+"开始"); for (int m = 0;m<sapWorkOrders.size();m++) {
logger.info("获取sap领料单" + sapWorkOrders.get(m)+"开始");
// //添加调用sap日志 // //添加调用sap日志
// SysSapLog sysSapLog = new SysSapLog(); // SysSapLog sysSapLog = new SysSapLog();
// sysSapLog.setId(IdUtils.fastSimpleUUID()); // sysSapLog.setId(IdUtils.fastSimpleUUID());
@ -360,16 +381,13 @@ public class ProOrderWorkorderServiceImpl implements IProOrderWorkorderService {
// sysSapLog.setCreateTime(DateUtils.getNowDate()); // sysSapLog.setCreateTime(DateUtils.getNowDate());
// proOrderMapper.addSapLog(sysSapLog); // proOrderMapper.addSapLog(sysSapLog);
List<SapMaterialPreparation> sapMaterialPreparationList = remoteSapService.materialPreparation(sapWorkOrder).getData(); List<SapMaterialPreparation> sapMaterialPreparationList = remoteSapService.materialPreparation(sapWorkOrders.get(m)).getData();
if (CollectionUtils.isEmpty(sapMaterialPreparationList)) { if (CollectionUtils.isEmpty(sapMaterialPreparationList)) {
System.out.println("sap无领料单数据"); System.out.println("sap无领料单数据");
} }
//取出各领料单 //取出各领料单
List<String> orderCodes = sapMaterialPreparationList.stream().map(SapMaterialPreparation::getAUFNR).collect(Collectors.toList()); String orderCode = sapWorkOrders.get(m);
Date createDate = DateUtils.getNowDate(); logger.info("sap虚拟工单码"+orderCode);
for (int m = 0;m<orderCodes.size();m++) {
String orderCode = orderCodes.get(m);
logger.info("领料单内容:"+orderCode);
/**mes_prepare**/ /**mes_prepare**/
String mesPrepareId = IdUtils.fastSimpleUUID(); String mesPrepareId = IdUtils.fastSimpleUUID();
MesPrepareDTO mesPrepare0 = new MesPrepareDTO(); MesPrepareDTO mesPrepare0 = new MesPrepareDTO();
@ -401,6 +419,7 @@ public class ProOrderWorkorderServiceImpl implements IProOrderWorkorderService {
detail.setBuyFlag(sap.getDBSKZ());//直接采购标识 detail.setBuyFlag(sap.getDBSKZ());//直接采购标识
detail.setCreateBy(SecurityUtils.getUsername()); detail.setCreateBy(SecurityUtils.getUsername());
detail.setCreateTime(createDate); detail.setCreateTime(createDate);
detail.setParentWorkOrder(workOrders.get(0));
details.add(detail); details.add(detail);
logger.info("领料单内容detail"+sap.getRSPOS()+","+sap.getMATNR()+","+ logger.info("领料单内容detail"+sap.getRSPOS()+","+sap.getMATNR()+","+
sap.getMAKTX()+","+sap.getWERKS()+","+ sap.getLGORT()+","+ sap.getMAKTX()+","+sap.getWERKS()+","+ sap.getLGORT()+","+
@ -409,8 +428,7 @@ public class ProOrderWorkorderServiceImpl implements IProOrderWorkorderService {
); );
} }
proOrderWorkorderMapper.insertMesPrepareDetails(details); proOrderWorkorderMapper.insertMesPrepareDetails(details);
logger.info("获取sap领料单" + sapWorkOrder+"结束"); logger.info("获取sap领料单" + sapWorkOrders.get(m)+"结束");
}
} }
} }
@ -773,18 +791,11 @@ public class ProOrderWorkorderServiceImpl implements IProOrderWorkorderService {
if (splitOrderDTO.getRouteCode() != null) { if (splitOrderDTO.getRouteCode() != null) {
proOrderWorkorder.setRouteCode(splitOrderDTO.getRouteCode()); proOrderWorkorder.setRouteCode(splitOrderDTO.getRouteCode());
} }
// // 白坯工单返修-车数
// if (proOrderWorkorder.getProdType().equals("white")) {
// if (splitOrderDTO.getCarNum() != null) {
// proOrderWorkorder.setCarNum(splitOrderDTO.getCarNum());
// }
// }
proOrderWorkorderMapper.updateProOrderWorkorder(proOrderWorkorder); proOrderWorkorderMapper.updateProOrderWorkorder(proOrderWorkorder);
// 删除工单下对应批次信息 // 删除工单下对应批次信息
proOrderWorkorderBatchMapper.deleteProOrderWorkorderBatchByWorkorderId(proOrderWorkorder.getWorkorderId()); proOrderWorkorderBatchMapper.deleteProOrderWorkorderBatchByWorkorderId(proOrderWorkorder.getWorkorderId());
// System.out.println("这里是workorderCode------------》"+proOrderWorkorder.getWorkorderCode());
// 生成对应批次表 // 生成对应批次表
workBatch.setWorkorderId(proOrderWorkorder.getWorkorderId()); workBatch.setWorkorderId(proOrderWorkorder.getWorkorderId());
@ -840,13 +851,6 @@ public class ProOrderWorkorderServiceImpl implements IProOrderWorkorderService {
if (!(proOrderWorkorder.getStatus().equals("w0") || proOrderWorkorder.getStatus().equals("w1"))) { if (!(proOrderWorkorder.getStatus().equals("w0") || proOrderWorkorder.getStatus().equals("w1"))) {
return error("工单已生产,不可变更!"); return error("工单已生产,不可变更!");
} }
// // 白坯工单所在湿料计划下发不允许变更
// if (proOrderWorkorder.getProdType().equals("white")) {
// ProWetMaterialPlan plan = proWetMaterialPlanMapper.selectProWetMaterialPlanByWorkId(proOrderWorkorder.getWorkorderId());
// if (plan != null) {
// return error("工单所在湿料计划已下发,不允许变更!");
// }
// }
return success(); return success();
} }
@ -1081,5 +1085,12 @@ public class ProOrderWorkorderServiceImpl implements IProOrderWorkorderService {
} }
return success("变更成功"); return success("变更成功");
} }
public static void main(String args[]){
List<String> wcodes =new ArrayList<>();
wcodes.add("aaa");
wcodes.add("bbb");
wcodes.add("ccc");
Collections.reverse(wcodes);
System.out.println(StringUtils.join(wcodes, ","));
}
} }

@ -457,13 +457,13 @@
INSERT INTO mes_prepare_detail ( INSERT INTO mes_prepare_detail (
record_id,prepare_id,material_code,material_name,unit, record_id,prepare_id,material_code,material_name,unit,
quantity,create_by,create_time,factory_code,status, quantity,create_by,create_time,factory_code,status,
locator,need_date,recoil,fund_quanlity,buy_flag locator,need_date,recoil,fund_quanlity,buy_flag,parent_work_order
)VALUES )VALUES
<foreach collection="list" item="d" index="index" separator=","> <foreach collection="list" item="d" index="index" separator=",">
( (
#{d.recordId},#{d.prepareId},#{d.materialCode},#{d.materailName},#{d.unit}, #{d.recordId},#{d.prepareId},#{d.materialCode},#{d.materailName},#{d.unit},
#{d.quantity},#{d.createBy},#{d.createTime},#{d.factoryCode},#{d.status}, #{d.quantity},#{d.createBy},#{d.createTime},#{d.factoryCode},#{d.status},
#{d.locator},#{d.needDate},#{d.recoil},#{d.fundQuanlity},#{d.buyFlag} #{d.locator},#{d.needDate},#{d.recoil},#{d.fundQuanlity},#{d.buyFlag},#{d.parentWorkOrder}
) )
</foreach> </foreach>

Loading…
Cancel
Save