|
|
|
@ -12,17 +12,19 @@ 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.ISDEnregyService; |
|
|
|
|
import com.dxhy.order.consumer.openapi.service.InterfaceServiceV3; |
|
|
|
|
import com.dxhy.order.consumer.utils.OpentextUtils; |
|
|
|
|
import com.dxhy.order.exception.OrderReceiveException; |
|
|
|
|
import com.dxhy.order.model.R; |
|
|
|
|
import com.dxhy.order.utils.JsonUtils; |
|
|
|
|
import lombok.SneakyThrows; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.apache.ibatis.annotations.Param; |
|
|
|
|
import org.apache.poi.ss.formula.functions.T; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
@ -154,194 +156,37 @@ public class InvoiceRestSDEnregy { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 主动拉取 MDM 集团物料 |
|
|
|
|
* opentext测试 上传文件 |
|
|
|
|
* |
|
|
|
|
* @param file |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@PostMapping("/fetch_group_tax") |
|
|
|
|
public String fetchMdmGroupTax() { |
|
|
|
|
// TODO
|
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 主动拉取客商信息 |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@PostMapping("/fetch_buyer_message") |
|
|
|
|
public String fetchBuyerMessage() { |
|
|
|
|
// TODO
|
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 将客商信息同步入库 |
|
|
|
|
* |
|
|
|
|
* @param requestBody MDM报文,TODO 后面页面做引用的时候需要改造成POJO |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private String syncMdmBuyerMessage2BuyerMessage(String requestBody) { |
|
|
|
|
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<>(); |
|
|
|
|
for (MdmGmfxxtbReqBO tempMdmGmfxxtbReqBO : mdmGmfxxtbReqBOS) { |
|
|
|
|
GmfxxtbReqBO gmfxxtbReqBO = new GmfxxtbReqBO(); |
|
|
|
|
// 处理客户信息
|
|
|
|
|
gmfxxtbReqBO.setGMFBM(tempMdmGmfxxtbReqBO.getCODE()); // 取code
|
|
|
|
|
gmfxxtbReqBO.setGMFMC(tempMdmGmfxxtbReqBO.getDESC1()); |
|
|
|
|
gmfxxtbReqBO.setGMFSBH(tempMdmGmfxxtbReqBO.getDESC14()); |
|
|
|
|
gmfxxtbReqBO.setGMFDH(tempMdmGmfxxtbReqBO.getDESC26()); |
|
|
|
|
|
|
|
|
|
// gmfxxtbReqBO.setXHFSBH(tempMdmGmfxxtbReqBO.getDESC14());
|
|
|
|
|
// gmfxxtbReqBO.setXHFMC(tempMdmGmfxxtbReqBO.getDESC1());
|
|
|
|
|
|
|
|
|
|
// 判断下DESC14是否为身份证,如果为身份证,则填写03,否则填写01,其余情况置空
|
|
|
|
|
// 身份证正则表达式
|
|
|
|
|
String idCardRegex = "(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)"; |
|
|
|
|
// 税号正则表达式
|
|
|
|
|
String taxNoRegex = "^[a-zA-Z0-9]{15,20}$"; |
|
|
|
|
gmfxxtbReqBO.setGMFLX(""); |
|
|
|
|
if (StringUtils.isNotEmpty(tempMdmGmfxxtbReqBO.getDESC14())) { |
|
|
|
|
if (tempMdmGmfxxtbReqBO.getDESC14().matches(idCardRegex)) { |
|
|
|
|
gmfxxtbReqBO.setGMFLX("03"); // 有可能出现个人
|
|
|
|
|
} |
|
|
|
|
if (tempMdmGmfxxtbReqBO.getDESC14().matches(taxNoRegex)) { |
|
|
|
|
gmfxxtbReqBO.setGMFLX("01"); |
|
|
|
|
@SneakyThrows |
|
|
|
|
@PostMapping("/test/opentext/upload") |
|
|
|
|
public String uploadOpentext(MultipartFile file) { |
|
|
|
|
R result = OpentextUtils.uploadFile(file.getInputStream(), file.getOriginalFilename()); |
|
|
|
|
if (result.isOk()) { |
|
|
|
|
return (String) result.getData(); |
|
|
|
|
} else { |
|
|
|
|
return result.getMessage(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String invoiceName = StringUtils.isNotEmpty(tempMdmGmfxxtbReqBO.getDESC48()) ? tempMdmGmfxxtbReqBO.getDESC48() : tempMdmGmfxxtbReqBO.getDESC1(); |
|
|
|
|
gmfxxtbReqBO.setINVOICE_NAME(invoiceName); |
|
|
|
|
String invoiceTaxno = StringUtils.isNotEmpty(tempMdmGmfxxtbReqBO.getDESC49()) ? tempMdmGmfxxtbReqBO.getDESC49() : tempMdmGmfxxtbReqBO.getDESC14(); |
|
|
|
|
gmfxxtbReqBO.setINVOICE_TAXNO(invoiceTaxno); |
|
|
|
|
// 根据要求,取VALUELIST中的第一组数据作为银行数据
|
|
|
|
|
if (tempMdmGmfxxtbReqBO.getMULTICODE() != null && !CollectionUtils.isEmpty(tempMdmGmfxxtbReqBO.getMULTICODE().getVALUELIST())) { |
|
|
|
|
// 处理开户行银行
|
|
|
|
|
MdmGmfxxtbMulticodeValuelistBO firstValueList = tempMdmGmfxxtbReqBO.getMULTICODE().getVALUELIST().get(0); |
|
|
|
|
if (firstValueList != null) { |
|
|
|
|
gmfxxtbReqBO.setGMFYH(firstValueList.getDESC3()); |
|
|
|
|
gmfxxtbReqBO.setGMFZH(firstValueList.getDESC4()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gmfxxtbReqBO.setGMFSJH(tempMdmGmfxxtbReqBO.getDESC27()); |
|
|
|
|
gmfxxtbReqBO.setGMFYX(tempMdmGmfxxtbReqBO.getDESC29()); |
|
|
|
|
gmfxxtbReqBO.setCZLX("3"); // 可能重复推送,重复推送可能出现更新的情况,增加先查询,存在则更新不存在则插入的逻辑
|
|
|
|
|
|
|
|
|
|
// 拼接邮箱和地址
|
|
|
|
|
String buyerAddress = ""; |
|
|
|
|
buyerAddress = buyerAddress.concat(StringUtils.isEmpty(tempMdmGmfxxtbReqBO.getDESC22()) ? "" : tempMdmGmfxxtbReqBO.getDESC22()); |
|
|
|
|
buyerAddress = buyerAddress.concat(StringUtils.isEmpty(tempMdmGmfxxtbReqBO.getDESC23()) ? "" : tempMdmGmfxxtbReqBO.getDESC23()); |
|
|
|
|
buyerAddress = buyerAddress.concat(StringUtils.isEmpty(tempMdmGmfxxtbReqBO.getDESC24()) ? "" : tempMdmGmfxxtbReqBO.getDESC24()); |
|
|
|
|
gmfxxtbReqBO.setGMFDZ(buyerAddress); |
|
|
|
|
gmfxxtbReqBO.setINVOICE_NAME(tempMdmGmfxxtbReqBO.getDESC48()); |
|
|
|
|
gmfxxtbReqBO.setINVOICE_TAXNO(tempMdmGmfxxtbReqBO.getDESC49()); |
|
|
|
|
|
|
|
|
|
gmfxxtbReqBO.setMDM_MULTICODE_JSON(JsonUtils.getInstance().toJsonStringNullToEmpty(tempMdmGmfxxtbReqBO.getMULTICODE())); |
|
|
|
|
gmfxxtbReqList.add(gmfxxtbReqBO); |
|
|
|
|
} |
|
|
|
|
List<GmfxxtbRspBO> gmfxxtbRspList = interfaceServiceV3.syncBuyerMessage(gmfxxtbReqList, ""); |
|
|
|
|
// 构造返回请求
|
|
|
|
|
SDEnergyMdmBaseBO result = isdEnregyService.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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 同步MDM集团税收分类编码到系统税收分类编码 |
|
|
|
|
* opentext测试 查阅文件 |
|
|
|
|
* |
|
|
|
|
* @param requestBody TODO 这里后面要改成POJO |
|
|
|
|
* @param docId |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public String syncMdmGroupTax2GroupTax(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()); |
|
|
|
|
@SneakyThrows |
|
|
|
|
@PostMapping("/test/opentext/show") |
|
|
|
|
public String uploadOpentext(@RequestParam("id") String docId) { |
|
|
|
|
R result = OpentextUtils.showFile(docId); |
|
|
|
|
if (result.isOk()) { |
|
|
|
|
return (String) result.getData(); |
|
|
|
|
} else { |
|
|
|
|
return result.getMessage(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 构造返回请求
|
|
|
|
|
SDEnergyMdmBaseBO result = isdEnregyService.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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|