修复gsclient 事务问题

release
wangrangrang 2 years ago
parent 00fd3ddadc
commit 2c0faec9c8
  1. 16
      dxhy-core/src/main/java/com/dxhy/core/service/gsclient/GsClientService.java
  2. 31
      dxhy-core/src/main/java/com/dxhy/core/service/gsclient/GsClientServiceImpl.java
  3. 86
      dxhy-core/src/main/java/com/dxhy/core/task/SdnyClientTask.java

@ -0,0 +1,16 @@
package com.dxhy.core.service.gsclient;
import com.dxhy.core.entity.GsClient;
import java.util.List;
/**
* @title: GsClient
* @Author: wrr
* @Date: 2023/11/3 09:02
* @Description:
*/
public interface GsClientService {
void updateGsClient(List<GsClient> list);
}

@ -0,0 +1,31 @@
package com.dxhy.core.service.gsclient;
import com.dxhy.core.dao.GsClientMapper;
import com.dxhy.core.entity.GsClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* @title: GsClientServiceImpl
* @Author: wrr
* @Date: 2023/11/3 09:03
* @Description:
*/
@Service
@Slf4j
public class GsClientServiceImpl implements GsClientService{
private static final String LOGGER_MSG = "pt(SAP获取公司clientService)";
@Resource
private GsClientMapper gsClientMapper;
@Override
public void updateGsClient(List<GsClient> list) {
log.info("{}删除gs_client表数据", LOGGER_MSG);
gsClientMapper.deleteAll();
log.info("{}插入gs_client表", LOGGER_MSG);
gsClientMapper.insertList(list);
}
}

@ -14,6 +14,7 @@ import com.dxhy.core.job.entity.SNSAPObject;
import com.dxhy.core.job.entity.ScheduleJobEntity;
import com.dxhy.core.job.service.InvoiceInterfaceService;
import com.dxhy.core.job.service.ScheduleJobService;
import com.dxhy.core.service.gsclient.GsClientService;
import com.dxhy.core.util.HttpUtils;
import com.dxhy.core.util.JsonUtils;
import lombok.extern.slf4j.Slf4j;
@ -46,9 +47,6 @@ public class SdnyClientTask extends AbstractController {
@Value("${po.password}")
private String password;
@Resource
private GsClientMapper gsClientMapper;
@Resource
private InvoiceInterfaceService invoiceInterfaceService;
@Resource
@ -56,6 +54,9 @@ public class SdnyClientTask extends AbstractController {
@Resource
private ScheduleJobService scheduleJobService;
@Resource
private GsClientService gsClientService;
/**
* 核心线程池大小
*/
@ -84,48 +85,53 @@ public class SdnyClientTask extends AbstractController {
// 需判断 设置不认证状态
String[] split = client.split(",");
for(int i = 0;i < split.length;i++) {
SNSAPObject object = new SNSAPObject();
object.setSYSID("FPXT");
object.setIFYWID("FI846");
object.setBSKEY(UUID.randomUUID().toString().replace("-", ""));
object.setZFILED5(split[i]);
object.setZDATA("");
//推送到SAP
log.info("推送山能数据:{}", JSONObject.toJSONString(object));
JSONObject request = new JSONObject();
request.put("IS_INPUT", object);
log.info("{}获取公司client入参:{}", LOGGER_MSG, request.toJSONString());
String result = HttpUtils.sendPo(snYxUrl, request.toJSONString(), userName, password);
log.info("{}获取公司client出参:{}", LOGGER_MSG, result);
PoCommonResponseParam poCommonResponseParam = JsonUtils.getInstance().parseObject(result, PoCommonResponseParam.class);
EsOutput es_output = poCommonResponseParam.getES_OUTPUT();
String ztype = es_output.getZTYPE();
String zmessage = es_output.getZMESSAGE();
Object zdata = es_output.getZDATA();
if ("S".equals(ztype)) {
List<Map<String, String>> gsClientList = JsonUtils.getInstance().parseObject(zdata.toString(), List.class);
gsClientList.stream().forEach(f -> {
GsClient gsClient = new GsClient();
gsClient.setGsdm(ObjectUtil.isNull(f.get("BUKRS")) ? "" : f.get("BUKRS").toString());
gsClient.setGsmc(ObjectUtil.isNull(f.get("BUTXT")) ? "" : f.get("BUTXT").toString());
gsClient.setClient(ObjectUtil.isNull(f.get("MANDT")) ? "" : f.get("MANDT").toString());
gsClient.setCreateTime(new Date());
list.add(gsClient);
});
} else {
log.error("{}client:{},获取公司client出错:{}", LOGGER_MSG, "200", zmessage);
try {
SNSAPObject object = new SNSAPObject();
object.setSYSID("FPXT");
object.setIFYWID("FI846");
object.setBSKEY(UUID.randomUUID().toString().replace("-", ""));
object.setZFILED5(split[i]);
object.setZDATA("");
//推送到SAP
log.info("推送山能数据:{}", JSONObject.toJSONString(object));
JSONObject request = new JSONObject();
request.put("IS_INPUT", object);
log.info("{}获取公司client入参:{}", LOGGER_MSG, request.toJSONString());
String result = HttpUtils.sendPo(snYxUrl, request.toJSONString(), userName, password);
log.info("{}获取公司client出参:{}", LOGGER_MSG, result);
PoCommonResponseParam poCommonResponseParam = JsonUtils.getInstance().parseObject(result, PoCommonResponseParam.class);
EsOutput es_output = poCommonResponseParam.getES_OUTPUT();
String ztype = es_output.getZTYPE();
String zmessage = es_output.getZMESSAGE();
Object zdata = es_output.getZDATA();
if("300".equals(split[i])){
throw new RuntimeException("测试异常");
}
if ("S".equals(ztype)) {
List<Map<String, String>> gsClientList = JsonUtils.getInstance().parseObject(zdata.toString(), List.class);
gsClientList.stream().forEach(f -> {
GsClient gsClient = new GsClient();
gsClient.setGsdm(ObjectUtil.isNull(f.get("BUKRS")) ? "" : f.get("BUKRS").toString());
gsClient.setGsmc(ObjectUtil.isNull(f.get("BUTXT")) ? "" : f.get("BUTXT").toString());
gsClient.setClient(ObjectUtil.isNull(f.get("MANDT")) ? "" : f.get("MANDT").toString());
gsClient.setCreateTime(new Date());
list.add(gsClient);
});
} else {
log.error("{}client:{},获取公司client出错:{}", LOGGER_MSG, "200", zmessage);
}
} catch (Exception e) {
//捕获异常 不抛出 一个公司的client出错不能影响其他的
log.error("{}client:{},获取公司client出现异常:{}",LOGGER_MSG,client,e.getMessage());
}
}
log.info("{}删除gs_client表数据", LOGGER_MSG);
gsClientMapper.deleteAll();
log.info("{}插入gs_client表", LOGGER_MSG);
gsClientMapper.insertList(list);
//list中有可能存在已部分有异常的client的公司,因为这些公司是在异常发生之前存到list中的
gsClientService.updateGsClient(list);
long endTime = System.currentTimeMillis();
log.debug("{}任务结束,耗时:{}", LOGGER_MSG, endTime - startTime);
} catch (Exception e) {
e.printStackTrace();
} finally {

Loading…
Cancel
Save