|
|
@@ -0,0 +1,521 @@
|
|
|
+package com.uas.eis.longcheer.serviceImpl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.uas.eis.core.config.SpObserver;
|
|
|
+import com.uas.eis.dao.BaseDao;
|
|
|
+import com.uas.eis.dao.SqlRowList;
|
|
|
+import com.uas.eis.longcheer.config.LongcheerConfig;
|
|
|
+import com.uas.eis.longcheer.dto.LongcheerResponse;
|
|
|
+import com.uas.eis.longcheer.entity.InventoryDetail;
|
|
|
+import com.uas.eis.longcheer.entity.InventoryPushRequest;
|
|
|
+import com.uas.eis.longcheer.entity.PoLine;
|
|
|
+import com.uas.eis.longcheer.entity.PoPushRequest;
|
|
|
+import com.uas.eis.longcheer.service.LongcheerService;
|
|
|
+import com.uas.eis.longcheer.utils.LongcheerHttpClient;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 龙旗接口对接服务实现
|
|
|
+ *
|
|
|
+ * @author ZXL
|
|
|
+ * @date 2026-06-26
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class LongcheerServiceImpl implements LongcheerService {
|
|
|
+
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(LongcheerServiceImpl.class);
|
|
|
+
|
|
|
+ /** 采购订单头表 */
|
|
|
+ private static final String TABLE_PO_HEADER = "LQPURCHASEORDER";
|
|
|
+ /** 采购订单行表 */
|
|
|
+ private static final String TABLE_PO_LINE = "LQPURCHASEORDERLINE";
|
|
|
+ /** 头表序列名 */
|
|
|
+ private static final String SEQ_PO_HEADER = "LQPO_SEQ";
|
|
|
+ /** 行表序列名 */
|
|
|
+ private static final String SEQ_PO_LINE = "LQPL_SEQ";
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private LongcheerConfig longcheerConfig;
|
|
|
+ @Autowired
|
|
|
+ private BaseDao baseDao;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public LongcheerResponse pushInventory(String master, Integer id) {
|
|
|
+ SpObserver.putSp(master);
|
|
|
+ InventoryPushRequest request = new InventoryPushRequest();
|
|
|
+ SqlRowList rs = baseDao.queryForRowSet("select * from LQINVENTORY left join LQINVENTORYDETAIL on LQI_ID = LQID_LQIID " +
|
|
|
+ "where LQI_ID = ?", id);
|
|
|
+ List<InventoryDetail> requestdets = new ArrayList<InventoryDetail>();
|
|
|
+ // 根据 master 解析 elsCode 和 supplierErpCode
|
|
|
+ String elsCode = resolveElsCode(master);
|
|
|
+ String supplierErpCode = resolveSupplierErpCode(master);
|
|
|
+ logger.info("[龙旗接口]库存推送动态解析,master={},elsCode={},supplierErpCode={}",
|
|
|
+ master, elsCode, supplierErpCode);
|
|
|
+ request.setElsCode(elsCode);
|
|
|
+ request.setSupplierErpCode(supplierErpCode);
|
|
|
+ while (rs.next()) {
|
|
|
+ InventoryDetail requestdet = new InventoryDetail();
|
|
|
+ // 龙旗物料编码(必填)
|
|
|
+ requestdet.setLongCheerMaterialCode(rs.getGeneralString("lqid_lqprcode"));
|
|
|
+ // 原厂未结PO数
|
|
|
+ requestdet.setUnClosedPo(String.valueOf(rs.getInt("lqid_poqty")));
|
|
|
+ // 供应商库存数量
|
|
|
+ requestdet.setSupplierInventory(String.valueOf(rs.getInt("lqid_kcqty")));
|
|
|
+ requestdets.add(requestdet);
|
|
|
+ }
|
|
|
+ request.setInventoryDetails(requestdets);
|
|
|
+
|
|
|
+ // 调用龙旗接口
|
|
|
+ String url = longcheerConfig.getInventory().getUrl();
|
|
|
+ // 需要提供
|
|
|
+ String appKey = longcheerConfig.getInventory().getAppKey();
|
|
|
+ String appSecret = longcheerConfig.getInventory().getAppSecret();
|
|
|
+
|
|
|
+ String requestBody = JSON.toJSONString(request);
|
|
|
+ logger.info("[龙旗接口]调用库存同步接口,url={}", url);
|
|
|
+
|
|
|
+ String responseBody = LongcheerHttpClient.post(url, appKey, appSecret, requestBody,
|
|
|
+ longcheerConfig.getTimeout(), longcheerConfig.getRetryTimes(), longcheerConfig.getRetryInterval());
|
|
|
+
|
|
|
+ return JSON.parseObject(responseBody, LongcheerResponse.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 接口02:接收龙旗推送的采购订单数据并入库
|
|
|
+ * 龙旗 → 供应商(本系统为接收方)
|
|
|
+ * <p>
|
|
|
+ * 账套定位优先级:
|
|
|
+ * 1) request.master(URL 传入,兼容旧调用方)
|
|
|
+ * 2) longcheerConfig.accountMapping.get(request.elsAccount)
|
|
|
+ * 3) 上述都没匹配上时返回 400 报错
|
|
|
+ *
|
|
|
+ * @param request 龙旗推送的采购订单数据
|
|
|
+ * @return 统一响应
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public LongcheerResponse receivePo(PoPushRequest request) {
|
|
|
+ logger.info("[龙旗接口]接收到采购订单推送,erpOrderNumber={},elsAccount={},supplierCode={}",
|
|
|
+ request.getErpOrderNumber(), request.getElsAccount(), request.getSupplierCode());
|
|
|
+
|
|
|
+ // 必填字段校验
|
|
|
+ String validateMsg = validatePoRequest(request);
|
|
|
+ if (validateMsg != null) {
|
|
|
+ return new LongcheerResponse(400, validateMsg, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 账套定位:master 优先,其次按 elsAccount 在配置里查映射
|
|
|
+ String master = resolveMaster(request);
|
|
|
+ if (isBlank(master)) {
|
|
|
+ logger.warn("[龙旗接口]无法定位账套,erpOrderNumber={},elsAccount={}",
|
|
|
+ request.getErpOrderNumber(), request.getElsAccount());
|
|
|
+ return new LongcheerResponse(400,
|
|
|
+ "无法定位账套:URL未传master且elsAccount未配置映射关系,请联系管理员", false);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 切换到对应账套数据源
|
|
|
+ SpObserver.putSp(master);
|
|
|
+
|
|
|
+ // 检查订单是否已存在(按 erpOrderNumber 去重)
|
|
|
+ boolean exists = baseDao.checkIf(TABLE_PO_HEADER,
|
|
|
+ "LQPO_ERPORDERNUMBER = '" + request.getErpOrderNumber().replace("'", "''") + "'");
|
|
|
+
|
|
|
+ if (exists) {
|
|
|
+ // 订单已存在,执行更新
|
|
|
+ int poId = updatePoHeader(request);
|
|
|
+ // 先删除旧明细,再重新插入
|
|
|
+ baseDao.deleteByCondition(TABLE_PO_LINE, "LQPL_POID = " + poId);
|
|
|
+ insertPoLines(poId, request.getPoLines());
|
|
|
+ //插入订单表
|
|
|
+ int said = baseDao.getSeqId("Sale_SEQ");
|
|
|
+ String sacode = baseDao.sGetMaxNumber("Sale",2);
|
|
|
+ baseDao.execute("insert into sale(sa_id,sa_code,sa_pocode,sa_date,sa_kind,sa_currency,sa_rate,sa_custcode,sa_custname,sa_apcustcode,sa_apcustname, " +
|
|
|
+ "sa_paymentscode,sa_payments,sa_sellercode,sa_seller,sa_departmentcode,sa_departmentname,sa_status,sa_statuscode,sa_recorder,sa_recorddate,SA_POID_USER) " +
|
|
|
+ "select "+said+",'"+sacode+"',LQPO_ERPORDERNUMBER,to_date(LQPO_ORDERDATE,'yyyy-mm-dd'),LQPO_ORDERTYPE,LQPO_CURRENCY,cm_crrate,cu_code,cu_name,cu_arcode,cu_arname, " +
|
|
|
+ "cu_paymentscode,cu_payments,cu_sellercode,cu_sellername,em_departmentcode,em_depart,'在录入','ENTERING','管理员',sysdate,LQPO_ID " +
|
|
|
+ "from LQPURCHASEORDER left join (select * from CUSTOMTABLE left join CUSTOMTABLEDETAIL on ct_id = cd_ctid where ct_caller='LQCustomerDZ' and ct_status = '已审核') on cd_varchar50_1 = LQPO_COMPANYCODE " +
|
|
|
+ "left join Customer on cu_code = cd_varchar50_2 left join CurrencysMonth on cm_crname = LQPO_CURRENCY and cm_yearmonth = to_char(to_date(LQPO_ORDERDATE,'yyyy-mm-dd'),'yyyymm') " +
|
|
|
+ "left join employee on em_code = cu_sellercode where LQPO_ID = " + poId);
|
|
|
+ baseDao.execute("insert into saledetail (sd_id,sd_said,sd_code,sd_detno,sd_prodcode,sd_custprodcode,sd_qty,sd_price,sd_total,sd_taxrate,sd_costprice,sd_taxtotal,sd_delivery)" +
|
|
|
+ "select Saledetail_SEQ.nextval,"+said+",'"+sacode+"',LQPL_ERPORDERLINENO,cd_varchar50_1,LQPL_MATERIALNUMBER,LQPL_QUANTITY,0,0,0,LQPL_NETPRICE,LQPL_NETAMOUNT,to_date(LQPL_REPLYDATE,'yyyy-mm-dd') " +
|
|
|
+ "from LQPURCHASEORDERLINE left join (select * from CUSTOMTABLE left join CUSTOMTABLEDETAIL on ct_id = cd_ctid where ct_caller='LQProductDZ' and ct_status = '已审核') on cd_varchar50_2 = LQPL_MATERIALNUMBER ");
|
|
|
+ baseDao.execute("update saledetail set sd_taxrate = (select cu_taxrate from sale left join Customer on sa_custcode = cu_code where sa_id = sd_said) where sd_said = " + said);
|
|
|
+ baseDao.execute("update saledetail set sd_price = round(sd_costprice * (1 + sd_taxrate / 100),8) where sd_said = " + said);
|
|
|
+ baseDao.execute("update saledetail set sd_total = round(sd_qty * sd_price,2) where sd_said = " + said);
|
|
|
+ logger.info("[龙旗接口]采购订单更新成功,erpOrderNumber={},poId={},明细数={}",
|
|
|
+ request.getErpOrderNumber(), poId, request.getPoLines().size());
|
|
|
+ } else {
|
|
|
+ // 新订单,执行插入
|
|
|
+ int poId = baseDao.getSeqId(SEQ_PO_HEADER);
|
|
|
+ insertPoHeader(poId, request);
|
|
|
+ insertPoLines(poId, request.getPoLines());
|
|
|
+ //插入订单表
|
|
|
+ int said = baseDao.getSeqId("Sale_SEQ");
|
|
|
+ String sacode = baseDao.sGetMaxNumber("Sale",2);
|
|
|
+ baseDao.execute("insert into sale(sa_id,sa_code,sa_pocode,sa_date,sa_kind,sa_currency,sa_rate,sa_custcode,sa_custname,sa_apcustcode,sa_apcustname, " +
|
|
|
+ "sa_paymentscode,sa_payments,sa_sellercode,sa_seller,sa_departmentcode,sa_departmentname,sa_status,sa_statuscode,sa_recorder,sa_recorddate,SA_POID_USER) " +
|
|
|
+ "select "+said+",'"+sacode+"',LQPO_ERPORDERNUMBER,to_date(LQPO_ORDERDATE,'yyyy-mm-dd'),LQPO_ORDERTYPE,LQPO_CURRENCY,cm_crrate,cu_code,cu_name,cu_arcode,cu_arname, " +
|
|
|
+ "cu_paymentscode,cu_payments,cu_sellercode,cu_sellername,em_departmentcode,em_depart,'在录入','ENTERING','管理员',sysdate,LQPO_ID " +
|
|
|
+ "from LQPURCHASEORDER left join (select * from CUSTOMTABLE left join CUSTOMTABLEDETAIL on ct_id = cd_ctid where ct_caller='LQCustomerDZ' and ct_status = '已审核') on cd_varchar50_1 = LQPO_COMPANYCODE " +
|
|
|
+ "left join Customer on cu_code = cd_varchar50_2 left join CurrencysMonth on cm_crname = LQPO_CURRENCY and cm_yearmonth = to_char(to_date(LQPO_ORDERDATE,'yyyy-mm-dd'),'yyyymm') " +
|
|
|
+ "left join employee on em_code = cu_sellercode where LQPO_ID = " + poId);
|
|
|
+ baseDao.execute("insert into saledetail (sd_id,sd_said,sd_code,sd_detno,sd_prodcode,sd_custprodcode,sd_qty,sd_price,sd_total,sd_taxrate,sd_costprice,sd_taxtotal,sd_delivery)" +
|
|
|
+ "select Saledetail_SEQ.nextval,"+said+",'"+sacode+"',LQPL_ERPORDERLINENO,cd_varchar50_1,LQPL_MATERIALNUMBER,LQPL_QUANTITY,0,0,0,LQPL_NETPRICE,LQPL_NETAMOUNT,to_date(LQPL_REPLYDATE,'yyyy-mm-dd') " +
|
|
|
+ "from LQPURCHASEORDERLINE left join (select * from CUSTOMTABLE left join CUSTOMTABLEDETAIL on ct_id = cd_ctid where ct_caller='LQProductDZ' and ct_status = '已审核') on cd_varchar50_2 = LQPL_MATERIALNUMBER ");
|
|
|
+ baseDao.execute("update saledetail set sd_taxrate = (select cu_taxrate from sale left join Customer on sa_custcode = cu_code where sa_id = sd_said) where sd_said = " + said);
|
|
|
+ baseDao.execute("update saledetail set sd_price = round(sd_costprice * (1 + sd_taxrate / 100),8) where sd_said = " + said);
|
|
|
+ baseDao.execute("update saledetail set sd_total = round(sd_qty * sd_price,2) where sd_said = " + said);
|
|
|
+ logger.info("[龙旗接口]采购订单新增成功,erpOrderNumber={},poId={},明细数={}",
|
|
|
+ request.getErpOrderNumber(), poId, request.getPoLines().size());
|
|
|
+ }
|
|
|
+
|
|
|
+ return new LongcheerResponse(200, "操作成功!", true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验采购订单必填字段
|
|
|
+ *
|
|
|
+ * @param request 采购订单请求
|
|
|
+ * @return 校验失败返回错误信息,校验通过返回 null
|
|
|
+ */
|
|
|
+ private String validatePoRequest(PoPushRequest request) {
|
|
|
+ if (request == null) {
|
|
|
+ return "请求体不能为空";
|
|
|
+ }
|
|
|
+ if (isBlank(request.getErpOrderNumber())) {
|
|
|
+ return "ERP订单号(erpOrderNumber)不能为空";
|
|
|
+ }
|
|
|
+ if (isBlank(request.getElsAccount())) {
|
|
|
+ return "ELS账号(elsAccount)不能为空";
|
|
|
+ }
|
|
|
+ if (isBlank(request.getSupplierCode())) {
|
|
|
+ return "供应商编号(supplierCode)不能为空";
|
|
|
+ }
|
|
|
+ if (isBlank(request.getCompanyCode())) {
|
|
|
+ return "业务实体(companyCode)不能为空";
|
|
|
+ }
|
|
|
+ if (isBlank(request.getOrderType())) {
|
|
|
+ return "订单类型(orderType)不能为空";
|
|
|
+ }
|
|
|
+ if (isBlank(request.getOrderStatus())) {
|
|
|
+ return "订单状态(orderStatus)不能为空";
|
|
|
+ }
|
|
|
+ if (isBlank(request.getSupplierLocation())) {
|
|
|
+ return "供应商地点(supplierLocation)不能为空";
|
|
|
+ }
|
|
|
+ if (isBlank(request.getCurrency())) {
|
|
|
+ return "币别(currency)不能为空";
|
|
|
+ }
|
|
|
+ if (isBlank(request.getPurchasePrincipal())) {
|
|
|
+ return "采购员(purchasePrincipal)不能为空";
|
|
|
+ }
|
|
|
+ if (isBlank(request.getOrderDate())) {
|
|
|
+ return "订单日期(orderDate)不能为空";
|
|
|
+ }
|
|
|
+ if (request.getPoLines() == null || request.getPoLines().isEmpty()) {
|
|
|
+ return "订单明细(poLines)不能为空";
|
|
|
+ }
|
|
|
+ // 校验每行明细
|
|
|
+ for (int i = 0; i < request.getPoLines().size(); i++) {
|
|
|
+ PoLine line = request.getPoLines().get(i);
|
|
|
+ String prefix = "第" + (i + 1) + "行明细:";
|
|
|
+ if (isBlank(line.getErpOrderLineNo())) {
|
|
|
+ return prefix + "ERP行号(erpOrderLineNo)不能为空";
|
|
|
+ }
|
|
|
+ if (isBlank(line.getFactory())) {
|
|
|
+ return prefix + "库存组织代码(factory)不能为空";
|
|
|
+ }
|
|
|
+ if (isBlank(line.getMaterialNumber())) {
|
|
|
+ return prefix + "物料编码(materialNumber)不能为空";
|
|
|
+ }
|
|
|
+ if (isBlank(line.getManufacturer())) {
|
|
|
+ return prefix + "生产厂家(manufacturer)不能为空";
|
|
|
+ }
|
|
|
+ if (isBlank(line.getRequireDate())) {
|
|
|
+ return prefix + "要求交期(requireDate)不能为空";
|
|
|
+ }
|
|
|
+ if (line.getQuantity() == null) {
|
|
|
+ return prefix + "数量(quantity)不能为空";
|
|
|
+ }
|
|
|
+ if (isBlank(line.getPurchaseUnit())) {
|
|
|
+ return prefix + "采购单位(purchaseUnit)不能为空";
|
|
|
+ }
|
|
|
+ if (line.getNetPrice() == null) {
|
|
|
+ return prefix + "未税单价(netPrice)不能为空";
|
|
|
+ }
|
|
|
+ if (line.getNetAmount() == null) {
|
|
|
+ return prefix + "未税金额(netAmount)不能为空";
|
|
|
+ }
|
|
|
+ if (isBlank(line.getPurchaseType())) {
|
|
|
+ return prefix + "采购类型(purchaseType)不能为空";
|
|
|
+ }
|
|
|
+ if (isBlank(line.getPlaceReceipt())) {
|
|
|
+ return prefix + "收货地点(placeReceipt)不能为空";
|
|
|
+ }
|
|
|
+ if (isBlank(line.getDeliveryAddress())) {
|
|
|
+ return prefix + "交货地址(deliveryAddress)不能为空";
|
|
|
+ }
|
|
|
+ if (isBlank(line.getReceiveContact())) {
|
|
|
+ return prefix + "收货联系人(receiveContact)不能为空";
|
|
|
+ }
|
|
|
+ if (isBlank(line.getReceivePhone())) {
|
|
|
+ return prefix + "收货联系电话(receivePhone)不能为空";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增采购订单头
|
|
|
+ *
|
|
|
+ * @param poId 主键ID
|
|
|
+ * @param request 采购订单请求
|
|
|
+ */
|
|
|
+ private void insertPoHeader(int poId, PoPushRequest request) {
|
|
|
+ String sql = "insert into " + TABLE_PO_HEADER + " ("
|
|
|
+ + "LQPO_ID, LQPO_ERPORDERNUMBER, LQPO_ELSACCOUNT, LQPO_SUPPLIERCODE, LQPO_SUPPLIERNAME, "
|
|
|
+ + "LQPO_COMPANYCODE, LQPO_ORDERTYPE, LQPO_ORDERSTATUS, LQPO_IFGIVEAWAY, LQPO_SUPPLIERLOCATION, "
|
|
|
+ + "LQPO_CURRENCY, LQPO_CUSTOMER, LQPO_HEADERPROJECTNAME, LQPO_BACKSO, LQPO_GTSNO, "
|
|
|
+ + "LQPO_GTSDELIVERYADDRESS, LQPO_PURCHASEREMARK, LQPO_PURCHASEPRINCIPAL, LQPO_ORDERDATE, "
|
|
|
+ + "LQPO_STATUS, LQPO_RECEIVETIME"
|
|
|
+ + ") values (?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, sysdate)";
|
|
|
+
|
|
|
+ baseDao.execute(sql,
|
|
|
+ poId,
|
|
|
+ request.getErpOrderNumber(),
|
|
|
+ request.getElsAccount(),
|
|
|
+ request.getSupplierCode(),
|
|
|
+ request.getSupplierName(),
|
|
|
+ request.getCompanyCode(),
|
|
|
+ request.getOrderType(),
|
|
|
+ request.getOrderStatus(),
|
|
|
+ request.getIfGiveaway(),
|
|
|
+ request.getSupplierLocation(),
|
|
|
+ request.getCurrency(),
|
|
|
+ request.getCustomer(),
|
|
|
+ request.getHeaderProjectName(),
|
|
|
+ request.getBackSo(),
|
|
|
+ request.getGtsNo(),
|
|
|
+ request.getGtsDeliveryAddress(),
|
|
|
+ request.getPurchaseRemark(),
|
|
|
+ request.getPurchasePrincipal(),
|
|
|
+ request.getOrderDate(),
|
|
|
+ "待处理"
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新采购订单头(订单已存在时)
|
|
|
+ *
|
|
|
+ * @param request 采购订单请求
|
|
|
+ * @return 订单主键ID
|
|
|
+ */
|
|
|
+ private int updatePoHeader(PoPushRequest request) {
|
|
|
+ // 查询已存在订单的ID
|
|
|
+ SqlRowList rs = baseDao.queryForRowSet(
|
|
|
+ "select LQPO_ID from " + TABLE_PO_HEADER
|
|
|
+ + " where LQPO_ERPORDERNUMBER = ?", request.getErpOrderNumber());
|
|
|
+ int poId = 0;
|
|
|
+ if (rs.next()) {
|
|
|
+ poId = rs.getInt("LQPO_ID");
|
|
|
+ }
|
|
|
+
|
|
|
+ String sql = "update " + TABLE_PO_HEADER + " set "
|
|
|
+ + "LQPO_ELSACCOUNT = ?, LQPO_SUPPLIERCODE = ?, LQPO_SUPPLIERNAME = ?, "
|
|
|
+ + "LQPO_COMPANYCODE = ?, LQPO_ORDERTYPE = ?, LQPO_ORDERSTATUS = ?, LQPO_IFGIVEAWAY = ?, "
|
|
|
+ + "LQPO_SUPPLIERLOCATION = ?, LQPO_CURRENCY = ?, LQPO_CUSTOMER = ?, "
|
|
|
+ + "LQPO_HEADERPROJECTNAME = ?, LQPO_BACKSO = ?, LQPO_GTSNO = ?, "
|
|
|
+ + "LQPO_GTSDELIVERYADDRESS = ?, LQPO_PURCHASEREMARK = ?, LQPO_PURCHASEPRINCIPAL = ?, "
|
|
|
+ + "LQPO_ORDERDATE = ?, LQPO_STATUS = ?, LQPO_RECEIVETIME = sysdate "
|
|
|
+ + "where LQPO_ID = ?";
|
|
|
+
|
|
|
+ baseDao.execute(sql,
|
|
|
+ request.getElsAccount(),
|
|
|
+ request.getSupplierCode(),
|
|
|
+ request.getSupplierName(),
|
|
|
+ request.getCompanyCode(),
|
|
|
+ request.getOrderType(),
|
|
|
+ request.getOrderStatus(),
|
|
|
+ request.getIfGiveaway(),
|
|
|
+ request.getSupplierLocation(),
|
|
|
+ request.getCurrency(),
|
|
|
+ request.getCustomer(),
|
|
|
+ request.getHeaderProjectName(),
|
|
|
+ request.getBackSo(),
|
|
|
+ request.getGtsNo(),
|
|
|
+ request.getGtsDeliveryAddress(),
|
|
|
+ request.getPurchaseRemark(),
|
|
|
+ request.getPurchasePrincipal(),
|
|
|
+ request.getOrderDate(),
|
|
|
+ "待处理",
|
|
|
+ poId
|
|
|
+ );
|
|
|
+
|
|
|
+ return poId;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量插入采购订单明细
|
|
|
+ *
|
|
|
+ * @param poId 订单主键ID
|
|
|
+ * @param lines 明细列表
|
|
|
+ */
|
|
|
+ private void insertPoLines(int poId, List<PoLine> lines) {
|
|
|
+ String sql = "insert into " + TABLE_PO_LINE + " ("
|
|
|
+ + "LQPL_ID, LQPL_POID, LQPL_ERPORDERLINENO, LQPL_FACTORY, LQPL_FACTORYNAME, "
|
|
|
+ + "LQPL_MATERIALNUMBER, LQPL_MATERIALSPEC, LQPL_MATERIALDESC, LQPL_MANUFACTURER, "
|
|
|
+ + "LQPL_REQUIREDATE, LQPL_QUANTITY, LQPL_PURCHASEUNIT, LQPL_NETPRICE, LQPL_NETAMOUNT, "
|
|
|
+ + "LQPL_PURCHASETYPE, LQPL_REPLYDATE, LQPL_PLACERECEIPT, LQPL_DELIVERYADDRESS, "
|
|
|
+ + "LQPL_ISCLOSE, LQPL_LINEPROJECTNUMBER, LQPL_RECEIVECONTACT, LQPL_RECEIVEPHONE"
|
|
|
+ + ") values (?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?, ?,?,?,?)";
|
|
|
+
|
|
|
+ for (PoLine line : lines) {
|
|
|
+ int lineId = baseDao.getSeqId(SEQ_PO_LINE);
|
|
|
+ /*System.out.println(showSql(sql,lineId,
|
|
|
+ poId,
|
|
|
+ line.getErpOrderLineNo(),
|
|
|
+ line.getFactory(),
|
|
|
+ line.getFactoryName(),
|
|
|
+ line.getMaterialNumber(),
|
|
|
+ line.getMaterialSpec(),
|
|
|
+ line.getMaterialDesc(),
|
|
|
+ line.getManufacturer(),
|
|
|
+ line.getRequireDate(),
|
|
|
+ line.getQuantity(),
|
|
|
+ line.getPurchaseUnit(),
|
|
|
+ line.getNetPrice(),
|
|
|
+ line.getNetAmount(),
|
|
|
+ line.getPurchaseType(),
|
|
|
+ line.getReplyDate(),
|
|
|
+ line.getPlaceReceipt(),
|
|
|
+ line.getDeliveryAddress(),
|
|
|
+ line.getIsClose(),
|
|
|
+ line.getLineProjectNumber(),
|
|
|
+ line.getReceiveContact(),
|
|
|
+ line.getReceivePhone()));*/
|
|
|
+ baseDao.execute(sql,
|
|
|
+ lineId,
|
|
|
+ poId,
|
|
|
+ line.getErpOrderLineNo(),
|
|
|
+ line.getFactory(),
|
|
|
+ line.getFactoryName(),
|
|
|
+ line.getMaterialNumber(),
|
|
|
+ line.getMaterialSpec(),
|
|
|
+ line.getMaterialDesc(),
|
|
|
+ line.getManufacturer(),
|
|
|
+ line.getRequireDate(),
|
|
|
+ line.getQuantity(),
|
|
|
+ line.getPurchaseUnit(),
|
|
|
+ line.getNetPrice(),
|
|
|
+ line.getNetAmount(),
|
|
|
+ line.getPurchaseType(),
|
|
|
+ line.getReplyDate(),
|
|
|
+ line.getPlaceReceipt(),
|
|
|
+ line.getDeliveryAddress(),
|
|
|
+ line.getIsClose(),
|
|
|
+ line.getLineProjectNumber(),
|
|
|
+ line.getReceiveContact(),
|
|
|
+ line.getReceivePhone()
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String showSql(String sql, Object... params) {
|
|
|
+ for (Object param : params) {
|
|
|
+ if (param == null) {
|
|
|
+ sql = sql.replaceFirst("\\?", "NULL");
|
|
|
+ } else if (param instanceof Number) {
|
|
|
+ sql = sql.replaceFirst("\\?", param.toString());
|
|
|
+ } else {
|
|
|
+ sql = sql.replaceFirst("\\?",
|
|
|
+ "'" + param.toString().replace("'", "''") + "'");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sql;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析账套标识
|
|
|
+ * 优先级:URL master > yml accountMapping[elsAccount]
|
|
|
+ *
|
|
|
+ * @param request 采购订单请求
|
|
|
+ * @return 账套标识,未匹配到返回 null
|
|
|
+ */
|
|
|
+ private String resolveMaster(PoPushRequest request) {
|
|
|
+ // 1. URL 上的 master 优先
|
|
|
+ if (!isBlank(request.getMaster())) {
|
|
|
+ return request.getMaster().trim();
|
|
|
+ }
|
|
|
+ // 2. 按 elsAccount 查配置映射
|
|
|
+ if (longcheerConfig != null && longcheerConfig.getAccountMapping() != null
|
|
|
+ && !isBlank(request.getElsAccount())) {
|
|
|
+ String mapped = longcheerConfig.getAccountMapping().get(request.getElsAccount().trim());
|
|
|
+ if (!isBlank(mapped)) {
|
|
|
+ logger.info("[龙旗接口]按elsAccount自动映射账套,elsAccount={},master={}",
|
|
|
+ request.getElsAccount(), mapped);
|
|
|
+ return mapped.trim();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据 master 解析对应的 elsCode(ELS 账号)
|
|
|
+ * 通过 accountMapping 反向查找(value → key)
|
|
|
+ *
|
|
|
+ * @param master 租户标识
|
|
|
+ * @return elsCode,未匹配到返回空串
|
|
|
+ */
|
|
|
+ private String resolveElsCode(String master) {
|
|
|
+ if (isBlank(master) || longcheerConfig == null
|
|
|
+ || longcheerConfig.getAccountMapping() == null
|
|
|
+ || longcheerConfig.getAccountMapping().isEmpty()) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ String trimmed = master.trim();
|
|
|
+ for (java.util.Map.Entry<String, String> entry : longcheerConfig.getAccountMapping().entrySet()) {
|
|
|
+ if (entry.getValue() != null && trimmed.equalsIgnoreCase(entry.getValue().trim())) {
|
|
|
+ return entry.getKey();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ logger.warn("[龙旗接口]未找到master对应的elsCode,master={}", master);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据 master 解析对应的 supplierErpCode(供应商 ERP 编码)
|
|
|
+ * 查 supplierMapping(key=master, value=supplierErpCode)
|
|
|
+ *
|
|
|
+ * @param master 租户标识
|
|
|
+ * @return supplierErpCode,未匹配到返回空串
|
|
|
+ */
|
|
|
+ private String resolveSupplierErpCode(String master) {
|
|
|
+ if (isBlank(master) || longcheerConfig == null
|
|
|
+ || longcheerConfig.getSupplierMapping() == null
|
|
|
+ || longcheerConfig.getSupplierMapping().isEmpty()) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ String mapped = longcheerConfig.getSupplierMapping().get(master.trim());
|
|
|
+ if (isBlank(mapped)) {
|
|
|
+ logger.warn("[龙旗接口]未找到master对应的supplierErpCode,master={}", master);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ return mapped.trim();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断字符串是否为空
|
|
|
+ *
|
|
|
+ * @param str 字符串
|
|
|
+ * @return true 表示为空
|
|
|
+ */
|
|
|
+ private boolean isBlank(String str) {
|
|
|
+ return str == null || str.trim().isEmpty();
|
|
|
+ }
|
|
|
+}
|