using GXWebApi.Common;
using Kingdee.BOS.WebApi.Client;
using log4net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Web.Http;
namespace GXWebApi.Controllers
{
public class ProcurementController : ApiController
{
private static readonly ILog Logger = LogManager.GetLogger(typeof(ProcurementController));
#region 屏蔽清单(2026-10-31 改为数据库配置表)
///
/// 屏蔽条件:从 OA 库 blocked_lcbh 表动态读取 active=1 的单号。
/// 加新屏蔽号:INSERT INTO blocked_lcbh (lcbh, reason, create_by) VALUES ('YFCGSQ-...', '原因', 'GS');
/// 无需改代码、无需重启,下次查询自动生效。
/// 历史硬编码 30 个单号已迁移至 blocked_lcbh 表。
///
private static readonly string BlockedLcbhNotInClause =
"S.lcbh NOT IN (SELECT lcbh FROM blocked_lcbh WHERE active=1)";
///
/// wheres 动态拼接列表里追加屏蔽条件(MySQL SQL)。
///
private static void AddBlockedLcbhFilter(List wheres)
{
wheres.Add(BlockedLcbhNotInClause);
}
#endregion
#region 金蝶登录配置
private K3CloudApiClient GetKingdeeClient()
{
string acctID = "20191111204222978";
string userID = "sysmes";
string password = "Admin@123";
string erpURL = "https://gaoxian.ik3cloud.com/k3cloud/";
int erpLaType = 2052;
K3CloudApiClient client = new K3CloudApiClient(erpURL);
var loginResult = client.ValidateLogin(acctID, userID, password, erpLaType);
var resultType = JObject.Parse(loginResult)["LoginResultType"].Value();
if (resultType != 1)
throw new Exception("登录金蝶云星空失败!");
return client;
}
private List> ExecuteKingdeeQuery(K3CloudApiClient client, string formId, string fieldKeys, string filterString, string orderString = "", int topRowCount = 0, int startRow = 0, int limit = 5000)
{
JObject queryData = new JObject
{
["FormId"] = formId,
["FieldKeys"] = fieldKeys,
["OrderString"] = orderString,
["FilterString"] = filterString,
["TopRowCount"] = topRowCount,
["StartRow"] = startRow,
["Limit"] = limit
};
var result = client.ExecuteBillQuery(queryData.ToString());
if (result != null && result.Count > 0)
{
string firstCell = result[0][0].ToStringEx();
if (firstCell.StartsWith("{\""))
{
try
{
JObject errObj = JObject.Parse(firstCell);
if (errObj["Result"] != null)
{
var errors = errObj["Result"]["ResponseStatus"]?["Errors"];
if (errors != null && errors.HasValues)
{
string errMsg = errors[0]["Message"]?.ToString() ?? "金蝶查询返回错误";
throw new Exception(errMsg);
}
}
}
catch (JsonReaderException) { }
}
}
return result;
}
private string SafeGet(List