You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
343 lines
14 KiB
343 lines
14 KiB
package com.dxhy.erp.controller;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.dxhy.common.aspect.SysLog;
|
|
import com.dxhy.common.constant.CommonConstants;
|
|
import com.dxhy.common.controller.AbstractController;
|
|
import com.dxhy.common.enums.FplxEnum;
|
|
import com.dxhy.common.enums.SNFplxEnum;
|
|
import com.dxhy.common.jwt.IJWTInfo;
|
|
import com.dxhy.common.util.InvoiceUtil;
|
|
import com.dxhy.common.util.UserInfoUtil;
|
|
import com.dxhy.common.utils.BaseContextHandler;
|
|
import com.dxhy.common.utils.R;
|
|
import com.dxhy.erp.entity.sdny.*;
|
|
import com.dxhy.erp.service.InvoiceQueryService;
|
|
import com.dxhy.erp.service.SNPushCheckRecordService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.security.auth.message.config.AuthConfig;
|
|
import java.math.BigDecimal;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 山东能源查验主流程控制器
|
|
*
|
|
* @author ariesy
|
|
* @date 2023-03-15
|
|
*/
|
|
@SuppressWarnings({"AlibabaUndefineMagicConstant", "AlibabaMethodTooLong"})
|
|
@RestController
|
|
@Slf4j
|
|
public class SDNYMainProcessController extends AbstractController {
|
|
@Resource
|
|
private InvoiceQueryService invoiceQueryService;
|
|
|
|
@Resource
|
|
private SNPushCheckRecordService snPushCheckRecordService;
|
|
|
|
/**
|
|
* 查验发票
|
|
*/
|
|
@PostMapping("/sn/singleInvoiceCheck")
|
|
@ResponseBody
|
|
@SysLog("发票查验")
|
|
public ResponseEntity<?> singleInvoiceCheck(@RequestBody Map<String, String> pramsMap) {
|
|
|
|
// // 入参统一在入口处理
|
|
// String userid = getLoginName();
|
|
// pramsMap.put("userid", userid);
|
|
// String dbName = getUserInfo().getDbName();
|
|
// pramsMap.put("dbName", dbName);
|
|
// pramsMap.put("saveHistory","Y");
|
|
//
|
|
// pramsMap.put("company", getUserInfo().getCompany());
|
|
//
|
|
// List<String> gfshAll = UserInfoUtil.getGfshAll(getUserInfo().getOrg());
|
|
// if (gfshAll.size() > 0) {
|
|
// pramsMap.put("taxNo", gfshAll.get(0));
|
|
//
|
|
// }
|
|
// pramsMap.put("purchaserTaxNo", pramsMap.get("purchaserTaxNo"));
|
|
|
|
|
|
InvoiceUtil iu = new InvoiceUtil(pramsMap.get("invoiceCode"));
|
|
String fplxdm = iu.getFplxdm();
|
|
|
|
if (pramsMap.get("invoiceCode").isEmpty()) {
|
|
|
|
return ResponseEntity.ok(R.error("发票代码不能为空!"));
|
|
}
|
|
// pramsMap.put("invoiceType", iu.getFplxdm());
|
|
|
|
|
|
if (pramsMap.get("invoiceNumber").isEmpty()) {
|
|
return ResponseEntity.ok(R.error("发票号码不能为空!"));
|
|
}
|
|
pramsMap.put("invoiceNo", pramsMap.get("invoiceNumber"));
|
|
|
|
if (!pramsMap.get("billingDate").isEmpty()) {
|
|
iu.setKprq(pramsMap.get("billingDate"));
|
|
pramsMap.put("invoiceDate", pramsMap.get("billingDate"));
|
|
if (!iu.kprqValid(null)) {
|
|
pramsMap.put("invoiceDate", "开票日期格式错误!");
|
|
}
|
|
} else {
|
|
return ResponseEntity.ok(R.error("开票日期不能为空!"));
|
|
}
|
|
|
|
if (SNFplxEnum.ZP.getSnFplxDm().equals(pramsMap.get("invoiceType"))
|
|
|| SNFplxEnum.JDC.getSnFplxDm().equals(pramsMap.get("invoiceType"))
|
|
|| SNFplxEnum.DZZP.getSnFplxDm().equals(pramsMap.get("invoiceType"))
|
|
|| SNFplxEnum.ESC.getSnFplxDm().equals(pramsMap.get("invoiceType"))
|
|
|| SNFplxEnum.QDZP.getSnFplxDm().equals(pramsMap.get("invoiceType"))
|
|
|| SNFplxEnum.QDPP.getSnFplxDm().equals(pramsMap.get("invoiceType"))) {
|
|
if (pramsMap.get("totalAmount").isEmpty()) {
|
|
return ResponseEntity.ok(R.error("金额不能为空!"));
|
|
}
|
|
} else {
|
|
if (pramsMap.get("checkCode").isEmpty()) {
|
|
return ResponseEntity.ok(R.error("校验码不能为空!"));
|
|
}
|
|
}
|
|
|
|
String uuid = (StringUtils.isBlank(pramsMap.get("invoiceCode"))?"":pramsMap.get("invoiceCode"))+ pramsMap.get("invoiceNo");
|
|
String notes = invoiceQueryService.checkingInvoiceInfo("business", uuid, getUserInfo());
|
|
if (notes != null) {
|
|
return ResponseEntity.ok(R.error(notes));
|
|
}
|
|
JSONObject checkInvoiceResult = null;
|
|
if (SNFplxEnum.ZP.getSnFplxDm().equals(pramsMap.get("invoiceType"))
|
|
|| SNFplxEnum.JDC.getSnFplxDm().equals(pramsMap.get("invoiceType"))
|
|
|| SNFplxEnum.PP.getSnFplxDm().equals(pramsMap.get("invoiceType"))
|
|
|| SNFplxEnum.DZZP.getSnFplxDm().equals(pramsMap.get("invoiceType"))
|
|
|| SNFplxEnum.DZP.getSnFplxDm().equals(pramsMap.get("invoiceType"))
|
|
|| SNFplxEnum.JSP.getSnFplxDm().equals(pramsMap.get("invoiceType"))
|
|
|| SNFplxEnum.TXF.getSnFplxDm().equals(pramsMap.get("invoiceType"))
|
|
|| SNFplxEnum.ESC.getSnFplxDm().equals(pramsMap.get("invoiceType"))
|
|
|| SNFplxEnum.QDZP.getSnFplxDm().equals(pramsMap.get("invoiceType"))
|
|
|| SNFplxEnum.QDPP.getSnFplxDm().equals(pramsMap.get("invoiceType"))
|
|
) {
|
|
|
|
pramsMap.put("invoiceType",fplxdm);
|
|
//查验发票数据
|
|
checkInvoiceResult = snPushCheckRecordService.checkInvoice(pramsMap, getUserInfo());
|
|
}else{
|
|
//价税分离
|
|
// snPushCheckRecordService.valoremTaxCount();
|
|
}
|
|
return ResponseEntity.ok(R.ok().put("data", checkInvoiceResult));
|
|
}
|
|
|
|
/**
|
|
* 查验发票
|
|
*/
|
|
@PostMapping("/sn/syncInvoiceInfo")
|
|
@ResponseBody
|
|
@SysLog("同步发票信息")
|
|
public ResponseEntity<?> syncInvoiceInfo(@RequestBody SNRequestObject snRequestObject) {
|
|
// 入参统一在入口处理
|
|
String userid = getLoginName();
|
|
String dbName = getUserInfo().getDbName();
|
|
String company = getUserInfo().getCompany();
|
|
|
|
|
|
List<String> gfshAll = UserInfoUtil.getGfshAll(getUserInfo().getOrg());
|
|
|
|
//String notes = invoiceQueryService.checkingInvoiceInfo(dbName, uuid, getUserInfo());
|
|
|
|
//入票池
|
|
|
|
//推送到SAP
|
|
List<SNInvoice> invoiceInfoList = snRequestObject.getInvoiceInfoList();
|
|
|
|
String imageId = snRequestObject.getImageId();
|
|
|
|
for(SNInvoice invoice : invoiceInfoList) {
|
|
SNSAPObject object = convertToSapOnject(invoice,imageId);
|
|
JSONObject sapObj = (JSONObject) JSONObject.toJSON(object);
|
|
|
|
String result = "";
|
|
try {
|
|
//将信息推送到影像系统
|
|
result = snPushCheckRecordService.pushCheckResultToSAP(sapObj);
|
|
|
|
return ResponseEntity.ok(R.ok().put("data", result));
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
log.error("", e);
|
|
return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
|
|
}
|
|
}
|
|
return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
|
|
}
|
|
|
|
private SNSAPObject convertToSapOnject(SNInvoice snInvoice,String imageId) {
|
|
|
|
Date date = new Date();
|
|
|
|
SNSAPObject object = new SNSAPObject();
|
|
object.setSYSID("JS");
|
|
object.setIFYWID("FI845");
|
|
object.setBSKEY("a77a8ba6c0dc45cd9e88972fb4750f93");
|
|
object.setSAPKEY("");
|
|
object.setZORG("");
|
|
object.setZFILED1("");
|
|
object.setZFILED2("");
|
|
object.setZFILED3("");
|
|
object.setZFILED4("");
|
|
object.setZFILED5("800");
|
|
List<SAPInvoiceInfo> sapInvoiceInfos = new ArrayList<>();
|
|
SAPInvoiceInfo info = new SAPInvoiceInfo();
|
|
info.setZBAZT("0");
|
|
info.setZXFSH(snInvoice.getSalesTaxNo());
|
|
info.setZJDDM("");
|
|
info.setZJDHM("");
|
|
info.setZFPSZD(snInvoice.getPlace());
|
|
info.setZXFBM("");
|
|
info.setZSPMC(snInvoice.getDraweeName());
|
|
info.setZSPSBH(snInvoice.getDraweeTaxNo());
|
|
info.setZCJR("");
|
|
info.setZCYJG(snInvoice.getCheckResultMessage());
|
|
info.setZJKZM(snInvoice.getImportCertificateNo());
|
|
info.setZDJZH(snInvoice.getCertificateNo());
|
|
info.setZGFMC(snInvoice.getPurchaserName());
|
|
|
|
BigDecimal total = new BigDecimal(snInvoice.getTotalAmount());
|
|
BigDecimal tax = new BigDecimal(snInvoice.getTotalTax());
|
|
BigDecimal subtract = total.subtract(tax);
|
|
|
|
info.setZJK(subtract.toString());
|
|
info.setZSCSJ(date);
|
|
info.setZCYZT(snInvoice.getCheckStaus());
|
|
info.setZYSHW(snInvoice.getCargoInformation());
|
|
info.setZFPLX(snInvoice.getInvoiceType());
|
|
info.setZFU("");
|
|
info.setZQYD(snInvoice.getTransportRoute());
|
|
info.setZCCRXM(snInvoice.getRiderName());
|
|
info.setZKPRQ(snInvoice.getBillingDate());
|
|
info.setZSLT("");
|
|
info.setZYWZT("");
|
|
info.setZSE(snInvoice.getTotalTax());
|
|
info.setZTXBZ(snInvoice.getTollSign());
|
|
info.setZYHM("");
|
|
info.setZSKPH(snInvoice.getMachineCode());
|
|
info.setZGFZH(snInvoice.getPurchaserBank());
|
|
info.setZBZ(snInvoice.getRemarks());
|
|
List<SNInvoiceDetail> invoiceLineList = snInvoice.getInvoiceLineList();
|
|
List<SAPInvoiceDetail> sapInvoiceDetailList = new ArrayList<>();
|
|
if(invoiceLineList != null && invoiceLineList.size() > 0){
|
|
SNInvoiceDetail snInvoiceDetail = invoiceLineList.get(0);
|
|
String taxRate = snInvoiceDetail.getTaxRate();
|
|
info.setZSM(taxRate);
|
|
info.setZTAX(taxRate);
|
|
|
|
SAPInvoiceDetail sapInvoiceDetail = new SAPInvoiceDetail();
|
|
sapInvoiceDetail.setZZWDJ("");
|
|
sapInvoiceDetail.setIMG_ID(imageId);
|
|
sapInvoiceDetail.setZCPH(snInvoiceDetail.getLicensePlateNum());
|
|
sapInvoiceDetail.setZCJSJ("");
|
|
sapInvoiceDetail.setZCJRQ("");
|
|
sapInvoiceDetail.setZCFZ(snInvoice.getStationGetOn());
|
|
sapInvoiceDetail.setZTXZ(snInvoiceDetail.getCurrentDateEnd());
|
|
sapInvoiceDetail.setZTXQ(snInvoiceDetail.getCurrentDateStart());
|
|
sapInvoiceDetail.setZJK(snInvoiceDetail.getAmount());
|
|
sapInvoiceDetail.setZHH(snInvoiceDetail.getRowNo());
|
|
sapInvoiceDetail.setZTAX(snInvoiceDetail.getTaxRate());
|
|
sapInvoiceDetail.setZHBH("");
|
|
sapInvoiceDetail.setZDJ(snInvoiceDetail.getUnitPrice());
|
|
sapInvoiceDetail.setZHID("");
|
|
sapInvoiceDetail.setZDDZ(snInvoice.getStationGetOff());
|
|
sapInvoiceDetail.setZHWMC(snInvoiceDetail.getCommodityName());
|
|
sapInvoiceDetail.setZCYR(info.getZCYRMC());
|
|
sapInvoiceDetail.setZDW(snInvoiceDetail.getUnit());
|
|
sapInvoiceDetail.setZGSJBM(snInvoiceDetail.getCommodityCode());
|
|
sapInvoiceDetail.setZSE(snInvoiceDetail.getTax());
|
|
sapInvoiceDetail.setZSL(snInvoiceDetail.getQuantity());
|
|
sapInvoiceDetail.setZSM(info.getZSM());
|
|
sapInvoiceDetail.setZGGXH(snInvoiceDetail.getSpecificationModel());
|
|
sapInvoiceDetail.setZTID("");
|
|
sapInvoiceDetailList.add(sapInvoiceDetail);
|
|
}
|
|
|
|
info.setIT_ITEM(sapInvoiceDetailList);
|
|
|
|
info.setZFPDM(snInvoice.getInvoiceCode());
|
|
info.setZCD(snInvoice.getOriginPlace());
|
|
info.setZSCCZ(snInvoice.getStationGetOn());
|
|
info.setZCC(snInvoice.getTrainNumber());
|
|
info.setZFPHM(snInvoice.getInvoiceNumber());
|
|
info.setZBXF(snInvoice.getInsurance());
|
|
info.setZRYFJ(snInvoice.getFuelSurcharge());
|
|
info.setZCLSB(snInvoice.getVehicleNo());
|
|
info.setZKPSJ(snInvoice.getBillingDate());
|
|
info.setZXCSJ(date);
|
|
info.setZXFMC(snInvoice.getSalesName());
|
|
info.setZCYRSBH(snInvoice.getCarrierName());
|
|
|
|
info.setIMG_ID(imageId);
|
|
info.setZCPH(snInvoice.getLicensePlate());
|
|
info.setZLSLBZ(snInvoice.getZeroTaxRateSign());
|
|
info.setZCJSJ(date);
|
|
info.setZFPZT(snInvoice.getState());
|
|
info.setZESCSC("");
|
|
info.setZFDJM(snInvoice.getEngineNo());
|
|
info.setZGXR("");
|
|
|
|
//认证相关
|
|
info.setZRZJG("");
|
|
info.setZRZSSQ("");
|
|
info.setZRZMS("");
|
|
info.setZRZRQ("");
|
|
|
|
info.setZLC(snInvoice.getMileage());
|
|
info.setZHGZH(snInvoice.getCertificateNo());
|
|
info.setZXFDH(snInvoice.getSalesAddressPhone());
|
|
|
|
info.setZESCSH("");
|
|
info.setZGSDM("BG90");
|
|
info.setZGFSH(snInvoice.getPurchaserTaxNo());
|
|
info.setZXCRS(snInvoice.getPassengersLimited());
|
|
info.setZWSPZ(snInvoice.getPaymentVoucherNo());
|
|
info.setZCCDW(snInvoice.getTonnage());
|
|
info.setZSWJG(snInvoice.getTaxAuthorityNo());
|
|
info.setZYWDJ("");
|
|
info.setZXCCZ(snInvoice.getStationGetOff());
|
|
info.setZCCRZH(snInvoice.getIdcardNo());
|
|
info.setZCPXH(snInvoice.getBrandModel());
|
|
info.setZMHFZJJ(snInvoice.getCaacDevelopmentFund());
|
|
info.setZGFDH(snInvoice.getPurchaserAddressPhone());
|
|
info.setZXFZH(snInvoice.getSalesBank());
|
|
info.setZJYM(snInvoice.getCheckCode());
|
|
info.setZSJDH(snInvoice.getInspectionListNo());
|
|
info.setZYGC("");
|
|
info.setZJSHJ(snInvoice.getAmountTax());
|
|
info.setZCYRMC(snInvoice.getCarrierName());
|
|
info.setZJGDM(snInvoice.getAdministrativeDivisionNo());
|
|
info.setZGXSJ(date);
|
|
info.setZQM("opentext");
|
|
info.setZPJLY(snInvoice.getSource());
|
|
info.setZZWLX(snInvoice.getSeat());
|
|
info.setZTID("");
|
|
|
|
|
|
sapInvoiceInfos.add(info);
|
|
object.setZDATA(sapInvoiceInfos);
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
}
|
|
|