|
|
@@ -0,0 +1,134 @@
|
|
|
+package com.uas.eis.task;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.transsion.exchange.base.dto.EntryForPOST;
|
|
|
+import com.transsion.exchange.utils.ecit.OpenApiUtil;
|
|
|
+import com.uas.eis.dao.BaseDao;
|
|
|
+import com.uas.eis.dao.SqlRowList;
|
|
|
+import com.uas.eis.entity.transsion.SupplierSecondMaterialStockVO;
|
|
|
+import com.uas.eis.utils.Configuration;
|
|
|
+import com.uas.eis.utils.StringUtil;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
+import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Component
|
|
|
+@EnableAsync
|
|
|
+@EnableScheduling
|
|
|
+public class SyncOriFactoryDeliveryCYTask {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BaseDao baseDao;
|
|
|
+ @Resource(name = "configuration")
|
|
|
+ private Configuration configuration;
|
|
|
+ @Autowired
|
|
|
+ private ObjectMapper objectMapper;
|
|
|
+
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 0/2 * * * ?")
|
|
|
+ public void syncOriFactoryDelivery() {
|
|
|
+ logger.info("sendOriFactoryDelivery-Begin:master {} ids {}");
|
|
|
+ try {
|
|
|
+ SqlRowList docMsg = baseDao.queryForRowSet(" select nvl(pd_qty-nvl(pd_acceptqty,0),0) wrkQty,tspr_uasprcode,tspr_eightcode,tspr_ninecode,to_char(pu_date,'yyyy-mm-dd') pu_date,pu_code,pd_detno, " +
|
|
|
+ " to_char(pd_delivery,'yyyy-mm-dd') pd_delivery,pd_qty,pd_qty pd_qtyreply,to_char(pd_delivery,'yyyy-mm-dd') pd_deliveryreply,'' pd_remark " +
|
|
|
+ " from purchasedetail left join purchase on pd_puid=pu_id left join transsionproduct on pd_prodcode=tspr_uasprcode " +
|
|
|
+ " where pu_statuscode = 'AUDITED' and nvl(pd_mrpstatuscode,' ')<>'FINISH' and pd_qty-nvl(pd_acceptqty,0)>0 and upper(pd_custname) in ('传音','上海传音') and nvl(tspr_uasprcode,' ') <> 'STK35F62' " +
|
|
|
+ " and nvl(TSPR_EIGHTCODE,' ')<>' ' and nvl(tspr_ENABLE,0) = -1 order by pd_prodcode,pd_puid,pd_detno");
|
|
|
+ SqlRowList rs2 = baseDao.queryForRowSet("select TO_CHAR(SYSDATE,'HH24') v_hour,TO_CHAR(SYSDATE,'MI') v_mi,TO_CHAR(SYSDATE, 'DY', 'NLS_DATE_LANGUAGE=AMERICAN') v_mon from dual");
|
|
|
+ String V_HOUR = rs2.getGeneralString("v_hour");
|
|
|
+ String V_MI = rs2.getGeneralString("v_mi");
|
|
|
+ String V_MON = rs2.getGeneralString("v_mon");
|
|
|
+ boolean XIAOMIUPLOAD = baseDao.isDBSetting("CHUANYIN", "XIAOMIUPLOAD");
|
|
|
+ if(docMsg.size()>0 && (("10".equals(V_HOUR) && "00".equals(V_MI) && "MON".equals(V_MON)) || XIAOMIUPLOAD)){
|
|
|
+ List<Map<String, Object>> docMsgResultList = docMsg.getResultList();
|
|
|
+ StringBuffer errMsg = new StringBuffer();
|
|
|
+ List<Object> docCodes = new ArrayList<>();
|
|
|
+ List<SupplierSecondMaterialStockVO> list = new ArrayList<>();
|
|
|
+ Map<String,Object> reqMap = new HashMap<>();
|
|
|
+ String prCodes = "";
|
|
|
+ for (Map<String, Object> map : docMsgResultList) {
|
|
|
+ docCodes.add(map.get("pr_code"));
|
|
|
+ logger.info("sendProd-test: id {} code {}",map.get("pr_id"),map.get("pr_code"));
|
|
|
+ // 创建SaleMaterialStockVO对象
|
|
|
+ SupplierSecondMaterialStockVO supplierSecondMaterialStockVO = new SupplierSecondMaterialStockVO.Builder()
|
|
|
+ .materialOem(StringUtil.nvl(map.get("tspr_uasprcode")," "))
|
|
|
+ .matOrderDate(StringUtil.nvl(map.get("pu_date")," "))
|
|
|
+ .orderNumber(StringUtil.nvl(map.get("pu_code")," "))
|
|
|
+ .orderItemNumber(StringUtil.nvl(map.get("pd_detno")," "))
|
|
|
+ .orderReqDate(StringUtil.nvl(map.get("pd_delivery")," "))
|
|
|
+ .orderQty(StringUtil.nvl(map.get("pd_qty")," "))
|
|
|
+ .orderCondate(StringUtil.nvl(map.get("pd_deliveryreply")," "))
|
|
|
+ .orderConQty(StringUtil.nvl(map.get("pd_qtyreply")," "))
|
|
|
+ .supplierRemark(StringUtil.nvl(map.get("pd_remark")," "))
|
|
|
+ .build();
|
|
|
+ list.add(supplierSecondMaterialStockVO);
|
|
|
+ }
|
|
|
+ reqMap.put("list",list);
|
|
|
+ logger.info("sendOriFactoryDelivery-End:master {} ids {}");
|
|
|
+ String json = null;
|
|
|
+ try{
|
|
|
+ json = objectMapper.writeValueAsString(reqMap);
|
|
|
+ logger.info("Request JSON: {}", json);
|
|
|
+ }
|
|
|
+ catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ logger.info("sendOriFactoryDelivery-Error:JSON转换失败 codes {} ",prCodes);
|
|
|
+ baseDao.execute("insert into CHUANYDOCKINGLOG(ML_ID,ML_DATE,ML_CONTENT,ML_RESULT)" +
|
|
|
+ " values(messagelog_seq.nextval,sysdate,'上传采购交期操作CY','上传失败JSON转换失败')");
|
|
|
+ //return ApiResponse.failRsp("106","JSON转换失败");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //eMsg = StringUtil.nvl(e.getMessage(),"无");
|
|
|
+ //baseDao.execute("update product set pr_sendwmsstatus='同步失败' ,pr_sendwmserr='操作:同步' where pr_code in ("+prCodes+")");
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ //接口入参,接口平台会直接将当前账号信息传入接口
|
|
|
+ //String json ="{\"elsAccount\":\"864385\"}";
|
|
|
+ //接口提供方企业应用账号
|
|
|
+ String elsAccount = "864385";
|
|
|
+ //接口标识
|
|
|
+ String interfaceCode = "SRM013";
|
|
|
+ //接口参数组装
|
|
|
+ EntryForPOST post = EntryForPOST.builder().elsAccount(elsAccount)
|
|
|
+ .businessType(interfaceCode)
|
|
|
+ .reuestData(json)
|
|
|
+ .specialSign(interfaceCode)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ JSONObject result = null;
|
|
|
+ try {
|
|
|
+ //接口调用
|
|
|
+ result = OpenApiUtil.doPost(post);
|
|
|
+ } catch (Exception e) {
|
|
|
+ jsonObject.put("message", e.getMessage());
|
|
|
+ System.out.println("error1"+e.getMessage());
|
|
|
+ }
|
|
|
+ //接口返回结果
|
|
|
+ jsonObject.put("message", result.toJSONString());
|
|
|
+ baseDao.execute("insert into CHUANYDOCKINGLOG(ML_ID,ML_DATE,ML_CONTENT,ML_RESULT)" +
|
|
|
+ " values(messagelog_seq.nextval,sysdate,'上传采购交期操作CY','上传成功')");
|
|
|
+ //return ApiResponse.successRsp("0","同步采购交期成功");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("message", e.getMessage());
|
|
|
+ baseDao.execute("insert into CHUANYDOCKINGLOG(ML_ID,ML_DATE,ML_CONTENT,ML_RESULT)" +
|
|
|
+ " values(messagelog_seq.nextval,sysdate,'上传采购交期操作CY','上传失败'"+jsonObject.getString("message")+")");
|
|
|
+ //return ApiResponse.failRsp("101",jsonObject.getString("message"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|