|
|
@@ -0,0 +1,165 @@
|
|
|
+package com.dk.mnls_mp.service.mnls;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.dk.mnls_mp.constant.Constant;
|
|
|
+import com.dk.mnls_mp.infrastructure.base.ResponseCodeEnum;
|
|
|
+import com.dk.mnls_mp.infrastructure.config.Config;
|
|
|
+import com.dk.mnls_mp.infrastructure.convert.IBOSSGoodsCodeConvert;
|
|
|
+import com.dk.mnls_mp.infrastructure.util.HttpHelper;
|
|
|
+import com.dk.mnls_mp.infrastructure.util.XmlUtil;
|
|
|
+import com.dk.mnls_mp.mapper.basic.*;
|
|
|
+import com.dk.mnls_mp.model.dto.IBOSSDTO;
|
|
|
+import com.dk.mnls_mp.model.pojo.basic.Customer;
|
|
|
+import com.dk.mnls_mp.model.pojo.basic.PullOrderDetail;
|
|
|
+import com.dk.mnls_mp.model.pojo.basic.WCFinfo;
|
|
|
+import com.dk.mnls_mp.model.pojo.mnls.IBOSSData;
|
|
|
+import com.dk.mnls_mp.service.mnls.IBOSSDataService;
|
|
|
+import com.dongke.base.exceptionHandler.ResponseResultUtil;
|
|
|
+import com.dongke.base.exceptionHandler.ResponseResultVO;
|
|
|
+import com.dongke.base.util.DateHelper;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author : sh4wmoo
|
|
|
+ * @date : 2021-5-12 13:09
|
|
|
+ * @desc : 多线程拉取iBOSS数据service类
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class PullIBOSSDataService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ Config config;
|
|
|
+ @Autowired
|
|
|
+ PullOrderDetailMapper pullOrderDetailMapper;
|
|
|
+ @Autowired
|
|
|
+ CustomerMapper customerMapper;
|
|
|
+ @Autowired
|
|
|
+ CodeFacRecordMapper pullFacCodeRecordMapper;
|
|
|
+ @Autowired
|
|
|
+ IBOSSGoodsCodeConvert convert;
|
|
|
+ @Autowired
|
|
|
+ CodeFacRecordMapper codeFacRecordMapper;
|
|
|
+ @Autowired
|
|
|
+ WCFinfoMapper wcFinfoMapper;
|
|
|
+ @Autowired
|
|
|
+ IBOSSDataService ibossDataService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ SynchStatusMapper synchStatusMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @author : sh4wmoo
|
|
|
+ * @date : 2021-5-8 11:19
|
|
|
+ * @desc : 拉取iBOSS数据通用方法
|
|
|
+ */
|
|
|
+ public void pullIbossData(Constant.PullDataType type, Map<String, Object> map) {
|
|
|
+ Date startTime = new Date();
|
|
|
+ log.info("拉取iBOSS:{}数据 开始,开始时间:{},{}毫秒(ms)", type.getName(), DateHelper.formatDate(startTime), startTime.getTime());
|
|
|
+
|
|
|
+ PullOrderDetail pullOrderDetail = new PullOrderDetail();
|
|
|
+ List<Customer> customers = new ArrayList<>();
|
|
|
+
|
|
|
+ //插入履历总单
|
|
|
+ pullOrderDetail.setPullTime(new Date());
|
|
|
+ //返回履历总单id
|
|
|
+ pullOrderDetailMapper.insertDate(pullOrderDetail);
|
|
|
+ //没有时间,不关联履历
|
|
|
+ customers = customerMapper.selectAllCusForPullDetail();
|
|
|
+ //循环调用
|
|
|
+ for (Customer it : customers) {
|
|
|
+ ResponseResultVO r = this.callWebService(it, pullOrderDetail, type);
|
|
|
+ }
|
|
|
+ Date endTime = new Date();
|
|
|
+ log.info("拉取iBOSS:{}数据 结束,结束时间:{},{},耗时{}毫秒(ms)", type.getName(), DateHelper.formatDate(endTime), endTime.getTime(), endTime.getTime() - startTime.getTime());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @author : sh4wmoo
|
|
|
+ * @date : 2021-5-8 13:44
|
|
|
+ * @desc : 调用webservice服务通用方法
|
|
|
+ */
|
|
|
+ @Async("pullIbossData")
|
|
|
+ public ResponseResultVO callWebService(Customer customer, PullOrderDetail pull, Constant.PullDataType type) {
|
|
|
+ //定义iBOSS接口返回值实体
|
|
|
+ IBOSSDTO IBOSSDTO=new IBOSSDTO();
|
|
|
+ //定义履历成功状态
|
|
|
+ Integer status=0;
|
|
|
+ //此处用try捕获异常,保证多线程之间不会受事务影响
|
|
|
+ try {
|
|
|
+ //查询客户webservice信息
|
|
|
+ WCFinfo wcFinfo = wcFinfoMapper.selectById(customer.getWcfid());
|
|
|
+ if (wcFinfo == null) {
|
|
|
+ return ResponseResultUtil.error(ResponseCodeEnum.SELECT_BY_ID_NULL.getCode(), ResponseCodeEnum.SELECT_BY_ID_NULL.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ //拼接url 区别于恒洁中台 直接调用iBOSS的webservice接口
|
|
|
+ String url = "http://"+wcFinfo.getWcfip() + ":" + wcFinfo.getWcfport() + config.getIBOSSWebserviceInterfacePostfix() +type.getFunctionName();
|
|
|
+
|
|
|
+ //整理参数
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("AccountCode", customer.getDongkeaccountcode());
|
|
|
+ param.put("PageNum","0");
|
|
|
+ param.put("PageSize","0");
|
|
|
+
|
|
|
+ log.info("=*=*=*=*=*=*=*=*=" + "参数:" + param + "=*=*=*=*=*=*=*=*=");
|
|
|
+
|
|
|
+ //调用接口
|
|
|
+ Date startTime = new Date();
|
|
|
+ ResponseResultVO resultVO = HttpHelper.callIBOSSWebservice(url, param,null);
|
|
|
+ Date endTime = new Date();
|
|
|
+ log.info("经销商id=>{},接口响应时间=>{}ms", customer.getCustomerid(), endTime.getTime() - startTime.getTime());
|
|
|
+
|
|
|
+ //成功后插入数据
|
|
|
+ if (ResponseCodeEnum.SUCCESS.getCode()==resultVO.getCode()) {
|
|
|
+ //XML转map
|
|
|
+ Map<String, Object> resJson = XmlUtil.xmlToJson(resultVO.getData().toString());
|
|
|
+ //map转DTO
|
|
|
+ IBOSSDTO = JSON.parseObject(resJson.get("string").toString(), IBOSSDTO.class);
|
|
|
+
|
|
|
+ //创建insert pojo
|
|
|
+ IBOSSData IBOSSData=new IBOSSData();
|
|
|
+ JSONArray dataArray = JSONArray.parseArray(IBOSSDTO.getResult().toString());
|
|
|
+ IBOSSData.setData(dataArray);
|
|
|
+ IBOSSData.setCount(dataArray.size());
|
|
|
+ IBOSSData.setDataType((long)type.getId());
|
|
|
+ IBOSSData.setCustomerId((long)customer.getCustomerid());
|
|
|
+ //减一天日期
|
|
|
+ IBOSSData.setCreateDate(DateTimeFormatter.ofPattern("yyyy-MM-dd").format(LocalDateTime.now().minusDays(1)));
|
|
|
+ ibossDataService.insert(IBOSSData);
|
|
|
+ //修改状态为成功
|
|
|
+ status=1;
|
|
|
+ }else{
|
|
|
+ log.error("调用iBOSS接口异常,经销商id=>{},返回值=>{}",customer.getCustomerid(),resultVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ //记录履历
|
|
|
+ this.recordPullDetail(IBOSSDTO,pull,(long)customer.getCustomerid(),type,status);
|
|
|
+ return ResponseResultUtil.success();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("callWebService失败,经销商id=>{},异常信息=>{}"+customer.getCustomerid(), e);
|
|
|
+ return ResponseResultUtil.error(666,"callWebService失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 记录抓取数据履历
|
|
|
+ * @author : 张潇木
|
|
|
+ * @date : 2022-9-20 14:33
|
|
|
+ */
|
|
|
+ private void recordPullDetail(IBOSSDTO IBOSSDTO, PullOrderDetail pull, Long customerId, Constant.PullDataType type, Integer status) {
|
|
|
+ PullOrderDetail pod =new PullOrderDetail()
|
|
|
+ .setCustomerId(customerId).setStatus(status).setType(type.getId()).setPullId(pull.getPullId()).setPullTime(new Date())
|
|
|
+ .setPullQuantity(0==IBOSSDTO.getStatus()?JSONArray.parseArray(IBOSSDTO.getResult().toString()).size():null)
|
|
|
+ .setMessage(IBOSSDTO.getMessage());
|
|
|
+ pullOrderDetailMapper.insertDetail(pod);
|
|
|
+ }
|
|
|
+}
|