|  |  | 
 |  |  | package com.zy.third.erp.task; | 
 |  |  |  | 
 |  |  | import com.core.common.Cools; | 
 |  |  | import com.zy.common.service.erp.ErpSqlServer; | 
 |  |  | import com.zy.third.erp.entity.InDetTB; | 
 |  |  | import com.zy.third.erp.entity.InHedTB; | 
 |  |  | import com.zy.third.erp.entity.OutDetTB; | 
 |  |  | import com.zy.third.erp.entity.OutHedTB; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.beans.factory.annotation.Value; | 
 |  |  | import org.springframework.scheduling.annotation.Async; | 
 |  |  | import org.springframework.scheduling.annotation.Scheduled; | 
 |  |  | import org.springframework.stereotype.Component; | 
 |  |  | import org.springframework.transaction.annotation.Transactional; | 
 |  |  | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * 入库单据 | 
 |  |  |  */@Slf4j | 
 |  |  |  */ | 
 |  |  | @Slf4j | 
 |  |  | @Component | 
 |  |  | public class ERPOutHedTBScheduler { | 
 |  |  |  | 
 |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private ERPInOrOutTBSchedulerMS inMS; | 
 |  |  |     private ERPInOrOutService inMS; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private ErpSqlServer erpSqlServer; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     //@Transactional(rollbackFor = Throwable.class) | 
 |  |  |     @Scheduled(cron = "${erp.refreshtime}") | 
 |  |  |     @Async("orderThreadPool") | 
 |  |  |     public void OutHedTBScheduler() { | 
 |  |  |         log.info("OutHedTBScheduler开始了"); | 
 |  |  |         //log.info("OutHedTBScheduler开始了"); | 
 |  |  |         if (!erpEnabled) return; | 
 |  |  |         String sqlInHed = "select * from erp_OutHedTB where LKName='中扬二期'"; | 
 |  |  |         List<InHedTB> inHeds = erpSqlServer.select(sqlInHed, InHedTB.class); | 
 |  |  |         if (inHeds.size() > 0) { | 
 |  |  |             for (InHedTB inHed : inHeds) { | 
 |  |  |                 System.out.println(inHed); | 
 |  |  |         List<OutHedTB> inHeds = erpSqlServer.select(sqlInHed, OutHedTB.class); | 
 |  |  |         if (!inHeds.isEmpty()) { | 
 |  |  |             for (OutHedTB inHed : inHeds) { | 
 |  |  |                 if (!Cools.isEmpty(inHed.getTemp3()) && inHed.getTemp3().equals("fault")) { | 
 |  |  |                     //continue; | 
 |  |  |                 } | 
 |  |  |                 HashMap<String, String> condition = new HashMap<>(); | 
 |  |  |                 condition.put("BillNo", "'" + inHed.getBillNo() + "'"); | 
 |  |  |                 List<InDetTB> inDetTBS = erpSqlServer.selectList(InDetTB.class, condition); | 
 |  |  |                 List<OutDetTB> inDetTBS = erpSqlServer.selectList(OutDetTB.class, condition); | 
 |  |  |                 HashMap<String, Object> hedAndDet = new HashMap<>(); | 
 |  |  |                 hedAndDet.put("hed", inHed); | 
 |  |  |                 hedAndDet.put("det", inDetTBS); | 
 |  |  |                 boolean result = inMS.createOrder(inHed, inDetTBS); | 
 |  |  |                 if (result) { | 
 |  |  |                 if (inDetTBS == null || inDetTBS.isEmpty()) { | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  |                 try { | 
 |  |  |                     inMS.createOutOrder(inHed, inDetTBS); | 
 |  |  |                     log.info("出库单据成功,{}", inHed); | 
 |  |  |                     move(hedAndDet); | 
 |  |  |                 } else { | 
 |  |  |                     String sql = "UPDATE erp_OutHedTB SET Temp3 = ‘fault’ WHERE BillNo = '" + inHed.getBillNo() + "'"; | 
 |  |  |                 } catch (Exception e) { | 
 |  |  |                     log.info(e.getMessage()); | 
 |  |  | //                    e.printStackTrace(); | 
 |  |  |                     String sql = "UPDATE erp_OutHedTB SET Temp3 = 'fault' WHERE BillNo = '" + inHed.getBillNo() + "'"; | 
 |  |  |                     erpSqlServer.update(sql); | 
 |  |  | // | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Transactional | 
 |  |  |     @Transactional(rollbackFor = Throwable.class) | 
 |  |  |     public void OutHedTBScheduler(String orderNo) { | 
 |  |  |         //log.info("OutHedTBScheduler开始了"); | 
 |  |  |         if (!erpEnabled) return; | 
 |  |  |         String sqlInHed = "select * from erp_OutHedTB where LKName='中扬二期' and BillNo = '" + orderNo + "'"; | 
 |  |  |         List<OutHedTB> inHeds = erpSqlServer.select(sqlInHed, OutHedTB.class); | 
 |  |  |         if (!inHeds.isEmpty()) { | 
 |  |  |             for (OutHedTB inHed : inHeds) { | 
 |  |  |                 if (!Cools.isEmpty(inHed.getTemp3()) && inHed.getTemp3().equals("fault")) { | 
 |  |  |                     //continue; | 
 |  |  |                 } | 
 |  |  |                 HashMap<String, String> condition = new HashMap<>(); | 
 |  |  |                 condition.put("BillNo", "'" + inHed.getBillNo() + "'"); | 
 |  |  |                 List<OutDetTB> inDetTBS = erpSqlServer.selectList(OutDetTB.class, condition); | 
 |  |  |                 HashMap<String, Object> hedAndDet = new HashMap<>(); | 
 |  |  |                 hedAndDet.put("hed", inHed); | 
 |  |  |                 hedAndDet.put("det", inDetTBS); | 
 |  |  |                 try { | 
 |  |  |                     inMS.createOutOrder(inHed, inDetTBS); | 
 |  |  |                     log.info("出库单据成功,{}", inHed); | 
 |  |  |                     move(hedAndDet); | 
 |  |  |                 } catch (Exception e) { | 
 |  |  |                     log.info(e.getMessage()); | 
 |  |  | //                    e.printStackTrace(); | 
 |  |  |                     String sql = "UPDATE erp_OutHedTB SET Temp3 = 'fault' WHERE BillNo = '" + inHed.getBillNo() + "'"; | 
 |  |  |                     erpSqlServer.update(sql); | 
 |  |  | // | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Transactional(rollbackFor = Throwable.class) | 
 |  |  |     public void move(HashMap<String, Object> hedAndDet) { | 
 |  |  |         InHedTB hed = (InHedTB) hedAndDet.get("hed"); | 
 |  |  |         ArrayList<InDetTB> dets = (ArrayList<InDetTB>) hedAndDet.get("det"); | 
 |  |  |         OutHedTB hed = (OutHedTB) hedAndDet.get("hed"); | 
 |  |  |         ArrayList<OutDetTB> dets = (ArrayList<OutDetTB>) hedAndDet.get("det"); | 
 |  |  |         HashMap<String, String> condition = new HashMap<>(); | 
 |  |  |         condition.put("BillNo", "'" + hed.getBillNo() + "'"); | 
 |  |  |         erpSqlServer.delete(InHedTB.class, condition); | 
 |  |  |  | 
 |  |  |         for (InDetTB det : dets) { | 
 |  |  |         erpSqlServer.delete(OutHedTB.class, condition); | 
 |  |  |         for (OutDetTB det : dets) { | 
 |  |  |             HashMap<String, String> condition2 = new HashMap<>(); | 
 |  |  |             condition2.put("BillNo", "'" + det.getBillNo() + "'"); | 
 |  |  |             condition2.put("iNo", String.valueOf(det.getINO())); | 
 |  |  |             erpSqlServer.delete(InDetTB.class, condition2); | 
 |  |  |  | 
 |  |  |             erpSqlServer.delete(OutDetTB.class, condition2); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |     } |