WMSUploadTask.java 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package com.uas.eis.task;
  2. import com.uas.eis.dao.BaseDao;
  3. import com.uas.eis.dao.SqlRowList;
  4. import com.uas.eis.sdk.entity.ApiResult;
  5. import com.uas.eis.service.DocCommonService;
  6. import com.uas.eis.service.ERPService;
  7. import com.uas.eis.utils.StringUtil;
  8. import org.slf4j.Logger;
  9. import org.slf4j.LoggerFactory;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.scheduling.annotation.EnableAsync;
  12. import org.springframework.scheduling.annotation.EnableScheduling;
  13. import org.springframework.scheduling.annotation.Scheduled;
  14. import org.springframework.stereotype.Component;
  15. import java.util.Map;
  16. @Component
  17. @EnableAsync
  18. @EnableScheduling
  19. public class WMSUploadTask {
  20. private final Logger logger = LoggerFactory.getLogger(this.getClass());
  21. @Autowired
  22. private BaseDao baseDao;
  23. @Autowired
  24. private DocCommonService docCommonService;
  25. @Autowired
  26. private ERPService erpService;
  27. @Scheduled(cron = "0 0/2 * * * ?")
  28. public void uploadfxML() {
  29. logger.info("uploadfxML-begin");
  30. //需要调用三次对接方法
  31. String[] masterList = new String[]{"YUEJH", "AIFL", "YJH_HK"};
  32. for (String master : masterList) {
  33. logger.info("uploadfxML-begin-master {}",master);
  34. String emCode = "ADMIN";
  35. SqlRowList toSendList = baseDao.queryForRowSet("select pi_id,pi_inoutno,pi_class,ds_table,nvl(pi_sendwmserr_count,0) pi_sendwmserr_count from "+master+".prodinout left join documentsetup on ds_name = pi_class " +
  36. "where pi_status ='未过账' and PI_WMSORDERTYPE is not null and nvl(PI_SENDWMSFLAG,0) = 0 and ds_inorout in ('-IN','OUT') and PI_SENDWMSERR IS NOT NULL AND NVL(PI_SENDWMSERR_COUNT,0)<5 " +
  37. "order by pi_id");
  38. if(toSendList.hasNext()){
  39. while (toSendList.next()){
  40. String id = String.valueOf(toSendList.getObject("pi_id"));
  41. String inoutno = String.valueOf(toSendList.getObject("pi_inoutno"));
  42. String caller = toSendList.getGeneralString("ds_table");
  43. Integer errCount = toSendList.getGeneralInt("pi_sendwmserr_count");
  44. logger.info("uploadfxML-Upload:caller {} id {} code {}",caller,id,inoutno);
  45. // 调用待测方法
  46. Map<String, Object> result = erpService.sendIO(master, id, emCode,caller);
  47. // System.out.println("result:"+result.toString());
  48. if (result.get("success") != null && "true".equals(result.get("success").toString())) {
  49. baseDao.execute("update "+master+".prodinout set "+(StringUtil.hasText(result.get("OrderId"))?"pi_wmsordercode='"+result.get("OrderId")+"',":"")+"pi_sendwmsstatus='同步成功' ,PI_SENDWMSERR_COUNT=0,pi_sendwmserr=null,pi_sendwmsflag=-1 where pi_id = "+id);
  50. }else{
  51. String message = result.get("message") == null ? "同步失败" : result.get("message").toString().replaceAll("'", "''");
  52. baseDao.execute("update "+master+".prodinout set pi_sendwmsstatus='同步失败',PI_SENDWMSERR_COUNT=NVL(PI_SENDWMSERR_COUNT,0)+1,pi_sendwmserr=('" + message + "') where pi_id = " + id);
  53. if(errCount == 4){
  54. StringBuffer msg = new StringBuffer();
  55. msg.append("账套:").append(master).append(",").append(toSendList.getGeneralString("pi_class"))
  56. .append("[").append(inoutno).append("]")
  57. .append("对接WMS失败已达5次,请确认失败原因。");
  58. docCommonService.sendErrToRobot("263a7170-3197-4ff5-8a29-be42b646a546",msg.toString());
  59. }
  60. }
  61. logger.info("uploadfxML-Upload:caller {} id {} Upload res {}",caller,id,result.toString());
  62. }
  63. //
  64. }
  65. logger.info("uploadfxML-End-master {}",master);
  66. }
  67. logger.info("uploadfxML-End");
  68. }
  69. }