| 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 lombok.extern.slf4j.Slf4j; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.beans.factory.annotation.Value; | 
| import org.springframework.scheduling.annotation.Scheduled; | 
| import org.springframework.stereotype.Component; | 
| import org.springframework.transaction.annotation.Transactional; | 
|   | 
| import java.util.ArrayList; | 
| import java.util.HashMap; | 
| import java.util.List; | 
|   | 
| /** | 
|  * 入库单据 | 
|  */ | 
| @Slf4j | 
| @Component | 
| public class ERPInHedTBScheduler { | 
|   | 
|     @Value("${erp.enabled}") | 
|     private Boolean erpEnabled; | 
|   | 
|   | 
|     @Autowired | 
|     private ERPInOrOutService inMS; | 
|   | 
|   | 
|     @Autowired | 
|     private ErpSqlServer erpSqlServer; | 
|   | 
|   | 
|     //@Transactional(rollbackFor = Throwable.class) | 
|     @Scheduled(cron = "${erp.refreshtime}") | 
|     public void InHedTBScheduler() { | 
|         //log.info("InHedTBScheduler开始了" | 
|         // 7); | 
|         if (!erpEnabled) return; | 
|         String sqlInHed = "select * from erp_InHedTB where LKName='高霖立库'"; | 
|         List<InHedTB> inHeds = erpSqlServer.select(sqlInHed, InHedTB.class); | 
|         if (!inHeds.isEmpty()) { | 
|             for (InHedTB inHed : inHeds) { | 
|                 if (!Cools.isEmpty(inHed.getTemp3()) && inHed.getTemp3().equals("fault")) { | 
|                     //continue; | 
|                 } | 
|                 HashMap<String, String> condition = new HashMap<>(); | 
|                 condition.put("bill_no", "'" + inHed.getBillNo() + "'"); | 
|                 List<InDetTB> inDetTBS = erpSqlServer.selectList(InDetTB.class, condition); | 
|                 HashMap<String, Object> hedAndDet = new HashMap<>(); | 
|                 hedAndDet.put("hed", inHed); | 
|                 hedAndDet.put("det", inDetTBS); | 
|                 if (inDetTBS == null || inDetTBS.isEmpty()) { | 
|                     continue; | 
|                 } | 
|                 try { | 
|                     inMS.createInOrder(inHed, inDetTBS); | 
|                     log.info("入库单据成功,{}", inHed); | 
|                     move(hedAndDet); | 
|                 } catch (Exception e) { | 
|                     log.info(e.getMessage()); | 
|                     //e.printStackTrace(); | 
|                     String sql = "UPDATE erp_InHedTB SET Temp3 = 'fault' WHERE bill_no = '" + 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"); | 
|         HashMap<String, String> condition = new HashMap<>(); | 
|         condition.put("bill_no", "'" + hed.getBillNo() + "'"); | 
|         erpSqlServer.delete(InHedTB.class, condition); | 
|         for (InDetTB det : dets) { | 
|             HashMap<String, String> condition2 = new HashMap<>(); | 
|             condition2.put("bill_no", "'" + det.getBillNo() + "'"); | 
|             condition2.put("i_no", String.valueOf(det.getINO())); | 
|             erpSqlServer.delete(InDetTB.class, condition2); | 
|         } | 
|   | 
|     } | 
| } |