package com.zy.third.erp.task; import com.zy.common.service.erp.ErpSqlServer; import com.zy.third.erp.entity.InCancelTB; 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.HashMap; import java.util.List; @Slf4j @Component public class ERPInCancelScheduler { @Value("${erp.enabled}") private Boolean erpEnabled; @Autowired private ERPInOrOutCancelService inMS; @Autowired private ErpSqlServer erpSqlServer; @Transactional(rollbackFor = Throwable.class) //@Scheduled(cron = "${erp.refreshtime}") public void InCancelScheduler() { if (!erpEnabled) return; String sqlInCancelTB = "select * from erp_InCancelTB where LKName='中扬二期'"; List ins = erpSqlServer.select(sqlInCancelTB, InCancelTB.class); for (InCancelTB in : ins) { com.zy.third.lk.entity.InCancelTB lkCancel = inMS.tryCancel(in.getBillNo()); if (lkCancel != null) { HashMap condition = new HashMap<>(); condition.put("BillNo", "'" + in.getBillNo() + "'"); int delete = erpSqlServer.delete(InCancelTB.class, condition); if (delete > 0) { log.info("将入库取消通知单删除成功,{}", lkCancel.getBillNo()); } else { log.error("将入库取消通知单删除失败,{}", lkCancel.getBillNo()); } HashMap content = new HashMap<>(); content.put("BillNo", "'" + lkCancel.getBillNo() + "'"); content.put("opFlag", lkCancel.getOpFlag()); int insert = erpSqlServer.insert(com.zy.third.lk.entity.InCancelTB.class, content); if (insert > 0) { log.info("将入库取消通知单写入成功,{}", lkCancel.getBillNo()); } else { log.error("将入库取消通知单写入失败,{}", lkCancel.getBillNo()); } } else { log.error("将入库取消通知单写入失败"); } } } }