|
|
@ -1,14 +1,20 @@ |
|
|
|
package com.dxhy.order.consumer.openapi.api; |
|
|
|
package com.dxhy.order.consumer.openapi.api; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
|
|
|
import com.dxhy.order.baseservice.module.buyer.protocol.BuyerResponseV4BO; |
|
|
|
import com.dxhy.order.baseservice.module.buyer.protocol.GmfxxtbReqBO; |
|
|
|
import com.dxhy.order.baseservice.module.buyer.protocol.GmfxxtbReqBO; |
|
|
|
import com.dxhy.order.baseservice.module.buyer.protocol.GmfxxtbRspBO; |
|
|
|
import com.dxhy.order.baseservice.module.buyer.protocol.GmfxxtbRspBO; |
|
|
|
import com.dxhy.order.consumer.openapi.protocol.v6.sdenergy.MdmGmfxxtbMulticodeValuelistBO; |
|
|
|
import com.dxhy.order.constant.OrderInfoContentEnum; |
|
|
|
import com.dxhy.order.consumer.openapi.protocol.v6.sdenergy.MdmGmfxxtbReqBO; |
|
|
|
import com.dxhy.order.consumer.openapi.protocol.v4.ResponseV4BO; |
|
|
|
|
|
|
|
import com.dxhy.order.consumer.openapi.protocol.v4.grouptax.GroupTaxReqBO; |
|
|
|
|
|
|
|
import com.dxhy.order.consumer.openapi.protocol.v4.grouptax.GroupTaxRespBO; |
|
|
|
|
|
|
|
import com.dxhy.order.consumer.openapi.protocol.v6.sdenergy.*; |
|
|
|
import com.dxhy.order.consumer.openapi.service.InterfaceServiceV3; |
|
|
|
import com.dxhy.order.consumer.openapi.service.InterfaceServiceV3; |
|
|
|
|
|
|
|
import com.dxhy.order.exception.OrderReceiveException; |
|
|
|
import com.dxhy.order.utils.JsonUtils; |
|
|
|
import com.dxhy.order.utils.JsonUtils; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
|
|
import org.apache.poi.ss.formula.functions.T; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
@ -17,8 +23,9 @@ import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.*; |
|
|
|
import java.util.List; |
|
|
|
import java.util.function.Function; |
|
|
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @Description |
|
|
|
* @Description |
|
|
@ -30,6 +37,7 @@ import java.util.List; |
|
|
|
@RequestMapping("/invoice/api/invoice_sd_energy") |
|
|
|
@RequestMapping("/invoice/api/invoice_sd_energy") |
|
|
|
public class InvoiceRestSDEnregy { |
|
|
|
public class InvoiceRestSDEnregy { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String LOGGER_MSG = "(对外接口山能MDM)"; |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
@Resource |
|
|
|
private InterfaceServiceV3 interfaceServiceV3; |
|
|
|
private InterfaceServiceV3 interfaceServiceV3; |
|
|
@ -40,7 +48,22 @@ public class InvoiceRestSDEnregy { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@PostMapping("/sync_buyer_message") |
|
|
|
@PostMapping("/sync_buyer_message") |
|
|
|
public String syncBuyerMessage(@RequestBody String requestBody) { |
|
|
|
public String syncBuyerMessage(@RequestBody String requestBody) { |
|
|
|
List<MdmGmfxxtbReqBO> mdmGmfxxtbReqBOS = JSONObject.parseArray(requestBody, MdmGmfxxtbReqBO.class); |
|
|
|
String logUUID = UUID.randomUUID().toString(); |
|
|
|
|
|
|
|
log.info("{}[syncBuyerMessage],uuid:{},收到请求报文:{}", LOGGER_MSG, logUUID, requestBody); |
|
|
|
|
|
|
|
SDEnergyMdmBaseBO baseBO = JSONObject.parseObject(requestBody, SDEnergyMdmBaseBO.class); |
|
|
|
|
|
|
|
List<MdmGmfxxtbReqBO> mdmGmfxxtbReqBOS = (List<MdmGmfxxtbReqBO>) Optional.of(baseBO) |
|
|
|
|
|
|
|
.map(SDEnergyMdmBaseBO::getESB) |
|
|
|
|
|
|
|
.map(ESBBO::getDATA) |
|
|
|
|
|
|
|
.map(DATABO::getDATAINFOS) |
|
|
|
|
|
|
|
.map(DATAINFOSBO::getDATAINFO) |
|
|
|
|
|
|
|
.map(i -> { |
|
|
|
|
|
|
|
// 转成List<MdmSyncGroupTaxCodeReqBO>
|
|
|
|
|
|
|
|
return i.stream().map(j -> { |
|
|
|
|
|
|
|
return JSONObject.parseObject(JSONObject.toJSONString(j), MdmGmfxxtbReqBO.class); |
|
|
|
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.orElse(new ArrayList<MdmGmfxxtbReqBO>()); |
|
|
|
|
|
|
|
|
|
|
|
List<GmfxxtbReqBO> gmfxxtbReqList = new ArrayList<>(); |
|
|
|
List<GmfxxtbReqBO> gmfxxtbReqList = new ArrayList<>(); |
|
|
|
for (MdmGmfxxtbReqBO tempMdmGmfxxtbReqBO : mdmGmfxxtbReqBOS) { |
|
|
|
for (MdmGmfxxtbReqBO tempMdmGmfxxtbReqBO : mdmGmfxxtbReqBOS) { |
|
|
|
GmfxxtbReqBO gmfxxtbReqBO = new GmfxxtbReqBO(); |
|
|
|
GmfxxtbReqBO gmfxxtbReqBO = new GmfxxtbReqBO(); |
|
|
@ -93,6 +116,113 @@ public class InvoiceRestSDEnregy { |
|
|
|
gmfxxtbReqList.add(gmfxxtbReqBO); |
|
|
|
gmfxxtbReqList.add(gmfxxtbReqBO); |
|
|
|
} |
|
|
|
} |
|
|
|
List<GmfxxtbRspBO> gmfxxtbRspList = interfaceServiceV3.syncBuyerMessage(gmfxxtbReqList, ""); |
|
|
|
List<GmfxxtbRspBO> gmfxxtbRspList = interfaceServiceV3.syncBuyerMessage(gmfxxtbReqList, ""); |
|
|
|
return JsonUtils.getInstance().toJsonStringNullToEmpty(gmfxxtbRspList); |
|
|
|
// 构造返回请求
|
|
|
|
|
|
|
|
SDEnergyMdmBaseBO result = buildResult( |
|
|
|
|
|
|
|
baseBO, |
|
|
|
|
|
|
|
gmfxxtbRspList, |
|
|
|
|
|
|
|
i -> { |
|
|
|
|
|
|
|
GmfxxtbRspBO t = (GmfxxtbRspBO) i; |
|
|
|
|
|
|
|
SDEnergyMdmBaseRespBO resp = new SDEnergyMdmBaseRespBO(); |
|
|
|
|
|
|
|
resp.setCODE(t.getCODE()); |
|
|
|
|
|
|
|
resp.setUUID(t.getUUID()); |
|
|
|
|
|
|
|
resp.setSYNSTATUS(StringUtils.equals(t.getZTDM(), OrderInfoContentEnum.SUCCESS.getKey()) ? "0" : "1"); |
|
|
|
|
|
|
|
resp.setSYNRESULT(t.getZTXX()); |
|
|
|
|
|
|
|
return resp; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String resp = JsonUtils.getInstance().toJsonStringNullToEmpty(result); |
|
|
|
|
|
|
|
log.info("{}[syncGroupTax],uuid:{},返回报文:{}", LOGGER_MSG, logUUID, resp); |
|
|
|
|
|
|
|
return resp; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/sync_group_tax") |
|
|
|
|
|
|
|
public String syncGroupTax(@RequestBody String requestBody) { |
|
|
|
|
|
|
|
String logUUID = UUID.randomUUID().toString(); |
|
|
|
|
|
|
|
log.info("{}[syncGroupTax],uuid:{},收到请求报文:{}", LOGGER_MSG, logUUID, requestBody); |
|
|
|
|
|
|
|
SDEnergyMdmBaseBO baseBO = JSONObject.parseObject(requestBody, SDEnergyMdmBaseBO.class); |
|
|
|
|
|
|
|
List<MdmSyncGroupTaxCodeReqBO> list = new ArrayList<>(); |
|
|
|
|
|
|
|
List<GroupTaxRespBO> respBO = new ArrayList<>(); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
// 逐级判断是否为空,直到取到DATAINFO
|
|
|
|
|
|
|
|
list = (List<MdmSyncGroupTaxCodeReqBO>) Optional.of(baseBO) |
|
|
|
|
|
|
|
.map(SDEnergyMdmBaseBO::getESB) |
|
|
|
|
|
|
|
.map(ESBBO::getDATA) |
|
|
|
|
|
|
|
.map(DATABO::getDATAINFOS) |
|
|
|
|
|
|
|
.map(DATAINFOSBO::getDATAINFO) |
|
|
|
|
|
|
|
.map(i -> { |
|
|
|
|
|
|
|
// 转成List<MdmSyncGroupTaxCodeReqBO>
|
|
|
|
|
|
|
|
return i.stream().map(j -> { |
|
|
|
|
|
|
|
return JSONObject.parseObject(JSONObject.toJSONString(j), MdmSyncGroupTaxCodeReqBO.class); |
|
|
|
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.orElse(new ArrayList<MdmSyncGroupTaxCodeReqBO>()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 进行同步
|
|
|
|
|
|
|
|
List<GroupTaxReqBO> reqBOList = list.stream().map(i -> { |
|
|
|
|
|
|
|
GroupTaxReqBO temp = new GroupTaxReqBO(); |
|
|
|
|
|
|
|
temp.setSpmc(i.getDESC1()); |
|
|
|
|
|
|
|
temp.setMs(i.getDESCSHORT()); |
|
|
|
|
|
|
|
temp.setUnit(i.getDESC5()); |
|
|
|
|
|
|
|
temp.setEncoding(i.getCODE()); |
|
|
|
|
|
|
|
temp.setCODE(i.getCODE()); |
|
|
|
|
|
|
|
temp.setUUID(i.getUUID()); |
|
|
|
|
|
|
|
return temp; |
|
|
|
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
respBO = interfaceServiceV3.syncGroupTax(reqBOList, ""); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
log.error("{}解析列表失败,原始string:{},错误原因{},错误堆栈:{}", LOGGER_MSG, requestBody, e.getMessage(), e.getStackTrace()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构造返回请求
|
|
|
|
|
|
|
|
SDEnergyMdmBaseBO result = buildResult( |
|
|
|
|
|
|
|
baseBO, |
|
|
|
|
|
|
|
respBO, |
|
|
|
|
|
|
|
i -> { |
|
|
|
|
|
|
|
GroupTaxRespBO t = (GroupTaxRespBO) i; |
|
|
|
|
|
|
|
SDEnergyMdmBaseRespBO resp = new SDEnergyMdmBaseRespBO(); |
|
|
|
|
|
|
|
resp.setCODE(t.getCode()); |
|
|
|
|
|
|
|
resp.setUUID(t.getUuid()); |
|
|
|
|
|
|
|
resp.setSYNSTATUS(StringUtils.equals(t.getZTDM(), OrderInfoContentEnum.SUCCESS.getKey()) ? "0" : "1"); |
|
|
|
|
|
|
|
resp.setSYNRESULT(t.getZTXX()); |
|
|
|
|
|
|
|
return resp; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String resp = JsonUtils.getInstance().toJsonStringNullToEmpty(result); |
|
|
|
|
|
|
|
log.info("{}[syncGroupTax],uuid:{},返回报文:{}", LOGGER_MSG, logUUID, resp); |
|
|
|
|
|
|
|
return resp; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 统一构造 山能MDM 返回 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param baseBO |
|
|
|
|
|
|
|
* @param respList |
|
|
|
|
|
|
|
* @param handleFunction |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private SDEnergyMdmBaseBO buildResult(SDEnergyMdmBaseBO baseBO, List respList, Function<Object, SDEnergyMdmBaseRespBO> handleFunction) { |
|
|
|
|
|
|
|
DATAINFOSBO requestDATAINFOSBO = (DATAINFOSBO) Optional.of(baseBO) |
|
|
|
|
|
|
|
.map(SDEnergyMdmBaseBO::getESB) |
|
|
|
|
|
|
|
.map(ESBBO::getDATA) |
|
|
|
|
|
|
|
.map(DATABO::getDATAINFOS) |
|
|
|
|
|
|
|
.orElse(DATAINFOSBO.build()); |
|
|
|
|
|
|
|
SDEnergyMdmBaseBO respBaseBO = SDEnergyMdmBaseBO.build(); |
|
|
|
|
|
|
|
respBaseBO.getESB().setRESULT("S"); |
|
|
|
|
|
|
|
respBaseBO.getESB().setDESC("处理完成"); |
|
|
|
|
|
|
|
respBaseBO.getESB().getDATA().getDATAINFOS().setPUUID(requestDATAINFOSBO.getPUUID()); |
|
|
|
|
|
|
|
List respDataInfo = respBaseBO.getESB().getDATA().getDATAINFOS().getDATAINFO(); |
|
|
|
|
|
|
|
// 开始循环处理结果
|
|
|
|
|
|
|
|
for (int i = 0; i < respList.size(); i++) { |
|
|
|
|
|
|
|
Object currentBO = respList.get(i); |
|
|
|
|
|
|
|
SDEnergyMdmBaseRespBO baseRespBO = handleFunction.apply(currentBO); |
|
|
|
|
|
|
|
respDataInfo.add(baseRespBO); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return respBaseBO; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|