501 lines
17 KiB
C#
501 lines
17 KiB
C#
using log4net;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using System.Threading.Tasks;
|
|
using UFIDA.U8.Framework.Api.ControlObject.Common;
|
|
using UFIDA.U8.Framework.Api.ControlObject.Entity;
|
|
using UFIDA.U8.Framework.Api.ControlObject.Json;
|
|
using UFSoft.U8.Framework.BizBase;
|
|
using UFSoft.U8.Framework.ContextSrv;
|
|
using UFSoft.U8.U8M.BFDispatcher;
|
|
using UFSoft.U8.U8M.Common;
|
|
using UFSoft.U8.U8M.DAC;
|
|
using UFSoft.U8.U8M.DOSchema.SF;
|
|
using UFSoft.U8.U8M.Exceptions;
|
|
|
|
// ReSharper disable IdentifierTypo
|
|
// ReSharper disable InconsistentNaming
|
|
// ReSharper disable StringLiteralTypo
|
|
|
|
namespace UFIDA.U8.Framework.Api.ControlObject.U8M
|
|
{
|
|
/// <summary>
|
|
/// 报工单
|
|
/// </summary>
|
|
public class MoRoutingBill : IBaseBF
|
|
{
|
|
//日志组件
|
|
private readonly ILog _logInfo = LogManager.GetLogger("logInfo");
|
|
|
|
/// <summary>
|
|
/// 获取空数据源
|
|
/// </summary>
|
|
/// <param name="callar"></param>
|
|
/// <param name="cCardNum"></param>
|
|
/// <returns></returns>
|
|
private MoRoutingBillDs GetEmptyDs(IContextContainer callar, string cCardNum)
|
|
{
|
|
try
|
|
{
|
|
_logInfo.Debug($"获取空数据集-----{cCardNum}");
|
|
|
|
var ds = SFExecutor.BFMoRoutingBill_LoadData("LoadFirst", 0, "", cCardNum, callar);
|
|
|
|
#region 清除数据集里的数据
|
|
|
|
_logInfo.Debug("清空数据集-----MoRoutingBilldetail_ExtraDefine");
|
|
if (ds.Tables.Contains("fc_MoRoutingBilldetail_ExtraDefine"))
|
|
{
|
|
ds.Tables["fc_MoRoutingBilldetail_ExtraDefine"].Clear();
|
|
}
|
|
|
|
_logInfo.Debug("清空数据集-----MoRoutingBill_ExtraDefine");
|
|
if (ds.Tables.Contains("fc_MoRoutingBill_ExtraDefine"))
|
|
{
|
|
ds.Tables["fc_MoRoutingBill_ExtraDefine"].Clear();
|
|
}
|
|
|
|
_logInfo.Debug("清空数据集-----MoRoutingBillRes");
|
|
ds.MoRoutingBillRes.Clear();
|
|
|
|
_logInfo.Debug("清空数据集-----MoRoutingBillDetail");
|
|
ds.MoRoutingBillDetail.Clear();
|
|
|
|
_logInfo.Debug("清空数据集-----MoRoutingBill");
|
|
ds.MoRoutingBill.Clear();
|
|
|
|
#endregion
|
|
|
|
return ds;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 填充DataSet数据
|
|
/// </summary>
|
|
/// <param name="callar"></param>
|
|
/// <param name="cCardNum"></param>
|
|
/// <param name="docNoParam"></param>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
private MoRoutingBillDs GetVoucherDs(IContextContainer callar, string cCardNum, AutoDocNoGenerateParam docNoParam, Dictionary<string, object> input)
|
|
{
|
|
|
|
_logInfo.Debug("获取空数据集");
|
|
var ds = GetEmptyDs(callar, cCardNum);
|
|
|
|
var head = ds.MoRoutingBill.NewMoRoutingBillRow();
|
|
|
|
ds.MoRoutingBill.AddMoRoutingBillRow(head);
|
|
|
|
//_logInfo.Debug($"获取单号规则-----{cCardNum}-----{docNoParam.Paramaters.ToJson()}");
|
|
//var hsTable = U8MCommonExecutor.BFVoucher_GetVoucherIDFormula(cCardNum, callar);
|
|
|
|
//_logInfo.Debug($"获取单号-----{cCardNum}-----{hsTable.ToJson()}");
|
|
//var docNo = U8MCommonExecutor.BFVoucher_GetVoucherID(cCardNum, hsTable, false, callar);
|
|
|
|
var docNo = "";
|
|
|
|
_logInfo.Debug("BE处理中");
|
|
var be = new UFSoft.U8.SF.BE.MoRoutingBill(ds);
|
|
|
|
be.cVouchType = cCardNum;
|
|
be.cVouchCode = "";
|
|
|
|
_logInfo.Debug("填充表头参数");
|
|
var beHead = new BEHelper(be);
|
|
|
|
beHead.SetValue(input);
|
|
|
|
if (string.IsNullOrWhiteSpace(be.cVouchCode))
|
|
{
|
|
_logInfo.Debug($"设置单号:{docNo}");
|
|
be.cVouchCode = docNo;
|
|
}
|
|
|
|
var bodys = input["body"] as List<Dictionary<string, object>> ?? $"{input["body"]}".ToObject<List<Dictionary<string, object>>>();
|
|
|
|
_logInfo.Debug("填充表体参数");
|
|
for (var i = 0; i < bodys.Count; i++)
|
|
{
|
|
var body = bodys[i];
|
|
var detail = be.MoRoutingBillDetails[i];
|
|
|
|
var beBody = new BEHelper(detail);
|
|
|
|
beBody.SetValue(body);
|
|
}
|
|
|
|
_logInfo.Debug($"获取数据集:{be.DataObject.ToJson()}");
|
|
ds = (MoRoutingBillDs)be.DataObject;
|
|
|
|
return ds;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存单据
|
|
/// </summary>
|
|
/// <param name="baseLogin"></param>
|
|
/// <param name="cCardNum"></param>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="Exception"></exception>
|
|
public BaseResult<string> Save(BaseLogin baseLogin, string cCardNum, Dictionary<string, object> input, bool bVerify = false)
|
|
{
|
|
try
|
|
{
|
|
var callar = new DefaultContextContainer();
|
|
|
|
var docNoParam = new AutoDocNoGenerateParam(EnumAutoDocNoType.HandAuto, cCardNum,false)
|
|
{
|
|
IsCurrentDocNoByHand = false
|
|
};
|
|
|
|
var ds = GetVoucherDs(callar, cCardNum, docNoParam, input);
|
|
|
|
if (ds == null)
|
|
{
|
|
throw new Exception("未能构建数据集");
|
|
}
|
|
|
|
_logInfo.Debug($"单据编码:{cCardNum},开始保存");
|
|
|
|
var id = SFExecutor.BFMoRoutingBill_MoRoutingBillSave(ds, docNoParam, callar);
|
|
|
|
var voucherCode = SFExecutor.BFMoRoutingBill_GetCodeById(id, callar);
|
|
|
|
_logInfo.Debug($"单据编码:{cCardNum},保存完成,id:{id},单号:{voucherCode}");
|
|
|
|
return new BaseResult<string> { bSuccess = true, message = "新增成功", result = $"{id}",voucherCode = voucherCode,voucherId =$"{id}" };
|
|
|
|
}
|
|
catch (U8MReferenceBENotExistException ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "新增失败", result = ex.Message };
|
|
}
|
|
catch (TargetInvocationException ex)
|
|
{
|
|
if (ex.InnerException is U8MReferenceBENotExistException)
|
|
{
|
|
_logInfo.Error(ex.InnerException.Message, ex.InnerException);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "新增失败", result = ex.InnerException.Message };
|
|
}
|
|
else
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "新增失败", result = ex.Message };
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "新增失败", result = ex.Message };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存单据(批量)
|
|
/// </summary>
|
|
/// <param name="baseLogin"></param>
|
|
/// <param name="cCardNum"></param>
|
|
/// <param name="inputs"></param>
|
|
/// <returns></returns>
|
|
public BaseResult<string> Save(BaseLogin baseLogin, string cCardNum, List<Dictionary<string, object>> inputs, bool bVerify = false)
|
|
{
|
|
|
|
var idList = new List<int>();
|
|
var codeList = new List<string>();
|
|
|
|
try
|
|
{
|
|
foreach (var input in inputs)
|
|
{
|
|
var iRes = Save(baseLogin, cCardNum, input);
|
|
|
|
if (!iRes.bSuccess && idList.Count > 0)
|
|
{
|
|
Delete(baseLogin, idList);
|
|
|
|
return iRes;
|
|
}
|
|
else if (!iRes.bSuccess)
|
|
{
|
|
return iRes;
|
|
}
|
|
|
|
idList.Add(Convert.ToInt32(iRes.voucherId));
|
|
codeList.Add(iRes.voucherCode);
|
|
|
|
}
|
|
|
|
return new BaseResult<string> { bSuccess = true, message = "新增成功", result = $"{string.Join(",", codeList)}" ,voucherCode = $"{string.Join(",", codeList)}",voucherId = $"{string.Join(",", idList)}" };
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "新增失败", result = ex.Message };
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除单据(单号)(批量)
|
|
/// </summary>
|
|
/// <param name="baseLogin"></param>
|
|
/// <param name="cCardNum"></param>
|
|
/// <param name="inputs"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="Exception"></exception>
|
|
public BaseResult<string> Delete(BaseLogin baseLogin, string cCardNum, List<string> inputs)
|
|
{
|
|
try
|
|
{
|
|
if (inputs == null || inputs.Count <= 0)
|
|
throw new Exception("没有需要删除的数据");
|
|
|
|
var dataReader = SimpleDACObject.ExecuteReader($"SELECT MID FROM dbo.fc_MoRoutingBill WHERE cVouchCode IN ('{string.Join("','", inputs)}') AND cVouchType='{cCardNum}'");
|
|
|
|
var newInput = new List<int>();
|
|
|
|
while (dataReader.Read())
|
|
{
|
|
newInput.Add(int.Parse($"{dataReader[0]}"));
|
|
}
|
|
|
|
return Delete(baseLogin, newInput);
|
|
}
|
|
catch (U8MReferenceBENotExistException ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "新增失败", result = ex.Message };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "删除失败", result = ex.Message };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除单据(ID)(批量)
|
|
/// </summary>
|
|
/// <param name="baseLogin"></param>
|
|
/// <param name="inputs"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="Exception"></exception>
|
|
public BaseResult<string> Delete(BaseLogin baseLogin, List<int> inputs)
|
|
{
|
|
try
|
|
{
|
|
if (inputs == null || inputs.Count <= 0)
|
|
throw new Exception("没有需要删除的数据");
|
|
|
|
var ht = new Hashtable();
|
|
|
|
foreach (var input in inputs)
|
|
{
|
|
ht.Add(input, input);
|
|
}
|
|
|
|
var id = SFExecutor.BFMoRoutingBill_MoRoutingBillBatchDelete(ht, baseLogin.callar);
|
|
|
|
return new BaseResult<string> { bSuccess = true, message = "删除成功", result = $"{id}" };
|
|
}
|
|
catch (U8MReferenceBENotExistException ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "新增失败", result = ex.Message };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "删除失败", result = ex.Message };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 审核单据(单号)(批量)
|
|
/// </summary>
|
|
/// <param name="baseLogin"></param>
|
|
/// <param name="cCardNum"></param>
|
|
/// <param name="inputs"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="Exception"></exception>
|
|
public BaseResult<string> Verify(BaseLogin baseLogin, string cCardNum, List<string> inputs)
|
|
{
|
|
try
|
|
{
|
|
if (inputs == null || inputs.Count <= 0)
|
|
throw new Exception("没有需要审核的数据");
|
|
|
|
var dataReader = SimpleDACObject.ExecuteReader($"SELECT MID FROM dbo.fc_MoRoutingBill WHERE cVouchCode IN ('{string.Join("','", inputs)}') AND cVouchType='{cCardNum}'");
|
|
|
|
var newInput = new List<int>();
|
|
|
|
while (dataReader.Read())
|
|
{
|
|
newInput.Add(int.Parse($"{dataReader[0]}"));
|
|
}
|
|
|
|
return Verify(baseLogin, newInput);
|
|
}
|
|
catch (U8MReferenceBENotExistException ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "新增失败", result = ex.Message };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "审核失败", result = ex.Message };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 审核单据(ID)(批量)
|
|
/// </summary>
|
|
/// <param name="baseLogin"></param>
|
|
/// <param name="inputs"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="Exception"></exception>
|
|
public BaseResult<string> Verify(BaseLogin baseLogin, List<int> inputs)
|
|
{
|
|
try
|
|
{
|
|
if (inputs == null || inputs.Count <= 0)
|
|
throw new Exception("没有需要审核的数据");
|
|
|
|
var ht = new Dictionary<int, string>();
|
|
|
|
foreach (var input in inputs)
|
|
{
|
|
ht.Add(input, $"{input}");
|
|
}
|
|
|
|
var id = SFExecutor.BFMoRoutingBill_Verify(ht, baseLogin.callar);
|
|
|
|
return new BaseResult<string> { bSuccess = true, message = "审核成功", result = $"{id}" };
|
|
}
|
|
catch (U8MReferenceBENotExistException ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "新增失败", result = ex.Message };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "审核失败", result = ex.Message };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 弃审单据(单号)(批量)
|
|
/// </summary>
|
|
/// <param name="baseLogin"></param>
|
|
/// <param name="cCardNum"></param>
|
|
/// <param name="inputs"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="Exception"></exception>
|
|
public BaseResult<string> UnVerify(BaseLogin baseLogin, string cCardNum, List<string> inputs)
|
|
{
|
|
try
|
|
{
|
|
if (inputs == null || inputs.Count <= 0)
|
|
throw new Exception("没有需要弃审的数据");
|
|
|
|
var dataReader = SimpleDACObject.ExecuteReader($"SELECT MID FROM dbo.fc_MoRoutingBill WHERE cVouchCode IN ('{string.Join("','", inputs)}') AND cVouchType='{cCardNum}'");
|
|
|
|
var newInput = new List<int>();
|
|
|
|
while (dataReader.Read())
|
|
{
|
|
newInput.Add(int.Parse($"{dataReader[0]}"));
|
|
}
|
|
|
|
return UnVerify(baseLogin, newInput);
|
|
}
|
|
catch (U8MReferenceBENotExistException ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "弃审失败", result = ex.Message };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "弃审失败", result = ex.Message };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 弃审单据(ID)(批量)
|
|
/// </summary>
|
|
/// <param name="baseLogin"></param>
|
|
/// <param name="inputs"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="Exception"></exception>
|
|
public BaseResult<string> UnVerify(BaseLogin baseLogin, List<int> inputs)
|
|
{
|
|
try
|
|
{
|
|
if (inputs == null || inputs.Count <= 0)
|
|
throw new Exception("没有需要弃审的数据");
|
|
|
|
var ht = new Dictionary<int, string>();
|
|
|
|
foreach (var input in inputs)
|
|
{
|
|
ht.Add(input, $"{input}");
|
|
}
|
|
|
|
var id = SFExecutor.BFMoRoutingBill_UnVerify(ht, baseLogin.callar);
|
|
|
|
return new BaseResult<string> { bSuccess = true, message = "弃审成功", result = $"{id}" };
|
|
}
|
|
catch (U8MReferenceBENotExistException ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "新增失败", result = ex.Message };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "弃审失败", result = ex.Message };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|