ncc2005后期修改代码迁移

This commit is contained in:
mzr 2025-04-11 16:54:05 +08:00
parent f4f73a0bfc
commit c25a9135dd
1 changed files with 333 additions and 283 deletions

View File

@ -2,13 +2,6 @@ package nccloud.api.so.saleinvoice.operator;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Map;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import nc.bs.framework.common.InvocationInfoProxy;
import nc.bs.framework.common.NCLocator;
import nc.bs.framework.core.util.ObjectCreator;
@ -17,6 +10,7 @@ import nc.jdbc.framework.processor.ColumnProcessor;
import nc.jdbc.framework.processor.MapProcessor;
import nc.pubitf.so.m32.api.ISaleinvoiceQueryAPI;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pubapp.pattern.model.entity.bill.AbstractBill;
import nc.vo.pubapp.pflow.PfUserObject;
import nc.vo.so.m32.entity.SaleInvoiceHVO;
@ -34,6 +28,13 @@ import nccloud.pubitf.ssctp.sscbd.lientage.ISSClientageMatchService.BusiUnitType
import nccloud.ws.rest.resource.AbstractNCCRestResource;
import org.json.JSONString;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Map;
/**
* 销售发票接口适配2005代码
@ -66,8 +67,8 @@ public class saveCommitAction extends AbstractNCCRestResource {
@POST
@Path("/saveCommit")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@Consumes({"application/json"})
@Produces({"application/json"})
public JSONString saveCommit(JSONString json) throws Exception {
JSONObject jobject = JSONObject.parseObject(json.toJSONString());
if (jobject == null) {
@ -114,7 +115,7 @@ public class saveCommitAction extends AbstractNCCRestResource {
return r != null ? ResultMessageUtil.toJSON(r.getDesc(), "0")
: ResultMessageUtil.exceptionToJSON(new NullPointerException("未知异常"));
}
String[] ids = { content };
String[] ids = {content};
SaleInvoiceVO[] saleInvoiceVO = NCLocator.getInstance().lookup(ISaleinvoiceQueryAPI.class)
.queryVOByIDs(ids);
SaleInvoiceVO saleInvoiceVO22 = saleInvoiceVO[0];
@ -123,14 +124,14 @@ public class saveCommitAction extends AbstractNCCRestResource {
InvocationInfoProxy.getInstance().setUserId(saleInvoiceHVO.getApprover());
CloudPFlowContext context = new CloudPFlowContext();
context.setBillType("32");
context.setBillVos(new SaleInvoiceVO[] { saleInvoiceVO[0] });
context.setBillVos(new SaleInvoiceVO[]{saleInvoiceVO[0]});
ISSCService sscService = (ISSCService) NCLocator.getInstance().lookup(ISSCService.class);
String[] actionNames = sscService.isStartSSCWorkFlow(
(AbstractBill[]) ((AbstractBill[]) context.getBillVos()), BusiUnitTypeEnum.SO);
context.setActionName("APPROVE");
context.setTrantype("32-02");
context.setBatch(false);
context.setBatchUserObj(new PfUserObject[] { new PfUserObject() });
context.setBatchUserObj(new PfUserObject[]{new PfUserObject()});
IBatchRunScriptService service = (IBatchRunScriptService) NCLocator.getInstance()
.lookup(IBatchRunScriptService.class);
SCMScriptResultDTO result = service.runBacth(context, SaleInvoiceVO.class);
@ -139,8 +140,12 @@ public class saveCommitAction extends AbstractNCCRestResource {
.lookup(ISaleInvoiceToTaxInvService.class);
invoiceService.issueTaxInvoice(saleInvoiceVO, "1");
return r != null ? ResultMessageUtil.toJSON(r.getDesc(), "0")
: ResultMessageUtil.exceptionToJSON(new NullPointerException("未知异常"));
JSONObject desc = r.getDesc();
if (desc != null) {
// 发票的全部信息都返回给合同平台
desc.put("vos", saleInvoiceVO);
}
return ResultMessageUtil.toJSON(desc, "0");
} catch (Exception e) {
return ResultMessageUtil.exceptionToJSON(e);
}
@ -198,11 +203,12 @@ public class saveCommitAction extends AbstractNCCRestResource {
// billhead.put("ctrantypeid", "32-02");//发票类型
billhead.put("fbuysellflag", "1");// 购销类型
billhead.put("creator", "BIP");// 创建人
billhead.put("corigcurrencyid", "CNY");// 币种
billhead.put("ccurrencyid", "CNY");// 本位币
billhead.put("corigcurrencyid", "CNY");// 币种
billhead.put("nexchangerate", 1);// 折本汇率
billhead.put("btriatradeflag", 0);// 三角贸易
JSONObject newItem = new JSONObject();
JSONObject otherJson = new JSONObject();
JSONArray csaleinvoicebid = new JSONArray();
// 遍历原始数据中的 csaleinvoicebid 数组
for (int i = 0; i < originalJson.getJSONObject("billhead").getJSONArray("csaleinvoicebid").size(); i++) {
@ -276,6 +282,13 @@ public class saveCommitAction extends AbstractNCCRestResource {
// // 主含税净价 = 含税单价原始
// BigDecimal norigtaxnetprice = norigtaxprice;
// 从销售订单中获取币种
String currencycode = getString_TrimAsNull(value2.get("currencycode"));
otherJson.put("corigcurrencyid", currencycode.isEmpty() ? "CNY" : currencycode);
// 从销售订单中获取折本汇率
BigDecimal nexchangerate = getUFDouble_NullAsZero(value2.get("nexchangerate")).toBigDecimal();
otherJson.put("nexchangerate", nexchangerate);
// 输入参数从你的 item 获取各个字段
BigDecimal nastnum = new BigDecimal(item.getString("nastnum")); // 数量
nastnum = nastnum.setScale(4, RoundingMode.HALF_UP);
@ -306,10 +319,20 @@ public class saveCommitAction extends AbstractNCCRestResource {
// 主无税净价即不含税单价
BigDecimal norignetprice = nqtorigprice;
// 本币(人民币)需要处理汇率金额保留两位小数单价保留4位小数
// 本币无税金额
BigDecimal nmny = norigmny.multiply(nexchangerate).setScale(2, RoundingMode.HALF_UP);
// 主本币无税净价
BigDecimal nnetprice = norignetprice.multiply(nexchangerate).setScale(4, RoundingMode.HALF_UP);
// 本币价税合计 价税合计*汇率
BigDecimal ntaxmny = norigtaxmny.multiply(nexchangerate).setScale(2, RoundingMode.HALF_UP);
// 税额
ntax = ntaxmny.subtract(nmny).setScale(2, RoundingMode.HALF_UP);
itemDetails.put("nqtorigprice", nqtorigprice);// 无税单价
itemDetails.put("norigprice", nqtorigprice);// 主无税单价
itemDetails.put("norigmny", norigmny);// 无税金额
itemDetails.put("nmny", norigmny);// 本币无税金额
itemDetails.put("nmny", nmny);// 本币无税金额
itemDetails.put("norigtaxmny", norigtaxmny);// 价税合计
itemDetails.put("norigtaxprice", norigtaxprice);// 主含税单价
itemDetails.put("norignetprice", norignetprice);// 主无税净价
@ -317,13 +340,18 @@ public class saveCommitAction extends AbstractNCCRestResource {
itemDetails.put("ntax", ntax);// 税额
itemDetails.put("ncaltaxmny", ncaltaxmny);// 计税金额
itemDetails.put("norigtaxnetprice", norigtaxnetprice);// 主含税净价
itemDetails.put("nnetprice", norignetprice);// 主本币无税净价
itemDetails.put("ntaxmny", norigtaxmny);// 本币价税合计
itemDetails.put("nnetprice", nnetprice);// 主本币无税净价
itemDetails.put("ntaxmny", ntaxmny);// 本币价税合计
csaleinvoicebid.add(itemDetails);
}
newItem.put("item", csaleinvoicebid);
billhead.put("csaleinvoicebid", newItem);
if (otherJson != null && !otherJson.isEmpty()) {
// 查询销售订单中的币种和汇率
billhead.put("corigcurrencyid", otherJson.get("corigcurrencyid"));// 币种
billhead.put("nexchangerate", otherJson.get("nexchangerate"));// 折本汇率
}
bill.put("billhead", billhead);
bill.put("id", "");
// bill 数组添加到 ufinterface
@ -363,13 +391,35 @@ public class saveCommitAction extends AbstractNCCRestResource {
private static Map<String, Object> getSaleorderVo(String csourcebillbidStr) throws BusinessException {
IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class);
String sql = " select s.vbillcode,s.csaleorderid,sb.csaleorderbid,sb.crowno,sb.blargessflag from so_saleorder_b sb\n"
+ "inner join so_saleorder s on sb.csaleorderid=s.csaleorderid\n" + "where sb.csaleorderbid='"
+ csourcebillbidStr + "' ";
String sql = " select s.vbillcode,s.csaleorderid, s.corigcurrencyid," +
" sb.csaleorderbid,sb.crowno,sb.blargessflag,sb.nexchangerate," +
" bdc.code currencycode" +
" from so_saleorder_b sb" +
" inner join so_saleorder s on sb.csaleorderid=s.csaleorderid" +
" left join bd_currtype bdc on s.corigcurrencyid=bdc.pk_currtype" +
" where sb.csaleorderbid='" + csourcebillbidStr + "' ";
Map<String, Object> value2 = (Map<String, Object>) queryBS.executeQuery(sql, new MapProcessor());
return value2;
}
private static String getString_TrimAsNull(Object value) {
if ((value == null) || (value.toString().trim().isEmpty())) {
return "";
}
return value.toString().trim();
}
private static UFDouble getUFDouble_NullAsZero(Object value) {
if ((value == null) || (value.toString().trim().isEmpty()) || (value.toString().trim().equals("~")))
return UFDouble.ONE_DBL;
if ((value instanceof UFDouble))
return (UFDouble) value;
if ((value instanceof BigDecimal)) {
return new UFDouble((BigDecimal) value);
}
return new UFDouble(value.toString().trim());
}
public IUAPQueryBS getQueryService() {
return NCLocator.getInstance().lookup(IUAPQueryBS.class);
}