|
|
@ -11,21 +11,26 @@ import com.dxhy.common.utils.DateUtils; |
|
|
|
import com.dxhy.common.utils.R; |
|
|
|
import com.dxhy.common.utils.R; |
|
|
|
import com.dxhy.erp.dao.*; |
|
|
|
import com.dxhy.erp.dao.*; |
|
|
|
import com.dxhy.erp.entity.sdny.*; |
|
|
|
import com.dxhy.erp.entity.sdny.*; |
|
|
|
|
|
|
|
import com.dxhy.erp.enums.TaxRateCodeEnum; |
|
|
|
import com.dxhy.erp.service.ImageSubmitService; |
|
|
|
import com.dxhy.erp.service.ImageSubmitService; |
|
|
|
|
|
|
|
import com.dxhy.erp.service.SNPushCheckRecordService; |
|
|
|
import com.dxhy.erp.service.SdnyTDxRecordInvoiceDetailSalesService; |
|
|
|
import com.dxhy.erp.service.SdnyTDxRecordInvoiceDetailSalesService; |
|
|
|
import com.dxhy.erp.utils.Constant; |
|
|
|
import com.dxhy.erp.utils.Constant; |
|
|
|
import com.dxhy.erp.utils.JsonUtils; |
|
|
|
import com.dxhy.erp.utils.JsonUtils; |
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
|
@Service |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
public class ImageSubmitServiceImpl implements ImageSubmitService { |
|
|
|
public class ImageSubmitServiceImpl implements ImageSubmitService { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
@ -44,6 +49,9 @@ public class ImageSubmitServiceImpl implements ImageSubmitService { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private SdnyTDxRecordInvoiceDetailSalesService sdnyTDxRecordInvoiceDetailSalesService; |
|
|
|
private SdnyTDxRecordInvoiceDetailSalesService sdnyTDxRecordInvoiceDetailSalesService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private SNPushCheckRecordService snPushCheckRecordService; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public R salesInvoiceSubmit(SNRequestObject params) { |
|
|
|
public R salesInvoiceSubmit(SNRequestObject params) { |
|
|
|
List<String> uuidList = new ArrayList<>(); |
|
|
|
List<String> uuidList = new ArrayList<>(); |
|
|
@ -130,7 +138,7 @@ public class ImageSubmitServiceImpl implements ImageSubmitService { |
|
|
|
salesInvoiceList.add(saleRecordInvoice); |
|
|
|
salesInvoiceList.add(saleRecordInvoice); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return R.success(); |
|
|
|
return pushSap(salesInvoiceList, params); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -204,11 +212,47 @@ public class ImageSubmitServiceImpl implements ImageSubmitService { |
|
|
|
zdata.setFPYXBH(params.getImageId()); |
|
|
|
zdata.setFPYXBH(params.getImageId()); |
|
|
|
zdata.setIMG_ID(params.getImageId()); |
|
|
|
zdata.setIMG_ID(params.getImageId()); |
|
|
|
zdata.setSORT(String.valueOf(item.getSort())); |
|
|
|
zdata.setSORT(String.valueOf(item.getSort())); |
|
|
|
|
|
|
|
// 处理明细行
|
|
|
|
BigDecimal taxRate = BigDecimal.ZERO; |
|
|
|
List<ZData> zDatas=new ArrayList<>(); |
|
|
|
for (SdnyTDxRecordInvoiceDetailSales detail : item.getDetailList()) { |
|
|
|
for (SdnyTDxRecordInvoiceDetailSales detail : item.getDetailList()) { |
|
|
|
|
|
|
|
detail.setTaxRateOfSap(getTaxRate(detail.getTaxRate())); |
|
|
|
|
|
|
|
detail.setTaxRate(detail.getTaxRateOfSap().multiply(new BigDecimal(100)).toPlainString()+"%"); |
|
|
|
|
|
|
|
BigDecimal totalAmount = new BigDecimal(detail.getDetailAmount()).add(new BigDecimal(detail.getTaxAmount())); |
|
|
|
|
|
|
|
zDatas.add(ZData.builder() |
|
|
|
|
|
|
|
.ZBHSJE(detail.getDetailAmount()) |
|
|
|
|
|
|
|
.ZBHSJE_DIF("0") |
|
|
|
|
|
|
|
.ZBHSJE_Y(detail.getDetailAmount()) |
|
|
|
|
|
|
|
.ZFPDM(item.getInvoiceCode()) |
|
|
|
|
|
|
|
.ZFPHM(item.getInvoiceNo()) |
|
|
|
|
|
|
|
.ZFPHH(detail.getDetailNo()) |
|
|
|
|
|
|
|
.ZGGXH(Optional.ofNullable(detail.getModel()).orElse("").replaceAll("\\.{3}|/|<|>", "")) //去掉包含...和/、<、>的特殊字符
|
|
|
|
|
|
|
|
.ZHSJE(totalAmount.toPlainString()) |
|
|
|
|
|
|
|
.ZHSJE_Y(totalAmount.toPlainString()) |
|
|
|
|
|
|
|
.ZZSE_Y(detail.getTaxAmount()) |
|
|
|
|
|
|
|
.ZSLDW(detail.getUnit()) |
|
|
|
|
|
|
|
.ZTAX(detail.getTaxRate()) |
|
|
|
|
|
|
|
.ZZDJ(detail.getUnitPrice()) |
|
|
|
|
|
|
|
.ZZDJFP(detail.getUnitPrice()) |
|
|
|
|
|
|
|
.ZZSL(detail.getNum()) |
|
|
|
|
|
|
|
.MANDT(params.getClientNum()) |
|
|
|
|
|
|
|
.INVOICEDATE(zdata.getZKPRQ()) |
|
|
|
|
|
|
|
.INVOICETYPE(invoiceType) |
|
|
|
|
|
|
|
.ZHWMC(detail.getGoodsName()) |
|
|
|
|
|
|
|
.ZTID(zdata.getZTID()) |
|
|
|
|
|
|
|
.ZSM(TaxRateCodeEnum.getCode(detail.getTaxRate())) |
|
|
|
|
|
|
|
.build()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
String taxRate = ""; |
|
|
|
|
|
|
|
if (item.getDetailList().size() > 0) { |
|
|
|
|
|
|
|
taxRate = item.getDetailList().stream().max(Comparator.comparing(SdnyTDxRecordInvoiceDetailSales::getTaxRateOfSap)).get().getTaxRate(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
zdata.setIT_ITEM(zDatas); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//税率
|
|
|
|
|
|
|
|
zdata.setZTAX(taxRate); |
|
|
|
|
|
|
|
//税码
|
|
|
|
|
|
|
|
zdata.setZSM(TaxRateCodeEnum.getCode(taxRate)); |
|
|
|
|
|
|
|
zDataList.add(zdata); |
|
|
|
}); |
|
|
|
}); |
|
|
|
S4Request request = S4Request.builder() |
|
|
|
S4Request request = S4Request.builder() |
|
|
|
.SYSID("FPXT") |
|
|
|
.SYSID("FPXT") |
|
|
@ -216,7 +260,13 @@ public class ImageSubmitServiceImpl implements ImageSubmitService { |
|
|
|
.BSKEY(params.getBillNum()) |
|
|
|
.BSKEY(params.getBillNum()) |
|
|
|
.ZORG(params.getCompCode()) |
|
|
|
.ZORG(params.getCompCode()) |
|
|
|
.ZFILED4(params.getImageId()) |
|
|
|
.ZFILED4(params.getImageId()) |
|
|
|
|
|
|
|
.ZDATA(JSONObject.toJSONString(zDataList)) |
|
|
|
.ZFILED5(params.getClientNum()).build(); |
|
|
|
.ZFILED5(params.getClientNum()).build(); |
|
|
|
|
|
|
|
JSONObject param = new JSONObject(); |
|
|
|
|
|
|
|
param.put("IS_INPUT", request); |
|
|
|
|
|
|
|
//推送到SAP
|
|
|
|
|
|
|
|
log.info("推送山能数据:{}", JSONObject.toJSONString(param)); |
|
|
|
|
|
|
|
String result = snPushCheckRecordService.pushCheckResultToSAP(param.toJSONString()); |
|
|
|
|
|
|
|
|
|
|
|
return R.success(); |
|
|
|
return R.success(); |
|
|
|
} |
|
|
|
} |
|
|
@ -224,9 +274,37 @@ public class ImageSubmitServiceImpl implements ImageSubmitService { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 处理税率 |
|
|
|
* 处理税率 |
|
|
|
* @param taxRate |
|
|
|
* @param taxRate |
|
|
|
* @return |
|
|
|
* @return 去掉%的小数 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public BigDecimal getTaxRate(String taxRate) { |
|
|
|
public BigDecimal getTaxRate(String taxRate) { |
|
|
|
|
|
|
|
if (StringUtils.isBlank(taxRate) || Constant.ZERO_TAXRATE_VALUE.contains(taxRate)) { |
|
|
|
|
|
|
|
taxRate = "0"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
taxRate = taxRate.replace("%", ""); |
|
|
|
|
|
|
|
// 判断是不是数字 不是数字的就给0
|
|
|
|
|
|
|
|
if (!isNumeric(taxRate)) { |
|
|
|
|
|
|
|
taxRate = "0.00"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// 不知道库里存的是13% 还是0.13 所以加一个判断
|
|
|
|
|
|
|
|
if (new BigDecimal(taxRate).compareTo(BigDecimal.ONE) >= 0) { |
|
|
|
|
|
|
|
// 存的是整数 13/1/1.5等
|
|
|
|
|
|
|
|
taxRate = new BigDecimal(taxRate).divide(new BigDecimal(100),2,BigDecimal.ROUND_HALF_UP).toPlainString(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// 存的是小数 0.13 0.015等就不处理了 直接返回
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return new BigDecimal(taxRate); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean isNumeric(String str){ |
|
|
|
|
|
|
|
for (int i = str.length();--i>=0;){ |
|
|
|
|
|
|
|
if (!Character.isDigit(str.charAt(i))){ |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|